Add ekDer and dkPkcs8 DER key encodings to ML-KEM keygen_seed vectors - #272
Open
Arpan0995 wants to merge 1 commit into
Open
Add ekDer and dkPkcs8 DER key encodings to ML-KEM keygen_seed vectors#272Arpan0995 wants to merge 1 commit into
Arpan0995 wants to merge 1 commit into
Conversation
This file contains hidden or 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
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.
This addresses the DER-encoding request in #184, scoped to the three ML-KEM
keygen_seedfiles as the smallest useful first step.What this adds
For each of the 300 cases in
mlkem_512_keygen_seed_test.json,mlkem_768_keygen_seed_test.json, andmlkem_1024_keygen_seed_test.json, two fields are added next to the existing raw keys:ekDer: the encapsulation key as a DER-encoded SubjectPublicKeyInfo (theekbytes wrapped in an SPKI with the ML-KEM algorithm identifier).dkPkcs8: the decapsulation key as a DER-encoded PrivateKeyInfo in the seed form (theseedwrapped in PKCS#8 with the[0] seedchoice).Both use
"format": "Der", consistent with thepublicKeyDerandprivateKeyPkcs8fields elsewhere in the corpus, and both are optional in the schema, the same choice made forprivateKeyPkcs8inmldsa_sign_seed. The namesekDeranddkPkcs8follow theekanddkfields already in these files and the naming used in the discussion above; I am happy to switch topublicKeyDerandprivateKeyPkcs8if you prefer the corpus-wide names.Why keygen_seed only
This is the smallest slice that adds real value: the seed-form private key and the SPKI public key are what a consumer needs to load these vectors through the standard key-encoding APIs, and key generation is where both are naturally available. Per the sizing discussion above, adding the two fields across all twelve ML-KEM files is about +50% of the ML-KEM corpus, whereas this slice is +0.79 MB, which is +9.5% of the corpus and about +35% across just these three files. Extending the same two fields to the other ML-KEM files is a straightforward follow-up if wanted.
Encoding and verification
The DER is not hand-rolled. The SPKI and seed-form PKCS#8 headers are taken from keys produced by a real ML-KEM provider, so the algorithm identifiers (the NIST OIDs 2.16.840.1.101.3.4.4.1/2/3) and structure match what implementations emit. Every field was checked back through a provider:
ekDerand 300dkPkcs8) import throughjava.security.KeyFactoryfor ML-KEM on JDK 27 and re-encode byte-identically. They also import cleanly under a second provider (BouncyCastle).ekDerpublic key and decapsulating with thedkPkcs8seed-form private key yields matching shared secrets, so the two added fields are a working key pair.ekcarried inside eachekDerequals the case'sek, and theseedinside eachdkPkcs8equals the case'sseed, with no mismatches.tools/reformat_json.pyleaves them unchanged, so the formatting is canonical.The change is add-only: no existing field or value is modified (610 insertions, 0 deletions).