summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/cms/cms_smime.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/cms/cms_smime.c')
-rw-r--r--src/lib/libcrypto/cms/cms_smime.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/lib/libcrypto/cms/cms_smime.c b/src/lib/libcrypto/cms/cms_smime.c
index 5a194748d9..a4918643d2 100644
--- a/src/lib/libcrypto/cms/cms_smime.c
+++ b/src/lib/libcrypto/cms/cms_smime.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cms_smime.c,v 1.28 2023/12/22 10:23:11 tb Exp $ */ 1/* $OpenBSD: cms_smime.c,v 1.31 2025/11/28 06:07:09 tb Exp $ */
2/* 2/*
3 * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 3 * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
4 * project. 4 * project.
@@ -59,7 +59,6 @@
59#include <openssl/asn1.h> 59#include <openssl/asn1.h>
60#include <openssl/bio.h> 60#include <openssl/bio.h>
61#include <openssl/cms.h> 61#include <openssl/cms.h>
62#include <openssl/err.h>
63#include <openssl/evp.h> 62#include <openssl/evp.h>
64#include <openssl/objects.h> 63#include <openssl/objects.h>
65#include <openssl/pkcs7.h> 64#include <openssl/pkcs7.h>
@@ -67,6 +66,7 @@
67#include <openssl/x509_vfy.h> 66#include <openssl/x509_vfy.h>
68 67
69#include "cms_local.h" 68#include "cms_local.h"
69#include "err_local.h"
70 70
71static BIO * 71static BIO *
72cms_get_text_bio(BIO *out, unsigned int flags) 72cms_get_text_bio(BIO *out, unsigned int flags)
@@ -277,25 +277,32 @@ CMS_ContentInfo *
277CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher, 277CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher,
278 const unsigned char *key, size_t keylen, unsigned int flags) 278 const unsigned char *key, size_t keylen, unsigned int flags)
279{ 279{
280 CMS_ContentInfo *cms; 280 CMS_ContentInfo *cms = NULL;
281 281
282 if (!cipher) { 282 if (cipher == NULL) {
283 CMSerror(CMS_R_NO_CIPHER); 283 CMSerror(CMS_R_NO_CIPHER);
284 return NULL; 284 goto err;
285 } 285 }
286 cms = CMS_ContentInfo_new(); 286
287 if (cms == NULL) 287 if ((cms = CMS_ContentInfo_new()) == NULL)
288 return NULL; 288 goto err;
289
289 if (!CMS_EncryptedData_set1_key(cms, cipher, key, keylen)) 290 if (!CMS_EncryptedData_set1_key(cms, cipher, key, keylen))
290 return NULL; 291 goto err;
291 292
292 if (!(flags & CMS_DETACHED)) 293 if ((flags & CMS_DETACHED) == 0) {
293 CMS_set_detached(cms, 0); 294 if (!CMS_set_detached(cms, 0))
295 goto err;
296 }
294 297
295 if ((flags & (CMS_STREAM | CMS_PARTIAL)) || 298 if ((flags & (CMS_STREAM | CMS_PARTIAL)) == 0) {
296 CMS_final(cms, in, NULL, flags)) 299 if (!CMS_final(cms, in, NULL, flags))
297 return cms; 300 goto err;
301 }
298 302
303 return cms;
304
305 err:
299 CMS_ContentInfo_free(cms); 306 CMS_ContentInfo_free(cms);
300 307
301 return NULL; 308 return NULL;