summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2025-01-11 13:58:31 +0000
committertb <>2025-01-11 13:58:31 +0000
commit9c5cffbcbf9cbe48fd4c1ced980da5a0201c9550 (patch)
tree460f3b16a854d1bc55ed31d9d7db53ad50353aa0
parent5ea88094167c5741d321839ce7cb0186a8a7028f (diff)
downloadopenbsd-9c5cffbcbf9cbe48fd4c1ced980da5a0201c9550.tar.gz
openbsd-9c5cffbcbf9cbe48fd4c1ced980da5a0201c9550.tar.bz2
openbsd-9c5cffbcbf9cbe48fd4c1ced980da5a0201c9550.zip
Neuter the EC_POINTs_* API
EC_POINTs_mul() was only ever used by Ruby and they stopped doing so for LibreSSL when we incorporated the constant time multiplication work of Brumley et al and restricted the length of the points array to 1, making this API effectively useless. The only real reason you want to have an API to calculate \sum n_i P_i is for ECDSA where you want m * G + n * P. Whether something like his needs to be in the public API is doubtful. EC_POINTs_make_affine() is an implementation detail of EC_POINTs_mul(). As such it never really belonged into the public API. ok jsing
-rw-r--r--src/lib/libcrypto/ec/ec_lib.c66
-rw-r--r--src/lib/libcrypto/ec/ec_local.h15
-rw-r--r--src/lib/libcrypto/ec/ec_mult.c4
-rw-r--r--src/lib/libcrypto/ec/ecp_methods.c8
4 files changed, 16 insertions, 77 deletions
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c
index de6fe20083..f1ff11a087 100644
--- a/src/lib/libcrypto/ec/ec_lib.c
+++ b/src/lib/libcrypto/ec/ec_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_lib.c,v 1.107 2025/01/11 13:41:17 tb Exp $ */ 1/* $OpenBSD: ec_lib.c,v 1.108 2025/01/11 13:58:31 tb Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller for the OpenSSL project. 3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */ 4 */
@@ -1265,32 +1265,8 @@ int
1265EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], 1265EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[],
1266 BN_CTX *ctx_in) 1266 BN_CTX *ctx_in)
1267{ 1267{
1268 BN_CTX *ctx; 1268 ECerror(ERR_R_DISABLED);
1269 size_t i; 1269 return 0;
1270 int ret = 0;
1271
1272 if ((ctx = ctx_in) == NULL)
1273 ctx = BN_CTX_new();
1274 if (ctx == NULL)
1275 goto err;
1276
1277 if (group->meth->points_make_affine == NULL) {
1278 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1279 goto err;
1280 }
1281 for (i = 0; i < num; i++) {
1282 if (group->meth != points[i]->meth) {
1283 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
1284 goto err;
1285 }
1286 }
1287 ret = group->meth->points_make_affine(group, num, points, ctx);
1288
1289 err:
1290 if (ctx != ctx_in)
1291 BN_CTX_free(ctx);
1292
1293 return ret;
1294} 1270}
1295LCRYPTO_ALIAS(EC_POINTs_make_affine); 1271LCRYPTO_ALIAS(EC_POINTs_make_affine);
1296 1272
@@ -1299,40 +1275,8 @@ EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
1299 size_t num, const EC_POINT *points[], const BIGNUM *scalars[], 1275 size_t num, const EC_POINT *points[], const BIGNUM *scalars[],
1300 BN_CTX *ctx_in) 1276 BN_CTX *ctx_in)
1301{ 1277{
1302 BN_CTX *ctx; 1278 ECerror(ERR_R_DISABLED);
1303 int ret = 0; 1279 return 0;
1304
1305 if ((ctx = ctx_in) == NULL)
1306 ctx = BN_CTX_new();
1307 if (ctx == NULL)
1308 goto err;
1309
1310 /* Only num == 0 and num == 1 is supported. */
1311 if (group->meth->mul_generator_ct == NULL ||
1312 group->meth->mul_single_ct == NULL ||
1313 group->meth->mul_double_nonct == NULL ||
1314 num > 1) {
1315 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1316 goto err;
1317 }
1318
1319 if (num == 1 && points != NULL && scalars != NULL) {
1320 /* Either bP or aG + bP, this is sane. */
1321 ret = EC_POINT_mul(group, r, scalar, points[0], scalars[0], ctx);
1322 } else if (scalar != NULL && points == NULL && scalars == NULL) {
1323 /* aG, this is sane */
1324 ret = EC_POINT_mul(group, r, scalar, NULL, NULL, ctx);
1325 } else {
1326 /* anything else is an error */
1327 ECerror(ERR_R_EC_LIB);
1328 goto err;
1329 }
1330
1331 err:
1332 if (ctx != ctx_in)
1333 BN_CTX_free(ctx);
1334
1335 return ret;
1336} 1280}
1337LCRYPTO_ALIAS(EC_POINTs_mul); 1281LCRYPTO_ALIAS(EC_POINTs_mul);
1338 1282
diff --git a/src/lib/libcrypto/ec/ec_local.h b/src/lib/libcrypto/ec/ec_local.h
index 7cb5c55f6d..0e81ab2b12 100644
--- a/src/lib/libcrypto/ec/ec_local.h
+++ b/src/lib/libcrypto/ec/ec_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_local.h,v 1.55 2025/01/11 13:38:42 tb Exp $ */ 1/* $OpenBSD: ec_local.h,v 1.56 2025/01/11 13:58:31 tb Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller for the OpenSSL project. 3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */ 4 */
@@ -79,12 +79,6 @@
79 79
80__BEGIN_HIDDEN_DECLS 80__BEGIN_HIDDEN_DECLS
81 81
82#if defined(__SUNPRO_C)
83# if __SUNPRO_C >= 0x520
84# pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
85# endif
86#endif
87
88struct ec_method_st { 82struct ec_method_st {
89 int field_type; 83 int field_type;
90 84
@@ -100,6 +94,10 @@ struct ec_method_st {
100 int (*point_set_compressed_coordinates)(const EC_GROUP *, EC_POINT *, 94 int (*point_set_compressed_coordinates)(const EC_GROUP *, EC_POINT *,
101 const BIGNUM *x, int y_bit, BN_CTX *); 95 const BIGNUM *x, int y_bit, BN_CTX *);
102 96
97 /* Only used by the wNAF code. */
98 int (*points_make_affine)(const EC_GROUP *, size_t num, EC_POINT **,
99 BN_CTX *);
100
103 int (*add)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, 101 int (*add)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a,
104 const EC_POINT *b, BN_CTX *); 102 const EC_POINT *b, BN_CTX *);
105 int (*dbl)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *); 103 int (*dbl)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
@@ -109,9 +107,6 @@ struct ec_method_st {
109 int (*point_cmp)(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, 107 int (*point_cmp)(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b,
110 BN_CTX *); 108 BN_CTX *);
111 109
112 int (*points_make_affine)(const EC_GROUP *, size_t num, EC_POINT *[],
113 BN_CTX *);
114
115 int (*mul_generator_ct)(const EC_GROUP *, EC_POINT *r, 110 int (*mul_generator_ct)(const EC_GROUP *, EC_POINT *r,
116 const BIGNUM *scalar, BN_CTX *); 111 const BIGNUM *scalar, BN_CTX *);
117 int (*mul_single_ct)(const EC_GROUP *group, EC_POINT *r, 112 int (*mul_single_ct)(const EC_GROUP *group, EC_POINT *r,
diff --git a/src/lib/libcrypto/ec/ec_mult.c b/src/lib/libcrypto/ec/ec_mult.c
index d11086de64..68061ffd67 100644
--- a/src/lib/libcrypto/ec/ec_mult.c
+++ b/src/lib/libcrypto/ec/ec_mult.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_mult.c,v 1.56 2024/12/19 21:05:46 tb Exp $ */ 1/* $OpenBSD: ec_mult.c,v 1.57 2025/01/11 13:58:31 tb Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller and Nils Larsch for the OpenSSL project. 3 * Originally written by Bodo Moeller and Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -219,7 +219,7 @@ ec_normalize_points(const EC_GROUP *group, struct ec_wnaf *wnaf0,
219 memcpy(&val[0], points0, sizeof(*val) * len0); 219 memcpy(&val[0], points0, sizeof(*val) * len0);
220 memcpy(&val[len0], points1, sizeof(*val) * len1); 220 memcpy(&val[len0], points1, sizeof(*val) * len1);
221 221
222 if (!EC_POINTs_make_affine(group, len, val, ctx)) 222 if (!group->meth->points_make_affine(group, len, val, ctx))
223 goto err; 223 goto err;
224 224
225 ret = 1; 225 ret = 1;
diff --git a/src/lib/libcrypto/ec/ecp_methods.c b/src/lib/libcrypto/ec/ecp_methods.c
index a2a74334f4..d1895c959f 100644
--- a/src/lib/libcrypto/ec/ecp_methods.c
+++ b/src/lib/libcrypto/ec/ecp_methods.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_methods.c,v 1.27 2025/01/11 13:38:42 tb Exp $ */ 1/* $OpenBSD: ecp_methods.c,v 1.28 2025/01/11 13:58:31 tb Exp $ */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> 2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. 3 * for the OpenSSL project.
4 * Includes code written by Bodo Moeller for the OpenSSL project. 4 * Includes code written by Bodo Moeller for the OpenSSL project.
@@ -892,7 +892,7 @@ ec_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
892} 892}
893 893
894static int 894static int
895ec_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], 895ec_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT **points,
896 BN_CTX *ctx) 896 BN_CTX *ctx)
897{ 897{
898 BIGNUM **prod_Z = NULL; 898 BIGNUM **prod_Z = NULL;
@@ -1425,12 +1425,12 @@ static const EC_METHOD ec_GFp_simple_method = {
1425 .point_set_affine_coordinates = ec_point_set_affine_coordinates, 1425 .point_set_affine_coordinates = ec_point_set_affine_coordinates,
1426 .point_get_affine_coordinates = ec_point_get_affine_coordinates, 1426 .point_get_affine_coordinates = ec_point_get_affine_coordinates,
1427 .point_set_compressed_coordinates = ec_set_compressed_coordinates, 1427 .point_set_compressed_coordinates = ec_set_compressed_coordinates,
1428 .points_make_affine = ec_points_make_affine,
1428 .add = ec_add, 1429 .add = ec_add,
1429 .dbl = ec_dbl, 1430 .dbl = ec_dbl,
1430 .invert = ec_invert, 1431 .invert = ec_invert,
1431 .is_on_curve = ec_is_on_curve, 1432 .is_on_curve = ec_is_on_curve,
1432 .point_cmp = ec_cmp, 1433 .point_cmp = ec_cmp,
1433 .points_make_affine = ec_points_make_affine,
1434 .mul_generator_ct = ec_mul_generator_ct, 1434 .mul_generator_ct = ec_mul_generator_ct,
1435 .mul_single_ct = ec_mul_single_ct, 1435 .mul_single_ct = ec_mul_single_ct,
1436 .mul_double_nonct = ec_mul_double_nonct, 1436 .mul_double_nonct = ec_mul_double_nonct,
@@ -1452,12 +1452,12 @@ static const EC_METHOD ec_GFp_mont_method = {
1452 .point_set_affine_coordinates = ec_point_set_affine_coordinates, 1452 .point_set_affine_coordinates = ec_point_set_affine_coordinates,
1453 .point_get_affine_coordinates = ec_point_get_affine_coordinates, 1453 .point_get_affine_coordinates = ec_point_get_affine_coordinates,
1454 .point_set_compressed_coordinates = ec_set_compressed_coordinates, 1454 .point_set_compressed_coordinates = ec_set_compressed_coordinates,
1455 .points_make_affine = ec_points_make_affine,
1455 .add = ec_add, 1456 .add = ec_add,
1456 .dbl = ec_dbl, 1457 .dbl = ec_dbl,
1457 .invert = ec_invert, 1458 .invert = ec_invert,
1458 .is_on_curve = ec_is_on_curve, 1459 .is_on_curve = ec_is_on_curve,
1459 .point_cmp = ec_cmp, 1460 .point_cmp = ec_cmp,
1460 .points_make_affine = ec_points_make_affine,
1461 .mul_generator_ct = ec_mul_generator_ct, 1461 .mul_generator_ct = ec_mul_generator_ct,
1462 .mul_single_ct = ec_mul_single_ct, 1462 .mul_single_ct = ec_mul_single_ct,
1463 .mul_double_nonct = ec_mul_double_nonct, 1463 .mul_double_nonct = ec_mul_double_nonct,