Skip to main content

Crate oxicrypto_rand

Crate oxicrypto_rand 

Source
Expand description

Pure Rust CSPRNG for the OxiCrypto stack.

Provides OxiRng, a ChaCha20-based CSPRNG seeded from the OS via getrandom.

§Fork Safety

On Unix platforms, OxiRng tracks the process PID and automatically reseeds after a fork() to prevent parent/child CSPRNG state sharing.

§Thread-Local RNG

Use with_thread_rng (available with the std feature) for a convenient per-thread RNG (lazily initialized, no explicit RNG management required).

§ChaCha Variants

OxiRng8 and OxiRng12 provide ChaCha8 and ChaCha12-based CSPRNGs for higher throughput when the full 20-round version is not required.

§Entropy Health Check

check_entropy performs a basic OS-entropy smoke test (two independent draws must be non-zero and differ). This is not a NIST SP 800-90B test.

Structs§

OxiRng
A ChaCha20 CSPRNG seeded from the OS random source.
OxiRng8
A ChaCha8 CSPRNG seeded from the OS random source.
OxiRng12
A ChaCha12 CSPRNG seeded from the OS random source.
ReseedingRng
A OxiRng wrapper that automatically reseeds from OS entropy after generating a configurable number of bytes (default: 1 MiB).

Functions§

check_entropy
Perform a basic OS-entropy smoke test.
random_bool
Generate a random bool with the given probability of being true.
random_bool_with_rng
Generate a random bool using an existing RNG, with the given probability of being true.
random_bytes
Allocate and fill a Vec<u8> with len cryptographically secure random bytes.
random_nonce
Generate a random nonce of N bytes for use with AEAD algorithms.
random_range
Generate a random integer in [min, max) using rejection sampling to eliminate modulo bias.
random_range_to
Generate a random integer in [0, max) using rejection sampling.
random_range_unbiased
Generate a random integer in [min, max) using an existing RNG, with rejection sampling to eliminate modulo bias.
random_u32
Generate a cryptographically secure random u32.
random_u64
Generate a cryptographically secure random u64.
random_u128
Generate a cryptographically secure random u128.
reseed
Perform a manual reseed of the given OxiRng from OS entropy.
shuffle
Cryptographically secure in-place Fisher-Yates shuffle.
weighted_choice
Sample an index from a weighted distribution.
weighted_choice_with_rng
Sample an index from a weighted distribution using an existing RNG.