"print" is GNU bc specific.
[oweals/openssl.git] / crypto / bn / bn_rand.c
index 7d6f635b70c771a26d1454d4e9945da2acbea866..943712c15b8f2e31b374f4e9af98000cfc43225b 100644 (file)
@@ -60,9 +60,9 @@
 #include <time.h>
 #include "cryptlib.h"
 #include "bn_lcl.h"
-#include "rand.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;
@@ -81,9 +81,19 @@ int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
 
        /* make a random number and set the top and bottom bits */
        time(&tim);
-       RAND_seed(&tim,sizeof(tim));
+       RAND_add(&tim,sizeof(tim),0);
+
+       if (pseudorand)
+               {
+               if (RAND_pseudo_bytes(buf, bytes) == -1)
+                       goto err;
+               }
+       else
+               {
+               if (RAND_bytes(buf, bytes) <= 0)
+                       goto err;
+               }
 
-       RAND_bytes(buf,(int)bytes);
        if (top)
                {
                if (bit == 0)
@@ -115,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);
+       }