Don't ignore passed ENGINE.
authorDr. Stephen Henson <steve@openssl.org>
Mon, 9 Oct 2017 13:37:21 +0000 (14:37 +0100)
committerDr. Stephen Henson <steve@openssl.org>
Wed, 11 Oct 2017 23:08:09 +0000 (00:08 +0100)
If we are passed an ENGINE to use in int_ctx_new e.g. via EVP_PKEY_CTX_new()
use it instead of the default.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4503)

(cherry picked from commit c2976edf4b22691d8bebb0e3ca2db18b3d0c71c6)

crypto/evp/pmeth_lib.c

index b7f06be5df2b18c1d1f6e8c0ca7cc380230c8c00..877fbd072e6554a14a704d1fefc88c5b0aab4aea 100644 (file)
@@ -89,7 +89,7 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
         id = pkey->ameth->pkey_id;
     }
 #ifndef OPENSSL_NO_ENGINE
-    if (pkey && pkey->engine)
+    if (e == NULL && pkey != NULL)
         e = pkey->engine;
     /* Try to find an ENGINE which implements this method */
     if (e) {
@@ -97,8 +97,9 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
             EVPerr(EVP_F_INT_CTX_NEW, ERR_R_ENGINE_LIB);
             return NULL;
         }
-    } else
+    } else {
         e = ENGINE_get_pkey_meth_engine(id);
+    }
 
     /*
      * If an ENGINE handled this method look it up. Otherwise use internal