diff options
| author | jsing <> | 2023-03-07 05:50:59 +0000 |
|---|---|---|
| committer | jsing <> | 2023-03-07 05:50:59 +0000 |
| commit | 9aae699938e6684ed47cd6d37a031e3100587c47 (patch) | |
| tree | 93bfa62d7ca2f54c1d644e7756c7b0746c9ce77a /src | |
| parent | 5ccfeda594a1e00600a37cf1184cfd1ccce1ed0d (diff) | |
| download | openbsd-9aae699938e6684ed47cd6d37a031e3100587c47.tar.gz openbsd-9aae699938e6684ed47cd6d37a031e3100587c47.tar.bz2 openbsd-9aae699938e6684ed47cd6d37a031e3100587c47.zip | |
Use static functions for EC_GF2m_simple_method() implementation.
Move the EC_METHOD to the bottom of the file, which allows implementation
functions to become static. Remove unneeded prototypes.
ok tb@
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/ec/ec2_smpl.c | 171 | ||||
| -rw-r--r-- | src/lib/libcrypto/ec/ec_local.h | 34 |
2 files changed, 74 insertions, 131 deletions
diff --git a/src/lib/libcrypto/ec/ec2_smpl.c b/src/lib/libcrypto/ec/ec2_smpl.c index 8bf5895e8a..910484fc65 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.29 2023/03/07 05:35:13 jsing Exp $ */ | 1 | /* $OpenBSD: ec2_smpl.c,v 1.30 2023/03/07 05:50:59 jsing Exp $ */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
| 4 | * | 4 | * |
| @@ -75,59 +75,11 @@ | |||
| 75 | 75 | ||
| 76 | #ifndef OPENSSL_NO_EC2M | 76 | #ifndef OPENSSL_NO_EC2M |
| 77 | 77 | ||
| 78 | const EC_METHOD * | ||
| 79 | EC_GF2m_simple_method(void) | ||
| 80 | { | ||
| 81 | static const EC_METHOD ret = { | ||
| 82 | .flags = EC_FLAGS_DEFAULT_OCT, | ||
| 83 | .field_type = NID_X9_62_characteristic_two_field, | ||
| 84 | .group_init = ec_GF2m_simple_group_init, | ||
| 85 | .group_finish = ec_GF2m_simple_group_finish, | ||
| 86 | .group_clear_finish = ec_GF2m_simple_group_clear_finish, | ||
| 87 | .group_copy = ec_GF2m_simple_group_copy, | ||
| 88 | .group_set_curve = ec_GF2m_simple_group_set_curve, | ||
| 89 | .group_get_curve = ec_GF2m_simple_group_get_curve, | ||
| 90 | .group_get_degree = ec_GF2m_simple_group_get_degree, | ||
| 91 | .group_order_bits = ec_group_simple_order_bits, | ||
| 92 | .group_check_discriminant = | ||
| 93 | ec_GF2m_simple_group_check_discriminant, | ||
| 94 | .point_init = ec_GF2m_simple_point_init, | ||
| 95 | .point_finish = ec_GF2m_simple_point_finish, | ||
| 96 | .point_clear_finish = ec_GF2m_simple_point_clear_finish, | ||
| 97 | .point_copy = ec_GF2m_simple_point_copy, | ||
| 98 | .point_set_to_infinity = ec_GF2m_simple_point_set_to_infinity, | ||
| 99 | .point_set_affine_coordinates = | ||
| 100 | ec_GF2m_simple_point_set_affine_coordinates, | ||
| 101 | .point_get_affine_coordinates = | ||
| 102 | ec_GF2m_simple_point_get_affine_coordinates, | ||
| 103 | .add = ec_GF2m_simple_add, | ||
| 104 | .dbl = ec_GF2m_simple_dbl, | ||
| 105 | .invert = ec_GF2m_simple_invert, | ||
| 106 | .is_at_infinity = ec_GF2m_simple_is_at_infinity, | ||
| 107 | .is_on_curve = ec_GF2m_simple_is_on_curve, | ||
| 108 | .point_cmp = ec_GF2m_simple_cmp, | ||
| 109 | .make_affine = ec_GF2m_simple_make_affine, | ||
| 110 | .points_make_affine = ec_GF2m_simple_points_make_affine, | ||
| 111 | .mul_generator_ct = ec_GFp_simple_mul_generator_ct, | ||
| 112 | .mul_single_ct = ec_GFp_simple_mul_single_ct, | ||
| 113 | .mul_double_nonct = ec_GFp_simple_mul_double_nonct, | ||
| 114 | .precompute_mult = ec_GF2m_precompute_mult, | ||
| 115 | .have_precompute_mult = ec_GF2m_have_precompute_mult, | ||
| 116 | .field_mul = ec_GF2m_simple_field_mul, | ||
| 117 | .field_sqr = ec_GF2m_simple_field_sqr, | ||
| 118 | .field_div = ec_GF2m_simple_field_div, | ||
| 119 | .blind_coordinates = NULL, | ||
| 120 | }; | ||
| 121 | |||
| 122 | return &ret; | ||
| 123 | } | ||
| 124 | |||
| 125 | |||
| 126 | /* | 78 | /* |
| 127 | * Initialize a GF(2^m)-based EC_GROUP structure. | 79 | * Initialize a GF(2^m)-based EC_GROUP structure. |
| 128 | * Note that all other members are handled by EC_GROUP_new. | 80 | * Note that all other members are handled by EC_GROUP_new. |
| 129 | */ | 81 | */ |
| 130 | int | 82 | static int |
| 131 | ec_GF2m_simple_group_init(EC_GROUP *group) | 83 | ec_GF2m_simple_group_init(EC_GROUP *group) |
| 132 | { | 84 | { |
| 133 | BN_init(&group->field); | 85 | BN_init(&group->field); |
| @@ -136,12 +88,11 @@ ec_GF2m_simple_group_init(EC_GROUP *group) | |||
| 136 | return 1; | 88 | return 1; |
| 137 | } | 89 | } |
| 138 | 90 | ||
| 139 | |||
| 140 | /* | 91 | /* |
| 141 | * Free a GF(2^m)-based EC_GROUP structure. | 92 | * Free a GF(2^m)-based EC_GROUP structure. |
| 142 | * Note that all other members are handled by EC_GROUP_free. | 93 | * Note that all other members are handled by EC_GROUP_free. |
| 143 | */ | 94 | */ |
| 144 | void | 95 | static void |
| 145 | ec_GF2m_simple_group_finish(EC_GROUP *group) | 96 | ec_GF2m_simple_group_finish(EC_GROUP *group) |
| 146 | { | 97 | { |
| 147 | BN_free(&group->field); | 98 | BN_free(&group->field); |
| @@ -149,12 +100,11 @@ ec_GF2m_simple_group_finish(EC_GROUP *group) | |||
| 149 | BN_free(&group->b); | 100 | BN_free(&group->b); |
| 150 | } | 101 | } |
| 151 | 102 | ||
| 152 | |||
| 153 | /* | 103 | /* |
| 154 | * Clear and free a GF(2^m)-based EC_GROUP structure. | 104 | * Clear and free a GF(2^m)-based EC_GROUP structure. |
| 155 | * Note that all other members are handled by EC_GROUP_clear_free. | 105 | * Note that all other members are handled by EC_GROUP_clear_free. |
| 156 | */ | 106 | */ |
| 157 | void | 107 | static void |
| 158 | ec_GF2m_simple_group_clear_finish(EC_GROUP *group) | 108 | ec_GF2m_simple_group_clear_finish(EC_GROUP *group) |
| 159 | { | 109 | { |
| 160 | BN_clear_free(&group->field); | 110 | BN_clear_free(&group->field); |
| @@ -168,12 +118,11 @@ ec_GF2m_simple_group_clear_finish(EC_GROUP *group) | |||
| 168 | group->poly[5] = -1; | 118 | group->poly[5] = -1; |
| 169 | } | 119 | } |
| 170 | 120 | ||
| 171 | |||
| 172 | /* | 121 | /* |
| 173 | * Copy a GF(2^m)-based EC_GROUP structure. | 122 | * Copy a GF(2^m)-based EC_GROUP structure. |
| 174 | * Note that all other members are handled by EC_GROUP_copy. | 123 | * Note that all other members are handled by EC_GROUP_copy. |
| 175 | */ | 124 | */ |
| 176 | int | 125 | static int |
| 177 | ec_GF2m_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src) | 126 | ec_GF2m_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src) |
| 178 | { | 127 | { |
| 179 | int i; | 128 | int i; |
| @@ -201,9 +150,8 @@ ec_GF2m_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src) | |||
| 201 | return 1; | 150 | return 1; |
| 202 | } | 151 | } |
| 203 | 152 | ||
| 204 | |||
| 205 | /* Set the curve parameters of an EC_GROUP structure. */ | 153 | /* Set the curve parameters of an EC_GROUP structure. */ |
| 206 | int | 154 | static int |
| 207 | ec_GF2m_simple_group_set_curve(EC_GROUP *group, | 155 | ec_GF2m_simple_group_set_curve(EC_GROUP *group, |
| 208 | const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) | 156 | const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) |
| 209 | { | 157 | { |
| @@ -238,12 +186,11 @@ ec_GF2m_simple_group_set_curve(EC_GROUP *group, | |||
| 238 | return ret; | 186 | return ret; |
| 239 | } | 187 | } |
| 240 | 188 | ||
| 241 | |||
| 242 | /* | 189 | /* |
| 243 | * Get the curve parameters of an EC_GROUP structure. | 190 | * Get the curve parameters of an EC_GROUP structure. |
| 244 | * If p, a, or b are NULL then there values will not be set but the method will return with success. | 191 | * If p, a, or b are NULL then there values will not be set but the method will return with success. |
| 245 | */ | 192 | */ |
| 246 | int | 193 | static int |
| 247 | ec_GF2m_simple_group_get_curve(const EC_GROUP *group, | 194 | ec_GF2m_simple_group_get_curve(const EC_GROUP *group, |
| 248 | BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) | 195 | BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) |
| 249 | { | 196 | { |
| @@ -267,20 +214,18 @@ ec_GF2m_simple_group_get_curve(const EC_GROUP *group, | |||
| 267 | return ret; | 214 | return ret; |
| 268 | } | 215 | } |
| 269 | 216 | ||
| 270 | |||
| 271 | /* Gets the degree of the field. For a curve over GF(2^m) this is the value m. */ | 217 | /* Gets the degree of the field. For a curve over GF(2^m) this is the value m. */ |
| 272 | int | 218 | static int |
| 273 | ec_GF2m_simple_group_get_degree(const EC_GROUP *group) | 219 | ec_GF2m_simple_group_get_degree(const EC_GROUP *group) |
| 274 | { | 220 | { |
| 275 | return BN_num_bits(&group->field) - 1; | 221 | return BN_num_bits(&group->field) - 1; |
| 276 | } | 222 | } |
| 277 | 223 | ||
| 278 | |||
| 279 | /* | 224 | /* |
| 280 | * Checks the discriminant of the curve. | 225 | * Checks the discriminant of the curve. |
| 281 | * y^2 + x*y = x^3 + a*x^2 + b is an elliptic curve <=> b != 0 (mod p) | 226 | * y^2 + x*y = x^3 + a*x^2 + b is an elliptic curve <=> b != 0 (mod p) |
| 282 | */ | 227 | */ |
| 283 | int | 228 | static int |
| 284 | ec_GF2m_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) | 229 | ec_GF2m_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) |
| 285 | { | 230 | { |
| 286 | int ret = 0; | 231 | int ret = 0; |
| @@ -317,9 +262,8 @@ ec_GF2m_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) | |||
| 317 | return ret; | 262 | return ret; |
| 318 | } | 263 | } |
| 319 | 264 | ||
| 320 | |||
| 321 | /* Initializes an EC_POINT. */ | 265 | /* Initializes an EC_POINT. */ |
| 322 | int | 266 | static int |
| 323 | ec_GF2m_simple_point_init(EC_POINT *point) | 267 | ec_GF2m_simple_point_init(EC_POINT *point) |
| 324 | { | 268 | { |
| 325 | BN_init(&point->X); | 269 | BN_init(&point->X); |
| @@ -328,9 +272,8 @@ ec_GF2m_simple_point_init(EC_POINT *point) | |||
| 328 | return 1; | 272 | return 1; |
| 329 | } | 273 | } |
| 330 | 274 | ||
| 331 | |||
| 332 | /* Frees an EC_POINT. */ | 275 | /* Frees an EC_POINT. */ |
| 333 | void | 276 | static void |
| 334 | ec_GF2m_simple_point_finish(EC_POINT *point) | 277 | ec_GF2m_simple_point_finish(EC_POINT *point) |
| 335 | { | 278 | { |
| 336 | BN_free(&point->X); | 279 | BN_free(&point->X); |
| @@ -338,9 +281,8 @@ ec_GF2m_simple_point_finish(EC_POINT *point) | |||
| 338 | BN_free(&point->Z); | 281 | BN_free(&point->Z); |
| 339 | } | 282 | } |
| 340 | 283 | ||
| 341 | |||
| 342 | /* Clears and frees an EC_POINT. */ | 284 | /* Clears and frees an EC_POINT. */ |
| 343 | void | 285 | static void |
| 344 | ec_GF2m_simple_point_clear_finish(EC_POINT *point) | 286 | ec_GF2m_simple_point_clear_finish(EC_POINT *point) |
| 345 | { | 287 | { |
| 346 | BN_clear_free(&point->X); | 288 | BN_clear_free(&point->X); |
| @@ -349,9 +291,8 @@ ec_GF2m_simple_point_clear_finish(EC_POINT *point) | |||
| 349 | point->Z_is_one = 0; | 291 | point->Z_is_one = 0; |
| 350 | } | 292 | } |
| 351 | 293 | ||
| 352 | |||
| 353 | /* Copy the contents of one EC_POINT into another. Assumes dest is initialized. */ | 294 | /* Copy the contents of one EC_POINT into another. Assumes dest is initialized. */ |
| 354 | int | 295 | static int |
| 355 | ec_GF2m_simple_point_copy(EC_POINT *dest, const EC_POINT *src) | 296 | ec_GF2m_simple_point_copy(EC_POINT *dest, const EC_POINT *src) |
| 356 | { | 297 | { |
| 357 | if (!BN_copy(&dest->X, &src->X)) | 298 | if (!BN_copy(&dest->X, &src->X)) |
| @@ -365,12 +306,11 @@ ec_GF2m_simple_point_copy(EC_POINT *dest, const EC_POINT *src) | |||
| 365 | return 1; | 306 | return 1; |
| 366 | } | 307 | } |
| 367 | 308 | ||
| 368 | |||
| 369 | /* | 309 | /* |
| 370 | * Set an EC_POINT to the point at infinity. | 310 | * Set an EC_POINT to the point at infinity. |
| 371 | * A point at infinity is represented by having Z=0. | 311 | * A point at infinity is represented by having Z=0. |
| 372 | */ | 312 | */ |
| 373 | int | 313 | static int |
| 374 | ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point) | 314 | ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point) |
| 375 | { | 315 | { |
| 376 | point->Z_is_one = 0; | 316 | point->Z_is_one = 0; |
| @@ -378,12 +318,11 @@ ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point) | |||
| 378 | return 1; | 318 | return 1; |
| 379 | } | 319 | } |
| 380 | 320 | ||
| 381 | |||
| 382 | /* | 321 | /* |
| 383 | * Set the coordinates of an EC_POINT using affine coordinates. | 322 | * Set the coordinates of an EC_POINT using affine coordinates. |
| 384 | * Note that the simple implementation only uses affine coordinates. | 323 | * Note that the simple implementation only uses affine coordinates. |
| 385 | */ | 324 | */ |
| 386 | int | 325 | static int |
| 387 | ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point, | 326 | ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point, |
| 388 | const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx) | 327 | const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx) |
| 389 | { | 328 | { |
| @@ -408,12 +347,11 @@ ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *poi | |||
| 408 | return ret; | 347 | return ret; |
| 409 | } | 348 | } |
| 410 | 349 | ||
| 411 | |||
| 412 | /* | 350 | /* |
| 413 | * Gets the affine coordinates of an EC_POINT. | 351 | * Gets the affine coordinates of an EC_POINT. |
| 414 | * Note that the simple implementation only uses affine coordinates. | 352 | * Note that the simple implementation only uses affine coordinates. |
| 415 | */ | 353 | */ |
| 416 | int | 354 | static int |
| 417 | ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *group, | 355 | ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *group, |
| 418 | const EC_POINT *point, BIGNUM *x, BIGNUM *y, BN_CTX *ctx) | 356 | const EC_POINT *point, BIGNUM *x, BIGNUM *y, BN_CTX *ctx) |
| 419 | { | 357 | { |
| @@ -447,7 +385,7 @@ ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *group, | |||
| 447 | * Computes a + b and stores the result in r. r could be a or b, a could be b. | 385 | * Computes a + b and stores the result in r. r could be a or b, a could be b. |
| 448 | * Uses algorithm A.10.2 of IEEE P1363. | 386 | * Uses algorithm A.10.2 of IEEE P1363. |
| 449 | */ | 387 | */ |
| 450 | int | 388 | static int |
| 451 | ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, | 389 | ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, |
| 452 | const EC_POINT *b, BN_CTX *ctx) | 390 | const EC_POINT *b, BN_CTX *ctx) |
| 453 | { | 391 | { |
| @@ -507,7 +445,6 @@ ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, | |||
| 507 | goto err; | 445 | goto err; |
| 508 | } | 446 | } |
| 509 | 447 | ||
| 510 | |||
| 511 | if (BN_GF2m_cmp(x0, x1)) { | 448 | if (BN_GF2m_cmp(x0, x1)) { |
| 512 | if (!BN_GF2m_add(t, x0, x1)) | 449 | if (!BN_GF2m_add(t, x0, x1)) |
| 513 | goto err; | 450 | goto err; |
| @@ -563,19 +500,18 @@ ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, | |||
| 563 | return ret; | 500 | return ret; |
| 564 | } | 501 | } |
| 565 | 502 | ||
| 566 | |||
| 567 | /* | 503 | /* |
| 568 | * Computes 2 * a and stores the result in r. r could be a. | 504 | * Computes 2 * a and stores the result in r. r could be a. |
| 569 | * Uses algorithm A.10.2 of IEEE P1363. | 505 | * Uses algorithm A.10.2 of IEEE P1363. |
| 570 | */ | 506 | */ |
| 571 | int | 507 | static int |
| 572 | ec_GF2m_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, | 508 | ec_GF2m_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, |
| 573 | BN_CTX *ctx) | 509 | BN_CTX *ctx) |
| 574 | { | 510 | { |
| 575 | return ec_GF2m_simple_add(group, r, a, a, ctx); | 511 | return ec_GF2m_simple_add(group, r, a, a, ctx); |
| 576 | } | 512 | } |
| 577 | 513 | ||
| 578 | int | 514 | static int |
| 579 | ec_GF2m_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) | 515 | ec_GF2m_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) |
| 580 | { | 516 | { |
| 581 | if (EC_POINT_is_at_infinity(group, point) > 0 || BN_is_zero(&point->Y)) | 517 | if (EC_POINT_is_at_infinity(group, point) > 0 || BN_is_zero(&point->Y)) |
| @@ -587,21 +523,19 @@ ec_GF2m_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) | |||
| 587 | return BN_GF2m_add(&point->Y, &point->X, &point->Y); | 523 | return BN_GF2m_add(&point->Y, &point->X, &point->Y); |
| 588 | } | 524 | } |
| 589 | 525 | ||
| 590 | |||
| 591 | /* Indicates whether the given point is the point at infinity. */ | 526 | /* Indicates whether the given point is the point at infinity. */ |
| 592 | int | 527 | static int |
| 593 | ec_GF2m_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) | 528 | ec_GF2m_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) |
| 594 | { | 529 | { |
| 595 | return BN_is_zero(&point->Z); | 530 | return BN_is_zero(&point->Z); |
| 596 | } | 531 | } |
| 597 | 532 | ||
| 598 | |||
| 599 | /* | 533 | /* |
| 600 | * Determines whether the given EC_POINT is an actual point on the curve defined | 534 | * Determines whether the given EC_POINT is an actual point on the curve defined |
| 601 | * in the EC_GROUP. A point is valid if it satisfies the Weierstrass equation: | 535 | * in the EC_GROUP. A point is valid if it satisfies the Weierstrass equation: |
| 602 | * y^2 + x*y = x^3 + a*x^2 + b. | 536 | * y^2 + x*y = x^3 + a*x^2 + b. |
| 603 | */ | 537 | */ |
| 604 | int | 538 | static int |
| 605 | ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx) | 539 | ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx) |
| 606 | { | 540 | { |
| 607 | int ret = -1; | 541 | int ret = -1; |
| @@ -658,7 +592,6 @@ ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX | |||
| 658 | return ret; | 592 | return ret; |
| 659 | } | 593 | } |
| 660 | 594 | ||
| 661 | |||
| 662 | /* | 595 | /* |
| 663 | * Indicates whether two points are equal. | 596 | * Indicates whether two points are equal. |
| 664 | * Return values: | 597 | * Return values: |
| @@ -666,7 +599,7 @@ ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX | |||
| 666 | * 0 equal (in affine coordinates) | 599 | * 0 equal (in affine coordinates) |
| 667 | * 1 not equal | 600 | * 1 not equal |
| 668 | */ | 601 | */ |
| 669 | int | 602 | static int |
| 670 | ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a, | 603 | ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a, |
| 671 | const EC_POINT *b, BN_CTX *ctx) | 604 | const EC_POINT *b, BN_CTX *ctx) |
| 672 | { | 605 | { |
| @@ -711,9 +644,8 @@ ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a, | |||
| 711 | return ret; | 644 | return ret; |
| 712 | } | 645 | } |
| 713 | 646 | ||
| 714 | |||
| 715 | /* Forces the given EC_POINT to internally use affine coordinates. */ | 647 | /* Forces the given EC_POINT to internally use affine coordinates. */ |
| 716 | int | 648 | static int |
| 717 | ec_GF2m_simple_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) | 649 | ec_GF2m_simple_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) |
| 718 | { | 650 | { |
| 719 | BN_CTX *new_ctx = NULL; | 651 | BN_CTX *new_ctx = NULL; |
| @@ -752,9 +684,8 @@ ec_GF2m_simple_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) | |||
| 752 | return ret; | 684 | return ret; |
| 753 | } | 685 | } |
| 754 | 686 | ||
| 755 | |||
| 756 | /* Forces each of the EC_POINTs in the given array to use affine coordinates. */ | 687 | /* Forces each of the EC_POINTs in the given array to use affine coordinates. */ |
| 757 | int | 688 | static int |
| 758 | ec_GF2m_simple_points_make_affine(const EC_GROUP *group, size_t num, | 689 | ec_GF2m_simple_points_make_affine(const EC_GROUP *group, size_t num, |
| 759 | EC_POINT *points[], BN_CTX *ctx) | 690 | EC_POINT *points[], BN_CTX *ctx) |
| 760 | { | 691 | { |
| @@ -768,31 +699,73 @@ ec_GF2m_simple_points_make_affine(const EC_GROUP *group, size_t num, | |||
| 768 | return 1; | 699 | return 1; |
| 769 | } | 700 | } |
| 770 | 701 | ||
| 771 | |||
| 772 | /* Wrapper to simple binary polynomial field multiplication implementation. */ | 702 | /* Wrapper to simple binary polynomial field multiplication implementation. */ |
| 773 | int | 703 | static int |
| 774 | ec_GF2m_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | 704 | ec_GF2m_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, |
| 775 | const BIGNUM *b, BN_CTX *ctx) | 705 | const BIGNUM *b, BN_CTX *ctx) |
| 776 | { | 706 | { |
| 777 | return BN_GF2m_mod_mul_arr(r, a, b, group->poly, ctx); | 707 | return BN_GF2m_mod_mul_arr(r, a, b, group->poly, ctx); |
| 778 | } | 708 | } |
| 779 | 709 | ||
| 780 | |||
| 781 | /* Wrapper to simple binary polynomial field squaring implementation. */ | 710 | /* Wrapper to simple binary polynomial field squaring implementation. */ |
| 782 | int | 711 | static int |
| 783 | ec_GF2m_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | 712 | ec_GF2m_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, |
| 784 | BN_CTX *ctx) | 713 | BN_CTX *ctx) |
| 785 | { | 714 | { |
| 786 | return BN_GF2m_mod_sqr_arr(r, a, group->poly, ctx); | 715 | return BN_GF2m_mod_sqr_arr(r, a, group->poly, ctx); |
| 787 | } | 716 | } |
| 788 | 717 | ||
| 789 | |||
| 790 | /* Wrapper to simple binary polynomial field division implementation. */ | 718 | /* Wrapper to simple binary polynomial field division implementation. */ |
| 791 | int | 719 | static int |
| 792 | ec_GF2m_simple_field_div(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | 720 | ec_GF2m_simple_field_div(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, |
| 793 | const BIGNUM *b, BN_CTX *ctx) | 721 | const BIGNUM *b, BN_CTX *ctx) |
| 794 | { | 722 | { |
| 795 | return BN_GF2m_mod_div(r, a, b, &group->field, ctx); | 723 | return BN_GF2m_mod_div(r, a, b, &group->field, ctx); |
| 796 | } | 724 | } |
| 797 | 725 | ||
| 726 | static const EC_METHOD ec_GF2m_simple_method = { | ||
| 727 | .flags = EC_FLAGS_DEFAULT_OCT, | ||
| 728 | .field_type = NID_X9_62_characteristic_two_field, | ||
| 729 | .group_init = ec_GF2m_simple_group_init, | ||
| 730 | .group_finish = ec_GF2m_simple_group_finish, | ||
| 731 | .group_clear_finish = ec_GF2m_simple_group_clear_finish, | ||
| 732 | .group_copy = ec_GF2m_simple_group_copy, | ||
| 733 | .group_set_curve = ec_GF2m_simple_group_set_curve, | ||
| 734 | .group_get_curve = ec_GF2m_simple_group_get_curve, | ||
| 735 | .group_get_degree = ec_GF2m_simple_group_get_degree, | ||
| 736 | .group_order_bits = ec_group_simple_order_bits, | ||
| 737 | .group_check_discriminant = ec_GF2m_simple_group_check_discriminant, | ||
| 738 | .point_init = ec_GF2m_simple_point_init, | ||
| 739 | .point_finish = ec_GF2m_simple_point_finish, | ||
| 740 | .point_clear_finish = ec_GF2m_simple_point_clear_finish, | ||
| 741 | .point_copy = ec_GF2m_simple_point_copy, | ||
| 742 | .point_set_to_infinity = ec_GF2m_simple_point_set_to_infinity, | ||
| 743 | .point_set_affine_coordinates = | ||
| 744 | ec_GF2m_simple_point_set_affine_coordinates, | ||
| 745 | .point_get_affine_coordinates = | ||
| 746 | ec_GF2m_simple_point_get_affine_coordinates, | ||
| 747 | .add = ec_GF2m_simple_add, | ||
| 748 | .dbl = ec_GF2m_simple_dbl, | ||
| 749 | .invert = ec_GF2m_simple_invert, | ||
| 750 | .is_at_infinity = ec_GF2m_simple_is_at_infinity, | ||
| 751 | .is_on_curve = ec_GF2m_simple_is_on_curve, | ||
| 752 | .point_cmp = ec_GF2m_simple_cmp, | ||
| 753 | .make_affine = ec_GF2m_simple_make_affine, | ||
| 754 | .points_make_affine = ec_GF2m_simple_points_make_affine, | ||
| 755 | .mul_generator_ct = ec_GFp_simple_mul_generator_ct, | ||
| 756 | .mul_single_ct = ec_GFp_simple_mul_single_ct, | ||
| 757 | .mul_double_nonct = ec_GFp_simple_mul_double_nonct, | ||
| 758 | .precompute_mult = ec_GF2m_precompute_mult, | ||
| 759 | .have_precompute_mult = ec_GF2m_have_precompute_mult, | ||
| 760 | .field_mul = ec_GF2m_simple_field_mul, | ||
| 761 | .field_sqr = ec_GF2m_simple_field_sqr, | ||
| 762 | .field_div = ec_GF2m_simple_field_div, | ||
| 763 | .blind_coordinates = NULL, | ||
| 764 | }; | ||
| 765 | |||
| 766 | const EC_METHOD * | ||
| 767 | EC_GF2m_simple_method(void) | ||
| 768 | { | ||
| 769 | return &ec_GF2m_simple_method; | ||
| 770 | } | ||
| 798 | #endif | 771 | #endif |
diff --git a/src/lib/libcrypto/ec/ec_local.h b/src/lib/libcrypto/ec/ec_local.h index 677ae0c368..a1d7c9d3f2 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.8 2023/03/07 05:45:14 jsing Exp $ */ | 1 | /* $OpenBSD: ec_local.h,v 1.9 2023/03/07 05:50:59 jsing 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 | */ |
| @@ -371,43 +371,13 @@ int ec_GFp_simple_mul_double_nonct(const EC_GROUP *, EC_POINT *r, const BIGNUM * | |||
| 371 | 371 | ||
| 372 | int ec_point_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx); | 372 | int ec_point_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx); |
| 373 | 373 | ||
| 374 | /* method functions in ec2_smpl.c */ | ||
| 375 | int ec_GF2m_simple_group_init(EC_GROUP *); | ||
| 376 | void ec_GF2m_simple_group_finish(EC_GROUP *); | ||
| 377 | void ec_GF2m_simple_group_clear_finish(EC_GROUP *); | ||
| 378 | int ec_GF2m_simple_group_copy(EC_GROUP *, const EC_GROUP *); | ||
| 379 | int ec_GF2m_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); | ||
| 380 | int ec_GF2m_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *); | ||
| 381 | int ec_GF2m_simple_group_get_degree(const EC_GROUP *); | ||
| 382 | int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *); | ||
| 383 | int ec_GF2m_simple_point_init(EC_POINT *); | ||
| 384 | void ec_GF2m_simple_point_finish(EC_POINT *); | ||
| 385 | void ec_GF2m_simple_point_clear_finish(EC_POINT *); | ||
| 386 | int ec_GF2m_simple_point_copy(EC_POINT *, const EC_POINT *); | ||
| 387 | int ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *); | ||
| 388 | int ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *, | ||
| 389 | const BIGNUM *x, const BIGNUM *y, BN_CTX *); | ||
| 390 | int ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *, const EC_POINT *, | ||
| 391 | BIGNUM *x, BIGNUM *y, BN_CTX *); | ||
| 392 | int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *, | 374 | int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *, |
| 393 | const BIGNUM *x, int y_bit, BN_CTX *); | 375 | const BIGNUM *x, int y_bit, BN_CTX *); |
| 394 | size_t ec_GF2m_simple_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form, | 376 | size_t ec_GF2m_simple_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form, |
| 395 | unsigned char *buf, size_t len, BN_CTX *); | 377 | unsigned char *buf, size_t len, BN_CTX *); |
| 396 | int ec_GF2m_simple_oct2point(const EC_GROUP *, EC_POINT *, | 378 | int ec_GF2m_simple_oct2point(const EC_GROUP *, EC_POINT *, |
| 397 | const unsigned char *buf, size_t len, BN_CTX *); | 379 | const unsigned char *buf, size_t len, BN_CTX *); |
| 398 | int ec_GF2m_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *); | 380 | |
| 399 | int ec_GF2m_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *); | ||
| 400 | int ec_GF2m_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *); | ||
| 401 | int ec_GF2m_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *); | ||
| 402 | int ec_GF2m_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *); | ||
| 403 | int ec_GF2m_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *); | ||
| 404 | int ec_GF2m_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *); | ||
| 405 | int ec_GF2m_simple_points_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *); | ||
| 406 | int ec_GF2m_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); | ||
| 407 | int ec_GF2m_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); | ||
| 408 | int ec_GF2m_simple_field_div(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); | ||
| 409 | |||
| 410 | /* method functions in ec2_mult.c */ | ||
| 411 | int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, | 381 | int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, |
| 412 | size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *); | 382 | size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *); |
| 413 | int ec_GF2m_precompute_mult(EC_GROUP *group, BN_CTX *ctx); | 383 | int ec_GF2m_precompute_mult(EC_GROUP *group, BN_CTX *ctx); |
