Expand description
KDF factory for creating instances of algorithms that implement the KDF trait.
As with all Factory objects, this implements constructions from strings and defaults, and returns a KDFFactory object which itself implements the KDF trait as a pass-through to the underlying algorithm.
Example usage:
use core_interface::key_material::{KeyMaterial256, KeyType};
use factory::AlgorithmFactory;
use core_interface::traits::KDF;
// get your key material from a secure place; here we'll use the default RNG, seeded from the OS
let seed_key = KeyMaterial256::from_rng(&mut rng::DefaultRNG::default()).unwrap();
let additional_input: &[u8] = b"some additional input";
let mut h = factory::kdf_factory::KDFFactory::new(hkdf::HKDF_SHA256_NAME).unwrap();
let new_key = h.derive_key(&seed_key, additional_input).unwrap();You can equivalently invoke this by string instead of using the constant:
use core_interface::key_material::{KeyMaterial256, KeyType};
use factory::AlgorithmFactory;
use core_interface::traits::KDF;
// get your key material from a secure place; here we'll use the default RNG, seeded from the OS
let seed_key = KeyMaterial256::from_rng(&mut rng::DefaultRNG::default()).unwrap();
let additional_input: &[u8] = b"some additional input";
let h = factory::kdf_factory::KDFFactory::new("HKDF-SHA256").unwrap();
let new_key = h.derive_key(&seed_key, additional_input).unwrap();Or if you don’t particularly care which algorithm is used, you can use the built-in default:
use core_interface::key_material::{KeyMaterial256, KeyType};
use factory::AlgorithmFactory;
use core_interface::traits::KDF;
// get your key material from a secure place; here we'll use the default RNG, seeded from the OS
let seed_key = KeyMaterial256::from_rng(&mut rng::DefaultRNG::default()).unwrap();
let additional_input: &[u8] = b"some additional input";
let h = factory::kdf_factory::KDFFactory::default();
let new_key = h.derive_key(&seed_key, additional_input).unwrap();