From cab63c063d816f7bdfc022c940ec9842e8308429 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sat, 24 May 2025 08:25:58 +0000 Subject: Provide method specific functions for EC POINT infinity. Provide method specific functions for EC_POINT_set_to_infinity() and EC_POINT_is_at_infinity(). These are not always the same thing and will depend on the coordinate system in use. ok beck@ tb@ --- src/lib/libcrypto/ec/ec_lib.c | 11 +++-------- src/lib/libcrypto/ec/ec_local.h | 5 ++++- src/lib/libcrypto/ec/ecp_methods.c | 21 ++++++++++++++++++++- 3 files changed, 27 insertions(+), 10 deletions(-) (limited to 'src/lib/libcrypto') diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c index d760ecfb95..7cc7efe73f 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.124 2025/05/10 05:54:38 tb Exp $ */ +/* $OpenBSD: ec_lib.c,v 1.125 2025/05/24 08:25:58 jsing Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -894,11 +894,7 @@ EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point) ECerror(EC_R_INCOMPATIBLE_OBJECTS); return 0; } - - BN_zero(point->Z); - point->Z_is_one = 0; - - return 1; + return point->meth->point_set_to_infinity(group, point); } LCRYPTO_ALIAS(EC_POINT_set_to_infinity); @@ -1200,8 +1196,7 @@ EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) ECerror(EC_R_INCOMPATIBLE_OBJECTS); return 0; } - - return BN_is_zero(point->Z); + return point->meth->point_is_at_infinity(group, point); } LCRYPTO_ALIAS(EC_POINT_is_at_infinity); diff --git a/src/lib/libcrypto/ec/ec_local.h b/src/lib/libcrypto/ec/ec_local.h index c7a54d3a2b..c0ff026fb2 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.67 2025/03/24 13:07:04 jsing Exp $ */ +/* $OpenBSD: ec_local.h,v 1.68 2025/05/24 08:25:58 jsing Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -85,6 +85,9 @@ typedef struct ec_method_st { int (*group_get_curve)(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *); + int (*point_set_to_infinity)(const EC_GROUP *, EC_POINT *); + int (*point_is_at_infinity)(const EC_GROUP *, const EC_POINT *); + int (*point_is_on_curve)(const EC_GROUP *, const EC_POINT *, BN_CTX *); int (*point_cmp)(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *); diff --git a/src/lib/libcrypto/ec/ecp_methods.c b/src/lib/libcrypto/ec/ecp_methods.c index 5adc049ab7..fcb48d9e33 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.46 2025/05/10 05:54:38 tb Exp $ */ +/* $OpenBSD: ecp_methods.c,v 1.47 2025/05/24 08:25:58 jsing Exp $ */ /* Includes code written by Lenka Fibikova * for the OpenSSL project. * Includes code written by Bodo Moeller for the OpenSSL project. @@ -179,6 +179,21 @@ ec_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, return 1; } +static int +ec_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point) +{ + BN_zero(point->Z); + point->Z_is_one = 0; + + return 1; +} + +static int +ec_point_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) +{ + return BN_is_zero(point->Z); +} + static int ec_point_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx) { @@ -1281,6 +1296,8 @@ ec_mont_field_decode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, static const EC_METHOD ec_GFp_simple_method = { .group_set_curve = ec_group_set_curve, .group_get_curve = ec_group_get_curve, + .point_set_to_infinity = ec_point_set_to_infinity, + .point_is_at_infinity = ec_point_is_at_infinity, .point_is_on_curve = ec_point_is_on_curve, .point_cmp = ec_point_cmp, .point_set_affine_coordinates = ec_point_set_affine_coordinates, @@ -1304,6 +1321,8 @@ EC_GFp_simple_method(void) static const EC_METHOD ec_GFp_mont_method = { .group_set_curve = ec_mont_group_set_curve, .group_get_curve = ec_group_get_curve, + .point_set_to_infinity = ec_point_set_to_infinity, + .point_is_at_infinity = ec_point_is_at_infinity, .point_is_on_curve = ec_point_is_on_curve, .point_cmp = ec_point_cmp, .point_set_affine_coordinates = ec_point_set_affine_coordinates, -- cgit v1.2.3-55-g6feb