Toom-Cook Multiplication
1. Generalizing Karatsuba: Toom-n
The Toom–Cook algorithm generalizes Karatsuba (which is Toom-2, where n=2). For an input polynomial of degree k−1, Toom-n splits it into n sub-polynomials and reduces the number of necessary recursive multiplications from n2 to 2n−1.
Complexity Comparison
For multiplying two polynomials of size k (degree k−1), the time complexity is determined by the split count n:
Karatsuba (Toom-2)
n=2
3
log23≈1.585
O(k1.585)
Toom-3
n=3
5
log35≈1.465
O(k1.465)
Toom-4
n=4
7
log47≈1.404
O(k1.404)
2. Toom–Cook Process in FPk (Toom-3 Example)
Let A(x) and B(x) be elements in FPk, represented as polynomials of degree approximately k−1. We aim to compute the polynomial product C′(x)=A(x)⋅B(x) efficiently.
Step 1: Splitting (Divide)
Divide A(x) and B(x) into n=3 sub-polynomials (A2,A1,A0 and B2,B1,B0) of degree less than m≈k/3:
Step 2: Evaluation
The resulting product C′(x) has a maximum degree of 4m, meaning it has 2n−1=5 unknown coefficients(from C0 to C4)that must be solved for. Therefore, we need to evaluate A(x) and B(x) at 5 distinct, carefully chosen evaluation points ei∈FP (or a small extension of FP).
Commonly chosen evaluation points are {0,1,−1,2,∞} for n=3 (Similarly, for n=4, we'll evaluate on {0,1,−1,2,−2,3,∞}).
Compute vi and wi:
vi=A(ei)andwi=B(ei)for i=0,…,4Evaluation at infinity:
A(∞)=An−1(x),B(∞)=Bn−1(x)
Step 3: Pointwise Multiplication
Perform the 2n−1=5 recursive multiplications (U0,…,U4) on the evaluated results. This is where the bulk of the computational cost lies:
Each Ui is a product of polynomials (or numbers) of size m, and these recursive calls continue until the polynomials are small enough to be handled by a classical or base-case multiplication algorithm.
Step 4: Interpolation (Solve)
Use the 2n−1=5 calculated products Ui to find the 2n−1 coefficient blocks (C0,…,C4) of the unreduced result C′(x).
The relationship between the evaluated values Ui=C′(ei) and the unknown coefficients Cj is a Vandermonde system of linear equations:
By pre-calculating the inverse of the Vandermonde matrix, the interpolation is performed quickly using only linear combinations (additions and scalar multiplications) of the Ui values over FP.
This above explains well why Karatuba is a specialized version of Toom-2.
Step 5: Recomposition and Final Reduction
Recomposition: Combine the resulting coefficient blocks Cj using shifts:
C′(x)=C4(x)x4m+C3(x)x3m+C2(x)x2m+C1(x)xm+C0(x)Reduction: Apply the final modulo reduction to get the element in FPk:
C(x)=C′(x)(modf(x))
3. Practical Considerations for FPk
In specialized hardware and software for finite field cryptography (like pairing-based cryptography which uses very large k), Toom–Cook is highly favored over Karatsuba because of its lower exponent.
Choice of n: The optimal choice for the splitting factor n depends on the size of the extension degree k and the hardware architecture. Higher n reduces the asymptotic complexity but increases the overhead of the Evaluation and Interpolation steps. Typically, n=3 or n=4 provides the best real-world performance gain before the overhead becomes prohibitive.
Base Field Operations: All additions, subtractions, and scalar multiplications are performed within the base field FP, which must itself be computed efficiently (often using Karatsuba or classical methods for the underlying integer arithmetic).
Written by Ryan Kim of Fractalyze
Last updated