PQC · Lecture 2 · Florida Atlantic University · Fall 2026
Lecture 2: The Number Theoretic Transform (NTT)
Multiplying two polynomials of 256 coefficients takes 65,536 products the schoolbook way. The NTT needs 3,584: evaluate at roots of unity, multiply point by point, and convert back. Every step runs on the same toy ring as the slides: q = 17, n = 4, ζ = 2.
3,584multiplications per product at n = 256, instead of 65,536
8 / 7NTT stages in ML-DSA / ML-KEM
ζ = 2root of unity of the toy ring mod 17
1753 / 17roots of unity of ML-DSA / ML-KEM
One polynomial product costs multiplications. Can we do better?
The cost problem
Where we stopped
- Our running example in :
- Schoolbook: multiply every pair, collect, fold back with , reduce mod 17.
- The cost is multiplications:
| 4 | 16 | 256 | 1024 | |
|---|---|---|---|---|
| 16 | 256 | 65,536 | 1,048,576 |
You have seen this kind of trick before
| Task | Slow way | Fast way | Lecture |
|---|---|---|---|
| multiply big integers | schoolbook, | Karatsuba, | FF multiplication |
| reduce mod | long division | Barrett, Montgomery | FF reduction |
| multiply in | schoolbook, | NTT, | today |
- Each time, a change of representation makes the expensive step cheap.
- NTT stands for Number Theoretic Transform. It is the FFT, done with integers mod instead of complex numbers.
Evaluate, multiply, go back
A polynomial is also its values
- Two points fix a line. Three points fix a parabola.
- In general, a polynomial with coefficients is fixed by its values at different points.
- So we can store in two ways:
Coefficients
meaning
Values at 4 points
, ,, (mod 17)
- Check one: .
Multiplying values is cheap
- If , then at any point : .
- One multiplication per point, so multiplications in total.
- What remains is to make the two conversions cheap: the NTT and its inverse.
The wrap-around needs special points
- The product in is folded with . A random point does not know about the fold.
- Unless the point itself satisfies . Then, at that point: exactly the fold rule from Lecture 1.
Choose the points well
Use the roots of , the numbers with .Then holds for the folded product too.
- For , we need four numbers with . Do they exist?
Powers of 2 mod 17
- and , so the powers of go around a circle of 8.
- is a primitive -th root of unity: and .
- Check one point: .
The idea, checked on numbers
- Evaluate and at the four points, multiply, and compare with :
| point | mod 17 | ||||
|---|---|---|---|---|---|
| 2 | 15 | 7 | 105 | 3 | 3 |
| 8 | 13 | 7 | 91 | 6 | 6 |
| 15 | 11 | 8 | 88 | 3 | 3 |
| 9 | 16 | 15 | 240 | 2 | 2 |
- Every row matches. Four multiplications gave the values of the product.
- The values fix . Getting the coefficients back from them is the inverse NTT.
Try it
Which points work?
Pick any point r mod 17. The product c = a·b is the folded one from Lecture 1. Its values match a(r)·b(r) only at the roots of x4 + 1.
Definition of the NTT
Number Theoretic Transform
is the list of values of at the odd powers of :
- Toy: , in some order.
- Done directly, each value costs multiplications, and there are values: again.
So far
The idea is right, but direct evaluation saves nothing. We need a fast way to compute all values.
A fast NTT
Split the problem in half
- Since :
- The four points split into two pairs:
- and are the roots of (, )
- and are the roots of (, )
- Plan: first reduce mod and mod . Each half has only 2 coefficients and is responsible for 2 of the points.
Reducing mod is one line
- Write and replace by or by :
mod
mod
Our with
mod : mod :
- Both results reuse the same products and : two multiplications for the whole step.
The butterfly
- The pattern " and " is called a Cooley-Tukey butterfly. is the twiddle factor.
- One multiplication, one addition, one subtraction, all mod .
Split again until single numbers remain
- and . Reducing mod gives , the value at .
The same steps on an array
- In code, is one array that is updated in place, one stage at a time. Same colour, same butterfly.
Stage 1,
pairs and Stage 2, and
: :
- 4 multiplications in total, against 16 for direct evaluation.
Try it
Butterfly stepper
Step through the NTT one butterfly at a time, for the toy ring or for n = 8 with ζ = 3. Switch to the inverse to undo it. You can type your own input.
Your turn:
- Compute for with the same stages: , then and .
Stage 1,
array:
Stage 2
, : , :
Bigger , deeper tree
- : three levels of splits. Each level is one stage of 4 butterflies; the chips are the twiddles.
- Every stage touches every coefficient once: butterflies per stage.
Counting the work
Cost of a fast NTT
stages butterflies 1 multiplication
| stages | fast NTT | direct evaluation | |
|---|---|---|---|
| 4 | 2 | 4 | 16 |
| 8 | 3 | 12 | 64 |
| 256 | 8 | 1,024 | 65,536 |
- Each split halves the problem, and 256 halves down to 1 in only 8 steps.
Why the output order looks shuffled
- The fast NTT returned , which is .
- Output is the value at , where reverses the bits of :
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |
| in binary | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111 |
| reversed | 000 | 100 | 010 | 110 | 001 | 101 | 011 | 111 |
| 0 | 4 | 2 | 6 | 1 | 5 | 3 | 7 |
- The order does not matter. Pointwise multiplication treats every position alike, and the inverse NTT puts things back.
Twiddle factors are a fixed table
- The twiddles depend only on , and , so they are computed once and stored. Block uses .
| Ring | Twiddles used | First entries |
|---|---|---|
| toy, , | 3 | (that is ) |
| ML-DSA, | 255 | |
| ML-KEM, | 127 |
- Software keeps them in a constant array, hardware in a small ROM next to the multiplier.
The whole forward NTT in code
def ntt(a, q, zetas):
n = len(a)
k = 1
length = n // 2
while length >= 1:
for start in range(0, n, 2*length):
w = zetas[k]
k += 1
for j in range(start, start+length):
t = w * a[j+length]
a[j+length] = (a[j] - t)
a[j] = (a[j] + t)
length //= 2
return a
length: distance between the two inputs of a butterfly. , then , down to 1.start: one block per twiddle.- Inner loop: the butterfly.
- Same shape as Algorithm 41 in FIPS 204. You write it in Assignment 7.
Going back: the inverse NTT
Undoing one butterfly
- The forward butterfly gave and . Add and subtract:
- So and .
- This is the Gentleman-Sande butterfly. The halves pile up, one per stage, so we divide by once at the end.
The inverse NTT on numbers
- Inverse twiddles mod 17: , , . The stages run in reverse order.
Stage 1, and
: :
Stage 2,
: :
Scale by
, the schoolbook result
The full pipeline
Pointwise step
, ,
Cost for one product
2 forward NTTs, pointwise products,1 inverse NTT, scalings
Is it really faster?
- Count every multiplication: , against for schoolbook.
| schoolbook | NTT way | ||
|---|---|---|---|
| 4 | 16 | 20 | NTT is slower |
| 16 | 256 | 128 | 2 faster |
| 64 | 4,096 | 704 | 6 faster |
| 256 | 65,536 | 3,584 | 18 faster |
| 1024 | 1,048,576 | 17,408 | 60 faster |
- Our toy is too small to profit. The win grows with , and is in the profitable range.
Try it
Schoolbook against the NTT
Slide n from 4 to 4096. The NTT count is 3·(n/2)·log2n + 2n.
The NTT in ML-DSA and ML-KEM
When does a good exist?
Rule
A primitive -th root of unity mod a prime exists exactly when divides .
| Ring | of order ? | ||
|---|---|---|---|
| toy | 8 | yes, | |
| ML-DSA | 512 | yes, | |
| ML-KEM | 512 | no: only order 256, |
- ML-KEM picked a small to keep keys short, and pays for it with a slightly different NTT.
ML-DSA: the full NTT
- , , , with .
- 8 stages of 128 butterflies, all the way down to single numbers.
- Pointwise product: 256 multiplications, .
| Step | Multiplications |
|---|---|
| 2 forward NTTs | |
| pointwise | 256 |
| inverse NTT and scaling | |
| total | 3,584 (schoolbook: 65,536) |
ML-KEM: stop one stage early
- Without a 512th root, the last split cannot happen. ML-KEM runs 7 stages and stops at pieces of degree 1.
- Toy version: stop after stage 1.
- ML-KEM ends with 128 pieces , each reduced mod .
Multiplying two degree-1 pieces
BaseCaseMultiply (mod )
Toy, after stage 1: ,
: :
- One inverse stage on gives . Times : again.
- Cost per piece: 5 multiplications.
ML-KEM in numbers
- , a second fixed table:
| Step | Multiplications |
|---|---|
| 2 forward NTTs, 7 stages each | |
| 128 base-case products | |
| inverse NTT and scaling | |
| total | 3,584 (schoolbook: 65,536) |
- Same total as ML-DSA by coincidence: one stage less, but a more expensive pointwise step.
Stay in the NTT domain
- The schemes avoid converting back and forth:
- The matrix is random anyway, so it is generated directly as NTT values.
- The secret is transformed once and reused in all rows.
- Only the final results go through the inverse NTT.
ML-KEM-768: computing
schoolbook: multiplicationsNTT way: NTTs of base cases inverse NTTs , about 50 times fewer
Summary
Summary
The NTT in five lines
- Store a polynomial by its values at the roots of (the odd powers of ).
- In that form, multiplication in is pointwise: multiplications.
- The fast NTT splits in half times, with butterflies per split.
- The inverse NTT undoes the splits with Gentleman-Sande butterflies and a final .
- ML-DSA uses the full NTT. ML-KEM stops one stage early and multiplies degree-1 pieces.
Assignment 7
Build all of this in Python: schoolbook, slow NTT, butterflies, fast NTT and inverse, then ML-DSA size.
Now we can afford the arithmetic. Next: ML-KEM and ML-DSA.