From: tb Date: Thu, 28 Dec 2023 22:12:37 +0000 (+0000) Subject: Clean up pkey_ec_paramgen() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b7075e6d1687fa6ae65792ae40dc53904495fc3a;p=openbsd Clean up pkey_ec_paramgen() This is basically the same as the dh and dsa version, except it's different because it's EC. Single exit, uniform error checking. "Plug" another leak. With this I earned another shining turd for my collection. ok jsing --- diff --git a/lib/libcrypto/ec/ec_pmeth.c b/lib/libcrypto/ec/ec_pmeth.c index 0f4f00bc448..16fc07642ac 100644 --- a/lib/libcrypto/ec/ec_pmeth.c +++ b/lib/libcrypto/ec/ec_pmeth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_pmeth.c,v 1.20 2023/12/28 22:09:10 tb Exp $ */ +/* $OpenBSD: ec_pmeth.c,v 1.21 2023/12/28 22:12:37 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -458,18 +458,25 @@ pkey_ec_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) EC_KEY *ec = NULL; EC_PKEY_CTX *dctx = ctx->data; int ret = 0; + if (dctx->gen_group == NULL) { ECerror(EC_R_NO_PARAMETERS_SET); - return 0; + goto err; } - ec = EC_KEY_new(); - if (!ec) - return 0; - ret = EC_KEY_set_group(ec, dctx->gen_group); - if (ret) - EVP_PKEY_assign_EC_KEY(pkey, ec); - else - EC_KEY_free(ec); + + if ((ec = EC_KEY_new()) == NULL) + goto err; + if (!EC_KEY_set_group(ec, dctx->gen_group)) + goto err; + if (!EVP_PKEY_assign_EC_KEY(pkey, ec)) + goto err; + ec = NULL; + + ret = 1; + + err: + EC_KEY_free(ec); + return ret; }