Fix CRL encoding bug.
[oweals/openssl.git] / crypto / asn1 / p5_pbev2.c
index 19888473e67f546a2ad67311b97c6a10f8232943..44d5b5bc6eca621481ee97c02b7951ee35f143ed 100644 (file)
@@ -175,19 +175,26 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
        PBKDF2PARAM *kdf = NULL;
        PBE2PARAM *pbe2 = NULL;
        ASN1_OCTET_STRING *osalt = NULL;
+       ASN1_OBJECT *obj;
+
+       alg_nid = EVP_CIPHER_type(cipher);
+       obj = OBJ_nid2obj(alg_nid);
+       if(!obj || !obj->data) {
+               ASN1err(ASN1_F_PKCS5_PBE2_SET,
+                               ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
+               goto err;
+       }
 
        if(!(pbe2 = PBE2PARAM_new())) goto merr;
 
        /* Setup the AlgorithmIdentifier for the encryption scheme */
        scheme = pbe2->encryption;
 
-       alg_nid = EVP_CIPHER_type(cipher);
-
-       scheme->algorithm = OBJ_nid2obj(alg_nid);
+       scheme->algorithm = obj;
        if(!(scheme->parameter = ASN1_TYPE_new())) goto merr;
 
        /* Create random IV */
-       RAND_bytes(iv, EVP_CIPHER_iv_length(cipher));
+       RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher));
 
        /* Dummy cipherinit to just setup the IV */
        EVP_CipherInit(&ctx, cipher, NULL, iv, 0);
@@ -205,7 +212,7 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
        if (!(osalt->data = Malloc (saltlen))) goto merr;
        osalt->length = saltlen;
        if (salt) memcpy (osalt->data, salt, saltlen);
-       else RAND_bytes (osalt->data, saltlen);
+       else if (RAND_bytes (osalt->data, saltlen) <= 0) goto merr;
 
        if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
        if(!ASN1_INTEGER_set(kdf->iter, iter)) goto merr;