Engineering/Mathematics/Applied cryptography
The RSA Cryptosystem
RSA is three lines of number theory and forty years of implementation lessons. The mathematics has never been broken; almost every practical failure has come from padding, parameter choice, fault handling or the random number generator.
- Application
- Computing
- Widely deployed
- ≈17 min read
- Synthesis of the library
01
Executive summary
RSA takes a modulus n = pq and a public exponent e coprime to λ(n) = lcm(p−1, q−1). The private exponent is d ≡ e−1 (mod λ(n)). Encryption raises to the power e, decryption to the power d, and Euler's theorem makes the two inverse.
This page assembles most of the library. Prime generation supplies p and q; the extended Euclidean algorithm produces d; Chinese remaindering accelerates the private operation; and the security argument rests on the difficulty of factoring, bounded by the number field sieve.
Two random primes, a public exponent, and its inverse modulo λ(n).
Modular exponentiation; the private direction uses CRT for a fourfold speed-up.
ed ≡ 1 (mod λ(n)) makes the two maps inverse on all of ℤ_n.
Recovering d from (n,e) is equivalent to factoring n; the raw problem is only conjecturally equivalent.
02
Key generation and operations
Generate two primes
Random p and q of half the modulus bit length, with the top two bits set so that n has exactly the nominal size. They must be independently generated from a well-seeded cryptographic source.
Check the separation condition
|p − q| must not be small, or Fermat factorization succeeds instantly. Independently generated primes satisfy this with overwhelming probability, but the check is cheap.
Form the modulus and compute λ(n)
n = pq and λ(n) = lcm(p−1, q−1).
Choose the public exponent
e = 65537 is standard: prime, only two bits set, so encryption and verification cost 17 squarings and one multiplication.
Compute the private exponent
d ≡ e−1 (mod λ(n)) by the extended Euclidean algorithm. It exists exactly when gcd(e, λ(n)) = 1; otherwise regenerate a prime.
Precompute CRT parameters
dp, dq, q−1 mod p for the accelerated private operation.
Destroy the intermediates
Zero p, q and λ(n) in any memory not intended to hold them.
Correctness
For every x ∈ ℤn, xed ≡ x (mod n). Proof: ed = 1 + kλ(n), so for units the claim follows from xλ(n) ≡ 1. For non-units, check modulo p and q separately — if p ∣ x both sides vanish modulo p, and Fermat's little theorem handles the other factor — then recombine by the Chinese remainder theorem.
| Operation | Exponent | Cost at 2048 bits |
|---|---|---|
| Encrypt / verify | e = 65537 | 17 squarings, 1 multiplication — sub-millisecond |
| Decrypt / sign, direct | d, full size | ≈ 3000 modular multiplications |
| Decrypt / sign, CRT | dp, dq, half size | ≈ 4× faster than direct |
| Key generation | — | Dominated by prime search: hundreds of candidates |
03
Why textbook RSA is unusable
The raw function is not an encryption scheme
Encrypting m as me mod n is deterministic, so identical plaintexts produce identical ciphertexts and a small message space can be searched exhaustively. It is also multiplicatively homomorphic: (m1m2)e = m1em2e, which enables blinding attacks against both encryption and signatures. Padding is what turns the trapdoor permutation into a scheme.
| Attack | Condition | Effect |
|---|---|---|
| Dictionary attack | Small or guessable message space | Recover the plaintext by encrypting candidates |
| Multiplicative blinding | Chosen-ciphertext access | Obtain a signature or decryption of a chosen value |
| Håstad broadcast | Same small e, same message to e recipients | Recover the message by CRT and an integer e-th root |
| Franklin–Reiter and Coppersmith | Related messages under the same modulus | Recover both messages |
| Signature forgery | Multiplicative structure | Forge a signature on a product of previously signed values |
None of these attacks the factoring problem; they exploit the algebraic structure that padding is designed to destroy.
| Scheme | Purpose | Status |
|---|---|---|
| PKCS #1 v1.5 encryption | Encryption | Legacy; vulnerable to Bleichenbacher-style oracle attacks unless implemented with extreme care |
| OAEP | Encryption | Recommended; provably secure in the random oracle model |
| PKCS #1 v1.5 signature | Signature | Still widely deployed; acceptable with strict verification |
| PSS | Signature | Recommended; randomised with a tight security proof |
Bleichenbacher's 1998 attack against PKCS #1 v1.5 encryption keeps reappearing in new forms because implementations leak whether padding was well formed. Constant-time, error-indistinguishable handling is mandatory.
04
Parameter and implementation attacks
| Attack | Condition | Countermeasure |
|---|---|---|
| Wiener | d < n1/4/3 | Never choose a small private exponent; derive d from e |
| Boneh–Durfee | d < n0.292 | Same |
| Coppersmith partial key exposure | A quarter of the bits of p or d leak | Treat all private material as all-or-nothing |
| Fermat factorization | |p−q| small | Generate primes independently and check the separation |
| Pollard p−1 | p−1 smooth | Random primes of modern size make this negligible |
| Shared factors across keys | Poor entropy at generation | Well-seeded cryptographic RNG; audit deployed moduli for common factors |
| Bellcore fault attack | A fault in one CRT half | Verify the signature before releasing it |
| Timing and power analysis | Secret-dependent execution | Constant-time exponentiation, blinding of base and exponent |
| Common modulus | One n with several exponent pairs | Never share a modulus between users |
Entropy failures are the most common real-world break
Large-scale surveys of deployed TLS and SSH keys have repeatedly found moduli sharing a prime factor, because embedded devices generated keys at first boot before their entropy pools were seeded. Any two such moduli are factored by a single gcd. The mathematics was sound in every case; the sampling was not.
- Never reuse a modulus. Any holder of one valid private exponent can factor the modulus, so a shared modulus offers no privacy between its users.
- Blind the private operation. Compute (rec)d·r−1 for random r, which decorrelates timing and power traces from the actual ciphertext.
- Validate on import. Reject moduli that are even, prime, perfect powers, or share small factors; reject public exponents that are 1 or even.
05
Key sizes and the alternatives
| Symmetric strength | RSA modulus | Finite-field DH | Elliptic curve | Guidance |
|---|---|---|---|---|
| 80 bits | 1024 bits | 1024 bits | 160 bits | Deprecated |
| 112 bits | 2048 bits | 2048 bits | 224 bits | Acceptable near term |
| 128 bits | 3072 bits | 3072 bits | 256 bits | Current recommendation |
| 192 bits | 7680 bits | 7680 bits | 384 bits | High assurance |
| 256 bits | 15360 bits | 15360 bits | 512 bits | Rarely justified for RSA |
Figures follow standard equivalence tables derived from extrapolating number field sieve and Pollard rho costs. Note how badly RSA scales: quadrupling the security level requires a fifteenfold larger modulus.
- RSA remains competitive for verification. With e = 65537, signature verification is far cheaper than an elliptic curve verification, which is why RSA persists in certificate chains where verification vastly outnumbers signing.
- Elliptic curves win on key size and on signing cost, which is why new deployments generally prefer them for key exchange and signatures.
- Quantum computing changes the ranking entirely. Shor's algorithm breaks RSA, finite-field Diffie–Hellman and elliptic curves alike in polynomial time. Migration guidance now points to lattice- and hash-based schemes, with hybrid deployments during transition.
06
Quick reference and FAQ
| Item | Value |
|---|---|
| Public key | (n, e) |
| Private key | (d, p, q, dp, dq, q−1 mod p) |
| Key equation | ed ≡ 1 (mod λ(n)), λ(n) = lcm(p−1,q−1) |
| Encrypt | c = OAEP(m)e mod n |
| Decrypt | m = OAEP−1(cd mod n), via CRT |
| Sign | s = PSS(m)d mod n, verified before release |
| Verify | se mod n checked against the encoding |
| Standard exponent | e = 65537 |
Is breaking RSA provably as hard as factoring?
Why e = 65537 rather than 3?
Do RSA primes need to be strong primes?
What should be done with existing 1024-bit RSA keys?
08
References and further reading
- R. L. Rivest, A. Shamir and L. Adleman, 'A method for obtaining digital signatures and public-key cryptosystems', Communications of the ACM 21 (1978) 120–126.
- V. Shoup, A Computational Introduction to Number Theory and Algebra, Cambridge University Press, 2005 — §7.8 and Chapter 10.
- D. Boneh, 'Twenty years of attacks on the RSA cryptosystem', Notices of the AMS 46 (1999) 203–213.
- RFC 8017 (PKCS #1 v2.2), IETF, 2016 — OAEP and PSS specifications.
- NIST SP 800-57 Part 1 Rev. 5, Recommendation for Key Management, 2020 — key size equivalences.
KEVOS® Knowledge LibraryEngineering → MathematicsTaxonomy ID: ENG-MATHPage ID: rsa-cryptosystemReview cycle: annual
