KeyDerivationFunction

Trait KeyDerivationFunction 

Source
pub trait KeyDerivationFunction {
    type Algorithm: KdfAlgorithm;
    type Salt: AsRef<[u8]> + AsMut<[u8]> + Clone;

    // Required methods
    fn new() -> Self;
    fn derive_key(
        &self,
        input: &[u8],
        salt: Option<&[u8]>,
        info: Option<&[u8]>,
        length: usize,
    ) -> Result<Vec<u8>>;
    fn builder(&self) -> impl KdfOperation<'_, Self::Algorithm>
       where Self: Sized;
    fn generate_salt<R: RngCore + CryptoRng>(rng: &mut R) -> Self::Salt;

    // Provided method
    fn security_level() -> SecurityLevel { ... }
}
Expand description

Common trait for all key derivation functions

Required Associated Types§

Source

type Algorithm: KdfAlgorithm

The algorithm this KDF implements

Source

type Salt: AsRef<[u8]> + AsMut<[u8]> + Clone

Salt type with appropriate validation

Required Methods§

Source

fn new() -> Self

Creates a new instance of the KDF with default parameters

Source

fn derive_key( &self, input: &[u8], salt: Option<&[u8]>, info: Option<&[u8]>, length: usize, ) -> Result<Vec<u8>>

Derives a key using the KDF parameters

§Arguments
  • input - Input keying material
  • salt - Optional salt value
  • info - Optional context and application-specific information
  • length - Length of the output key in bytes
§Returns

The derived key as a byte vector

Source

fn builder(&self) -> impl KdfOperation<'_, Self::Algorithm>
where Self: Sized,

Creates a builder for fluent API usage - FIXED: Elided lifetime

Source

fn generate_salt<R: RngCore + CryptoRng>(rng: &mut R) -> Self::Salt

Generate a random salt with appropriate size

Provided Methods§

Source

fn security_level() -> SecurityLevel

Returns the security level of the KDF in bits

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§