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);
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;