Reduced and Refined Karatsuba - Simple Micro-optimization of Karatsuba Multiplication
Introduction
Karatsuba multiplication is a famous algorithm for efficient bignum multiplication. In most descriptions, it’s said to reduce 4 multiplications to 3 multiplications, 4 additions and 2 subtractions.
In fact, there’s an extremely simple and less-known micro-optimization known as Refined Karatsuba that only uses 3.5 additions. It can be useful in high-speed cryptography in general, and in embedded systems with limited resource. A reader may find it’s trivial, but it’s almost never documented in most textbooks or tutorials, thus often missed. This article attempts to raise its awareness.
For modular multiplication in a finite field, an extra technique called Reduced Refined Karatsuba further reduces the cost to 3 additions.
Standard Karatsuba
First, let’s have a quick review.
In standard Karatsuba multiplication, we have two integers
First, we “split” both integers at the middle into two parts of equal
size:
Second, independently multiply the low and high parts of the result.
Third, calculate the middle part. There are two equivalent ways to calculate this: addition and subtraction. We use the subtractive variant.
The final result is:
This is the Karatsuba Identity. Using the schoolbook algorithm, it requires 4 half word multiplications (16 digits in total), as the high and low parts of the results must all be multiplied with each other. The Karatsuba algorithm needs just 3 half-word multiplications (12 digit) at the expense of 4 additions and 2 subtractions. But we can do better.
Refined Karatsuba
Note that in our final formula,
both
Then, we can calculate
It should be obvious by now: the standard Karatsuba formula has a hidden
inefficiency: a duplicated addition. If
We can solve the problem by precomputing the result.
For maximum efficiency,
Then the final summation simplifies to:
This is the Refined Karatsuba Identity, it requires only 7 half-word (3.5 full-word) additions instead of 8. This micro-optimization was originally proposed by Daniel J. Bernstein.
Reduced Refined Karatsuba
In cryptography applications, arithmetic operations are modular (i.e. the numbers “wrap back” after reaching a maximum value) because they represent elements in a finite field. Once the value went off the scale, a modular reduction is needed to bring it back within the proper range. In elliptic curve cryptography, extremely efficiency special-purpose reduction algorithms can be used, because the field size of a curve is often carefully chosen.
For example, in base-10 arithmetic, if the modulus is
Fast reduction algorithms in cryptography is outside the scope of the article, I only want to convince you that sometimes using an extra reduction step is reasonable, which brings us to the Reduced Refined Karatsuba algorithm. It reduces the number of additions from 3.5 to 3.