Skip to content

ml-dsa: lower stack size of KeyGen::from_seed by up to 207kb#1261

Open
baloo wants to merge 1 commit intoRustCrypto:masterfrom
baloo:baloo/push-qvmpxpnrrwys
Open

ml-dsa: lower stack size of KeyGen::from_seed by up to 207kb#1261
baloo wants to merge 1 commit intoRustCrypto:masterfrom
baloo:baloo/push-qvmpxpnrrwys

Conversation

@baloo
Copy link
Member

@baloo baloo commented Mar 20, 2026

This reworks the API to make KeyGen::from_seed return a SeededSigningKey instead of a KeyPair.
The SeededSigningKey effectively replaces the KeyPair, and instead of eagerly generating the VerifyingKey (implementing signature::KeypairRef), it implements signature::Keypair and makes the verifying key when requested.

This reduces the depth of the stack when calling from_seed and reduces the size of the stack by 207kb using ML-DSA-87 in debug/tests builds (the heaviest consumers).

This is an API break.

See #1024

This reworks the API to make KeyGen::from_seed return a
`SeededSigningKey` instead of a `KeyPair`.
The `SeededSigningKey` effectively replaces the `KeyPair`, and instead
of eagerly generating the VerifyingKey (implementing
`signature::KeypairRef`), it implements `signature::Keypair` and makes
the verifying key when requested.

This reduces the depth of the stack when calling from_seed and reduces
the size of the stack by 207kb using ML-DSA-87 in debug/tests builds
(the heaviest consumers).

This is an API break.
@baloo baloo force-pushed the baloo/push-qvmpxpnrrwys branch from 9a3dfdd to c3230e4 Compare March 20, 2026 17:59
@baloo
Copy link
Member Author

baloo commented Mar 20, 2026

This lowers the stack size by 136kB in release mode (ML-DSA-87).

@baloo
Copy link
Member Author

baloo commented Mar 20, 2026

cc @mgodf89
I'd love if you could give this a shot.

@baloo
Copy link
Member Author

baloo commented Mar 20, 2026

Tested this and #1259 in a fairly large repository and that fixed our immediate issues with stack sizes (we had stack overflows in the test suite).

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.

1 participant