Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
random.h File Reference
#include <inttypes.h>
#include "../common/namespace.h"
Include dependency graph for random.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define random_boundedl1   COMMON(random_boundedl1)
#define random_coin   COMMON(random_coin)

Functions

int64_t random_coin (uint64_t num, uint64_t den)
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)

Macro Definition Documentation

◆ random_boundedl1

#define random_boundedl1   COMMON(random_boundedl1)

Definition at line 7 of file random.h.

◆ random_coin

#define random_coin   COMMON(random_coin)

Definition at line 8 of file random.h.

Function Documentation

◆ 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
203 randombytes(buf, sizeof buf);
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 // XXX: speed this up
213
214 return uint64mask_lessthan(r, num);
215}
void randombytes(void *x, size_t l)
Definition rng.c:8
num
for i

References i, num, and randombytes().

Here is the call graph for this function:

◆ 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{
17 int32_t batch_len = batch_stop - batch_start;
18 int32_t r[4 * batch_len];
19 uint8_t ells[numkeys];
20 for (;;)
21 { /* rejection-sampling loop */
22 randombytes(r, 4 * batch_len);
23 for (long long j = 0; j < batch_len; ++j)
24 r[j] &= ~1;
25 for (long long j = 0; j < numkeys; ++j)
26 r[j] |= 1;
27 int32_sort(r, batch_len);
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)
40 ells[j] = 0;
41
42 for (int32_t j = 0; j < batch_len; ++j)
43 r[j] &= 1;
44
45 for (int32_t i = 0; i < numkeys; ++i)
46 {
47 for (int32_t j = i; j < batch_len; ++j)
48 {
49 // r[j] &= 1;
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)
57 key[batch_sumykeys + i] = batch_start + ells[i] - 1;
58
59 return;
60 }
61}
#define int32_sort
Definition int32_sort.h:6
for j
#define batch_start
Definition primes.h:55
#define batch_stop
Definition primes.h:56

References batch_start, batch_stop, i, int32_sort, j, and randombytes().

Here is the call graph for this function: