summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/cms/cms_enc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/cms/cms_enc.c')
-rw-r--r--src/lib/libcrypto/cms/cms_enc.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/lib/libcrypto/cms/cms_enc.c b/src/lib/libcrypto/cms/cms_enc.c
index b019d8e8e0..b3a00f67fa 100644
--- a/src/lib/libcrypto/cms/cms_enc.c
+++ b/src/lib/libcrypto/cms/cms_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cms_enc.c,v 1.13 2019/08/10 16:42:20 jsing Exp $ */ 1/* $OpenBSD: cms_enc.c,v 1.14 2019/08/10 18:15:52 jsing 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.
@@ -65,7 +65,8 @@
65 65
66/* Return BIO based on EncryptedContentInfo and key */ 66/* Return BIO based on EncryptedContentInfo and key */
67 67
68BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec) 68BIO *
69cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec)
69{ 70{
70 BIO *b; 71 BIO *b;
71 EVP_CIPHER_CTX *ctx; 72 EVP_CIPHER_CTX *ctx;
@@ -207,9 +208,9 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec)
207 return NULL; 208 return NULL;
208} 209}
209 210
210int cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec, 211int
211 const EVP_CIPHER *cipher, 212cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec,
212 const unsigned char *key, size_t keylen) 213 const EVP_CIPHER *cipher, const unsigned char *key, size_t keylen)
213{ 214{
214 ec->cipher = cipher; 215 ec->cipher = cipher;
215 if (key) { 216 if (key) {
@@ -222,13 +223,16 @@ int cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec,
222 ec->keylen = keylen; 223 ec->keylen = keylen;
223 if (cipher) 224 if (cipher)
224 ec->contentType = OBJ_nid2obj(NID_pkcs7_data); 225 ec->contentType = OBJ_nid2obj(NID_pkcs7_data);
226
225 return 1; 227 return 1;
226} 228}
227 229
228int CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph, 230int
229 const unsigned char *key, size_t keylen) 231CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph,
232 const unsigned char *key, size_t keylen)
230{ 233{
231 CMS_EncryptedContentInfo *ec; 234 CMS_EncryptedContentInfo *ec;
235
232 if (!key || !keylen) { 236 if (!key || !keylen) {
233 CMSerr(CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY, CMS_R_NO_KEY); 237 CMSerr(CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY, CMS_R_NO_KEY);
234 return 0; 238 return 0;
@@ -246,13 +250,17 @@ int CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph,
246 return 0; 250 return 0;
247 } 251 }
248 ec = cms->d.encryptedData->encryptedContentInfo; 252 ec = cms->d.encryptedData->encryptedContentInfo;
253
249 return cms_EncryptedContent_init(ec, ciph, key, keylen); 254 return cms_EncryptedContent_init(ec, ciph, key, keylen);
250} 255}
251 256
252BIO *cms_EncryptedData_init_bio(CMS_ContentInfo *cms) 257BIO *
258cms_EncryptedData_init_bio(CMS_ContentInfo *cms)
253{ 259{
254 CMS_EncryptedData *enc = cms->d.encryptedData; 260 CMS_EncryptedData *enc = cms->d.encryptedData;
261
255 if (enc->encryptedContentInfo->cipher && enc->unprotectedAttrs) 262 if (enc->encryptedContentInfo->cipher && enc->unprotectedAttrs)
256 enc->version = 2; 263 enc->version = 2;
264
257 return cms_EncryptedContent_init_bio(enc->encryptedContentInfo); 265 return cms_EncryptedContent_init_bio(enc->encryptedContentInfo);
258} 266}