Skip to content

ml-kem: optimize keygen, encaps and decaps - #421

Open
ccipherx wants to merge 10 commits into
RustCrypto:masterfrom
ccipherx:ml-kem/perf
Open

ccipherx wants to merge 10 commits into
RustCrypto:masterfrom
ccipherx:ml-kem/perf

Conversation

@ccipherx

@ccipherx ccipherx commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Replace hardened ctutils selects in module-lattice arithmetic with select-free kernels using 16-bit Montgomery and Barrett reductions. This removes per-butterfly memory spills and enables x86 vectorization.

Benchmarks

ML-KEM-512 ML-KEM-768 ML-KEM-1024
KeyGen 30.7 → 10.4 50.3 → 17.1 75.2 → 27.0
Encaps 36.3 → 5.6 56.6 → 7.2 82.6 → 10.1
Decaps 51.3 → 8.8 77.4 → 11.7 109.0 → 16.1
EK parse 2.6 → 6.7 3.9 → 12.9 5.2 → 21.2

Trade-offs

  • Matrix caching adds 2 / 4.5 / 8 KiB per key and moves expansion to EncryptionKey::new.
  • thumbv7em .text grows 17% (70,876 → 83,216 bytes).
  • KeyGen-768 worst-case stack grows 30.1 → 41.7 KB. Decaps stack drops by up to 16%.

@tarcieri

tarcieri commented Nov 9, 2026

Copy link
Copy Markdown
Member

Thanks, this looks promising but I need some time to review it

@tarcieri

tarcieri commented Nov 9, 2026

Copy link
Copy Markdown
Member

I think some of this might be worth extracting into module-lattice too so we can reuse it with ml-dsa, but let's start with it just in ml-kem and then follow up on that.

@ccipherx

Copy link
Copy Markdown
Contributor Author

I think some of this might be worth extracting into module-lattice too so we can reuse it with ml-dsa, but let's start with it just in ml-kem and then follow up on that.

sounds good, will create a follow up pr

This branch has not been deployed

No deployments
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