summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libcrypto/bn/bn_rand.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/libcrypto/bn/bn_rand.c b/lib/libcrypto/bn/bn_rand.c
index df798f41bc4..4626960a0dd 100644
--- a/lib/libcrypto/bn/bn_rand.c
+++ b/lib/libcrypto/bn/bn_rand.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bn_rand.c,v 1.22 2018/11/06 06:49:45 tb Exp $ */
+/* $OpenBSD: bn_rand.c,v 1.23 2020/09/12 15:24:39 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -129,6 +129,11 @@ bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
return (0);
}
+ if (bits < 0 || (bits == 1 && top > 0)) {
+ BNerror(BN_R_BITS_TOO_SMALL);
+ return (0);
+ }
+
if (bits == 0) {
BN_zero(rnd);
return (1);
@@ -166,8 +171,8 @@ bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
}
#endif
- if (top != -1) {
- if (top) {
+ if (top >= 0) {
+ if (top > 0) {
if (bit == 0) {
buf[0] = 1;
buf[1] |= 0x80;