# 数论变换

数论变换（NTT）是在有限环或有限域上计算的离散傅里叶变换（DFT），而非在复数域上计算。它被用于整数序列的精确快速卷积、多项式乘法以及格密码学中的算术运算。普通的DFT是通过复数单位根进行乘法运算，这会引入截断误差或舍入误差，而数论变换则是在素数模下通过整数单位根进行乘法运算，因此所有运算都是精确的。${}^1{}^2$ 它是一种有限域上的DFT的特例，大多数快速傅里叶变换（FFT）技术都可以直接应用于它。${}^3$<sup>[1](https://ccrma.stanford.edu/~jos/dft/Number_Theoretic_Transform.html)</sup><sup> • </sup><sup>[2](https://par.nsf.gov/servlets/purl/10501324)</sup><sup> • </sup><sup>[3](https://arxiv.org/pdf/2211.13546)</sup>

| 关键事实 | 细节 |
| :--- | :--- |
| 计算内容 | 在有限域 $\mathbb{F}_{p}$ 上计算的DFT求和 $b_{j} = \sum_{i=0}^{L-1} \omega^{ij} a_{i}$，其中 $\omega$ 是一个整数单位根。${}^4$<sup>[4](https://ar5iv.labs.arxiv.org/html/1205.2926)</sup> |
| 精确性 | 所有算术都是模素数的整数加法和乘法；不存在舍入误差。${}^1$<sup>[1](https://ccrma.stanford.edu/~jos/dft/Number_Theoretic_Transform.html)</sup> |
| 长度限制 | 一个长度为 $n$ 的变换需要一个素数 $p = k \cdot n + 1$，即 $n \mid p-1$。${}^5$<sup>[5](https://www.apfloat.org/ntt.html)</sup> |
| 复杂度 | 时间复杂度为 $O(n \log n)$，空间复杂度为 $O(n)$，类似于FFT。${}^6$<sup>[6](https://www.takeuhigh.org/docs/math-course/chapter-11-polynomials/04-ntt-modular-convolution/)</sup> |
| 加密应用 | NTT及其逆运算是全同态加密中密钥切换的瓶颈；Harvey蝴蝶结构被用于HElib、SEAL和Intel HEXL。${}^7$<sup>[7](https://eprint.iacr.org/2021/1396.pdf)</sup> |
| 负循环条件 | 在模 $X^{n}+1$ 下进行乘法运算且不进行零填充，需要一个满足 $q \equiv 1 \pmod{2n}$ 的素数。${}^8$<sup>[8](https://eprint.iacr.org/2016/504.pdf)</sup> |

## 工作原理

数论变换将DFT的复数第 $n$ 次单位根替换为一个满足 $\omega^{n} = 1 \bmod p$ 的整数 $\omega$，其中 $p$ 是一个素数。${}^1$ 当 $n$ 整除 $p-1$ 时，这样的根是存在的：如果 $g$ 是模 $p$ 的原根，那么 $\omega = g^{(p-1)/n} \bmod p$ 就是一个本原 $n$ 次单位根。${}^6$ 等价地，可以选择一个形式为 $p = k \cdot n + 1$ 的素数，并为原根 $r$ 设置 $\omega = r^{k} \bmod p$。${}^5$<sup>[1](https://ccrma.stanford.edu/~jos/dft/Number_Theoretic_Transform.html)</sup><sup> • </sup><sup>[6](https://www.takeuhigh.org/docs/math-course/chapter-11-polynomials/04-ntt-modular-convolution/)</sup><sup> • </sup><sup>[5](https://www.apfloat.org/ntt.html)</sup>

序列 $a_{0}, \ldots, a_{n-1}$ 的变换为：

\[ b_{j} = \sum_{i=0}^{n-1} \omega^{ij} a_{i} \bmod p, \qquad 0 \le j < n, \]

这与DFT的求和形式相同，但所有算术都在 $\mathbb{F}_{p}$ 中进行。${}^4$ 由于系数环是一个包含正确单位根的域，该变换是可逆的，且卷积定理成立：将两个序列的变换相乘再反变换，可以精确地得到它们的循环卷积。${}^8$ 当 $n$ 是合数时，从该变换构建快速NTT的方式，与从DFT构建快速傅里叶变换（FFT）的方式完全相同。${}^1$ 与DFT不同的是，其结果没有有意义的频域解释；它的价值在于卷积定理和精确性。${}^1$<sup>[4](https://ar5iv.labs.arxiv.org/html/1205.2926)</sup><sup> • </sup><sup>[8](https://eprint.iacr.org/2016/504.pdf)</sup><sup> • </sup><sup>[1](https://ccrma.stanford.edu/~jos/dft/Number_Theoretic_Transform.html)</sup><sup> • </sup><sup>[1](https://ccrma.stanford.edu/~jos/dft/Number_Theoretic_Transform.html)</sup>

## 实现方式

多项式或整数乘法的软件NTT的实现步骤如下。

1. **选择模数和根。** 选择一个素数 $p = k \cdot n + 1$，并从原根 $g$ 计算 $\omega = g^{(p-1)/n} \bmod p$。${}^5{}^6$<sup>[5](https://www.apfloat.org/ntt.html)</sup><sup> • </sup><sup>[6](https://www.takeuhigh.org/docs/math-course/chapter-11-polynomials/04-ntt-modular-convolution/)</sup>
2. **正向变换。** 在 $\mathbb{F}_{p}$ 上运行一个迭代的基底-2 Cooley–Tukey 蝶形网络：先进行比特逆序置换，然后进行 $\log_{2} n$ 级带有模旋转因子的蝶形运算，实现 $O(n \log n)$ 的时间复杂度。${}^6{}^9$ Cooley–Tukey 步骤将多项式 $A(X) = A_{0}(X^{2}) + X \cdot A_{1}(X^{2})$ 分拆为偶数次项系数和奇数次项系数两半，逐级进行。${}^{10}$<sup>[6](https://www.takeuhigh.org/docs/math-course/chapter-11-polynomials/04-ntt-modular-convolution/)</sup><sup> • </sup><sup>[9](https://isa-afp.org/browser_info/current/AFP/Number_Theoretic_Transform/outline.pdf)</sup><sup> • </sup><sup>[10](https://fhetextbook.github.io/ForwardFFTorNTT.html)</sup>
3. **点乘。** 将两个变换后的向量按分量相乘，并对 $p$ 取模。
4. **逆变换。** 使用 Gentleman–Sande 蝶形（Cooley–Tukey 的转置）并乘以模逆元 $n^{-1} = n^{p-2} \bmod p$ 进行缩放。${}^6$<sup>[6](https://www.takeuhigh.org/docs/math-course/chapter-11-polynomials/04-ntt-modular-convolution/)</sup>

对于模 $X^{n}+1$ 的负循环乘法，输入会预先和后乘以 $\psi$ 的幂，其中 $\psi$ 是一个本原 $2n$ 次单位根且 $\psi^{2} = \omega$。这使得环绕的符号得以折叠进变换中，避免了零填充。${}^8$<sup>[8](https://eprint.iacr.org/2016/504.pdf)</sup>

## 起源

J. M. Pollard 的论文《有限域中的快速傅里叶变换》（Mathematics of Computation, 1971）定义了一种类似于有限域中DFT的变换，该变换可以通过FFT算法计算，用于长整数序列的精确卷积；当单位根的阶 $d$ 是高度合数时，它将操作计数从 $O(d^{2})$ 降低到 $O(d \log d)$。${}^{11}{}^{11}$ 这种方法是在有限域和具有模算术的整数环上开发的。${}^{12}{}^{13}$ Agarwal 和 Burrus 于1974年发表的伴随论文介绍了使用费马数变换进行数字滤波的卷积。${}^{14}$ 随后，一篇1976年的《电子学快报》论文提出了在处理器或专用硬件中将NTT实现到素数或素数幂模数上的设想。${}^{15}$ 其底层的FFT分解可以追溯到1965年的 Cooley–Tukey 算法。${}^{16}$ 这一想法被综述文献追溯到卡尔·弗里德里希·高斯（Carl Friedrich Gauss）在1805年的一项未发表的工作。${}^3$ Pollard 的1971年论文还给出了该变换在模素数幂 $m = p^{n}$ 的整数环中的版本，而这是一个非域。${}^{11}$<sup>[11](https://doi.org/10.1090/s0025-5718-1971-0301966-0)</sup><sup> • </sup><sup>[11](https://doi.org/10.1090/s0025-5718-1971-0301966-0)</sup><sup> • </sup><sup>[12](https://doi.org/10.1109/t-c.1972.223497)</sup><sup> • </sup><sup>[13](https://doi.org/10.1109/proc.1975.9791)</sup><sup> • </sup><sup>[14](https://doi.org/10.1109/tassp.1974.1162555)</sup><sup> • </sup><sup>[15](https://digital-library.theiet.org/doi/10.1049/el%3A19760289)</sup><sup> • </sup><sup>[16](https://doi.org/10.1090/s0025-5718-1965-0178586-1)</sup><sup> • </sup><sup>[3](https://arxiv.org/pdf/2211.13546)</sup><sup> • </sup><sup>[11](https://doi.org/10.1090/s0025-5718-1971-0301966-0)</sup>

## 变体

**费马数变换（Fermat number transform）。** 使用费马数模数的变换，只需要 $O(N \log N)$ 次加法和字移操作，无需乘法，且没有舍入误差，也无需存储基函数。${}^{13}$ R. C. Agarwal 和 C. S. Burrus 于1974年描述了这一数字滤波构造。${}^{14}$ V. S. Dimitrov, T. V. Cooklev 和 B. D. Donevsky 后来推广了费马-梅森构造（IEEE Transactions on Circuits and Systems II, 1994）。${}^{17}$<sup>[13](https://doi.org/10.1109/proc.1975.9791)</sup><sup> • </sup><sup>[14](https://doi.org/10.1109/tassp.1974.1162555)</sup><sup> • </sup><sup>[17](https://doi.org/10.1109/82.281844)</sup>

**梅森变换（Mersenne transform）。** C. M. Rader 的1972年论文在梅森模数上构建了离散卷积。${}^{12}$<sup>[12](https://doi.org/10.1109/t-c.1972.223497)</sup>

**负循环数论变换（Negacyclic NTT, NWC）。** 使用一个本原 $2n$ 次单位根 $\psi$ 来计算 $a \cdot b \bmod (X^{n}+1)$，而无需零填充，要求 $q \equiv 1 \pmod{2n}$。${}^8$ 通过 $\psi^{j}$ 的预乘和后乘，需要 $2n$ 次额外的模乘法；低复杂度的 NWC（LC-NWC）则将这些操作合并到蝶形运算中。${}^2$ 在NIST后量子签名方案中，Dilithium 和 Falcon 满足 NWC 条件，而 Kyber 的模数仅满足 $q \equiv 1 \pmod{n}$。${}^3$<sup>[8](https://eprint.iacr.org/2016/504.pdf)</sup><sup> • </sup><sup>[2](https://par.nsf.gov/servlets/purl/10501324)</sup><sup> • </sup><sup>[3](https://arxiv.org/pdf/2211.13546)</sup>

**多模数数论变换（Multi-modulus NTT）。** 对于不是NTT友好的模数，可以对形式为 $k \cdot n + 1$ 的多个素数运行变换（其乘积超过最大的可能系数），然后利用中国剩余定理重建结果。${}^5$<sup>[5](https://www.apfloat.org/ntt.html)</sup>

**DGT 和 NTTRU。** 离散伽罗瓦变换（Discrete Galois Transform, DGT）缩短了NTT的数据路径，使用一个 $n/2$ 点数据路径在高斯有限域 $\mathrm{GF}(q^{2})$ 上计算负循环卷积，其中 $q \equiv 3 \pmod{4}$；Al Badawi 及其同事将其推广到满足 $q \equiv 1 \pmod{4}$ 的素数。${}^{18}$ NTTRU 通过拆分 $x^{n} - \omega^{j}$ 类型的因子来处理维度为 $n = 768$ 的环（而非2的幂），相对于 NTRU-HRSS 提供了约一个数量级的改进。${}^{18}$<sup>[18](https://pdfs.semanticscholar.org/2461/162b96ba9b8919c3c1344aa43f4b4776ef95.pdf)</sup><sup> • </sup><sup>[18](https://pdfs.semanticscholar.org/2461/162b96ba9b8919c3c1344aa43f4b4776ef95.pdf)</sup>

## 应用

**快速乘法。** NTT使用整数算术精确计算长整数序列的卷积，将 $O(d^{2})$ 的工作量降低到 $O(d \log d)$。${}^{11}$<sup>[11](https://doi.org/10.1090/s0025-5718-1971-0301966-0)</sup>

**同态加密。** 在全同态加密（FHE）中，NTT将多项式模乘法从 $O(N^{2})$ 降低到 $O(N \log N)$，而NTT及其逆是密钥切换的瓶颈。${}^{19}{}^{7}$ 各种库实现了基底-2 Cooley–Tukey 和 Gentleman–Sande 网络配合 Harvey 蝴蝶结构；采用此设计的 Intel HEXL 已被 Microsoft SEAL 和 PALISADE 采用。${}^{19}{}^{7}$<sup>[19](https://arxiv.org/abs/2103.16400.pdf)</sup><sup> • </sup><sup>[7](https://eprint.iacr.org/2021/1396.pdf)</sup><sup> • </sup><sup>[19](https://arxiv.org/abs/2103.16400.pdf)</sup><sup> • </sup><sup>[7](https://eprint.iacr.org/2021/1396.pdf)</sup>

**后量子密码学和大规模计算。** Kyber、Dilithium、Falcon 和 NTRU Prime 等格方案依赖于基于NTT的环乘法，即使在嵌入式 Cortex-M4 硬件上也是如此。${}^3{}^{20}$ 模算术的精确性也常被用来将极其巨大的数相乘，例如计算到数百万位 $\pi$ 的值。${}^1$<sup>[3](https://arxiv.org/pdf/2211.13546)</sup><sup> • </sup><sup>[20](https://homepage.iis.sinica.edu.tw/papers/byyang/23610-F.pdf)</sup><sup> • </sup><sup>[1](https://ccrma.stanford.edu/~jos/dft/Number_Theoretic_Transform.html)</sup>

## 局限性与替代方案

**长度和字宽限制。** 一个长度为 $n$ 的变换要求 $n \mid p-1$。${}^5$ 对于32位整数，实际最大长度为 $2^{27}$，因为当 $n = 2^{27}$ 时，小于 $2^{32}$ 且满足 $p = k \cdot n + 1$ 的素数只有三个（当 $n = 2^{28}$ 时只有两个）。${}^5$ 字宽也限制了系数的增长：Agarwal 和 Burrus 指出，序列长度受字宽和溢出问题限制，但他们也提出了克服这些问题的方案。${}^{13}$<sup>[5](https://www.apfloat.org/ntt.html)</sup><sup> • </sup><sup>[5](https://www.apfloat.org/ntt.html)</sup><sup> • </sup><sup>[13](https://doi.org/10.1109/proc.1975.9791)</sup>

**对比浮点数FFT。** 浮点数FFT引入的截断和舍入误差是NTT完全避免的。${}^2$ 这种差异是实际的：Bailey报告说，在Cray超级计算机上，FFT代码在计算 $\pi$ 的大约1000万位时因舍入误差而失败，而NTT则没有舍入误差，代价是速度较慢，但所需存储空间较少。${}^5$<sup>[2](https://par.nsf.gov/servlets/purl/10501324)</sup><sup> • </sup><sup>[5](https://www.apfloat.org/ntt.html)</sup>

**实现性能。** Harvey 将 $\mathbb{F}_{p}$ 元素冗余表示为 $[0, 2p)$ 的方法，消除了蝶形运算中的模约减，在长度为2048的变换中，其速度约为 Shoup 的 NTL 实现的1.5倍（在Intel处理器上）和1.15倍（在AMD处理器上）。${}^4$<sup>[4](https://ar5iv.labs.arxiv.org/html/1205.2926)</sup>

## References

1. [Number Theoretic Transform (Julius O. Smith, Mathematics of the DFT, W3K Publishing, 2007)](https://ccrma.stanford.edu/~jos/dft/Number_Theoretic_Transform.html)
2. [Long Polynomial Modular Multiplication using the Number Theoretic Transform (tutorial)](https://par.nsf.gov/servlets/purl/10501324)
3. [A survey for NTT in lattice-based cryptography (arXiv 2211.13546)](https://arxiv.org/pdf/2211.13546)
4. [Faster arithmetic for number-theoretic transforms (Harvey, arXiv 1205.2926)](https://ar5iv.labs.arxiv.org/html/1205.2926)
5. [Number theoretic transforms (apfloat documentation)](https://www.apfloat.org/ntt.html)
6. [NTT and Modular Convolution](https://www.takeuhigh.org/docs/math-course/chapter-11-polynomials/04-ntt-modular-convolution/)
7. [NTT software optimization using an extended Harvey butterfly](https://eprint.iacr.org/2021/1396.pdf)
8. [Speeding up the Number Theoretic Transform for Faster Ideal Lattice-Based Cryptography (Longa & Naehrig)](https://eprint.iacr.org/2016/504.pdf)
9. [Number Theoretic Transform, Isabelle Archive of Formal Proofs](https://isa-afp.org/browser_info/current/AFP/Number_Theoretic_Transform/outline.pdf)
10. [Forward FFT (or NTT), FHE textbook appendix](https://fhetextbook.github.io/ForwardFFTorNTT.html)
11. [The fast Fourier transform in a finite field (Mathematics of Computation, 1971)](https://doi.org/10.1090/s0025-5718-1971-0301966-0)
12. [C.M. Rader (1972). Discrete Convolutions via Mersenne Transforms. IEEE Transactions on Computers.](https://doi.org/10.1109/t-c.1972.223497)
13. [R.C. Agarwal, C.S. Burrus (1975). Number theoretic transforms to implement fast digital convolution. Proceedings of the IEEE.](https://doi.org/10.1109/proc.1975.9791)
14. [R. Agarwal, C. Burrus (1974). Fast Convolution using fermat number transforms with applications to digital filtering. IEEE Transactions on Acoustics Speech and Signal Processing.](https://doi.org/10.1109/tassp.1974.1162555)
15. [Implementation of number-theoretic transforms (Electronics Letters, 1976)](https://digital-library.theiet.org/doi/10.1049/el%3A19760289)
16. [James W. Cooley, John W. Tukey (1965). An algorithm for the machine calculation of complex Fourier series. Mathematics of Computation.](https://doi.org/10.1090/s0025-5718-1965-0178586-1)
17. [V.S. Dimitrov, T.V. Cooklev, B.D. Donevsky (1994). Generalized Fermat-Mersenne number theoretic transform. IEEE Transactions on Circuits and Systems II Analog and Digital Signal Processing.](https://doi.org/10.1109/82.281844)
18. [A Generalized Number-Theoretic Transform for Efficient Multiplication in Lattice Cryptography (Al Badawi et al.)](https://pdfs.semanticscholar.org/2461/162b96ba9b8919c3c1344aa43f4b4776ef95.pdf)
19. [Intel HEXL: Accelerating Homomorphic Encryption with Intel AVX512-IFMA52](https://arxiv.org/abs/2103.16400.pdf)
20. [Polynomial Multiplication in NTRU Prime](https://homepage.iis.sinica.edu.tw/papers/byyang/23610-F.pdf)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Number theory › Computational and probabilistic number theory

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/number-theoretic-transform

English original: https://www.edgepedia.org/number-theoretic-transform
