Function orion::util::secure_rand_bytes

source ·
pub fn secure_rand_bytes(dst: &mut [u8]) -> Result<(), UnknownCryptoError>
Expand description

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 of dst.

Errors:

An error will be returned if:

  • dst is empty.

Panics:

A panic will occur if:

  • Failure to generate random bytes securely.
  • The platform is not supported by getrandom.

Example:

use orion::util;

let mut salt = [0u8; 64];
util::secure_rand_bytes(&mut salt)?;