PKCS#8 support for alternative PRFs.
[openssl.git] / crypto / pkcs12 / p12_p8e.c
index bf20a77b4c7420279d8db00ccaab7c08b526f68b..1adb969fc40068bf82055a9ebeccf218f3a379e4 100644 (file)
@@ -73,8 +73,15 @@ X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
                goto err;
        }
 
-       if(pbe_nid == -1) pbe = PKCS5_pbe2_set(cipher, iter, salt, saltlen);
-       else pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen);
+       if(pbe_nid == -1)
+               pbe = PKCS5_pbe2_set(cipher, iter, salt, saltlen);
+       else if (EVP_PBE_find(EVP_PBE_TYPE_PRF, pbe_nid, NULL, NULL, 0))
+               pbe = PKCS5_pbe2_set_iv(cipher, iter, salt, saltlen, NULL, pbe_nid);
+       else
+               {
+               ERR_clear_error();
+               pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen);
+               }
        if(!pbe) {
                PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_ASN1_LIB);
                goto err;