Skip to content

Conversation

hoxxep
Copy link

@hoxxep hoxxep commented Sep 3, 2025

This is an alternative to #1046 to reduce copying the seed derivation logic. Implementing a from_seed as raised in issue #1045.

  • Renames KeyGen::key_gen_internal to KeyGen::from_seed.
  • Adds SigningKey::from_seed. This internally calls KeyGen::from_seed for now, as the majority of the computational work is the same for both keys. A future PR could be slightly more efficient by specialising the SigningKey from_seed method by skipping the couple of extra steps performed to also compute a VerifyingKey, but ml-dsa: SigningKey::from_seed(&B32) implementation #1046 shows this only nets a 20us / 10% speed up.
  • Adds a test to the from_seed implementations don't deviate from each other in future, if more efficient implementations are provided.

I am not sure why key_gen_internal was commented to be behind a feature flag or private, as I believe deriving from a seed value is a must-have, assuming this implementation correctly matches the spec. I can look through the spec and codebase for test vectors to make sure, if desired?

Cheers!

@@ -913,8 +927,7 @@ pub trait KeyGen: MlDsaParams {
fn key_gen<R: CryptoRng + ?Sized>(rng: &mut R) -> Self::KeyPair;

/// Deterministically generate a signing key pair from the specified seed
// TODO(RLB): Only expose this based on a feature.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure of this comment in particular. There may be reasons key_gen_internal cannot be named from_seed that I'm not aware of, and I can't think of reasons for feature gating this? cc. @tarcieri @bifurcation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name comes from FIPS 204, namely section 6.1 where it is referred to as ML-DSA.KeyGen_internal.

I don't oppose the change in this PR, though, just providing a reference for why it's named the way it is.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've updated the docstrings to include that for end users.

@hoxxep hoxxep force-pushed the ml-dsa-keygen-from-seed branch 2 times, most recently from 46fcc7b to e4514bc Compare September 3, 2025 14:05
@hoxxep hoxxep force-pushed the ml-dsa-keygen-from-seed branch from e4514bc to 8121172 Compare September 3, 2025 14:30
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