9f9318664f
ML-DSA-65 keeps large vectors on the stack, and a thread that is too small aborts the process; that is not an Error a caller can handle. Measured here with tests/sig_stack.rs (Windows x86-64, a thread per run): release: 128 KiB overflows, 256/512/1024 KiB pass debug (deps at opt-level 2): 128 and 256 KiB overflow, 512/1024 KiB pass SigningKey's docs now say so and advise at least 512 KiB for threads that sign. generate_and_sign_fit_in_256_kib_of_stack pins the release figure (ignored in debug builds); the four on_a_<n>_kib_stack measurements are ignored and run by hand, one at a time.
58 lines
1.8 KiB
Rust
58 lines
1.8 KiB
Rust
//! 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_<n>_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);
|
|
}
|