diff options
author | tb <> | 2023-08-03 18:53:56 +0000 |
---|---|---|
committer | tb <> | 2023-08-03 18:53:56 +0000 |
commit | e680fe5b2098d1406fab3bb3994254f026651090 (patch) | |
tree | 3779d2c9bdc12cd8a0d0eb7981bf515d6e27b344 /src/lib/libcrypto/ec/ec_key.c | |
parent | 9110c93cd11bc18d800c645352c10a57e2ceea4b (diff) | |
download | openbsd-e680fe5b2098d1406fab3bb3994254f026651090.tar.gz openbsd-e680fe5b2098d1406fab3bb3994254f026651090.tar.bz2 openbsd-e680fe5b2098d1406fab3bb3994254f026651090.zip |
Make the bn_rand_interval() API a bit more ergonomic
Provide bn_rand_in_range() which is a slightly tweaked version of what was
previously called bn_rand_range().
The way bn_rand_range() is called in libcrypto, the lower bound is always
expressible as a word. In fact, most of the time it is 1, the DH code uses
a 2, the MR tests in BPSW use 3 and an exceptinally high number appears in
the Tonelli-Shanks implementation where we use 32. Converting these lower
bounds to BIGNUMs on the call site is annoying so let bn_rand_interval()
do that internally and route that through bn_rand_in_range(). This way we
can avoid using BN_sub_word().
Adjust the bn_isqrt() test to use bn_rand_in_range() since that's the
only caller that uses actual BIGNUMs as lower bounds.
ok jsing
Diffstat (limited to 'src/lib/libcrypto/ec/ec_key.c')
-rw-r--r-- | src/lib/libcrypto/ec/ec_key.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/lib/libcrypto/ec/ec_key.c b/src/lib/libcrypto/ec/ec_key.c index e5ff189803..d9ddd5d797 100644 --- a/src/lib/libcrypto/ec/ec_key.c +++ b/src/lib/libcrypto/ec/ec_key.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_key.c,v 1.36 2023/07/07 13:54:45 beck Exp $ */ | 1 | /* $OpenBSD: ec_key.c,v 1.37 2023/08/03 18:53:56 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -269,7 +269,7 @@ ec_key_gen(EC_KEY *eckey) | |||
269 | 269 | ||
270 | if ((order = EC_GROUP_get0_order(eckey->group)) == NULL) | 270 | if ((order = EC_GROUP_get0_order(eckey->group)) == NULL) |
271 | goto err; | 271 | goto err; |
272 | if (!bn_rand_interval(priv_key, BN_value_one(), order)) | 272 | if (!bn_rand_interval(priv_key, 1, order)) |
273 | goto err; | 273 | goto err; |
274 | if (!EC_POINT_mul(eckey->group, pub_key, priv_key, NULL, NULL, NULL)) | 274 | if (!EC_POINT_mul(eckey->group, pub_key, priv_key, NULL, NULL, NULL)) |
275 | goto err; | 275 | goto err; |