Convolution is a mathematical operation that blends two functions (or signals) to produce a third function, which shows how one function modifies or overlaps with the other.
A convolution is linear if it satisfies the properties of additivity and homogeneity. This means that the convolution of a linear combination of sequences is the same as the corresponding linear combination of their convolutions. For example, (A+B)∘C=A∘C+B∘C
So discrete linear convolution is when it is working on sequences of integers rather than on continuous functions.
Polynomial Multiplication
Definition 1: Suppose that G(x) and H(x) are polynomials of degree n−1 in the ring Zq[x] where q∈Z and x is the polynomial variable, a polynomial multiplication of G(x) and H(x) is defined as:
Y(x)=G(x)⋅H(x)=k=0∑2(n−1)ykxk(1)
where yk=∑i=0kgihk−imodq, g and h are the polynomial coefficients of G(x) and H(x) respectively.
Polynomial multiplication is equivalent to a discrete linear convolution between the coefficients' vectors g=(g0,…,gn) and h=(h0,…,hn).
Cyclic Convolution
Definition 2: Suppose that G(x) and H(x) are polynomials of degree n−1 in the quotient ring Zq[x]/(xn−1) where q∈Z. A cyclic convolution or positive wrapped convolution (PWC) is defined as:
Negacyclic convolution
Note that the only difference between cyclic and negacyclic convolution is the divisor.
Number Theoretic Transform
Many researchers do not differentiate the term NTT and FFT-based algorithms to calculate NTT, which creates confusion when understanding the topic. This report refers to the transformation itself as NTT and the FFT-like algorithms as fast-NTT
and
To reduce the complexity and fasten the process of the matrix multiplication needed for the NTT transformation, one can use ‘‘divide and conquer’’ techniques by utilizing the periodicity and symmetry property of:
Cooley-Tukey (CT) Algorithm for Fast NTT
PWC case
The idea is to calculate similar terms in the brackets once and then distribute the results instead of calculating them multiple times.
NWC case
Gentleman-Sande (GS) Algorithm for Fast INTT
PWC case
If we consider the odd and even term separately, we get:
NWC case
If we consider the odd and even term, we get:
References:
PWC(x)=k=0∑n−1ckxk(2)
where ck=∑i=0kgihk−i+∑i=k+1n−1gihk+n−imodq. If Y(x) from equation (1) is the result of their linear convolution in the ring Zq[x], it can also be defined as:
PWC(x)=Y(x)mod(xn−1)(3)
Naive method to calculate the PWC is through a polynomial multiplication followed by a long division. This method has O(n2) complexity.
The term "cyclic" stems from the fact that xncycles back to1 in this quotient ring. For example, F(x)=xn will map to F(x)=1 in this quotient ring.
Definition 3: Suppose that G(x) and H(x) are polynomials of degree n−1 in the quotient ring Z[x]/(xn+1) where q∈Z. A negacyclic convolution or negative wrapped convolution, NWC(x) is defined as:
NWC(x)=k=0∑n−1ckxk(4)
where ck=∑i=0kgihk−i−∑i=k+in−1gihk+n−imodq. If Y(x) from equation (1) is the result of their linear convolution in the ring Z[x], it also can be defined as:
NWC(x)=Y(x)mod(xn+1)(5)
The term "negacyclic" stems from the fact that xncycles back to−1 in this quotient ring. For example, F(x)=xn will map to F(x)=−1 in this quotient ring.
The classical NTT has quadratic complexity of O(n2) while fast-NTT algorithms have a more efficient quasi-linear complexity O(nlogn).
Remember that for NTT, we are particularly interested in the evaluations at the roots of the quotient polynomial. (A⋅B=C+QuotientPoly⋅c and we want the QuotientPoly to vanish).
Definition 4: Let Zq be an integer ring modulo q, and n−1 is the polynomial degree of G(x) and H(x). Such rings have a multiplicative identity (unity) of 1. Define ω as primitive n-th root of unity in Zq if and only if:
ωn≡1modq(6)
ωk≡1modq(7)
for all k=1,…,n−1.
One thing to note is that the primitive n-th root of unity in a ring Zq might not be unique. For example, in a ring Z7, primitive 3rd root of unity can be 2 and 4. The choice of value of ω will be important in calculating NWC and PWC.
Definition 5: The Number Theoretic Transform (NTT) of a vector of polynomial coefficients a is defined as a^=NTT(a), where:
a^j=i=0∑n−1ωijaimodq(8)
and j=0,1,…,n−1. Here, a^ denotes the evaluations of the polynomial defined by a over {ω0,ω1,…,ωn−1} which are the roots of (xn−1).
Definition 6: The Inverse of Number Theoretic Transform (INTT) of an NTT vector a^ is defined as a=INTT(a^), where:
ai=n−1j=0∑n−1w−ija^jmodq(9)
and j=0,1,…,n−1.
Note that the INTT has a very similar formula to NTT. The only differences are ω replaced by its inverse in Zq and a n−1 scaling factor. It always holds that a=INTT(NTT(a)).
In the ZK scene, it is common to work on a polynomial with some max degree n−1. This just means that we are working on polynomials from the quotient ring Zq[x]/(xn−1). In such rings, we must utilize positive-wrapped convolution.
In the context of PQC and HE, the chosen ring is mostly Zq[x]/(xn+1) instead of Zq[x]/(xn−1). One must calculate the polynomial multiplications via the negative-wrapped convolution in such rings. To calculate negative-wrapped convolution, one needs the primitive 2n-th root of unity, ψ.
Definition 7: Let Zq be an integer ring modulo q, and n−1 is the polynomial degree of G(x) and H(x) and ω is its primitive n-th root of unity. Define ψ as the primitive 2n-th root of unity if and only if:
(ψ2≡ωmodq)∧(ψn≡−1modq)(10)
Example. In a ring Z7681 and n=4, when ω=3383, the value of ψ can be 1925 or 5756 as 19252≡57562≡3383mod7681 and 19254≡57564≡7680≡−1mod7681. Therefore, one can choose the value of ψ=1925 or ψ=5756.
Definition 8: The Negative-Wrapped Number Theoretic Transform (NTTψ) of a vector of polynomial coefficients a is defined as a^=NTTψ(a), where:
a^j=i=0∑n−1ψ2ij+iaimodq(11)
and j=0,1,…,n−1. Here, a^ denotes the evaluations of the polynomial defined by a over {ψ1,ψ3,…,ψ2n−1} which are the roots of (xn+1).
Definition 9: The Negative-Wrapped Inverse of Number Theoretic Transform (INTT) of an NTT vector a^ is defined as a=INTTψ−1(a^), where:
ai=n−1j=0∑n−1ψ−iω−ija^jmodq(12)
and i=0,1,…,n−1. Substituting ω=ψ2 yields:
ai=n−1j=0∑n−1ψ−(2ij+i)a^jmodq(17)
periodicity:symmetry:ψk+2nψk+n==ψk−ψk(18)
From equation (8) for NTT, one can separate the summation into two parts, based on odd and even indices:
If we denote, Aj=∑i=0n/2−1ω2ija2i and Bj=∑i=0n/2−1ω2ija2i+1, the equation(19) and (20) becomes:
a^ja^j+n/2=Aj+ωjBjmodq=Aj−ωjBjmodq(21)
With this finding, we can calculate Aj and Bj for j=0,…,2n and calculate a^ by reusing them for the upper half. Notice that Aj and Bj can be calculated using 2n point NTT so if we repeat recursively, we can achieve the best case scenario O(nlogn) which occurs when n is a power of 2.
Example. Let's consider the case when a=(1,2,3,4).
With this finding, we can calculate Aj and Bj for j=0,…,2n and calculate a^ by reusing them for the upper half. Notice that Aj and Bj can be calculated using 2n point NTT so if we repeat recursively, we can achieve the best case scenario O(nlogn) which occurs when n is a power of 2.
Figure 1 illustrates how this butterfly operation is denoted as a graph. This figure represents the computation of A+ψkB and A−ψkB.
For the INTT, instead of dividing the summation by even and odd indices, it is separated by the lower and upper half of the summation. From equation (10) for INTT and ignoring n−1 term:
Let Ai=∑j=02n−1(a^j+a^j+2n)ω−2ij and Bi=∑j=02n−1((a^j−a^j+2n)ω−j)ω−2ij, equation (26) and (27) become:
a2ia2i+1=Ai=Bimodqmodq(27)
With this finding, we just need to calculate Ai and Bi for 0≤i≤2n−1. Notice that Ai and Bi can be calculated using 2n point INTT so if we repeat recursively, we can achieve the best case scenario O(nlogn) which occurs when n is a power of 2.
Similarly, continuing from equation (17) for INTTψ, ignoring n−1 term, we got:
Let Ai=∑j=02n−1ψ−(4ij+2i)(a^j+a^j+2n) and Bi=∑j=02n−1ψ−(4ij+2i)((a^j−a^j+2n)ψ−2j), then equation (29) and (30) becomes:
a2ia2i+1=Ai=ψ−1Bimodqmodq(31)
With this finding, we just need to calculate Ai and Bi for 0≤i≤2n−1. Notice that Ai and Bi can be calculated using 2n point INTT so if we repeat recursively, we can achieve the best case scenario O(nlogn) which occurs when n is a power of 2.
Figure 2 illustrates how this butterfly operation is denoted as a graph. This figure represents the computation of (A+B) and (A−B)ψk.