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.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c
index 91b8e34ae6..943712c15b 100644
--- a/src/lib/libcrypto/bn/bn_rand.c
+++ b/src/lib/libcrypto/bn/bn_rand.c
@@ -62,7 +62,7 @@
62#include "bn_lcl.h" 62#include "bn_lcl.h"
63#include <openssl/rand.h> 63#include <openssl/rand.h>
64 64
65int BN_rand(BIGNUM *rnd, int bits, int top, int bottom) 65static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
66 { 66 {
67 unsigned char *buf=NULL; 67 unsigned char *buf=NULL;
68 int ret=0,bit,bytes,mask; 68 int ret=0,bit,bytes,mask;
@@ -81,9 +81,19 @@ int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
81 81
82 /* make a random number and set the top and bottom bits */ 82 /* make a random number and set the top and bottom bits */
83 time(&tim); 83 time(&tim);
84 RAND_seed(&tim,sizeof(tim)); 84 RAND_add(&tim,sizeof(tim),0);
85
86 if (pseudorand)
87 {
88 if (RAND_pseudo_bytes(buf, bytes) == -1)
89 goto err;
90 }
91 else
92 {
93 if (RAND_bytes(buf, bytes) <= 0)
94 goto err;
95 }
85 96
86 RAND_bytes(buf,(int)bytes);
87 if (top) 97 if (top)
88 { 98 {
89 if (bit == 0) 99 if (bit == 0)
@@ -115,3 +125,12 @@ err:
115 return(ret); 125 return(ret);
116 } 126 }
117 127
128int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
129 {
130 return bnrand(0, rnd, bits, top, bottom);
131 }
132
133int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom)
134 {
135 return bnrand(1, rnd, bits, top, bottom);
136 }