diff options
author | tb <> | 2023-07-28 08:49:43 +0000 |
---|---|---|
committer | tb <> | 2023-07-28 08:49:43 +0000 |
commit | 27bf20b08f028e09b36afd8b49d1fbaa87746bb6 (patch) | |
tree | efbe0438383ae81f0c511a990e4a656ecd91e76c /src/lib | |
parent | 783244ed4a6bd90016acb876b9752acd0db924be (diff) | |
download | openbsd-27bf20b08f028e09b36afd8b49d1fbaa87746bb6.tar.gz openbsd-27bf20b08f028e09b36afd8b49d1fbaa87746bb6.tar.bz2 openbsd-27bf20b08f028e09b36afd8b49d1fbaa87746bb6.zip |
Make extended ECDSA signing routines internal
ECDSA_sign_setup() permits precomputing the values of the inverse of the
random k and the corresponding r. These can then be fed into the signing
routines ECDSA_{do_,}sign_ex() multiple times if needed. This is not a
great idea and the interface adds a lot of unwanted complexity.
Not to mention that nothing ever used this correctly - if s works out to
0, a special error code is thrown requesting that the caller provide new
kinv and r values. Unsurprisingly, nobody ever checked for that special
error code.
ok jsing
This commit marks the start of a libcrypto major bump. Do not build the
tree until I bumped the shlib_version and synced file sets (in about 35
commits).
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/Symbols.list | 3 | ||||
-rw-r--r-- | src/lib/libcrypto/Symbols.namespace | 3 | ||||
-rw-r--r-- | src/lib/libcrypto/ecdsa/ecdsa.c | 19 | ||||
-rw-r--r-- | src/lib/libcrypto/ecdsa/ecdsa.h | 9 | ||||
-rw-r--r-- | src/lib/libcrypto/hidden/openssl/ecdsa.h | 5 |
5 files changed, 14 insertions, 25 deletions
diff --git a/src/lib/libcrypto/Symbols.list b/src/lib/libcrypto/Symbols.list index 626cd78b3b..00d9cfa65e 100644 --- a/src/lib/libcrypto/Symbols.list +++ b/src/lib/libcrypto/Symbols.list | |||
@@ -1028,7 +1028,6 @@ ECDSA_SIG_it | |||
1028 | ECDSA_SIG_new | 1028 | ECDSA_SIG_new |
1029 | ECDSA_SIG_set0 | 1029 | ECDSA_SIG_set0 |
1030 | ECDSA_do_sign | 1030 | ECDSA_do_sign |
1031 | ECDSA_do_sign_ex | ||
1032 | ECDSA_do_verify | 1031 | ECDSA_do_verify |
1033 | ECDSA_get_default_method | 1032 | ECDSA_get_default_method |
1034 | ECDSA_get_ex_data | 1033 | ECDSA_get_ex_data |
@@ -1037,8 +1036,6 @@ ECDSA_set_default_method | |||
1037 | ECDSA_set_ex_data | 1036 | ECDSA_set_ex_data |
1038 | ECDSA_set_method | 1037 | ECDSA_set_method |
1039 | ECDSA_sign | 1038 | ECDSA_sign |
1040 | ECDSA_sign_ex | ||
1041 | ECDSA_sign_setup | ||
1042 | ECDSA_size | 1039 | ECDSA_size |
1043 | ECDSA_verify | 1040 | ECDSA_verify |
1044 | ECPARAMETERS_free | 1041 | ECPARAMETERS_free |
diff --git a/src/lib/libcrypto/Symbols.namespace b/src/lib/libcrypto/Symbols.namespace index 60d6195fac..186e065ba2 100644 --- a/src/lib/libcrypto/Symbols.namespace +++ b/src/lib/libcrypto/Symbols.namespace | |||
@@ -1429,16 +1429,13 @@ _libre_ECDSA_SIG_get0_r | |||
1429 | _libre_ECDSA_SIG_get0_s | 1429 | _libre_ECDSA_SIG_get0_s |
1430 | _libre_ECDSA_SIG_set0 | 1430 | _libre_ECDSA_SIG_set0 |
1431 | _libre_ECDSA_do_sign | 1431 | _libre_ECDSA_do_sign |
1432 | _libre_ECDSA_do_sign_ex | ||
1433 | _libre_ECDSA_do_verify | 1432 | _libre_ECDSA_do_verify |
1434 | _libre_ECDSA_OpenSSL | 1433 | _libre_ECDSA_OpenSSL |
1435 | _libre_ECDSA_set_default_method | 1434 | _libre_ECDSA_set_default_method |
1436 | _libre_ECDSA_get_default_method | 1435 | _libre_ECDSA_get_default_method |
1437 | _libre_ECDSA_set_method | 1436 | _libre_ECDSA_set_method |
1438 | _libre_ECDSA_size | 1437 | _libre_ECDSA_size |
1439 | _libre_ECDSA_sign_setup | ||
1440 | _libre_ECDSA_sign | 1438 | _libre_ECDSA_sign |
1441 | _libre_ECDSA_sign_ex | ||
1442 | _libre_ECDSA_verify | 1439 | _libre_ECDSA_verify |
1443 | _libre_ECDSA_get_ex_new_index | 1440 | _libre_ECDSA_get_ex_new_index |
1444 | _libre_ECDSA_set_ex_data | 1441 | _libre_ECDSA_set_ex_data |
diff --git a/src/lib/libcrypto/ecdsa/ecdsa.c b/src/lib/libcrypto/ecdsa/ecdsa.c index e47ec21281..17f968f0cc 100644 --- a/src/lib/libcrypto/ecdsa/ecdsa.c +++ b/src/lib/libcrypto/ecdsa/ecdsa.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ecdsa.c,v 1.12 2023/07/10 19:10:51 tb Exp $ */ | 1 | /* $OpenBSD: ecdsa.c,v 1.13 2023/07/28 08:49:43 tb Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 2000-2002 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2000-2002 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -71,6 +71,14 @@ | |||
71 | #include "ec_local.h" | 71 | #include "ec_local.h" |
72 | #include "ecdsa_local.h" | 72 | #include "ecdsa_local.h" |
73 | 73 | ||
74 | static ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen, | ||
75 | const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey); | ||
76 | static int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen, | ||
77 | unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv, | ||
78 | const BIGNUM *rp, EC_KEY *eckey); | ||
79 | static int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *in_ctx, BIGNUM **out_kinv, | ||
80 | BIGNUM **out_r); | ||
81 | |||
74 | static const ASN1_TEMPLATE ECDSA_SIG_seq_tt[] = { | 82 | static const ASN1_TEMPLATE ECDSA_SIG_seq_tt[] = { |
75 | { | 83 | { |
76 | .flags = 0, | 84 | .flags = 0, |
@@ -762,7 +770,7 @@ ECDSA_do_sign(const unsigned char *digest, int digest_len, EC_KEY *key) | |||
762 | } | 770 | } |
763 | LCRYPTO_ALIAS(ECDSA_do_sign); | 771 | LCRYPTO_ALIAS(ECDSA_do_sign); |
764 | 772 | ||
765 | ECDSA_SIG * | 773 | static ECDSA_SIG * |
766 | ECDSA_do_sign_ex(const unsigned char *digest, int digest_len, | 774 | ECDSA_do_sign_ex(const unsigned char *digest, int digest_len, |
767 | const BIGNUM *kinv, const BIGNUM *out_r, EC_KEY *key) | 775 | const BIGNUM *kinv, const BIGNUM *out_r, EC_KEY *key) |
768 | { | 776 | { |
@@ -772,7 +780,6 @@ ECDSA_do_sign_ex(const unsigned char *digest, int digest_len, | |||
772 | } | 780 | } |
773 | return key->meth->sign_sig(digest, digest_len, kinv, out_r, key); | 781 | return key->meth->sign_sig(digest, digest_len, kinv, out_r, key); |
774 | } | 782 | } |
775 | LCRYPTO_ALIAS(ECDSA_do_sign_ex); | ||
776 | 783 | ||
777 | int | 784 | int |
778 | ECDSA_sign(int type, const unsigned char *digest, int digest_len, | 785 | ECDSA_sign(int type, const unsigned char *digest, int digest_len, |
@@ -783,7 +790,7 @@ ECDSA_sign(int type, const unsigned char *digest, int digest_len, | |||
783 | } | 790 | } |
784 | LCRYPTO_ALIAS(ECDSA_sign); | 791 | LCRYPTO_ALIAS(ECDSA_sign); |
785 | 792 | ||
786 | int | 793 | static int |
787 | ECDSA_sign_ex(int type, const unsigned char *digest, int digest_len, | 794 | ECDSA_sign_ex(int type, const unsigned char *digest, int digest_len, |
788 | unsigned char *signature, unsigned int *signature_len, const BIGNUM *kinv, | 795 | unsigned char *signature, unsigned int *signature_len, const BIGNUM *kinv, |
789 | const BIGNUM *r, EC_KEY *key) | 796 | const BIGNUM *r, EC_KEY *key) |
@@ -795,9 +802,8 @@ ECDSA_sign_ex(int type, const unsigned char *digest, int digest_len, | |||
795 | return key->meth->sign(type, digest, digest_len, signature, | 802 | return key->meth->sign(type, digest, digest_len, signature, |
796 | signature_len, kinv, r, key); | 803 | signature_len, kinv, r, key); |
797 | } | 804 | } |
798 | LCRYPTO_ALIAS(ECDSA_sign_ex); | ||
799 | 805 | ||
800 | int | 806 | static int |
801 | ECDSA_sign_setup(EC_KEY *key, BN_CTX *in_ctx, BIGNUM **out_kinv, | 807 | ECDSA_sign_setup(EC_KEY *key, BN_CTX *in_ctx, BIGNUM **out_kinv, |
802 | BIGNUM **out_r) | 808 | BIGNUM **out_r) |
803 | { | 809 | { |
@@ -807,7 +813,6 @@ ECDSA_sign_setup(EC_KEY *key, BN_CTX *in_ctx, BIGNUM **out_kinv, | |||
807 | } | 813 | } |
808 | return key->meth->sign_setup(key, in_ctx, out_kinv, out_r); | 814 | return key->meth->sign_setup(key, in_ctx, out_kinv, out_r); |
809 | } | 815 | } |
810 | LCRYPTO_ALIAS(ECDSA_sign_setup); | ||
811 | 816 | ||
812 | int | 817 | int |
813 | ECDSA_do_verify(const unsigned char *digest, int digest_len, | 818 | ECDSA_do_verify(const unsigned char *digest, int digest_len, |
diff --git a/src/lib/libcrypto/ecdsa/ecdsa.h b/src/lib/libcrypto/ecdsa/ecdsa.h index 2e6b672627..9960a4b1ea 100644 --- a/src/lib/libcrypto/ecdsa/ecdsa.h +++ b/src/lib/libcrypto/ecdsa/ecdsa.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ecdsa.h,v 1.16 2023/06/19 09:12:41 tb Exp $ */ | 1 | /* $OpenBSD: ecdsa.h,v 1.17 2023/07/28 08:49:43 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project | 3 | * Written by Nils Larsch for the OpenSSL project |
4 | */ | 4 | */ |
@@ -108,8 +108,6 @@ int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s); | |||
108 | 108 | ||
109 | ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len, | 109 | ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len, |
110 | EC_KEY *eckey); | 110 | EC_KEY *eckey); |
111 | ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen, | ||
112 | const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey); | ||
113 | int ECDSA_do_verify(const unsigned char *dgst, int dgst_len, | 111 | int ECDSA_do_verify(const unsigned char *dgst, int dgst_len, |
114 | const ECDSA_SIG *sig, EC_KEY* eckey); | 112 | const ECDSA_SIG *sig, EC_KEY* eckey); |
115 | 113 | ||
@@ -119,13 +117,8 @@ const ECDSA_METHOD *ECDSA_get_default_method(void); | |||
119 | int ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth); | 117 | int ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth); |
120 | int ECDSA_size(const EC_KEY *eckey); | 118 | int ECDSA_size(const EC_KEY *eckey); |
121 | 119 | ||
122 | int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, | ||
123 | BIGNUM **rp); | ||
124 | int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen, | 120 | int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen, |
125 | unsigned char *sig, unsigned int *siglen, EC_KEY *eckey); | 121 | unsigned char *sig, unsigned int *siglen, EC_KEY *eckey); |
126 | int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen, | ||
127 | unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv, | ||
128 | const BIGNUM *rp, EC_KEY *eckey); | ||
129 | int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen, | 122 | int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen, |
130 | const unsigned char *sig, int siglen, EC_KEY *eckey); | 123 | const unsigned char *sig, int siglen, EC_KEY *eckey); |
131 | 124 | ||
diff --git a/src/lib/libcrypto/hidden/openssl/ecdsa.h b/src/lib/libcrypto/hidden/openssl/ecdsa.h index ef8a789939..b2563ed37d 100644 --- a/src/lib/libcrypto/hidden/openssl/ecdsa.h +++ b/src/lib/libcrypto/hidden/openssl/ecdsa.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ecdsa.h,v 1.2 2023/07/07 19:37:54 beck Exp $ */ | 1 | /* $OpenBSD: ecdsa.h,v 1.3 2023/07/28 08:49:43 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Bob Beck <beck@openbsd.org> | 3 | * Copyright (c) 2023 Bob Beck <beck@openbsd.org> |
4 | * | 4 | * |
@@ -34,16 +34,13 @@ LCRYPTO_USED(ECDSA_SIG_get0_r); | |||
34 | LCRYPTO_USED(ECDSA_SIG_get0_s); | 34 | LCRYPTO_USED(ECDSA_SIG_get0_s); |
35 | LCRYPTO_USED(ECDSA_SIG_set0); | 35 | LCRYPTO_USED(ECDSA_SIG_set0); |
36 | LCRYPTO_USED(ECDSA_do_sign); | 36 | LCRYPTO_USED(ECDSA_do_sign); |
37 | LCRYPTO_USED(ECDSA_do_sign_ex); | ||
38 | LCRYPTO_USED(ECDSA_do_verify); | 37 | LCRYPTO_USED(ECDSA_do_verify); |
39 | LCRYPTO_USED(ECDSA_OpenSSL); | 38 | LCRYPTO_USED(ECDSA_OpenSSL); |
40 | LCRYPTO_USED(ECDSA_set_default_method); | 39 | LCRYPTO_USED(ECDSA_set_default_method); |
41 | LCRYPTO_USED(ECDSA_get_default_method); | 40 | LCRYPTO_USED(ECDSA_get_default_method); |
42 | LCRYPTO_USED(ECDSA_set_method); | 41 | LCRYPTO_USED(ECDSA_set_method); |
43 | LCRYPTO_USED(ECDSA_size); | 42 | LCRYPTO_USED(ECDSA_size); |
44 | LCRYPTO_USED(ECDSA_sign_setup); | ||
45 | LCRYPTO_USED(ECDSA_sign); | 43 | LCRYPTO_USED(ECDSA_sign); |
46 | LCRYPTO_USED(ECDSA_sign_ex); | ||
47 | LCRYPTO_USED(ECDSA_verify); | 44 | LCRYPTO_USED(ECDSA_verify); |
48 | LCRYPTO_USED(ECDSA_get_ex_new_index); | 45 | LCRYPTO_USED(ECDSA_get_ex_new_index); |
49 | LCRYPTO_USED(ECDSA_set_ex_data); | 46 | LCRYPTO_USED(ECDSA_set_ex_data); |