From aee4d44b17e8fc57dfaadf57efabb128712c9f72 Mon Sep 17 00:00:00 2001 From: tb <> Date: Thu, 13 Feb 2025 11:19:49 +0000 Subject: ec_mont_group_set_curve: convert to BN_MONT_CTX_create() and simplify This removes the penultimate internal call of BN_MONT_CTX_new(). The last one could be removed at the cost of introducing a BN_MONT_CTX_dup(), which probably isn't worth it. ok jsing --- src/lib/libcrypto/ec/ecp_methods.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/lib/libcrypto/ec/ecp_methods.c b/src/lib/libcrypto/ec/ecp_methods.c index ad975cb646..d1d0add538 100644 --- a/src/lib/libcrypto/ec/ecp_methods.c +++ b/src/lib/libcrypto/ec/ecp_methods.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecp_methods.c,v 1.42 2025/01/25 13:15:21 tb Exp $ */ +/* $OpenBSD: ecp_methods.c,v 1.43 2025/02/13 11:19:49 tb Exp $ */ /* Includes code written by Lenka Fibikova * for the OpenSSL project. * Includes code written by Bodo Moeller for the OpenSSL project. @@ -1217,33 +1217,20 @@ static int ec_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) { - BN_MONT_CTX *mont = NULL; - int ret = 0; - BN_MONT_CTX_free(group->mont_ctx); - group->mont_ctx = NULL; - - if ((mont = BN_MONT_CTX_new()) == NULL) + if ((group->mont_ctx = BN_MONT_CTX_create(p, ctx)) == NULL) goto err; - if (!BN_MONT_CTX_set(mont, p, ctx)) { - ECerror(ERR_R_BN_LIB); - goto err; - } - group->mont_ctx = mont; - mont = NULL; - if (!ec_group_set_curve(group, p, a, b, ctx)) { - BN_MONT_CTX_free(group->mont_ctx); - group->mont_ctx = NULL; + if (!ec_group_set_curve(group, p, a, b, ctx)) goto err; - } - ret = 1; + return 1; err: - BN_MONT_CTX_free(mont); + BN_MONT_CTX_free(group->mont_ctx); + group->mont_ctx = NULL; - return ret; + return 0; } static int -- cgit v1.2.3-55-g6feb