docs: the stack a signing key needs, and a release test that pins it (QA S-11)
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.
This commit is contained in:
@@ -285,6 +285,14 @@ impl fmt::Debug for Signature {
|
|||||||
|
|
||||||
/// A composite signing key: two independent 32-byte seeds and the keys expanded from them, all
|
/// A composite signing key: two independent 32-byte seeds and the keys expanded from them, all
|
||||||
/// zeroised on drop. Not `Clone`; `Debug` prints nothing secret.
|
/// zeroised on drop. Not `Clone`; `Debug` prints nothing secret.
|
||||||
|
///
|
||||||
|
/// **Stack** (QA S-11): building a key ([`SigningKey::generate`], [`SigningKey::from_bytes`]) and
|
||||||
|
/// signing keep ML-DSA-65's polynomial vectors on the stack. Measured on Windows x86-64
|
||||||
|
/// (`tests/sig_stack.rs`): a release build needs more than 128 KiB and fits in 256 KiB; a debug
|
||||||
|
/// build (with dependencies at `opt-level = 2`, as in Arcanum's own profile) needs more than
|
||||||
|
/// 256 KiB and fits in 512 KiB. Too small a thread **aborts the process** with a stack overflow;
|
||||||
|
/// it is not an error that can be caught. Default threads (1–2 MiB) are fine; give worker,
|
||||||
|
/// blocking-pool or JNI threads that sign at least 512 KiB, and measure unoptimised debug builds.
|
||||||
pub struct SigningKey {
|
pub struct SigningKey {
|
||||||
seeds: Zeroizing<[u8; SIGNING_KEY_LEN]>,
|
seeds: Zeroizing<[u8; SIGNING_KEY_LEN]>,
|
||||||
// Boxed: the expanded ML-DSA-65 key is about 64 kB.
|
// Boxed: the expanded ML-DSA-65 key is about 64 kB.
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
//! 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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user