summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ecp_methods.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/ec/ecp_methods.c')
-rw-r--r--src/lib/libcrypto/ec/ecp_methods.c61
1 files changed, 1 insertions, 60 deletions
diff --git a/src/lib/libcrypto/ec/ecp_methods.c b/src/lib/libcrypto/ec/ecp_methods.c
index 8623131ffa..9593428870 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.25 2025/01/06 18:43:27 tb Exp $ */ 1/* $OpenBSD: ecp_methods.c,v 1.26 2025/01/07 08:30:52 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.
@@ -167,63 +167,6 @@ ec_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b,
167} 167}
168 168
169static int 169static int
170ec_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)
171{
172 BIGNUM *p, *a, *b, *discriminant;
173 int ret = 0;
174
175 BN_CTX_start(ctx);
176
177 if ((p = BN_CTX_get(ctx)) == NULL)
178 goto err;
179 if ((a = BN_CTX_get(ctx)) == NULL)
180 goto err;
181 if ((b = BN_CTX_get(ctx)) == NULL)
182 goto err;
183 if ((discriminant = BN_CTX_get(ctx)) == NULL)
184 goto err;
185
186 if (!EC_GROUP_get_curve(group, p, a, b, ctx))
187 goto err;
188
189 /*
190 * Check that the discriminant 4a^3 + 27b^2 is non-zero modulo p.
191 */
192
193 if (BN_is_zero(a) && BN_is_zero(b))
194 goto err;
195 if (BN_is_zero(a) || BN_is_zero(b))
196 goto done;
197
198 /* Compute the discriminant: first 4a^3, then 27b^2, then their sum. */
199 if (!BN_mod_sqr(discriminant, a, p, ctx))
200 goto err;
201 if (!BN_mod_mul(discriminant, discriminant, a, p, ctx))
202 goto err;
203 if (!BN_lshift(discriminant, discriminant, 2))
204 goto err;
205
206 if (!BN_mod_sqr(b, b, p, ctx))
207 goto err;
208 if (!BN_mul_word(b, 27))
209 goto err;
210
211 if (!BN_mod_add(discriminant, discriminant, b, p, ctx))
212 goto err;
213
214 if (BN_is_zero(discriminant))
215 goto err;
216
217 done:
218 ret = 1;
219
220 err:
221 BN_CTX_end(ctx);
222
223 return ret;
224}
225
226static int
227ec_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point, 170ec_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point,
228 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx) 171 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
229{ 172{
@@ -1511,7 +1454,6 @@ static const EC_METHOD ec_GFp_simple_method = {
1511 .field_type = NID_X9_62_prime_field, 1454 .field_type = NID_X9_62_prime_field,
1512 .group_set_curve = ec_group_set_curve, 1455 .group_set_curve = ec_group_set_curve,
1513 .group_get_curve = ec_group_get_curve, 1456 .group_get_curve = ec_group_get_curve,
1514 .group_check_discriminant = ec_group_check_discriminant,
1515 .point_set_affine_coordinates = ec_point_set_affine_coordinates, 1457 .point_set_affine_coordinates = ec_point_set_affine_coordinates,
1516 .point_get_affine_coordinates = ec_point_get_affine_coordinates, 1458 .point_get_affine_coordinates = ec_point_get_affine_coordinates,
1517 .point_set_compressed_coordinates = ec_set_compressed_coordinates, 1459 .point_set_compressed_coordinates = ec_set_compressed_coordinates,
@@ -1540,7 +1482,6 @@ static const EC_METHOD ec_GFp_mont_method = {
1540 .field_type = NID_X9_62_prime_field, 1482 .field_type = NID_X9_62_prime_field,
1541 .group_set_curve = ec_mont_group_set_curve, 1483 .group_set_curve = ec_mont_group_set_curve,
1542 .group_get_curve = ec_group_get_curve, 1484 .group_get_curve = ec_group_get_curve,
1543 .group_check_discriminant = ec_group_check_discriminant,
1544 .point_set_affine_coordinates = ec_point_set_affine_coordinates, 1485 .point_set_affine_coordinates = ec_point_set_affine_coordinates,
1545 .point_get_affine_coordinates = ec_point_get_affine_coordinates, 1486 .point_get_affine_coordinates = ec_point_get_affine_coordinates,
1546 .point_set_compressed_coordinates = ec_set_compressed_coordinates, 1487 .point_set_compressed_coordinates = ec_set_compressed_coordinates,