119 #include "../../internal.h"
120 #include "../rand/internal.h"
144 if (
bits > INT_MAX - (BN_BITS2 - 1)) {
149 int words = (
bits + BN_BITS2 - 1) / BN_BITS2;
150 int bit = (
bits - 1) % BN_BITS2;
151 const BN_ULONG kOne = 1;
152 const BN_ULONG kThree = 3;
153 BN_ULONG mask = bit < BN_BITS2 - 1 ? (kOne << (bit + 1)) - 1 : BN_MASK2;
159 rnd->
d[
words - 1] &= mask;
164 rnd->
d[
words - 2] |= kOne << (BN_BITS2 - 1);
166 rnd->
d[
words - 1] |= kThree << (bit - 1);
169 rnd->
d[
words - 1] |= kOne << bit;
199 "crypto_word_t is too small");
200 crypto_word_t mask = 0;
201 for (
size_t i = 1;
i <
len;
i++) {
211 const BN_ULONG *max_exclusive,
size_t len) {
217 size_t min_inclusive,
const BN_ULONG *max_exclusive,
221 while (
words > 0 && max_exclusive[
words - 1] == 0) {
225 (
words == 1 && max_exclusive[0] <= min_inclusive)) {
229 BN_ULONG mask = max_exclusive[
words - 1];
236 #if defined(OPENSSL_64_BIT)
246 const BN_ULONG *max_exclusive,
size_t len,
247 const uint8_t additional_data[32]) {
264 unsigned count = 100;
284 const BIGNUM *max_exclusive) {
293 r->width = max_exclusive->
width;
298 const BIGNUM *max_exclusive) {
302 max_exclusive->
width) ||
310 if (
words == 1 && min_inclusive > mask >> 1) {
322 crypto_word_t in_range = *out_is_uniform;
323 in_range = 0 - in_range;