CSEC3616Cybersecurity Engineering

    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 pp, qq and ee 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 dd without permission means either finding the ee-th root of CC directly, which is believed infeasible, or factoring nn back into pp and qq, which lets an attacker reconstruct φ(n)\varphi(n) and then dd exactly as the key holder did. Both are believed hard. Factoring is the one that fails first as nn shrinks, so RSA’s key-size recommendation is set by how large nn needs to be before factoring is out of reach.

    Two conditions on pp and qq keep factoring hard:

    • pp and qq must be very large. The lecture states RSA key lengths of 2048 bits and above are needed for nn today; the Week 5 practice quiz is explicit that key sizes below 2048 bits are no longer considered secure.
    • pp and qq must not be close together. If they are, n=pqn = pq sits close to n2\sqrt{n}^2, and searching near n\sqrt{n} 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:

    1. Brute force. Try every possible private key. Feasible only against small keys, which is the attack the 2048-bit recommendation defends against.
    2. Mathematical attacks. Several distinct approaches exist, but all of them are equivalent in effort to factoring nn.
    3. Timing attacks. Measure how long decryption takes. Variation in running time can leak information about dd.
    4. Hardware fault-based attacks. Deliberately induce a fault in the processor computing a signature, then use the faulty output to extract key material.
    5. 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: p=17p=17, q=11q=11, n=187n=187, e=7e=7, d=23d=23.

    1. Eve intercepts c=memodnc = m^e \bmod n for some plaintext mm she has not seen. Say m=3m = 3: c=37mod187c = 3^7 \bmod 187. By repeated squaring: 31=33^1 = 3, 32=93^2 = 9, 34=813^4 = 81. 7=4+2+17 = 4+2+1, so 37=81×9×3mod1873^7 = 81 \times 9 \times 3 \bmod 187: 81×9=729mod187=16881 \times 9 = 729 \bmod 187 = 168, then 168×3=504mod187=130168 \times 3 = 504 \bmod 187 = 130. So c=130c = 130.

    2. The general trick, from the lecture: pick any rr, compute c=cremodnc' = c \cdot r^e \bmod n, and get it decrypted. Since (c)d(cre)dmedredmr(modn)(c')^d \equiv (c \cdot r^e)^d \equiv m^{ed} \cdot r^{ed} \equiv m \cdot r \pmod n, the decrypted value is mrm \cdot r, not mm, but mrm \cdot r is enough to recover mm once rr is known.

    3. Eve doesn’t need to pick rr out of thin air. If she has already seen another ciphertext c2=remodnc_2 = r^e \bmod n for a known r=5r = 5 (say c2=57mod187c_2 = 5^7 \bmod 187), she can use it directly as her multiplier. Computing c2c_2: 51=55^1 = 5, 52=255^2 = 25, 54=625mod187=645^4 = 625 \bmod 187 = 64. 57=64×25×5mod1875^7 = 64 \times 25 \times 5 \bmod 187: 64×25=1600mod187=10464 \times 25 = 1600 \bmod 187 = 104, then 104×5=520mod187=146104 \times 5 = 520 \bmod 187 = 146. So c2=146c_2 = 146.

    4. Eve computes c=cc2modn=130×146mod187c' = c \cdot c_2 \bmod n = 130 \times 146 \bmod 187. 130×146=18980130 \times 146 = 18980, and 18980mod187=9318980 \bmod 187 = 93. She submits c=93c' = 93 for decryption. This is the chosen ciphertext attack step.

    5. The decryption oracle returns (c)dmodn=9323mod187(c')^d \bmod n = 93^{23} \bmod 187. By repeated squaring: 931=9393^1 = 93, 932=4793^2 = 47, 934=15293^4 = 152, 938=10393^8 = 103, 9316=13793^{16} = 137. 23=16+4+2+123 = 16+4+2+1, so 9316×934×932×931mod18793^{16} \times 93^4 \times 93^2 \times 93^1 \bmod 187: 137×152mod187=67137 \times 152 \bmod 187 = 67, then 67×47mod187=15767 \times 47 \bmod 187 = 157, then 157×93mod187=15157 \times 93 \bmod 187 = 15. The oracle returns 1515.

    6. 15=mr=m×515 = m \cdot r = m \times 5, and Eve knows r=5r = 5, so m=15÷5=3m = 15 \div 5 = 3: the original plaintext, never once decrypted directly, with dd never exposed. (In general mm is recovered as 15×r1modn15 \times r^{-1} \bmod n; here plain division works because mr=15m \cdot r = 15 is smaller than nn.)

    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 ee, 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:

    1. Generate a random symmetric key kk.
    2. Encrypt the actual message with a symmetric cipher: cm=Enck(m)c_m = \mathrm{Enc}_k(m).
    3. Encrypt kk itself with the receiver’s public key: ck=EncPU(k)c_k = \mathrm{Enc}_{PU}(k).
    4. Send both (ck,cm)(c_k, c_m).

    The receiver decrypts ckc_k with their private key to recover kk, then uses kk to decrypt cmc_m 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: ccre(modn)c' \equiv c \cdot r^e \pmod n decrypts to mrm \cdot r. 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 nn, ee or dd 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: c=c1c2modnc' = c_1 \cdot c_2 \bmod n. Because RSA preserves multiplicative structure, decrypting cc' returns m1m2=15m_1 \cdot m_2 = 15. Since the attacker already knows m2=5m_2 = 5 from their own ciphertext, they recover m1=15÷5=3m_1 = 15 \div 5 = 3, the plaintext behind c1c_1, without the private key and without ever submitting c1c_1 itself for decryption.