X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fbn%2Fbn_rand.c;h=bab4510345090374089fd7d66d1313b88a29b6ed;hp=91b8e34ae65b364c03ed333c5f181ed6840c7aca;hb=111482cf2e1eda0d433f939d23509094da706dc0;hpb=ec577822f95a8bca0023c5c77cef1a4916822d4a diff --git a/crypto/bn/bn_rand.c b/crypto/bn/bn_rand.c index 91b8e34ae6..bab4510345 100644 --- a/crypto/bn/bn_rand.c +++ b/crypto/bn/bn_rand.c @@ -62,17 +62,23 @@ #include "bn_lcl.h" #include -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; time_t tim; + if (bits == 0) + { + BN_zero(rnd); + return 1; + } + bytes=(bits+7)/8; bit=(bits-1)%8; mask=0xff<= 128 && i > 0) + buf[i] = buf[i-1]; + else if (c < 42) + buf[i] = 0; + else if (c < 84) + buf[i] = 255; + } + } +#endif - RAND_bytes(buf,(int)bytes); if (top) { if (bit == 0) @@ -110,8 +147,24 @@ err: if (buf != NULL) { memset(buf,0,bytes); - Free(buf); + OPENSSL_free(buf); } 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); + } + +#if 1 +int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom) + { + return bnrand(2, rnd, bits, top, bottom); + } +#endif