Module dryoc::classic::crypto_kdf
source · Expand description
Key derivation function
Implements libsodium’s key derivation functions (crypto_kdf_*
).
For details, refer to libsodium docs.
Classic API example
use base64::encode;
use dryoc::classic::crypto_kdf::*;
// Generate a random main key
let main_key = crypto_kdf_keygen();
// Provide 8 bytes of context data, can be any data
let context = b"hello123";
// Derive 20 subkeys
for i in 0..20 {
let mut key = Key::default();
crypto_kdf_derive_from_key(&mut key, i, context, &main_key).expect("kdf failed");
println!("Subkey {}: {}", i, encode(&key));
}
Functions
Derives
subkey
from main_key
, using context
and subkey_id
such that
subkey
will always be the same for the given set of inputs, but main_key
cannot be derived from subkey
.Generates a random key, suitable for use as a main key with
crypto_kdf_derive_from_key
.