Make ciphers and digests obtain an ENGINE functional reference
[openssl.git] / crypto / evp / evp_enc.c
index eb39539ca63a34570716328fa624cb83e2dd0a46..22a7b745c174ac3d68bd36698da6d8cf57fa82f5 100644 (file)
@@ -77,7 +77,8 @@ void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
 int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
             const unsigned char *key, const unsigned char *iv, int enc)
        {
-       EVP_CIPHER_CTX_init(ctx);
+       if (cipher)
+               EVP_CIPHER_CTX_init(ctx);
        return EVP_CipherInit_ex(ctx,cipher,NULL,key,iv,enc);
        }
 
@@ -99,7 +100,15 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp
                 * ENGINE and EVP_CIPHER could be used). */
                if(ctx->engine)
                        ENGINE_finish(ctx->engine);
-               if(!impl)
+               if(impl)
+                       {
+                       if (!ENGINE_init(impl))
+                               {
+                               EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_INITIALIZATION_ERROR);
+                               return 0;
+                               }
+                       }
+               else
                        /* Ask if an ENGINE is reserved for this job */
                        impl = ENGINE_get_cipher_engine(cipher->nid);
                if(impl)