Skip to main content

Module rng_factory

Module rng_factory 

Source
Expand description

RNG factory for creating instances of algorithms that implement the RNG trait.

As with all Factory objects, this implements constructions from strings and defaults, and returns a RNGFactory object which itself implements the RNG trait as a pass-through to the underlying algorithm.

A quick note about cryptographic random number generators (RNGs), which are also sometimes cryptographically secure random number generators (CSRNGs) or pseudorandom number generators (PRNGS)). As the last name suggests, they are based on deterministic permutation functions called deterministic random bit generators (DRBGs), which, always produce the same output for the same seed value. Meaning that they are only as cryptographically strong and unique as their seed.

All RNGs exposed through the RNGFactory are seeded from the underlying operating system’s entropy pool, and therefore should be sufficient for most cryptographic use. Additional entropy can be added via the RNG::add_seed_keymaterial function.

Applications that require direct control over the seed material, for example in order to deterministically re-generate a key stream from a private seed, or in order to use a specific approved entropy source should instead use the objects in the rng crate, which expose more instantiation functionality.

Example usage:

use factory::AlgorithmFactory;
use core_interface::traits::Hash;

let data: &[u8] = b"Hello, world!";

let h = factory::hash_factory::HashFactory::new(sha3::SHA3_256_NAME).unwrap();
let output: Vec<u8> = h.hash(data);

You can equivalently invoke this by string instead of using the constant:

use factory::AlgorithmFactory;
use core_interface::traits::Hash;

let data: &[u8] = b"Hello, world!";

let h = factory::hash_factory::HashFactory::new("SHA3-256").unwrap();
let output: Vec<u8> = h.hash(data);

Enums§

RNGFactory
All members must impl RNG.

Constants§

DEFAULT_128BIT_DRBG_NAME
DEFAULT_256BIT_DRBG_NAME
DEFAULT_DRBG_NAME