Skip to content

Commit 8e86d9d

Browse files
author
tb
committed
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]...
1 parent 6d3b5c4 commit 8e86d9d

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/regress/lib/libcrypto/bn/bn_mod_exp.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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 $ */
22
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
33
* All rights reserved.
44
*
@@ -73,7 +73,7 @@ main(int argc, char *argv[])
7373
BIGNUM *r_mont, *r_mont_const, *r_recp, *r_simple;
7474
BIGNUM *r_mont_ct, *r_mont_nonct, *a, *b, *m;
7575
BN_CTX *ctx;
76-
unsigned char c;
76+
int c;
7777
int i, ret;
7878

7979
ERR_load_BN_strings();
@@ -103,18 +103,15 @@ main(int argc, char *argv[])
103103
goto err;
104104

105105
for (i = 0; i < 200; i++) {
106-
arc4random_buf(&c, 1);
107-
c = (c % BN_BITS) - BN_BITS2;
106+
c = (arc4random() % BN_BITS) - BN_BITS2;
108107
if (!BN_rand(a, NUM_BITS + c, 0, 0))
109108
goto err;
110109

111-
arc4random_buf(&c, 1);
112-
c = (c % BN_BITS) - BN_BITS2;
110+
c = (arc4random() % BN_BITS) - BN_BITS2;
113111
if (!BN_rand(b, NUM_BITS + c, 0, 0))
114112
goto err;
115113

116-
arc4random_buf(&c, 1);
117-
c = (c % BN_BITS) - BN_BITS2;
114+
c = (arc4random() % BN_BITS) - BN_BITS2;
118115
if (!BN_rand(m, NUM_BITS + c, 0, 1))
119116
goto err;
120117

0 commit comments

Comments
 (0)