Repository navigation
Spec: ML-KEM NTT and inverse of a polynomial stored with 16 bits - #3042
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FoYWDDEDFq1DFev5X7n2aq
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.
Trust change: new Spec (
lean/VerifiedGarbage/Spec/MlKem/Ntt16.lean). It adds the contracts andApis of two new functions:vg_mlkem16_ntt(f: *mut [u16; 256], scratch: *mut [u64; 64]):NTT(FIPS 203 Algorithm 9) in place.vg_mlkem16_inv_ntt(f: *mut [u16; 256], scratch: *mut [u64; 64]):NTT⁻¹(Algorithm 10) in place.They are the 16-bit counterparts of
vg_mlkem_nttandvg_mlkem_inv_ntt.Why
The AArch64 ML-KEM tops inline the 16-bit NTT today, in 4 to 11 copies per function. The next PR replaces it with a rescheduled transform, in the style of mlkem-native: by-element zetas, fewer transposes in layers 4–7, and two blocks interleaved per trip. That doubles the transform's size, so the tops will call it out of line instead of inlining it. A call needs a registered function with a contract, and none exists for 16-bit storage:
vg_mlkem_ntttakesu32coefficients. The inverse is included so that its rescheduling can follow without another Spec PR.The contract (
inPlace16Contract)fis reduced with 16-bit coefficients (ReducedW 16).fholdstof it, reduced (PolyIsW 16 … (t (polyAtW 16 m f))), witht = nttort = nttInv.Spec/MlKem/Kpke16.lean, andnttandnttInvare those ofSpec/MlKem/Poly.lean.constsentry, as today, not an argument.Nothing implements or calls these yet, so no code is emitted and
src/asm/is unchanged.Checks
lake buildof the module.check_lean_imports,check_lean_modulesandcheck_lean_public_imports;check_lean_speedandcheck_registrations.Generated by Claude Code