test_mont was exercising 100-bit multiplication modulus X*I-bit, where
[openssl.git] / crypto / bn / bn_rand.c
index 75b6b0493b1015da080b9c93cf81733737d77417..943712c15b8f2e31b374f4e9af98000cfc43225b 100644 (file)
 #include <time.h>
 #include "cryptlib.h"
 #include "bn_lcl.h"
-#include "rand.h"
+#include <openssl/rand.h>
 
-int BN_rand(rnd, bits, top, bottom)
-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;
@@ -85,9 +81,19 @@ int bottom;
 
        /* make a random number and set the top and bottom bits */
        time(&tim);
-       RAND_seed((unsigned char *)&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)
@@ -119,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);
+       }