Skip to main content

random_bytes

Function random_bytes 

Source
pub fn random_bytes<const N: usize>() -> Result<[u8; N]>
Expand description

Fill an N-byte array from the operating system’s CSPRNG

Used for handshake nonces, the per-session secret, and unpredictable staging-directory names. There is deliberately no fallback generator: if the operating system cannot supply randomness, the caller fails closed instead of continuing with a guessable value.

§Example

let nonce: [u8; 32] = whisker_dev_protocol::random_bytes()?;
assert_eq!(nonce.len(), 32);