test: the v0.2.0 signature tests, written before the code
The mandatory tests of docs/02_signatures.md, against the API the doc sets out (arcanum::sign). They do not compile yet: the module does not exist. 1 kat_mldsa65: ACVP keyGen, sigGen (deterministic and hedged groups, byte for byte, through sign_randomized/sign_mu_randomized fed the vector's rnd), sigVer on the corrected file; Wycheproof sign_seed and verify. 2 kat_ed25519: RFC 8032 section 7.1 and Wycheproof, with verify_strict. 3 sig_composite: the RFC 10073 vectors s and sWithContext verify, the RFC key derives the RFC public key, own signatures verify under an independent rebuild of M', ML-DSA hedged with ctx = Label. 4 sig_halves: either half swapped in from another signature, zeroed or cut, or the halves swapped, is refused; the ML-DSA half fails an empty-ctx verifier. Not SUF-CMA (RFC 10073 9.2) is pinned. 5 sig_every_byte: any flipped byte of message, ctx, public key or signature fails; contexts are prefix-free; key bindings and app messages never verify as each other; every binding field matters. 6 sig_malformed: wrong lengths, weak and non-canonical Ed25519 keys, 0- and 256-byte contexts, a 65536-byte key id, random bytes. 7 sig_hygiene and feature_hygiene: compile-fail checks against a default-features consumer (hazmat raw interface, ml-dsa internals, non-crypto RNG, Clone), ZeroizeOnDrop, Debug; ml-dsa and ed25519-dalek in the normal graph with zeroize and without hazmat or defaults. The allocator probe covers the signing keys. 8 golden_v1.rs is untouched. Adds ml-dsa =0.1.2 (alloc, rand_core, zeroize) and ed25519-dalek =3.0.0 (zeroize) with default features off, base64 for the tests, and bumps the version to 0.2.0. The fuzz target follows with the code.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
use arcanum::exchange;
|
||||
use arcanum::seal;
|
||||
use arcanum::sign::{self, AppContext, SigningKey};
|
||||
use arcanum::xwing::SecretKey;
|
||||
use arcanum_zeroize_probe::{CANARY, arm, disarm};
|
||||
use chacha20::ChaCha20Rng;
|
||||
@@ -88,4 +89,30 @@ fn secrets_are_wiped_before_their_heap_memory_is_freed() {
|
||||
let psk = Box::new(is.wireguard_psk(1));
|
||||
drop((psk, is, rs));
|
||||
assert!(!disarm(), "an exchange freed its context unwiped");
|
||||
|
||||
// --- v0.2.0: signatures ---
|
||||
// Both seeds are the canary. Building the key runs `ml-dsa`'s `SigningKey::from_seed`, which
|
||||
// keeps a copy of the ML-DSA seed in a heap box (`alloc`) and wipes it on drop (`zeroize`).
|
||||
let seeds: Zeroizing<Vec<u8>> = Zeroizing::new([CANARY, CANARY].concat());
|
||||
arm();
|
||||
drop(std::hint::black_box(Box::new(SigningKey::from_bytes(&seeds).unwrap())));
|
||||
assert!(!disarm(), "a boxed signing key (or ml-dsa's seed box) was freed with a seed in memory");
|
||||
|
||||
// The exported seeds.
|
||||
let sk = SigningKey::from_bytes(&seeds).unwrap();
|
||||
arm();
|
||||
drop(std::hint::black_box(Box::new(sk.to_bytes())));
|
||||
assert!(!disarm(), "a boxed to_bytes() copy was freed unwiped");
|
||||
|
||||
// Signing, an app message and a key binding, with the canary key; then the key is dropped.
|
||||
let ctx = AppContext::new(b"probe").unwrap();
|
||||
let kem = SecretKey::from_bytes(&[9; 32]).unwrap();
|
||||
arm();
|
||||
let sk = Box::new(SigningKey::from_bytes(&seeds).unwrap());
|
||||
let sig = sk.sign(b"message", &ctx, &mut rng(6)).unwrap();
|
||||
assert_eq!(sk.verifying_key().verify(b"message", &ctx, &sig), Ok(()));
|
||||
let bound = sign::bind_kem_key(&sk, b"id", kem.public_key(), (0, 1), &mut rng(7)).unwrap();
|
||||
assert_eq!(sign::verify_binding(sk.verifying_key(), b"id", kem.public_key(), (0, 1), 0, &bound), Ok(()));
|
||||
drop((sig, bound, sk));
|
||||
assert!(!disarm(), "signing freed a buffer that held a seed");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user