First, we give a bit of history. Ron Rivest, Adi Shamir, and Leonard Adleman (shown in Figure 5.5.4.1) first publicly described this algorithm for public key encryption in 1978 [9]. 1
Clifford Cocks described an equivalent system in 1973, but it was classified by the UK intelligence agency GCHQ until 1997}
They offered a $100 prize and remarked that using technology and factoring techniques available at that time, it would take 40 quadrillion years to crack. Advances in factoring techniques and computers cracked the code in April 1994 [5] to find that the secret message was:
The Magic Words are Squeamish Ossifrage 2
According to Wikipedia, Ossifrage is an older name for the lammergeier, a scavenging vulture that is famous for dropping animal bones and live tortoises onto rocks to crack them open. It might perhaps be considered among the least squeamish of creatures.
The RSA public encryption key consists of a pair of integers \((N,e)\text{,}\) where \(N\) is the product of two distinct primes \(p\) and \(q\text{,}\) and the encryption exponent \(e\) is relatively prime to \(\phi(N) = (p-1)(q-1)\text{.}\)
The message space is set of integers \(\{1, 2,\cdots, N\}\text{.}\) To encrypt a message \(M\) from the message space, Alice computes the integer \(C\) in the message space that satisfies
\begin{equation*}
C \equiv M^e \pmod{N}.
\end{equation*}
Notice that with fast exponentiation, this is fast.
RSA encryption works when the messages are integers between \(1\) and \(N\text{.}\) As we saw in Subsection 5.2.2, ASCII encoding allows us to encode a message string into an integer. After the message is encoded as an integer, we can encrypt it with RSA encryption.
If an eavesdropper Eve captures \(C\) while it is being transmitted, Eve will have a hard time computing the original message \(M\text{,}\) since taking \(e\) th roots is a hard problem known as the discrete log problem .
How is it any easier for Bob? The trick is that Bob has a bit of extra information. When constructing the key, Bob chooses \(N\) to be a product of two distinct primes \(p\) and \(q\text{,}\) so that \(N = pq\text{.}\) The exponent \(e\) is chosen so that the greatest common divisor \(\gcd(e,\phi(N))=1\text{.}\) Since Bob knows the factorization of \(N\text{,}\) he can easily compute the Euler \(phi\) function \(\phi(N) = (p-1)(q-1)\text{.}\) Then using the Euclidean algorithm, Bob can compute an inverse to \(e\) modulo \(\phi(N)\text{,}\) an integer \(d\) such that \(ed \equiv 1 \pmod{\phi(N)}\text{.}\) By Bézout’s Theorem, there is an integer \(k\) so that \(ed = 1 +k\phi(N)\text{.}\) Now Euler’s generalization to Fermat’s little theorem says that if \(\gcd(C,N)=1\text{,}\) we have
Thus, to decrypt the message, Bob does not need to take an \(e\) th root of \(C\) modulo \(N\text{.}\) Instead, he can raise \(C\) to the \(d\) th power and achieve the same result. Thank you, Euler! Again, with fast exponentiation, this is fast.
Suppose Bob has public key \((N,e) = (55,3)\text{.}\) For the purposes of this example, pretend \(55\) is so large that Eve cannot factor it. Then Alice can encrypt any number from \(1\) to \(55\text{.}\) Suppose Alice wants to send \(M = 18\text{.}\) She computes
How does Bob decrypt \(C\text{?}\) He knows that \(\phi(55) = 40\text{,}\) since he created the key. The decryption exponent \(d\) is the inverse if \(e\) modulo \(\phi(N)\text{,}\) so it satisfies \(ed \equiv 1 \pmod{\phi(N)}\text{.}\) Bob can compute \(d\equiv -13 \pmod{40}\) by Extended Euclidean Algorithm
Next, the message space is too small. Notice that if Eve could solve \(x^3\equiv 2 \pmod{55}\text{,}\) she can find Alice’s message. The message space \(\set{1,2,\dots,55}\) is small enough that Eve could just compute \(x^3 \bmod{55}\) for several values of \(x\) and quickly find an answer.
Figure5.5.4.7.The RSA Cryptosystem. Bob creates a key pair consisting of a private and a public key (top right) and the makes the public key available, for example in a public key directory (top left). To send Bob a secret message Alice obtains Bob’s public key and uses it to encrypts a message (bottom left). Bob decrypts the message using his private key (bottom right).
Bob’s decription \(X^d\bmod N\) in Figure 5.5.4.7 works because \((e\cdot d) \bmod \bigl((p-1)(q-1)\bigr)=1\) and \(0\le M\lt N\) and because by Theorem 5.5.4.6 we have
\begin{align*}
X^d \bmod n\amp =(m^e)^d \bmod N\\
\amp= M^{ed}\bmod N\\
\amp= M^{1+k(p-1)(q-1)} \bmod N = M
\end{align*}
Why is RSA secure? What numbers should I pick? The encryption exponent \(e\) is typically chosen to be \(e = 2^{16} + 1 = 65537\text{.}\) This is not for security, but for speed. Because of our fast powering algorithm, this choice of \(e\) allows encryption to be done even more quickly.
If \(p\) and \(q\) are chosen to be large primes (for today’s technology 100-200 digit primes are large enough), then the claim is that this encryption is secure. To decrypt a message, we either have to be able to take \(e\) th roots ( that is , solve \(x^e \equiv C \pmod{N}\)), or compute \(d\text{.}\) The first problem is hard, and one of the main ways to try to solve it is via finding \(d\text{.}\) In order to find \(d\text{,}\) we must know \(\phi(N)\text{.}\) As long as Bob keeps the factors \(p\) and \(q\) secret then computing \(\phi(N)\) is hard.
In the days of early commercial cryptography, many companies offered “challenges” to measure the state of progress in practical cryptanalysis. RSA used a Factoring Challenge. More information can be found at https://en.wikipedia.org/wiki/RSA_Factoring_Challenge.
They posted a set of eight challenge numbers, ranging in size from 576 bits (174 decimal digits) to 2048 bits (617 decimal digits) that made up the challenge 3
The RSA numbers were generated on a computer with no network connection of any kind. The computer’s hard drive was subsequently destroyed so that no record would exist, anywhere, of the solution to the factoring challenge. Not even the people at RSA knew the factorizations.
. Each number is the product of two large primes, similar to the modulus of an RSA key pair. The first person to submit a correct factorization for any of the challenge numbers was eligible for a cash prize. To date, only four of the eight challenge numbers have been factored.
Just how large is \(N\text{?}\) There is a nice video by Vsauce explaining to see how large \(52!\) is. If you don’t have 20 minutes, skip to around the 15:56 minute mark. Even then, we are not done, since \(52!\) is MUCH smaller than \(N\text{.}\) In fact,
\begin{equation*}
N \gt (52!)^4,
\end{equation*}
so if we repeat the process \(52!\) times, then repeat all of that \(52!\) times, then repeat all of that \(52!\) times, we are still not done. https://www.youtube.com/watch?v=ObiqJzfyACM
Figure5.5.4.9.Security. (https://xkcd.com/538/) Actual actual reality: nobody cares about his secrets. (Also, I would be hard-pressed to find that wrench for \$5.)