← Back to section · Foundations of Cryptography
The Point of Padding: How OAEP and PSS Turn RSA into Real Cryptography
Padding is not about making messages longer — it is an encoding layer that injects randomness, structural checks and hash mixing before the exponentiation. The history of PKCS#1 v1.5 and Bleichenbacher's attack, and the design ideas behind OAEP and PSS.
The previous article listed textbook RSA’s four sins: determinism, malleability, integer roots on small messages, and no integrity. The fix is not to change the exponentiation but to insert an encoding layer before the message ever reaches it — padding. The name is undersold; it sounds like merely topping messages up to length. In fact padding carries the bulk of RSA’s security: choose the wrong padding, or implement the right one carelessly, and no amount of mathematical hardness will save the system.
Three jobs the padding layer must do
First, inject randomness. Each encoding folds in a fresh random value, so the same message produces completely different encodings and determinism disappears — a precondition for semantic security. Second, fill the modulus range. The encoded value must be a number close to the size of the modulus, so degenerate cases like “message so small the power never reduces” cannot occur, and the attacker cannot treat the encoding space as an enumerable structure. Third, verifiable redundant structure. The encoding embeds a fixed format stirred together with the randomness, and the decoder checks it strictly; the probability that an arbitrarily forged or reshaped number passes the check must be negligible. That turns the decryptor from “decrypts everything” into “rejects almost everything”, and chosen-ciphertext attacks lose their footing.
All three are indispensable. Randomness without structural checks still lets homomorphic reshaping through; structure without randomness leaves determinism intact. The padding schemes actually deployed in history line up neatly by how many of the three they achieved.
PKCS#1 v1.5: simple, ubiquitous, then broken
The PKCS#1 v1.5 encryption padding, fixed in the 1990s, encodes as 00 02 || random non-zero bytes || 00 || message. It has randomness and fills the length, but its structural check is loose: correct first two bytes, a zero separator somewhere — accepted. It carried no security proof; at the time, intuition said this was enough.
In 1998 Daniel Bleichenbacher published his famous adaptive chosen-ciphertext attack. If the decryptor reacts distinguishably to “format valid” versus “format invalid” — a different error code, an alert present or absent, a timing wobble — the attacker can repeatedly multiply the intercepted ciphertext by chosen factors and submit the results, using each yes/no answer to narrow the interval in which the plaintext lies, until on the order of a million queries recover the plaintext in full. The point is not that the attacker can decrypt anything; it is that the decryptor becomes an oracle answering only yes or no, and the padding check is loose enough that the “yes” set can be binary-searched.
The sequel is just as instructive: in 2018 the ROBOT study found the same attack still working against many mainstream vendors’ TLS implementations — a twenty-year-old flaw resurrected because one error branch in an implementation had not been cleaned up. Today’s consensus is clear: v1.5 encryption padding survives only for compatibility and must not be used in new systems. The v1.5 signature padding (a deterministic digest encoding) is in somewhat better shape and remains widespread, but new designs prefer PSS there too.
OAEP: padding designed for encryption
OAEP (Optimal Asymmetric Encryption Padding, proposed by Bellare and Rogaway in 1994) builds the encoding as a two-round Feistel-style mix: take a random seed, use a mask generation function (essentially a hash stretched to length) to mask the message together with a check block, then use the masked message to mask the seed in return. The effect is that every bit of the encoding depends on all of the message and all of the randomness — flip any bit of the ciphertext and, at decoding time, the checks on both the seed and the message collapse together, so the attacker cannot make small, surgical changes.
OAEP carries a proof of IND-CCA security in the random oracle model — the fundamental difference from v1.5: not “nobody has broken it yet” but “breaking it reduces to the RSA problem itself”. The costs are a shorter maximum message (room must be left for the seed and the hash) and an unforgiving implementation burden. Nearly every successful attack on OAEP has targeted implementations: decode failures returning too early, comparisons not done in constant time, reassembling an oracle out of the side channels. Manger’s 2001 attack on early OAEP implementations is the canonical lesson. Padding security is half design, half implementation discipline.
PSS: padding designed for signatures
Signatures need something different: not confidentiality, but unforgeability with a randomised, verifiable structure. PSS (Probabilistic Signature Scheme, also from Bellare and Rogaway) hashes the message together with a random salt, hashes again, stirs the result through a mask generation function, and encodes it into a number near the size of the modulus before the private-key exponentiation. Verification recovers the salt and the hash from the signature and recomputes the comparison.
PSS is probabilistic: sign the same message twice and the signatures differ. This destroys the homomorphic forgeries of textbook signing — the “product of signatures is a signature of the product” trick — because the encoding layer’s mixing leaves no usable algebraic relation between signatures. PSS also has a security proof (a tight reduction to RSA hardness in the random oracle model), and its salt length and hash function are negotiable parameters, which is why it became the only RSA signature option in TLS 1.3: TLS 1.3 mandates RSA-PSS and shows v1.5 signature padding out of the handshake.
Choosing and implementing
The conclusions compress into three rules. First, use RSAES-OAEP for encryption and RSASSA-PSS for signatures — the joint choice of PKCS#1 v2.2 (RFC 8017) and modern protocols. Second, match the hash function and parameters to the key size and negotiate them explicitly in the protocol, leaving no implicit defaults. Third, at the implementation level, let decode failure be a single undifferentiated failure: every padding error returns the same error, nothing returns early, comparisons run in constant time. Bleichenbacher’s ghost has haunted implementations for over two decades purely through side doors they left open. The padding layer looks like mere encoding; in truth it is the last — and most easily underestimated — step that turns a hard mathematical problem into usable cryptography.
Tags: RSAOAEPPSSpadding