From 5eecd1d368f9fc54cc77a51545a9a83998afedab Mon Sep 17 00:00:00 2001 From: tb Date: Mon, 3 Jul 2023 09:25:44 +0000 Subject: [PATCH] Inline two copies of EC_GROUP_order_bits() This code is way more complicated than it needs to be. Simplify. ec_bits() was particularly stupid. ok beck jsing --- lib/libcrypto/ec/ec_ameth.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/lib/libcrypto/ec/ec_ameth.c b/lib/libcrypto/ec/ec_ameth.c index 45f51e9dd8e..8676ace9d86 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.39 2023/07/01 08:15:31 tb Exp $ */ +/* $OpenBSD: ec_ameth.c,v 1.40 2023/07/03 09:25:44 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -367,23 +367,12 @@ int_ec_size(const EVP_PKEY *pkey) static int ec_bits(const EVP_PKEY *pkey) { - BIGNUM *order = BN_new(); const EC_GROUP *group; - int ret; - if (!order) { - ERR_clear_error(); + if ((group = EC_KEY_get0_group(pkey->pkey.ec)) == NULL) return 0; - } - group = EC_KEY_get0_group(pkey->pkey.ec); - if (!EC_GROUP_get_order(group, order, NULL)) { - BN_free(order); - ERR_clear_error(); - return 0; - } - ret = BN_num_bits(order); - BN_free(order); - return ret; + + return EC_GROUP_order_bits(group); } static int @@ -442,7 +431,7 @@ do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype) const char *ecstr; size_t buf_len = 0, i; int ret = 0, reason = ERR_R_BIO_LIB; - BIGNUM *pub_key = NULL, *order = NULL; + BIGNUM *pub_key = NULL; BN_CTX *ctx = NULL; const EC_GROUP *group; const EC_POINT *public_key; @@ -492,12 +481,8 @@ do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype) if (!BIO_indent(bp, off, 128)) goto err; - if ((order = BN_new()) == NULL) - goto err; - if (!EC_GROUP_get_order(group, order, NULL)) - goto err; if (BIO_printf(bp, "%s: (%d bit)\n", ecstr, - BN_num_bits(order)) <= 0) + EC_GROUP_order_bits(group)) <= 0) goto err; if (!ASN1_bn_print(bp, "priv:", priv_key, buffer, off)) @@ -511,7 +496,6 @@ do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype) if (!ret) ECerror(reason); BN_free(pub_key); - BN_free(order); BN_CTX_free(ctx); free(buffer); return (ret); -- 2.20.1