118 static int bnrand(
int pseudorand,
BIGNUM *rnd,
int bits,
int top,
int bottom)
120 unsigned char *buf=NULL;
121 int ret=0,bit,
bytes,mask;
164 for (i = 0; i <
bytes; i++)
167 if (c >= 128 && i > 0)
188 buf[0]|=(3<<(bit-1));
213 return bnrand(0, rnd, bits, top, bottom);
218 return bnrand(1, rnd, bits, top, bottom);
224 return bnrand(2, rnd, bits, top, bottom);
230 static int bn_rand_range(
int pseudo,
BIGNUM *r,
const BIGNUM *range)
254 if (!bn_rand(r, n + 1, -1, 0))
return 0;
260 if (
BN_cmp(r ,range) >= 0)
262 if (!
BN_sub(r, r, range))
return 0;
263 if (
BN_cmp(r, range) >= 0)
264 if (!
BN_sub(r, r, range))
return 0;
274 while (
BN_cmp(r, range) >= 0);
281 if (!bn_rand(r, n, -1, 0))
return 0;
289 while (
BN_cmp(r, range) >= 0);
299 return bn_rand_range(0, r, range);
304 return bn_rand_range(1, r, range);