summaryrefslogtreecommitdiff
path: root/lib/libcrypto/ec
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2024-04-17 13:51:42 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2024-04-17 13:51:42 +0000
commit551385f6ce4e97a84b23b2a715301e183b9b2f8a (patch)
treee15c2e4d84e3b8132f3f45d38db888a46ec8ca92 /lib/libcrypto/ec
parent670a09d5328ab3ea0e977979ad01d1f415ef60c4 (diff)
ecdh_cms_encrypt: simplify handling of pkey
The pkey is only used in one scope. i2o allocates if passed a pointer to NULL, so use that to drop two unnecessary local variables. ok jsing
Diffstat (limited to 'lib/libcrypto/ec')
-rw-r--r--lib/libcrypto/ec/ec_ameth.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/lib/libcrypto/ec/ec_ameth.c b/lib/libcrypto/ec/ec_ameth.c
index 1c2b6be87ca..78580024e00 100644
--- a/lib/libcrypto/ec/ec_ameth.c
+++ b/lib/libcrypto/ec/ec_ameth.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ec_ameth.c,v 1.56 2024/04/17 13:50:01 tb Exp $ */
+/* $OpenBSD: ec_ameth.c,v 1.57 2024/04/17 13:51:41 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
@@ -912,7 +912,6 @@ static int
ecdh_cms_encrypt(CMS_RecipientInfo *ri)
{
EVP_PKEY_CTX *pctx;
- EVP_PKEY *pkey;
EVP_CIPHER_CTX *ctx;
int keylen;
X509_ALGOR *talg, *wrap_alg = NULL;
@@ -928,8 +927,6 @@ ecdh_cms_encrypt(CMS_RecipientInfo *ri)
if ((pctx = CMS_RecipientInfo_get0_pkey_ctx(ri)) == NULL)
goto err;
- /* Get ephemeral key */
- pkey = EVP_PKEY_CTX_get0_pkey(pctx);
if (!CMS_RecipientInfo_kari_get0_orig_id(ri, &talg, &pubkey,
NULL, NULL, NULL))
goto err;
@@ -937,19 +934,13 @@ ecdh_cms_encrypt(CMS_RecipientInfo *ri)
/* Is everything uninitialised? */
if (aoid == OBJ_nid2obj(NID_undef)) {
- EC_KEY *eckey = pkey->pkey.ec;
- unsigned char *p;
+ EVP_PKEY *pkey;
- /* Set the key */
- penclen = i2o_ECPublicKey(eckey, NULL);
- if (penclen <= 0)
+ if ((pkey = EVP_PKEY_CTX_get0_pkey(pctx)) == NULL)
goto err;
- penc = malloc(penclen);
- if (penc == NULL)
- goto err;
- p = penc;
- penclen = i2o_ECPublicKey(eckey, &p);
- if (penclen <= 0)
+
+ penc = NULL;
+ if ((penclen = i2o_ECPublicKey(pkey->pkey.ec, &penc)) <= 0)
goto err;
ASN1_STRING_set0(pubkey, penc, penclen);