Lines Matching defs:range
221 /* random number r: 0 <= r < range */
222 static int bn_rand_range(int pseudo, BIGNUM *r, const BIGNUM *range)
229 if (range->neg || BN_is_zero(range)) {
234 n = BN_num_bits(range); /* n > 0 */
236 /* BN_is_bit_set(range, n - 1) always holds */
240 else if (!BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3)) {
242 * range = 100..._2, so 3*range (= 11..._2) is exactly one bit longer
243 * than range
249 * If r < 3*range, use r := r MOD range (which is either r, r -
250 * range, or r - 2*range). Otherwise, iterate once more. Since
251 * 3*range = 11..._2, each iteration succeeds with probability >=
254 if (BN_cmp(r, range) >= 0) {
255 if (!BN_sub(r, r, range))
257 if (BN_cmp(r, range) >= 0)
258 if (!BN_sub(r, r, range))
268 while (BN_cmp(r, range) >= 0);
271 /* range = 11..._2 or range = 101..._2 */
280 while (BN_cmp(r, range) >= 0);
287 int BN_rand_range(BIGNUM *r, const BIGNUM *range)
289 return bn_rand_range(0, r, range);
292 int BN_pseudo_rand_range(BIGNUM *r, const BIGNUM *range)
294 return bn_rand_range(1, r, range);