diff options
| author | tb <> | 2024-11-12 10:57:56 +0000 |
|---|---|---|
| committer | tb <> | 2024-11-12 10:57:56 +0000 |
| commit | c5b3dbdfa0e9f0a87d8889531971dddf653b6f5f (patch) | |
| tree | 8387c003637f0b179a4ea258bdff20a6d5c3c910 /src/lib/libcrypto/ec/ecp_methods.c | |
| parent | b3e4524c8e3edbf9d20ca74196ff1dec1489065a (diff) | |
| download | openbsd-c5b3dbdfa0e9f0a87d8889531971dddf653b6f5f.tar.gz openbsd-c5b3dbdfa0e9f0a87d8889531971dddf653b6f5f.tar.bz2 openbsd-c5b3dbdfa0e9f0a87d8889531971dddf653b6f5f.zip | |
Lose the ugly GFp_simple_ and GFp_mont_ infixes
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/ec/ecp_methods.c | 244 |
1 files changed, 117 insertions, 127 deletions
diff --git a/src/lib/libcrypto/ec/ecp_methods.c b/src/lib/libcrypto/ec/ecp_methods.c index 6770ef839b..6431551c8c 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.4 2024/11/12 10:53:22 tb Exp $ */ | 1 | /* $OpenBSD: ecp_methods.c,v 1.5 2024/11/12 10:57:56 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. |
| @@ -80,14 +80,14 @@ | |||
| 80 | * multiplication, and field_encode and field_decode (if defined) | 80 | * multiplication, and field_encode and field_decode (if defined) |
| 81 | * will be used for converting between representations. | 81 | * will be used for converting between representations. |
| 82 | * | 82 | * |
| 83 | * Functions ec_GFp_simple_points_make_affine() and | 83 | * Functions ec_points_make_affine() and |
| 84 | * ec_GFp_simple_point_get_affine_coordinates() specifically assume | 84 | * ec_point_get_affine_coordinates() specifically assume |
| 85 | * that if a non-trivial representation is used, it is a Montgomery | 85 | * that if a non-trivial representation is used, it is a Montgomery |
| 86 | * representation (i.e. 'encoding' means multiplying by some factor R). | 86 | * representation (i.e. 'encoding' means multiplying by some factor R). |
| 87 | */ | 87 | */ |
| 88 | 88 | ||
| 89 | static int | 89 | static int |
| 90 | ec_GFp_simple_group_init(EC_GROUP *group) | 90 | ec_group_init(EC_GROUP *group) |
| 91 | { | 91 | { |
| 92 | BN_init(&group->field); | 92 | BN_init(&group->field); |
| 93 | BN_init(&group->a); | 93 | BN_init(&group->a); |
| @@ -97,7 +97,7 @@ ec_GFp_simple_group_init(EC_GROUP *group) | |||
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | static void | 99 | static void |
| 100 | ec_GFp_simple_group_finish(EC_GROUP *group) | 100 | ec_group_finish(EC_GROUP *group) |
| 101 | { | 101 | { |
| 102 | BN_free(&group->field); | 102 | BN_free(&group->field); |
| 103 | BN_free(&group->a); | 103 | BN_free(&group->a); |
| @@ -105,7 +105,7 @@ ec_GFp_simple_group_finish(EC_GROUP *group) | |||
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | static int | 107 | static int |
| 108 | ec_GFp_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src) | 108 | ec_group_copy(EC_GROUP *dest, const EC_GROUP *src) |
| 109 | { | 109 | { |
| 110 | if (!bn_copy(&dest->field, &src->field)) | 110 | if (!bn_copy(&dest->field, &src->field)) |
| 111 | return 0; | 111 | return 0; |
| @@ -161,7 +161,7 @@ ec_encode_z_coordinate(const EC_GROUP *group, BIGNUM *bn, int *is_one, | |||
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | static int | 163 | static int |
| 164 | ec_GFp_simple_group_set_curve(EC_GROUP *group, | 164 | ec_group_set_curve(EC_GROUP *group, |
| 165 | const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) | 165 | const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) |
| 166 | { | 166 | { |
| 167 | BIGNUM *a_plus_3; | 167 | BIGNUM *a_plus_3; |
| @@ -203,7 +203,7 @@ ec_GFp_simple_group_set_curve(EC_GROUP *group, | |||
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | static int | 205 | static int |
| 206 | ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, | 206 | ec_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, |
| 207 | BIGNUM *b, BN_CTX *ctx) | 207 | BIGNUM *b, BN_CTX *ctx) |
| 208 | { | 208 | { |
| 209 | if (p != NULL) { | 209 | if (p != NULL) { |
| @@ -219,13 +219,13 @@ ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, | |||
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | static int | 221 | static int |
| 222 | ec_GFp_simple_group_get_degree(const EC_GROUP *group) | 222 | ec_group_get_degree(const EC_GROUP *group) |
| 223 | { | 223 | { |
| 224 | return BN_num_bits(&group->field); | 224 | return BN_num_bits(&group->field); |
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | static int | 227 | static int |
| 228 | ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) | 228 | ec_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) |
| 229 | { | 229 | { |
| 230 | BIGNUM *p, *a, *b, *discriminant; | 230 | BIGNUM *p, *a, *b, *discriminant; |
| 231 | int ret = 0; | 231 | int ret = 0; |
| @@ -282,7 +282,7 @@ ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) | |||
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | static int | 284 | static int |
| 285 | ec_GFp_simple_point_init(EC_POINT * point) | 285 | ec_point_init(EC_POINT * point) |
| 286 | { | 286 | { |
| 287 | BN_init(&point->X); | 287 | BN_init(&point->X); |
| 288 | BN_init(&point->Y); | 288 | BN_init(&point->Y); |
| @@ -293,7 +293,7 @@ ec_GFp_simple_point_init(EC_POINT * point) | |||
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | static void | 295 | static void |
| 296 | ec_GFp_simple_point_finish(EC_POINT *point) | 296 | ec_point_finish(EC_POINT *point) |
| 297 | { | 297 | { |
| 298 | BN_free(&point->X); | 298 | BN_free(&point->X); |
| 299 | BN_free(&point->Y); | 299 | BN_free(&point->Y); |
| @@ -302,7 +302,7 @@ ec_GFp_simple_point_finish(EC_POINT *point) | |||
| 302 | } | 302 | } |
| 303 | 303 | ||
| 304 | static int | 304 | static int |
| 305 | ec_GFp_simple_point_copy(EC_POINT *dest, const EC_POINT *src) | 305 | ec_point_copy(EC_POINT *dest, const EC_POINT *src) |
| 306 | { | 306 | { |
| 307 | if (!bn_copy(&dest->X, &src->X)) | 307 | if (!bn_copy(&dest->X, &src->X)) |
| 308 | return 0; | 308 | return 0; |
| @@ -316,7 +316,7 @@ ec_GFp_simple_point_copy(EC_POINT *dest, const EC_POINT *src) | |||
| 316 | } | 316 | } |
| 317 | 317 | ||
| 318 | static int | 318 | static int |
| 319 | ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point) | 319 | ec_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point) |
| 320 | { | 320 | { |
| 321 | point->Z_is_one = 0; | 321 | point->Z_is_one = 0; |
| 322 | BN_zero(&point->Z); | 322 | BN_zero(&point->Z); |
| @@ -324,7 +324,7 @@ ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point) | |||
| 324 | } | 324 | } |
| 325 | 325 | ||
| 326 | static int | 326 | static int |
| 327 | ec_GFp_simple_set_Jprojective_coordinates(const EC_GROUP *group, | 327 | ec_set_Jprojective_coordinates(const EC_GROUP *group, |
| 328 | EC_POINT *point, const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, | 328 | EC_POINT *point, const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, |
| 329 | BN_CTX *ctx) | 329 | BN_CTX *ctx) |
| 330 | { | 330 | { |
| @@ -356,7 +356,7 @@ ec_GFp_simple_set_Jprojective_coordinates(const EC_GROUP *group, | |||
| 356 | } | 356 | } |
| 357 | 357 | ||
| 358 | static int | 358 | static int |
| 359 | ec_GFp_simple_get_Jprojective_coordinates(const EC_GROUP *group, | 359 | ec_get_Jprojective_coordinates(const EC_GROUP *group, |
| 360 | const EC_POINT *point, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx) | 360 | const EC_POINT *point, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx) |
| 361 | { | 361 | { |
| 362 | int ret = 0; | 362 | int ret = 0; |
| @@ -375,7 +375,7 @@ ec_GFp_simple_get_Jprojective_coordinates(const EC_GROUP *group, | |||
| 375 | } | 375 | } |
| 376 | 376 | ||
| 377 | static int | 377 | static int |
| 378 | ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point, | 378 | ec_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point, |
| 379 | const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx) | 379 | const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx) |
| 380 | { | 380 | { |
| 381 | if (x == NULL || y == NULL) { | 381 | if (x == NULL || y == NULL) { |
| @@ -388,7 +388,7 @@ ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *poin | |||
| 388 | } | 388 | } |
| 389 | 389 | ||
| 390 | static int | 390 | static int |
| 391 | ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group, | 391 | ec_point_get_affine_coordinates(const EC_GROUP *group, |
| 392 | const EC_POINT *point, BIGNUM *x, BIGNUM *y, BN_CTX *ctx) | 392 | const EC_POINT *point, BIGNUM *x, BIGNUM *y, BN_CTX *ctx) |
| 393 | { | 393 | { |
| 394 | BIGNUM *z, *Z, *Z_1, *Z_2, *Z_3; | 394 | BIGNUM *z, *Z, *Z_1, *Z_2, *Z_3; |
| @@ -469,7 +469,7 @@ ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group, | |||
| 469 | } | 469 | } |
| 470 | 470 | ||
| 471 | static int | 471 | static int |
| 472 | ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group, | 472 | ec_set_compressed_coordinates(const EC_GROUP *group, |
| 473 | EC_POINT *point, const BIGNUM *in_x, int y_bit, BN_CTX *ctx) | 473 | EC_POINT *point, const BIGNUM *in_x, int y_bit, BN_CTX *ctx) |
| 474 | { | 474 | { |
| 475 | const BIGNUM *p = &group->field, *a = &group->a, *b = &group->b; | 475 | const BIGNUM *p = &group->field, *a = &group->a, *b = &group->b; |
| @@ -567,7 +567,7 @@ ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group, | |||
| 567 | } | 567 | } |
| 568 | 568 | ||
| 569 | static int | 569 | static int |
| 570 | ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx) | 570 | ec_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx) |
| 571 | { | 571 | { |
| 572 | int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); | 572 | int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); |
| 573 | int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *); | 573 | int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *); |
| @@ -749,7 +749,7 @@ ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const E | |||
| 749 | } | 749 | } |
| 750 | 750 | ||
| 751 | static int | 751 | static int |
| 752 | ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx) | 752 | ec_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx) |
| 753 | { | 753 | { |
| 754 | int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); | 754 | int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); |
| 755 | int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *); | 755 | int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *); |
| @@ -883,7 +883,7 @@ ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX | |||
| 883 | } | 883 | } |
| 884 | 884 | ||
| 885 | static int | 885 | static int |
| 886 | ec_GFp_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) | 886 | ec_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) |
| 887 | { | 887 | { |
| 888 | if (EC_POINT_is_at_infinity(group, point) || BN_is_zero(&point->Y)) | 888 | if (EC_POINT_is_at_infinity(group, point) || BN_is_zero(&point->Y)) |
| 889 | /* point is its own inverse */ | 889 | /* point is its own inverse */ |
| @@ -893,13 +893,13 @@ ec_GFp_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) | |||
| 893 | } | 893 | } |
| 894 | 894 | ||
| 895 | static int | 895 | static int |
| 896 | ec_GFp_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) | 896 | ec_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) |
| 897 | { | 897 | { |
| 898 | return BN_is_zero(&point->Z); | 898 | return BN_is_zero(&point->Z); |
| 899 | } | 899 | } |
| 900 | 900 | ||
| 901 | static int | 901 | static int |
| 902 | ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx) | 902 | ec_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx) |
| 903 | { | 903 | { |
| 904 | int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); | 904 | int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); |
| 905 | int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *); | 905 | int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *); |
| @@ -996,7 +996,7 @@ ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX * | |||
| 996 | } | 996 | } |
| 997 | 997 | ||
| 998 | static int | 998 | static int |
| 999 | ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx) | 999 | ec_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx) |
| 1000 | { | 1000 | { |
| 1001 | /* | 1001 | /* |
| 1002 | * return values: -1 error 0 equal (in affine coordinates) 1 | 1002 | * return values: -1 error 0 equal (in affine coordinates) 1 |
| @@ -1092,7 +1092,7 @@ ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, B | |||
| 1092 | } | 1092 | } |
| 1093 | 1093 | ||
| 1094 | static int | 1094 | static int |
| 1095 | ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) | 1095 | ec_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) |
| 1096 | { | 1096 | { |
| 1097 | BIGNUM *x, *y; | 1097 | BIGNUM *x, *y; |
| 1098 | int ret = 0; | 1098 | int ret = 0; |
| @@ -1124,7 +1124,7 @@ ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) | |||
| 1124 | } | 1124 | } |
| 1125 | 1125 | ||
| 1126 | static int | 1126 | static int |
| 1127 | ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx) | 1127 | ec_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx) |
| 1128 | { | 1128 | { |
| 1129 | BIGNUM *tmp0, *tmp1; | 1129 | BIGNUM *tmp0, *tmp1; |
| 1130 | size_t pow2 = 0; | 1130 | size_t pow2 = 0; |
| @@ -1293,13 +1293,13 @@ ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *po | |||
| 1293 | } | 1293 | } |
| 1294 | 1294 | ||
| 1295 | static int | 1295 | static int |
| 1296 | ec_GFp_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) | 1296 | ec_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) |
| 1297 | { | 1297 | { |
| 1298 | return BN_mod_mul(r, a, b, &group->field, ctx); | 1298 | return BN_mod_mul(r, a, b, &group->field, ctx); |
| 1299 | } | 1299 | } |
| 1300 | 1300 | ||
| 1301 | static int | 1301 | static int |
| 1302 | ec_GFp_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx) | 1302 | ec_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx) |
| 1303 | { | 1303 | { |
| 1304 | return BN_mod_sqr(r, a, &group->field, ctx); | 1304 | return BN_mod_sqr(r, a, &group->field, ctx); |
| 1305 | } | 1305 | } |
| @@ -1312,7 +1312,7 @@ ec_GFp_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CT | |||
| 1312 | * where lambda is in the interval [1, group->field). | 1312 | * where lambda is in the interval [1, group->field). |
| 1313 | */ | 1313 | */ |
| 1314 | static int | 1314 | static int |
| 1315 | ec_GFp_simple_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx) | 1315 | ec_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx) |
| 1316 | { | 1316 | { |
| 1317 | BIGNUM *lambda = NULL; | 1317 | BIGNUM *lambda = NULL; |
| 1318 | BIGNUM *tmp = NULL; | 1318 | BIGNUM *tmp = NULL; |
| @@ -1400,7 +1400,7 @@ ec_GFp_simple_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx) | |||
| 1400 | * Returns 1 on success, 0 otherwise. | 1400 | * Returns 1 on success, 0 otherwise. |
| 1401 | */ | 1401 | */ |
| 1402 | static int | 1402 | static int |
| 1403 | ec_GFp_simple_mul_ct(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, | 1403 | ec_mul_ct(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, |
| 1404 | const EC_POINT *point, BN_CTX *ctx) | 1404 | const EC_POINT *point, BN_CTX *ctx) |
| 1405 | { | 1405 | { |
| 1406 | int i, cardinality_bits, group_top, kbit, pbit, Z_is_one; | 1406 | int i, cardinality_bits, group_top, kbit, pbit, Z_is_one; |
| @@ -1587,21 +1587,21 @@ ec_GFp_simple_mul_ct(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, | |||
| 1587 | #undef EC_POINT_CSWAP | 1587 | #undef EC_POINT_CSWAP |
| 1588 | 1588 | ||
| 1589 | static int | 1589 | static int |
| 1590 | ec_GFp_simple_mul_generator_ct(const EC_GROUP *group, EC_POINT *r, | 1590 | ec_mul_generator_ct(const EC_GROUP *group, EC_POINT *r, |
| 1591 | const BIGNUM *scalar, BN_CTX *ctx) | 1591 | const BIGNUM *scalar, BN_CTX *ctx) |
| 1592 | { | 1592 | { |
| 1593 | return ec_GFp_simple_mul_ct(group, r, scalar, NULL, ctx); | 1593 | return ec_mul_ct(group, r, scalar, NULL, ctx); |
| 1594 | } | 1594 | } |
| 1595 | 1595 | ||
| 1596 | static int | 1596 | static int |
| 1597 | ec_GFp_simple_mul_single_ct(const EC_GROUP *group, EC_POINT *r, | 1597 | ec_mul_single_ct(const EC_GROUP *group, EC_POINT *r, |
| 1598 | const BIGNUM *scalar, const EC_POINT *point, BN_CTX *ctx) | 1598 | const BIGNUM *scalar, const EC_POINT *point, BN_CTX *ctx) |
| 1599 | { | 1599 | { |
| 1600 | return ec_GFp_simple_mul_ct(group, r, scalar, point, ctx); | 1600 | return ec_mul_ct(group, r, scalar, point, ctx); |
| 1601 | } | 1601 | } |
| 1602 | 1602 | ||
| 1603 | static int | 1603 | static int |
| 1604 | ec_GFp_simple_mul_double_nonct(const EC_GROUP *group, EC_POINT *r, | 1604 | ec_mul_double_nonct(const EC_GROUP *group, EC_POINT *r, |
| 1605 | const BIGNUM *g_scalar, const BIGNUM *p_scalar, const EC_POINT *point, | 1605 | const BIGNUM *g_scalar, const BIGNUM *p_scalar, const EC_POINT *point, |
| 1606 | BN_CTX *ctx) | 1606 | BN_CTX *ctx) |
| 1607 | { | 1607 | { |
| @@ -1609,7 +1609,7 @@ ec_GFp_simple_mul_double_nonct(const EC_GROUP *group, EC_POINT *r, | |||
| 1609 | } | 1609 | } |
| 1610 | 1610 | ||
| 1611 | static void | 1611 | static void |
| 1612 | ec_GFp_mont_group_clear(EC_GROUP *group) | 1612 | ec_mont_group_clear(EC_GROUP *group) |
| 1613 | { | 1613 | { |
| 1614 | BN_MONT_CTX_free(group->mont_ctx); | 1614 | BN_MONT_CTX_free(group->mont_ctx); |
| 1615 | group->mont_ctx = NULL; | 1615 | group->mont_ctx = NULL; |
| @@ -1619,29 +1619,29 @@ ec_GFp_mont_group_clear(EC_GROUP *group) | |||
| 1619 | } | 1619 | } |
| 1620 | 1620 | ||
| 1621 | static int | 1621 | static int |
| 1622 | ec_GFp_mont_group_init(EC_GROUP *group) | 1622 | ec_mont_group_init(EC_GROUP *group) |
| 1623 | { | 1623 | { |
| 1624 | int ok; | 1624 | int ok; |
| 1625 | 1625 | ||
| 1626 | ok = ec_GFp_simple_group_init(group); | 1626 | ok = ec_group_init(group); |
| 1627 | group->mont_ctx = NULL; | 1627 | group->mont_ctx = NULL; |
| 1628 | group->mont_one = NULL; | 1628 | group->mont_one = NULL; |
| 1629 | return ok; | 1629 | return ok; |
| 1630 | } | 1630 | } |
| 1631 | 1631 | ||
| 1632 | static void | 1632 | static void |
| 1633 | ec_GFp_mont_group_finish(EC_GROUP *group) | 1633 | ec_mont_group_finish(EC_GROUP *group) |
| 1634 | { | 1634 | { |
| 1635 | ec_GFp_mont_group_clear(group); | 1635 | ec_mont_group_clear(group); |
| 1636 | ec_GFp_simple_group_finish(group); | 1636 | ec_group_finish(group); |
| 1637 | } | 1637 | } |
| 1638 | 1638 | ||
| 1639 | static int | 1639 | static int |
| 1640 | ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src) | 1640 | ec_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src) |
| 1641 | { | 1641 | { |
| 1642 | ec_GFp_mont_group_clear(dest); | 1642 | ec_mont_group_clear(dest); |
| 1643 | 1643 | ||
| 1644 | if (!ec_GFp_simple_group_copy(dest, src)) | 1644 | if (!ec_group_copy(dest, src)) |
| 1645 | return 0; | 1645 | return 0; |
| 1646 | 1646 | ||
| 1647 | if (src->mont_ctx != NULL) { | 1647 | if (src->mont_ctx != NULL) { |
| @@ -1667,14 +1667,14 @@ ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src) | |||
| 1667 | } | 1667 | } |
| 1668 | 1668 | ||
| 1669 | static int | 1669 | static int |
| 1670 | ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, | 1670 | ec_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, |
| 1671 | const BIGNUM *b, BN_CTX *ctx) | 1671 | const BIGNUM *b, BN_CTX *ctx) |
| 1672 | { | 1672 | { |
| 1673 | BN_MONT_CTX *mont = NULL; | 1673 | BN_MONT_CTX *mont = NULL; |
| 1674 | BIGNUM *one = NULL; | 1674 | BIGNUM *one = NULL; |
| 1675 | int ret = 0; | 1675 | int ret = 0; |
| 1676 | 1676 | ||
| 1677 | ec_GFp_mont_group_clear(group); | 1677 | ec_mont_group_clear(group); |
| 1678 | 1678 | ||
| 1679 | mont = BN_MONT_CTX_new(); | 1679 | mont = BN_MONT_CTX_new(); |
| 1680 | if (mont == NULL) | 1680 | if (mont == NULL) |
| @@ -1694,9 +1694,9 @@ ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, | |||
| 1694 | group->mont_one = one; | 1694 | group->mont_one = one; |
| 1695 | one = NULL; | 1695 | one = NULL; |
| 1696 | 1696 | ||
| 1697 | ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx); | 1697 | ret = ec_group_set_curve(group, p, a, b, ctx); |
| 1698 | if (!ret) | 1698 | if (!ret) |
| 1699 | ec_GFp_mont_group_clear(group); | 1699 | ec_mont_group_clear(group); |
| 1700 | 1700 | ||
| 1701 | err: | 1701 | err: |
| 1702 | BN_MONT_CTX_free(mont); | 1702 | BN_MONT_CTX_free(mont); |
| @@ -1706,7 +1706,7 @@ ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, | |||
| 1706 | } | 1706 | } |
| 1707 | 1707 | ||
| 1708 | static int | 1708 | static int |
| 1709 | ec_GFp_mont_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | 1709 | ec_mont_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, |
| 1710 | const BIGNUM *b, BN_CTX *ctx) | 1710 | const BIGNUM *b, BN_CTX *ctx) |
| 1711 | { | 1711 | { |
| 1712 | if (group->mont_ctx == NULL) { | 1712 | if (group->mont_ctx == NULL) { |
| @@ -1717,7 +1717,7 @@ ec_GFp_mont_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | |||
| 1717 | } | 1717 | } |
| 1718 | 1718 | ||
| 1719 | static int | 1719 | static int |
| 1720 | ec_GFp_mont_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | 1720 | ec_mont_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, |
| 1721 | BN_CTX *ctx) | 1721 | BN_CTX *ctx) |
| 1722 | { | 1722 | { |
| 1723 | if (group->mont_ctx == NULL) { | 1723 | if (group->mont_ctx == NULL) { |
| @@ -1728,7 +1728,7 @@ ec_GFp_mont_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | |||
| 1728 | } | 1728 | } |
| 1729 | 1729 | ||
| 1730 | static int | 1730 | static int |
| 1731 | ec_GFp_mont_field_encode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | 1731 | ec_mont_field_encode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, |
| 1732 | BN_CTX *ctx) | 1732 | BN_CTX *ctx) |
| 1733 | { | 1733 | { |
| 1734 | if (group->mont_ctx == NULL) { | 1734 | if (group->mont_ctx == NULL) { |
| @@ -1739,7 +1739,7 @@ ec_GFp_mont_field_encode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | |||
| 1739 | } | 1739 | } |
| 1740 | 1740 | ||
| 1741 | static int | 1741 | static int |
| 1742 | ec_GFp_mont_field_decode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | 1742 | ec_mont_field_decode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, |
| 1743 | BN_CTX *ctx) | 1743 | BN_CTX *ctx) |
| 1744 | { | 1744 | { |
| 1745 | if (group->mont_ctx == NULL) { | 1745 | if (group->mont_ctx == NULL) { |
| @@ -1750,7 +1750,7 @@ ec_GFp_mont_field_decode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | |||
| 1750 | } | 1750 | } |
| 1751 | 1751 | ||
| 1752 | static int | 1752 | static int |
| 1753 | ec_GFp_mont_field_set_to_one(const EC_GROUP *group, BIGNUM *r, BN_CTX *ctx) | 1753 | ec_mont_field_set_to_one(const EC_GROUP *group, BIGNUM *r, BN_CTX *ctx) |
| 1754 | { | 1754 | { |
| 1755 | if (group->mont_one == NULL) { | 1755 | if (group->mont_one == NULL) { |
| 1756 | ECerror(EC_R_NOT_INITIALIZED); | 1756 | ECerror(EC_R_NOT_INITIALIZED); |
| @@ -1764,42 +1764,37 @@ ec_GFp_mont_field_set_to_one(const EC_GROUP *group, BIGNUM *r, BN_CTX *ctx) | |||
| 1764 | 1764 | ||
| 1765 | static const EC_METHOD ec_GFp_simple_method = { | 1765 | static const EC_METHOD ec_GFp_simple_method = { |
| 1766 | .field_type = NID_X9_62_prime_field, | 1766 | .field_type = NID_X9_62_prime_field, |
| 1767 | .group_init = ec_GFp_simple_group_init, | 1767 | .group_init = ec_group_init, |
| 1768 | .group_finish = ec_GFp_simple_group_finish, | 1768 | .group_finish = ec_group_finish, |
| 1769 | .group_copy = ec_GFp_simple_group_copy, | 1769 | .group_copy = ec_group_copy, |
| 1770 | .group_set_curve = ec_GFp_simple_group_set_curve, | 1770 | .group_set_curve = ec_group_set_curve, |
| 1771 | .group_get_curve = ec_GFp_simple_group_get_curve, | 1771 | .group_get_curve = ec_group_get_curve, |
| 1772 | .group_get_degree = ec_GFp_simple_group_get_degree, | 1772 | .group_get_degree = ec_group_get_degree, |
| 1773 | .group_order_bits = ec_group_simple_order_bits, | 1773 | .group_order_bits = ec_group_simple_order_bits, |
| 1774 | .group_check_discriminant = ec_GFp_simple_group_check_discriminant, | 1774 | .group_check_discriminant = ec_group_check_discriminant, |
| 1775 | .point_init = ec_GFp_simple_point_init, | 1775 | .point_init = ec_point_init, |
| 1776 | .point_finish = ec_GFp_simple_point_finish, | 1776 | .point_finish = ec_point_finish, |
| 1777 | .point_copy = ec_GFp_simple_point_copy, | 1777 | .point_copy = ec_point_copy, |
| 1778 | .point_set_to_infinity = ec_GFp_simple_point_set_to_infinity, | 1778 | .point_set_to_infinity = ec_point_set_to_infinity, |
| 1779 | .point_set_Jprojective_coordinates = | 1779 | .point_set_Jprojective_coordinates = ec_set_Jprojective_coordinates, |
| 1780 | ec_GFp_simple_set_Jprojective_coordinates, | 1780 | .point_get_Jprojective_coordinates = ec_get_Jprojective_coordinates, |
| 1781 | .point_get_Jprojective_coordinates = | 1781 | .point_set_affine_coordinates = ec_point_set_affine_coordinates, |
| 1782 | ec_GFp_simple_get_Jprojective_coordinates, | 1782 | .point_get_affine_coordinates = ec_point_get_affine_coordinates, |
| 1783 | .point_set_affine_coordinates = | 1783 | .point_set_compressed_coordinates = ec_set_compressed_coordinates, |
| 1784 | ec_GFp_simple_point_set_affine_coordinates, | 1784 | .add = ec_add, |
| 1785 | .point_get_affine_coordinates = | 1785 | .dbl = ec_dbl, |
| 1786 | ec_GFp_simple_point_get_affine_coordinates, | 1786 | .invert = ec_invert, |
| 1787 | .point_set_compressed_coordinates = | 1787 | .is_at_infinity = ec_is_at_infinity, |
| 1788 | ec_GFp_simple_set_compressed_coordinates, | 1788 | .is_on_curve = ec_is_on_curve, |
| 1789 | .add = ec_GFp_simple_add, | 1789 | .point_cmp = ec_cmp, |
| 1790 | .dbl = ec_GFp_simple_dbl, | 1790 | .make_affine = ec_make_affine, |
| 1791 | .invert = ec_GFp_simple_invert, | 1791 | .points_make_affine = ec_points_make_affine, |
| 1792 | .is_at_infinity = ec_GFp_simple_is_at_infinity, | 1792 | .mul_generator_ct = ec_mul_generator_ct, |
| 1793 | .is_on_curve = ec_GFp_simple_is_on_curve, | 1793 | .mul_single_ct = ec_mul_single_ct, |
| 1794 | .point_cmp = ec_GFp_simple_cmp, | 1794 | .mul_double_nonct = ec_mul_double_nonct, |
| 1795 | .make_affine = ec_GFp_simple_make_affine, | 1795 | .field_mul = ec_field_mul, |
| 1796 | .points_make_affine = ec_GFp_simple_points_make_affine, | 1796 | .field_sqr = ec_field_sqr, |
| 1797 | .mul_generator_ct = ec_GFp_simple_mul_generator_ct, | 1797 | .blind_coordinates = ec_blind_coordinates, |
| 1798 | .mul_single_ct = ec_GFp_simple_mul_single_ct, | ||
| 1799 | .mul_double_nonct = ec_GFp_simple_mul_double_nonct, | ||
| 1800 | .field_mul = ec_GFp_simple_field_mul, | ||
| 1801 | .field_sqr = ec_GFp_simple_field_sqr, | ||
| 1802 | .blind_coordinates = ec_GFp_simple_blind_coordinates, | ||
| 1803 | }; | 1798 | }; |
| 1804 | 1799 | ||
| 1805 | const EC_METHOD * | 1800 | const EC_METHOD * |
| @@ -1811,45 +1806,40 @@ LCRYPTO_ALIAS(EC_GFp_simple_method); | |||
| 1811 | 1806 | ||
| 1812 | static const EC_METHOD ec_GFp_mont_method = { | 1807 | static const EC_METHOD ec_GFp_mont_method = { |
| 1813 | .field_type = NID_X9_62_prime_field, | 1808 | .field_type = NID_X9_62_prime_field, |
| 1814 | .group_init = ec_GFp_mont_group_init, | 1809 | .group_init = ec_mont_group_init, |
| 1815 | .group_finish = ec_GFp_mont_group_finish, | 1810 | .group_finish = ec_mont_group_finish, |
| 1816 | .group_copy = ec_GFp_mont_group_copy, | 1811 | .group_copy = ec_mont_group_copy, |
| 1817 | .group_set_curve = ec_GFp_mont_group_set_curve, | 1812 | .group_set_curve = ec_mont_group_set_curve, |
| 1818 | .group_get_curve = ec_GFp_simple_group_get_curve, | 1813 | .group_get_curve = ec_group_get_curve, |
| 1819 | .group_get_degree = ec_GFp_simple_group_get_degree, | 1814 | .group_get_degree = ec_group_get_degree, |
| 1820 | .group_order_bits = ec_group_simple_order_bits, | 1815 | .group_order_bits = ec_group_simple_order_bits, |
| 1821 | .group_check_discriminant = ec_GFp_simple_group_check_discriminant, | 1816 | .group_check_discriminant = ec_group_check_discriminant, |
| 1822 | .point_init = ec_GFp_simple_point_init, | 1817 | .point_init = ec_point_init, |
| 1823 | .point_finish = ec_GFp_simple_point_finish, | 1818 | .point_finish = ec_point_finish, |
| 1824 | .point_copy = ec_GFp_simple_point_copy, | 1819 | .point_copy = ec_point_copy, |
| 1825 | .point_set_to_infinity = ec_GFp_simple_point_set_to_infinity, | 1820 | .point_set_to_infinity = ec_point_set_to_infinity, |
| 1826 | .point_set_Jprojective_coordinates = | 1821 | .point_set_Jprojective_coordinates = ec_set_Jprojective_coordinates, |
| 1827 | ec_GFp_simple_set_Jprojective_coordinates, | 1822 | .point_get_Jprojective_coordinates = ec_get_Jprojective_coordinates, |
| 1828 | .point_get_Jprojective_coordinates = | 1823 | .point_set_affine_coordinates = ec_point_set_affine_coordinates, |
| 1829 | ec_GFp_simple_get_Jprojective_coordinates, | 1824 | .point_get_affine_coordinates = ec_point_get_affine_coordinates, |
| 1830 | .point_set_affine_coordinates = | 1825 | .point_set_compressed_coordinates = ec_set_compressed_coordinates, |
| 1831 | ec_GFp_simple_point_set_affine_coordinates, | 1826 | .add = ec_add, |
| 1832 | .point_get_affine_coordinates = | 1827 | .dbl = ec_dbl, |
| 1833 | ec_GFp_simple_point_get_affine_coordinates, | 1828 | .invert = ec_invert, |
| 1834 | .point_set_compressed_coordinates = | 1829 | .is_at_infinity = ec_is_at_infinity, |
| 1835 | ec_GFp_simple_set_compressed_coordinates, | 1830 | .is_on_curve = ec_is_on_curve, |
| 1836 | .add = ec_GFp_simple_add, | 1831 | .point_cmp = ec_cmp, |
| 1837 | .dbl = ec_GFp_simple_dbl, | 1832 | .make_affine = ec_make_affine, |
| 1838 | .invert = ec_GFp_simple_invert, | 1833 | .points_make_affine = ec_points_make_affine, |
| 1839 | .is_at_infinity = ec_GFp_simple_is_at_infinity, | 1834 | .mul_generator_ct = ec_mul_generator_ct, |
| 1840 | .is_on_curve = ec_GFp_simple_is_on_curve, | 1835 | .mul_single_ct = ec_mul_single_ct, |
| 1841 | .point_cmp = ec_GFp_simple_cmp, | 1836 | .mul_double_nonct = ec_mul_double_nonct, |
| 1842 | .make_affine = ec_GFp_simple_make_affine, | 1837 | .field_mul = ec_mont_field_mul, |
| 1843 | .points_make_affine = ec_GFp_simple_points_make_affine, | 1838 | .field_sqr = ec_mont_field_sqr, |
| 1844 | .mul_generator_ct = ec_GFp_simple_mul_generator_ct, | 1839 | .field_encode = ec_mont_field_encode, |
| 1845 | .mul_single_ct = ec_GFp_simple_mul_single_ct, | 1840 | .field_decode = ec_mont_field_decode, |
| 1846 | .mul_double_nonct = ec_GFp_simple_mul_double_nonct, | 1841 | .field_set_to_one = ec_mont_field_set_to_one, |
| 1847 | .field_mul = ec_GFp_mont_field_mul, | 1842 | .blind_coordinates = ec_blind_coordinates, |
| 1848 | .field_sqr = ec_GFp_mont_field_sqr, | ||
| 1849 | .field_encode = ec_GFp_mont_field_encode, | ||
| 1850 | .field_decode = ec_GFp_mont_field_decode, | ||
| 1851 | .field_set_to_one = ec_GFp_mont_field_set_to_one, | ||
| 1852 | .blind_coordinates = ec_GFp_simple_blind_coordinates, | ||
| 1853 | }; | 1843 | }; |
| 1854 | 1844 | ||
| 1855 | const EC_METHOD * | 1845 | const EC_METHOD * |
