Clean & Better Encryption

This commit is contained in:
Alex Emmet 2026-06-25 19:41:51 +02:00
commit 2a00bb35e7
17 changed files with 640 additions and 367 deletions

View file

@ -16,10 +16,12 @@ pub fn hkdf_expand(
}
pub fn hkdf_extract(ikm: &[u8], salt: &[u8]) -> [u8; 32] {
let (_, hk) = Hkdf::<Sha256>::extract(Some(salt), ikm);
let mut okm = [0u8; 32];
hk.expand(&[], &mut okm).expect("hkdf expand failed");
okm
// Return the pseudo-random key (PRK) produced by HKDF-Extract directly.
// Extract cannot fail, so this avoids the panicking expand step entirely.
let (prk, _) = Hkdf::<Sha256>::extract(Some(salt), ikm);
let mut out = [0u8; 32];
out.copy_from_slice(&prk);
out
}
pub fn derive_encryption_key(