seeded.h

The seeded sampler: values that are a pure function of a context and a seed.

What a protocol uses for values both parties must agree on, such as challenges derived from a transcript. The sequence is defined by its index: attempt stream k is BLAKE3 in derive-key mode with context over seed || LE64(k), and value i is word i of stream 0 masked to the bits of bound - 1, falling through to word i of streams 1, 2, … while the masked word is not below bound. Values are exactly uniform, identical on every engine, and independent of how many are asked for.

Note

Thread-safe; no state. Not constant time in bound.

Functions

void seeded_below_from(uint64_t *out, uint64_t count, uint64_t start, uint64_t bound, const char *context, const uint8_t *seed, uint64_t seed_len)

Writes values [start, start + count) of the sequence.

Each position is located by its index, so a window costs what its own values cost.

Parameters:
  • out – [out] Receives count values.

  • count – [in] Values.

  • start – [in] Index of the first.

  • bound – [in] Values are below it; at least 1.

  • context – [in] A NUL-terminated domain-separation tag: a fixed string literal per call site, never caller data.

  • seed – [in] Any length.

  • seed_len – [in] Bytes of seed.

Pre:

bound is at least 1.

void seeded_below(uint64_t *out, uint64_t count, uint64_t bound, const char *context, const uint8_t *seed, uint64_t seed_len)

Writes values [0, count) of the sequence: seeded_below_from() with start = 0.

Parameters:
  • out – [out] Receives count values.

  • count – [in] Values.

  • bound – [in] Values are below it; at least 1.

  • context – [in] As in seeded_below_from().

  • seed – [in] Any length.

  • seed_len – [in] Bytes of seed.

Pre:

bound is at least 1.