gettables: core changes to pass the provider context.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/12581)
This commit is contained in:
Pauli 2020-08-05 13:23:16 +10:00
parent c5ec6dcf0b
commit 18ec26babc
10 changed files with 118 additions and 65 deletions

View File

@ -557,7 +557,8 @@ int EVP_MD_get_params(const EVP_MD *digest, OSSL_PARAM params[])
const OSSL_PARAM *EVP_MD_gettable_params(const EVP_MD *digest)
{
if (digest != NULL && digest->gettable_params != NULL)
return digest->gettable_params();
return digest->gettable_params(
ossl_provider_ctx(EVP_MD_provider(digest)));
return NULL;
}
@ -581,7 +582,7 @@ int EVP_MD_CTX_set_params(EVP_MD_CTX *ctx, const OSSL_PARAM params[])
const OSSL_PARAM *EVP_MD_settable_ctx_params(const EVP_MD *md)
{
if (md != NULL && md->settable_ctx_params != NULL)
return md->settable_ctx_params();
return md->settable_ctx_params(ossl_provider_ctx(EVP_MD_provider(md)));
return NULL;
}
@ -589,10 +590,12 @@ const OSSL_PARAM *EVP_MD_CTX_settable_params(EVP_MD_CTX *ctx)
{
EVP_PKEY_CTX *pctx;
if (ctx != NULL
&& ctx->digest != NULL
&& ctx->digest->settable_ctx_params != NULL)
return ctx->digest->settable_ctx_params();
if (ctx == NULL)
return NULL;
if (ctx->digest != NULL && ctx->digest->settable_ctx_params != NULL)
return ctx->digest->settable_ctx_params(
ossl_provider_ctx(EVP_MD_provider(ctx->digest)));
pctx = ctx->pctx;
if (pctx != NULL
@ -627,7 +630,7 @@ int EVP_MD_CTX_get_params(EVP_MD_CTX *ctx, OSSL_PARAM params[])
const OSSL_PARAM *EVP_MD_gettable_ctx_params(const EVP_MD *md)
{
if (md != NULL && md->gettable_ctx_params != NULL)
return md->gettable_ctx_params();
return md->gettable_ctx_params(ossl_provider_ctx(EVP_MD_provider(md)));
return NULL;
}
@ -638,7 +641,8 @@ const OSSL_PARAM *EVP_MD_CTX_gettable_params(EVP_MD_CTX *ctx)
if (ctx != NULL
&& ctx->digest != NULL
&& ctx->digest->gettable_ctx_params != NULL)
return ctx->digest->gettable_ctx_params();
return ctx->digest->gettable_ctx_params(
ossl_provider_ctx(EVP_MD_provider(ctx->digest)));
pctx = ctx->pctx;
if (pctx != NULL

View File

@ -1160,21 +1160,24 @@ int EVP_CIPHER_CTX_get_params(EVP_CIPHER_CTX *ctx, OSSL_PARAM params[])
const OSSL_PARAM *EVP_CIPHER_gettable_params(const EVP_CIPHER *cipher)
{
if (cipher != NULL && cipher->gettable_params != NULL)
return cipher->gettable_params();
return cipher->gettable_params(
ossl_provider_ctx(EVP_CIPHER_provider(cipher)));
return NULL;
}
const OSSL_PARAM *EVP_CIPHER_settable_ctx_params(const EVP_CIPHER *cipher)
{
if (cipher != NULL && cipher->settable_ctx_params != NULL)
return cipher->settable_ctx_params();
return cipher->settable_ctx_params(
ossl_provider_ctx(EVP_CIPHER_provider(cipher)));
return NULL;
}
const OSSL_PARAM *EVP_CIPHER_gettable_ctx_params(const EVP_CIPHER *cipher)
{
if (cipher != NULL && cipher->gettable_ctx_params != NULL)
return cipher->gettable_ctx_params();
return cipher->gettable_ctx_params(
ossl_provider_ctx(EVP_CIPHER_provider(cipher)));
return NULL;
}

View File

@ -377,19 +377,25 @@ int EVP_RAND_set_ctx_params(EVP_RAND_CTX *ctx, const OSSL_PARAM params[])
const OSSL_PARAM *EVP_RAND_gettable_params(const EVP_RAND *rand)
{
return rand->gettable_params == NULL ? NULL : rand->gettable_params();
if (rand->gettable_params == NULL)
return NULL;
return rand->gettable_params(ossl_provider_ctx(EVP_RAND_provider(rand)));
}
const OSSL_PARAM *EVP_RAND_gettable_ctx_params(const EVP_RAND *rand)
{
return rand->gettable_ctx_params == NULL ? NULL
: rand->gettable_ctx_params();
if (rand->gettable_params == NULL)
return NULL;
return rand->gettable_ctx_params(
ossl_provider_ctx(EVP_RAND_provider(rand)));
}
const OSSL_PARAM *EVP_RAND_settable_ctx_params(const EVP_RAND *rand)
{
return rand->settable_ctx_params == NULL ? NULL
: rand->settable_ctx_params();
if (rand->gettable_params == NULL)
return NULL;
return rand->settable_ctx_params(
ossl_provider_ctx(EVP_RAND_provider(rand)));
}
void EVP_RAND_do_all_provided(OPENSSL_CTX *libctx,

View File

@ -169,21 +169,21 @@ const OSSL_PARAM *EVP_KDF_gettable_params(const EVP_KDF *kdf)
{
if (kdf->gettable_params == NULL)
return NULL;
return kdf->gettable_params();
return kdf->gettable_params(ossl_provider_ctx(EVP_KDF_provider(kdf)));
}
const OSSL_PARAM *EVP_KDF_gettable_ctx_params(const EVP_KDF *kdf)
{
if (kdf->gettable_ctx_params == NULL)
return NULL;
return kdf->gettable_ctx_params();
return kdf->gettable_ctx_params(ossl_provider_ctx(EVP_KDF_provider(kdf)));
}
const OSSL_PARAM *EVP_KDF_settable_ctx_params(const EVP_KDF *kdf)
{
if (kdf->settable_ctx_params == NULL)
return NULL;
return kdf->settable_ctx_params();
return kdf->settable_ctx_params(ossl_provider_ctx(EVP_KDF_provider(kdf)));
}
void EVP_KDF_do_all_provided(OPENSSL_CTX *libctx,

View File

@ -369,9 +369,11 @@ int evp_keymgmt_get_params(const EVP_KEYMGMT *keymgmt, void *keydata,
const OSSL_PARAM *evp_keymgmt_gettable_params(const EVP_KEYMGMT *keymgmt)
{
void *provctx = ossl_provider_ctx(EVP_KEYMGMT_provider(keymgmt));
if (keymgmt->gettable_params == NULL)
return NULL;
return keymgmt->gettable_params();
return keymgmt->gettable_params(provctx);
}
int evp_keymgmt_set_params(const EVP_KEYMGMT *keymgmt, void *keydata,
@ -384,9 +386,11 @@ int evp_keymgmt_set_params(const EVP_KEYMGMT *keymgmt, void *keydata,
const OSSL_PARAM *evp_keymgmt_settable_params(const EVP_KEYMGMT *keymgmt)
{
void *provctx = ossl_provider_ctx(EVP_KEYMGMT_provider(keymgmt));
if (keymgmt->settable_params == NULL)
return NULL;
return keymgmt->settable_params();
return keymgmt->settable_params(provctx);
}
int evp_keymgmt_has(const EVP_KEYMGMT *keymgmt, void *keydata, int selection)

View File

@ -176,21 +176,21 @@ const OSSL_PARAM *EVP_MAC_gettable_params(const EVP_MAC *mac)
{
if (mac->gettable_params == NULL)
return NULL;
return mac->gettable_params();
return mac->gettable_params(ossl_provider_ctx(EVP_MAC_provider(mac)));
}
const OSSL_PARAM *EVP_MAC_gettable_ctx_params(const EVP_MAC *mac)
{
if (mac->gettable_ctx_params == NULL)
return NULL;
return mac->gettable_ctx_params();
return mac->gettable_ctx_params(ossl_provider_ctx(EVP_MAC_provider(mac)));
}
const OSSL_PARAM *EVP_MAC_settable_ctx_params(const EVP_MAC *mac)
{
if (mac->settable_ctx_params == NULL)
return NULL;
return mac->settable_ctx_params();
return mac->settable_ctx_params(ossl_provider_ctx(EVP_MAC_provider(mac)));
}
void EVP_MAC_do_all_provided(OPENSSL_CTX *libctx,

View File

@ -631,35 +631,55 @@ int EVP_PKEY_CTX_get_params(EVP_PKEY_CTX *ctx, OSSL_PARAM *params)
#ifndef FIPS_MODULE
const OSSL_PARAM *EVP_PKEY_CTX_gettable_params(EVP_PKEY_CTX *ctx)
{
void *provctx;
if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)
&& ctx->op.kex.exchange != NULL
&& ctx->op.kex.exchange->gettable_ctx_params != NULL)
return ctx->op.kex.exchange->gettable_ctx_params();
&& ctx->op.kex.exchange->gettable_ctx_params != NULL) {
provctx = ossl_provider_ctx(EVP_KEYEXCH_provider(ctx->op.kex.exchange));
return ctx->op.kex.exchange->gettable_ctx_params(provctx);
}
if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
&& ctx->op.sig.signature != NULL
&& ctx->op.sig.signature->gettable_ctx_params != NULL)
return ctx->op.sig.signature->gettable_ctx_params();
&& ctx->op.sig.signature->gettable_ctx_params != NULL) {
provctx = ossl_provider_ctx(
EVP_SIGNATURE_provider(ctx->op.sig.signature));
return ctx->op.sig.signature->gettable_ctx_params(provctx);
}
if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
&& ctx->op.ciph.cipher != NULL
&& ctx->op.ciph.cipher->gettable_ctx_params != NULL)
return ctx->op.ciph.cipher->gettable_ctx_params();
&& ctx->op.ciph.cipher->gettable_ctx_params != NULL) {
provctx = ossl_provider_ctx(
EVP_ASYM_CIPHER_provider(ctx->op.ciph.cipher));
return ctx->op.ciph.cipher->gettable_ctx_params(provctx);
}
return NULL;
}
const OSSL_PARAM *EVP_PKEY_CTX_settable_params(EVP_PKEY_CTX *ctx)
{
void *provctx;
if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)
&& ctx->op.kex.exchange != NULL
&& ctx->op.kex.exchange->settable_ctx_params != NULL)
return ctx->op.kex.exchange->settable_ctx_params();
&& ctx->op.kex.exchange->settable_ctx_params != NULL) {
provctx = ossl_provider_ctx(EVP_KEYEXCH_provider(ctx->op.kex.exchange));
return ctx->op.kex.exchange->settable_ctx_params(provctx);
}
if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
&& ctx->op.sig.signature != NULL
&& ctx->op.sig.signature->settable_ctx_params != NULL)
return ctx->op.sig.signature->settable_ctx_params();
&& ctx->op.sig.signature->settable_ctx_params != NULL) {
provctx = ossl_provider_ctx(
EVP_SIGNATURE_provider(ctx->op.sig.signature));
return ctx->op.sig.signature->settable_ctx_params(provctx);
}
if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
&& ctx->op.ciph.cipher != NULL
&& ctx->op.ciph.cipher->settable_ctx_params != NULL)
return ctx->op.ciph.cipher->settable_ctx_params();
&& ctx->op.ciph.cipher->settable_ctx_params != NULL) {
provctx = ossl_provider_ctx(
EVP_ASYM_CIPHER_provider(ctx->op.ciph.cipher));
return ctx->op.ciph.cipher->settable_ctx_params(provctx);
}
if (EVP_PKEY_CTX_IS_GEN_OP(ctx)
&& ctx->keymgmt != NULL)
return evp_keymgmt_gen_settable_params(ctx->keymgmt);

