diff options
author | tb <> | 2021-04-20 17:32:57 +0000 |
---|---|---|
committer | tb <> | 2021-04-20 17:32:57 +0000 |
commit | e3bdd39cc031d39a8ea071c9a8ecea5b6a958967 (patch) | |
tree | b19c2d7871b27d3b2f6ce519613278cb8c4140a5 /src/lib | |
parent | 5ac32b17def2bf66d2e60cc7866c946a98c4a411 (diff) | |
download | openbsd-e3bdd39cc031d39a8ea071c9a8ecea5b6a958967.tar.gz openbsd-e3bdd39cc031d39a8ea071c9a8ecea5b6a958967.tar.bz2 openbsd-e3bdd39cc031d39a8ea071c9a8ecea5b6a958967.zip |
Prepare to provide EC_POINT_set_compressed_coordinates
ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/ec/ec.h | 27 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec2_oct.c | 6 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_lcl.h | 7 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_oct.c | 52 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ecp_oct.c | 6 |
5 files changed, 41 insertions, 57 deletions
diff --git a/src/lib/libcrypto/ec/ec.h b/src/lib/libcrypto/ec/ec.h index ff60e80952..dece357d02 100644 --- a/src/lib/libcrypto/ec/ec.h +++ b/src/lib/libcrypto/ec/ec.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec.h,v 1.21 2021/04/20 17:28:18 tb Exp $ */ | 1 | /* $OpenBSD: ec.h,v 1.22 2021/04/20 17:32:57 tb 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 | */ |
@@ -455,11 +455,20 @@ const EC_METHOD *EC_POINT_method_of(const EC_POINT *point); | |||
455 | int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point); | 455 | int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point); |
456 | 456 | ||
457 | #if defined(LIBRESSL_INTERNAL) | 457 | #if defined(LIBRESSL_INTERNAL) |
458 | |||
458 | int EC_POINT_set_Jprojective_coordinates(const EC_GROUP *group, EC_POINT *p, | 459 | int EC_POINT_set_Jprojective_coordinates(const EC_GROUP *group, EC_POINT *p, |
459 | const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx); | 460 | const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx); |
460 | int EC_POINT_get_Jprojective_coordinates(const EC_GROUP *group, | 461 | int EC_POINT_get_Jprojective_coordinates(const EC_GROUP *group, |
461 | const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx); | 462 | const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx); |
463 | int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *p, | ||
464 | const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx); | ||
465 | int EC_POINT_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *p, | ||
466 | BIGNUM *x, BIGNUM *y, BN_CTX *ctx); | ||
467 | int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *p, | ||
468 | const BIGNUM *x, int y_bit, BN_CTX *ctx); | ||
469 | |||
462 | #else | 470 | #else |
471 | |||
463 | /** Sets the jacobian projective coordinates of a EC_POINT over GFp | 472 | /** Sets the jacobian projective coordinates of a EC_POINT over GFp |
464 | * \param group underlying EC_GROUP object | 473 | * \param group underlying EC_GROUP object |
465 | * \param p EC_POINT object | 474 | * \param p EC_POINT object |
@@ -483,14 +492,7 @@ int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *p, | |||
483 | */ | 492 | */ |
484 | int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, | 493 | int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, |
485 | const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx); | 494 | const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx); |
486 | #endif | ||
487 | 495 | ||
488 | #if defined(LIBRESSL_INTERNAL) | ||
489 | int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *p, | ||
490 | const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx); | ||
491 | int EC_POINT_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *p, | ||
492 | BIGNUM *x, BIGNUM *y, BN_CTX *ctx); | ||
493 | #else | ||
494 | /** Sets the affine coordinates of a EC_POINT over GFp | 496 | /** Sets the affine coordinates of a EC_POINT over GFp |
495 | * \param group underlying EC_GROUP object | 497 | * \param group underlying EC_GROUP object |
496 | * \param p EC_POINT object | 498 | * \param p EC_POINT object |
@@ -512,7 +514,6 @@ int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *p, | |||
512 | */ | 514 | */ |
513 | int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, | 515 | int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, |
514 | const EC_POINT *p, BIGNUM *x, BIGNUM *y, BN_CTX *ctx); | 516 | const EC_POINT *p, BIGNUM *x, BIGNUM *y, BN_CTX *ctx); |
515 | #endif | ||
516 | 517 | ||
517 | /** Sets the x9.62 compressed coordinates of a EC_POINT over GFp | 518 | /** Sets the x9.62 compressed coordinates of a EC_POINT over GFp |
518 | * \param group underlying EC_GROUP object | 519 | * \param group underlying EC_GROUP object |
@@ -526,7 +527,6 @@ int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *p, | |||
526 | const BIGNUM *x, int y_bit, BN_CTX *ctx); | 527 | const BIGNUM *x, int y_bit, BN_CTX *ctx); |
527 | 528 | ||
528 | #ifndef OPENSSL_NO_EC2M | 529 | #ifndef OPENSSL_NO_EC2M |
529 | #if !defined(LIBRESSL_INTERNAL) | ||
530 | /** Sets the affine coordinates of a EC_POINT over GF2m | 530 | /** Sets the affine coordinates of a EC_POINT over GF2m |
531 | * \param group underlying EC_GROUP object | 531 | * \param group underlying EC_GROUP object |
532 | * \param p EC_POINT object | 532 | * \param p EC_POINT object |
@@ -548,7 +548,6 @@ int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, EC_POINT *p, | |||
548 | */ | 548 | */ |
549 | int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group, | 549 | int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group, |
550 | const EC_POINT *p, BIGNUM *x, BIGNUM *y, BN_CTX *ctx); | 550 | const EC_POINT *p, BIGNUM *x, BIGNUM *y, BN_CTX *ctx); |
551 | #endif | ||
552 | 551 | ||
553 | /** Sets the x9.62 compressed coordinates of a EC_POINT over GF2m | 552 | /** Sets the x9.62 compressed coordinates of a EC_POINT over GF2m |
554 | * \param group underlying EC_GROUP object | 553 | * \param group underlying EC_GROUP object |
@@ -560,7 +559,9 @@ int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group, | |||
560 | */ | 559 | */ |
561 | int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, EC_POINT *p, | 560 | int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, EC_POINT *p, |
562 | const BIGNUM *x, int y_bit, BN_CTX *ctx); | 561 | const BIGNUM *x, int y_bit, BN_CTX *ctx); |
563 | #endif | 562 | #endif /* OPENSSL_NO_EC2M */ |
563 | #endif /* !LIBRESSL_INTERNAL */ | ||
564 | |||
564 | /** Encodes a EC_POINT object to a octet string | 565 | /** Encodes a EC_POINT object to a octet string |
565 | * \param group underlying EC_GROUP object | 566 | * \param group underlying EC_GROUP object |
566 | * \param p EC_POINT object | 567 | * \param p EC_POINT object |
diff --git a/src/lib/libcrypto/ec/ec2_oct.c b/src/lib/libcrypto/ec/ec2_oct.c index 28eb7a01b6..ad38991471 100644 --- a/src/lib/libcrypto/ec/ec2_oct.c +++ b/src/lib/libcrypto/ec/ec2_oct.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec2_oct.c,v 1.14 2021/04/20 17:16:37 tb Exp $ */ | 1 | /* $OpenBSD: ec2_oct.c,v 1.15 2021/04/20 17:32: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 | * |
@@ -366,10 +366,10 @@ ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point, | |||
366 | } | 366 | } |
367 | if (form == POINT_CONVERSION_COMPRESSED) { | 367 | if (form == POINT_CONVERSION_COMPRESSED) { |
368 | /* | 368 | /* |
369 | * EC_POINT_set_compressed_coordinates_GF2m checks that the | 369 | * EC_POINT_set_compressed_coordinates checks that the |
370 | * point is on the curve as required by X9.62. | 370 | * point is on the curve as required by X9.62. |
371 | */ | 371 | */ |
372 | if (!EC_POINT_set_compressed_coordinates_GF2m(group, point, x, y_bit, ctx)) | 372 | if (!EC_POINT_set_compressed_coordinates(group, point, x, y_bit, ctx)) |
373 | goto err; | 373 | goto err; |
374 | } else { | 374 | } else { |
375 | if (!BN_bin2bn(buf + 1 + field_len, field_len, y)) | 375 | if (!BN_bin2bn(buf + 1 + field_len, field_len, y)) |
diff --git a/src/lib/libcrypto/ec/ec_lcl.h b/src/lib/libcrypto/ec/ec_lcl.h index 7570cdc7f2..a0343aa1d2 100644 --- a/src/lib/libcrypto/ec/ec_lcl.h +++ b/src/lib/libcrypto/ec/ec_lcl.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_lcl.h,v 1.16 2021/04/20 17:28:18 tb Exp $ */ | 1 | /* $OpenBSD: ec_lcl.h,v 1.17 2021/04/20 17:32:57 tb 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 | */ |
@@ -121,12 +121,13 @@ struct ec_method_st { | |||
121 | void (*point_clear_finish)(EC_POINT *); | 121 | void (*point_clear_finish)(EC_POINT *); |
122 | int (*point_copy)(EC_POINT *, const EC_POINT *); | 122 | int (*point_copy)(EC_POINT *, const EC_POINT *); |
123 | 123 | ||
124 | /* used by EC_POINT_set_to_infinity, | 124 | /* |
125 | * used by EC_POINT_set_to_infinity, | ||
125 | * EC_POINT_set_Jprojective_coordinates, | 126 | * EC_POINT_set_Jprojective_coordinates, |
126 | * EC_POINT_get_Jprojective_coordinates, | 127 | * EC_POINT_get_Jprojective_coordinates, |
127 | * EC_POINT_set_affine_coordinates, | 128 | * EC_POINT_set_affine_coordinates, |
128 | * EC_POINT_get_affine_coordinates, | 129 | * EC_POINT_get_affine_coordinates, |
129 | * EC_POINT_set_compressed_coordinates_GFp, ..._GF2m: | 130 | * EC_POINT_set_compressed_coordinates: |
130 | */ | 131 | */ |
131 | int (*point_set_to_infinity)(const EC_GROUP *, EC_POINT *); | 132 | int (*point_set_to_infinity)(const EC_GROUP *, EC_POINT *); |
132 | int (*point_set_Jprojective_coordinates)(const EC_GROUP *, EC_POINT *, | 133 | int (*point_set_Jprojective_coordinates)(const EC_GROUP *, EC_POINT *, |
diff --git a/src/lib/libcrypto/ec/ec_oct.c b/src/lib/libcrypto/ec/ec_oct.c index a285c81459..a3a826d0f1 100644 --- a/src/lib/libcrypto/ec/ec_oct.c +++ b/src/lib/libcrypto/ec/ec_oct.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_oct.c,v 1.6 2020/12/04 08:55:30 tb Exp $ */ | 1 | /* $OpenBSD: ec_oct.c,v 1.7 2021/04/20 17:32:57 tb 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 | */ |
@@ -70,9 +70,9 @@ | |||
70 | 70 | ||
71 | #include "ec_lcl.h" | 71 | #include "ec_lcl.h" |
72 | 72 | ||
73 | int | 73 | int |
74 | EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP * group, EC_POINT * point, | 74 | EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point, |
75 | const BIGNUM * x, int y_bit, BN_CTX * ctx) | 75 | const BIGNUM *x, int y_bit, BN_CTX *ctx) |
76 | { | 76 | { |
77 | if (group->meth->point_set_compressed_coordinates == 0 | 77 | if (group->meth->point_set_compressed_coordinates == 0 |
78 | && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) { | 78 | && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) { |
@@ -108,40 +108,23 @@ EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP * group, EC_POINT * point | |||
108 | return 1; | 108 | return 1; |
109 | } | 109 | } |
110 | 110 | ||
111 | int | ||
112 | EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point, | ||
113 | const BIGNUM *x, int y_bit, BN_CTX *ctx) | ||
114 | { | ||
115 | return EC_POINT_set_compressed_coordinates(group, point, x, y_bit, ctx); | ||
116 | } | ||
117 | |||
111 | #ifndef OPENSSL_NO_EC2M | 118 | #ifndef OPENSSL_NO_EC2M |
112 | int | 119 | int |
113 | EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP * group, EC_POINT * point, | 120 | EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, EC_POINT *point, |
114 | const BIGNUM * x, int y_bit, BN_CTX * ctx) | 121 | const BIGNUM *x, int y_bit, BN_CTX *ctx) |
115 | { | 122 | { |
116 | if (group->meth->point_set_compressed_coordinates == 0 | 123 | return EC_POINT_set_compressed_coordinates(group, point, x, y_bit, ctx); |
117 | && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) { | ||
118 | ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
119 | return 0; | ||
120 | } | ||
121 | if (group->meth != point->meth) { | ||
122 | ECerror(EC_R_INCOMPATIBLE_OBJECTS); | ||
123 | return 0; | ||
124 | } | ||
125 | if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) { | ||
126 | if (group->meth->field_type == NID_X9_62_prime_field) | ||
127 | return ec_GFp_simple_set_compressed_coordinates( | ||
128 | group, point, x, y_bit, ctx); | ||
129 | else | ||
130 | return ec_GF2m_simple_set_compressed_coordinates( | ||
131 | group, point, x, y_bit, ctx); | ||
132 | } | ||
133 | if (!group->meth->point_set_compressed_coordinates(group, point, x, | ||
134 | y_bit, ctx)) | ||
135 | return 0; | ||
136 | if (EC_POINT_is_on_curve(group, point, ctx) <= 0) { | ||
137 | ECerror(EC_R_POINT_IS_NOT_ON_CURVE); | ||
138 | return 0; | ||
139 | } | ||
140 | return 1; | ||
141 | } | 124 | } |
142 | #endif | 125 | #endif |
143 | 126 | ||
144 | size_t | 127 | size_t |
145 | EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point, | 128 | EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point, |
146 | point_conversion_form_t form, | 129 | point_conversion_form_t form, |
147 | unsigned char *buf, size_t len, BN_CTX *ctx) | 130 | unsigned char *buf, size_t len, BN_CTX *ctx) |
@@ -173,8 +156,7 @@ EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point, | |||
173 | return group->meth->point2oct(group, point, form, buf, len, ctx); | 156 | return group->meth->point2oct(group, point, form, buf, len, ctx); |
174 | } | 157 | } |
175 | 158 | ||
176 | 159 | int | |
177 | int | ||
178 | EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point, | 160 | EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point, |
179 | const unsigned char *buf, size_t len, BN_CTX *ctx) | 161 | const unsigned char *buf, size_t len, BN_CTX *ctx) |
180 | { | 162 | { |
diff --git a/src/lib/libcrypto/ec/ecp_oct.c b/src/lib/libcrypto/ec/ecp_oct.c index 901220483c..177bbe152e 100644 --- a/src/lib/libcrypto/ec/ecp_oct.c +++ b/src/lib/libcrypto/ec/ecp_oct.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ecp_oct.c,v 1.13 2021/04/20 17:16:38 tb Exp $ */ | 1 | /* $OpenBSD: ecp_oct.c,v 1.14 2021/04/20 17:32:57 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. |
@@ -363,10 +363,10 @@ ec_GFp_simple_oct2point(const EC_GROUP * group, EC_POINT * point, | |||
363 | } | 363 | } |
364 | if (form == POINT_CONVERSION_COMPRESSED) { | 364 | if (form == POINT_CONVERSION_COMPRESSED) { |
365 | /* | 365 | /* |
366 | * EC_POINT_set_compressed_coordinates_GFp checks that the point | 366 | * EC_POINT_set_compressed_coordinates checks that the point |
367 | * is on the curve as required by X9.62. | 367 | * is on the curve as required by X9.62. |
368 | */ | 368 | */ |
369 | if (!EC_POINT_set_compressed_coordinates_GFp(group, point, x, y_bit, ctx)) | 369 | if (!EC_POINT_set_compressed_coordinates(group, point, x, y_bit, ctx)) |
370 | goto err; | 370 | goto err; |
371 | } else { | 371 | } else { |
372 | if (!BN_bin2bn(buf + 1 + field_len, field_len, y)) | 372 | if (!BN_bin2bn(buf + 1 + field_len, field_len, y)) |