summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_rand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/bn_rand.c')
-rw-r--r--src/lib/libcrypto/bn/bn_rand.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c
index acb17882ef..334c65dd57 100644
--- a/src/lib/libcrypto/bn/bn_rand.c
+++ b/src/lib/libcrypto/bn/bn_rand.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_rand.c,v 1.15 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: bn_rand.c,v 1.16 2014/10/22 13:02:04 jsing 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 *
@@ -110,10 +110,10 @@
110 */ 110 */
111 111
112#include <stdio.h> 112#include <stdio.h>
113#include <stdlib.h>
113#include <time.h> 114#include <time.h>
114 115
115#include <openssl/err.h> 116#include <openssl/err.h>
116#include <openssl/rand.h>
117 117
118#include "bn_lcl.h" 118#include "bn_lcl.h"
119 119
@@ -139,14 +139,7 @@ bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
139 } 139 }
140 140
141 /* make a random number and set the top and bottom bits */ 141 /* make a random number and set the top and bottom bits */
142 142 arc4random_buf(buf, bytes);
143 if (pseudorand) {
144 if (RAND_pseudo_bytes(buf, bytes) == -1)
145 goto err;
146 } else {
147 if (RAND_bytes(buf, bytes) <= 0)
148 goto err;
149 }
150 143
151#if 1 144#if 1
152 if (pseudorand == 2) { 145 if (pseudorand == 2) {
@@ -156,7 +149,7 @@ bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
156 unsigned char c; 149 unsigned char c;
157 150
158 for (i = 0; i < bytes; i++) { 151 for (i = 0; i < bytes; i++) {
159 RAND_pseudo_bytes(&c, 1); 152 arc4random_buf(&c, 1);
160 if (c >= 128 && i > 0) 153 if (c >= 128 && i > 0)
161 buf[i] = buf[i - 1]; 154 buf[i] = buf[i - 1];
162 else if (c < 42) 155 else if (c < 42)