[−][src]Function orion::util::secure_rand_bytes
#[must_use]pub fn secure_rand_bytes(dst: &mut [u8]) -> Result<(), UnknownCryptoError>
Generate random bytes using a CSPRNG. Not available in no_std
context.
About:
This function can be used to generate cryptographic keys, salts or other
values that rely on strong randomness. Please note that most keys and other
types used throughout orion, implement their own generate()
function and
it is strongly preferred to use those, compared to secure_rand_bytes()
.
This uses getrandom
.
Parameters:
dst
: Destination buffer for the randomly generated bytes. The amount of bytes to be generated is implied by the length ofdst
.
Errors:
An error will be returned if:
dst
is empty.
Panics:
A panic will occur if:
- The
OsRng
fails to initialize or read from its source.
Example:
use orion::util; let mut salt = [0u8; 64]; util::secure_rand_bytes(&mut salt)?;