Move the caching of cipher constants into evp_cipher_from_dispatch
[openssl.git] / crypto / evp / evp_enc.c
index 7818ab25ea22661e61d54e813d8432a4f33b85db..c1c8f1cf2865ed0bbf503d70b93d4314b058d125 100644 (file)
@@ -1470,6 +1470,12 @@ static void *evp_cipher_from_dispatch(const int name_id,
     if (prov != NULL)
         ossl_provider_up_ref(prov);
 
+    if (!evp_cipher_cache_constants(cipher)) {
+        EVP_CIPHER_free(cipher);
+        ERR_raise(ERR_LIB_EVP, EVP_R_CACHE_CONSTANTS_FAILED);
+        cipher = NULL;
+    }
+
     return cipher;
 }
 
@@ -1491,10 +1497,6 @@ EVP_CIPHER *EVP_CIPHER_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
                           evp_cipher_from_dispatch, evp_cipher_up_ref,
                           evp_cipher_free);
 
-    if (cipher != NULL && !evp_cipher_cache_constants(cipher)) {
-        EVP_CIPHER_free(cipher);
-        cipher = NULL;
-    }
     return cipher;
 }