ML-KEM: harden constant-time cmov and add cross-implementation test coverage#40
Merged
Merged
Conversation
…mprehensive tests - Add ct_barrier_u8 using inline asm (x86/arm/riscv) to prevent optimizer from converting cmov into a branch (side-channel protection) - Add NIST FIPS 203 intermediate value tests (full keygen/encaps/decaps) - Add cross-implementation tests using pqcrypto (liboqs) generated vectors - Add unit tests for: cmov, barrett_reduce, montgomery_reduce, NTT, compression/decompression roundtrips, CBD2, rej_uniform, poly_tomsg boundaries - Add gen_matrix transpose relationship verification - Total: 53 ML-KEM tests passing (up from 34)
Copilot
AI
changed the title
ML-KEM: code review improvements - strengthen constant-time ops and add comprehensive tests
ML-KEM: harden constant-time cmov and add cross-implementation test coverage
Jun 3, 2026
Copilot created this pull request from a session on behalf of
notABot101010
June 3, 2026 16:09
View session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Code review of ML-KEM (FIPS 203) implementation for spec conformance, side-channel resistance, and test coverage.
Side-channel fix
The
cmovfunction converted aboolto a mask without a compiler barrier, allowing the optimizer to potentially convert the branchless XOR pattern into a conditional branch—leaking timing in the FO transform's implicit rejection path.Same technique used by the
constant_time_eqcrate in this repo. Platform coverage: x86/x86_64, ARM/AArch64, RISC-V, withblack_boxfallback.Conformance review (no issues found)
G(d || k)keygen domain separation correctv - s^T·udecryption order correct (Algorithm 6 step 3)New tests (34 → 53)
poly_tobytesroundtrip,gen_matrixtranspose, CBD2 range,rej_uniformrejection,poly_tomsgboundaries