From 28b0d0a86ff16d35928ff812a03e9ae9abb97ac1 Mon Sep 17 00:00:00 2001 From: tb <> Date: Sat, 11 Jan 2025 13:38:42 +0000 Subject: Inline ec_point_make_affine() in the public API Whatever the EC_METHOD, this will always be equivalent to getting and setting the affine coordinates, so this needs no dedicated method. Also, this is a function that makes no real sense since a caller should never need to care about this... As always, our favorite language bindings thought they might have users who care. This time it's Ruby and Perl. ok jsing --- src/lib/libcrypto/ec/ec_lib.c | 27 ++++++++++++++++++++------- src/lib/libcrypto/ec/ec_local.h | 3 +-- src/lib/libcrypto/ec/ecp_methods.c | 36 +----------------------------------- 3 files changed, 22 insertions(+), 44 deletions(-) diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c index d7f0bc6358..c2a5545c30 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.105 2025/01/09 11:35:46 tb Exp $ */ +/* $OpenBSD: ec_lib.c,v 1.106 2025/01/11 13:38:42 tb Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -1229,6 +1229,7 @@ int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx_in) { BN_CTX *ctx; + BIGNUM *x, *y; int ret = 0; if ((ctx = ctx_in) == NULL) @@ -1236,17 +1237,29 @@ EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx_in) if (ctx == NULL) goto err; - if (group->meth->make_affine == NULL) { - ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); + BN_CTX_start(ctx); + + if ((x = BN_CTX_get(ctx)) == NULL) goto err; - } - if (group->meth != point->meth) { - ECerror(EC_R_INCOMPATIBLE_OBJECTS); + if ((y = BN_CTX_get(ctx)) == NULL) + goto err; + + if (!EC_POINT_get_affine_coordinates(group, point, x, y, ctx)) + goto err; + if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx)) + goto err; + + /* XXX - is this the right spot for this check? */ + if (!point->Z_is_one) { + ECerror(ERR_R_INTERNAL_ERROR); goto err; } - ret = group->meth->make_affine(group, point, ctx); + + ret = 1; err: + BN_CTX_end(ctx); + if (ctx != ctx_in) BN_CTX_free(ctx); diff --git a/src/lib/libcrypto/ec/ec_local.h b/src/lib/libcrypto/ec/ec_local.h index 5949908991..7cb5c55f6d 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.54 2025/01/07 08:52:17 tb Exp $ */ +/* $OpenBSD: ec_local.h,v 1.55 2025/01/11 13:38:42 tb Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -109,7 +109,6 @@ struct ec_method_st { int (*point_cmp)(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *); - int (*make_affine)(const EC_GROUP *, EC_POINT *, BN_CTX *); int (*points_make_affine)(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *); diff --git a/src/lib/libcrypto/ec/ecp_methods.c b/src/lib/libcrypto/ec/ecp_methods.c index 9593428870..a2a74334f4 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.26 2025/01/07 08:30:52 tb Exp $ */ +/* $OpenBSD: ecp_methods.c,v 1.27 2025/01/11 13:38:42 tb Exp $ */ /* Includes code written by Lenka Fibikova * for the OpenSSL project. * Includes code written by Bodo Moeller for the OpenSSL project. @@ -891,38 +891,6 @@ ec_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx) return ret; } -static int -ec_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) -{ - BIGNUM *x, *y; - int ret = 0; - - if (point->Z_is_one || EC_POINT_is_at_infinity(group, point)) - return 1; - - BN_CTX_start(ctx); - - if ((x = BN_CTX_get(ctx)) == NULL) - goto err; - if ((y = BN_CTX_get(ctx)) == NULL) - goto err; - - if (!EC_POINT_get_affine_coordinates(group, point, x, y, ctx)) - goto err; - if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx)) - goto err; - if (!point->Z_is_one) { - ECerror(ERR_R_INTERNAL_ERROR); - goto err; - } - ret = 1; - - err: - BN_CTX_end(ctx); - - return ret; -} - static int ec_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx) @@ -1462,7 +1430,6 @@ static const EC_METHOD ec_GFp_simple_method = { .invert = ec_invert, .is_on_curve = ec_is_on_curve, .point_cmp = ec_cmp, - .make_affine = ec_make_affine, .points_make_affine = ec_points_make_affine, .mul_generator_ct = ec_mul_generator_ct, .mul_single_ct = ec_mul_single_ct, @@ -1490,7 +1457,6 @@ static const EC_METHOD ec_GFp_mont_method = { .invert = ec_invert, .is_on_curve = ec_is_on_curve, .point_cmp = ec_cmp, - .make_affine = ec_make_affine, .points_make_affine = ec_points_make_affine, .mul_generator_ct = ec_mul_generator_ct, .mul_single_ct = ec_mul_single_ct, -- cgit v1.2.3-55-g6feb