Repository navigation
Reduce ML-DSA matrix-row dot products once per coefficient - #2574
Open
carstenartur wants to merge 1 commit into
Open
carstenartur wants to merge 1 commit into
carstenartur wants to merge 1 commit into
Conversation
Accumulate each ML-DSA NTT matrix-row dot product coefficient in a `long` and apply one Montgomery reduction. For `L = 4, 5, or 7`, this lowers the count per row from 1,024/1,280/1,792 to 256, with no additional allocations. ### Why this is equivalent Write `M(x) = x*R^-1` modulo `q`, with `q = 8380417` and `R = 2^32`. For products `p_i`, `sum(M(p_i)) = sum(p_i)*R^-1 = M(sum(p_i))` modulo `q`, so the Montgomery scale is preserved. Across the four engine callers, matrix entries lie in `[0,q-1]` and transformed vector coefficients have magnitude at most 34,162,429, including malformed eta encodings. Thus `abs(sum(p_i)) <= 7*(q-1)*34,162,429 < q*2^31`. The accumulation and Montgomery numerator fit `long`, and the result fits `int`. The callers use independent outputs. Existing reduction, inverse NTT and final canonicalization preserve packed outputs, rounding and verification decisions. The optional terms depend only on public `L`; no secret-dependent branch or address is added. ### Validation and measurements Recompiled the complete core on this upstream-based branch and passed all 28 ML-DSA, Wycheproof and internal tests on JDK 21. Differential tests cover every parameter set, endpoints and canonical results after inverse NTT; a malformed eta regression checks key derivation. Against upstream bb81bfa on OpenJDK 21, median kernel CPU time fell from 2.36/2.76/4.51 us to 1.83/1.66/2.27 us for 44/65/87. Full-operation timings were mixed: ML-DSA-44 keygen was +6.5% CPU in the primary run and +1.5% in a longer follow-up. Allocation was unchanged. Single-host timings are not a uniform speedup claim. [Detailed proof and measurements](https://github.com/carstenartur/bc-java/blob/475def1f62cc4ada95dfc6913dbff449f7b7fafe/scripts/bench/montgomery-study.md) [Montgomery (1985)](https://doi.org/10.1090/S0025-5718-1985-0777282-X) [Dilithium v3.1, section 5.6](https://pq-crystals.org/dilithium/data/dilithium-specification-round3-20210208.pdf) Developed with assistance from OpenAI Codex.
Collaborator
|
Thanks for the PRs and the detailed write-up. They overlap with work we already have in progress on the ML-KEM/ML-DSA NTT code, so we'll look at them together with that and come back to you here. |
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.
Accumulate each ML-DSA NTT matrix-row dot product coefficient in a
longand apply one Montgomery reduction. ForL = 4, 5, or 7, this lowers the count per row from 1,024/1,280/1,792 to 256, with no additional allocations.Why this is equivalent
Write
M(x) = x*R^-1moduloq, withq = 8380417andR = 2^32. For productsp_i,sum(M(p_i)) = sum(p_i)*R^-1 = M(sum(p_i))moduloq, so the Montgomery scale is preserved.Across the four engine callers, matrix entries lie in
[0,q-1]and transformed vector coefficients have magnitude at most 34,162,429, including malformed eta encodings. Thusabs(sum(p_i)) <= 7*(q-1)*34,162,429 < q*2^31. The accumulation and Montgomery numerator fitlong, and the result fitsint. The callers use independent outputs. Existing reduction, inverse NTT and final canonicalization preserve packed outputs, rounding and verification decisions. The optional terms depend only on publicL; no secret-dependent branch or address is added.Validation and measurements
Recompiled the complete core on this upstream-based branch and passed all 28 ML-DSA, Wycheproof and internal tests on JDK 21. Differential tests cover every parameter set, endpoints and canonical results after inverse NTT; a malformed eta regression checks key derivation.
Against upstream bb81bfa on OpenJDK 21, median kernel CPU time fell from 2.36/2.76/4.51 us to 1.83/1.66/2.27 us for 44/65/87. Full-operation timings were mixed: ML-DSA-44 keygen was +6.5% CPU in the primary run and +1.5% in a longer follow-up. Allocation was unchanged. Single-host timings are not a uniform speedup claim.
Detailed proof and measurements Montgomery (1985) Dilithium v3.1, section 5.6
Developed with assistance from OpenAI Codex.