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 ee, reduce modulo nn — 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.

Key takeaways
  • 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.
The core insight

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 n=pqn = pq (product of two large primes), a public exponent ee, and a ciphertext c=me  nc = m^e \bmod n, recover mm without knowing the factorization of nn. The factoring assumption states that no probabilistic polynomial-time algorithm can, with non-negligible probability, recover pp and qq from nn alone, when pp and qq are randomly chosen primes of sufficient bit-length. RSA's private key dd satisfies ed≡1(modφ(n))ed \equiv 1 \pmod{\varphi(n)}, and computing dd from (n,e)(n, e) is provably as hard as factoring nn — so if factoring is hard, recovering the private key is hard. Crucially, the RSA problem (invert m↦me  nm \mapsto m^e \bmod n) is only believed to be as hard as factoring; no proof of equivalence in general is known, though for special cases (e.g. recovering dd) the equivalence does hold. This distinction matters: an attacker does not need to factor nn 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 c=me  nc = m^e \bmod n 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 ((m1m2)e≡m1em2e(modn)(m_1 m_2)^e \equiv m_1^e m_2^e \pmod n, letting an attacker manipulate ciphertexts algebraically), and for small messages or small exponents, mem^e may not even "wrap around" modulo nn, 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 n=pqn = pq with p,qp, q random kk-bit primes, the assumption is that any algorithm A\mathcal{A} running in time polynomial in kk satisfies

Pr⁡[A(n)={p,q}]≤negl(k).\Pr[\mathcal{A}(n) = \{p, q\}] \le \text{negl}(k).

The best known classical algorithm, the General Number Field Sieve (GNFS), factors an nn-bit integer in expected time

Ln[13,c]=exp⁡ ⁣((c+o(1))(ln⁡n)1/3(ln⁡ln⁡n)2/3),c≈1.923,L_n\left[\tfrac{1}{3}, c\right] = \exp\!\left((c + o(1)) (\ln n)^{1/3} (\ln \ln n)^{2/3}\right), \quad c \approx 1.923,

which is subexponential — faster than exponential in nn'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 nn directly.

1. Small public exponent, no padding (Coppersmith / cube-root attack). If e=3e = 3 and the message mm is small enough that m3<nm^3 < n, then c=m3c = m^3 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 mm is sent to e=3e=3 recipients with distinct moduli n1,n2,n3n_1, n_2, n_3, an attacker who intercepts c1,c2,c3c_1, c_2, c_3 combines them via the Chinese Remainder Theorem to recover m3  (n1n2n3)m^3 \bmod (n_1 n_2 n_3), and since m3<n1n2n3m^3 < n_1n_2n_3, an integer cube root recovers mm — again with no factoring involved.

3. Common modulus attack. If two parties share the same nn but use different exponents e1,e2e_1, e_2 with gcd⁡(e1,e2)=1\gcd(e_1, e_2) = 1, and the same message mm is encrypted under both, an attacker who has c1=me1,c2=me2c_1 = m^{e_1}, c_2 = m^{e_2} can use the extended Euclidean algorithm to find integers a,ba, b with ae1+be2=1a e_1 + b e_2 = 1, then compute

c1ac2b≡mae1+be2≡m(modn).c_1^a c_2^b \equiv m^{a e_1 + b e_2} \equiv m \pmod n.

