RSA security, attacks, padding and hybrid encryption
Why factoring is the whole game, the five attack classes the lecture names against RSA, why textbook RSA is malleable, and how padding and hybrid encryption fix RSA's two practical weaknesses.
- State why factoring n is the foundation of RSA's security, and why key sizes below 2048 bits are no longer considered safe.
- Explain why p and q must be large and must not be close together.
- Name the five classes of attack the lecture identifies against RSA.
- Reproduce the lecture's malleability derivation and explain why it defeats semantic security.
- Explain what OAEP padding adds to RSA and why hybrid encryption exists.
20 min read
Intuition
The previous page showed RSA working correctly: choose keys, encrypt, decrypt, get the right answer back. None of that says the scheme is safe to actually deploy. RSA’s security rests on one hard problem, factoring, and even a mathematically sound choice of , and can still be broken if the ciphertext is used carelessly. This page covers both halves: what makes the numbers themselves hard to attack, and what makes naive RSA unsafe even when the numbers are fine.
Mechanism
Why factoring is the whole game. Recovering without permission means either finding the -th root of directly, which is believed infeasible, or factoring back into and , which lets an attacker reconstruct and then exactly as the key holder did. Both are believed hard. Factoring is the one that fails first as shrinks, so RSA’s key-size recommendation is set by how large needs to be before factoring is out of reach.
Two conditions on and keep factoring hard:
- and must be very large. The lecture states RSA key lengths of
2048bits and above are needed for today; the Week 5 practice quiz is explicit that key sizes below2048bits are no longer considered secure. - and must not be close together. If they are, sits close to , and searching near finds the factors quickly, a much cheaper search than factoring in general.
The lecture is blunt about the rest: there are further constraints on what makes a good key beyond these two, and the guidance is simply never implement RSA yourself for production use.
Mechanism
Five ways to attack RSA, as the lecture names them:
- Brute force. Try every possible private key. Feasible only against small keys, which is the attack the
2048-bit recommendation defends against. - Mathematical attacks. Several distinct approaches exist, but all of them are equivalent in effort to factoring .
- Timing attacks. Measure how long decryption takes. Variation in running time can leak information about .
- Hardware fault-based attacks. Deliberately induce a fault in the processor computing a signature, then use the faulty output to extract key material.
- Chosen ciphertext attacks. Exploit a structural property of RSA itself, with malleability as the lecture’s example, rather than attacking the key.
The rest of this page is about the fifth one, because it is the attack that motivates everything RSA does in practice beyond raw key generation.
Threat
Malleability. Textbook RSA preserves multiplicative structure: if you have two ciphertexts, their product decrypts to the product of the two plaintexts, and nobody needs to know either plaintext or the private key to produce that product. An attacker who can get a chosen ciphertext decrypted (a chosen ciphertext attack) turns this into a way to recover a plaintext they never directly saw.
Worked example
AnswerEve turns c = E(3) into a product with E(5) = 146, gets 15 back from decryption, and divides by 5 to recover the original 3, without ever learning d.
Using the key from the previous page: , , , , .
Eve intercepts for some plaintext she has not seen. Say : . By repeated squaring: , , . , so : , then . So .
The general trick, from the lecture: pick any , compute , and get it decrypted. Since , the decrypted value is , not , but is enough to recover once is known.
Eve doesn’t need to pick out of thin air. If she has already seen another ciphertext for a known (say ), she can use it directly as her multiplier. Computing : , , . : , then . So .
Eve computes . , and . She submits for decryption. This is the chosen ciphertext attack step.
The decryption oracle returns . By repeated squaring: , , , , . , so : , then , then . The oracle returns .
, and Eve knows , so : the original plaintext, never once decrypted directly, with never exposed. (In general is recovered as ; here plain division works because is smaller than .)
Control
OAEP, Optimal Asymmetric Encryption Padding, is what the lecture names as today’s fix. Padding adds randomness to the message before it is raised to the power , so encrypting the same plaintext twice under the same key produces two different ciphertexts. That randomness breaks the algebra above: an attacker who multiplies two OAEP-padded ciphertexts together does not get a padded encryption of the product, because the padding does not survive the multiplication cleanly. Malleability is a property of the raw mathematical function; OAEP changes what gets fed into that function.
Mechanism
Why textbook RSA has no semantic security. A cryptosystem is semantically secure when a ciphertext leaks only a small amount of information about its plaintext. Plain RSA is deterministic: the same plaintext under the same public key always produces the same ciphertext. An attacker facing a small or guessable message space can encrypt candidate plaintexts under the known public key and compare the results to the target ciphertext. This is a chosen plaintext attack, and it works precisely because RSA has no randomness of its own. OAEP’s padding is also what supplies the randomness semantic security needs; the fix for malleability and the fix for missing semantic security are the same padding scheme, because both problems trace back to the same cause.
Mechanism
Hybrid encryption. Public-key cryptography solves key distribution but has two practical problems: it can
only encrypt numbers, so non-numeric data needs an extra mapping step, and it is slow: the lecture states RSA
runs 100 to 1000 times slower than AES. Almost every real system avoids encrypting bulk data with RSA
directly. Instead:
- Generate a random symmetric key .
- Encrypt the actual message with a symmetric cipher: .
- Encrypt itself with the receiver’s public key: .
- Send both .
The receiver decrypts with their private key to recover , then uses to decrypt with the fast symmetric cipher. RSA’s job shrinks to moving one short key; the symmetric cipher, covered on the AES page, carries everything else.
Aside
The lecture frames this as two separate roles working together, not RSA being replaced: the public key still solves the problem symmetric cryptography cannot (agreeing on a secret with no prior shared key), while the symmetric cipher solves the problem RSA is bad at (encrypting a lot of data quickly).
Exam detail
Three numbers are worth having cold: 2048 bits as the minimum RSA key length the unit treats as secure,
the five named attack classes in order (brute force, mathematical, timing, hardware fault, chosen ciphertext),
and the malleability identity itself: decrypts to . A question that
gives you a ciphertext and asks what an attacker who never saw the plaintext can still produce is testing this
identity directly.
Pitfall
“Textbook RSA is insecure” does not mean the RSA problem itself is broken. Factoring is still believed hard, and a well-chosen key pair is still safe to use. The vulnerability is in using raw, unpadded RSA directly on a message. Padding does not touch key generation at all; it changes what gets encrypted, not how , or are chosen.
Recall
An attacker has two ciphertexts, c1 = E(3) and c2 = E(5), under the same RSA key, and can get any ciphertext decrypted. How do they recover 3 without ever seeing it decrypted directly?
Multiply the ciphertexts: . Because RSA preserves multiplicative structure, decrypting returns . Since the attacker already knows from their own ciphertext, they recover , the plaintext behind , without the private key and without ever submitting itself for decryption.
Source
Week 5 notes PDF