From e66ace5866e5cf640f90e9158ea3245cf5c846e4 Mon Sep 17 00:00:00 2001 From: tb <> Date: Wed, 1 Jan 2025 10:01:31 +0000 Subject: Garbage collect .group_finish() There is only one caller, EC_GROUP_free(), so inline the relevant free calls there and dispose of a few layers of indirection. ok jsing --- src/lib/libcrypto/ec/ec_lib.c | 10 +++++++--- src/lib/libcrypto/ec/ec_local.h | 3 +-- src/lib/libcrypto/ec/ecp_methods.c | 19 +------------------ 3 files changed, 9 insertions(+), 23 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c index aeb627dfba..89d26e1177 100644 --- a/src/lib/libcrypto/ec/ec_lib.c +++ b/src/lib/libcrypto/ec/ec_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_lib.c,v 1.92 2025/01/01 09:57:02 tb Exp $ */ +/* $OpenBSD: ec_lib.c,v 1.93 2025/01/01 10:01:31 tb Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -109,8 +109,12 @@ EC_GROUP_free(EC_GROUP *group) if (group == NULL) return; - if (group->meth->group_finish != NULL) - group->meth->group_finish(group); + BN_free(&group->p); + BN_free(&group->a); + BN_free(&group->b); + + BN_MONT_CTX_free(group->mont_ctx); + BN_free(group->mont_one); EC_POINT_free(group->generator); BN_free(&group->order); diff --git a/src/lib/libcrypto/ec/ec_local.h b/src/lib/libcrypto/ec/ec_local.h index bce3f31d4d..cc918b38fd 100644 --- a/src/lib/libcrypto/ec/ec_local.h +++ b/src/lib/libcrypto/ec/ec_local.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_local.h,v 1.44 2025/01/01 09:57:02 tb Exp $ */ +/* $OpenBSD: ec_local.h,v 1.45 2025/01/01 10:01:31 tb Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -88,7 +88,6 @@ __BEGIN_HIDDEN_DECLS struct ec_method_st { int field_type; - void (*group_finish)(EC_GROUP *); int (*group_copy)(EC_GROUP *, const EC_GROUP *); int (*group_set_curve)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, diff --git a/src/lib/libcrypto/ec/ecp_methods.c b/src/lib/libcrypto/ec/ecp_methods.c index 333922d351..af19addab4 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.16 2025/01/01 09:57:02 tb Exp $ */ +/* $OpenBSD: ecp_methods.c,v 1.17 2025/01/01 10:01:31 tb Exp $ */ /* Includes code written by Lenka Fibikova * for the OpenSSL project. * Includes code written by Bodo Moeller for the OpenSSL project. @@ -84,14 +84,6 @@ * representation (i.e. 'encoding' means multiplying by some factor R). */ -static void -ec_group_finish(EC_GROUP *group) -{ - BN_free(&group->p); - BN_free(&group->a); - BN_free(&group->b); -} - static int ec_group_copy(EC_GROUP *dest, const EC_GROUP *src) { @@ -1526,13 +1518,6 @@ ec_mont_group_clear(EC_GROUP *group) group->mont_one = NULL; } -static void -ec_mont_group_finish(EC_GROUP *group) -{ - ec_mont_group_clear(group); - ec_group_finish(group); -} - static int ec_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src) { @@ -1661,7 +1646,6 @@ ec_mont_field_set_to_one(const EC_GROUP *group, BIGNUM *r, BN_CTX *ctx) static const EC_METHOD ec_GFp_simple_method = { .field_type = NID_X9_62_prime_field, - .group_finish = ec_group_finish, .group_copy = ec_group_copy, .group_set_curve = ec_group_set_curve, .group_get_curve = ec_group_get_curve, @@ -1697,7 +1681,6 @@ LCRYPTO_ALIAS(EC_GFp_simple_method); static const EC_METHOD ec_GFp_mont_method = { .field_type = NID_X9_62_prime_field, - .group_finish = ec_mont_group_finish, .group_copy = ec_mont_group_copy, .group_set_curve = ec_mont_group_set_curve, .group_get_curve = ec_group_get_curve, -- cgit v1.2.3-55-g6feb