Skip to content

Add ML-KEM support (keygen/encaps/decaps, DMA/non-DMA, tests, benchmark)#1

Open
Frauschi wants to merge 7 commits intomainfrom
mlkem
Open

Add ML-KEM support (keygen/encaps/decaps, DMA/non-DMA, tests, benchmark)#1
Frauschi wants to merge 7 commits intomainfrom
mlkem

Conversation

@Frauschi
Copy link
Copy Markdown
Owner

Summary

  • add ML-KEM core support for key generation, encapsulation, and decapsulation
  • support both non-DMA and DMA request paths in client/server crypto handling
  • add wolfCrypt crypto callback integration for ML-KEM PK operations
  • add ML-KEM unit tests (all enabled levels) for non-DMA and DMA flows
  • add benchmark module coverage for ML-KEM-512/768/1024 keygen/encaps/decaps (DMA and non-DMA)

Notes

  • local implementation plan file remains untracked and is not part of this PR

Validation

  • targeted object builds for touched units pass
  • full test/benchmark links in this environment still show pre-existing ASAN/DMA link issues unrelated to the new ML-KEM logic

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
claude and others added 2 commits April 8, 2026 10:57
- Change 0 == _IsMlKemLevelSupported() to !_IsMlKemLevelSupported()
  across all 6 server handler call sites
- Fix uint32 overflow in Decapsulate total_len: use uint64_t to
  prevent overflow when ct_len is large
- Fix server encaps bounds check: use ct_len + ss_len > max_out
  to properly verify both ct and ss fit in response buffer
- Store original DMA buffer sizes for POST processing in
  EncapsulateDma/DecapsulateDma to avoid using potentially modified
  inout sizes
- Use exact key size (via wc_MlKemKey_PrivateKeySize) in ImportKey
  XMALLOC instead of WC_ML_KEM_MAX_PRIVATE_KEY_SIZE to minimize
  allocation
- Fix MlKemSerializeKey: try wc_MlKemKey_EncodePrivateKey first and
  fall back to public key on failure, since PrivateKeySize always
  returns a size regardless of whether a private key exists
- Remove unnecessary { } nesting in _MlKemMakeKey and
  _MlKemMakeKeyDma, move variables to function scope
- Move DMA POST processing to end of _MlKemMakeKeyDma, after
  response handling, consistent with other DMA functions
- Move shared secret from DmaBuffer to inline in DMA encaps/decaps
  messages: ss is always 32 bytes (WC_ML_KEM_SS_SZ) so it fits
  efficiently in the message like AES key data
- Fix MAX_BENCH_OPS: change from 128 to 119 (101 + 18 ML-KEM ops)

https://claude.ai/code/session_011esueUzLf9urCUHRPEhyXb
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