diff options
author | tb <> | 2021-04-20 17:04:13 +0000 |
---|---|---|
committer | tb <> | 2021-04-20 17:04:13 +0000 |
commit | 05c3c8fff8c081d09d5d0feb2306a16cd2b9f6f7 (patch) | |
tree | 173c34f3f2e636d34625fd1b38effccf5db6b71f /src/lib | |
parent | c1737c38418f1a215997d19f2ff6dd2977f52430 (diff) | |
download | openbsd-05c3c8fff8c081d09d5d0feb2306a16cd2b9f6f7.tar.gz openbsd-05c3c8fff8c081d09d5d0feb2306a16cd2b9f6f7.tar.bz2 openbsd-05c3c8fff8c081d09d5d0feb2306a16cd2b9f6f7.zip |
Prepare to provide EC_GROUP_{get,set}_curve(3)
There are numerous functions in ec/ that exist with _GF2m and _GFp
variants for no good reason. The code of both variants is the same.
The EC_METHODs contain a pointer to the appropriate version. This
commit hides the _GF2m and _GFp variants from internal use and
provides versions that work for both curve types. These will be made
public in an upcoming library bump.
Similar to part of OpenSSL commit 8e3cced75fb5fee5da59ebef9605d403a999391b
ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/ec/ec.h | 10 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_asn1.c | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_cvt.c | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_lcl.h | 5 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_lib.c | 55 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/eck_prn.c | 6 |
6 files changed, 51 insertions, 41 deletions
diff --git a/src/lib/libcrypto/ec/ec.h b/src/lib/libcrypto/ec/ec.h index a95d99f6a9..a6ae3e3ac3 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.18 2019/09/29 10:09:09 tb Exp $ */ | 1 | /* $OpenBSD: ec.h,v 1.19 2021/04/20 17:04:13 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 | */ |
@@ -280,6 +280,12 @@ unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x); | |||
280 | size_t EC_GROUP_get_seed_len(const EC_GROUP *); | 280 | size_t EC_GROUP_get_seed_len(const EC_GROUP *); |
281 | size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len); | 281 | size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len); |
282 | 282 | ||
283 | #if defined(LIBRESSL_INTERNAL) | ||
284 | int EC_GROUP_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, | ||
285 | const BIGNUM *b, BN_CTX *ctx); | ||
286 | int EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, | ||
287 | BN_CTX *ctx); | ||
288 | #else | ||
283 | /** Sets the parameter of a ec over GFp defined by y^2 = x^3 + a*x + b | 289 | /** Sets the parameter of a ec over GFp defined by y^2 = x^3 + a*x + b |
284 | * \param group EC_GROUP object | 290 | * \param group EC_GROUP object |
285 | * \param p BIGNUM with the prime number | 291 | * \param p BIGNUM with the prime number |
@@ -321,6 +327,8 @@ int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, c | |||
321 | */ | 327 | */ |
322 | int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx); | 328 | int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx); |
323 | #endif | 329 | #endif |
330 | #endif | ||
331 | |||
324 | /** Returns the number of bits needed to represent a field element | 332 | /** Returns the number of bits needed to represent a field element |
325 | * \param group EC_GROUP object | 333 | * \param group EC_GROUP object |
326 | * \return number of bits needed to represent a field element | 334 | * \return number of bits needed to represent a field element |
diff --git a/src/lib/libcrypto/ec/ec_asn1.c b/src/lib/libcrypto/ec/ec_asn1.c index f69dd023de..65bb007cae 100644 --- a/src/lib/libcrypto/ec/ec_asn1.c +++ b/src/lib/libcrypto/ec/ec_asn1.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_asn1.c,v 1.31 2018/09/01 16:23:15 tb Exp $ */ | 1 | /* $OpenBSD: ec_asn1.c,v 1.32 2021/04/20 17:04:13 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -709,7 +709,7 @@ ec_asn1_group2fieldid(const EC_GROUP * group, X9_62_FIELDID * field) | |||
709 | goto err; | 709 | goto err; |
710 | } | 710 | } |
711 | /* the parameters are specified by the prime number p */ | 711 | /* the parameters are specified by the prime number p */ |
712 | if (!EC_GROUP_get_curve_GFp(group, tmp, NULL, NULL, NULL)) { | 712 | if (!EC_GROUP_get_curve(group, tmp, NULL, NULL, NULL)) { |
713 | ECerror(ERR_R_EC_LIB); | 713 | ECerror(ERR_R_EC_LIB); |
714 | goto err; | 714 | goto err; |
715 | } | 715 | } |
@@ -819,14 +819,14 @@ ec_asn1_group2curve(const EC_GROUP * group, X9_62_CURVE * curve) | |||
819 | 819 | ||
820 | /* get a and b */ | 820 | /* get a and b */ |
821 | if (nid == NID_X9_62_prime_field) { | 821 | if (nid == NID_X9_62_prime_field) { |
822 | if (!EC_GROUP_get_curve_GFp(group, NULL, tmp_1, tmp_2, NULL)) { | 822 | if (!EC_GROUP_get_curve(group, NULL, tmp_1, tmp_2, NULL)) { |
823 | ECerror(ERR_R_EC_LIB); | 823 | ECerror(ERR_R_EC_LIB); |
824 | goto err; | 824 | goto err; |
825 | } | 825 | } |
826 | } | 826 | } |
827 | #ifndef OPENSSL_NO_EC2M | 827 | #ifndef OPENSSL_NO_EC2M |
828 | else { /* nid == NID_X9_62_characteristic_two_field */ | 828 | else { /* nid == NID_X9_62_characteristic_two_field */ |
829 | if (!EC_GROUP_get_curve_GF2m(group, NULL, tmp_1, tmp_2, NULL)) { | 829 | if (!EC_GROUP_get_curve(group, NULL, tmp_1, tmp_2, NULL)) { |
830 | ECerror(ERR_R_EC_LIB); | 830 | ECerror(ERR_R_EC_LIB); |
831 | goto err; | 831 | goto err; |
832 | } | 832 | } |
diff --git a/src/lib/libcrypto/ec/ec_cvt.c b/src/lib/libcrypto/ec/ec_cvt.c index a0982064b8..05c7dd1bf1 100644 --- a/src/lib/libcrypto/ec/ec_cvt.c +++ b/src/lib/libcrypto/ec/ec_cvt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_cvt.c,v 1.6 2014/07/10 22:45:57 jsing Exp $ */ | 1 | /* $OpenBSD: ec_cvt.c,v 1.7 2021/04/20 17:04:13 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 | */ |
@@ -112,7 +112,7 @@ EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, | |||
112 | if (ret == NULL) | 112 | if (ret == NULL) |
113 | return NULL; | 113 | return NULL; |
114 | 114 | ||
115 | if (!EC_GROUP_set_curve_GFp(ret, p, a, b, ctx)) { | 115 | if (!EC_GROUP_set_curve(ret, p, a, b, ctx)) { |
116 | unsigned long err; | 116 | unsigned long err; |
117 | 117 | ||
118 | err = ERR_peek_last_error(); | 118 | err = ERR_peek_last_error(); |
@@ -136,7 +136,7 @@ EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, | |||
136 | if (ret == NULL) | 136 | if (ret == NULL) |
137 | return NULL; | 137 | return NULL; |
138 | 138 | ||
139 | if (!EC_GROUP_set_curve_GFp(ret, p, a, b, ctx)) { | 139 | if (!EC_GROUP_set_curve(ret, p, a, b, ctx)) { |
140 | EC_GROUP_clear_free(ret); | 140 | EC_GROUP_clear_free(ret); |
141 | return NULL; | 141 | return NULL; |
142 | } | 142 | } |
@@ -158,7 +158,7 @@ EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, | |||
158 | if (ret == NULL) | 158 | if (ret == NULL) |
159 | return NULL; | 159 | return NULL; |
160 | 160 | ||
161 | if (!EC_GROUP_set_curve_GF2m(ret, p, a, b, ctx)) { | 161 | if (!EC_GROUP_set_curve(ret, p, a, b, ctx)) { |
162 | EC_GROUP_clear_free(ret); | 162 | EC_GROUP_clear_free(ret); |
163 | return NULL; | 163 | return NULL; |
164 | } | 164 | } |
diff --git a/src/lib/libcrypto/ec/ec_lcl.h b/src/lib/libcrypto/ec/ec_lcl.h index 8948e51d69..f689428852 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.13 2019/01/19 01:12:48 tb Exp $ */ | 1 | /* $OpenBSD: ec_lcl.h,v 1.14 2021/04/20 17:04:13 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 | */ |
@@ -105,8 +105,7 @@ struct ec_method_st { | |||
105 | void (*group_clear_finish)(EC_GROUP *); | 105 | void (*group_clear_finish)(EC_GROUP *); |
106 | int (*group_copy)(EC_GROUP *, const EC_GROUP *); | 106 | int (*group_copy)(EC_GROUP *, const EC_GROUP *); |
107 | 107 | ||
108 | /* used by EC_GROUP_set_curve_GFp, EC_GROUP_get_curve_GFp, */ | 108 | /* used by EC_GROUP_{get,set}_curve */ |
109 | /* EC_GROUP_set_curve_GF2m, and EC_GROUP_get_curve_GF2m: */ | ||
110 | int (*group_set_curve)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); | 109 | int (*group_set_curve)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); |
111 | int (*group_get_curve)(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *); | 110 | int (*group_get_curve)(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *); |
112 | 111 | ||
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c index 3442c7a324..67db821ec4 100644 --- a/src/lib/libcrypto/ec/ec_lib.c +++ b/src/lib/libcrypto/ec/ec_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_lib.c,v 1.33 2020/12/04 08:55:30 tb Exp $ */ | 1 | /* $OpenBSD: ec_lib.c,v 1.34 2021/04/20 17:04:13 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 | */ |
@@ -488,10 +488,9 @@ EC_GROUP_get_seed_len(const EC_GROUP * group) | |||
488 | return group->seed_len; | 488 | return group->seed_len; |
489 | } | 489 | } |
490 | 490 | ||
491 | 491 | int | |
492 | int | 492 | EC_GROUP_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, |
493 | EC_GROUP_set_curve_GFp(EC_GROUP * group, const BIGNUM * p, const BIGNUM * a, | 493 | const BIGNUM *b, BN_CTX *ctx) |
494 | const BIGNUM * b, BN_CTX * ctx) | ||
495 | { | 494 | { |
496 | if (group->meth->group_set_curve == 0) { | 495 | if (group->meth->group_set_curve == 0) { |
497 | ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 496 | ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
@@ -500,10 +499,9 @@ EC_GROUP_set_curve_GFp(EC_GROUP * group, const BIGNUM * p, const BIGNUM * a, | |||
500 | return group->meth->group_set_curve(group, p, a, b, ctx); | 499 | return group->meth->group_set_curve(group, p, a, b, ctx); |
501 | } | 500 | } |
502 | 501 | ||
503 | 502 | int | |
504 | int | 503 | EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, |
505 | EC_GROUP_get_curve_GFp(const EC_GROUP * group, BIGNUM * p, BIGNUM * a, | 504 | BN_CTX *ctx) |
506 | BIGNUM * b, BN_CTX * ctx) | ||
507 | { | 505 | { |
508 | if (group->meth->group_get_curve == 0) { | 506 | if (group->meth->group_get_curve == 0) { |
509 | ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 507 | ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
@@ -512,28 +510,33 @@ EC_GROUP_get_curve_GFp(const EC_GROUP * group, BIGNUM * p, BIGNUM * a, | |||
512 | return group->meth->group_get_curve(group, p, a, b, ctx); | 510 | return group->meth->group_get_curve(group, p, a, b, ctx); |
513 | } | 511 | } |
514 | 512 | ||
515 | #ifndef OPENSSL_NO_EC2M | 513 | int |
516 | int | 514 | EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, |
517 | EC_GROUP_set_curve_GF2m(EC_GROUP * group, const BIGNUM * p, const BIGNUM * a, | 515 | const BIGNUM *b, BN_CTX *ctx) |
518 | const BIGNUM * b, BN_CTX * ctx) | ||
519 | { | 516 | { |
520 | if (group->meth->group_set_curve == 0) { | 517 | return EC_GROUP_set_curve(group, p, a, b, ctx); |
521 | ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
522 | return 0; | ||
523 | } | ||
524 | return group->meth->group_set_curve(group, p, a, b, ctx); | ||
525 | } | 518 | } |
526 | 519 | ||
520 | int | ||
521 | EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, | ||
522 | BN_CTX *ctx) | ||
523 | { | ||
524 | return EC_GROUP_get_curve(group, p, a, b, ctx); | ||
525 | } | ||
527 | 526 | ||
528 | int | 527 | #ifndef OPENSSL_NO_EC2M |
529 | EC_GROUP_get_curve_GF2m(const EC_GROUP * group, BIGNUM * p, BIGNUM * a, | 528 | int |
530 | BIGNUM * b, BN_CTX * ctx) | 529 | EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, |
530 | const BIGNUM *b, BN_CTX *ctx) | ||
531 | { | 531 | { |
532 | if (group->meth->group_get_curve == 0) { | 532 | return EC_GROUP_set_curve(group, p, a, b, ctx); |
533 | ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 533 | } |
534 | return 0; | 534 | |
535 | } | 535 | int |
536 | return group->meth->group_get_curve(group, p, a, b, ctx); | 536 | EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, |
537 | BIGNUM *b, BN_CTX *ctx) | ||
538 | { | ||
539 | return EC_GROUP_get_curve(group, p, a, b, ctx); | ||
537 | } | 540 | } |
538 | #endif | 541 | #endif |
539 | 542 | ||
diff --git a/src/lib/libcrypto/ec/eck_prn.c b/src/lib/libcrypto/ec/eck_prn.c index be57d875e3..b17908d7fa 100644 --- a/src/lib/libcrypto/ec/eck_prn.c +++ b/src/lib/libcrypto/ec/eck_prn.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: eck_prn.c,v 1.15 2018/07/15 16:27:39 tb Exp $ */ | 1 | /* $OpenBSD: eck_prn.c,v 1.16 2021/04/20 17:04:13 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -216,14 +216,14 @@ ECPKParameters_print(BIO * bp, const EC_GROUP * x, int off) | |||
216 | } | 216 | } |
217 | #ifndef OPENSSL_NO_EC2M | 217 | #ifndef OPENSSL_NO_EC2M |
218 | if (is_char_two) { | 218 | if (is_char_two) { |
219 | if (!EC_GROUP_get_curve_GF2m(x, p, a, b, ctx)) { | 219 | if (!EC_GROUP_get_curve(x, p, a, b, ctx)) { |
220 | reason = ERR_R_EC_LIB; | 220 | reason = ERR_R_EC_LIB; |
221 | goto err; | 221 | goto err; |
222 | } | 222 | } |
223 | } else /* prime field */ | 223 | } else /* prime field */ |
224 | #endif | 224 | #endif |
225 | { | 225 | { |
226 | if (!EC_GROUP_get_curve_GFp(x, p, a, b, ctx)) { | 226 | if (!EC_GROUP_get_curve(x, p, a, b, ctx)) { |
227 | reason = ERR_R_EC_LIB; | 227 | reason = ERR_R_EC_LIB; |
228 | goto err; | 228 | goto err; |
229 | } | 229 | } |