mlkem: export the seed instead of the raw private key#120
Merged
Conversation
gdams
approved these changes
Nov 20, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR changes the ML-KEM implementation to export and use 64-byte seeds instead of the full raw private key material (2400 bytes for MLKEM768, 3168 bytes for MLKEM1024), aligning with the upstream standard library approach.
Key changes:
- Updated to use
MLKEM_PRIVATE_SEED_BLOBinstead ofMLKEM_PRIVATE_BLOBfor exporting/importing keys - Changed
DecapsulationKeyMLKEM768andDecapsulationKeyMLKEM1024types to use 64-byte seeds instead of full key material - Added test assertions to verify that decapsulation key sizes match between CNG and stdlib implementations
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/bcrypt/bcrypt_windows.go | Added MLKEM_PRIVATE_SEED_BLOB constant and MLKEM_PRIVATE_SEED_MAGIC magic number, with formatting alignment improvements |
| cng/mlkem.go | Removed full key size constants, updated functions to use seeds, and changed type definitions to use 64-byte seeds instead of full key material |
| cng/mlkem_test.go | Changed import from math/rand to crypto/rand for proper cryptographic randomness, and added size validation checks for interoperability testing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
gdams
approved these changes
Nov 20, 2025
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.
Upstream uses the MLKEM seeds instead of raw private keys to pass keys around. We should do the same. Added a test to ensure we don't regress.