summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2023-07-28 08:49:43 +0000
committertb <>2023-07-28 08:49:43 +0000
commit27bf20b08f028e09b36afd8b49d1fbaa87746bb6 (patch)
treeefbe0438383ae81f0c511a990e4a656ecd91e76c /src/lib
parent783244ed4a6bd90016acb876b9752acd0db924be (diff)
downloadopenbsd-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.list3
-rw-r--r--src/lib/libcrypto/Symbols.namespace3
-rw-r--r--src/lib/libcrypto/ecdsa/ecdsa.c19
-rw-r--r--src/lib/libcrypto/ecdsa/ecdsa.h9
-rw-r--r--src/lib/libcrypto/hidden/openssl/ecdsa.h5
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
1028ECDSA_SIG_new 1028ECDSA_SIG_new
1029ECDSA_SIG_set0 1029ECDSA_SIG_set0
1030ECDSA_do_sign 1030ECDSA_do_sign
1031ECDSA_do_sign_ex
1032ECDSA_do_verify 1031ECDSA_do_verify
1033ECDSA_get_default_method 1032ECDSA_get_default_method
1034ECDSA_get_ex_data 1033ECDSA_get_ex_data
@@ -1037,8 +1036,6 @@ ECDSA_set_default_method
1037ECDSA_set_ex_data 1036ECDSA_set_ex_data
1038ECDSA_set_method 1037ECDSA_set_method
1039ECDSA_sign 1038ECDSA_sign
1040ECDSA_sign_ex
1041ECDSA_sign_setup
1042ECDSA_size 1039ECDSA_size
1043ECDSA_verify 1040ECDSA_verify
1044ECPARAMETERS_free 1041ECPARAMETERS_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
74static ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
75 const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey);
76static 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);
79static int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *in_ctx, BIGNUM **out_kinv,
80 BIGNUM **out_r);
81
74static const ASN1_TEMPLATE ECDSA_SIG_seq_tt[] = { 82static 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}
763LCRYPTO_ALIAS(ECDSA_do_sign); 771LCRYPTO_ALIAS(ECDSA_do_sign);
764 772
765ECDSA_SIG * 773static ECDSA_SIG *
766ECDSA_do_sign_ex(const unsigned char *digest, int digest_len, 774ECDSA_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}
775LCRYPTO_ALIAS(ECDSA_do_sign_ex);
776 783
777int 784int
778ECDSA_sign(int type, const unsigned char *digest, int digest_len, 785ECDSA_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}
784LCRYPTO_ALIAS(ECDSA_sign); 791LCRYPTO_ALIAS(ECDSA_sign);
785 792
786int 793static int
787ECDSA_sign_ex(int type, const unsigned char *digest, int digest_len, 794ECDSA_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}
798LCRYPTO_ALIAS(ECDSA_sign_ex);
799 805
800int 806static int
801ECDSA_sign_setup(EC_KEY *key, BN_CTX *in_ctx, BIGNUM **out_kinv, 807ECDSA_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}
810LCRYPTO_ALIAS(ECDSA_sign_setup);
811 816
812int 817int
813ECDSA_do_verify(const unsigned char *digest, int digest_len, 818ECDSA_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
109ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len, 109ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len,
110 EC_KEY *eckey); 110 EC_KEY *eckey);
111ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
112 const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey);
113int ECDSA_do_verify(const unsigned char *dgst, int dgst_len, 111int 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);
119int ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth); 117int ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth);
120int ECDSA_size(const EC_KEY *eckey); 118int ECDSA_size(const EC_KEY *eckey);
121 119
122int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv,
123 BIGNUM **rp);
124int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen, 120int 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);
126int 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);
129int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen, 122int 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);
34LCRYPTO_USED(ECDSA_SIG_get0_s); 34LCRYPTO_USED(ECDSA_SIG_get0_s);
35LCRYPTO_USED(ECDSA_SIG_set0); 35LCRYPTO_USED(ECDSA_SIG_set0);
36LCRYPTO_USED(ECDSA_do_sign); 36LCRYPTO_USED(ECDSA_do_sign);
37LCRYPTO_USED(ECDSA_do_sign_ex);
38LCRYPTO_USED(ECDSA_do_verify); 37LCRYPTO_USED(ECDSA_do_verify);
39LCRYPTO_USED(ECDSA_OpenSSL); 38LCRYPTO_USED(ECDSA_OpenSSL);
40LCRYPTO_USED(ECDSA_set_default_method); 39LCRYPTO_USED(ECDSA_set_default_method);
41LCRYPTO_USED(ECDSA_get_default_method); 40LCRYPTO_USED(ECDSA_get_default_method);
42LCRYPTO_USED(ECDSA_set_method); 41LCRYPTO_USED(ECDSA_set_method);
43LCRYPTO_USED(ECDSA_size); 42LCRYPTO_USED(ECDSA_size);
44LCRYPTO_USED(ECDSA_sign_setup);
45LCRYPTO_USED(ECDSA_sign); 43LCRYPTO_USED(ECDSA_sign);
46LCRYPTO_USED(ECDSA_sign_ex);
47LCRYPTO_USED(ECDSA_verify); 44LCRYPTO_USED(ECDSA_verify);
48LCRYPTO_USED(ECDSA_get_ex_new_index); 45LCRYPTO_USED(ECDSA_get_ex_new_index);
49LCRYPTO_USED(ECDSA_set_ex_data); 46LCRYPTO_USED(ECDSA_set_ex_data);