wp_mlx_kmgmt: derive the classical public point when duplicating - #472
Open
yosuke-wolfssl wants to merge 1 commit into
Open
wp_mlx_kmgmt: derive the classical public point when duplicating#472yosuke-wolfssl wants to merge 1 commit into
yosuke-wolfssl wants to merge 1 commit into
Conversation
- wp_mlx_dup() calls wc_ecc_make_pub() on the duplicate's ECC key once wc_ecc_import_private_key_ex() succeeds. - test_mlx_dup covers EVP_PKEY_dup() over the hybrid groups: it compares the OSSL_PKEY_PARAM_PUB_KEY bytes of the duplicate and the original, encapsulates against the duplicate, and decapsulates that ciphertext with both keys. - test/unit.h declares test_mlx_dup and test/unit.c registers it after test_mlx_encap_decap. Issue: F-11549
There was a problem hiding this comment.
Pull request overview
This PR fixes hybrid ML-KEM + classical key duplication so that duplicated keypairs retain a usable classical public component (matching OpenSSL’s EVP_PKEY_dup() behavior) and adds unit coverage to prevent regressions.
Changes:
- Derive the ECC public point after importing an ECC private key during
wp_mlx_dup()to avoid ending up with anECC_PRIVATEKEY_ONLYstate that breaks public export. - Add a new hybrid-group duplication roundtrip test that validates public-key retrieval and encapsulate/decapsulate behavior across original and duplicated keys.
- Register the new test in the unit test declarations and test case list.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/wp_mlx_kmgmt.c |
Ensures duplicated ECC hybrids derive a classical public point after private import so public export works. |
test/test_mlkem.c |
Adds test_mlx_dup covering EVP_PKEY_dup() for hybrid groups, including pub-key byte equality and KEM roundtrips. |
test/unit.h |
Declares the new test_mlx_dup unit test. |
test/unit.c |
Registers test_mlx_dup in the unit test table. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #472
Scan targets checked: wolfprovider-bugs, wolfprovider-src
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
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.
Problem
wp_mlx_dup()duplicates the public half first, then imports the classicalprivate key with
wc_ecc_import_private_key_ex(..., pub=NULL, ...). That pathsets
key->type = ECC_PRIVATEKEY_ONLY, so every laterwc_ecc_export_x963()returns
ECC_PRIVATEONLY_Ewhiledst->hasPubstays 1.EVP_PKEY_dup()copies withOSSL_KEYMGMT_SELECT_ALL— exactly thiscombination. Duplicating a
SecP256r1MLKEM768orSecP384r1MLKEM1024key pairyields a key whose public half cannot be read:
OSSL_PKEY_PARAM_PUB_KEYandENCODED_PUBLIC_KEYfail,wp_mlx_export()fails before its callback (takingthe private half down with it), and
EVP_PKEY_eq()fails on a key pairselection.
X25519MLKEM768is unaffected —wc_curve25519_import_private_ex()never touches
pubSet.Failures are loud error returns; no memory-safety or key-material exposure.
libssl does not dup key-share keys, so TLS 1.3 hybrid key exchange is not on the
failing path.
Fix (
src/wp_mlx_kmgmt.c)Derive the public point after the private import, matching what
wp_mlx_load_keys()already does for the same hazard:Closes f_11549.
Tests (
test/test_mlkem.c)test_mlx_dup— the hybrid groups had no dup coverage at all;test_mlkem_dupexercises only the pure ML-KEM levels. For each of the three hybrid names it
dups the key, compares public key bytes against the original, encapsulates
against the duplicate, and decapsulates that ciphertext with both keys.
Verification
SecP256r1MLKEM768without the fix(
Dup public key retrieval failed);X25519MLKEM768passes.-Werror(OpenSSL 3.6.0, wolfSSL master,--enable-mlkem).