summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ec2_smpl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/ec/ec2_smpl.c')
-rw-r--r--src/lib/libcrypto/ec/ec2_smpl.c54
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 */
129int 129int
130ec_GF2m_simple_group_init(EC_GROUP * group) 130ec_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 */
142void 142void
143ec_GF2m_simple_group_finish(EC_GROUP * group) 143ec_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 */
154void 154void
155ec_GF2m_simple_group_clear_finish(EC_GROUP * group) 155ec_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 */
172int 172int
173ec_GF2m_simple_group_copy(EC_GROUP * dest, const EC_GROUP * src) 173ec_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. */
202int 202int
203ec_GF2m_simple_group_set_curve(EC_GROUP * group, 203ec_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 */
241int 241int
242ec_GF2m_simple_group_get_curve(const EC_GROUP *group, 242ec_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. */
267int 267int
268ec_GF2m_simple_group_get_degree(const EC_GROUP * group) 268ec_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 */
277int 277int
278ec_GF2m_simple_group_check_discriminant(const EC_GROUP * group, BN_CTX * ctx) 278ec_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. */
316int 316int
317ec_GF2m_simple_point_init(EC_POINT * point) 317ec_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. */
327void 327void
328ec_GF2m_simple_point_finish(EC_POINT * point) 328ec_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. */
337void 337void
338ec_GF2m_simple_point_clear_finish(EC_POINT * point) 338ec_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. */
348int 348int
349ec_GF2m_simple_point_copy(EC_POINT * dest, const EC_POINT * src) 349ec_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 */
366int 366int
367ec_GF2m_simple_point_set_to_infinity(const EC_GROUP * group, EC_POINT * point) 367ec_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 */
378int 378int
379ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP * group, EC_POINT * point, 379ec_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 */
407int 407int
408ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *group, 408ec_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 */
440int 440int
441ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, 441ec_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 */
560int 560int
561ec_GF2m_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, 561ec_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
567int 567int
568ec_GF2m_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) 568ec_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. */
581int 581int
582ec_GF2m_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) 582ec_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 */
592int 592int
593ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx) 593ec_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 */
656int 656int
657ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a, 657ec_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. */
703int 703int
704ec_GF2m_simple_make_affine(const EC_GROUP * group, EC_POINT * point, BN_CTX * ctx) 704ec_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. */
744int 744int
745ec_GF2m_simple_points_make_affine(const EC_GROUP *group, size_t num, 745ec_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. */
760int 760int
761ec_GF2m_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, 761ec_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. */
769int 769int
770ec_GF2m_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, 770ec_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. */
778int 778int
779ec_GF2m_simple_field_div(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, 779ec_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{