lp: 4078 title: Six-Step NTT for Extended N description: Bailey's six-step factorization lifts the NTT past the N = 2^16 memory-bandwidth ceiling by running two passes of sqrt(N)-size sub-transforms that fit in L1 cache, with a single global transpose between them author: Lux Core Team (@luxfi) discussions-to: https://github.com/luxfi/lps/discussions status: Draft implementation-rust: none implementation-cpp: shipped implementation-go: none type: Standards Track category: Core tags: [ntt, lattice, arithmetic, six-step, ml-dsa, tfhe]
- lp-4076
- lp-4074
- lp-4040
Abstract
Above N = 2^16 the radix-2 Cooley-Tukey NTT (LP-4076) stops being
compute-bound and becomes memory-bandwidth-bound on every backend: the
working set no longer fits in cache and each butterfly layer streams the
whole array from main memory.
Bailey's six-step formulation fixes this by changing the shape rather
than the arithmetic. Factor N = N₁ · N₂ and run two passes of
√N-sized sub-transforms with a transpose between them. Each
sub-transform then fits in L1 — 8 KB or less for
N₁ = N₂ = 2^10 — and exactly one global-memory transpose is required
for the whole thing.
Required for ML-DSA-87 polynomial cores at N = 2^17 and TFHE bootstrap
LWE re-keying at N = 2^20.
Specification
Algorithm
Factor N = N₁ · N₂, typically N₁ = N₂ = √N:
six_step_ntt(a, N, omega):
# 1. Reshape a as N_1 x N_2 row-major matrix
A[i, j] = a[i * N_2 + j]
# 2. Column NTTs (size N_1, parallel over N_2 columns)
for j in 0..N_2-1:
A[:, j] = ntt(A[:, j], N_1, omega^N_2)
# 3. Twiddle multiplication
for i, j:
A[i, j] *= omega^(i * j)
# 4. Transpose -> N_2 x N_1
A = A.T
# 5. Row NTTs (now columns after transpose, size N_2)
for j in 0..N_1-1:
A[:, j] = ntt(A[:, j], N_2, omega^N_1)
# 6. Output left in transposed layout for downstream consumers
return A.flatten()
The inverse uses omega^{-1} and a final · N^{-1} scale.
Two flavors:
- Prime modulus (ML-DSA
q = 8,380,417; ML-KEMq = 3329): 64-bit operands,__uint128_tintermediate, Barrett reduction at the bottleneck. The caller supplies a primitive2N-th root of unity inF_q. - Power-of-two modulus (TFHE
q = 2^64): plain 64-bit machine arithmetic, no reduction at all. The twiddle table is precomputed inZ_{2^64}[X] / (X^N + 1).
Output layout
Step 4 is the only memory-bandwidth hit; steps 1, 2 and 5 are stream-coalesced. The output is left transposed by design and downstream consumers — pointwise multiply, inverse transform — read the transposed form directly. Byte-equality across backends is asserted on the post-step-6 transposed buffer.
Known-answer tests
- ML-DSA-87
N = 2^17poly-mul vectors from PQCleanpqcrystals-dilithium5/poly. - TFHE
N = 2^20LWE re-key vectors from lattigoring.NTT. crypto/ntt/test/six_step_kat.json.
Performance
N | (N₁, N₂) | Modulus | Backend | Measurement |
|---|---|---|---|---|
| 2^16 | (2^8, 2^8) | TFHE 2^64 | Metal | 16.92× over the Go reference |
| 2^20 | (2^10, 2^10) | TFHE 2^64 | CPU | 6–9 Mops/s, Apple M2 Ultra, single thread |
| 2^17 | (2^9, 2^8) | ML-DSA q | CPU | from ntt/test/six_step_test |
Where no GPU device is present, the dispatcher routes the kernel byte-equal to the CPU canonical, which asserts the determinism contract even on a host that cannot run the kernel. Real-device CUDA and WGSL throughput at the larger sizes is recorded when it is measured, not projected.
N = 2^20 is the current ceiling. Below N = 2^14 the radix-2 path
stays canonical.
Implementation
CPU canonical
luxcpp/crypto/ntt/cpp/ntt_large.{hpp,cpp}— prime-modulus branch, power-of-two-modulus branch, and per-Ntwiddle precompute.luxcpp/crypto/poly_mul/cpp/poly_mul.cppdispatches throughntt_largewhenN > 2^16.- Go canonical:
NTTLarge(coeffs, N1, N2).
GPU kernels
six_step_ntt.{metal,cu,wgsl} plus host drivers, adding the
twiddle-merged six-step variant for prime modulus and the TFHE
q = 2^64 specialization on top of the existing four-step Metal kernel.
C-ABI
// Prime-modulus six-step NTT
int ntt_six_step_prime(uint8_t *coeffs, // N * 8 bytes (in/out)
uint32_t N, // = N_1 * N_2, power-of-2
uint64_t q, // prime, q = 1 (mod 2N)
uint64_t omega_2N, // primitive 2N-th root in F_q
uint8_t forward); // 1 = forward, 0 = inverse
// Power-of-two-modulus six-step NTT (TFHE)
int ntt_six_step_pow2(uint64_t *coeffs, // N words (in/out)
uint32_t N,
uint8_t forward);
Determinism harness
six_step_test.{cpp,mm,cu} — N ∈ {2^14 … 2^20}, 50 random
polynomials per N per modulus class, byte-equal across CPU, Metal,
CUDA and WGSL. Cross-oracles: lattigo ring.NTT and PQClean
pqcrystals-dilithium5/ntt, both test-only.
Security Considerations
- The NTT operates on public polynomial coefficients. In a lattice
scheme the ciphertext
c = (a, b)is public and the secretsis multiplied by the publica; the Barrett reduction inside the prime path is therefore not secret-dependent. - The TFHE
q = 2^64path is truncate-to-64-bit, with no constant-time consideration beyond the surrounding scheme's posture. - The transposed output layout is a correctness hazard, and the one worth flagging. A forward six-step transform paired with a canonical radix-2 inverse produces garbage, silently. Callers go all-six-step (forward + pointwise + inverse, where the layouts cancel) or all-radix-2. Never mixed.
Crossover
N | Path |
|---|---|
| ≤ 2^13 | schoolbook (small-N branch in poly_mul) |
| 2^14 – 2^16 | radix-2 Cooley-Tukey (LP-4076) |
| 2^17 – 2^20 | six-step |
| > 2^20 | nine-step (3-D factorization) — not in this LP |
References
- Bailey, "FFTs in External or Hierarchical Memory" (1990) — the six-step formulation
- Longa, Naehrig, "Speeding up the Number-Theoretic Transform for Faster Ideal Lattice-Based Cryptography" (2016)
- FIPS 204 §7 — ML-DSA NTT,
q = 8,380,417 - TFHE-rs (Zama) —
q = 2^64ring arithmetic
Copyright
Copyright (C) 2024-2026, Lux Industries Inc. All rights reserved.
Licensed under the MIT License.