diff options
Diffstat (limited to 'src/lib/libcrypto/ec/ec2_smpl.c')
-rw-r--r-- | src/lib/libcrypto/ec/ec2_smpl.c | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/src/lib/libcrypto/ec/ec2_smpl.c b/src/lib/libcrypto/ec/ec2_smpl.c index 9f3b380bfe..17664d0426 100644 --- a/src/lib/libcrypto/ec/ec2_smpl.c +++ b/src/lib/libcrypto/ec/ec2_smpl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec2_smpl.c,v 1.23 2021/09/08 17:29:21 tb Exp $ */ | 1 | /* $OpenBSD: ec2_smpl.c,v 1.24 2022/11/19 07:00:57 tb Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
4 | * | 4 | * |
@@ -126,7 +126,7 @@ EC_GF2m_simple_method(void) | |||
126 | /* Initialize a GF(2^m)-based EC_GROUP structure. | 126 | /* Initialize a GF(2^m)-based EC_GROUP structure. |
127 | * Note that all other members are handled by EC_GROUP_new. | 127 | * Note that all other members are handled by EC_GROUP_new. |
128 | */ | 128 | */ |
129 | int | 129 | int |
130 | ec_GF2m_simple_group_init(EC_GROUP * group) | 130 | ec_GF2m_simple_group_init(EC_GROUP * group) |
131 | { | 131 | { |
132 | BN_init(&group->field); | 132 | BN_init(&group->field); |
@@ -139,7 +139,7 @@ ec_GF2m_simple_group_init(EC_GROUP * group) | |||
139 | /* Free a GF(2^m)-based EC_GROUP structure. | 139 | /* Free a GF(2^m)-based EC_GROUP structure. |
140 | * Note that all other members are handled by EC_GROUP_free. | 140 | * Note that all other members are handled by EC_GROUP_free. |
141 | */ | 141 | */ |
142 | void | 142 | void |
143 | ec_GF2m_simple_group_finish(EC_GROUP * group) | 143 | ec_GF2m_simple_group_finish(EC_GROUP * group) |
144 | { | 144 | { |
145 | BN_free(&group->field); | 145 | BN_free(&group->field); |
@@ -151,7 +151,7 @@ ec_GF2m_simple_group_finish(EC_GROUP * group) | |||
151 | /* Clear and free a GF(2^m)-based EC_GROUP structure. | 151 | /* Clear and free a GF(2^m)-based EC_GROUP structure. |
152 | * Note that all other members are handled by EC_GROUP_clear_free. | 152 | * Note that all other members are handled by EC_GROUP_clear_free. |
153 | */ | 153 | */ |
154 | void | 154 | void |
155 | ec_GF2m_simple_group_clear_finish(EC_GROUP * group) | 155 | ec_GF2m_simple_group_clear_finish(EC_GROUP * group) |
156 | { | 156 | { |
157 | BN_clear_free(&group->field); | 157 | BN_clear_free(&group->field); |
@@ -169,7 +169,7 @@ ec_GF2m_simple_group_clear_finish(EC_GROUP * group) | |||
169 | /* Copy a GF(2^m)-based EC_GROUP structure. | 169 | /* Copy a GF(2^m)-based EC_GROUP structure. |
170 | * Note that all other members are handled by EC_GROUP_copy. | 170 | * Note that all other members are handled by EC_GROUP_copy. |
171 | */ | 171 | */ |
172 | int | 172 | int |
173 | ec_GF2m_simple_group_copy(EC_GROUP * dest, const EC_GROUP * src) | 173 | ec_GF2m_simple_group_copy(EC_GROUP * dest, const EC_GROUP * src) |
174 | { | 174 | { |
175 | int i; | 175 | int i; |
@@ -199,7 +199,7 @@ ec_GF2m_simple_group_copy(EC_GROUP * dest, const EC_GROUP * src) | |||
199 | 199 | ||
200 | 200 | ||
201 | /* Set the curve parameters of an EC_GROUP structure. */ | 201 | /* Set the curve parameters of an EC_GROUP structure. */ |
202 | int | 202 | int |
203 | ec_GF2m_simple_group_set_curve(EC_GROUP * group, | 203 | ec_GF2m_simple_group_set_curve(EC_GROUP * group, |
204 | const BIGNUM * p, const BIGNUM * a, const BIGNUM * b, BN_CTX * ctx) | 204 | const BIGNUM * p, const BIGNUM * a, const BIGNUM * b, BN_CTX * ctx) |
205 | { | 205 | { |
@@ -238,7 +238,7 @@ ec_GF2m_simple_group_set_curve(EC_GROUP * group, | |||
238 | /* Get the curve parameters of an EC_GROUP structure. | 238 | /* Get the curve parameters of an EC_GROUP structure. |
239 | * If p, a, or b are NULL then there values will not be set but the method will return with success. | 239 | * If p, a, or b are NULL then there values will not be set but the method will return with success. |
240 | */ | 240 | */ |
241 | int | 241 | int |
242 | ec_GF2m_simple_group_get_curve(const EC_GROUP *group, | 242 | ec_GF2m_simple_group_get_curve(const EC_GROUP *group, |
243 | BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) | 243 | BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) |
244 | { | 244 | { |
@@ -264,7 +264,7 @@ ec_GF2m_simple_group_get_curve(const EC_GROUP *group, | |||
264 | 264 | ||
265 | 265 | ||
266 | /* Gets the degree of the field. For a curve over GF(2^m) this is the value m. */ | 266 | /* Gets the degree of the field. For a curve over GF(2^m) this is the value m. */ |
267 | int | 267 | int |
268 | ec_GF2m_simple_group_get_degree(const EC_GROUP * group) | 268 | ec_GF2m_simple_group_get_degree(const EC_GROUP * group) |
269 | { | 269 | { |
270 | return BN_num_bits(&group->field) - 1; | 270 | return BN_num_bits(&group->field) - 1; |
@@ -274,7 +274,7 @@ ec_GF2m_simple_group_get_degree(const EC_GROUP * group) | |||
274 | /* Checks the discriminant of the curve. | 274 | /* Checks the discriminant of the curve. |
275 | * y^2 + x*y = x^3 + a*x^2 + b is an elliptic curve <=> b != 0 (mod p) | 275 | * y^2 + x*y = x^3 + a*x^2 + b is an elliptic curve <=> b != 0 (mod p) |
276 | */ | 276 | */ |
277 | int | 277 | int |
278 | ec_GF2m_simple_group_check_discriminant(const EC_GROUP * group, BN_CTX * ctx) | 278 | ec_GF2m_simple_group_check_discriminant(const EC_GROUP * group, BN_CTX * ctx) |
279 | { | 279 | { |
280 | int ret = 0; | 280 | int ret = 0; |
@@ -313,7 +313,7 @@ ec_GF2m_simple_group_check_discriminant(const EC_GROUP * group, BN_CTX * ctx) | |||
313 | 313 | ||
314 | 314 | ||
315 | /* Initializes an EC_POINT. */ | 315 | /* Initializes an EC_POINT. */ |
316 | int | 316 | int |
317 | ec_GF2m_simple_point_init(EC_POINT * point) | 317 | ec_GF2m_simple_point_init(EC_POINT * point) |
318 | { | 318 | { |
319 | BN_init(&point->X); | 319 | BN_init(&point->X); |
@@ -324,7 +324,7 @@ ec_GF2m_simple_point_init(EC_POINT * point) | |||
324 | 324 | ||
325 | 325 | ||
326 | /* Frees an EC_POINT. */ | 326 | /* Frees an EC_POINT. */ |
327 | void | 327 | void |
328 | ec_GF2m_simple_point_finish(EC_POINT * point) | 328 | ec_GF2m_simple_point_finish(EC_POINT * point) |
329 | { | 329 | { |
330 | BN_free(&point->X); | 330 | BN_free(&point->X); |
@@ -334,7 +334,7 @@ ec_GF2m_simple_point_finish(EC_POINT * point) | |||
334 | 334 | ||
335 | 335 | ||
336 | /* Clears and frees an EC_POINT. */ | 336 | /* Clears and frees an EC_POINT. */ |
337 | void | 337 | void |
338 | ec_GF2m_simple_point_clear_finish(EC_POINT * point) | 338 | ec_GF2m_simple_point_clear_finish(EC_POINT * point) |
339 | { | 339 | { |
340 | BN_clear_free(&point->X); | 340 | BN_clear_free(&point->X); |
@@ -345,7 +345,7 @@ ec_GF2m_simple_point_clear_finish(EC_POINT * point) | |||
345 | 345 | ||
346 | 346 | ||
347 | /* Copy the contents of one EC_POINT into another. Assumes dest is initialized. */ | 347 | /* Copy the contents of one EC_POINT into another. Assumes dest is initialized. */ |
348 | int | 348 | int |
349 | ec_GF2m_simple_point_copy(EC_POINT * dest, const EC_POINT * src) | 349 | ec_GF2m_simple_point_copy(EC_POINT * dest, const EC_POINT * src) |
350 | { | 350 | { |
351 | if (!BN_copy(&dest->X, &src->X)) | 351 | if (!BN_copy(&dest->X, &src->X)) |
@@ -363,7 +363,7 @@ ec_GF2m_simple_point_copy(EC_POINT * dest, const EC_POINT * src) | |||
363 | /* Set an EC_POINT to the point at infinity. | 363 | /* Set an EC_POINT to the point at infinity. |
364 | * A point at infinity is represented by having Z=0. | 364 | * A point at infinity is represented by having Z=0. |
365 | */ | 365 | */ |
366 | int | 366 | int |
367 | ec_GF2m_simple_point_set_to_infinity(const EC_GROUP * group, EC_POINT * point) | 367 | ec_GF2m_simple_point_set_to_infinity(const EC_GROUP * group, EC_POINT * point) |
368 | { | 368 | { |
369 | point->Z_is_one = 0; | 369 | point->Z_is_one = 0; |
@@ -375,7 +375,7 @@ ec_GF2m_simple_point_set_to_infinity(const EC_GROUP * group, EC_POINT * point) | |||
375 | /* Set the coordinates of an EC_POINT using affine coordinates. | 375 | /* Set the coordinates of an EC_POINT using affine coordinates. |
376 | * Note that the simple implementation only uses affine coordinates. | 376 | * Note that the simple implementation only uses affine coordinates. |
377 | */ | 377 | */ |
378 | int | 378 | int |
379 | ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP * group, EC_POINT * point, | 379 | ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP * group, EC_POINT * point, |
380 | const BIGNUM * x, const BIGNUM * y, BN_CTX * ctx) | 380 | const BIGNUM * x, const BIGNUM * y, BN_CTX * ctx) |
381 | { | 381 | { |
@@ -404,7 +404,7 @@ ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP * group, EC_POINT * p | |||
404 | /* Gets the affine coordinates of an EC_POINT. | 404 | /* Gets the affine coordinates of an EC_POINT. |
405 | * Note that the simple implementation only uses affine coordinates. | 405 | * Note that the simple implementation only uses affine coordinates. |
406 | */ | 406 | */ |
407 | int | 407 | int |
408 | ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *group, | 408 | ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *group, |
409 | const EC_POINT *point, BIGNUM *x, BIGNUM *y, BN_CTX *ctx) | 409 | const EC_POINT *point, BIGNUM *x, BIGNUM *y, BN_CTX *ctx) |
410 | { | 410 | { |
@@ -437,7 +437,7 @@ ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *group, | |||
437 | /* Computes a + b and stores the result in r. r could be a or b, a could be b. | 437 | /* Computes a + b and stores the result in r. r could be a or b, a could be b. |
438 | * Uses algorithm A.10.2 of IEEE P1363. | 438 | * Uses algorithm A.10.2 of IEEE P1363. |
439 | */ | 439 | */ |
440 | int | 440 | int |
441 | ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, | 441 | ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, |
442 | const EC_POINT *b, BN_CTX *ctx) | 442 | const EC_POINT *b, BN_CTX *ctx) |
443 | { | 443 | { |
@@ -557,14 +557,14 @@ ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, | |||
557 | /* Computes 2 * a and stores the result in r. r could be a. | 557 | /* Computes 2 * a and stores the result in r. r could be a. |
558 | * Uses algorithm A.10.2 of IEEE P1363. | 558 | * Uses algorithm A.10.2 of IEEE P1363. |
559 | */ | 559 | */ |
560 | int | 560 | int |
561 | ec_GF2m_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, | 561 | ec_GF2m_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, |
562 | BN_CTX *ctx) | 562 | BN_CTX *ctx) |
563 | { | 563 | { |
564 | return ec_GF2m_simple_add(group, r, a, a, ctx); | 564 | return ec_GF2m_simple_add(group, r, a, a, ctx); |
565 | } | 565 | } |
566 | 566 | ||
567 | int | 567 | int |
568 | ec_GF2m_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) | 568 | ec_GF2m_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) |
569 | { | 569 | { |
570 | if (EC_POINT_is_at_infinity(group, point) > 0 || BN_is_zero(&point->Y)) | 570 | if (EC_POINT_is_at_infinity(group, point) > 0 || BN_is_zero(&point->Y)) |
@@ -578,7 +578,7 @@ ec_GF2m_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) | |||
578 | 578 | ||
579 | 579 | ||
580 | /* Indicates whether the given point is the point at infinity. */ | 580 | /* Indicates whether the given point is the point at infinity. */ |
581 | int | 581 | int |
582 | ec_GF2m_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) | 582 | ec_GF2m_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) |
583 | { | 583 | { |
584 | return BN_is_zero(&point->Z); | 584 | return BN_is_zero(&point->Z); |
@@ -589,7 +589,7 @@ ec_GF2m_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) | |||
589 | * in the EC_GROUP. A point is valid if it satisfies the Weierstrass equation: | 589 | * in the EC_GROUP. A point is valid if it satisfies the Weierstrass equation: |
590 | * y^2 + x*y = x^3 + a*x^2 + b. | 590 | * y^2 + x*y = x^3 + a*x^2 + b. |
591 | */ | 591 | */ |
592 | int | 592 | int |
593 | ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx) | 593 | ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx) |
594 | { | 594 | { |
595 | int ret = -1; | 595 | int ret = -1; |
@@ -653,7 +653,7 @@ ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX | |||
653 | * 0 equal (in affine coordinates) | 653 | * 0 equal (in affine coordinates) |
654 | * 1 not equal | 654 | * 1 not equal |
655 | */ | 655 | */ |
656 | int | 656 | int |
657 | ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a, | 657 | ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a, |
658 | const EC_POINT *b, BN_CTX *ctx) | 658 | const EC_POINT *b, BN_CTX *ctx) |
659 | { | 659 | { |
@@ -700,7 +700,7 @@ ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a, | |||
700 | 700 | ||
701 | 701 | ||
702 | /* Forces the given EC_POINT to internally use affine coordinates. */ | 702 | /* Forces the given EC_POINT to internally use affine coordinates. */ |
703 | int | 703 | int |
704 | ec_GF2m_simple_make_affine(const EC_GROUP * group, EC_POINT * point, BN_CTX * ctx) | 704 | ec_GF2m_simple_make_affine(const EC_GROUP * group, EC_POINT * point, BN_CTX * ctx) |
705 | { | 705 | { |
706 | BN_CTX *new_ctx = NULL; | 706 | BN_CTX *new_ctx = NULL; |
@@ -741,7 +741,7 @@ ec_GF2m_simple_make_affine(const EC_GROUP * group, EC_POINT * point, BN_CTX * ct | |||
741 | 741 | ||
742 | 742 | ||
743 | /* Forces each of the EC_POINTs in the given array to use affine coordinates. */ | 743 | /* Forces each of the EC_POINTs in the given array to use affine coordinates. */ |
744 | int | 744 | int |
745 | ec_GF2m_simple_points_make_affine(const EC_GROUP *group, size_t num, | 745 | ec_GF2m_simple_points_make_affine(const EC_GROUP *group, size_t num, |
746 | EC_POINT *points[], BN_CTX *ctx) | 746 | EC_POINT *points[], BN_CTX *ctx) |
747 | { | 747 | { |
@@ -757,7 +757,7 @@ ec_GF2m_simple_points_make_affine(const EC_GROUP *group, size_t num, | |||
757 | 757 | ||
758 | 758 | ||
759 | /* Wrapper to simple binary polynomial field multiplication implementation. */ | 759 | /* Wrapper to simple binary polynomial field multiplication implementation. */ |
760 | int | 760 | int |
761 | ec_GF2m_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | 761 | ec_GF2m_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, |
762 | const BIGNUM *b, BN_CTX *ctx) | 762 | const BIGNUM *b, BN_CTX *ctx) |
763 | { | 763 | { |
@@ -766,7 +766,7 @@ ec_GF2m_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | |||
766 | 766 | ||
767 | 767 | ||
768 | /* Wrapper to simple binary polynomial field squaring implementation. */ | 768 | /* Wrapper to simple binary polynomial field squaring implementation. */ |
769 | int | 769 | int |
770 | ec_GF2m_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | 770 | ec_GF2m_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, |
771 | BN_CTX *ctx) | 771 | BN_CTX *ctx) |
772 | { | 772 | { |
@@ -775,7 +775,7 @@ ec_GF2m_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | |||
775 | 775 | ||
776 | 776 | ||
777 | /* Wrapper to simple binary polynomial field division implementation. */ | 777 | /* Wrapper to simple binary polynomial field division implementation. */ |
778 | int | 778 | int |
779 | ec_GF2m_simple_field_div(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | 779 | ec_GF2m_simple_field_div(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, |
780 | const BIGNUM *b, BN_CTX *ctx) | 780 | const BIGNUM *b, BN_CTX *ctx) |
781 | { | 781 | { |