Skip to content

ml-kem: use NttPolynomial from module-lattice#210

Merged
tarcieri merged 1 commit intomasterfrom
ml-kem/use-ntt-polynomial-from-module-lattice
Jan 29, 2026
Merged

ml-kem: use NttPolynomial from module-lattice#210
tarcieri merged 1 commit intomasterfrom
ml-kem/use-ntt-polynomial-from-module-lattice

Conversation

@tarcieri
Copy link
Copy Markdown
Member

It seems module-lattice has a Mul impl for NttPolynomial that implements ML-DSA's MultiplyNTT which seems incompatible with the one in ml-kem that defines its own MultiplyNTTs (Algorithm 11) which is used here instead.

It perhaps suggests that code should be factored into ml-dsa.

It seems `module-lattice` has a `Mul` impl for `NttPolynomial` that
implements ML-DSA's `MultiplyNTT` which seems incompatible with the one
in `ml-kem` that defines its own `MultiplyNTTs` (Algorithm 11) which is
used here instead.

It perhaps suggests that code should be factored into `ml-dsa`.
@tarcieri tarcieri merged commit 0c3d436 into master Jan 29, 2026
28 checks passed
@tarcieri tarcieri deleted the ml-kem/use-ntt-polynomial-from-module-lattice branch January 29, 2026 04:15
tarcieri added a commit that referenced this pull request Jan 29, 2026
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 added a commit that referenced this pull request Jan 29, 2026
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 added a commit that referenced this pull request Jan 29, 2026
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 added a commit that referenced this pull request Jan 29, 2026
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 added a commit that referenced this pull request Jan 29, 2026
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 mentioned this pull request Apr 28, 2026
tarcieri added a commit that referenced this pull request Apr 28, 2026
## Added
- `Seed` support e.g. `DecapsulationKey::from_seed` (#133, #138)
- PKCS#8 support (#135)
- `KeyInit`, `KeySizeUser`, and `KeyExport` impls for decapsulation keys
  (#156, #228)
- Parameter set modules: `ml_kem_512`, `mk_kem_768`, `mk_kem_1024`
  (#162)
- `DecapsulationKey::from_expanded` deprecated compatibility support
  (#163)
- `TryKeyInit` and `KeyExport` impls for encapsulation keys (#188)
- Validations against Wycheproof test vectors (#213, #214, #215,
  #217)
- Implement `kem::Kem` trait (#223)
- Support for `kem::FromSeed` trait (#255)

## Changed
- Edition changed to 2024 and MSRV bumped to 1.85 (#118)
- Relax MSRV policy and allow MSRV bumps in patch releases
- Upgrade `hybrid-array` dependency to 0.4 (#129)
- Extract `module-lattice` crate (#199, #202, #204, #209,
  #210, #211, #212, #218, #219, #220)
- Replace `EncodedSizeUser` with `ExpandedKeyEncoding` (#226)
- Bump `getrandom` to v0.4 (#245)
- Bump `rand_core` to v0.10 (#245)
- Migrate from `subtle` to `ctutils` (#277)
- Bump `sha3` dependency to v0.11 (#282)
- Bump `kem` dependency to v0.3 (#283)
- Bump `pkcs8` dependency to v0.11 (#291)

## Fixed
- Validate encryption/encapsulation keys (#179)
- Validate expanded decapsulation key hash (#207)

## Removed
- `Kem` struct and `KemCore` trait - replaced by `kem::Kem` (#223)
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.

1 participant