Skip to main content

RNG

Trait RNG 

Source
pub trait RNG {
    // Required methods
    fn add_seed_keymaterial(
        &mut self,
        additional_seed: &dyn KeyMaterialTrait,
    ) -> Result<(), RNGError>;
    fn next_int(&mut self) -> Result<u32, RNGError>;
    fn next_bytes(&mut self, len: usize) -> Result<Vec<u8>, RNGError>;
    fn next_bytes_out(&mut self, out: &mut [u8]) -> Result<usize, RNGError>;
    fn fill_keymaterial_out(
        &mut self,
        out: &mut dyn KeyMaterialTrait,
    ) -> Result<usize, RNGError>;
    fn security_strength(&self) -> SecurityStrength;
}
Expand description

An interface for random number generation. This interface is meant to be simpler and more ergonomic than the interfaces provided by the rng crate, but that one should be used by applications that intend to submit to FIPS certification as it more closely aligns with the requirements of SP 800-90A. Note: this interface produces bytes. If you want a KeyMaterialTrait, then use KeyMaterial::from_rng.

Implementors are expected to also implement Default (default-construction should produce a securely OS-seeded instance), but this is intentionally not a supertrait bound: requiring Default would make RNG not dyn-compatible, and &mut dyn RNG is needed so RNG instances can be handed around as trait objects.

Required Methods§

Source

fn add_seed_keymaterial( &mut self, additional_seed: &dyn KeyMaterialTrait, ) -> Result<(), RNGError>

Provide additional key material to be mixed in to the existing RNG instance. The exact behaviour will be implementation-specific, but this is intended for injecting additional entropy, not as the primary method of seeding the RNG.

Source

fn next_int(&mut self) -> Result<u32, RNGError>

Returns the next random 32-bit integer.

Source

fn next_bytes(&mut self, len: usize) -> Result<Vec<u8>, RNGError>

Returns the number of requested bytes.

Source

fn next_bytes_out(&mut self, out: &mut [u8]) -> Result<usize, RNGError>

Returns the number of bytes written. The entire output buffer is zeroized before the random bytes are written.

Source

fn fill_keymaterial_out( &mut self, out: &mut dyn KeyMaterialTrait, ) -> Result<usize, RNGError>

Fill the provided KeyMaterial with random bytes.

Source

fn security_strength(&self) -> SecurityStrength

Returns the Security Strength of this RNG.

Implementors§