Skip to content

pqc: hold the key mutex around shared-key wolfCrypt calls - #535

Merged
aidangarske merged 1 commit into
wolfSSL:masterfrom
ColtonWilley:fix/pqc-key-mutex
Dec 3, 2026
Merged

aidangarske merged 1 commit into
wolfSSL:masterfrom
ColtonWilley:fix/pqc-key-mutex

Conversation

@ColtonWilley

Copy link
Copy Markdown
Contributor

wolfCrypt's ML-KEM and ML-DSA keys hold SHA-3/SHAKE state that every encapsulate, decapsulate, encode, sign and verify mutates, so concurrent operations on one shared EVP_PKEY returned wrong shared secrets, invalid signatures and false verify failures. This takes the existing per-key mutex around those calls, adds concurrency tests that fail without the fix, and runs the PQC tests in the TSan job on wolfSSL versions that support them.

Copilot AI balanced review requested due to automatic review settings December 2, 2026 19:03

Copilot AI 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.

🔵 Needs a closer look

Shared-key cryptographic concurrency warrants TSan validation on supported wolfSSL versions, and unavailable backend ML-DSA raw/DER export code prevents full verification of interactions with the new sign/verify locks.

No open issues 🎉

What changed in this PR

Protects shared post-quantum keys in wolfProvider by extending per-key mutex coverage around wolfCrypt operations.

Changes:

  • Serializes shared-key ML-KEM, hybrid KEM, and ML-DSA operations.
  • Adds concurrency and hybrid-key equality regression tests.
  • Enables post-quantum tests in ThreadSanitizer builds on supported wolfSSL versions.
File Description
test/​unit.h Declares new regression tests.
test/​unit.c Registers new regression tests.
test/​test_mlkem.c Adds shared-key concurrency and hybrid equality tests.
test/​test_mldsa.c Adds concurrent signing and verification tests.
src/​wp_mlx_kmgmt.c Locks hybrid-key encoding, duplication, and comparison reads.
src/​wp_mlx_kem.c Locks both hybrid components during KEM operations.
src/​wp_mlkem_kmgmt.c Adds locked key-encoding helpers.
src/​wp_mlkem_kem.c Locks encapsulation and decapsulation.
src/​wp_mldsa_sig.c Locks signing and verification across supported paths.
src/​wp_mldsa_kmgmt.c Exposes and documents the key mutex.
include/​wolfprovider/​alg_funcs.h Declares key-mutex accessors.
.github/​workflows/​sanitizers.yml Enables version-gated post-quantum testing under ThreadSanitizer.

Review effort: Balanced

ML-KEM and ML-DSA keys carry SHA-3/SHAKE state that encapsulate,
decapsulate, encode, sign and verify all mutate, so threads sharing one
EVP_PKEY corrupted each other's results. Take the per-key mutex around
those calls, covering both halves of the hybrid KEMs, and add
concurrency tests that the TSan CI job now runs.
@aidangarske
aidangarske merged commit 77985e5 into wolfSSL:master Dec 3, 2026
84 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.

3 participants