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.
- Reseeding
Rng - A
OxiRngwrapper 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
boolwith the given probability of beingtrue. - random_
bool_ with_ rng - Generate a random
boolusing an existing RNG, with the given probability of beingtrue. - random_
bytes - Allocate and fill a
Vec<u8>withlencryptographically secure random bytes. - random_
nonce - Generate a random nonce of
Nbytes 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
OxiRngfrom 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.