Module sodiumoxide::randombytes[][src]

Expand description

Cryptographic random number generation.

Structs

Seed

Seed bytes for the deterministic random functions

Constants

SEEDBYTES

The number of seed bytes to use for the deterministic RNG functions randombytes_buf_deterministic() and randombytes_buf_deterministic_into()

Functions

randombytes

randombytes() randomly generates size bytes of data.

randombytes_buf_deterministic

WARNING: you should only use this function for testing purposes or a known good use case in which it is acceptable to rely on the secrecy of the seed passed to randombytes_buf_deterministic. The function is (as its name suggests) entirely deterministic given knowledge of the seed. It does not incorporate entropy of any form and should almost never be used for cryptographic purposes. If you need to generate a deterministic stream of cryptographic quality pseudo random data you’re better suited using a stream cipher directly e.g. one of the stream ciphers exposed in sodiumoxide::crypto::stream or the higher level secretstream API.

randombytes_buf_deterministic_into

WARNING: using this function in a cryptographic setting is dangerous. Read the full documentation of randombytes_buf_deterministic() before proceeding.

randombytes_into

randombytes_into() fills a buffer buf with random data.

randombytes_uniform

randombytes_uniform() returns an unpredictable value between 0 and upper_bound (excluded). It guarantees a uniform distribution of the possible output values even when upper_bound is not a power of 2. Note that an upper_bound < 2 leaves only a single element to be chosen, namely 0.