ml-kem/module-lattice: add traits for NTT operations #211
+141
−107
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.
Adds
MultiplyNtttomodule-lattice, andNttandNttInversetoml-kem.Previously
module-latticedefined theMulimpl onNttPolynomialin terms of Algorithm 45 from FIPS 204, and this is used by theMulimpls onNttVectorandNttMatrixas well.For ML-KEM we instead need to plug in Algorithm 11 from FIPS 203 (MultiplyNTTs), so we need a trait that lets each crate define the
Mulimpl onNttPolynomial.This adds a
MultiplyNtttrait tomodule-lattice, currently defined on aField(perhaps not great but it's the generic parameter we have), which allows each construction to plug in their own NTT multiplication algorithm.The existing implementation of Algorithm 45 from FIPS 204 will need to move to the
ml-dsacrate.Also, following the structure of the
ml-dsacrate, this defines two same-shaped traits,NttandNttInverse, that can be impl'd on types frommodule-latticeto use the same method syntax that was being used previously before #210.Unfortunately we can't share traits with
ml-dsa, because the only way we can impl these traits for types frommodule-latticeis if we define them. But they're small and there aren't that many of them.