2a432f5d86
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.
71 lines
3.4 KiB
Rust
71 lines
3.4 KiB
Rust
//! QA A-35: no test-only feature may reach a normal (release) build through Cargo feature
|
|
//! unification. Checks the normal-edge graph a consumer of Arcanum gets with default features.
|
|
//!
|
|
//! `arcanum/hazmat` exposes the deterministic entry points. `ml-kem/hazmat` only un-hides docs in
|
|
//! 0.3.4 (its `encapsulate_deterministic` is public either way), but is kept out on principle.
|
|
//! Consumers (via-core, via) must run the same check in their own CI: a `[dependencies]` entry
|
|
//! there could still enable `arcanum/hazmat`.
|
|
|
|
use std::process::Command;
|
|
|
|
fn tree(args: &[&str]) -> String {
|
|
let out = Command::new(env!("CARGO"))
|
|
.current_dir(env!("CARGO_MANIFEST_DIR"))
|
|
.args(["tree", "--offline", "--locked", "-e", "features,normal", "--prefix", "none"])
|
|
.args(args)
|
|
.output()
|
|
.expect("run cargo tree");
|
|
assert!(out.status.success(), "cargo tree failed: {}", String::from_utf8_lossy(&out.stderr));
|
|
String::from_utf8(out.stdout).unwrap()
|
|
}
|
|
|
|
fn assert_no_hazmat(t: &str, what: &str) {
|
|
for line in t.lines() {
|
|
assert!(!line.contains("feature \"hazmat\""), "{what}: hazmat reached a normal build: {line}\n{t}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn arcanum_default_features_do_not_include_hazmat() {
|
|
let t = tree(&["-i", "arcanum"]);
|
|
assert!(t.contains("arcanum feature \"default\""), "the tree must list arcanum's features:\n{t}");
|
|
assert_no_hazmat(&t, "arcanum");
|
|
// Prove the check can see the feature at all: asking for it must make it appear.
|
|
let with = tree(&["-i", "arcanum", "--features", "hazmat"]);
|
|
assert!(with.contains("arcanum feature \"hazmat\""), "the check is blind:\n{with}");
|
|
}
|
|
|
|
#[test]
|
|
fn ml_kem_hazmat_is_not_in_the_normal_graph() {
|
|
let t = tree(&["-i", "ml-kem"]);
|
|
assert!(t.contains("ml-kem feature \"zeroize\""), "the tree must list ml-kem's features:\n{t}");
|
|
assert_no_hazmat(&t, "ml-kem");
|
|
}
|
|
|
|
#[test]
|
|
fn no_os_rng_in_the_normal_graph() {
|
|
// Randomness is a parameter (QA A-36): nothing in the normal graph may pull an OS RNG.
|
|
let t = tree(&["-p", "arcanum"]);
|
|
assert!(t.contains("rand_core"), "the tree must include rand_core:\n{t}");
|
|
assert!(!t.contains("getrandom"), "getrandom reached a normal build:\n{t}");
|
|
}
|
|
|
|
/// v0.2.0, mandatory test 7: the signature crates enter the normal graph with `zeroize` on and
|
|
/// no `hazmat`. `ed25519-dalek` has a `hazmat` feature of its own (raw `ExpandedSecretKey`
|
|
/// signing, `verify_stream`); `ml-dsa`'s `default` would pull `getrandom` and `pkcs8`.
|
|
#[test]
|
|
fn signature_crates_have_zeroize_and_no_hazmat() {
|
|
let t = tree(&["-i", "ml-dsa"]);
|
|
assert!(t.contains("ml-dsa feature \"zeroize\""), "ml-dsa must have zeroize:\n{t}");
|
|
assert!(t.contains("ml-dsa feature \"rand_core\""), "the tree must list ml-dsa's features:\n{t}");
|
|
assert!(!t.contains("ml-dsa feature \"default\""), "ml-dsa's default features reached a normal build:\n{t}");
|
|
assert!(!t.contains("ml-dsa feature \"getrandom\""), "ml-dsa's getrandom reached a normal build:\n{t}");
|
|
assert_no_hazmat(&t, "ml-dsa");
|
|
|
|
let t = tree(&["-i", "ed25519-dalek"]);
|
|
assert!(t.contains("ed25519-dalek feature \"zeroize\""), "ed25519-dalek must have zeroize:\n{t}");
|
|
assert!(!t.contains("ed25519-dalek feature \"default\""), "ed25519-dalek's defaults reached a normal build:\n{t}");
|
|
assert_no_hazmat(&t, "ed25519-dalek");
|
|
// (That the check can see a `hazmat` feature at all is proved for arcanum's own, above.)
|
|
}
|