Skip to content

ml-dsa: lower stack usage of KeyPair::from_seed by up to 112kb#1259

Merged
tarcieri merged 1 commit intoRustCrypto:masterfrom
baloo:baloo/push-nrxukulsnnvw
Mar 20, 2026
Merged

ml-dsa: lower stack usage of KeyPair::from_seed by up to 112kb#1259
tarcieri merged 1 commit intoRustCrypto:masterfrom
baloo:baloo/push-nrxukulsnnvw

Conversation

@baloo
Copy link
Member

@baloo baloo commented Mar 19, 2026

When using the KeyGen::from_seed is used, the A Matrix is computed (using expand_a).

By design, the matrix is kept on the stack, and two copies end up being held (One in the SigningKey and another one in the VerifyingKey). That matrix takes up to 56kB for ML-DSA-87.

Because two SigningKey::new/VerifyingKey::new code paths maybe used without the A matrix (when decoding from an expanded key), the code paths for both builder end up having to store two copies of the matrix and increases the stack size.

This is all private API and does not break any of the public API.

This only affects the debug/test builds as the release builds appears to optimize the unwrap_or_else and not use extraneous stack space.

See #1024

When using the KeyGen::from_seed is used, the A Matrix is
computed (using `expand_a`).

By design, the matrix is kept on the stack, and two copies end up being
held (One in the `SigningKey` and another one in the `VerifyingKey`).
That matrix takes up to 56kB for ML-DSA-87.

Because two `SigningKey::new`/`VerifyingKey::new` code paths maybe
used without the A matrix (when decoding from an expanded key), the code
paths for both builder end up having to store two copies of the matrix
and increases the stack size.

This is all private API and does not break any of the public API.

This only affects the debug/test builds as the release builds appears to
optimize the unwrap_or_else and not use extraneous stack space.
@baloo baloo force-pushed the baloo/push-nrxukulsnnvw branch from ad3bf8e to 2c62aab Compare March 19, 2026 23:28
@tarcieri tarcieri merged commit d6e621b into RustCrypto:master Mar 20, 2026
9 checks passed
@baloo baloo deleted the baloo/push-nrxukulsnnvw branch March 20, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants