diff --git a/Cargo.lock b/Cargo.lock index 3494423ea..aefc5b984 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1010,6 +1010,7 @@ version = "0.0.2-pre.2" dependencies = [ "hex", "libcrux-sha3", + "rand", "serde", "serde_json", ] diff --git a/libcrux-ml-dsa/Cargo.toml b/libcrux-ml-dsa/Cargo.toml index dcc3340ee..dc62791c0 100644 --- a/libcrux-ml-dsa/Cargo.toml +++ b/libcrux-ml-dsa/Cargo.toml @@ -14,6 +14,7 @@ readme.workspace = true libcrux-sha3 = { version = "0.0.2-pre.2", path = "../libcrux-sha3" } [dev-dependencies] +rand = { version = "0.8" } hex = { version = "0.4.3", features = ["serde"] } serde_json = { version = "1.0" } serde = { version = "1.0", features = ["derive"] } diff --git a/libcrux-ml-dsa/tests/self.rs b/libcrux-ml-dsa/tests/self.rs new file mode 100644 index 000000000..2937cbe59 --- /dev/null +++ b/libcrux-ml-dsa/tests/self.rs @@ -0,0 +1,49 @@ +use rand::{rngs::OsRng, RngCore}; + +fn random_array() -> [u8; L] { + let mut rng = OsRng; + let mut seed = [0; L]; + rng.try_fill_bytes(&mut seed).unwrap(); + seed +} + +macro_rules! impl_consistency { + ($name:ident, $key_gen:expr, $sign:expr, $verify:expr) => { + #[test] + fn $name() { + let key_generation_seed = random_array(); + let signing_randomness = random_array(); + + // TODO: Choose the length randomly + let message = random_array::<948839>(); + + let key_pair = $key_gen(key_generation_seed); + + let signature = $sign(key_pair.signing_key, &message, signing_randomness); + + $verify(key_pair.verification_key, &message, signature) + .expect("Verification should pass since the signature was honestly generated"); + } + }; +} + +impl_consistency!( + consistency_44, + libcrux_ml_dsa::ml_dsa_44::generate_key_pair, + libcrux_ml_dsa::ml_dsa_44::sign, + libcrux_ml_dsa::ml_dsa_44::verify +); + +impl_consistency!( + consistency_65, + libcrux_ml_dsa::ml_dsa_65::generate_key_pair, + libcrux_ml_dsa::ml_dsa_65::sign, + libcrux_ml_dsa::ml_dsa_65::verify +); + +impl_consistency!( + consistency_87, + libcrux_ml_dsa::ml_dsa_87::generate_key_pair, + libcrux_ml_dsa::ml_dsa_87::sign, + libcrux_ml_dsa::ml_dsa_87::verify +);