Functions for generating random traversal orders. More...
Go to the source code of this file.
Data Structures | |
struct | random_order |
Context for a random traversal order. More... | |
Macros | |
#define | RANDOM_ORDER_HARDENED_CHECK_DONE(ctx_) |
Hardened check that a random_order iteration is complete. | |
Typedefs | |
typedef struct random_order | random_order_t |
Context for a random traversal order. | |
Functions | |
uint32_t | random_order_random_word (void) |
Expects some external implementation of randomness to be linked. | |
void | random_order_init (random_order_t *ctx, size_t min_len) |
Constructs a new, randomly-seeded traversal order, running from 0 to at least min_len . | |
size_t | random_order_len (const random_order_t *ctx) |
Returns the length of the sequence represented by ctx . | |
size_t | random_order_advance (random_order_t *ctx) |
Returns the next element in the sequence represented by ctx . | |
Functions for generating random traversal orders.
Definition in file random_order.h.
struct random_order |
Context for a random traversal order.
A "random traversal order" specifies a random order to walk through some buffer of length n
, which is an important building block for constant-power code. Given n
, the random order emits integers in the range 0..m
, where m
is an implementation-defined, per-random-order value greater than n
. The order is guaranteed to visit each integer in 0..n
at least once, but with some caveats:
n
may be returned.Users must be mindful of these constraints when using random_order_t
. These caveats are intended to allow for implementation flexibility, such as intentionally adding decoys to the sequence.
Definition at line 45 of file random_order.h.
Data Fields | ||
---|---|---|
size_t | ctr | Total number of iterations so far. |
size_t | max | Maximum index to return (exclusive). |
size_t | state | Next index to return. |
size_t | step | Step size. |
#define RANDOM_ORDER_HARDENED_CHECK_DONE | ( | ctx_ | ) |
Hardened check that a random_order iteration is complete.
ctx | The context to check. |
Definition at line 69 of file random_order.h.
typedef struct random_order random_order_t |
Context for a random traversal order.
A "random traversal order" specifies a random order to walk through some buffer of length n
, which is an important building block for constant-power code. Given n
, the random order emits integers in the range 0..m
, where m
is an implementation-defined, per-random-order value greater than n
. The order is guaranteed to visit each integer in 0..n
at least once, but with some caveats:
n
may be returned.Users must be mindful of these constraints when using random_order_t
. These caveats are intended to allow for implementation flexibility, such as intentionally adding decoys to the sequence.
size_t random_order_advance | ( | random_order_t * | ctx | ) |
Returns the next element in the sequence represented by ctx
.
See random_order_len()
for discovering how many times this function can be called.
ctx | The context to advance. |
Definition at line 42 of file random_order.c.
void random_order_init | ( | random_order_t * | ctx, |
size_t | min_len ) |
Constructs a new, randomly-seeded traversal order, running from 0
to at least min_len
.
This function does not take a seed as input; instead, the seed is extracted, in some manner or another, from the hardware by this function.
The EDN must be initialized before calling this function, since it uses the Ibex RND interface and will wait until entropy is available.
rnd | Function to call for fresh randomness. |
ctx | The context to initialize. |
min_len | The minimum length this traversal order must visit. |
Definition at line 10 of file random_order.c.
size_t random_order_len | ( | const random_order_t * | ctx | ) |
Returns the length of the sequence represented by ctx
.
This value may be greater than min_len
specified in random_order_init()
, but the sequence is guaranteed to contain every integer in 0..min_len
.
This value represents the number of times random_order_advance()
may be called.
ctx | The context to query. |
Definition at line 40 of file random_order.c.
|
extern |
Expects some external implementation of randomness to be linked.