pub enum Kdf {
None,
Pbkdf2 {
digest: Digest,
iterations: u32,
salt: Vec<u8>,
},
}
Expand description
Supported key derivation functions.
Defines data used to calculate a wrapping key.
The wrapping key is created used by an algorithm defined as a variant of this enum. The variants holds fields to customize the algorithm.
Based on a password provided by the user one of the algorithms are used to calculate a wrapping key. The wrapping key then is used for encryption of the secret in the header of the container.
Variants§
Implementations§
Source§impl Kdf
impl Kdf
Sourcepub fn pbkdf2(digest: Digest, iterations: u32, salt: &[u8]) -> Kdf
pub fn pbkdf2(digest: Digest, iterations: u32, salt: &[u8]) -> Kdf
Creates a Kdf
instance for the PBKDF2 algorithm.
The digest
, iterations
and the salt
values are used to customize
the PBKDF2 algorithm.
§Examples
use nuts_container::*;
let pbkdf2 = Kdf::pbkdf2(Digest::Sha1, 5, &[1, 2, 3]);
match pbkdf2 {
Kdf::Pbkdf2 {
digest,
iterations,
salt,
} => {
assert_eq!(digest, Digest::Sha1);
assert_eq!(iterations, 5);
assert_eq!(salt, [1, 2, 3]);
}
_ => panic!("invalid kdf"),
}
Sourcepub fn generate_pbkdf2(
digest: Digest,
iterations: u32,
salt_len: u32,
) -> Result<Kdf, KdfError>
pub fn generate_pbkdf2( digest: Digest, iterations: u32, salt_len: u32, ) -> Result<Kdf, KdfError>
Generates a Kdf
instance for the PBKDF2 algorithm.
The digest
and iterations
value is used to customize the PBKDF2
algorithm. For the salt
salt_len
bytes of random data are
generated.
§Errors
This method will return an Error::OpenSSL
error if there was an
error generating the random data.
§Examples
use nuts_container::*;
let kdf = Kdf::generate_pbkdf2(Digest::Sha1, 5, 3).unwrap();
match kdf {
Kdf::Pbkdf2 {
digest,
iterations,
salt,
} => {
assert_eq!(digest, Digest::Sha1);
assert_eq!(iterations, 5);
assert_eq!(salt.len(), 3); // salt filled with random data
}
_ => panic!("invalid kdf"),
}