Skip to content

Stricter mldsa contract for no public keys - #11644

Merged
SparkiDev merged 2 commits into
wolfSSL:masterfrom
stenslae:pr2-stricter-contracts
Nov 5, 2026
Merged

SparkiDev merged 2 commits into
wolfSSL:masterfrom
stenslae:pr2-stricter-contracts

Conversation

@stenslae

@stenslae stenslae commented Oct 5, 2026

Copy link
Copy Markdown
Member

Description

Updated ML-DSA verify and export operations to strictly require a public key so a specific PUBLIC_KEY_E error is returned.

Depends on PR #10985

Testing

Added coverage to exercise PUBLIC_KEY_E cases.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@stenslae stenslae self-assigned this Oct 5, 2026
Copilot AI balanced review requested due to automatic review settings October 5, 2026 17:41
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m4-pq

  • FLASH: .text +192 B (+0.1%, 312,336 B / 1,048,576 B, total: 30% used)

gcc-arm-cortex-m7-pq

  • FLASH: .text +192 B (+0.1%, 313,232 B / 1,048,576 B, total: 30% used)

zephyr-frdm_rw612

  • FLASH: log_const_area -8 B, rodata -8 B, text +1,512 B (+0.5%, 283,960 B / 67,108,864 B, total: 0% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The small-memory error path can process uninitialized accumulator data after rejection sampling fails.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Tightens ML-DSA public-key requirements and adds explicit public-key derivation from private keys.

Changes:

  • Returns PUBLIC_KEY_E when verification/export lacks a public key.
  • Adds wc_MlDsaKey_MakePublicKey() with fault-hardening support.
  • Expands API, white-box, OOM, and CI coverage.
File Description
wolfssl/​wolfcrypt/​wc_mldsa.h Declares public-key derivation support.
wolfcrypt/​src/​wc_mldsa.c Implements derivation and stricter validation.
tests/​unit-mcdc/​test_wc_mldsa_whitebox.c Updates white-box coverage notes.
tests/​unit-mcdc/​test_mldsa_hash_fault_whitebox.c Tests derivation hash failures.
tests/​include.am Documents shared fault allocator usage.
tests/​api/​test_mldsa.h Registers new ML-DSA tests.
tests/​api/​test_mldsa.c Adds derivation and error-path coverage.
doc/​dox_comments/​header_files/​wc_mldsa.h Documents API and error contracts.
.github/​configs/​pq-all.json Adds fault-hardened CI configurations.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread wolfcrypt/src/wc_mldsa.c Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The cryptographic derivation and fault-hardening paths span numerous compile-time configurations and warrant final human validation.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11644

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Coverage: 2 of 5 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_mldsa.c, tests/unit-mcdc/test_mldsa_hash_fault_whitebox.c, tests/unit-mcdc/test_wc_mldsa_whitebox.c

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

@stenslae stenslae assigned wolfSSL-Bot and unassigned stenslae Oct 5, 2026
@SparkiDev

Copy link
Copy Markdown
Contributor

Conflicts - please fix.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The cryptographic derivation implementation and extensive build-configuration branches warrant final human review.

0 open findings

🧠 Review effort: Balanced

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11644

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Coverage: 3 of 5 in-scope changed file(s) opened by the reviewer; not opened: tests/unit-mcdc/test_mldsa_hash_fault_whitebox.c, tests/unit-mcdc/test_wc_mldsa_whitebox.c

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

@stenslae stenslae removed their assignment Oct 12, 2026
@stenslae
stenslae force-pushed the pr2-stricter-contracts branch 2 times, most recently from d7de8c8 to 934db28 Compare October 19, 2026 17:54
@stenslae
stenslae requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot October 19, 2026 17:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The cryptographic API contract change needs human validation across native, callback-only, and FIPS configurations.

No open issues 🎉

Review effort: Balanced

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11644

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/wc_mldsa.h, tests/api/test_mldsa.h
Coverage: 3 of 3 in-scope changed file(s) opened by the reviewer

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

@stenslae
stenslae force-pushed the pr2-stricter-contracts branch from 934db28 to 277218e Compare October 19, 2026 20:44
@stenslae
stenslae force-pushed the pr2-stricter-contracts branch from 277218e to 1204886 Compare October 21, 2026 18:05
@stenslae
stenslae requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot October 21, 2026 18:28
@stenslae

Copy link
Copy Markdown
Member Author

@claude review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Security-sensitive key validation and configuration-dependent callback behavior require human review across supported build configurations.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11644

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): ChangeLog.md, doc/dox_comments/header_files/wc_mldsa.h, tests/api/test_mldsa.h
Coverage: 4 of 5 in-scope changed file(s) opened by the reviewer; not opened: tests/unit-mcdc/test_mldsa_hash_fault_whitebox.c

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I reviewed this PR and found no bugs. It changes the error codes returned by the public ML-DSA verify and export APIs, and makes the OpenSSL compat layer check key pairs, so a maintainer should still look at it.

