Don't attempt to parse nested ASN1 strings by default.
[oweals/openssl.git] / crypto / asn1 / p5_pbev2.c
index cd597ff41889c35812c8b3786510c8157c2bf3db..c834a38ddf3cfa16fec7e961e751d49eb5a8c462 100644 (file)
@@ -1,6 +1,6 @@
 /* p5_pbev2.c */
 /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
- * project 1999.
+ * project 1999-2004.
  */
 /* ====================================================================
  * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
@@ -113,14 +113,18 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
        if(!(scheme->parameter = ASN1_TYPE_new())) goto merr;
 
        /* Create random IV */
-       if (RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0)
-               goto err;
+       if (EVP_CIPHER_iv_length(cipher) &&
+               RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0)
+               goto err;
+
+       EVP_CIPHER_CTX_init(&ctx);
 
        /* Dummy cipherinit to just setup the IV */
-       EVP_CipherInit(&ctx, cipher, NULL, iv, 0);
+       EVP_CipherInit_ex(&ctx, cipher, NULL, NULL, iv, 0);
        if(EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) {
                ASN1err(ASN1_F_PKCS5_PBE2_SET,
                                        ASN1_R_ERROR_SETTING_CIPHER_PARAMS);
+               EVP_CIPHER_CTX_cleanup(&ctx);
                goto err;
        }
        EVP_CIPHER_CTX_cleanup(&ctx);
@@ -160,7 +164,7 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
 
        if(!(pbe2->keyfunc->parameter = ASN1_TYPE_new())) goto merr;
 
-       if(!ASN1_pack_string(kdf, i2d_PBKDF2PARAM,
+       if(!ASN1_pack_string_of(PBKDF2PARAM, kdf, i2d_PBKDF2PARAM,
                         &pbe2->keyfunc->parameter->value.sequence)) goto merr;
        pbe2->keyfunc->parameter->type = V_ASN1_SEQUENCE;
 
@@ -176,7 +180,7 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
 
        /* Encode PBE2PARAM into parameter */
 
-       if(!ASN1_pack_string(pbe2, i2d_PBE2PARAM,
+       if(!ASN1_pack_string_of(PBE2PARAM, pbe2, i2d_PBE2PARAM,
                                 &ret->parameter->value.sequence)) goto merr;
        ret->parameter->type = V_ASN1_SEQUENCE;