diff options
author | Richard Levitte <levitte@openssl.org> | 2020-03-17 14:37:47 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-03-21 09:28:11 +0100 |
commit | 4b9e90f42a367a880af2dae6f6c4b455a0d2c0f4 (patch) | |
tree | a64f44c6f27a4f4c70fe671d0f984f859ef94990 /crypto/evp/pmeth_gn.c | |
parent | 9a1c170d6309bb814ba8d720503069337f628b32 (diff) |
EVP: fetch the EVP_KEYMGMT earlier
Instead of fetching the EVP_KEYMGMT in the init for every different
operation, do it when creating the EVP_PKEY_CTX.
This allows certain control functions to be called between the
creation of the EVP_PKEY_CTX and the call of the operation's init
function.
Use case: EVP_PKEY_CTX_set1_id(), which is allowed to be called very
early with the legacy implementation, this should still be allowed
with provider implementations.
Reviewed-by: Paul Yang <kaishen.yy@antfin.com>
(Merged from https://github.com/openssl/openssl/pull/11343)
Diffstat (limited to 'crypto/evp/pmeth_gn.c')
-rw-r--r-- | crypto/evp/pmeth_gn.c | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/crypto/evp/pmeth_gn.c b/crypto/evp/pmeth_gn.c index 03f1426d85..1bf95af2ac 100644 --- a/crypto/evp/pmeth_gn.c +++ b/crypto/evp/pmeth_gn.c @@ -30,22 +30,9 @@ static int gen_init(EVP_PKEY_CTX *ctx, int operation) evp_pkey_ctx_free_old_ops(ctx); ctx->operation = operation; - if (ctx->engine != NULL || ctx->keytype == NULL) + if (ctx->keymgmt == NULL || ctx->keymgmt->gen_init == NULL) goto legacy; - if (ctx->keymgmt == NULL) { - ctx->keymgmt = - EVP_KEYMGMT_fetch(ctx->libctx, ctx->keytype, ctx->propquery); - if (ctx->keymgmt == NULL - || ctx->keymgmt->gen_init == NULL) { - EVP_KEYMGMT_free(ctx->keymgmt); - ctx->keymgmt = NULL; - goto legacy; - } - } - if (ctx->keymgmt->gen_init == NULL) - goto not_supported; - switch (operation) { case EVP_PKEY_OP_PARAMGEN: ctx->op.keymgmt.genctx = @@ -156,7 +143,7 @@ int EVP_PKEY_gen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey) return -1; } - if (ctx->keymgmt == NULL) + if (ctx->keymgmt == NULL || ctx->op.keymgmt.genctx == NULL) goto legacy; ret = 1; @@ -309,13 +296,10 @@ static int fromdata_init(EVP_PKEY_CTX *ctx, int operation) goto not_supported; evp_pkey_ctx_free_old_ops(ctx); - ctx->operation = operation; - if (ctx->keymgmt == NULL) - ctx->keymgmt = EVP_KEYMGMT_fetch(ctx->libctx, ctx->keytype, - ctx->propquery); if (ctx->keymgmt == NULL) goto not_supported; + ctx->operation = operation; return 1; not_supported: |