X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fcms%2Fcms_env.c;h=c54667f5df5007ed2e57918be4dd2b7c01f6b08d;hp=e8274beabfe3ab1b85ed78e5d6579246c1076428;hb=03273d61e742b02485831ce739e4a6c9b197e3f3;hpb=b548a1f11c06ccdfa4f52a539912d22d77ee309e diff --git a/crypto/cms/cms_env.c b/crypto/cms/cms_env.c index e8274beabf..c54667f5df 100644 --- a/crypto/cms/cms_env.c +++ b/crypto/cms/cms_env.c @@ -1,4 +1,3 @@ -/* crypto/cms/cms_env.c */ /* * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project. @@ -52,7 +51,7 @@ * ==================================================================== */ -#include "cryptlib.h" +#include "internal/cryptlib.h" #include #include #include @@ -62,16 +61,10 @@ #include #include "cms_lcl.h" #include "internal/asn1_int.h" +#include "internal/evp_int.h" /* CMS EnvelopedData Utilities */ -DECLARE_ASN1_ITEM(CMS_EnvelopedData) -DECLARE_ASN1_ITEM(CMS_KeyTransRecipientInfo) -DECLARE_ASN1_ITEM(CMS_KEKRecipientInfo) -DECLARE_ASN1_ITEM(CMS_OtherKeyAttribute) - -DECLARE_STACK_OF(CMS_RecipientInfo) - CMS_EnvelopedData *cms_get0_enveloped(CMS_ContentInfo *cms) { if (OBJ_obj2nid(cms->contentType) != NID_pkcs7_enveloped) { @@ -158,18 +151,17 @@ CMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher) CMS_ContentInfo *cms; CMS_EnvelopedData *env; cms = CMS_ContentInfo_new(); - if (!cms) + if (cms == NULL) goto merr; env = cms_enveloped_data_init(cms); - if (!env) + if (env == NULL) goto merr; if (!cms_EncryptedContent_init(env->encryptedContentInfo, cipher, NULL, 0)) goto merr; return cms; merr: - if (cms) - CMS_ContentInfo_free(cms); + CMS_ContentInfo_free(cms); CMSerr(CMS_F_CMS_ENVELOPEDDATA_CREATE, ERR_R_MALLOC_FAILURE); return NULL; } @@ -207,14 +199,15 @@ static int cms_RecipientInfo_ktri_init(CMS_RecipientInfo *ri, X509 *recip, if (!cms_set1_SignerIdentifier(ktri->rid, recip, idtype)) return 0; - CRYPTO_add(&recip->references, 1, CRYPTO_LOCK_X509); - CRYPTO_add(&pk->references, 1, CRYPTO_LOCK_EVP_PKEY); + X509_up_ref(recip); + EVP_PKEY_up_ref(pk); + ktri->pkey = pk; ktri->recip = recip; if (flags & CMS_KEY_PARAM) { ktri->pctx = EVP_PKEY_CTX_new(ktri->pkey, NULL); - if (!ktri->pctx) + if (ktri->pctx == NULL) return 0; if (EVP_PKEY_encrypt_init(ktri->pctx) <= 0) return 0; @@ -242,7 +235,7 @@ CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms, if (!ri) goto merr; - pk = X509_get_pubkey(recip); + pk = X509_get0_pubkey(recip); if (!pk) { CMSerr(CMS_F_CMS_ADD1_RECIPIENT_CERT, CMS_R_ERROR_GETTING_PUBLIC_KEY); goto err; @@ -270,15 +263,12 @@ CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms, if (!sk_CMS_RecipientInfo_push(env->recipientInfos, ri)) goto merr; - EVP_PKEY_free(pk); - return ri; merr: CMSerr(CMS_F_CMS_ADD1_RECIPIENT_CERT, ERR_R_MALLOC_FAILURE); err: M_ASN1_free_of(ri, CMS_RecipientInfo); - EVP_PKEY_free(pk); return NULL; } @@ -368,7 +358,7 @@ static int cms_RecipientInfo_ktri_encrypt(CMS_ContentInfo *cms, goto err; } else { pctx = EVP_PKEY_CTX_new(ktri->pkey, NULL); - if (!pctx) + if (pctx == NULL) return 0; if (EVP_PKEY_encrypt_init(pctx) <= 0) @@ -400,10 +390,8 @@ static int cms_RecipientInfo_ktri_encrypt(CMS_ContentInfo *cms, ret = 1; err: - if (pctx) { - EVP_PKEY_CTX_free(pctx); - ktri->pctx = NULL; - } + EVP_PKEY_CTX_free(pctx); + ktri->pctx = NULL; OPENSSL_free(ek); return ret; @@ -428,7 +416,7 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms, } ktri->pctx = EVP_PKEY_CTX_new(pkey, NULL); - if (!ktri->pctx) + if (ktri->pctx == NULL) return 0; if (EVP_PKEY_decrypt_init(ktri->pctx) <= 0) @@ -693,7 +681,7 @@ static int cms_RecipientInfo_kekri_encrypt(CMS_ContentInfo *cms, wkey = OPENSSL_malloc(ec->keylen + 8); - if (!wkey) { + if (wkey == NULL) { CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT, ERR_R_MALLOC_FAILURE); goto err; } @@ -763,7 +751,7 @@ static int cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms, ukey = OPENSSL_malloc(kekri->encryptedKey->length - 8); - if (!ukey) { + if (ukey == NULL) { CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT, ERR_R_MALLOC_FAILURE); goto err; }