Only set CMS parameter when encrypting
authorDr. Stephen Henson <steve@openssl.org>
Fri, 6 May 2016 18:27:49 +0000 (19:27 +0100)
committerDr. Stephen Henson <steve@openssl.org>
Fri, 6 May 2016 20:12:29 +0000 (21:12 +0100)
Reviewed-by: Rich Salz <rsalz@openssl.org>
crypto/cms/cms_enc.c

index 4c4c9f24b155a7f6b868f9b7cf33bc4c41419530..7093511663384cc2cd83091296e2c8a38f496253 100644 (file)
@@ -175,21 +175,22 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec)
                CMS_R_CIPHER_INITIALISATION_ERROR);
         goto err;
     }
-
-    calg->parameter = ASN1_TYPE_new();
-    if (calg->parameter == NULL) {
-        CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, ERR_R_MALLOC_FAILURE);
-        goto err;
-    }
-    if (EVP_CIPHER_param_to_asn1(ctx, calg->parameter) <= 0) {
-        CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
-               CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR);
-        goto err;
-    }
-    /* If parameter type not set omit parameter */
-    if (calg->parameter->type == V_ASN1_UNDEF) {
-        ASN1_TYPE_free(calg->parameter);
-        calg->parameter = NULL;
+    if (enc) {
+        calg->parameter = ASN1_TYPE_new();
+        if (calg->parameter == NULL) {
+            CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, ERR_R_MALLOC_FAILURE);
+            goto err;
+        }
+        if (EVP_CIPHER_param_to_asn1(ctx, calg->parameter) <= 0) {
+            CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
+                   CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR);
+            goto err;
+        }
+        /* If parameter type not set omit parameter */
+        if (calg->parameter->type == V_ASN1_UNDEF) {
+            ASN1_TYPE_free(calg->parameter);
+            calg->parameter = NULL;
+        }
     }
     ok = 1;