Path: blob/main/foundations/04-number-theory-rsa/connect/rsa-oaep-padding.ipynb
483 views
Connect: RSA-OAEP Padding
Module 04 | Real-World Connections
Why textbook RSA is never used in practice and how OAEP fixes it.
Introduction
Textbook RSA --- --- is mathematically elegant but completely unsuitable for real-world encryption. It has two fatal flaws:
Deterministic: the same message always encrypts to the same ciphertext
Malleable: an attacker can manipulate ciphertexts to produce related plaintexts
Every real RSA deployment uses padding to fix these problems. The modern standard is OAEP (Optimal Asymmetric Encryption Padding), specified in PKCS#1 v2.2.
This notebook demonstrates why textbook RSA fails and how OAEP fixes each flaw.
Problem 1: Deterministic Encryption
Textbook RSA is a deterministic function: given the same , , and , it always produces the same .
This means an attacker can:
Detect when the same message is sent twice
Build a dictionary mapping known plaintexts to ciphertexts
Distinguish between two candidate messages (breaks IND-CPA security)
Problem 2: Malleability (Chosen Ciphertext Attack)
Textbook RSA is multiplicatively homomorphic:
An attacker who sees can compute:
--- an encryption of !
Without knowing , the attacker can manipulate the ciphertext to produce a related plaintext. This enables devastating chosen-ciphertext attacks.
The Bleichenbacher Attack (1998)
Daniel Bleichenbacher demonstrated a practical attack against RSA PKCS#1 v1.5 encryption padding. The attacker sends millions of modified ciphertexts to a server and observes whether the server reports a padding error. By exploiting the multiplicative malleability, each response leaks a small amount of information about the plaintext, eventually recovering it entirely.
This attack affected real SSL/TLS implementations and is the primary motivation for OAEP.
OAEP: Optimal Asymmetric Encryption Padding
OAEP (Bellare and Rogaway, 1994) pads the message with randomness using a Feistel-like structure before applying RSA:
To decrypt:
Compute
Split into
Recover
Recover
Check the zero padding; reject if invalid
Concept Map: Module 04 and OAEP
| Module 04 Concept | RSA-OAEP Application |
|---|---|
| RSA encryption () | Applied to the OAEP-padded message, not raw plaintext |
| RSA decryption () | Recovers padded message; OAEP unpadding extracts plaintext |
| CRT (Notebook 04d) | RSA-CRT optimization: compute and separately |
| Euler's theorem (Notebook 04c) | Still guarantees ; OAEP adds security on top |
OAEP transforms textbook RSA (which is a trapdoor permutation) into a proper encryption scheme with provable security against chosen-ciphertext attacks.
Summary
| Property | Textbook RSA | RSA-OAEP |
|---|---|---|
| Deterministic? | Yes (same always gives same ) | No (fresh randomness each time) |
| Malleable? | Yes ( encrypts ) | No (Feistel structure prevents manipulation) |
| IND-CPA secure? | No | Yes |
| IND-CCA2 secure? | No | Yes (in the random oracle model) |
| Used in practice? | Never | Yes (PKCS#1 v2.2, RFC 8017) |
Key takeaways:
Textbook RSA is a mathematical building block, not a cryptosystem.
Determinism lets an attacker detect equal plaintexts and perform dictionary attacks.
Malleability lets an attacker manipulate ciphertexts without knowing the plaintext.
OAEP fixes both problems by padding the message with randomness through a Feistel-like structure.
Every real RSA encryption uses OAEP (or is being migrated to it).
The underlying RSA math from Module 04 is unchanged --- OAEP adds a layer of security on top.
Back to Module 04: Number Theory and RSA