Attacks on RSA
tl;dr: I discuss the issues related to small exponents, how to improve the success rate of an attack on RSA, how the square root relates to the hardness of the RSA problem, and its connection with Shor’s algorithm. Many of the materials discussed below are thanks to the lecture notes and coursework that I have taken in Introduction to Cryptography.
Prerequisites
- RSA
- Chinese Remainder Theorem (CRT)
- Shor’s Algorithm (for the last section only)
Small Exponent Attack
Alice wants to send a (k − 1)-bit message, , to Bob, Cathy, and Dave. Bob, Cathy, and Dave have distinct k-bit RSA keys, , , and , and they all use the same exponent, . Alice uses plain textbook RSA to encrypt under each key, resulting in three ciphertexts , , and , which she sends to them. Eve intercepts all three ciphertexts. Show that Eve can recover the plaintext .
There are two cases to consider:
-
, , and are not pairwise coprime.
Without loss of generality, suppose and are not coprime. Then one can use to factor both and . Once factored, computing is straightforward, which then enables decryption of the ciphertext .
-
, , and are pairwise coprime.
In this case, we have:
Using the Chinese Remainder Theorem (CRT), we can compute a value such that
Since is smaller than any of the moduli, . Therefore, the cube root of can be taken directly to recover .
Improve RSA Attack Success Rate
Let be an RSA key, where . Suppose is a probabilistic algorithm that runs in time with
Show that can be used as a subroutine to construct an algorithm such that
To build such an algorithm , we rely on the fact that RSA is multiplicatively homomorphic. With this in mind, one can devise an algorithm as follows:
- Repeat:
- Sample .
- Compute .
- Until .
Then, by using the homomorphic property, recover as:
By repeating the algorithm a bounded number of times, we can design with a success probability of 99%.
Square Root and RSA
Let’s begin by examining an interesting attack.
RSA Key Leakage Vulnerability
Suppose Bob uses the RSA cryptosystem and has a key pair with public key and private key . If Bob accidentally leaks his private key and decides to generate a new public/private key pair without generating a new modulus, show that this approach is insecure.
To prove that this approach is insecure, we will show that, given , one can factor (assuming is the product of two odd primes).
- Given , compute using the public key .
- By definition, is divisible by . Since Euler’s totient function is even, is even, and hence is an integer.
- By Euler’s theorem, for every , we have . Therefore, is a square root of .
Properties of Square Roots
Before proceeding with the proof, let’s study the properties of the square roots of , which we denote by .
Using the CRT, since where and are primes, solving
is equivalent to solving
For a prime , the solutions to are . Similarly for . Hence, there are four solutions modulo , determined by the combinations of and :
- and , i.e., .
- and , i.e., .
- and .
- and .
Each satisfies because modulo both and .
The nontrivial solutions and are especially important for factoring . Consider :
- Since , we have ; hence, divides .
- Since , we have , and since is odd, . Thus, does not divide .
Therefore, . A similar argument applies to , except it yields .
However, finding a nontrivial square root of 1 is not straightforward in RSA. In fact, it can be shown that for every , . To explain this, express and with . Then,
where is a positive integer and . This implies that divides and similarly for . By the CRT and Euler’s Theorem, it follows that
On the bright side, if is even, we can iterate and consider , , and so on to search for a nontrivial square root of 1. Formally, writing where and is an odd integer, we can examine the sequence:
If, for any , the value is neither 1 nor , then we can successfully factor 1 The sequence computation and gcd calculation can be done in polynomial time. See Proof of Fact 1..
But what is the probability that such an event occurs when we randomly select ?
We will now prove a lower bound: such an event occurs with probability at least . Let .
A strawman example: First, consider where . Since , both and divide . Thus, for any , will always be 1. This suggests that we should instead look at the case when .
Before proceeding further, we prove the following lemma:
Lemma
- The multiplicative group (with prime) is cyclic; that is, it has a generator.
- has a subgroup of order , and for every , we have if and only if .
Proof.
-
This follows from the standard result that the multiplicative group of a finite field is cyclic. Let denote a generator of this group.
-
The subgroup exists and can be generated by . Its order is because is the smallest integer satisfying . The rest of the lemma follows:
-
() If , then for some integer , so
-
() Conversely, if and , then
Since has order , it must be that is a multiple of ; hence, is even. Writing , we have , so . This also implies that if , then .
-
Now, consider the case . There are two cases to analyze:
-
Case 1: (without loss of generality).
Since , we have and thus divides . This implies . To obtain a nontrivial square root, we require . Writing (with odd), by the lemma, if is in the subgroup of (which has order ), then ; if , then . Therefore, for a randomly sampled ,
-
Case 2: .
In this case, to obtain a nontrivial square root of 1, either
- and , or
- and .
By a similar analysis as in Case 1, the total probability of a nontrivial square root occurring is
Thus, regardless of and , we have:
Therefore,
This completes the proof.
You can also programmatically verify the above proof using this simulation. The simulation verifies the above proof and additionally provides another method to simulate the probability of factorizing by checking all the elements in the sequence.
Proof (Continued)
To factor , we can randomly sample group elements until we find one that yields a nontrivial square root of 1. Based on the analysis above, this happens with a high probability after only a few tries. Ultimately, the nontrivial square root is used to factor 2 This is not the only method to attack RSA when both and are known. This post details an alternative approach that estimates to compute , which then allows one to deduce and factor ..
Shor’s Algorithm
The idea behind Shor’s algorithm (period finding) is also connected to using square roots to factor .
Suppose we use Shor’s algorithm to find an such that
that is,
Then, by the previous arguments, with probability at least , we can use to factor . Consequently, one can repeatedly sample elements and apply Shor’s algorithm until success is achieved.
Another perspective on how a nontrivial square root aids in factoring is to note that for an element with , we have:
Thus, one of the factors in the parenthesis will be a prime factor of (provided ).
Next Steps
- Read Twenty Years of Attacks on the RSA Cryptosystem.
- Considering it has been over 25 years since this survey, what are the new attacks against RSA?