//! QA S-11 (PR #2 review): how much stack building a signing key and signing need. ML-DSA-65 keeps //! large polynomial vectors on the stack; a thread that is too small aborts the process with a //! stack overflow, which is not an `Error` a caller can handle. The figure is documented on //! `SigningKey`: at least 256 KiB in a release build (128 KiB overflows, QA measured). //! //! The pinned test runs in release builds only (debug frames are larger). The others are //! measurements, run by hand one at a time, because an overflow aborts the whole test binary: //! `cargo test --test sig_stack -- --ignored --exact on_a__kib_stack`. mod common; use arcanum::sign::{AppContext, SigningKey}; use common::rng; fn generate_sign_verify_on(kib: usize) { std::thread::Builder::new() .stack_size(kib * 1024) .spawn(|| { let sk = SigningKey::generate(&mut rng(80)); let ctx = AppContext::new(b"stack").unwrap(); let sig = sk.sign(b"m", &ctx, &mut rng(81)).unwrap(); assert_eq!(sk.verifying_key().verify(b"m", &ctx, &sig), Ok(())); }) .unwrap() .join() .unwrap(); } #[test] #[cfg_attr(debug_assertions, ignore = "the documented 256 KiB is for release builds")] fn generate_and_sign_fit_in_256_kib_of_stack() { generate_sign_verify_on(256); } #[test] #[ignore = "measurement: may abort the test binary"] fn on_a_128_kib_stack() { generate_sign_verify_on(128); } #[test] #[ignore = "measurement: may abort the test binary"] fn on_a_256_kib_stack() { generate_sign_verify_on(256); } #[test] #[ignore = "measurement: may abort the test binary"] fn on_a_512_kib_stack() { generate_sign_verify_on(512); } #[test] #[ignore = "measurement: may abort the test binary"] fn on_a_1024_kib_stack() { generate_sign_verify_on(1024); }