RSA Security and the Factoring Problem
A bank sends an encrypted key over the internet. An attacker intercepts the ciphertext. Can the attacker recover the message without ever learning the secret key? The entire safety of The RSA Cryptosystem rests on one confident guess. That guess is that factoring a large number into its prime components is computationally infeasible. This guess, known as the factoring assumption, has survived five decades of scrutiny by mathematicians and cryptanalysts. Yet the assumption alone does not make RSA safe to use naively. RSA as taught in an introductory course — raise the message to the power , reduce modulo — is called "textbook RSA." It is deterministic, malleable, and structurally weak in ways that have nothing to do with factoring. Real systems that use RSA, from TLS handshakes to code-signing certificates, must wrap the raw algebraic operation in padding schemes. They must also enforce protocol discipline to close these gaps. Understanding exactly which attacks exploit unpadded RSA is essential to using public-key cryptography safely. So is knowing why padding schemes like OAEP and PSS neutralize them. This article separates two questions that students often conflate: "Is factoring hard?" and "Is RSA-as-deployed secure?" The first question concerns the mathematical hardness assumption underlying the scheme. The second concerns implementation, padding, randomness, and protocol design. A cryptosystem can rest on a rock-solid hardness assumption. It can still be catastrophically insecure if deployed carelessly. RSA is the canonical teaching example of this gap. By the end of this article you will be able to state the factoring assumption precisely. You will trace through the classical attacks on textbook RSA: small exponent, common modulus, related message, and Bleichenbacher's padding oracle. You will also explain why modern deployments require randomized padding, domain separation, and constant-time implementations. This sets the stage for later material on quantum attacks against factoring and general key-management discipline.
- RSA's hardness rests on the factoring assumption: no known efficient (polynomial-time) classical algorithm factors large semiprimes.
- Textbook RSA is deterministic and multiplicative, which enables chosen-ciphertext and low-exponent attacks that have nothing to do with factoring.
- Classic attacks include Coppersmith's low-exponent attack, Håstad's broadcast attack, common modulus attacks, and Bleichenbacher's padding-oracle attack.
- Modern deployments use OAEP for encryption and PSS for signatures — randomized, structured paddings with security proofs in the random oracle model.
- Key size must scale superpolynomially with security level because the best known factoring algorithm (GNFS) runs in subexponential time.
- Factoring is efficiently solvable by Shor's algorithm on a large quantum computer, motivating the shift toward Post-Quantum Cryptography.
RSA's security depends on two independent pillars — the hardness of factoring and the correctness of the padding scheme — and a failure in either one breaks the system.
The idea
The RSA problem is: given a modulus (product of two large primes), a public exponent , and a ciphertext , recover without knowing the factorization of . The factoring assumption states that no probabilistic polynomial-time algorithm can, with non-negligible probability, recover and from alone, when and are randomly chosen primes of sufficient bit-length. RSA's private key satisfies , and computing from is provably as hard as factoring — so if factoring is hard, recovering the private key is hard. Crucially, the RSA problem (invert ) is only believed to be as hard as factoring; no proof of equivalence in general is known, though for special cases (e.g. recovering ) the equivalence does hold. This distinction matters: an attacker does not need to factor to break RSA in practice. They only need to invert the specific ciphertext they intercepted, exploit algebraic structure in how RSA is used, or exploit implementation side channels. This is the source of the gap between "factoring is hard" and "RSA as I coded it is secure."
Textbook RSA denotes the bare operation with no additional processing. It has three properties that make it unsuitable for direct use: it is deterministic (the same plaintext always produces the same ciphertext, leaking equality information), it is multiplicatively homomorphic (, letting an attacker manipulate ciphertexts algebraically), and for small messages or small exponents, may not even "wrap around" modulo , making the modular reduction meaningless. Secure deployments instead use padding schemes — most notably OAEP (Optimal Asymmetric Encryption Padding) for encryption and PSS (Probabilistic Signature Scheme) for signatures — that inject randomness and structural checks before the modular exponentiation, breaking determinism and homomorphism while remaining provably secure under the RSA assumption in the random oracle model.
How it works
The factoring assumption, precisely
Given with random -bit primes, the assumption is that any algorithm running in time polynomial in satisfies
The best known classical algorithm, the General Number Field Sieve (GNFS), factors an -bit integer in expected time
which is subexponential — faster than exponential in 's bit-length, but slower than any polynomial. This subexponential runtime is precisely why RSA key sizes must be large (2048–3072 bits today) and must grow over time as computing power increases, unlike symmetric ciphers whose key length scales linearly with security level.
Why textbook RSA fails: attack catalogue
The following is a step-by-step walk through the classic attacks, each exploiting a specific structural weakness rather than factoring directly.
1. Small public exponent, no padding (Coppersmith / cube-root attack). If and the message is small enough that , then over the integers (no modular wraparound occurs), so the attacker simply computes an integer cube root.
2. Håstad's broadcast attack. If the same message is sent to recipients with distinct moduli , an attacker who intercepts combines them via the Chinese Remainder Theorem to recover , and since , an integer cube root recovers — again with no factoring involved.
3. Common modulus attack. If two parties share the same but use different exponents with , and the same message is encrypted under both, an attacker who has can use the extended Euclidean algorithm to find integers with , then compute
4. Related-message / Franklin-Reiter attack. If two messages are related by a known linear function () and encrypted under the same small exponent, polynomial GCD techniques recover both messages.
5. Bleichenbacher's padding-oracle attack (1998). This is the most consequential attack in practice. Even with padding (PKCS#1 v1.5), if the decryption oracle leaks whether a ciphertext's padding is well-formed (e.g., via a distinguishable error message or timing difference), an attacker can adaptively query millions of ciphertexts to narrow down the plaintext, eventually decrypting any target ciphertext without the private key. This underlies "ROBOT" and similar attacks against TLS servers even decades after the original discovery.
The fix: OAEP and PSS
OAEP (encryption) transforms message using two random oracles and a random seed before RSA is applied: ``` OAEP-Encode(m, k0, k1):
# m is the message, padded with k1 zero bits, total length n - k0 r <- random k0-bit string dbMask <- G(r) # G expands r to length (n - k0) maskedDB <- (m || 0^k1) XOR dbMask seedMask <- H(maskedDB) # H compresses to length k0 maskedSeed <- r XOR seedMask return maskedSeed || maskedDB # this is the OAEP-encoded message, then RSA-exponentiated ``` Decryption reverses the masks and checks that the trailing zero bits are present; if not, decryption fails without revealing which check failed (a well-implemented OAEP decryption returns a single generic error). The random seed ensures encryption is probabilistic (defeating the determinism weakness), and the two-round Feistel-like structure destroys the multiplicative homomorphism (defeating common-modulus and related-message attacks), because the ciphertext no longer corresponds to a simple algebraic function of .
PSS (signatures) similarly randomizes signing: a random salt is hashed together with the message digest, embedded in a padded block, and only then RSA-exponentiated with the private key. This prevents existential forgery attacks that exploit RSA's multiplicative structure (e.g., an attacker computing a valid signature on from valid signatures on and ). ``` RSA-Encrypt-Secure(m, pk = (n, e)): EM <- OAEP-Encode(m) # randomized, structured encoding c <- EM^e mod n return c RSA-Decrypt-Secure(c, sk = (n, d)): EM <- c^d mod n m, valid <- OAEP-Decode(EM) if not valid: return GENERIC_ERROR # never distinguish error types or leak timing return m ``` The critical implementation discipline is that `OAEP-Decode` must run in constant time and must return exactly one error code regardless of which internal check failed — this is precisely what Bleichenbacher-style attacks exploit when violated.
Complexity & correctness
Factoring runtime. The GNFS complexity, , is neither polynomial nor exponential in the bit-length ; it lies strictly between the two, which is why key sizes for RSA (2048–4096 bits) are far larger than for comparable symmetric ciphers (128–256 bits) at the same security level. Trial division and Pollard's rho give exponential-time baselines; GNFS is the asymptotically best known classical algorithm and is what drove the deprecation of 512-bit and 1024-bit RSA.
Correctness of RSA decryption. The scheme's correctness (that decryption recovers the original plaintext) follows from Euler's theorem: since , write ; then for coprime to ,
For sharing a factor with (a negligible-probability event for random over a large modulus), correctness still holds via the Chinese Remainder Theorem applied separately mod and mod . This is a correctness argument, entirely separate from security — the algebra guarantees the ciphertext decrypts to the right value, but says nothing about whether an eavesdropper can also recover .
Security reduction (why we trust RSA-OAEP). OAEP's security proof shows that, in the random oracle model, if an adversary can break the semantic security (IND-CCA2) of RSA-OAEP, then that adversary can be used as a subroutine to invert the RSA trapdoor permutation itself. Symbolically: security of RSA-OAEP solving the RSA problem (invert ) is easy (conjecturally) factoring is easy. The contrapositive gives the guarantee developers rely on: if factoring stays hard and behave like random oracles, RSA-OAEP resists chosen-ciphertext attacks — closing exactly the gap that Bleichenbacher's attack exploited in the unpadded/naively-padded case.
Tradeoffs to be honest about. The random oracle model is an idealization; real hash functions are not literally random oracles, so OAEP's proof is a heuristic guarantee, not an unconditional one. Padding also adds overhead: OAEP consumes bits for the seed and redundancy, shrinking the maximum plaintext size relative to raw RSA (roughly 's bit-length minus minus bits). And no amount of padding fixes RSA against a large-scale quantum computer, since Shor's algorithm factors in polynomial time on such hardware — a limitation that padding cannot address at all, motivating Post-Quantum Cryptography.
Worked example
Consider the common modulus attack traced through concrete (small, illustrative) numbers. Let , , so and . Suppose (insecurely) two different services share this modulus but use different public exponents:
- Service A:
- Service B:
Both are coprime to and to each other: . A user sends the same message to both services.
| Step | Computation | Result |
|---|---|---|
| Encrypt for A | ||
| Encrypt for B | ||
| Extended Euclid on | find with | (check: ... adjust) |
Let's redo the extended Euclidean step carefully since must be verified properly:
Back-substitute: So , , giving . ✓ Now the attacker, who intercepted and but knows neither private key, computes:
Since is negative, the attacker first computes the modular inverse of modulo , call it , then squares it, then multiplies by . Carrying this out (using modular exponentiation and the extended Euclidean algorithm for the inverse) yields:
recovering the plaintext without ever factoring and without knowing either private exponent or — purely from algebraic manipulation of two ciphertexts of the same message under coprime exponents sharing a modulus. This demonstrates precisely why "textbook RSA is insecure" is not a vague slogan: the attack above runs in time dominated by a handful of modular exponentiations and one Euclidean algorithm call, all polynomial-time operations, entirely bypassing the (hard) factoring problem.
Common pitfalls & traps
| Pitfall | Why it happens | Consequence |
|---|---|---|
| Using textbook RSA directly on messages | Treating RSA as a black-box "encrypt with public key" primitive | Deterministic ciphertexts leak equality; small-/ enables cube-root attack |
| Sharing a modulus across users with different exponents | Misunderstanding key generation as "just pick " per user | Common modulus attack recovers plaintext without factoring |
| Distinguishable padding-error messages in decryption | Returning different error codes for "bad padding" vs "bad length" | Bleichenbacher-style oracle attacks reconstruct plaintext via millions of queries |
| Non-constant-time modular exponentiation | Using naive square-and-multiply with data-dependent branching | Timing side channels leak bits of the private exponent |
| Small public exponent with no OAEP and small messages | Optimizing for encryption speed () without padding | Direct integer cube root recovers when |
| Reusing random seed/salt in OAEP or PSS | Faulty or predictable random number generator | Breaks probabilistic-encryption security guarantee, reintroduces determinism weaknesses |
| Assuming "RSA is secure" means "any use of RSA is secure" | Conflating the hardness assumption with protocol-level security | Ignores decades of chosen-ciphertext and padding-oracle literature |
Pioneers & history
Origins · 1 minDaniel Bleichenbacher and how this was discovered
Bleichenbacher discovered in 1998 that PKCS#1 v1.5 padding, though seemingly adequate, allowed an adaptive chosen-ciphertext attack whenever a server leaked padding-validity information. His attack forced a rethinking of RSA padding standards and directly motivated the adoption of OAEP in practical protocols, cementing the principle that error-handling discipline is itself a security-critical component of a cryptosystem.
RSA's story is inseparable from the broader arc of public-key cryptography inaugurated by Whitfield Diffie and Martin Hellman's 1976 key-exchange paper, and it echoes Claude Shannon's earlier insight that a cryptosystem's strength must be measured against a well-defined adversarial model rather than intuition. The repeated pattern in RSA's history — a clean mathematical primitive, followed by a subtle protocol-level attack, followed by a provably secure padding fix — is a template that recurs throughout applied cryptography, and it foreshadows the current transition toward lattice-based schemes as factoring's classical hardness comes under threat from quantum algorithms.
Where this matters
RSA with OAEP and PSS padding underlies the TLS handshake used to secure HTTPS connections, code-signing systems that verify software authenticity (from operating system updates to mobile app stores), and secure email standards like S/MIME. Hardware security modules (HSMs) in banking infrastructure implement constant-time RSA operations specifically to prevent the timing side-channels discussed above. Certificate authorities issuing X.509 certificates rely on RSA-PSS or RSA-PKCS#1 signatures to bind public keys to identities, making correct padding a foundational trust anchor for the entire web PKI. Understanding textbook RSA's weaknesses is also a prerequisite for Key Management practice, since key reuse across protocols (a real-world instance of the common-modulus pattern) remains a recurring audit finding in production systems, and for grasping why Post-Quantum Cryptography migration is treated as urgent despite RSA's continued classical-security margin.
Ask the tutor: Can you walk through why OAEP's security proof breaks down if the random oracles G and H are replaced with a real hash function that has a subtle correlation?
Does breaking textbook RSA mean factoring is easy?
No. The attacks described here (small exponent, common modulus, Håstad's broadcast attack) exploit how RSA is used, not the hardness of factoring itself. An attacker recovering a plaintext via the common modulus attack never learns or ; they only exploit algebraic relationships between two ciphertexts. Factoring the modulus remains believed-hard throughout. This is exactly why textbook RSA can be simultaneously "broken in practice" and "based on an unbroken hardness assumption" — the two statements describe different layers of the system, the protocol layer versus the underlying number-theoretic layer.
Why doesn't RSA just use a bigger e to avoid the small-exponent attack?
Increasing (commonly is used, chosen for fast exponentiation via repeated squaring) does raise the bar against the naive cube-root style attacks, since will almost certainly exceed and wrap around modulo , hiding the integer root. But a larger alone does not fix determinism or malleability: the ciphertext is still a deterministic function of , and it still satisfies . OAEP padding is required regardless of exponent size to obtain semantic security and resistance to chosen-ciphertext attacks.
What is the difference between OAEP and PSS?
OAEP (Optimal Asymmetric Encryption Padding) is used for RSA encryption: it randomizes a plaintext before exponentiation with the public key, aiming for IND-CCA2 security. PSS (Probabilistic Signature Scheme) is used for RSA signing: it randomizes a message digest with a salt before exponentiation with the private key, aiming for existential unforgeability under chosen-message attack. Both share the design philosophy of injecting randomness and structured redundancy around the RSA trapdoor permutation, but they target different security goals (confidentiality versus authenticity) and are not interchangeable.
If I use a 4096-bit RSA key, am I safe from all these attacks?
Key size alone protects only against brute-force factoring; it does nothing against protocol-level attacks. A 4096-bit RSA key used without OAEP padding, or deployed with a padding-oracle-vulnerable error handler, remains vulnerable to Bleichenbacher-style attacks and related-message attacks regardless of key size. Security requires getting both layers right: a modulus large enough to resist GNFS-class factoring, and a padding/protocol layer that eliminates determinism, malleability, and oracle leakage. Larger keys also increase computational cost, so oversizing without fixing the protocol layer is a wasted tradeoff.
How does Shor's algorithm change this picture?
Shor's algorithm, if run on a sufficiently large fault-tolerant quantum computer, factors an -bit integer in time polynomial in , collapsing the subexponential GNFS barrier entirely. This would break the factoring assumption outright, independent of any padding scheme — no amount of OAEP or PSS protects against an adversary who can simply factor and recompute the private key . This threat, while not yet practical at RSA-relevant key sizes, is the central motivation for migrating toward lattice-based and other schemes studied under Post-Quantum Cryptography.
Why is the random oracle model considered a heuristic rather than a proof?
OAEP's and PSS's security proofs model the hash functions and as ideal random oracles — functions that behave as truly random, independent mappings queried only via oracle access. Real hash functions like SHA-256 are concrete algorithms, not literal random functions, so the proof is a heuristic argument that has held up well empirically but is not a proof in the unconditional sense a Turing-machine-based reduction would give. Some artificial schemes are known to be secure in the random oracle model yet insecure when the oracle is instantiated with any real hash function, illustrating the gap, though no such separation is known to afflict OAEP or PSS in practice.
Is the common modulus attack a real-world threat today?
It is rare in well-run infrastructure because standard key-generation tools produce a fresh modulus per key pair, but it has appeared as an audit finding in embedded systems, IoT devices, and misconfigured multi-tenant certificate systems that reused moduli to save computation. It is taught primarily as a clean illustration of "algebra beats algebra" — recovering a shared plaintext without touching the factoring problem — and as a warning against any key-management shortcut that causes moduli or exponents to be reused across contexts, a theme central to Key Management practice.