std1.0.0-beta-7 SafeC docs

std :: crypto::rng

Struct std::RngCtx

#include <std/crypto/rng.h> source

struct RngCtx {
    unsigned int state[16];
    unsigned char buf[RNG_BLOCK_SIZE];
    unsigned long buf_pos;
}

Fields

§unsigned int state[16]source

ChaCha20 key + nonce + counter

§unsigned char buf[RNG_BLOCK_SIZE]source
§unsigned long buf_possource

next byte to consume from buf

Methods

§int init()source · definition

Initialise in place with automatic seeding (the OS's random source, else rdrand on x86-64, else /dev/urandom). Returns 1; aborts with a diagnostic if no entropy source is available (use init_seed() with your own entropy source on such targets).

§void init_seed(const unsigned char seed[32])source · definition

Initialise in place with a user-provided 32-byte seed (deterministic; useful for tests).

§void fill([]unsigned char out)source · definition

Fill out[0..len-1] with cryptographically strong random bytes.

§unsigned int rand32()source · definition

Return a random 32-bit unsigned integer.

§unsigned long long rand64()source · definition

Return a random 64-bit unsigned integer.

§unsigned long rand_range(unsigned long bound)source · definition

Return a uniform random integer in [0, bound).