Skip to content

Comments

mlkem: export the seed instead of the raw private key#120

Merged
qmuntal merged 2 commits intomainfrom
dev/qmuntal/mlkemopt
Nov 20, 2025
Merged

mlkem: export the seed instead of the raw private key#120
qmuntal merged 2 commits intomainfrom
dev/qmuntal/mlkemopt

Conversation

@qmuntal
Copy link
Member

@qmuntal qmuntal commented Nov 20, 2025

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_BLOB instead of MLKEM_PRIVATE_BLOB for exporting/importing keys
  • Changed DecapsulationKeyMLKEM768 and DecapsulationKeyMLKEM1024 types 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.

@qmuntal qmuntal requested a review from gdams November 20, 2025 10:20
@qmuntal qmuntal merged commit 3017072 into main Nov 20, 2025
27 checks passed
@qmuntal qmuntal deleted the dev/qmuntal/mlkemopt branch November 20, 2025 10:20
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