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 bouncycastle_core::key_material::{KeyMaterial256, KeyType};
use bouncycastle_core::traits::KDF;
use bouncycastle_factory::AlgorithmFactory;
// 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 bouncycastle_rng::DefaultRNG::default()).unwrap();
let additional_input: &[u8] = b"some additional input";
let mut h = bouncycastle_factory::kdf_factory::KDFFactory::new(bouncycastle_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 bouncycastle_core::key_material::{KeyMaterial256, KeyType};
use bouncycastle_core::traits::KDF;
use bouncycastle_factory::AlgorithmFactory;
// 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 bouncycastle_rng::DefaultRNG::default()).unwrap();
let additional_input: &[u8] = b"some additional input";
let h = bouncycastle_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 bouncycastle_core::key_material::{KeyMaterial256, KeyType};
use bouncycastle_core::traits::KDF;
use bouncycastle_factory::AlgorithmFactory;
// 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 bouncycastle_rng::DefaultRNG::default()).unwrap();
let additional_input: &[u8] = b"some additional input";
let h = bouncycastle_factory::kdf_factory::KDFFactory::default();
let new_key = h.derive_key(&seed_key, additional_input).unwrap();