4. Related-message / Franklin-Reiter attack. If two messages are related by a known linear function (m2=f(m1)m_2 = f(m_1)) 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 mm using two random oracles G,HG, H and a random seed rr 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 k1k_1 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 rr 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 mm.

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 m1m2m_1 m_2 from valid signatures on m1m_1 and m2m_2). ``` 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.

Figure
Textbook RSA vs. OAEP-wrapped RSA: where the attacks bite
Message flow: Textbook RSA (top) vs. RSA-OAEP (bottom) message m c = m^e mod n (deterministic) vulnerable: small-e, common-mod, Håstad broadcast, malleability attacks message m OAEP-Encode + random seed r + G, H masks → EM c = EM^e mod n (probabilistic) decode must return ONE generic error in constant time — blocks Bleichenbacher Same trapdoor permutation, m^e mod n — but structure around it determines security.

Complexity & correctness

Factoring runtime. The GNFS complexity, Ln[1/3,1.923]L_n[1/3, 1.923], is neither polynomial nor exponential in the bit-length log⁡n\log n; 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 ed≡1(modφ(n))ed \equiv 1 \pmod{\varphi(n)}, write ed=1+kφ(n)ed = 1 + k\varphi(n); then for mm coprime to nn,

(me)d=m1+kφ(n)=m⋅(mφ(n))k≡m⋅1k≡m(modn).(m^e)^d = m^{1 + k\varphi(n)} = m \cdot (m^{\varphi(n)})^k \equiv m \cdot 1^k \equiv m \pmod n.

For mm sharing a factor with nn (a negligible-probability event for random mm over a large modulus), correctness still holds via the Chinese Remainder Theorem applied separately mod pp and mod qq. 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 mm.

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 ⇒\Rightarrow solving the RSA problem (invert m↦me  nm \mapsto m^e \bmod n) is easy ⇒\Rightarrow (conjecturally) factoring nn is easy. The contrapositive gives the guarantee developers rely on: if factoring stays hard and G,HG, H 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 nn's bit-length minus 2k02k_0 minus k1k_1 bits). And no amount of padding fixes RSA against a large-scale quantum computer, since Shor's algorithm factors nn 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 p=61p = 61, q=53q = 53, so n=pq=3233n = pq = 3233 and φ(n)=60×52=3120\varphi(n) = 60 \times 52 = 3120. Suppose (insecurely) two different services share this modulus n=3233n = 3233 but use different public exponents:

  • Service A: e1=17e_1 = 17
  • Service B: e2=7e_2 = 7

Both are coprime to φ(n)=3120\varphi(n) = 3120 and to each other: gcd⁡(17,7)=1\gcd(17, 7) = 1. A user sends the same message m=65m = 65 to both services.

StepComputationResult
Encrypt for Ac1=6517  3233c_1 = 65^{17} \bmod 3233c1=2790c_1 = 2790
Encrypt for Bc2=657  3233c_2 = 65^{7} \bmod 3233c2=2668c_2 = 2668
Extended Euclid on (17,7)(17, 7)find a,ba, b with 17a+7b=117a + 7b = 1a=−3, b=8a = -3,\ b = 8 (check: 17(−3)+7(8)=−51+56=517(-3) + 7(8) = -51+56=5... adjust)

Let's redo the extended Euclidean step carefully since gcd⁡(17,7)=1\gcd(17,7)=1 must be verified properly:

17=2⋅7+3,7=2⋅3+1,3=3⋅1+0.17 = 2 \cdot 7 + 3,\quad 7 = 2\cdot 3 + 1,\quad 3 = 3 \cdot 1 + 0.

Back-substitute: 1=7−2⋅3=7−2(17−2⋅7)=5⋅7−2⋅17.1 = 7 - 2\cdot 3 = 7 - 2(17 - 2\cdot7) = 5\cdot 7 - 2\cdot 17. So a=−2a = -2, b=5b = 5, giving 17(−2)+7(5)=−34+35=117(-2) + 7(5) = -34 + 35 = 1. ✓ Now the attacker, who intercepted c1=2790c_1 = 2790 and c2=2668c_2 = 2668 but knows neither private key, computes:

m≡c1a⋅c2b≡2790−2⋅26685(mod3233).m \equiv c_1^{a} \cdot c_2^{b} \equiv 2790^{-2} \cdot 2668^{5} \pmod{3233}.

Since a=−2a = -2 is negative, the attacker first computes the modular inverse of 27902790 modulo 32333233, call it 2790−1  32332790^{-1} \bmod 3233, then squares it, then multiplies by 26685  32332668^5 \bmod 3233. Carrying this out (using modular exponentiation and the extended Euclidean algorithm for the inverse) yields:

m=65,m = 65,

recovering the plaintext without ever factoring nn and without knowing either private exponent d1d_1 or d2d_2 — 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

PitfallWhy it happensConsequence
Using textbook RSA directly on messagesTreating RSA as a black-box "encrypt with public key" primitiveDeterministic ciphertexts leak equality; small-mm/e=3e=3 enables cube-root attack
Sharing a modulus nn across users with different exponentsMisunderstanding key generation as "just pick ee" per userCommon modulus attack recovers plaintext without factoring
Distinguishable padding-error messages in decryptionReturning different error codes for "bad padding" vs "bad length"Bleichenbacher-style oracle attacks reconstruct plaintext via millions of queries
Non-constant-time modular exponentiationUsing naive square-and-multiply with data-dependent branchingTiming side channels leak bits of the private exponent dd
Small public exponent with no OAEP and small messagesOptimizing for encryption speed (e=3e=3) without paddingDirect integer cube root recovers mm when me<nm^e < n
Reusing random seed/salt in OAEP or PSSFaulty or predictable random number generatorBreaks 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 securityIgnores decades of chosen-ciphertext and padding-oracle literature

Pioneers & history

Origins · 1 minDaniel Bleichenbacher and how this was discovered
DB
Daniel Bleichenbacher
b. 1964 (est.) · Swiss cryptographer, Bell Labs

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.

History
1977
— Rivest, Shamir, and Adleman publish the RSA cryptosystem, basing security on the presumed hardness of factoring.
1985
— Håstad and later researchers formalize broadcast attacks against low-exponent RSA without padding.
1994
— Mihir Bellare and Phillip Rogaway introduce OAEP with a security proof in the random oracle model.
1998
— Daniel Bleichenbacher publishes the adaptive chosen-ciphertext attack against PKCS#1 v1.5 padding.
1999
— RSA Factoring Challenge milestones (RSA-155, 512-bit) are factored, prompting migration to larger keys.

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 nn itself. An attacker recovering a plaintext via the common modulus attack never learns pp or qq; 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 ee (commonly 65537=216+165537 = 2^{16}+1 is used, chosen for fast exponentiation via repeated squaring) does raise the bar against the naive cube-root style attacks, since mem^e will almost certainly exceed nn and wrap around modulo nn, hiding the integer root. But a larger ee alone does not fix determinism or malleability: the ciphertext c=me  nc = m^e \bmod n is still a deterministic function of mm, and it still satisfies (m1m2)e=c1c2  n(m_1 m_2)^e = c_1 c_2 \bmod n. 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 nn-bit integer in time polynomial in nn, 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 nn and recompute the private key dd. 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 GG and HH 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.

Before this

Where this leads