RustCrypto / KDFs

Collection of Key Derivation Functions written in pure Rust
62 stars 26 forks source link

Missing KDFs #75

Open tarcieri opened 1 year ago

tarcieri commented 1 year ago

This is a tracking issue for KDF algorithms we should potentially implement.

Please leave a comment with your requests!

touilleMan commented 3 months ago

Hi,

It seems the kdf algo from libsodium is missing.

It would be pretty trivial to add it given it's basically a bit of cooking on top of blake2b:

    pub fn kdf_blake2b_derive_from_key::<OutSize>(subkey_id: u64, context: &[u8;8], key: &GenericArray<u8, U32>) -> [u8;OutSize] {
        let mut personal: [u8;16] = [0u8;16];
        personal[..8].copy_from_slice(context);

        let mut salt: [u8;16] = [0u8;16];
        salt[..8].copy_from_slice(&subkey_id.to_le_bytes());

        Blake2bMac<OutSize>::new_with_salt_and_personal(&key, &salt, &personal)
          .expect("subkey has always a valid size")
          .finalize().into()
}