test: pin verify_strict, the verify_binding order and independent seeds (QA S-01 to S-03)
Ported from QA's proof tests for PR #2 (qa_s03 to qa_s05): - S-01, sig_halves: an Ed25519 half with a small-order R (the identity, s = H(R || A || M')·a from a throwaway key's own scalar) is accepted by plain verify and refused by verify_strict; Arcanum must refuse it. - S-02, sig_every_byte: a forged window that also excludes now gives InvalidSignature, never OutsideValidity. - S-03, sig_composite: generate draws exactly 64 bytes, and the two seeds are those bytes in order (RFC 10073 3.1, independent component keys). Each mutation QA describes now fails (applied to src/sign.rs, reverted): Q1 verify_strict -> verify fails the S-01 test; Q3 now checked before the signature fails the S-02 test; Q4 the Ed25519 seed copied from the ML-DSA seed fails the S-03 test. Adds curve25519-dalek =5.0.0 as a dev-dependency (already in the lock) for the scalar arithmetic.
This commit is contained in:
@@ -175,3 +175,36 @@ fn ml_dsa_half_uses_the_label_as_its_context() {
|
||||
assert!(!ml_vk.verify_with_context(&mp, b"", &ml_sig), "not the empty ctx");
|
||||
assert!(!ml_vk.verify_with_context(&mp, ctx.as_bytes(), &ml_sig), "not the application ctx");
|
||||
}
|
||||
|
||||
/// An RNG that records what it hands out (backed by the test ChaCha20).
|
||||
struct Recording(chacha20::ChaCha20Rng, Vec<u8>);
|
||||
|
||||
impl rand_core::TryRng for Recording {
|
||||
type Error = core::convert::Infallible;
|
||||
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
|
||||
unimplemented!("signing draws bytes, not words")
|
||||
}
|
||||
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
|
||||
unimplemented!("signing draws bytes, not words")
|
||||
}
|
||||
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), Self::Error> {
|
||||
rand_core::Rng::fill_bytes(&mut self.0, dst);
|
||||
self.1.extend_from_slice(dst);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl rand_core::TryCryptoRng for Recording {}
|
||||
|
||||
/// QA S-03 (their `qa_s05`), RFC 10073 §3.1: `generate` draws 64 fresh bytes, the ML-DSA seed then
|
||||
/// the Ed25519 seed, independently. Kills deriving one seed from the other, or drawing only 32.
|
||||
#[test]
|
||||
fn generate_draws_two_independent_seeds() {
|
||||
let mut rec = Recording(rng(35), Vec::new());
|
||||
let sk = SigningKey::generate(&mut rec);
|
||||
assert_eq!(rec.1.len(), 64, "exactly 64 bytes drawn");
|
||||
assert_eq!(sk.to_bytes().as_slice(), rec.1.as_slice(), "the seeds are the RNG output, in order");
|
||||
assert_ne!(rec.1[..32], rec.1[32..], "two different seeds");
|
||||
let again = SigningKey::from_bytes(&rec.1).unwrap();
|
||||
assert_eq!(again.verifying_key(), sk.verifying_key());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user