-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ML-DSA private keys from seeds #2157
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
justsmth
previously approved these changes
Feb 3, 2025
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2157 +/- ##
=======================================
Coverage ? 78.97%
=======================================
Files ? 611
Lines ? 105682
Branches ? 14960
=======================================
Hits ? 83463
Misses ? 21566
Partials ? 653 ☔ View full report in Codecov by Sentry. |
justsmth
reviewed
Feb 3, 2025
justsmth
reviewed
Feb 4, 2025
justsmth
previously approved these changes
Feb 5, 2025
WillChilds-Klein
previously approved these changes
Feb 5, 2025
jakemas
dismissed stale reviews from WillChilds-Klein and justsmth
via
February 5, 2025 17:35
1809d69
WillChilds-Klein
approved these changes
Feb 5, 2025
justsmth
approved these changes
Feb 5, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issues:
Resolves #CryptoAlg-2889
Description of changes:
The industry has decided upon a few conventions to assist with the usability of ML-DSA key sizes, one of which is to decrease the amount of bytes transferred when encoding ML-DSA private keys. As ML-DSA keys can be deterministically generated from a provided 32-byte seed, many standards bodies have selected to use private keys in seed format. For example, the IETF draft that standardizes the use of ML-DSA in X.509. https://datatracker.ietf.org/doc/draft-ietf-lamps-dilithium-certificates/
This provides:
The functionality that provides key generation from seeds for ML-DSA was added in my previous PR #1999. This PR exposes the internal key generation functions within the
PQDSA
struct, so that a new function namedPQDSA_KEY_set_raw_keypair_from_seed
can directly call the method.The function
PQDSA_KEY_set_raw_keypair_from_seed
simply performs:seed
is of the correct lengthpqdsa_keygen_internal
As such,
pqdsa_priv_decode
has been modified to call:PQDSA_KEY_set_raw_private_key
when the provided length of the key ispqdsa->private_key_len
PQDSA_KEY_set_raw_keypair_from_seed
when the provided length of the key ispqdsa->keygen_seed_len
We implement this at the EVP layer by modifying
EVP_PKEY_pqdsa_new_raw_private_key
to:PQDSA_KEY_set_raw_private_key
when thelen
provided isprivate_key_len
PQDSA_KEY_set_raw_keypair_from_seed
when thelen
provided iskeygen_seed_len
Call-outs:
EVP_PKEY_pqdsa_new_raw_private_key
will now populate both public and private keys when provided a seed.EVP_PKEY_pqdsa_new_raw_public_key
only sets the public keyPQDSA_KEY_set_raw_private_key
will only set private keyPQDSA_KEY_set_raw_public_key
will only set public keyEVP_parse_public_key
sets the public key from DER encoded of public keyEVP_parse_private_key
can accept DER encodings of either the full private key representation, or the 32-byte seed.EVP_marshal_public_key
sets the DER encoded public key from a EVP PKEYEVP_marshal_private_key
sets the DER encoded full private key representation (it cannot marshal the seed, as this cannot be derived from the full private key representation.Testing:
To provide KAT for keys from seeds I have included the
Appendix C. Examples
from https://datatracker.ietf.org/doc/draft-ietf-lamps-dilithium-certificates/. For each provided ML-DSA parameter set, we generate the example private key provided from seed, and check that the corresponding public key matches that in the specification. These tests are inPQDSAParameterTest
namely,ParsePrivateKey
.These examples show how much shorter ML-DSA-87 private keys are in seed format:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.