What was reviewed:

  • Software verify paths (msg, ctx, ctx-hash, VerifyMu): they now return PUBLIC_KEY_E when no public key is set, before H(pk) is computed over an unset buffer.
  • mldsa_check_key_pair() and the wider #if guard on mldsa_check_pub_tr(): the helper sits under WOLFSSL_MLDSA_PRIVATE_KEY plus WOLFSSL_MLDSA_PUBLIC_KEY, so it is defined in every build that uses it. The tr comparison uses ConstantCompare.
  • ExportKey and ExportPubRaw: buffer sizes are checked before anything is written, and both sizes are reported on BUFFER_E. Also checked the MakePublicKey calls added to wolfSSL_X509_set_pubkey and wolfssl_i_i2d_mldsapublickey, including the cleanup when they fail.
Extended reasoning...

The change touches the ML-DSA core in wolfcrypt/src/wc_mldsa.c, the PKCS#11 public-key path and two OpenSSL compat entry points (src/x509.c, wolfcrypt/src/evp_pk.c), plus about 700 lines of new tests. This is security-sensitive crypto code. Several public APIs now return PUBLIC_KEY_E where they used to return BAD_FUNC_ARG. wolfSSL_X509_set_pubkey and the i2d path can now fail on keys they used to accept. Those contract changes, and two earlier inline review threads that only the author resolved, are why this is a defer and not an approval.

@stenslae
stenslae force-pushed the pr2-stricter-contracts branch from 1204886 to f404bb7 Compare October 23, 2026 19:23
@stenslae
stenslae requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot October 23, 2026 19:24

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11644

Scan targets checked: none
Unchanged since last review (not re-run): wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): ChangeLog.md, doc/dox_comments/header_files/wc_mldsa.h, tests/api/test_mldsa.h

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Cryptographic validation and serialization changes need maintainer review across native, callback-only, and reduced-feature configurations.

No open issues 🎉

Review effort: Balanced

@stenslae stenslae assigned stenslae and unassigned wolfSSL-Bot Nov 2, 2026
@stenslae
stenslae force-pushed the pr2-stricter-contracts branch from f404bb7 to 049aadb Compare November 4, 2026 18:10
@stenslae
stenslae requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 4, 2026 18:10
@stenslae

stenslae commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

@claude review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the ML-DSA public-key requirements and export-handling changes.

No open issues 🎉

Review effort: Balanced

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11644

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): ChangeLog.md, doc/dox_comments/header_files/wc_mldsa.h, tests/api/test_mldsa.h
Coverage: 3 of 6 in-scope changed file(s) opened by the reviewer; not opened: tests/unit-mcdc/test_mldsa_hash_fault_whitebox.c, tests/unit-mcdc/test_wc_mldsa_whitebox.c, wolfssl/wolfcrypt/wc_mldsa.h

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I reviewed the latest push and didn't find any bugs. A maintainer should still look at it, because it changes error codes that callers can see in ML-DSA verify and export. It also adds an H(pk) == tr check, so wc_MlDsaKey_ExportKey and wc_MlDsaKey_KeyToDer now reject mismatched key pairs that they used to accept.

What was reviewed:

  • mldsa_verify_key_check is used in all three verify paths and in the non-callback path of VerifyMu, so verify can no longer run against an unset public key.
  • The new guards for mldsa_check_pub_tr and mldsa_check_key_pair match where they are called (PRIVATE_KEY && PUBLIC_KEY, with the hash skipped under CB_ONLY), so neither helper is left defined but unused.
  • The ExportKey rewrite sets both sizes before returning BUFFER_E and copies nothing until both buffers fit. ExportPubRaw now gets its size from wc_MlDsaKey_PubSize, which also covers the FIPS204-draft levels.
Extended reasoning...

This change edits error handling for ML-DSA verify, export and DER encoding in wolfcrypt/src/wc_mldsa.c, plus one line in wc_pkcs11.c. It also updates the doxygen docs and the ChangeLog and adds about 600 lines of tests. The security-sensitive surface is public-key presence checks and a new constant-time H(pk)/tr consistency check when exporting a key pair. No bugs were found. It is a deferral rather than an approval because this is crypto library code with error-code changes callers can see and new rejection behavior, which a maintainer should sign off on.

@stenslae stenslae assigned wolfSSL-Bot and unassigned stenslae Nov 4, 2026
@SparkiDev
SparkiDev merged commit b33bc98 into wolfSSL:master Nov 5, 2026
444 of 445 checks passed
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.

5 participants