#include <inttypes.h>
#include "../common/namespace.h"
Go to the source code of this file.
◆ random_boundedl1
#define random_boundedl1 COMMON(random_boundedl1) |
◆ random_coin
#define random_coin COMMON(random_coin) |
◆ random_coin()
int64_t random_coin |
( |
uint64_t | num, |
|
|
uint64_t | den ) |
Definition at line 198 of file random.c.
199{
200 uint8_t buf[32];
201 uint64_t r = 0;
202
204
205 for (
long long i = 0;
i < 256; ++
i)
206 {
207 uint64_t bit = 1 & (buf[
i / 8] >> (
i & 7));
208 r <<= 1;
209 r += bit;
210 r ^= (~uint64mask_lessthan(r, den)) & (r ^ (r - den));
211 }
212
213
214 return uint64mask_lessthan(r,
num);
215}
void randombytes(void *x, size_t l)
References i, num, and randombytes().
◆ random_wombats()
void random_wombats |
( |
uint8_t * | key, |
|
|
const long long | numkeys, |
|
|
const long long | batch_start, |
|
|
const long long | batch_stop, |
|
|
const long long | batch_sumykeys ) |
Definition at line 15 of file random.c.
16{
18 int32_t r[4 * batch_len];
19 uint8_t ells[numkeys];
20 for (;;)
21 {
23 for (
long long j = 0;
j < batch_len; ++
j)
25 for (
long long j = 0;
j < numkeys; ++
j)
28
29 long long collision = 0;
30 for (
long long j = 1;
j < numkeys; ++
j)
31 collision |= int32mask_zero((r[
j] ^ r[
j - 1]) & ~1);
32
33#ifdef ENABLE_CT_TESTING
34 VALGRIND_MAKE_MEM_DEFINED(&collision, sizeof(collision));
35#endif
36 if (collision)
37 continue;
38
39 for (int32_t
j = 0;
j < numkeys; ++
j)
41
42 for (int32_t
j = 0;
j < batch_len; ++
j)
44
45 for (int32_t
i = 0;
i < numkeys; ++
i)
46 {
47 for (int32_t
j =
i;
j < batch_len; ++
j)
48 {
49
50 int32_t updatemask = int32mask_zero(ells[
i]) & int32mask_nonzero(r[
j]);
51 r[
j] ^= (1 & updatemask);
52 ells[
i] |= (updatemask & (
j + 1));
53 }
54 }
55
56 for (int32_t
i = 0;
i < numkeys; ++
i)
58
59 return;
60 }
61}
References batch_start, batch_stop, i, int32_sort, j, and randombytes().