Number Theory: Exponentiation with Fast Powering and Montgomery Ladder
17 Dec 2021
§ Motivation
We often use exponentiation over finite fields in cryptography, as solving for given in the discrete log problem is very difficult. However, our exponents are often quite large and computing them through the naïve method of repeated multiplication is not the fastest method asymptotically.
Suppose we wanted to compute , in this case we must compute multiplications of the base in the naïve method. With fast-powering we can get it down to steps which have at most multiplications each.
This reduction in the number of steps is doubly important, because naïve integer multiplication in binary is . In cryptography we work with very large bases and exponents, so these time complexities are very important in terms of practicality. So, using both naïve exponentiation and multiplication, we can expect time complexity. We can get better asymptotic times for multiplication using Karatsuba, Toom-k, or fast-fourier transforms for increasingly larger numbers; thusly reducing the asymptotic run-time of the fast-powering approach.
Additionally, we can use a result from Euler's theorem in certain cases to reduce the exponent before attempting to compute the exponent value.
§ Fast Powering
Most texts refer to this method as Exponentiation by squaring instead of fast-powering.
Fast Powering
Suppose for a large we want to compute , we first want to find the binary expansion of :
Then, for each power of two we compute
Finally, we compute
§ Montgomery Ladder
Side Channel Attacks
Suppose we performed fast powering, as described previously, for an application like RSA.
In this case Mallory, a malicious actor, wants to recover the our private exponent and has the means to profile the fast-powering algorithm.
Mallory knows the public-key information: the modulus and the public exponent .
Mallory sends an encrypted message to us, and we try to decrypt it with our private key .
Because Mallory has profiling capabilities, she can tell when the program is running relatively slower or faster.
By counting the slow (squaring) and faster (multiplication) frames, it is possible for her to recover some information about .
The Montgomery ladder method attempts to mitigate the viability of side-channel attacks by performing a squaring and multiplication at each step.
Montgomery Ladder
- # Inputs: base , binary expansion of
- function MontgomeryLadder(, )
- for in do
- if then
- else
- if then
- return