Spec: ML-DSA's RejNTTPoly four times (vg_mldsa_rej_ntt_poly4) - #492
Merged
Merged
Conversation
The contract of a function that samples four elements of the matrix A at once, as ML-KEM's vg_mlkem_sample_ntt4 does: for each of the four 34-byte seeds, RejNTTPoly (FIPS 204 Algorithm 30) of it, reduced, or 0 if the loop does not finish within Appendix C's least bound for one of them. Its scratch is that of vg_mldsa_rej_ntt_poly (256 u64s), so callers can pass the same working space. No implementation yet: an x86-64 one, with four SHAKE128 instances in AVX2 registers, follows in its own PR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ddof3szoTi7HB8iCsM2MCr
Four interleaved Keccak states, the second buffer of the 4-way permutation and its table of round constants already take 2368 bytes, before the squeezed output; ML-KEM's vg_mlkem_sample_ntt4 has 1024 u64s for the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ddof3szoTi7HB8iCsM2MCr
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 (Spec only). This is the first step towards sampling ML-DSA's matrix
Afour elements at a time on x86-64, with four SHAKE128 instances in AVX2 registers, as ML-KEM already does withvg_mlkem_sample_ntt4. Per CLAUDE.md, the spec goes in its own PR. The implementation, its proofs, and movingExpandAin keygen, sign and verify onto it come in later PRs.Why
With the AVX2 polynomial arithmetic (#491), Keccak is now the largest cost in ML-DSA on x86-64: about 38% of signing instructions, and more of keygen and verify. Most of the permutations are spent in
ExpandA, which runsRejNTTPolyk·l times (30 for ML-DSA-65). Those calls are independent, so they suit the existing 4-way AVX2 Keccak (Impl/Sha3/X86_64/X4.lean).What
All of this is in
Spec/MlDsa/Poly.lean. It mirrorssampleNTT4Sig/sampleNTT4Contract/sampleNTT4Apifrom ML-KEM, and uses ML-DSA's ownrejNTTPoly,Bounds,minBoundsandleakBytesthe same wayrejNTTContractdoes.rejNTT4Sig:vg_mldsa_rej_ntt_poly4(seeds: *const [u8; 136], a: *mut [u32; 1024], scratch: *mut [u64; 1024]) -> u32. That is 8 KiB of scratch, the same as ML-KEM'svg_mlkem_sample_ntt4. The four interleaved states, the 4-way permutation's second buffer and its round-constant table already take 2,368 bytes before any squeezed output.seed4andpoly4: seedkis the 34 bytes from byte34 k, and polynomialkstarts at byte1024 k.rejNTT4Contract. If it returns 1, every output polynomial is reduced and, for eachk < 4, the polynomial atpoly4 a kisRejNTTPoly(seed4 seeds k)for some bounds. If it returns 0, thenRejNTTPolyfails withinminBoundsfor at least one seed. It may leak the 136 seed bytes, which are public in ML-DSA (ρand the indices). That is the same leakage as four calls torejNTTContract.rejNTT4Api: name, module, contract on every target, and documentation, which reusesboundDocandscratchSafety.There are no other changes: no TCB, Impl or artifacts.
Checks run
lake build +VerifiedGarbage.Spec.MlDsa.Polycheck_lean_imports,check_lean_speed🤖 Generated with Claude Code
https://claude.ai/code/session_01Ddof3szoTi7HB8iCsM2MCr