RSA, DSA, DH: Allow some given input to be NULL on already initialised keys
[openssl.git] / crypto / asn1 / p5_scrypt.c
index 35ff396566ca2807d7e44b6091b2ebcdfeaa14be..6ee7ef4b3b539084f826fe37798aa003c28ac4e3 100644 (file)
@@ -1,4 +1,3 @@
-/* p5_scrypt.c */
 /*
  * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
  * 2015.
@@ -82,7 +81,7 @@ ASN1_SEQUENCE(SCRYPT_PARAMS) = {
         ASN1_SIMPLE(SCRYPT_PARAMS, blockSize, ASN1_INTEGER),
         ASN1_SIMPLE(SCRYPT_PARAMS, parallelizationParameter, ASN1_INTEGER),
         ASN1_OPT(SCRYPT_PARAMS, keyLength, ASN1_INTEGER),
-} ASN1_SEQUENCE_END(SCRYPT_PARAMS)
+} static_ASN1_SEQUENCE_END(SCRYPT_PARAMS)
 
 DECLARE_ASN1_ALLOC_FUNCTIONS(SCRYPT_PARAMS)
 IMPLEMENT_ASN1_ALLOC_FUNCTIONS(SCRYPT_PARAMS)
@@ -103,7 +102,7 @@ X509_ALGOR *PKCS5_pbe2_set_scrypt(const EVP_CIPHER *cipher,
     X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL;
     int alg_nid;
     size_t keylen = 0;
-    EVP_CIPHER_CTX ctx;
+    EVP_CIPHER_CTX *ctx = NULL;
     unsigned char iv[EVP_MAX_IV_LENGTH];
     PBE2PARAM *pbe2 = NULL;
     ASN1_OBJECT *obj;
@@ -146,18 +145,20 @@ X509_ALGOR *PKCS5_pbe2_set_scrypt(const EVP_CIPHER *cipher,
             goto err;
     }
 
-    EVP_CIPHER_CTX_init(&ctx);
+    ctx = EVP_CIPHER_CTX_new();
+    if (ctx == NULL)
+        goto merr;
 
     /* Dummy cipherinit to just setup the IV */
-    if (EVP_CipherInit_ex(&ctx, cipher, NULL, NULL, iv, 0) == 0)
+    if (EVP_CipherInit_ex(ctx, cipher, NULL, NULL, iv, 0) == 0)
         goto err;
-    if (EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) {
+    if (EVP_CIPHER_param_to_asn1(ctx, scheme->parameter) < 0) {
         ASN1err(ASN1_F_PKCS5_PBE2_SET_SCRYPT,
                 ASN1_R_ERROR_SETTING_CIPHER_PARAMS);
-        EVP_CIPHER_CTX_cleanup(&ctx);
         goto err;
     }
-    EVP_CIPHER_CTX_cleanup(&ctx);
+    EVP_CIPHER_CTX_free(ctx);
+    ctx = NULL;
 
     /* If its RC2 then we'd better setup the key length */
 
@@ -199,6 +200,7 @@ X509_ALGOR *PKCS5_pbe2_set_scrypt(const EVP_CIPHER *cipher,
     PBE2PARAM_free(pbe2);
     X509_ALGOR_free(kalg);
     X509_ALGOR_free(ret);
+    EVP_CIPHER_CTX_free(ctx);
 
     return NULL;
 
@@ -247,7 +249,7 @@ static X509_ALGOR *pkcs5_scrypt_set(const unsigned char *salt, size_t saltlen,
     /* Finally setup the keyfunc structure */
 
     keyfunc = X509_ALGOR_new();
-    if (!keyfunc)
+    if (keyfunc == NULL)
         goto merr;
 
     keyfunc->algorithm = OBJ_nid2obj(NID_id_scrypt);