summaryrefslogtreecommitdiff
path: root/src/regress/lib
diff options
context:
space:
mode:
authortb <>2023-08-03 18:53:56 +0000
committertb <>2023-08-03 18:53:56 +0000
commite680fe5b2098d1406fab3bb3994254f026651090 (patch)
tree3779d2c9bdc12cd8a0d0eb7981bf515d6e27b344 /src/regress/lib
parent9110c93cd11bc18d800c645352c10a57e2ceea4b (diff)
downloadopenbsd-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/regress/lib')
-rw-r--r--src/regress/lib/libcrypto/bn/bn_isqrt.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/regress/lib/libcrypto/bn/bn_isqrt.c b/src/regress/lib/libcrypto/bn/bn_isqrt.c
index 2663bb74e9..d8a2d2755f 100644
--- a/src/regress/lib/libcrypto/bn/bn_isqrt.c
+++ b/src/regress/lib/libcrypto/bn/bn_isqrt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_isqrt.c,v 1.3 2023/03/08 06:28:08 tb Exp $ */ 1/* $OpenBSD: bn_isqrt.c,v 1.4 2023/08/03 18:53:56 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> 3 * Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
4 * 4 *
@@ -194,8 +194,8 @@ isqrt_test(void)
194 if (!BN_set_bit(upper, UPPER_BITS)) 194 if (!BN_set_bit(upper, UPPER_BITS))
195 errx(1, "BN_set_bit(upper, %d)", UPPER_BITS); 195 errx(1, "BN_set_bit(upper, %d)", UPPER_BITS);
196 196
197 if (!bn_rand_interval(n, lower, upper)) 197 if (!bn_rand_in_range(n, lower, upper))
198 errx(1, "bn_rand_interval n"); 198 errx(1, "bn_rand_in_range n");
199 199
200 /* n_sqr = n^2 */ 200 /* n_sqr = n^2 */
201 if (!BN_sqr(n_sqr, n, ctx)) 201 if (!BN_sqr(n_sqr, n, ctx))
@@ -246,8 +246,8 @@ isqrt_test(void)
246 */ 246 */
247 247
248 for (i = 0; i < N_TESTS; i++) { 248 for (i = 0; i < N_TESTS; i++) {
249 if (!bn_rand_interval(testcase, n_sqr, upper)) 249 if (!bn_rand_in_range(testcase, n_sqr, upper))
250 errx(1, "bn_rand_interval testcase"); 250 errx(1, "bn_rand_in_range testcase");
251 251
252 if (!bn_isqrt(isqrt, &is_perfect_square, testcase, ctx)) 252 if (!bn_isqrt(isqrt, &is_perfect_square, testcase, ctx))
253 errx(1, "bn_isqrt testcase"); 253 errx(1, "bn_isqrt testcase");