Add bn_kron.c (BN_kronecker), which I forgot in the previous commit.
[openssl.git] / crypto / asn1 / p5_pbev2.c
index 2f6a4c4518ed75068a3c3c3698f2b4a9ddb5ee6d..6a7b578c0e2293aa97a40c87d587685efdb55e72 100644 (file)
@@ -104,7 +104,7 @@ void PBE2PARAM_free (PBE2PARAM *a)
        if(a==NULL) return;
        X509_ALGOR_free(a->keyfunc);
        X509_ALGOR_free(a->encryption);
-       Free (a);
+       OPENSSL_free (a);
 }
 
 int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **pp)
@@ -158,7 +158,7 @@ void PBKDF2PARAM_free (PBKDF2PARAM *a)
        M_ASN1_INTEGER_free(a->iter);
        M_ASN1_INTEGER_free(a->keylength);
        X509_ALGOR_free(a->prf);
-       Free (a);
+       OPENSSL_free (a);
 }
 
 /* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm:
@@ -178,12 +178,12 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
        ASN1_OBJECT *obj;
 
        alg_nid = EVP_CIPHER_type(cipher);
-       obj = OBJ_nid2obj(alg_nid);
-       if(!obj || !obj->data) {
+       if(alg_nid == NID_undef) {
                ASN1err(ASN1_F_PKCS5_PBE2_SET,
                                ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
                goto err;
        }
+       obj = OBJ_nid2obj(alg_nid);
 
        if(!(pbe2 = PBE2PARAM_new())) goto merr;
 
@@ -194,7 +194,8 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
        if(!(scheme->parameter = ASN1_TYPE_new())) goto merr;
 
        /* Create random IV */
-       RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher));
+       if (RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0)
+               goto err;
 
        /* Dummy cipherinit to just setup the IV */
        EVP_CipherInit(&ctx, cipher, NULL, iv, 0);
@@ -209,10 +210,10 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
        if(!(osalt = M_ASN1_OCTET_STRING_new())) goto merr;
 
        if (!saltlen) saltlen = PKCS5_SALT_LEN;
-       if (!(osalt->data = Malloc (saltlen))) goto merr;
+       if (!(osalt->data = OPENSSL_malloc (saltlen))) goto merr;
        osalt->length = saltlen;
        if (salt) memcpy (osalt->data, salt, saltlen);
-       else if (RAND_bytes (osalt->data, saltlen) <= 0) goto merr;
+       else if (RAND_pseudo_bytes (osalt->data, saltlen) < 0) goto merr;
 
        if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
        if(!ASN1_INTEGER_set(kdf->iter, iter)) goto merr;