View File

@ -452,7 +452,8 @@ const OSSL_PARAM *
OSSL_DESERIALIZER_gettable_params(OSSL_DESERIALIZER *deser)
{
if (deser != NULL && deser->gettable_params != NULL)
return deser->gettable_params();
return deser->gettable_params(
ossl_provider_ctx(OSSL_DESERIALIZER_provider(deser)));
return NULL;
}
@ -467,7 +468,8 @@ const OSSL_PARAM *
OSSL_DESERIALIZER_settable_ctx_params(OSSL_DESERIALIZER *deser)
{
if (deser != NULL && deser->settable_ctx_params != NULL)
return deser->settable_ctx_params();
return deser->settable_ctx_params(
ossl_provider_ctx(OSSL_DESERIALIZER_provider(deser)));
return NULL;
}

View File

@ -444,7 +444,8 @@ void OSSL_SERIALIZER_names_do_all(const OSSL_SERIALIZER *ser,
const OSSL_PARAM *OSSL_SERIALIZER_settable_ctx_params(OSSL_SERIALIZER *ser)
{
if (ser != NULL && ser->settable_ctx_params != NULL)
return ser->settable_ctx_params();
return ser->settable_ctx_params(
ossl_provider_ctx(OSSL_SERIALIZER_provider(ser)));
return NULL;
}

View File

@ -229,9 +229,12 @@ OSSL_CORE_MAKE_FUNC(int, digest_set_ctx_params,
(void *vctx, const OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(int, digest_get_ctx_params,
(void *vctx, OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, digest_gettable_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, digest_settable_ctx_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, digest_gettable_ctx_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, digest_gettable_params,
(void *provctx))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, digest_settable_ctx_params,
(void *provctx))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, digest_gettable_ctx_params,
(void *provctx))
/* Symmetric Ciphers */
@ -279,9 +282,12 @@ OSSL_CORE_MAKE_FUNC(int, cipher_get_ctx_params, (void *cctx,
OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(int, cipher_set_ctx_params, (void *cctx,
const OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, cipher_gettable_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, cipher_settable_ctx_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, cipher_gettable_ctx_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, cipher_gettable_params,
(void *provctx))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, cipher_settable_ctx_params,
(void *provctx))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, cipher_gettable_ctx_params,
(void *provctx))
/* MACs */
@ -308,9 +314,11 @@ OSSL_CORE_MAKE_FUNC(int, mac_update,
OSSL_CORE_MAKE_FUNC(int, mac_final,
(void *mctx,
unsigned char *out, size_t *outl, size_t outsize))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, mac_gettable_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, mac_gettable_ctx_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, mac_settable_ctx_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, mac_gettable_params, (void *provctx))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, mac_gettable_ctx_params,
(void *provctx))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, mac_settable_ctx_params,
(void *provctx))
OSSL_CORE_MAKE_FUNC(int, mac_get_params, (OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(int, mac_get_ctx_params,
(void *mctx, OSSL_PARAM params[]))
@ -337,9 +345,11 @@ OSSL_CORE_MAKE_FUNC(void, kdf_freectx, (void *kctx))
OSSL_CORE_MAKE_FUNC(void, kdf_reset, (void *kctx))
OSSL_CORE_MAKE_FUNC(int, kdf_derive, (void *kctx, unsigned char *key,
size_t keylen))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, kdf_gettable_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, kdf_gettable_ctx_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, kdf_settable_ctx_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, kdf_gettable_params, (void *provctx))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, kdf_gettable_ctx_params,
(void *provctx))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, kdf_settable_ctx_params,
(void *provctx))
OSSL_CORE_MAKE_FUNC(int, kdf_get_params, (OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(int, kdf_get_ctx_params,
(void *kctx, OSSL_PARAM params[]))
@ -390,9 +400,11 @@ OSSL_CORE_MAKE_FUNC(size_t,rand_nonce,
OSSL_CORE_MAKE_FUNC(int,rand_enable_locking, (void *vctx))
OSSL_CORE_MAKE_FUNC(int,rand_lock, (void *vctx))
OSSL_CORE_MAKE_FUNC(void,rand_unlock, (void *vctx))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,rand_gettable_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,rand_gettable_ctx_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,rand_settable_ctx_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,rand_gettable_params, (void *provctx))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,rand_gettable_ctx_params,
(void *provctx))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,rand_settable_ctx_params,
(void *provctx))
OSSL_CORE_MAKE_FUNC(int,rand_get_params, (OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(int,rand_get_ctx_params,
(void *vctx, OSSL_PARAM params[]))
@ -497,13 +509,13 @@ OSSL_CORE_MAKE_FUNC(void, keymgmt_free, (void *keydata))
#define OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS 12
OSSL_CORE_MAKE_FUNC(int, keymgmt_get_params,
(void *keydata, OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, keymgmt_gettable_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, keymgmt_gettable_params, (void *))
#define OSSL_FUNC_KEYMGMT_SET_PARAMS 13
#define OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS 14
OSSL_CORE_MAKE_FUNC(int, keymgmt_set_params,
(void *keydata, const OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, keymgmt_settable_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, keymgmt_settable_params, (void *))
/* Key checks - discovery of supported operations */
# define OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME 20
@ -568,11 +580,11 @@ OSSL_CORE_MAKE_FUNC(void *, keyexch_dupctx, (void *ctx))
OSSL_CORE_MAKE_FUNC(int, keyexch_set_ctx_params, (void *ctx,
const OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, keyexch_settable_ctx_params,
(void))
(void *provctx))
OSSL_CORE_MAKE_FUNC(int, keyexch_get_ctx_params, (void *ctx,
OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, keyexch_gettable_ctx_params,
(void))
(void *provctx))
/* Signature */
@ -647,11 +659,11 @@ OSSL_CORE_MAKE_FUNC(void *, signature_dupctx, (void *ctx))
OSSL_CORE_MAKE_FUNC(int, signature_get_ctx_params,
(void *ctx, OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, signature_gettable_ctx_params,
(void))
(void *provctx))
OSSL_CORE_MAKE_FUNC(int, signature_set_ctx_params,
(void *ctx, const OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, signature_settable_ctx_params,
(void))
(void *provctx))
OSSL_CORE_MAKE_FUNC(int, signature_get_ctx_md_params,
(void *ctx, OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, signature_gettable_ctx_md_params,
@ -694,11 +706,11 @@ OSSL_CORE_MAKE_FUNC(void *, asym_cipher_dupctx, (void *ctx))
OSSL_CORE_MAKE_FUNC(int, asym_cipher_get_ctx_params,
(void *ctx, OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, asym_cipher_gettable_ctx_params,
(void))
(void *provctx))
OSSL_CORE_MAKE_FUNC(int, asym_cipher_set_ctx_params,
(void *ctx, const OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, asym_cipher_settable_ctx_params,
(void))
(void *provctx))
/* Serializers and deserializers */
# define OSSL_FUNC_SERIALIZER_NEWCTX 1
@ -712,7 +724,7 @@ OSSL_CORE_MAKE_FUNC(void, serializer_freectx, (void *ctx))
OSSL_CORE_MAKE_FUNC(int, serializer_set_ctx_params,
(void *ctx, const OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, serializer_settable_ctx_params,
(void))
(void *provctx))
OSSL_CORE_MAKE_FUNC(int, serializer_serialize_data,
(void *ctx, const OSSL_PARAM[], OSSL_CORE_BIO *out,
@ -732,11 +744,12 @@ OSSL_CORE_MAKE_FUNC(int, serializer_serialize_object,
OSSL_CORE_MAKE_FUNC(void *, deserializer_newctx, (void *provctx))
OSSL_CORE_MAKE_FUNC(void, deserializer_freectx, (void *ctx))
OSSL_CORE_MAKE_FUNC(int, deserializer_get_params, (OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, deserializer_gettable_params, (void))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, deserializer_gettable_params,
(void *provctx))
OSSL_CORE_MAKE_FUNC(int, deserializer_set_ctx_params,
(void *ctx, const OSSL_PARAM params[]))
OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, deserializer_settable_ctx_params,
(void))
(void *provctx))
OSSL_CORE_MAKE_FUNC(int, deserializer_deserialize,
(void *ctx, OSSL_CORE_BIO *in,