pub struct Kdf<Key: ByteArray<CRYPTO_KDF_KEYBYTES> + Zeroize + ZeroizeOnDrop, Context: ByteArray<CRYPTO_KDF_CONTEXTBYTES> + Zeroize> { /* private fields */ }Expand description
Key derivation implementation based on Blake2b, compatible with libsodium’s
crypto_kdf_* functions.
The main-key type must implement ZeroizeOnDrop so keys remain
self-wiping after Kdf::into_parts transfers ownership to the caller.
Implementations§
Source§impl<Key: NewByteArray<CRYPTO_KDF_KEYBYTES> + Zeroize + ZeroizeOnDrop, Context: NewByteArray<CRYPTO_KDF_CONTEXTBYTES> + Zeroize> Kdf<Key, Context>
impl<Key: NewByteArray<CRYPTO_KDF_KEYBYTES> + Zeroize + ZeroizeOnDrop, Context: NewByteArray<CRYPTO_KDF_CONTEXTBYTES> + Zeroize> Kdf<Key, Context>
Source§impl<Key: ByteArray<CRYPTO_KDF_KEYBYTES> + Zeroize + ZeroizeOnDrop, Context: ByteArray<CRYPTO_KDF_CONTEXTBYTES> + Zeroize> Kdf<Key, Context>
impl<Key: ByteArray<CRYPTO_KDF_KEYBYTES> + Zeroize + ZeroizeOnDrop, Context: ByteArray<CRYPTO_KDF_CONTEXTBYTES> + Zeroize> Kdf<Key, Context>
Sourcepub fn derive_subkey<const LENGTH: usize, Subkey: NewByteArray<LENGTH>>(
&self,
subkey_id: u64,
) -> Result<Subkey, Error>
pub fn derive_subkey<const LENGTH: usize, Subkey: NewByteArray<LENGTH>>( &self, subkey_id: u64, ) -> Result<Subkey, Error>
Derives a subkey for subkey_id, returning it.
§Errors
Returns an error unless LENGTH is between
CRYPTO_KDF_BLAKE2B_BYTES_MIN
and
CRYPTO_KDF_BLAKE2B_BYTES_MAX,
inclusive.
Sourcepub fn derive_subkey_to_vec(
&self,
subkey_id: u64,
length: usize,
) -> Result<Vec<u8>, Error>
pub fn derive_subkey_to_vec( &self, subkey_id: u64, length: usize, ) -> Result<Vec<u8>, Error>
Derives a subkey for subkey_id, returning it as a Vec. Provided
for convenience.
§Errors
Returns an error unless length is between
CRYPTO_KDF_BLAKE2B_BYTES_MIN
and
CRYPTO_KDF_BLAKE2B_BYTES_MAX,
inclusive.
Sourcepub fn from_parts(main_key: Key, context: Context) -> Self
pub fn from_parts(main_key: Key, context: Context) -> Self
Constructs a new instance from key and context, consuming them both.
Sourcepub fn into_parts(self) -> (Key, Context)
pub fn into_parts(self) -> (Key, Context)
Moves the key and context out of this instance, returning them as a tuple.
Source§impl Kdf<Key, Context>
impl Kdf<Key, Context>
Sourcepub fn generate_with_defaults() -> Self
pub fn generate_with_defaults() -> Self
Randomly generates a new pair of main key and context.
Sourcepub fn gen_with_defaults() -> Self
👎Deprecated: use generate_with_defaults() instead
pub fn gen_with_defaults() -> Self
use generate_with_defaults() instead
Randomly generates a new pair of main key and context.
Prefer generate_with_defaults. This
method is retained for compatibility.