diff options
author | Richard Levitte <levitte@openssl.org> | 2021-10-01 15:02:15 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2021-10-27 12:46:16 +0200 |
commit | 29a007870ed639fb6ba7547095d53f241a3ee7fd (patch) | |
tree | e73ab367b40707ac1ed2a30eca7b94fb7d58a1d7 | |
parent | 72d93b93ba502582d3488ee256858b8923343804 (diff) |
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)
(cherry picked from commit 433e13455ede1a39d415b690b8a564b4f36b8dee)
-rw-r--r-- | crypto/evp/asymcipher.c | 6 | ||||
-rw-r--r-- | crypto/evp/kem.c | 5 | ||||
-rw-r--r-- | crypto/evp/m_sigver.c | 6 | ||||
-rw-r--r-- | crypto/evp/signature.c | 6 |
4 files changed, 23 insertions, 0 deletions
diff --git a/crypto/evp/asymcipher.c b/crypto/evp/asymcipher.c index f158b815cf..b7784c8994 100644 --- a/crypto/evp/asymcipher.c +++ b/crypto/evp/asymcipher.c @@ -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|. */ diff --git a/crypto/evp/kem.c b/crypto/evp/kem.c index d5bdc6290a..6ba598eb98 100644 --- a/crypto/evp/kem.c +++ b/crypto/evp/kem.c @@ -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|. */ diff --git a/crypto/evp/m_sigver.c b/crypto/evp/m_sigver.c index eeb1a9adfa..2972734d8d 100644 --- a/crypto/evp/m_sigver.c +++ b/crypto/evp/m_sigver.c @@ -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|. */ diff --git a/crypto/evp/signature.c b/crypto/evp/signature.c index b33fe0d952..026a430fe8 100644 --- a/crypto/evp/signature.c +++ b/crypto/evp/signature.c @@ -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|. */ |