The one-sentence version
RSA turns a plaintext into , then recovers it with . This works because the unit group has order , and every element raised to the power equals (Lagrange's theorem). Real implementations also use the Chinese Remainder Theorem to split one large operation modulo into two small ones modulo and modulo , which is about 4 times faster.
This article has three layers:
- The intuition: public keys, private keys and the "one-way door"
- Real-world use: HTTPS certificates, signatures and some classic failures
- The mathematics: Euler's theorem, why , CRT speedups and a worked example
Layer 1: The Intuition
1.1 A padlock anyone can close but only you can open
An RSA public key is like an open padlock: you can make thousands of copies and send them around the world, and anyone can use one to lock a box. But only you hold the key, so only you can open a locked box.
| Analogy | In RSA |
|---|---|
| Open padlock (share freely) | Public key |
| Key (keep hidden) | Private key |
| Locking a box | Encryption |
| Opening a box | Decryption |
1.2 A one-way door: easy to multiply, hard to take apart
RSA's security comes from a very plain fact:
- A computer multiplies two 300-digit primes in the blink of an eye;
- But given the product , recovering and would take the fastest known classical algorithms practically forever.
The private key is computed from and . An outsider only knows , and without factoring cannot compute . A structure that is "easy in one direction, hard in the other, but easy again if you know a secret ()" is called a trapdoor one-way function.
1.3 Why "a power of a power" returns to the start
Picture a clock face, not with 12 positions but with very many. Start from and step forward by multiplying by each time. After exactly steps you always land on ; one more step brings you back to itself.
RSA chooses and so that , so "going times, then times" means circling full laps plus one more step, landing exactly on . Outsiders don't know how long a lap is (), so they don't know how many steps lead back.
Layer 2: Real-World Use
2.1 Encryption and signatures
- Encryption: lock with someone else's public key, and only they can open it. In practice RSA only encrypts a random AES key (a "digital envelope"), and AES handles the bulk data.
- Signatures: the reverse. "Lock" a document's hash with your own private key, and anyone can open it with your public key to verify. If it opens, the private-key holder must have signed it.
HTTPS certificates, software-update signatures, PGP email and SSH logins relied mostly on RSA for decades. New systems increasingly use elliptic curves (see "Elliptic Curves"), because the keys are far shorter for the same security:
| Security strength | RSA modulus length | Elliptic curve key length |
|---|---|---|
| 112 bits | 2048 bits | 224 bits |
| 128 bits | 3072 bits | 256 bits |
| 256 bits | 15360 bits | 512 bits |
2.2 Some classic failures
| Failure | What happened |
|---|---|
| No padding | Textbook RSA is deterministic: the same plaintext always yields the same ciphertext, and a small plaintext space can simply be enumerated. Real systems must use OAEP padding |
| Håstad's broadcast attack | With , the same message is sent to 3 people. An attacker uses the CRT to combine the 3 ciphertexts into (an integer, with no reduction) and takes the cube root directly |
| Shared prime factors | In 2012 researchers scanned certificates across the internet and found that many devices, because of poor randomness, shared some prime . Taking the of two values of factors both at once |
| ROCA (2017) | One chip maker's way of generating primes had a special structure. It affected millions of keys (including about 750,000 Estonian ID cards), and those keys could be factored |
The quantum threat
Shor's algorithm factors large integers efficiently on a quantum computer, which would break RSA completely. See "Post-Quantum Cryptography" for details.
Layer 3: The Mathematics
3.1 Key generation
- Choose two large primes and let ;
- Compute , the number of integers in coprime to ;
- Choose with (commonly );
- Use the extended Euclidean algorithm to find .
The public key is and the private key is .
3.2 Euler's theorem: a corollary of Lagrange's theorem
(the invertible elements modulo ) is a finite group under multiplication, of order . By Lagrange's theorem, the order of every element divides the order of the group, so
This is Euler's theorem; when is prime it is Fermat's little theorem, .
3.3 Why decryption is correct
From ,
What if and aren't coprime?
Then is not in the unit group, and Euler's theorem doesn't apply directly. But we can look modulo and modulo separately: say , then both sides are modulo ; modulo , Fermat's little theorem works as usual. Combining them with the Chinese Remainder Theorem still gives . (In practice you will almost never meet such an , and if you did, you would have factored .)
3.4 The CRT speedup
By the Chinese Remainder Theorem, is a ring isomorphism. So can be split into two halves:
and is then combined into the unique solution modulo . Reducing the exponents modulo first is also thanks to Fermat's little theorem. The modulus has half as many bits, making multiplication about 4 times cheaper, and the exponent has half as many bits too; overall it is 3 to 4 times faster.
Fault attacks
If a CRT implementation makes an error in just one half (say, disturbed by a voltage glitch), the faulty signature satisfies but is wrong modulo , so , and a single signature factors (the Boneh–DeMillo–Lipton attack). So a signature should be verified locally before it is sent out.
3.5 A worked example
A tiny RSA
Take , , , . Take ; from we get .
Encrypt : , so .
Decrypt directly: .
Decrypt with the CRT:
- Modulo : , , , so
- Modulo : , , , so
- Combining: the only value from to with both and is
Both methods give . (Checked with Python.)
Summary
| Layer | Key points |
|---|---|
| Intuition | Easy to multiply, hard to take apart; knowing is the trapdoor |
| Algebra | has order ; Lagrange's theorem gives Euler's theorem; guarantees correct decryption |
| Engineering | The CRT speeds things up 3 to 4 times; padding is mandatory; verify signatures before sending |
| Future | Will be broken by Shor's algorithm; migration to post-quantum algorithms is under way |