"print" is GNU bc specific.
[oweals/openssl.git] / crypto / bn / bn_rand.c
index b567b43a6ff96ecd8b925b8a0d791f674db419dd..943712c15b8f2e31b374f4e9af98000cfc43225b 100644 (file)
@@ -62,7 +62,7 @@
 #include "bn_lcl.h"
 #include <openssl/rand.h>
 
-int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
+static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
        {
        unsigned char *buf=NULL;
        int ret=0,bit,bytes,mask;
@@ -83,8 +83,17 @@ int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
        time(&tim);
        RAND_add(&tim,sizeof(tim),0);
 
-       if (RAND_bytes(buf,(int)bytes) <= 0)
-               goto err;
+       if (pseudorand)
+               {
+               if (RAND_pseudo_bytes(buf, bytes) == -1)
+                       goto err;
+               }
+       else
+               {
+               if (RAND_bytes(buf, bytes) <= 0)
+                       goto err;
+               }
+
        if (top)
                {
                if (bit == 0)
@@ -116,3 +125,12 @@ err:
        return(ret);
        }
 
+int     BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
+       {
+       return bnrand(0, rnd, bits, top, bottom);
+       }
+
+int     BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom)
+       {
+       return bnrand(1, rnd, bits, top, bottom);
+       }