Skip to content

Commit

Permalink
mlar: Add basic regression tests for apply_derive
Browse files Browse the repository at this point in the history
  • Loading branch information
commial committed Aug 2, 2024
1 parent ae098e2 commit 45208aa
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions mlar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1303,9 +1303,50 @@ fn main() {
#[cfg(test)]
pub(crate) mod tests {
use super::*;
use mla::crypto::hybrid::{generate_keypair_from_rng, MLKEMDecapsulationKey};
use std::iter::FromIterator;
use x25519_dalek::StaticSecret;

#[test]
fn verify_app() {
app().debug_assert();
}

#[test]
/// Naive checks for "apply_derive", to avoid naive erros
fn check_apply_derive() {
// Ensure determinism
let rng = ChaChaRng::from_seed([0u8; 32]);
let (privkey, _pubkey) = generate_keypair_from_rng(rng);

// Derive along "test"
let path = "test";
let seed = apply_derive(path, privkey);
assert_ne!(seed, [0u8; 32]);

// Derive along "test2"
let rng = ChaChaRng::from_seed([0u8; 32]);
let (privkey, _pubkey) = generate_keypair_from_rng(rng);
let path = "test2";
let seed2 = apply_derive(path, privkey);
assert_ne!(seed, seed2);

// Ensure the secret depends on both keys
let mut priv_keys = vec![];
for i in 0..1 {
for j in 0..1 {
priv_keys.push(HybridPrivateKey {
private_key_ecc: StaticSecret::from([i as u8; 32]),
private_key_ml: MLKEMDecapsulationKey::from_bytes(&[j as u8; 3168].into()),
});
}
}

// Generated seeds for (0, 0), (0, 1), (1, 0) and (1, 1) must be different
let seeds: Vec<_> = priv_keys
.into_iter()
.map(|pkey| apply_derive("test", pkey))
.collect();
assert_eq!(HashSet::<_>::from_iter(seeds.iter()).len(), seeds.len());
}
}

0 comments on commit 45208aa

Please sign in to comment.