Reject curve448 public key export from an unset key - #11154
Reject curve448 public key export from an unset key#11154yosuke-wolfssl wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes an invalid Curve448 key-state edge case where wc_curve448_export_public_ex() could derive and export a degenerate public key from an uninitialized (privSet==0 && pubSet==0) key. The change aligns public-key export behavior with existing private export and shared-secret APIs that already reject unset keys.
Changes:
- Add a key-state guard in
wc_curve448_export_public_ex()to returnECC_BAD_ARG_Ewhen neither public nor private key material is set. - Update in-source and Doxygen (EN/JA) documentation to reflect the new error condition.
- Extend the Curve448 API tests to cover export attempts from a freshly-initialized, unset key.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| wolfcrypt/src/curve448.c | Reject public key export when both pubSet and privSet are unset, preventing lazy derivation from an all-zero scalar. |
| tests/api/test_curve448.c | Add a regression test asserting ECC_BAD_ARG_E for exporting from an unset key. |
| doc/dox_comments/header_files/curve448.h | Document the additional ECC_BAD_ARG_E condition for unset keys (English). |
| doc/dox_comments/header_files-ja/curve448.h | Document the additional ECC_BAD_ARG_E condition for unset keys (Japanese). |
💡 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 #11154
Scan targets checked: wolfcrypt-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src
Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Findings are non-blocking.
eb1e50e to
1c9efc4
Compare
Problem
wc_curve448_export_public_ex()lazily derives the public key wheneverkey->pubSetis clear, but never checkskey->privSet.wc_curve448_init()zeroes the whole key andwc_curve448_make_pub()does no clamping of its own, so this sequence succeeds and returns a public key for a key pair that does not exist:The ladder runs over the all-zero scalar,
pubSetis set to 1,CURVE448_PUB_KEY_SIZEbytes are written and 0 is returned, with nothing to distinguish the result from a real export. Callers that treat a 0 return as "this key is usable" get a degenerate public value.This is inconsistent with the rest of the file:
wc_curve448_export_private_raw_ex()rejects!privSet, andwc_curve448_shared_secret_ex()rejects!privSet || !pubSet. Only the public exporter was missing the state check. Closes f-7076.Fix (
wolfcrypt/src/curve448.c)Return
ECC_BAD_ARG_Ewhen neither component is set, before the lazy derivation:Keys holding only a private scalar, as produced by
wc_curve448_import_private_ex(), still derive the public key on export as before. Doc comments on both the_exfunction and thewc_curve448_export_public()wrapper are updated, along with the doxygen headers (English and Japanese).Tests
test_wc_curve448_export_public_ex()gains an unset-key case: a second freshlywc_curve448_init()ed key, assertingECC_BAD_ARG_Efrom bothwc_curve448_export_public()andwc_curve448_export_public_ex().Verification
--enable-curve25519 --enable-curve448 --enable-all-crypto, no warnings../tests/unit.test: 943 passed, 0 failed.testwolfcryptexit 0.0instead ofECC_BAD_ARG_E.test_wc_curve448_export_import_endianstill passes, covering theprivSet-only lazy-derivation path.