Skip to content

Conversation

@tarcieri
Copy link
Member

Adds MultiplyNtt to module-lattice, and Ntt and NttInverse to ml-kem.

Previously module-lattice defined the Mul impl on NttPolynomial in terms of Algorithm 45 from FIPS 204, and this is used by the Mul impls on NttVector and NttMatrix as 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 Mul impl on NttPolynomial.

This adds a MultiplyNtt trait to module-lattice, currently defined on a Field (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-dsa crate.

Also, following the structure of the ml-dsa crate, this defines two same-shaped traits, Ntt and NttInverse, that can be impl'd on types from module-lattice to 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 from module-lattice is if we define them. But they're small and there aren't that many of them.

@tarcieri tarcieri requested a review from bifurcation January 29, 2026 14:57
@tarcieri tarcieri force-pushed the ml-kem/traits-for-ntt-ops branch 2 times, most recently from f78886d to 22409f7 Compare January 29, 2026 15:13
Adds `MultiplyNtt` to `module-lattice`, and `Ntt` and `NttInverse` to
`ml-kem`.

Previously `module-lattice` defined the `Mul` impl on `NttPolynomial`
in terms of Algorithm 45 from FIPS 204, and this is used by the `Mul`
impls on `NttVector` and `NttMatrix` as 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 `Mul`
impl on `NttPolynomial`.

This adds a `MultiplyNtt` trait to `module-lattice`, currently defined
on a `Field` (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-dsa` crate.

Also, following the structure of the `ml-dsa` crate, this defines two
same-shaped traits, `Ntt` and `NttInverse`, that can be impl'd on types
from `module-lattice` to 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 from `module-lattice` is if we define
them. But they're small and there aren't that many of them.
@tarcieri tarcieri force-pushed the ml-kem/traits-for-ntt-ops branch from 22409f7 to 8a9b7be Compare January 29, 2026 15:17
@tarcieri tarcieri merged commit 89b4192 into master Jan 29, 2026
28 checks passed
@tarcieri tarcieri deleted the ml-kem/traits-for-ntt-ops branch January 29, 2026 15:19
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