diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2016-05-06 19:27:49 +0100 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2016-05-06 21:13:56 +0100 |
commit | 6e216ba689c38cf8183dbe09d00af644b3d7bc10 (patch) | |
tree | f5775802460476fc51b493c329d91be520768edc /crypto/cms | |
parent | 0c4465ede7847227e2958e8a3fbcc0bc98af0e06 (diff) |
Only set CMS parameter when encrypting
Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit 708cf5ded249f871fcd5e3de27d9281b1f37ae71)
Diffstat (limited to 'crypto/cms')
-rw-r--r-- | crypto/cms/cms_enc.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/crypto/cms/cms_enc.c b/crypto/cms/cms_enc.c index 9f8e514cb4..e282c9dd28 100644 --- a/crypto/cms/cms_enc.c +++ b/crypto/cms/cms_enc.c @@ -179,21 +179,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; |