pub struct OxiRng { /* private fields */ }Expand description
A ChaCha20 CSPRNG seeded from the OS random source.
Use OxiRng::new to create an instance. The seed is obtained from
getrandom::fill which calls /dev/urandom, RtlGenRandom, or
arc4random depending on the platform — no C library required.
On Unix platforms, OxiRng automatically reseeds itself if the process
PID changes (i.e. after a fork()), preventing parent/child state sharing.
Implementations§
Source§impl OxiRng
impl OxiRng
Sourcepub fn new() -> Result<Self, CryptoError>
pub fn new() -> Result<Self, CryptoError>
Create a new OxiRng seeded from the OS.
Returns CryptoError::Internal if getrandom fails.
Sourcepub fn reseed(&mut self) -> Result<(), CryptoError>
pub fn reseed(&mut self) -> Result<(), CryptoError>
Reseed this RNG from OS entropy.
Replaces the internal ChaCha20 state with a fresh 32-byte seed and
updates the stored PID to the current process. The free function
crate::reseed is kept for backward compatibility.
Returns CryptoError::Rng if getrandom fails.
Sourcepub fn fill_exact<const N: usize>(
&mut self,
dst: &mut [u8; N],
) -> Result<(), CryptoError>
pub fn fill_exact<const N: usize>( &mut self, dst: &mut [u8; N], ) -> Result<(), CryptoError>
Fill a fixed-size array with cryptographically random bytes.