EVP: For all operations that use an EVP_PKEY, check that there is one
authorRichard Levitte <levitte@openssl.org>
Fri, 1 Oct 2021 13:02:15 +0000 (15:02 +0200)
committerRichard Levitte <levitte@openssl.org>
Wed, 27 Oct 2021 10:41:14 +0000 (12:41 +0200)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16725)

crypto/evp/asymcipher.c
crypto/evp/kem.c
crypto/evp/m_sigver.c
crypto/evp/signature.c

index f158b815cff68a0dbd1cf0861ccc73c07b150293..b7784c899457ee26ff4d73d4ced452e8244551f6 100644 (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|.
      */
index d5bdc6290a3ab97c4f5fff7fc5c757bd01065681..6ba598eb98f3b9418ca80e3ee04b2e61d7485ba9 100644 (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|.
      */
index eeb1a9adfa91b649cd4716760ba8664a6c4b1834..2972734d8d91755ae8338acd3b0d1772f9a669d8 100644 (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|.
      */
index b33fe0d95253e2eb65f5d7ad8099a61d00e941e6..026a430fe8439f91a602c3bc6df7ca08d3b60ed1 100644 (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|.
      */