diff options
Diffstat (limited to 'src/lib/libcrypto/cms/cms_enc.c')
| -rw-r--r-- | src/lib/libcrypto/cms/cms_enc.c | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/src/lib/libcrypto/cms/cms_enc.c b/src/lib/libcrypto/cms/cms_enc.c index b3a00f67fa..a04c831f95 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.14 2019/08/10 18:15:52 jsing Exp $ */ | 1 | /* $OpenBSD: cms_enc.c,v 1.15 2019/08/11 10:38:27 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. |
| @@ -84,7 +84,7 @@ cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec) | |||
| 84 | 84 | ||
| 85 | b = BIO_new(BIO_f_cipher()); | 85 | b = BIO_new(BIO_f_cipher()); |
| 86 | if (b == NULL) { | 86 | if (b == NULL) { |
| 87 | CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, ERR_R_MALLOC_FAILURE); | 87 | CMSerror(ERR_R_MALLOC_FAILURE); |
| 88 | return NULL; | 88 | return NULL; |
| 89 | } | 89 | } |
| 90 | 90 | ||
| @@ -101,14 +101,13 @@ cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec) | |||
| 101 | ciph = EVP_get_cipherbyobj(calg->algorithm); | 101 | ciph = EVP_get_cipherbyobj(calg->algorithm); |
| 102 | 102 | ||
| 103 | if (!ciph) { | 103 | if (!ciph) { |
| 104 | CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, CMS_R_UNKNOWN_CIPHER); | 104 | CMSerror(CMS_R_UNKNOWN_CIPHER); |
| 105 | goto err; | 105 | goto err; |
| 106 | } | 106 | } |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | if (EVP_CipherInit_ex(ctx, ciph, NULL, NULL, NULL, enc) <= 0) { | 109 | if (EVP_CipherInit_ex(ctx, ciph, NULL, NULL, NULL, enc) <= 0) { |
| 110 | CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, | 110 | CMSerror(CMS_R_CIPHER_INITIALISATION_ERROR); |
| 111 | CMS_R_CIPHER_INITIALISATION_ERROR); | ||
| 112 | goto err; | 111 | goto err; |
| 113 | } | 112 | } |
| 114 | 113 | ||
| @@ -123,8 +122,7 @@ cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec) | |||
| 123 | piv = iv; | 122 | piv = iv; |
| 124 | } | 123 | } |
| 125 | } else if (EVP_CIPHER_asn1_to_param(ctx, calg->parameter) <= 0) { | 124 | } else if (EVP_CIPHER_asn1_to_param(ctx, calg->parameter) <= 0) { |
| 126 | CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, | 125 | CMSerror(CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR); |
| 127 | CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR); | ||
| 128 | goto err; | 126 | goto err; |
| 129 | } | 127 | } |
| 130 | tkeylen = EVP_CIPHER_CTX_key_length(ctx); | 128 | tkeylen = EVP_CIPHER_CTX_key_length(ctx); |
| @@ -132,7 +130,7 @@ cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec) | |||
| 132 | if (!enc || !ec->key) { | 130 | if (!enc || !ec->key) { |
| 133 | tkey = OPENSSL_malloc(tkeylen); | 131 | tkey = OPENSSL_malloc(tkeylen); |
| 134 | if (tkey == NULL) { | 132 | if (tkey == NULL) { |
| 135 | CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, ERR_R_MALLOC_FAILURE); | 133 | CMSerror(ERR_R_MALLOC_FAILURE); |
| 136 | goto err; | 134 | goto err; |
| 137 | } | 135 | } |
| 138 | if (EVP_CIPHER_CTX_rand_key(ctx, tkey) <= 0) | 136 | if (EVP_CIPHER_CTX_rand_key(ctx, tkey) <= 0) |
| @@ -158,8 +156,7 @@ cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec) | |||
| 158 | * which may be useful in MMA. | 156 | * which may be useful in MMA. |
| 159 | */ | 157 | */ |
| 160 | if (enc || ec->debug) { | 158 | if (enc || ec->debug) { |
| 161 | CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, | 159 | CMSerror(CMS_R_INVALID_KEY_LENGTH); |
| 162 | CMS_R_INVALID_KEY_LENGTH); | ||
| 163 | goto err; | 160 | goto err; |
| 164 | } else { | 161 | } else { |
| 165 | /* Use random key */ | 162 | /* Use random key */ |
| @@ -173,19 +170,17 @@ cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec) | |||
| 173 | } | 170 | } |
| 174 | 171 | ||
| 175 | if (EVP_CipherInit_ex(ctx, NULL, NULL, ec->key, piv, enc) <= 0) { | 172 | if (EVP_CipherInit_ex(ctx, NULL, NULL, ec->key, piv, enc) <= 0) { |
| 176 | CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, | 173 | CMSerror(CMS_R_CIPHER_INITIALISATION_ERROR); |
| 177 | CMS_R_CIPHER_INITIALISATION_ERROR); | ||
| 178 | goto err; | 174 | goto err; |
| 179 | } | 175 | } |
| 180 | if (enc) { | 176 | if (enc) { |
| 181 | calg->parameter = ASN1_TYPE_new(); | 177 | calg->parameter = ASN1_TYPE_new(); |
| 182 | if (calg->parameter == NULL) { | 178 | if (calg->parameter == NULL) { |
| 183 | CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, ERR_R_MALLOC_FAILURE); | 179 | CMSerror(ERR_R_MALLOC_FAILURE); |
| 184 | goto err; | 180 | goto err; |
| 185 | } | 181 | } |
| 186 | if (EVP_CIPHER_param_to_asn1(ctx, calg->parameter) <= 0) { | 182 | if (EVP_CIPHER_param_to_asn1(ctx, calg->parameter) <= 0) { |
| 187 | CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, | 183 | CMSerror(CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR); |
| 188 | CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR); | ||
| 189 | goto err; | 184 | goto err; |
| 190 | } | 185 | } |
| 191 | /* If parameter type not set omit parameter */ | 186 | /* If parameter type not set omit parameter */ |
| @@ -215,7 +210,7 @@ cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec, | |||
| 215 | ec->cipher = cipher; | 210 | ec->cipher = cipher; |
| 216 | if (key) { | 211 | if (key) { |
| 217 | if ((ec->key = OPENSSL_malloc(keylen)) == NULL) { | 212 | if ((ec->key = OPENSSL_malloc(keylen)) == NULL) { |
| 218 | CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT, ERR_R_MALLOC_FAILURE); | 213 | CMSerror(ERR_R_MALLOC_FAILURE); |
| 219 | return 0; | 214 | return 0; |
| 220 | } | 215 | } |
| 221 | memcpy(ec->key, key, keylen); | 216 | memcpy(ec->key, key, keylen); |
| @@ -234,19 +229,19 @@ CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph, | |||
| 234 | CMS_EncryptedContentInfo *ec; | 229 | CMS_EncryptedContentInfo *ec; |
| 235 | 230 | ||
| 236 | if (!key || !keylen) { | 231 | if (!key || !keylen) { |
| 237 | CMSerr(CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY, CMS_R_NO_KEY); | 232 | CMSerror(CMS_R_NO_KEY); |
| 238 | return 0; | 233 | return 0; |
| 239 | } | 234 | } |
| 240 | if (ciph) { | 235 | if (ciph) { |
| 241 | cms->d.encryptedData = M_ASN1_new_of(CMS_EncryptedData); | 236 | cms->d.encryptedData = M_ASN1_new_of(CMS_EncryptedData); |
| 242 | if (!cms->d.encryptedData) { | 237 | if (!cms->d.encryptedData) { |
| 243 | CMSerr(CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY, ERR_R_MALLOC_FAILURE); | 238 | CMSerror(ERR_R_MALLOC_FAILURE); |
| 244 | return 0; | 239 | return 0; |
| 245 | } | 240 | } |
| 246 | cms->contentType = OBJ_nid2obj(NID_pkcs7_encrypted); | 241 | cms->contentType = OBJ_nid2obj(NID_pkcs7_encrypted); |
| 247 | cms->d.encryptedData->version = 0; | 242 | cms->d.encryptedData->version = 0; |
| 248 | } else if (OBJ_obj2nid(cms->contentType) != NID_pkcs7_encrypted) { | 243 | } else if (OBJ_obj2nid(cms->contentType) != NID_pkcs7_encrypted) { |
| 249 | CMSerr(CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY, CMS_R_NOT_ENCRYPTED_DATA); | 244 | CMSerror(CMS_R_NOT_ENCRYPTED_DATA); |
| 250 | return 0; | 245 | return 0; |
| 251 | } | 246 | } |
| 252 | ec = cms->d.encryptedData->encryptedContentInfo; | 247 | ec = cms->d.encryptedData->encryptedContentInfo; |
