Skip to content

Commit 2b745f2

Browse files
author
tb
committed
Check BN_rand() and BN_mod() return values
CID 430848 CID 430849
1 parent 4fbc023 commit 2b745f2

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: bn_mod_exp.c,v 1.2 2022/12/02 17:33:38 tb Exp $ */
1+
/* $OpenBSD: bn_mod_exp.c,v 1.3 2022/12/02 17:42:45 tb Exp $ */
22
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
33
* All rights reserved.
44
*
@@ -108,18 +108,23 @@ main(int argc, char *argv[])
108108
for (i = 0; i < 200; i++) {
109109
arc4random_buf(&c, 1);
110110
c = (c % BN_BITS) - BN_BITS2;
111-
BN_rand(a, NUM_BITS + c, 0, 0);
111+
if (!BN_rand(a, NUM_BITS + c, 0, 0))
112+
goto err;
112113

113114
arc4random_buf(&c, 1);
114115
c = (c % BN_BITS) - BN_BITS2;
115-
BN_rand(b, NUM_BITS + c, 0, 0);
116+
if (!BN_rand(b, NUM_BITS + c, 0, 0))
117+
goto err;
116118

117119
arc4random_buf(&c, 1);
118120
c = (c % BN_BITS) - BN_BITS2;
119-
BN_rand(m, NUM_BITS + c, 0, 1);
121+
if (!BN_rand(m, NUM_BITS + c, 0, 1))
122+
goto err;
120123

121-
BN_mod(a, a, m, ctx);
122-
BN_mod(b, b, m, ctx);
124+
if (!BN_mod(a, a, m, ctx))
125+
goto err;
126+
if (!BN_mod(b, b, m, ctx))
127+
goto err;
123128

124129
ret = BN_mod_exp_mont(r_mont, a, b, m, ctx, NULL);
125130
if (ret <= 0) {

0 commit comments

Comments
 (0)