skip to content

Why is textbook RSA - treating the message as an integer and raising it to the public exponent modulo n with no padding - insecure even when nobody can factor the modulus? Name the property that randomized padding restores.

level: seniorimportance: should knowfreq 34%

answer

  1. attacker holds the encryption key
  2. deterministic means offline guess-and-compare
  3. IND-CPA requires randomised encryption
  4. raw RSA multiplicative; small-exponent root
  5. uniform, constant-time decryption failure

basics

~20 s

Because the attacker holds the encryption key. Unpadded encryption is deterministic, so any low-entropy plaintext can be guessed and encrypted offline until the ciphertext matches. Randomized padding restores semantic security: the same message encrypts to unlinkable ciphertexts.

solid answer

~50 s

The distinguishing feature of public-key encryption is that everybody can encrypt. A deterministic scheme therefore hands the attacker a free offline oracle: for a yes/no answer, a six-digit code, a salary band or an account identifier, they encrypt every candidate with the public key and compare. No key recovery, no interaction, no rate limit. The missing property is semantic security - indistinguishability under chosen-plaintext attack - which no deterministic scheme can satisfy, so encryption must be randomized. Padding also destroys raw algebraic structure: unpadded RSA is multiplicatively malleable, and a small public exponent with a small message can be recovered by taking an ordinary integer root because no modular wrap-around occurs. The decryption side matters equally. If a service reveals through its error message or its timing that padding was invalid rather than the content, it becomes a chosen-ciphertext oracle. Decryption must fail uniformly and in constant time.

go deeper

for a junior

Know that unpadded public-key encryption is unsafe and that padding adds required randomness.

for a middle

Explain determinism plus a public encryption key as an offline guessing attack, and name semantic security.

for a senior

Cover malleability, the small-exponent case, and the chosen-ciphertext oracle created by non-uniform decryption failures.

for a principal

Treat the decryption interface, its error taxonomy and its timing as part of the cryptosystem's attack surface and set review rules accordingly.

## The asymmetry in the threat model With symmetric encryption an attacker who wants to test a guess must persuade the system to encrypt for them. With public-key encryption they hold the encryption key already. Every property that depends on the attacker not being able to encrypt is therefore void by construction. This is why padding is mandatory rather than a hardening extra. ## Attack one: guess and compare Deterministic encryption preserves equality. If the plaintext space is small or predictable - an approve/reject decision, a numeric identifier, a national ID, a one-time code, a card number with a known prefix and check digit - the attacker enumerates candidates, encrypts each with the public key, and matches. Even over large spaces, equality leakage alone is damaging: identical ciphertexts prove identical plaintexts, so patterns across records are visible without any decryption. The same equality leak makes deterministic tokenisation and naive block-by-block encryption unsafe; what is peculiar to the asymmetric setting is that the attacker needs nothing from you to exploit it. ## Attack two: algebraic structure Raw RSA is homomorphic under multiplication: multiplying two ciphertexts yields the encryption of the product of the plaintexts. An attacker can therefore transform a ciphertext into a related one with a predictable effect, which is malleability - an integrity failure, not just a confidentiality failure. Small-exponent cases are worse still: if the message raised to a small public exponent is smaller than the modulus, there is no modular reduction and an ordinary integer root recovers the plaintext. ## The property, stated precisely Semantic security, formalised as indistinguishability under chosen-plaintext attack, says an adversary who picks two plaintexts cannot tell which one a ciphertext corresponds to, even holding the public key. No deterministic scheme can satisfy it, because the adversary simply encrypts both candidates. So the scheme must inject fresh randomness per operation, from a cryptographically secure source. A modern padding scheme mixes the message with random bytes through hash-based masking so the encoded value is spread across the whole modulus width, killing both the equality leak and the small-message shortcut. The stronger target is indistinguishability under chosen-ciphertext attack, which additionally requires that access to a decryption service teaches the attacker nothing. ## The decryption side is half the problem A padded scheme is only as strong as the way failure is reported. If a service distinguishes 'padding malformed' from 'padding fine but content rejected' - by error code, log line, response time or response length - an attacker who can submit chosen ciphertexts learns one bit per query and can iteratively recover a plaintext without ever obtaining the private key. That is the classic padding-oracle shape against older padding formats. The defences are structural: use a padding construction designed to resist chosen-ciphertext attack, return a single indistinguishable failure for every reason, branch and compare in constant time, and rate-limit and monitor the decryption endpoint. Constant-time comparison matters because an early-exit byte comparison leaks how many leading bytes were correct, converting a search over the whole space into a search one byte at a time. ## The transferable rule Encryption alone is not a safe interface. Any decryption service is an oracle whose observable behaviour - including its errors and its timing - is part of the cryptosystem. Design the failure path with the same care as the algorithm choice.

  • Why is a low-entropy plaintext, such as a six-digit code, especially dangerous under a deterministic public-key scheme?
    The attacker can enumerate the entire plaintext space themselves. With a million candidates and the public key in hand they encrypt every one offline and compare against the captured ciphertext, recovering the value in seconds without touching your system. There is no rate limit to hit and no log entry to raise, so a large modulus provides no protection whatsoever.
  • What makes a decryption endpoint an oracle, and how do you close it?
    Any behaviour that differs by reason for failure - distinct error codes or messages, different response lengths, measurably different timing - lets an attacker submit modified ciphertexts and learn something about the plaintext one query at a time. You close it by returning a single opaque failure for every cause, keeping the failure path constant-time, using a padding scheme designed against chosen-ciphertext attack, and rate-limiting and alerting on failure bursts.

saying these in an interview costs you the question

  • Believing that if the modulus cannot be factored the encryption must be safe.
  • Treating padding as a length-encoding detail rather than the source of required randomness.
  • Returning distinct error responses for bad padding versus bad content from a decryption service.
  • Sourcing padding randomness from a general-purpose, non-cryptographic random generator.

context