diff options
author | Richard Levitte <levitte@openssl.org> | 2020-11-04 12:23:19 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-11-13 09:35:02 +0100 |
commit | 9311d0c471ca2eaa259e8c1bbbeb7c46394c7ba2 (patch) | |
tree | e82c26569e5a952980e65a746af920beed602aab /crypto/cms | |
parent | 31a6b52f6db009c639c67387a707dd235f29a430 (diff) |
Convert all {NAME}err() in crypto/ to their corresponding ERR_raise() call
This includes error reporting for libcrypto sub-libraries in surprising
places.
This was done using util/err-to-raise
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/13318)
Diffstat (limited to 'crypto/cms')
-rw-r--r-- | crypto/cms/cms_att.c | 2 | ||||
-rw-r--r-- | crypto/cms/cms_cd.c | 9 | ||||
-rw-r--r-- | crypto/cms/cms_dd.c | 8 | ||||
-rw-r--r-- | crypto/cms/cms_dh.c | 8 | ||||
-rw-r--r-- | crypto/cms/cms_ec.c | 12 | ||||
-rw-r--r-- | crypto/cms/cms_enc.c | 32 | ||||
-rw-r--r-- | crypto/cms/cms_env.c | 116 | ||||
-rw-r--r-- | crypto/cms/cms_ess.c | 49 | ||||
-rw-r--r-- | crypto/cms/cms_io.c | 2 | ||||
-rw-r--r-- | crypto/cms/cms_kari.c | 14 | ||||
-rw-r--r-- | crypto/cms/cms_lib.c | 37 | ||||
-rw-r--r-- | crypto/cms/cms_pwri.c | 41 | ||||
-rw-r--r-- | crypto/cms/cms_rsa.c | 14 | ||||
-rw-r--r-- | crypto/cms/cms_sd.c | 69 | ||||
-rw-r--r-- | crypto/cms/cms_smime.c | 72 |
15 files changed, 219 insertions, 266 deletions
diff --git a/crypto/cms/cms_att.c b/crypto/cms/cms_att.c index 2c8138f13e..91e8f75db7 100644 --- a/crypto/cms/cms_att.c +++ b/crypto/cms/cms_att.c @@ -276,7 +276,7 @@ int CMS_si_check_attributes(const CMS_SignerInfo *si) si->signedAttrs, have_signed_attrs) || !cms_check_attribute(nid, flags, CMS_ATTR_F_UNSIGNED, si->unsignedAttrs, have_unsigned_attrs)) { - CMSerr(CMS_F_CMS_SI_CHECK_ATTRIBUTES, CMS_R_ATTRIBUTE_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_ATTRIBUTE_ERROR); return 0; } } diff --git a/crypto/cms/cms_cd.c b/crypto/cms/cms_cd.c index c806a472d5..c781268659 100644 --- a/crypto/cms/cms_cd.c +++ b/crypto/cms/cms_cd.c @@ -32,8 +32,7 @@ CMS_ContentInfo *cms_CompressedData_create(int comp_nid, OSSL_LIB_CTX *libctx, * compression algorithm or parameters have some meaning... */ if (comp_nid != NID_zlib_compression) { - CMSerr(CMS_F_CMS_COMPRESSEDDATA_CREATE, - CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); + ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); return NULL; } cms = CMS_ContentInfo_new_ex(libctx, propq); @@ -68,15 +67,13 @@ BIO *cms_CompressedData_init_bio(const CMS_ContentInfo *cms) const ASN1_OBJECT *compoid; if (OBJ_obj2nid(cms->contentType) != NID_id_smime_ct_compressedData) { - CMSerr(CMS_F_CMS_COMPRESSEDDATA_INIT_BIO, - CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA); + ERR_raise(ERR_LIB_CMS, CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA); return NULL; } cd = cms->d.compressedData; X509_ALGOR_get0(&compoid, NULL, NULL, cd->compressionAlgorithm); if (OBJ_obj2nid(compoid) != NID_zlib_compression) { - CMSerr(CMS_F_CMS_COMPRESSEDDATA_INIT_BIO, - CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); + ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); return NULL; } return BIO_new(BIO_f_zlib()); diff --git a/crypto/cms/cms_dd.c b/crypto/cms/cms_dd.c index 0353c2276f..4eba827d62 100644 --- a/crypto/cms/cms_dd.c +++ b/crypto/cms/cms_dd.c @@ -64,7 +64,7 @@ int cms_DigestedData_do_final(const CMS_ContentInfo *cms, BIO *chain, int verify CMS_DigestedData *dd; if (mctx == NULL) { - CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); goto err; } @@ -78,14 +78,12 @@ int cms_DigestedData_do_final(const CMS_ContentInfo *cms, BIO *chain, int verify if (verify) { if (mdlen != (unsigned int)dd->digest->length) { - CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL, - CMS_R_MESSAGEDIGEST_WRONG_LENGTH); + ERR_raise(ERR_LIB_CMS, CMS_R_MESSAGEDIGEST_WRONG_LENGTH); goto err; } if (memcmp(md, dd->digest->data, mdlen)) - CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL, - CMS_R_VERIFICATION_FAILURE); + ERR_raise(ERR_LIB_CMS, CMS_R_VERIFICATION_FAILURE); else r = 1; } else { diff --git a/crypto/cms/cms_dh.c b/crypto/cms/cms_dh.c index 2c64f50259..90b439dd35 100644 --- a/crypto/cms/cms_dh.c +++ b/crypto/cms/cms_dh.c @@ -77,7 +77,7 @@ static int dh_cms_set_shared_info(EVP_PKEY_CTX *pctx, CMS_RecipientInfo *ri) * we will need something cleverer. */ if (OBJ_obj2nid(alg->algorithm) != NID_id_smime_alg_ESDH) { - CMSerr(0, CMS_R_KDF_PARAMETER_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_KDF_PARAMETER_ERROR); goto err; } @@ -148,13 +148,13 @@ static int dh_cms_decrypt(CMS_RecipientInfo *ri) if (alg == NULL || pubkey == NULL) return 0; if (!dh_cms_set_peerkey(pctx, alg, pubkey)) { - DHerr(DH_F_DH_CMS_DECRYPT, DH_R_PEER_KEY_ERROR); + ERR_raise(ERR_LIB_DH, DH_R_PEER_KEY_ERROR); return 0; } } /* Set DH derivation parameters and initialise unwrap context */ if (!dh_cms_set_shared_info(pctx, ri)) { - DHerr(DH_F_DH_CMS_DECRYPT, DH_R_SHARED_INFO_ERROR); + ERR_raise(ERR_LIB_DH, DH_R_SHARED_INFO_ERROR); return 0; } return 1; @@ -311,6 +311,6 @@ int cms_dh_envelope(CMS_RecipientInfo *ri, int decrypt) if (decrypt == 0) return dh_cms_encrypt(ri); - CMSerr(0, CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE); + ERR_raise(ERR_LIB_CMS, CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE); return 0; } diff --git a/crypto/cms/cms_ec.c b/crypto/cms/cms_ec.c index 5dac7f0683..8cb41dfdef 100644 --- a/crypto/cms/cms_ec.c +++ b/crypto/cms/cms_ec.c @@ -46,13 +46,13 @@ static EVP_PKEY *pkey_type2param(int ptype, const void *pval, groupname = OBJ_nid2sn(OBJ_obj2nid(poid)); if (groupname == NULL || !EVP_PKEY_CTX_set_group_name(pctx, groupname)) { - CMSerr(0, CMS_R_DECODE_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_DECODE_ERROR); goto err; } if (EVP_PKEY_paramgen(pctx, &pkey) <= 0) goto err; } else { - CMSerr(0, CMS_R_DECODE_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_DECODE_ERROR); goto err; } @@ -166,7 +166,7 @@ static int ecdh_cms_set_shared_info(EVP_PKEY_CTX *pctx, CMS_RecipientInfo *ri) return 0; if (!ecdh_cms_set_kdf_param(pctx, OBJ_obj2nid(alg->algorithm))) { - CMSerr(0, CMS_R_KDF_PARAMETER_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_KDF_PARAMETER_ERROR); return 0; } @@ -229,13 +229,13 @@ static int ecdh_cms_decrypt(CMS_RecipientInfo *ri) if (alg == NULL || pubkey == NULL) return 0; if (!ecdh_cms_set_peerkey(pctx, alg, pubkey)) { - CMSerr(0, CMS_R_PEER_KEY_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_PEER_KEY_ERROR); return 0; } } /* Set ECDH derivation parameters and initialise unwrap context */ if (!ecdh_cms_set_shared_info(pctx, ri)) { - CMSerr(0, CMS_R_SHARED_INFO_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_SHARED_INFO_ERROR); return 0; } return 1; @@ -381,7 +381,7 @@ int cms_ecdh_envelope(CMS_RecipientInfo *ri, int decrypt) if (decrypt == 0) return ecdh_cms_encrypt(ri); - CMSerr(0, CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE); + ERR_raise(ERR_LIB_CMS, CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE); return 0; } #endif diff --git a/crypto/cms/cms_enc.c b/crypto/cms/cms_enc.c index ef87fac8ef..0069bde939 100644 --- a/crypto/cms/cms_enc.c +++ b/crypto/cms/cms_enc.c @@ -42,7 +42,7 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec, b = BIO_new(BIO_f_cipher()); if (b == NULL) { - CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); return NULL; } @@ -67,14 +67,13 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec, } if (cipher == NULL) { (void)ERR_clear_last_mark(); - CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, CMS_R_UNKNOWN_CIPHER); + ERR_raise(ERR_LIB_CMS, CMS_R_UNKNOWN_CIPHER); goto err; } (void)ERR_pop_to_mark(); if (EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, enc) <= 0) { - CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, - CMS_R_CIPHER_INITIALISATION_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_CIPHER_INITIALISATION_ERROR); goto err; } @@ -89,7 +88,7 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec, } } else { if (evp_cipher_asn1_to_param_ex(ctx, calg->parameter, &aparams) <= 0) { - CMSerr(0, CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR); goto err; } if ((EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)) { @@ -97,7 +96,7 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec, if (ec->taglen > 0 && EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, ec->taglen, ec->tag) <= 0) { - CMSerr(0, CMS_R_CIPHER_AEAD_SET_TAG_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_CIPHER_AEAD_SET_TAG_ERROR); goto err; } } @@ -111,7 +110,7 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec, if (!enc || !ec->key) { tkey = OPENSSL_malloc(tkeylen); if (tkey == NULL) { - CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); goto err; } if (EVP_CIPHER_CTX_rand_key(ctx, tkey) <= 0) @@ -137,8 +136,7 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec, * which may be useful in MMA. */ if (enc || ec->debug) { - CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, - CMS_R_INVALID_KEY_LENGTH); + ERR_raise(ERR_LIB_CMS, CMS_R_INVALID_KEY_LENGTH); goto err; } else { /* Use random key */ @@ -152,14 +150,13 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec, } if (EVP_CipherInit_ex(ctx, NULL, NULL, ec->key, piv, enc) <= 0) { - CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, - CMS_R_CIPHER_INITIALISATION_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_CIPHER_INITIALISATION_ERROR); goto err; } if (enc) { calg->parameter = ASN1_TYPE_new(); if (calg->parameter == NULL) { - CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); goto err; } if ((EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)) { @@ -171,8 +168,7 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec, } if (evp_cipher_param_to_asn1_ex(ctx, calg->parameter, &aparams) <= 0) { - CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, - CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR); goto err; } /* If parameter type not set omit parameter */ @@ -204,7 +200,7 @@ int cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec, ec->cipher = cipher; if (key) { if ((ec->key = OPENSSL_malloc(keylen)) == NULL) { - CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); return 0; } memcpy(ec->key, key, keylen); @@ -221,19 +217,19 @@ int CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph, CMS_EncryptedContentInfo *ec; if (!key || !keylen) { - CMSerr(CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY, CMS_R_NO_KEY); + ERR_raise(ERR_LIB_CMS, CMS_R_NO_KEY); return 0; } if (ciph) { cms->d.encryptedData = M_ASN1_new_of(CMS_EncryptedData); if (!cms->d.encryptedData) { - CMSerr(CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); return 0; } cms->contentType = OBJ_nid2obj(NID_pkcs7_encrypted); cms->d.encryptedData->version = 0; } else if (OBJ_obj2nid(cms->contentType) != NID_pkcs7_encrypted) { - CMSerr(CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY, CMS_R_NOT_ENCRYPTED_DATA); + ERR_raise(ERR_LIB_CMS, CMS_R_NOT_ENCRYPTED_DATA); return 0; } ec = cms->d.encryptedData->encryptedContentInfo; diff --git a/crypto/cms/cms_env.c b/crypto/cms/cms_env.c index 83826beb51..cedabe1f3c 100644 --- a/crypto/cms/cms_env.c +++ b/crypto/cms/cms_env.c @@ -37,7 +37,7 @@ static int cms_get_enveloped_type(const CMS_ContentInfo *cms) return CMS_ENVELOPED_AUTH; default: - CMSerr(0, CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA); + ERR_raise(ERR_LIB_CMS, CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA); return 0; } } @@ -45,8 +45,7 @@ static int cms_get_enveloped_type(const CMS_ContentInfo *cms) CMS_EnvelopedData *cms_get0_enveloped(CMS_ContentInfo *cms) { if (OBJ_obj2nid(cms->contentType) != NID_pkcs7_enveloped) { - CMSerr(CMS_F_CMS_GET0_ENVELOPED, - CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA); + ERR_raise(ERR_LIB_CMS, CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA); return NULL; } return cms->d.envelopedData; @@ -55,7 +54,7 @@ CMS_EnvelopedData *cms_get0_enveloped(CMS_ContentInfo *cms) CMS_AuthEnvelopedData *cms_get0_auth_enveloped(CMS_ContentInfo *cms) { if (OBJ_obj2nid(cms->contentType) != NID_id_smime_ct_authEnvelopedData) { - CMSerr(0, CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA); + ERR_raise(ERR_LIB_CMS, CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA); return NULL; } return cms->d.authEnvelopedData; @@ -66,7 +65,7 @@ static CMS_EnvelopedData *cms_enveloped_data_init(CMS_ContentInfo *cms) if (cms->d.other == NULL) { cms->d.envelopedData = M_ASN1_new_of(CMS_EnvelopedData); if (cms->d.envelopedData == NULL) { - CMSerr(CMS_F_CMS_ENVELOPED_DATA_INIT, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); return NULL; } cms->d.envelopedData->version = 0; @@ -85,7 +84,7 @@ cms_auth_enveloped_data_init(CMS_ContentInfo *cms) if (cms->d.other == NULL) { cms->d.authEnvelopedData = M_ASN1_new_of(CMS_AuthEnvelopedData); if (cms->d.authEnvelopedData == NULL) { - CMSerr(0, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); return NULL; } /* Defined in RFC 5083 - Section 2.1. "AuthEnvelopedData Type" */ @@ -134,12 +133,11 @@ int cms_env_asn1_ctrl(CMS_RecipientInfo *ri, int cmd) return 1; i = pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_CMS_ENVELOPE, cmd, ri); if (i == -2) { - CMSerr(CMS_F_CMS_ENV_ASN1_CTRL, - CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE); + ERR_raise(ERR_LIB_CMS, CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE); return 0; } if (i <= 0) { - CMSerr(CMS_F_CMS_ENV_ASN1_CTRL, CMS_R_CTRL_FAILURE); + ERR_raise(ERR_LIB_CMS, CMS_R_CTRL_FAILURE); return 0; } return 1; @@ -238,7 +236,7 @@ CMS_ContentInfo *CMS_EnvelopedData_create_ex(const EVP_CIPHER *cipher, return cms; merr: CMS_ContentInfo_free(cms); - CMSerr(0, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); return NULL; } @@ -266,7 +264,7 @@ CMS_AuthEnvelopedData_create_ex(const EVP_CIPHER *cipher, OSSL_LIB_CTX *libctx, return cms; merr: CMS_ContentInfo_free(cms); - CMSerr(0, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); return NULL; } @@ -353,7 +351,7 @@ CMS_RecipientInfo *CMS_add1_recipient(CMS_ContentInfo *cms, X509 *recip, pk = X509_get0_pubkey(recip); if (pk == NULL) { - CMSerr(CMS_F_CMS_ADD1_RECIPIENT, CMS_R_ERROR_GETTING_PUBLIC_KEY); + ERR_raise(ERR_LIB_CMS, CMS_R_ERROR_GETTING_PUBLIC_KEY); goto err; } @@ -371,8 +369,7 @@ CMS_RecipientInfo *CMS_add1_recipient(CMS_ContentInfo *cms, X509 *recip, break; default: - CMSerr(CMS_F_CMS_ADD1_RECIPIENT, - CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE); + ERR_raise(ERR_LIB_CMS, CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE); goto err; } @@ -383,7 +380,7 @@ CMS_RecipientInfo *CMS_add1_recipient(CMS_ContentInfo *cms, X509 *recip, return ri; merr: - CMSerr(CMS_F_CMS_ADD1_RECIPIENT, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); err: M_ASN1_free_of(ri, CMS_RecipientInfo); return NULL; @@ -402,8 +399,7 @@ int CMS_RecipientInfo_ktri_get0_algs(CMS_RecipientInfo *ri, { CMS_KeyTransRecipientInfo *ktri; if (ri->type != CMS_RECIPINFO_TRANS) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_ALGS, - CMS_R_NOT_KEY_TRANSPORT); + ERR_raise(ERR_LIB_CMS, CMS_R_NOT_KEY_TRANSPORT); return 0; } @@ -425,8 +421,7 @@ int CMS_RecipientInfo_ktri_get0_signer_id(CMS_RecipientInfo *ri, { CMS_KeyTransRecipientInfo *ktri; if (ri->type != CMS_RECIPINFO_TRANS) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_SIGNER_ID, - CMS_R_NOT_KEY_TRANSPORT); + ERR_raise(ERR_LIB_CMS, CMS_R_NOT_KEY_TRANSPORT); return 0; } ktri = ri->d.ktri; @@ -437,8 +432,7 @@ int CMS_RecipientInfo_ktri_get0_signer_id(CMS_RecipientInfo *ri, int CMS_RecipientInfo_ktri_cert_cmp(CMS_RecipientInfo *ri, X509 *cert) { if (ri->type != CMS_RECIPINFO_TRANS) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_CERT_CMP, - CMS_R_NOT_KEY_TRANSPORT); + ERR_raise(ERR_LIB_CMS, CMS_R_NOT_KEY_TRANSPORT); return -2; } return cms_SignerIdentifier_cert_cmp(ri->d.ktri->rid, cert); @@ -447,7 +441,7 @@ int CMS_RecipientInfo_ktri_cert_cmp(CMS_RecipientInfo *ri, X509 *cert) int CMS_RecipientInfo_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pkey) { if (ri->type != CMS_RECIPINFO_TRANS) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_SET0_PKEY, CMS_R_NOT_KEY_TRANSPORT); + ERR_raise(ERR_LIB_CMS, CMS_R_NOT_KEY_TRANSPORT); return 0; } EVP_PKEY_free(ri->d.ktri->pkey); @@ -470,7 +464,7 @@ static int cms_RecipientInfo_ktri_encrypt(const CMS_ContentInfo *cms, int ret = 0; if (ri->type != CMS_RECIPINFO_TRANS) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_ENCRYPT, CMS_R_NOT_KEY_TRANSPORT); + ERR_raise(ERR_LIB_CMS, CMS_R_NOT_KEY_TRANSPORT); return 0; } ktri = ri->d.ktri; @@ -492,7 +486,7 @@ static int cms_RecipientInfo_ktri_encrypt(const CMS_ContentInfo *cms, if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_ENCRYPT, EVP_PKEY_CTRL_CMS_ENCRYPT, 0, ri) <= 0) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_ENCRYPT, CMS_R_CTRL_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_CTRL_ERROR); goto err; } @@ -502,7 +496,7 @@ static int cms_RecipientInfo_ktri_encrypt(const CMS_ContentInfo *cms, ek = OPENSSL_malloc(eklen); if (ek == NULL) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_ENCRYPT, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); goto err; } @@ -540,7 +534,7 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms, ec = cms_get0_env_enc_content(cms); if (ktri->pkey == NULL) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT, CMS_R_NO_PRIVATE_KEY); + ERR_raise(ERR_LIB_CMS, CMS_R_NO_PRIVATE_KEY); return 0; } @@ -558,7 +552,7 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms, cipher = EVP_get_cipherbyobj(calg->algorithm); if (cipher == NULL) { (void)ERR_clear_last_mark(); - CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT, CMS_R_UNKNOWN_CIPHER); + ERR_raise(ERR_LIB_CMS, CMS_R_UNKNOWN_CIPHER); return 0; } (void)ERR_pop_to_mark(); @@ -579,7 +573,7 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms, if (EVP_PKEY_CTX_ctrl(ktri->pctx, -1, EVP_PKEY_OP_DECRYPT, EVP_PKEY_CTRL_CMS_DECRYPT, 0, ri) <= 0) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT, CMS_R_CTRL_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_CTRL_ERROR); goto err; } @@ -590,7 +584,7 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms, ek = OPENSSL_malloc(eklen); if (ek == NULL) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); goto err; } @@ -599,7 +593,7 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms, ktri->encryptedKey->length) <= 0 || eklen == 0 || (fixlen != 0 && eklen != fixlen)) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT, CMS_R_CMS_LIB); + ERR_raise(ERR_LIB_CMS, CMS_R_CMS_LIB); goto err; } @@ -626,7 +620,7 @@ int CMS_RecipientInfo_kekri_id_cmp(CMS_RecipientInfo *ri, ASN1_OCTET_STRING tmp_os; CMS_KEKRecipientInfo *kekri; if (ri->type != CMS_RECIPINFO_KEK) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ID_CMP, CMS_R_NOT_KEK); + ERR_raise(ERR_LIB_CMS, CMS_R_NOT_KEK); return -2; } kekri = ri->d.kekri; @@ -685,7 +679,7 @@ CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid, break; default: - CMSerr(CMS_F_CMS_ADD0_RECIPIENT_KEY, CMS_R_INVALID_KEY_LENGTH); + ERR_raise(ERR_LIB_CMS, CMS_R_INVALID_KEY_LENGTH); goto err; } @@ -694,13 +688,12 @@ CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid, size_t exp_keylen = aes_wrap_keylen(nid); if (!exp_keylen) { - CMSerr(CMS_F_CMS_ADD0_RECIPIENT_KEY, - CMS_R_UNSUPPORTED_KEK_ALGORITHM); + ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_KEK_ALGORITHM); goto err; } if (keylen != exp_keylen) { - CMSerr(CMS_F_CMS_ADD0_RECIPIENT_KEY, CMS_R_INVALID_KEY_LENGTH); + ERR_raise(ERR_LIB_CMS, CMS_R_INVALID_KEY_LENGTH); goto err; } @@ -749,7 +742,7 @@ CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid, return ri; merr: - CMSerr(CMS_F_CMS_ADD0_RECIPIENT_KEY, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); err: M_ASN1_free_of(ri, CMS_RecipientInfo); return NULL; @@ -764,7 +757,7 @@ int CMS_RecipientInfo_kekri_get0_id(CMS_RecipientInfo *ri, { CMS_KEKIdentifier *rkid; if (ri->type != CMS_RECIPINFO_KEK) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_GET0_ID, CMS_R_NOT_KEK); + ERR_raise(ERR_LIB_CMS, CMS_R_NOT_KEK); return 0; } rkid = ri->d.kekri->kekid; @@ -794,7 +787,7 @@ int CMS_RecipientInfo_set0_key(CMS_RecipientInfo *ri, { CMS_KEKRecipientInfo *kekri; if (ri->type != CMS_RECIPINFO_KEK) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_SET0_KEY, CMS_R_NOT_KEK); + ERR_raise(ERR_LIB_CMS, CMS_R_NOT_KEK); return 0; } @@ -847,26 +840,26 @@ static int cms_RecipientInfo_kekri_encrypt(const CMS_ContentInfo *cms, kekri = ri->d.kekri; if (kekri->key == NULL) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT, CMS_R_NO_KEY); + ERR_raise(ERR_LIB_CMS, CMS_R_NO_KEY); return 0; } cipher = cms_get_key_wrap_cipher(kekri->keylen, cms_ctx); if (cipher == NULL) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT, CMS_R_INVALID_KEY_LENGTH); + ERR_raise(ERR_LIB_CMS, CMS_R_INVALID_KEY_LENGTH); goto err; } /* 8 byte prefix for AES wrap ciphers */ wkey = OPENSSL_malloc(ec->keylen + 8); if (wkey == NULL) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); goto err; } ctx = EVP_CIPHER_CTX_new(); if (ctx == NULL) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); goto err; } @@ -874,12 +867,12 @@ static int cms_RecipientInfo_kekri_encrypt(const CMS_ContentInfo *cms, if (!EVP_EncryptInit_ex(ctx, cipher, NULL, kekri->key, NULL) || !EVP_EncryptUpdate(ctx, wkey, &wkeylen, ec->key, ec->keylen) || !EVP_EncryptFinal_ex(ctx, wkey + wkeylen, &outlen)) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT, CMS_R_WRAP_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_WRAP_ERROR); goto err; } wkeylen += outlen; if (!ossl_assert((size_t)wkeylen == ec->keylen + 8)) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT, CMS_R_WRAP_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_WRAP_ERROR); goto err; } @@ -918,40 +911,38 @@ static int cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms, kekri = ri->d.kekri; if (!kekri->key) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT, CMS_R_NO_KEY); + ERR_raise(ERR_LIB_CMS, CMS_R_NO_KEY); return 0; } wrap_nid = OBJ_obj2nid(kekri->keyEncryptionAlgorithm->algorithm); if (aes_wrap_keylen(wrap_nid) != kekri->keylen) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT, - CMS_R_INVALID_KEY_LENGTH); + ERR_raise(ERR_LIB_CMS, CMS_R_INVALID_KEY_LENGTH); return 0; } /* If encrypted key length is invalid don't bother */ if (kekri->encryptedKey->length < 16) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT, - CMS_R_INVALID_ENCRYPTED_KEY_LENGTH); + ERR_raise(ERR_LIB_CMS, CMS_R_INVALID_ENCRYPTED_KEY_LENGTH); goto err; } cipher = cms_get_key_wrap_cipher(kekri->keylen, cms_ctx); if (cipher == NULL) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT, CMS_R_INVALID_KEY_LENGTH); + ERR_raise(ERR_LIB_CMS, CMS_R_INVALID_KEY_LENGTH); goto err; } ukey = OPENSSL_malloc(kekri->encryptedKey->length - 8); if (ukey == NULL) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); goto err; } ctx = EVP_CIPHER_CTX_new(); if (ctx == NULL) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); goto err; } @@ -960,7 +951,7 @@ static int cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms, kekri->encryptedKey->data, kekri->encryptedKey->length) || !EVP_DecryptFinal_ex(ctx, ukey + ukeylen, &outlen)) { - CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT, CMS_R_UNWRAP_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_UNWRAP_ERROR); goto err; } ukeylen += outlen; @@ -992,8 +983,7 @@ int CMS_RecipientInfo_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri) return cms_RecipientInfo_pwri_crypt(cms, ri, 0); default: - CMSerr(CMS_F_CMS_RECIPIENTINFO_DECRYPT, - CMS_R_UNSUPPORTED_RECIPIENTINFO_TYPE); + ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_RECIPIENTINFO_TYPE); return 0; } } @@ -1014,8 +1004,7 @@ int CMS_RecipientInfo_encrypt(const CMS_ContentInfo *cms, CMS_RecipientInfo *ri) return cms_RecipientInfo_pwri_crypt(cms, ri, 1); default: - CMSerr(CMS_F_CMS_RECIPIENTINFO_ENCRYPT, - CMS_R_UNSUPPORTED_RECIPIENT_TYPE); + ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_RECIPIENT_TYPE); return 0; } } @@ -1152,8 +1141,7 @@ static BIO *cms_EnvelopedData_Encryption_init_bio(CMS_ContentInfo *cms) /* Now encrypt content key according to each RecipientInfo type */ rinfos = env->recipientInfos; if (cms_env_encrypt_content_key(cms, rinfos) < 0) { - CMSerr(CMS_F_CMS_ENVELOPEDDATA_ENCRYPTION_INIT_BIO, - CMS_R_ERROR_SETTING_RECIPIENTINFO); + ERR_raise(ERR_LIB_CMS, CMS_R_ERROR_SETTING_RECIPIENTINFO); goto err; } @@ -1205,7 +1193,7 @@ BIO *cms_AuthEnvelopedData_init_bio(CMS_ContentInfo *cms) /* Now encrypt content key according to each RecipientInfo type */ rinfos = aenv->recipientInfos; if (cms_env_encrypt_content_key(cms, rinfos) < 0) { - CMSerr(0, CMS_R_ERROR_SETTING_RECIPIENTINFO); + ERR_raise(ERR_LIB_CMS, CMS_R_ERROR_SETTING_RECIPIENTINFO); goto err; } @@ -1233,7 +1221,7 @@ int cms_EnvelopedData_final(CMS_ContentInfo *cms, BIO *chain) return 0; if (mbio == NULL) { - CMSerr(CMS_F_CMS_ENVELOPEDDATA_FINAL, CMS_R_CONTENT_NOT_FOUND); + ERR_raise(ERR_LIB_CMS, CMS_R_CONTENT_NOT_FOUND); return 0; } @@ -1248,13 +1236,13 @@ int cms_EnvelopedData_final(CMS_ContentInfo *cms, BIO *chain) env->unprotectedAttrs = sk_X509_ATTRIBUTE_new_null(); if (env->unprotectedAttrs == NULL) { - CMSerr(CMS_F_CMS_ENVELOPEDDATA_FINAL, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); return 0; } if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_PROCESS_UNPROTECTED, 1, env->unprotectedAttrs) <= 0) { - CMSerr(CMS_F_CMS_ENVELOPEDDATA_FINAL, CMS_R_CTRL_FAILURE); + ERR_raise(ERR_LIB_CMS, CMS_R_CTRL_FAILURE); return 0; } } @@ -1283,7 +1271,7 @@ int cms_AuthEnvelopedData_final(CMS_ContentInfo *cms, BIO *cmsbio) || (tag = OPENSSL_malloc(taglen)) == NULL || EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, taglen, tag) <= 0) { - CMSerr(0, CMS_R_CIPHER_GET_TAG); + ERR_raise(ERR_LIB_CMS, CMS_R_CIPHER_GET_TAG); goto err; } diff --git a/crypto/cms/cms_ess.c b/crypto/cms/cms_ess.c index 287bcf86c0..ba05d4695c 100644 --- a/crypto/cms/cms_ess.c +++ b/crypto/cms/cms_ess.c @@ -99,15 +99,13 @@ int ess_check_signing_certs(CMS_SignerInfo *si, STACK_OF(X509) *chain) } } } else { - CMSerr(CMS_F_ESS_CHECK_SIGNING_CERTS, - CMS_R_ESS_NO_SIGNING_CERTID_ATTRIBUTE); + ERR_raise(ERR_LIB_CMS, CMS_R_ESS_NO_SIGNING_CERTID_ATTRIBUTE); return 0; } ret = 1; err: if (!ret) - CMSerr(CMS_F_ESS_CHECK_SIGNING_CERTS, - CMS_R_ESS_SIGNING_CERTID_MISMATCH_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_ESS_SIGNING_CERTID_MISMATCH_ERROR); ESS_SIGNING_CERT_free(ss); ESS_SIGNING_CERT_V2_free(ssv2); @@ -147,7 +145,7 @@ CMS_ReceiptRequest *CMS_ReceiptRequest_create0_ex( return rr; merr: - CMSerr(0, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); err: CMS_ReceiptRequest_free(rr); @@ -180,7 +178,7 @@ int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr) merr: if (!r) - CMSerr(CMS_F_CMS_ADD1_RECEIPTREQUEST, ERR_R_MALLOC_FAILURE); + ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); OPENSSL_free(rrder); @@ -235,12 +233,12 @@ int cms_msgSigDigest_add1(CMS_SignerInfo *dest, CMS_SignerInfo *src) unsigned int diglen; if (!cms_msgSigDigest(src, dig, &diglen)) { - CMSerr(CMS_F_CMS_MSGSIGDIGEST_ADD1, CMS_R_MSGSIGDIGEST_ERROR); + ERR_raise(ERR_LIB_CMS, CMS_R_MSGSIGDIGEST_ERROR); return 0; } if (!CMS_signed_add1_attr_by_NID(dest, NID_id_smime_aa_msgSigDigest, |