From e568a255270032a6a88715db4e3609b6129702ed Mon Sep 17 00:00:00 2001 From: tb <> Date: Fri, 26 Dec 2025 18:44:19 +0000 Subject: Replace group->meth != point->meth checks The method will currently always be identical since all groups use the EC_GFp_mont_method(). Use the ec_group_and_point_compatible() check to ensure this and if both group and point have a nid set, check that they are identical. ok jsing kenjiro --- src/lib/libcrypto/ec/ec_convert.c | 6 +++--- src/lib/libcrypto/ec/ec_lib.c | 25 ++++++++++++++----------- src/lib/libcrypto/ec/ec_mult.c | 7 ++++--- 3 files changed, 21 insertions(+), 17 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libcrypto/ec/ec_convert.c b/src/lib/libcrypto/ec/ec_convert.c index 84641a4e72..3b88bd20ba 100644 --- a/src/lib/libcrypto/ec/ec_convert.c +++ b/src/lib/libcrypto/ec/ec_convert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_convert.c,v 1.15 2025/05/10 05:54:38 tb Exp $ */ +/* $OpenBSD: ec_convert.c,v 1.16 2025/12/26 18:44:19 tb Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -452,7 +452,7 @@ EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point, if (ctx == NULL) goto err; - if (group->meth != point->meth) { + if (!ec_group_and_point_compatible(group, point)) { ECerror(EC_R_INCOMPATIBLE_OBJECTS); goto err; } @@ -478,7 +478,7 @@ EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point, if (ctx == NULL) goto err; - if (group->meth != point->meth) { + if (!ec_group_and_point_compatible(group, point)) { ECerror(EC_R_INCOMPATIBLE_OBJECTS); goto err; } diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c index b3d3c4ca71..c140249f0e 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.128 2025/12/26 18:42:33 tb Exp $ */ +/* $OpenBSD: ec_lib.c,v 1.129 2025/12/26 18:44:19 tb Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -911,7 +911,7 @@ LCRYPTO_ALIAS(EC_POINT_dup); int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point) { - if (group->meth != point->meth) { + if (!ec_group_and_point_compatible(group, point)) { ECerror(EC_R_INCOMPATIBLE_OBJECTS); return 0; } @@ -935,7 +935,7 @@ EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point, ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); goto err; } - if (group->meth != point->meth) { + if (!ec_group_and_point_compatible(group, point)) { ECerror(EC_R_INCOMPATIBLE_OBJECTS); goto err; } @@ -986,7 +986,7 @@ EC_POINT_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *point, ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); goto err; } - if (group->meth != point->meth) { + if (!ec_group_and_point_compatible(group, point)) { ECerror(EC_R_INCOMPATIBLE_OBJECTS); goto err; } @@ -1136,8 +1136,9 @@ EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); goto err; } - if (group->meth != r->meth || group->meth != a->meth || - group->meth != b->meth) { + if (!ec_group_and_point_compatible(group, r) || + !ec_group_and_point_compatible(group, a) || + !ec_group_and_point_compatible(group, b)) { ECerror(EC_R_INCOMPATIBLE_OBJECTS); goto err; } @@ -1167,7 +1168,8 @@ EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); goto err; } - if (group->meth != r->meth || r->meth != a->meth) { + if (!ec_group_and_point_compatible(group, r) || + !ec_group_and_point_compatible(group, a)) { ECerror(EC_R_INCOMPATIBLE_OBJECTS); goto err; } @@ -1196,7 +1198,7 @@ EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx_in) ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); goto err; } - if (group->meth != a->meth) { + if (!ec_group_and_point_compatible(group, a)) { ECerror(EC_R_INCOMPATIBLE_OBJECTS); goto err; } @@ -1213,7 +1215,7 @@ LCRYPTO_ALIAS(EC_POINT_invert); int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) { - if (group->meth != point->meth) { + if (!ec_group_and_point_compatible(group, point)) { ECerror(EC_R_INCOMPATIBLE_OBJECTS); return 0; } @@ -1237,7 +1239,7 @@ EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); goto err; } - if (group->meth != point->meth) { + if (!ec_group_and_point_compatible(group, point)) { ECerror(EC_R_INCOMPATIBLE_OBJECTS); goto err; } @@ -1267,7 +1269,8 @@ EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); goto err; } - if (group->meth != a->meth || a->meth != b->meth) { + if (!ec_group_and_point_compatible(group, a) || + !ec_group_and_point_compatible(group, b)) { ECerror(EC_R_INCOMPATIBLE_OBJECTS); goto err; } diff --git a/src/lib/libcrypto/ec/ec_mult.c b/src/lib/libcrypto/ec/ec_mult.c index 8816be7501..067df9a2a2 100644 --- a/src/lib/libcrypto/ec/ec_mult.c +++ b/src/lib/libcrypto/ec/ec_mult.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_mult.c,v 1.60 2025/08/26 14:14:52 tb Exp $ */ +/* $OpenBSD: ec_mult.c,v 1.61 2025/12/26 18:44:19 tb Exp $ */ /* * Copyright (c) 2024 Theo Buehler @@ -287,8 +287,9 @@ ec_wnaf_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar1, ECerror(ERR_R_PASSED_NULL_PARAMETER); goto err; } - if (group->meth != r->meth || group->meth != point1->meth || - group->meth != point2->meth) { + if (!ec_group_and_point_compatible(group, r) || + !ec_group_and_point_compatible(group, point1) || + !ec_group_and_point_compatible(group, point2)) { ECerror(EC_R_INCOMPATIBLE_OBJECTS); goto err; } -- cgit v1.2.3-55-g6feb