Skip to content

Address ML-KEM PR review feedback and fix security issues#2

Merged
Frauschi merged 2 commits intomlkemfrom
claude/ml-kem-review-fixes-9GzYi
Apr 7, 2026
Merged

Address ML-KEM PR review feedback and fix security issues#2
Frauschi merged 2 commits intomlkemfrom
claude/ml-kem-review-fixes-9GzYi

Conversation

@Frauschi
Copy link
Copy Markdown
Owner

@Frauschi Frauschi commented Apr 7, 2026

Summary

Review Comment Fixes

  • Header includes: Use wc_mlkem.h instead of mlkem.h across all 8 files
  • Redundant message fields: Remove sz from keygen request, ctSz/ssSz from encaps request, ssSz from decaps request (all derivable from ML-KEM level)
  • Redundant API parameter: Remove size from MakeExportKey/MakeCacheKey, aligning non-DMA with DMA signatures
  • Documentation: Add doxygen comments to all 13 ML-KEM function declarations
  • Heap allocation: Move large WC_ML_KEM_MAX_PRIVATE_KEY_SIZE stack buffers to heap via XMALLOC
  • Debug logging: Add WH_DEBUG_CLIENT_VERBOSE() to all ML-KEM client methods
  • Code structure: Refactor _MlKemMakeKey to early-exit pattern for readability
  • Buffer validation: Error on insufficient user buffers instead of silently truncating
  • Server handlers: Compute output sizes from level via wc_MlKemKey_CipherTextSize()/wc_MlKemKey_SharedSecretSize() instead of trusting request fields

Security and Bug Fixes

  • Sensitive data cleanup: Zero key material with ForceZero() before XFREE() in all import/export/keygen functions
  • Response buffer bounds: Validate server-reported sizes fit within comm buffer before memcpy in encaps/decaps
  • Info disclosure: Zero-initialize DMA response structs in server handlers to prevent leaking stack memory on error paths
  • Key eviction leak: Fix early returns in encaps/decaps that skipped eviction of auto-imported temporary keys
  • Uninitialized variables: Initialize evict, ctLen, ssLen in DMA server handlers
  • Test fix: Fix missed call site still using old 4-arg MakeExportKey signature

Test plan

  • Verify all ML-KEM unit tests pass (non-DMA and DMA flows)
  • Verify ML-KEM benchmarks build and run for all levels (512/768/1024)
  • Verify no regressions in existing crypto tests

https://claude.ai/code/session_011esueUzLf9urCUHRPEhyXb

claude added 2 commits April 7, 2026 21:03
- Use wc_mlkem.h instead of mlkem.h across all includes
- Remove redundant sz from keygen request (determined by level)
- Remove redundant ctSz/ssSz from encaps request and ssSz from
  decaps request (output sizes fixed by ML-KEM level)
- Remove redundant size parameter from MakeExportKey/MakeCacheKey
  APIs, aligning non-DMA with DMA signatures
- Move large ML-KEM key buffers from stack to heap via XMALLOC
- Add WH_DEBUG_CLIENT_VERBOSE logging to all ML-KEM client methods
- Add doxygen documentation comments to all ML-KEM function
  declarations in wh_client_crypto.h
- Refactor _MlKemMakeKey to use early-exit pattern for readability
- Fix encaps/decaps buffer size checks: error on insufficient
  buffers instead of silently truncating
- Update server encaps/decaps handlers to compute output sizes
  from key level instead of request fields
- Update tests and benchmarks for API changes

https://claude.ai/code/session_011esueUzLf9urCUHRPEhyXb
- Fix missed test call with old 4-arg MakeExportKey signature
- Zero sensitive key material with ForceZero before XFREE in all
  import/export/keygen functions to prevent key data remaining on
  the heap after deallocation
- Add response buffer bounds validation in encaps/decaps to prevent
  reading past the comm buffer on corrupted server responses
- Fix early returns in encaps/decaps (both DMA and non-DMA) that
  skipped key eviction when dataPtr was NULL after auto-import
- Zero-initialize DMA response structs in server-side keygen,
  encaps, and decaps handlers to prevent leaking uninitialized
  stack memory to the client on error paths
- Initialize evict and size variables in DMA server handlers

https://claude.ai/code/session_011esueUzLf9urCUHRPEhyXb
@Frauschi Frauschi merged commit 067203f into mlkem Apr 7, 2026
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