summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2022-12-03 08:05:52 +0000
committertb <>2022-12-03 08:05:52 +0000
commit2144af446f33a4d2a7f49c3b448e506ed6f3cd62 (patch)
tree317e4fc69c6e7d6202f03d8464c5005cbe0c4d19 /src
parent57f24ec1b0bbd51340fca9a724ac63b2daff089c (diff)
downloadopenbsd-2144af446f33a4d2a7f49c3b448e506ed6f3cd62.tar.gz
openbsd-2144af446f33a4d2a7f49c3b448e506ed6f3cd62.tar.bz2
openbsd-2144af446f33a4d2a7f49c3b448e506ed6f3cd62.zip
Fix some ancient silliness with a random byte
For nearly 25 years this test has attempted to generate random numbers of bit length between 192 and 319 bits. Unfortunately, it used an unsigned char so instead of generating numbers in the interval [-64..63] and add them to 256, it used numbers in the intervals [0..63] and [192..255]...
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/bn/bn_mod_exp.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/regress/lib/libcrypto/bn/bn_mod_exp.c b/src/regress/lib/libcrypto/bn/bn_mod_exp.c
index 236851bc75..f7be5110ea 100644
--- a/src/regress/lib/libcrypto/bn/bn_mod_exp.c
+++ b/src/regress/lib/libcrypto/bn/bn_mod_exp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_mod_exp.c,v 1.5 2022/12/02 18:31:40 tb Exp $ */ 1/* $OpenBSD: bn_mod_exp.c,v 1.6 2022/12/03 08:05:52 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -73,7 +73,7 @@ main(int argc, char *argv[])
73 BIGNUM *r_mont, *r_mont_const, *r_recp, *r_simple; 73 BIGNUM *r_mont, *r_mont_const, *r_recp, *r_simple;
74 BIGNUM *r_mont_ct, *r_mont_nonct, *a, *b, *m; 74 BIGNUM *r_mont_ct, *r_mont_nonct, *a, *b, *m;
75 BN_CTX *ctx; 75 BN_CTX *ctx;
76 unsigned char c; 76 int c;
77 int i, ret; 77 int i, ret;
78 78
79 ERR_load_BN_strings(); 79 ERR_load_BN_strings();
@@ -103,18 +103,15 @@ main(int argc, char *argv[])
103 goto err; 103 goto err;
104 104
105 for (i = 0; i < 200; i++) { 105 for (i = 0; i < 200; i++) {
106 arc4random_buf(&c, 1); 106 c = (arc4random() % BN_BITS) - BN_BITS2;
107 c = (c % BN_BITS) - BN_BITS2;
108 if (!BN_rand(a, NUM_BITS + c, 0, 0)) 107 if (!BN_rand(a, NUM_BITS + c, 0, 0))
109 goto err; 108 goto err;
110 109
111 arc4random_buf(&c, 1); 110 c = (arc4random() % BN_BITS) - BN_BITS2;
112 c = (c % BN_BITS) - BN_BITS2;
113 if (!BN_rand(b, NUM_BITS + c, 0, 0)) 111 if (!BN_rand(b, NUM_BITS + c, 0, 0))
114 goto err; 112 goto err;
115 113
116 arc4random_buf(&c, 1); 114 c = (arc4random() % BN_BITS) - BN_BITS2;
117 c = (c % BN_BITS) - BN_BITS2;
118 if (!BN_rand(m, NUM_BITS + c, 0, 1)) 115 if (!BN_rand(m, NUM_BITS + c, 0, 1))
119 goto err; 116 goto err;
120 117