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::engine::general_purpose;
use base64::Engine as _;
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, general_purpose::STANDARD.encode(&key));
}

Functions

Type Aliases

  • Context for key derivation.
  • Key type for the main key used for deriving subkeys.