EVP: For all operations that use an EVP_PKEY, check that there is one

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16725)
This commit is contained in:
Richard Levitte 2021-10-01 15:02:15 +02:00
parent 839ffdd11c
commit 433e13455e
4 changed files with 23 additions and 0 deletions

View File

@ -41,6 +41,12 @@ static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation,
if (evp_pkey_ctx_is_legacy(ctx))
goto legacy;
if (ctx->pkey == NULL) {
ERR_clear_last_mark();
ERR_raise(ERR_LIB_EVP, EVP_R_NO_KEY_SET);
goto err;
}
/*
* Try to derive the supported asym cipher from |ctx->keymgmt|.
*/

View File

@ -36,6 +36,11 @@ static int evp_kem_init(EVP_PKEY_CTX *ctx, int operation,
evp_pkey_ctx_free_old_ops(ctx);
ctx->operation = operation;
if (ctx->pkey == NULL) {
ERR_raise(ERR_LIB_EVP, EVP_R_NO_KEY_SET);
goto err;
}
/*
* Try to derive the supported kem from |ctx->keymgmt|.
*/

View File

@ -81,6 +81,12 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
if (evp_pkey_ctx_is_legacy(locpctx))
goto legacy;
if (locpctx->pkey == NULL) {
ERR_clear_last_mark();
ERR_raise(ERR_LIB_EVP, EVP_R_NO_KEY_SET);
goto err;
}
/*
* Try to derive the supported signature from |locpctx->keymgmt|.
*/

View File

@ -414,6 +414,12 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, int operation,
if (evp_pkey_ctx_is_legacy(ctx))
goto legacy;
if (ctx->pkey == NULL) {
ERR_clear_last_mark();
ERR_raise(ERR_LIB_EVP, EVP_R_NO_KEY_SET);
goto err;
}
/*
* Try to derive the supported signature from |ctx->keymgmt|.
*/