Chapter 2 · Lectures 5 to 6
Public-Key Cryptography
Public-key cryptography lets parties communicate without a previously shared key. This chapter develops the necessary number theory before covering RSA, ElGamal, elliptic curves and pairings. It ends with the systems that bind public keys to names.
Lecture 5 (07/10/25) opened with one-way functions, pseudorandom generators (PRGs), pseudorandom functions (PRFs) and pseudorandom permutations (PRPs). This Minicrypt material belongs to the Chapter 1 deck and is written up on the symmetric cryptography page. The remainder of Lecture 5 is the number theory in sections 1 to 5 below. Lecture 6 (09/10/25) is sections 6 to 13: RSA, ElGamal, the Diffie-Hellman assumptions, pairings, signatures, public-key infrastructures and identity-based encryption. Study plans: Lecture 5, Lecture 6.
Section 1The Key Distribution Problem
Lecture 5 and Lecture 6.
Every construction in Chapter 1 begins with a key both parties already hold. In a network of $n$ parties, pairwise symmetric keys number $\binom{n}{2} = O(n^2)$: roughly half a million for a thousand users, five hundred billion for a million. Each key must be generated, transported over a channel that is already confidential, stored and destroyed when a party leaves. The arithmetic is the smaller problem. The bootstrapping is the obstacle, since a symmetric key can only be established over a channel that is already secure. Two consequences follow. The secrets each party holds grow with the network, so one compromised machine exposes every conversation it joined, and two parties who have never met (a shop and a first-time customer) have no shared history to derive a key from.
Diffie and Hellman proposed a solution in 1976: split the key in two. Every party gets a public key that may be published in a directory and a matching private key that never leaves them. Anyone can encrypt to Bob using material Bob himself made public; only Bob can decrypt. The number of keys collapses to $O(n)$, and public keys require integrity alone, so the confidential distribution channel disappears.
Common mistake. A received public key can be trusted at face value. The key distribution problem shrinks, but authenticity remains: without a binding of key to owner, a man in the middle substitutes his own key and reads everything.
Rivest, Shamir and Adleman gave the first concrete public-key scheme in 1978. James Ellis had described the idea at GCHQ (Government Communications Headquarters) in 1970. The work stayed classified. Goldwasser and Micali supplied the security definition in 1984.
The price is that public-key encryption can never be unconditionally secure. An adversary holding $\mathit{pk}$ can, in unbounded time, encrypt every candidate message and compare, or search for a private key consistent with the public one, so perfect secrecy in Shannon's sense is unattainable and every scheme rests on a computational assumption. The scheme also does not replace symmetric encryption, because exponentiation modulo a 3072-bit number is thousands of times more expensive per byte than The Advanced Encryption Standard (AES). The practical norm is hybrid encryption, or key encapsulation: the public-key scheme runs once, to transport or agree a short session key. The traffic is then encrypted under that key with an authenticated symmetric scheme. TLS (Transport Layer Security) is built this way, and Chapter 3 treats it in detail.
Worked number. A $2048$-bit modulus holds $256$ bytes; Optimal Asymmetric Encryption Padding with SHA-256 leaves $256 - 66 = 190$. So one Rivest-Shamir-Adleman operation carries a $16$-byte Advanced Encryption Standard key, and AES encrypts the gigabytes.
Public-key cryptography makes key distribution possible, at the cost of a computational assumption and a large constant factor in speed; the strength of the encryption is unchanged. Both costs are paid once per session and amortize over every byte of it.
Section 2Modular Arithmetic, and Which Residues Are Invertible
Lecture 5.
The trapdoors of this chapter are built from arithmetic modulo an integer. Division is the operation that fails. The structure of that failure determines the rest of the chapter.
For $n > 0$ and any integer $a$ there are unique $q$ and $r$ with $a = qn + r$ and $0 \le r < n$; write $a \bmod n = r$. Two integers are congruent, $a \equiv b \pmod n$, when $n$ divides $a - b$, equivalently when they leave the same remainder. Congruence is an equivalence relation compatible with addition and multiplication, so the $n$ residue classes form a commutative ring $\Z_n = (\{0, 1, \dots, n-1\}, +, \cdot)$.
An element $a$ has a multiplicative inverse exactly when $\gcd(a, n) = 1$, by Bézout's identity: some $u, v$ satisfy $au + nv = \gcd(a,n)$, and when that gcd is $1$ the identity reduces modulo $n$ to $au \equiv 1$. If $\gcd(a,n) = d > 1$ then every multiple of $a$ is a multiple of $d$ modulo $n$, so $1$ is unreachable.
$\Z_n^{*} = \{a \in \Z_n : \gcd(a,n) = 1\}$ is a finite abelian group under multiplication modulo $n$, of order
$$\varphi(n) = \abs{\Z_n^{*}} = \#\{a < n : \gcd(a,n) = 1\}.$$The totient is multiplicative on coprime arguments, so for distinct primes $p, q$ one has $\varphi(pq) = (p-1)(q-1)$, and $\varphi(p^k) = p^k - p^{k-1}$.
When $n$ is prime every nonzero residue is coprime to it, so $\Z_p$ is a field and $\Z_p^{*} = \{1, \dots, p-1\}$ has order $p-1$. Moreover $\Z_p^{*}$ is cyclic: some $g$ generates it, its successive powers running through every element exactly once. There are $\varphi(p-1)$ such generators. No efficient formula produces one; they are found by testing candidates.
Inverses are computed by the Euclidean algorithm, which rests on $\gcd(a,b) = \gcd(b, a \bmod b)$ for $a \ge b > 0$ and terminates in $O(\log \min(a,b))$ divisions; tracking the quotients while running it yields the Bézout coefficients, and hence the inverse.
For all $a \ge b > 0$ one can compute, in time polynomial in the bit length of $a$, integers $u, v$ with $au + bv = \gcd(a,b)$. Taking $a = 14$, $b = 10$: $14 = 1 \cdot 10 + 4$, $10 = 2 \cdot 4 + 2$, $4 = 2 \cdot 2 + 0$, so $\gcd = 2$, and back-substituting, $2 = 10 - 2 \cdot 4 = 10 - 2(14 - 10) = -2 \cdot 14 + 3 \cdot 10$, giving $(u,v) = (-2, 3)$.
Extended Euclidean Algorithm
The division steps, the back-substitution and both modular inverses when they exist.
Modulo $n$, an element is invertible precisely when it is coprime to $n$. The extended Euclidean algorithm finds the inverse in logarithmic time. RSA key generation calls this one subroutine to turn $e$ into $d$.
Section 3Euler, Fermat and the Arithmetic of Exponents
Lecture 5.
Public-key schemes exponentiate numbers hundreds of digits long. Naive repetition would take exponentially many multiplications and would leave no way to invert exponentiation deliberately. Both problems are solved by the fact that exponents live in a group of known order, and can be reduced.
For every $n > 0$ and every $a \in \Z_n^{*}$,
$$a^{\varphi(n)} \equiv 1 \pmod n.$$This is Lagrange's theorem applied to the finite abelian group $\Z_n^{*}$ of order $\varphi(n)$: the map $x \mapsto ax$ permutes the group. The order of any element divides the order of the group.
For a prime $p$ and any $a$ with $p \nmid a$, $\; a^{p-1} \equiv 1 \pmod p$, and hence $a^{p} \equiv a \pmod p$ for every $a$ without exception.
The practical content is that exponents may be reduced modulo $\varphi(n)$: if $x \equiv y \pmod{\varphi(n)}$ then $a^x \equiv a^y$ for every unit $a$, so a seventy-digit exponent collapses to something smaller than $n$. Equally important, the map $x \mapsto x^{e}$ on $\Z_n^{*}$ can be inverted by anyone who knows $\varphi(n)$: choose $d$ with $ed \equiv 1 \pmod{\varphi(n)}$ and then $(x^{e})^{d} = x^{1 + k\varphi(n)} = x$. That is RSA. The trapdoor is knowledge of $\varphi(n)$; the modulus $n$ alone gives no inverse.
A function that is easy to compute and hard to invert from its output alone, but easy to invert for anyone holding extra trapdoor information. The $e$-th power map $x \mapsto x^{e} \bmod n$ is the running example: inverting it given $n$ alone is believed hard, while knowledge of $\varphi(n)$ supplies the inverse exponent $d$. RSA, ElGamal and the signature schemes below are all built from functions of this kind.
A small example fixes the ideas. $\Z_{10}^{*} = \{1,3,7,9\}$ has order $\varphi(10) = 4$. The element $3$ generates it: $3^{0} \equiv 1$, $3^{1} \equiv 3$, $3^{2} \equiv 9$, $3^{3} \equiv 7$ and $3^{4} \equiv 1$ closes the cycle. The element $7$ also has order $4$; the element $9$ has order $2$. Euler's theorem is visible as the fact that every one of these orders divides $4$.
Exponentiation itself is done by square and multiply: read the exponent in binary, square the running value at every bit position and multiply in the base wherever the bit is $1$. Computing $a^{x} \bmod n$ costs about $\log_2 x$ squarings and at most $\log_2 x$ multiplications on numbers the size of $n$. That is what makes the forward direction cheap; no analogous trick is known for going backwards.
Common mistake. Factoring has been proved hard, which is why RSA is safe. No such proof exists. The belief rests on decades of failed attempts, and breaking RSA is not even proved equivalent to factoring the modulus.
The deck does not state the Chinese remainder theorem, but RSA implementations rely on it and the exercises below use it. For coprime $n_1, n_2$ the map $x \mapsto (x \bmod n_1,\, x \bmod n_2)$ is a ring isomorphism $\Z_{n_1 n_2} \cong \Z_{n_1} \times \Z_{n_2}$. Three consequences matter here. It proves $\varphi$ multiplicative. It lets the holder of $(p,q)$ decrypt by working modulo $p$ and modulo $q$ separately, about four times faster than working modulo $N$. And it shows that $m^{ed} \equiv m \bmod N$ holds for every $m$, including messages that share a factor with the modulus, so RSA never has to check for such a factor.
Exponents live modulo $\varphi(n)$. Knowing $\varphi(n)$ turns the $e$-th power map into a bijection with a computable inverse; not knowing it appears to leave no way in.
Section 4Primality Testing, and the Tests That Lie
Lecture 5.
RSA key generation needs large primes on demand, and nothing about the definition of a prime suggests they can be recognized quickly: trial division takes $\Theta(\sqrt{n})$ steps, exponential in the bit length. Density is settled by the prime number theorem: the number of primes up to $n$ is asymptotically $n / \ln n$, so a random $1024$-bit odd integer is prime with probability roughly $2 / \ln(2^{1024}) \approx 1/355$ and a few hundred candidates suffice. Every integer factors into primes (Euclid) and does so uniquely up to order (Gauss), which is what makes factoring a well-posed target in the first place.
Recognition is settled too. Agrawal, Kayal and Saxena gave a deterministic polynomial-time primality test in 2002. In practice nobody uses it: the randomized tests are far faster. A failure probability of $2^{-128}$ is not a real risk.
To test $n$, pick $a$ at random with $1 < a < n-1$. If $\gcd(a,n) \neq 1$, or if $a^{n-1} \not\equiv 1 \pmod n$, output composite: by Fermat's little theorem no prime behaves this way, so the verdict is certain. Otherwise output probably prime.
The second verdict is where the trouble is. A composite $n$ with $a^{n-1} \equiv 1 \pmod n$ is a Fermat pseudoprime to the base $a$, and $a$ is a Fermat liar; the smallest base-$2$ example is $341 = 11 \cdot 31$. There are infinitely many pseudoprimes for every base, and infinitely many Carmichael numbers, composites for which every base coprime to $n$ is a liar. The smallest is $561 = 3 \cdot 11 \cdot 17$, on which the Fermat test is wrong for all $320$ admissible bases, and repetition cannot help.
The standard repair, and what every library actually implements, is Miller-Rabin. Write $n - 1 = 2^{s} d$ with $d$ odd and compute the chain $a^{d}, a^{2d}, \dots, a^{2^{s-1}d}$. If $n$ is prime the chain must either start at $1$ or pass through $-1$, because in the field $\Z_p$ the only square roots of $1$ are $\pm 1$. A chain that arrives at $1$ without passing through $-1$ exhibits a nontrivial square root of $1$, which no prime has, and whose gcd with $n$ is a proper factor. For every odd composite, at most a quarter of the bases are strong liars, so $t$ independent rounds err with probability at most $4^{-t}$, uniformly over inputs. Carmichael numbers have no special power against it.
Fermat Versus Miller-Rabin
Both tests on the same bases, side by side. Try $561$ (a Carmichael number, where every base is a Fermat liar), then $341$, $2047$ and a genuine prime.
The Fermat test has inputs on which it is wrong for every base, so its error probability cannot be driven down by repetition. Miller-Rabin's quarter-of-all-bases bound holds for every composite, which is why Miller-Rabin generates RSA primes and the Fermat test cannot.
Section 5Factoring and Discrete Logarithms
Lecture 5.
Two problems carry almost all of classical public-key cryptography. Neither is proved hard. Their conjectured hardness is what every scheme in this chapter is priced against.
Integer factoring. Given $N = p \cdot q$ for primes of comparable size, find $p$ and $q$. Trial division up to $\sqrt{N}$ costs about $\sqrt{N}/\ln \sqrt{N}$ divisions, exponential in $\log N$. The better algorithms are all sub-exponential: Pollard's rho and $p-1$ methods, the quadratic sieve and the general number field sieve, whose heuristic running time is $\exp\big(O((\log N)^{1/3}(\log\log N)^{2/3})\big)$. The RSA factoring challenges calibrate this: RSA-768, a $232$-digit modulus, was factored in 2009 after roughly two years of computation spread over a large network of machines. Current moduli are $2048$ or $3072$ bits; $768$-bit moduli are obsolete.
Worked number. In February 2020 Boudot, Gaudry, Guillevic, Heninger, Thomé and Zimmermann factored RSA-250, an $829$-bit modulus, at a cost of about $2700$ core-years. $1024$-bit RSA sits near end of life; $2048$-bit stays out of classical reach.
Discrete logarithm. Let $p$ be prime and $g$ a generator of $\Z_p^{*}$, so every $y \in \Z_p^{*}$ equals $g^{x}$ for some $x \in \{0, \dots, p-2\}$. Given $(p, g, y)$, find $x$. Forward evaluation costs $O(\log x)$ multiplications by square and multiply; the best known inversion is again sub-exponential, by index calculus. Generic algorithms that treat the group as a black box (Shanks's baby-step giant-step, Pollard's rho) cost $\Theta(\sqrt{q})$ in a group of order $q$, the bound elliptic curves live at.
For a group generator producing $(\mathbb{G}, q, g)$ with $\abs{\mathbb{G}} = q$, the DL problem is hard if for every probabilistic polynomial-time $\Adv$
$$\Pr\big[x \getsr \Z_q,\; \Adv(\mathbb{G}, q, g, g^{x}) = x\big] \le \negl(\log q).$$Equivalently, $x \mapsto g^{x}$ is a one-way function. It is in fact a one-way permutation of the exponent space, which is rarer and occasionally useful.
The animation below plots the orbit of a generator. The forward map is fast and structurally simple, while the inverse has no exploitable structure: the values do not increase, do not cluster and do not approach the target as the exponent approaches the answer, so a hill-climbing search has no information to guide it.
Common mistake. A $2048$-bit RSA key gives $2048$ bits of security. The general number field sieve factors far faster than brute force: the National Institute of Standards and Technology rates $2048$-bit RSA at about $112$ bits, like a $112$-bit symmetric key.
The best known algorithms for factoring and discrete logarithm are sub-exponential, and polynomial algorithms are unknown for both; both problems are only conjecturally hard. Key sizes are chosen so that the best known algorithm costs more than $2^{128}$ operations, which is why RSA needs $3072$ bits where a symmetric key needs $128$.
Section 6Public-Key Encryption and Its Security Definitions
Lecture 6.
The security definition comes before the constructions. RSA and ElGamal are later measured against it. A definition that only forbids recovering the whole message is too weak to be useful, since a scheme that leaks all but the last bit would satisfy it. The history of public-key encryption is largely a history of schemes that met a weak definition and fell to an attack outside it.
A triple of algorithms $(\mathsf{Gen}, \Enc, \Dec)$ where $\mathsf{Gen}(1^{\lambda})$ outputs a key pair $(\mathit{pk}, \mathit{sk})$, $\Enc(\mathit{pk}, m)$ is randomized and outputs a ciphertext $c$ and $\Dec(\mathit{sk}, c)$ outputs a message. Correctness requires $\Dec(\mathit{sk}, \Enc(\mathit{pk}, m)) = m$ for all $m$ in the message space and all key pairs. It must be infeasible to compute $\mathit{sk}$ from $\mathit{pk}$. That is a necessary condition, never a sufficient one.
The game between $\Adv$ and a challenger:
- The challenger runs $(\mathit{pk}, \mathit{sk}) \gets \mathsf{Gen}(1^{\lambda})$ and sends $\mathit{pk}$ to $\Adv$.
- $\Adv$ outputs two messages $m_0, m_1$ of equal length.
- The challenger draws $b \getsr \bits$ and returns $c \gets \Enc(\mathit{pk}, m_b)$.
- $\Adv$ outputs $b'$ and wins if $b' = b$.
The scheme is CPA secure if for every probabilistic polynomial-time $\Adv$,
$$\Big| \Pr[b' = b] - \tfrac{1}{2} \Big| \le \negl(\lambda).$$No encryption oracle appears in the game because none is needed: $\Adv$ holds $\mathit{pk}$ and can encrypt anything it likes. This is the structural difference from the symmetric setting. It has a sharp consequence: a deterministic public-key scheme can never be CPA secure, since $\Adv$ encrypts $m_0$ itself and compares.
As above, with $\Adv$ additionally given oracle access to $\Dec(\mathit{sk}, \cdot)$ both before and after receiving the challenge, subject only to the restriction that it may not query the challenge ciphertext $c$ itself. Restricting the queries to the pre-challenge phase gives the weaker notion CCA1; allowing them afterwards as well gives CCA2, which is what "CCA secure" means without qualification.
The one forbidden query is the subtle part. If $\Adv$ can transform $c$ into some related $c' \neq c$ whose decryption reveals something about $m$, the restriction is vacuous and the scheme falls, so CCA security is in effect a non-malleability requirement. It is also the notion that matches practice, because real receivers decrypt attacker-chosen ciphertexts all day and their behavior (even just an error message) is an oracle.
What went wrong. In 1998 Bleichenbacher read Secure Sockets Layer sessions through one signal: whether decrypted padding was valid. About a million chosen ciphertexts sufficed. Padding checks must stay silent and uniform; Optimal Asymmetric Encryption Padding removes the oracle entirely.
In the public-key setting the adversary encrypts for free. Randomized encryption is therefore a requirement, and CCA security is the notion that models real receivers, which decrypt attacker-chosen ciphertexts.
Section 7Textbook RSA, and Why It Is Broken
Lecture 6.
RSA in its bare form instantiates the $e$-th power map of section 3. It is correct, it is efficient and it fails every security definition of section 6, which makes it the most instructive broken scheme in the subject.
Sample distinct primes $p, q$ of $\lambda/2$ bits each and set $N = pq$ and $\varphi(N) = (p-1)(q-1)$. Choose $e$ with $\gcd(e, \varphi(N)) = 1$ and compute $d = e^{-1} \bmod \varphi(N)$ by the extended Euclidean algorithm. Then
$$\mathit{pk} = (N, e), \qquad \mathit{sk} = (d, p, q),$$ $$\Enc(\mathit{pk}, m) = m^{e} \bmod N, \qquad \Dec(\mathit{sk}, c) = c^{d} \bmod N.$$Correctness: $ed = 1 + k\varphi(N)$, so $c^{d} \equiv m^{ed} \equiv m \cdot (m^{\varphi(N)})^{k} \equiv m \pmod N$ by Euler's theorem. The Chinese remainder theorem extends the identity from $\Z_N^{*}$ to all of $\Z_N$.
A worked example with small numbers. Take $p = 61$ and $q = 53$, so $N = 3233$ and $\varphi(N) = 60 \cdot 52 = 3120$, and choose $e = 17$, coprime to $3120$. The extended Euclidean algorithm gives $e^{-1} \bmod 3120 = 2753$, and reducing it modulo $\mathrm{lcm}(60, 52) = 780$ yields the smaller equivalent exponent $d = 413$, valid because $780$ is a multiple of both $60$ and $52$, so Fermat's little theorem modulo each prime gives $m^{780} \equiv 1$ for every $m$ coprime to $N$. Encrypting $m = 65$ gives $c = 65^{17} \bmod 3233 = 2790$. Decrypting gives $2790^{413} \bmod 3233 = 65$.
Messages must first be encoded as integers in $\Z_N$. The encoding is a real design task. Exponentiation uses square and multiply. Decryption is usually done modulo $p$ and $q$ separately, recombining by CRT. A small public exponent ($e = 3$ or $e = 65537$) makes encryption and verification fast and public keys compact, at the cost of two constraints: $e$ must stay coprime to $\varphi(N)$, which slightly complicates prime generation, and short messages become dangerous.
Common mistake. RSA encrypts your message directly. One padded Rivest-Shamir-Adleman operation fits under $190$ bytes, so real systems encrypt a random Advanced Encryption Standard key with Optimal Asymmetric Encryption Padding and let AES carry the actual data.
- Determinism breaks CPA security outright. $\Enc$ is a function of $m$ alone, so given the challenge $c$ the adversary computes $m_0^{e} \bmod N$ and compares. When the plaintext space is small or predictable (a vote, a price, a credit card number) the same observation is a dictionary attack, no algebra required.
- Multiplicativity breaks CCA security. $(m_1 m_2)^{e} \equiv m_1^{e} m_2^{e}$, so ciphertexts multiply: given the challenge $c$ for an unknown $m$, pick any $r$, submit $c' = c \cdot r^{e} \bmod N$ to the decryption oracle, receive $rm \bmod N$ and divide by $r$. One query suffices, and $c' \neq c$ makes it legal.
- Low exponents break small messages. If $e = 3$ and $m < N^{1/3}$ then $m^{3} < N$, so no reduction happens at all and $c$ is the plain integer cube of $m$; an integer cube root recovers $m$ with no key material. This is why padding pushes the encoded value up into the top of the modulus.
What went wrong. Håstad showed in 1985 that one message sent as textbook RSA to three recipients with $e = 3$ is recoverable through the Chinese remainder theorem, with no key material. Randomized padding makes the three ciphertexts unrelated and destroys the attack.
RSA End to End, with the Malleability Attack Attached
Choose the primes and watch $N$, $\varphi(N)$, a valid $e$ and the
computed $d$ follow. Everything runs on BigInt, so the arithmetic is
exact. The last block performs the attack: Eve multiplies the ciphertext by
$r^{e}$ and the plaintext is multiplied by $r$.
Textbook RSA is a correct trapdoor permutation, yet it fails as an encryption scheme. Determinism costs CPA security, multiplicativity costs CCA security and neither failure depends on the modulus being small.
Section 8The RSA Assumption, and RSA with Padding
Lecture 6.
The attacks of section 7 all target the scheme. The underlying hardness remains intact. Separating the two is what lets the scheme be repaired.
Given $N = pq$ with $p, q$ random primes of the appropriate size, an exponent $e$ coprime to $\varphi(N)$ and $y = x^{e} \bmod N$ for $x \getsr \Z_N^{*}$, it is infeasible to compute $x$. Equivalently, extracting $e$-th roots modulo a composite of unknown factorization is hard.
Factoring breaks RSA: from $p$ and $q$ one computes $\varphi(N) = (p-1)(q-1)$ and hence $d$, so the RSA assumption is at least as strong as the factoring assumption. The converse is not known, since computing $e$-th roots might conceivably be easier than factoring. No approach to RSA has ever beaten factoring the modulus, so in practice the two are priced identically. Knowledge of $d$, incidentally, does yield the factorization, even though the reduction runs only one way.
The repair is randomized padding. Encrypting $r \| m$ for fresh random $r$ destroys determinism immediately: the same message now has exponentially many ciphertexts, and decryption simply discards $r$. It also disrupts the multiplicative structure, because a ciphertext that Eve multiplies decrypts to something whose padding is malformed with overwhelming probability. The receiver rejects it.
For a $k$-byte modulus, the integer that gets exponentiated is the byte string
$$\texttt{0x00} \;\|\; \texttt{0x02} \;\|\; r \;\|\; \texttt{0x00} \;\|\; m,$$where $r$ is at least eight nonzero random bytes and the block is exactly $k$ bytes long. The leading zero byte guarantees the encoded integer is smaller than $N$; the $\texttt{0x02}$ identifies the block type as encryption and, together with the padding length, forces a genuine modular reduction so that no small-message cube-root attack applies. The zero byte before $m$ delimits the padding, since $r$ contains no zero bytes.
PKCS #1 v1.5 is a heuristic, and in 1998 Bleichenbacher broke it with a chosen-ciphertext attack that uses only the receiver's willingness to say whether a decrypted block had valid padding; about a million such queries recover the plaintext. The response was OAEP (Optimal Asymmetric Encryption Padding), which pads through a two-round Feistel network built from hash functions and is provably CCA secure in the random oracle model under the RSA assumption. The random oracle model idealizes the hash as a uniformly random function that every party can query; a proof there guides the design, and any concrete hash substituted for the oracle must still be analyzed on its own. OAEP addresses all three failures of section 7. The fresh randomness removes determinism. The Feistel mixing destroys the multiplicative structure. The padded block sits near the top of the modulus, so no small-message cube root exists. The deck stops at PKCS #1; the lesson is that randomness guides the design, and only a proof certifies security.
What went wrong. In 2012 Heninger, Durumeric, Wustrow and Halderman factored about $0.5$ percent of the Rivest-Shamir-Adleman keys then securing Hypertext Transfer Protocol Secure servers by taking greatest common divisors of moduli that shared a prime. Weak randomness on one device endangers another.
The RSA assumption survives the attacks on textbook RSA, because those attacks exploit the encoding and leave the trapdoor intact. Randomized padding turns a trapdoor permutation into an encryption scheme, and only a padding with a proof delivers CCA security; OAEP has such a proof, and PKCS #1 v1.5 does not.
Section 9ElGamal, and the Diffie-Hellman Assumptions
Lecture 6.
RSA needs an encoding scheme to introduce randomness. ElGamal is randomized by construction: every encryption carries a fresh exponent from the discrete-logarithm group.
Let $g$ generate a group $\mathbb{G}$ of prime order $q$ (in the slides, $\Z_p^{*}$). Draw $x \getsr \Z_q$ and set $h = g^{x}$. Then $\mathit{pk} = (\mathbb{G}, g, h)$ and $\mathit{sk} = x$. To encrypt $m \in \mathbb{G}$, draw a fresh $r \getsr \Z_q$ and output
$$c = (c_1, c_2) = (g^{r},\; h^{r} \cdot m).$$To decrypt, compute $c_2 / c_1^{x}$. Correctness:
$$\frac{c_2}{c_1^{x}} = \frac{h^{r} m}{(g^{r})^{x}} = \frac{g^{xr} m}{g^{rx}} = m.$$The ciphertext is twice the length of the plaintext. The scheme is multiplicatively homomorphic: $(c_1 c_1', c_2 c_2')$ encrypts $m m'$. That is useful in some protocols and fatal to CCA security in all of them.
ElGamal is CPA secure. The assumption it needs is the statement that the mask $h^{r}$ looks random.
Computational Diffie-Hellman. Given $(\mathbb{G}, g, g^{a}, g^{b})$ for $a, b \getsr \Z_q$, compute $g^{ab}$.
Decisional Diffie-Hellman. Distinguish $(g, g^{a}, g^{b}, g^{ab})$ from $(g, g^{a}, g^{b}, g^{z})$ for $a, b, z \getsr \Z_q$.
The implications run $\text{DDH} \Rightarrow \text{CDH} \Rightarrow \text{DL}$: an algorithm for the easier problem breaks the harder assumption. Solving The Discrete Logarithm (DL) yields $a$ and hence $g^{ab} = (g^{b})^{a}$, so CDH is no harder than DL; solving CDH yields $g^{ab}$, which can then be compared against the challenge, so DDH is no harder than CDH. Neither converse is known.
The last implication is strict. In $\Z_p^{*}$ with $g$ a generator, $g^{a}$ is a quadratic residue exactly when $a$ is even. The Legendre symbol $g^{a} \mapsto (g^{a})^{(p-1)/2}$ computes that in one exponentiation, so an adversary learns the parity of $a$, of $b$ and of the exponent in the fourth component. When $a$ and $b$ are both odd, $ab$ is odd, whereas a uniform $z$ is even half the time, giving a distinguisher with advantage $1/4$. The fix is the one the deck states: take $p = 2q + 1$ with $q$ prime and work in the subgroup $\mathbb{G} = \{y^{2} : y \in \Z_p^{*}\}$ of squares, which has prime order $q$. A group of prime order has no proper subgroups, so no analogous partial information survives, and DDH is believed to hold there.
CDH is what a key exchange needs to be unpredictable, while DDH is what it needs for the shared value to be usable directly as a key. Chapter 3 returns to the protocol; here the assumption is the point.
What went wrong. Logjam (2015) broke $512$-bit export Diffie-Hellman in about a minute per connection after one nation-scale precomputation, and common $1024$-bit groups look within reach of the same method. Use $2048$-bit or elliptic-curve groups.
Diffie-Hellman and ElGamal in a Small Group
Set the prime, the generator and the exponents; both parties' routes to the shared value are shown, then an ElGamal encryption under $h = g^{b}$. The last block computes the Legendre symbol that makes DDH false in $\Z_p^{*}$.
ElGamal is randomized by construction and CPA secure under DDH. The assumption must be stated in the right group: in $\Z_p^{*}$ it is simply false, so the standard cure is a prime-order subgroup.
Section 10Elliptic Curves and Bilinear Pairings
Lecture 6.
Nothing in section 9 mentioned $\Z_p^{*}$ except by way of example. ElGamal, and the Diffie-Hellman assumptions with it, need only a cyclic group of known prime order in which exponentiation is cheap. Choosing a different group changes the security per bit dramatically, because index calculus, the sub-exponential attack on discrete logarithms, depends on the arithmetic of the integers and does not transfer.
For a prime $p > 3$ and $a, b \in \Z_p$ with $4a^{3} + 27b^{2} \neq 0$, let
$$E(\Z_p) = \{(X, Y) \in \Z_p^{2} : Y^{2} = X^{3} + aX + b\} \cup \{\mathcal{O}\}.$$These points form an abelian group under the chord-and-tangent law, with the point at infinity $\mathcal{O}$ as identity. Hasse's theorem bounds the order: $\abs{\#E(\Z_p) - (p+1)} \le 2\sqrt{p}$.
The group law is geometric before it is algebraic. To add $P$ and $Q$, draw the line through them, take its third intersection with the curve and reflect that point in the $X$-axis; $-P$ is the reflection of $P$, and adding $P$ to itself uses the tangent at $P$ in place of the chord. The group is written additively, so exponentiation becomes scalar multiplication, computed by double-and-add: read the scalar $x$ in binary, doubling the running point at each bit and adding $P$ where the bit is $1$, for about $\log_2 x$ doublings. The discrete-logarithm problem reads: given $P$ and $Q = xP$, find $x$.
On a well-chosen curve the best known attacks are the generic ones. Pollard's rho needs $\Theta(\sqrt{q})$ steps in a group of order $q$, so the field size must be twice the security parameter: a $256$-bit curve delivers roughly $128$ bits of security, matching a $3072$-bit RSA public key. Whether Decisional Diffie-Hellman (DDH) holds depends on the chosen group. That ratio is why elliptic curves dominate deployed key exchange and signatures.
Worked number. Security estimates match across schemes: $1024$-bit RSA or Diffie-Hellman gives about $80$ bits, $2048$-bit about $112$ and $3072$-bit about $128$. A $256$-bit elliptic-curve key already reaches $128$ bits.
Some curves carry additional structure: a pairing, a map into a second group that turns the multiplication of exponents into an operation one can actually perform.
Groups $\mathbb{G}, \mathbb{G}_T$ of prime order $q$ with $g$ generating $\mathbb{G}$, together with an efficiently computable $e : \mathbb{G} \times \mathbb{G} \to \mathbb{G}_T$ that is
- bilinear: $e(g^{a}, g^{b}) = e(g,g)^{ab}$ for all $a, b \in \Z_q$;
- non-degenerate: $e(g,g) \neq 1$, so $e(g,g)$ generates $\mathbb{G}_T$.
Concretely these come from the Weil and Tate pairings on curves of small embedding degree, with $\mathbb{G}_T$ a subgroup of the multiplicative group of an extension field. The version above is symmetric, or type 1; asymmetric pairings take $e : \mathbb{G}_1 \times \mathbb{G}_2 \to \mathbb{G}_T$ with no efficient map between the source groups.
Bilinearity is immediately destructive and immediately constructive. Destructive: DDH is easy in $\mathbb{G}$, since a candidate $Z$ satisfies $Z = g^{ab}$ if and only if $e(g^{a}, g^{b}) = e(g, Z)$, a check anyone can perform. Any protocol whose proof invokes DDH in $\mathbb{G}$ is void on a pairing-friendly curve.
BCDH. Given $(\mathbb{G}, q, g, e, g^{x}, g^{y}, g^{z})$ for random $x, y, z$, compute $e(g,g)^{xyz}$. This is believed hard, and BCDH implies Computational Diffie-Hellman (CDH), since a CDH solver produces $g^{xy}$, whence $e(g^{xy}, g^{z})$; the converse is unknown.
Symmetric External Diffie-Hellman (SXDH). One may additionally assume DDH holds in each of $\mathbb{G}_1$ and $\mathbb{G}_2$ in the asymmetric setting, since no further pairing maps out of the target group.
Constructive: bilinearity lets two exponents that were never in the same place be multiplied. That is what section 13 uses to build identity-based encryption. It is also behind short signatures, three-party one-round key agreement and much of the succinct-proof literature.
Elliptic curves achieve a much better security-to-key-size ratio because index calculus does not apply to them. Pairings add an extra algebraic operation, at the cost of DDH in the source group; the surviving assumption is the computational one, BCDH.
Section 11Digital Signatures and Unforgeability
Lecture 6.
Encryption protects a message from being read; nothing so far stops an attacker from writing one. The two properties are separate. A signature does not encrypt anything, and public-key encryption does not identify the sender, so deployments that need both must combine them. In the symmetric setting a Message Authentication Code (MAC) authenticates. It requires a shared key and its verdict is meaningful only to the two key holders, since either party could have produced any tag. A signature is the public-key analogue, with a property no MAC has: anyone can verify, and only one party could have signed.
Algorithms $(\mathsf{Gen}, \mathbf{S}, \mathbf{V})$ where $\mathsf{Gen}$ outputs $(\mathit{pk}, \mathit{sk})$, $\mathbf{S}(\mathit{sk}, m)$ outputs $\sigma$ and $\mathbf{V}(\mathit{pk}, (m, \sigma)) \in \{0,1\}$. Correctness: $\mathbf{V}(\mathit{pk}, (m, \mathbf{S}(\mathit{sk}, m))) = 1$ for every key pair and every message.
$\Adv$ receives $\mathit{pk}$ and may query a signing oracle $\mathbf{S}(\mathit{sk}, \cdot)$ on messages of its choice, collecting a set $Q$ of queried messages. It then outputs a pair $(m, \sigma)$ and wins if $\mathbf{V}(\mathit{pk}, (m, \sigma)) = 1$ and $m \notin Q$. The scheme is secure if every probabilistic polynomial-time $\Adv$ wins with probability $\negl(\lambda)$.
Freshness of $m$ is what makes the definition non-trivial: re-presenting a signature the oracle produced is not an attack. Strong unforgeability additionally forbids a new signature $\sigma' \neq \sigma$ on an already queried $m$.
RSA suggests an immediate construction: run the trapdoor backwards. With $\mathit{pk} = (N, e)$ and $\mathit{sk} = (d, p, q)$, sign as $\sigma = m^{d} \bmod N$ and verify by checking $\sigma^{e} \equiv m$. Correctness is Euler's theorem again. Security is absent.
- An existential forgery needs no queries at all. Pick any $\sigma \in \Z_N^{*}$ and set $m = \sigma^{e} \bmod N$; then $(m, \sigma)$ verifies by construction. The forger does not choose $m$. The definition does not require that, since a signature on a message nobody intended is already a break.
- A selective forgery needs two queries, because signing is multiplicative: $\mathbf{S}(m_1 m_2) = (m_1 m_2)^{d} = m_1^{d} m_2^{d}$. To forge on a target $m$, write $m = m_1 m_2 \bmod N$ for any nontrivial split, query both factors and multiply the results. The target itself was never queried, so the forgery is valid.
Let $\Hash$ be a hash function mapping messages onto $\Z_N^{*}$. Sign $\sigma = \Hash(m)^{d} \bmod N$ and verify $\sigma^{e} \equiv \Hash(m)$.
The hash blocks both forgeries. Each block uses a different hash property. The existential forgery now requires, from a chosen $\sigma$, a preimage $m$ with $\Hash(m) = \sigma^{e}$, blocked by one-wayness. Transferring a legitimate signature $\sigma$ from $m$ to another message requires an $m' \neq m$ with $\Hash(m') = \Hash(m)$, blocked by second-preimage resistance. Inducing a signer to sign a benign $m$ whose signature also verifies on a malicious $m'$ requires finding such a pair in advance, blocked by collision resistance, which is why the birthday bound sets the required digest length. The multiplicative attack fails because $\Hash(m_1 m_2) \neq \Hash(m_1)\Hash(m_2)$. RSA-FDH is provably unforgeable under the RSA assumption in the random oracle model. The deployed variant is RSA-PSS (Probabilistic Signature Scheme), which pads the hash with fresh randomness before signing.
Signature schemes that use randomness need it to be fresh on every call. The Elliptic Curve Digital Signature Algorithm (ECDSA) signs each message with a secret per-message nonce, and if the same nonce is ever used twice, the two signatures together determine the private key. Sony's PlayStation 3 firmware signing used one fixed nonce for every signature, so the signing key was recovered from published signatures. The arithmetic is only half the design; the randomness is the other half.
A trapdoor permutation used raw as a signature scheme is forgeable without any queries, because the forger works backwards from the signature. Hashing first is the security argument itself. Each of the three attacks it blocks corresponds to a different property of the hash.
Section 12Public-Key Infrastructures
Lecture 6.
Everything so far assumes the reader of a public key knows whose it is. Drop that assumption and every construction above is exposed to a man-in-the-middle attack, which runs as follows:
| Step | What Eve does | What Alice and Bob see |
|---|---|---|
| 1 | Intercepts Bob's public key in transit and hands Alice her own key instead. | Alice accepts the key as Bob's. |
| 2 | Decrypts Alice's ciphertext with her private key. | Alice believes she is encrypting to Bob. |
| 3 | Re-encrypts the plaintext under Bob's real key and forwards it. | Bob decrypts normally. |
| 4 | Repeats in both directions for every message. | Both parties see correct plaintext and nothing alerts them. |
Public keys have no need of confidentiality, but authenticity is essential, and supplying it is a separate problem from any of the mathematics above.
Common mistake. Diffie-Hellman key exchange authenticates the two parties. Classic Diffie-Hellman is anonymous key agreement: each side must add signatures or certificates, since otherwise an attacker runs one exchange with Alice, another with Bob and reads both sides.
The standard answer is to sign the binding. A certification authority holds a signing key pair, verifies out of band that a public key belongs to a named party and issues
$$\mathrm{Cert}_{\mathrm{CA} \to A} \gets \mathbf{S}\big(\mathit{sk}_{\mathrm{CA}},\; \mathit{pk}_{A} \,\|\, \text{“Alice”}\big).$$
Anyone holding $\mathit{pk}_{\mathrm{CA}}$ can verify the binding, and Alice's certificate can travel with her key over any channel at all. The trust problem has been reduced from $n$ authentic keys to one. The format of these objects is standardized by the ITU (International Telecommunication Union) as X.509, carrying
- the subject and issuer names;
- the subject's public key and its algorithm;
- a validity interval and a serial number;
- extensions, and the CA's signature over all of the above.
Relying on one CA creates a single point of failure because its compromise makes every binding it issued suspect. Practice therefore uses chains. A root CA certifies intermediate CAs, which certify end entities. A verifier walks the chain from a locally trusted root down to the certificate in hand, checking each signature in turn. Trust propagates along the chain, so a user may belong to several distinct infrastructures at once, linked by cross-certification. What the binding asserts varies, and is often a domain name and nothing more, with the user name retained only for management and auditing.
Certificates must also expire and be revoked, and revocation is the part of PKI that works least well in practice. Every certificate carries a validity interval, so a verifier must check the current time. Choosing the lifetime is a tradeoff, since short lifetimes mean constant reissuance, while long ones widen the window after a key is stolen. Revocation before expiry needs the serial number, which is distinct per certificate; the CA publishes a certificate revocation list naming those withdrawn, and verifiers must fetch it, which means the CA has to stay reachable. CRLs have largely given way to The Online Certificate Status Protocol (OCSP) and to short-lived certificates for this reason.
The alternative to hierarchy is a web of trust, as used by PGP (Pretty Good Privacy). Users sign each other's keys directly. A verifier accepts a key if it is reachable by a sufficiently short chain of signatures from someone already trusted. No trusted party is required; the costs are that trust decisions fall on individual users, that revocation is even harder and that the graph must be connected for a stranger's key to be verifiable at all.
Public keys need integrity. A signature supplies it; secrecy is not a requirement. A PKI concentrates trust into a small number of roots and makes every other binding verifiable, at the price of expiry, revocation and an authority that must stay reachable.
Section 13Identity-Based Encryption
Lecture 6.
A Public-Key Infrastructure (PKI) exists because a public key is a meaningless string that has to be bound to a
name. Shamir asked in 1984 whether the name could simply be the key, so
that anyone could encrypt to bob@example.com with no certificate, no
lookup and no prior interaction with Bob. He proposed the notion and could not build
it; the first realization came from Boneh and Franklin in 2001, using pairings.
Four algorithms. $\mathsf{Setup}(1^{\lambda})$ outputs public parameters $\mathit{params}$ and a master secret key $\mathit{msk}$. $\mathsf{Extract}$ takes $(\mathit{msk}, \mathit{ID})$ and outputs the private key $\mathit{sk}_{\mathit{ID}}$. Encryption takes $(\mathit{params}, \mathit{ID}, m)$; decryption takes $(\mathit{sk}_{\mathit{ID}}, c)$. The party running $\mathsf{Setup}$ and $\mathsf{Extract}$ is the key generation center.
$\Adv$ receives $\mathit{params}$ and may query $\mathsf{Extract}$ on any identity $\mathit{ID}'$ of its choice. It then outputs $m_0, m_1$ and a challenge identity $\mathit{ID}$, and receives $c \gets \Enc(\mathit{ID}, m_b)$ for $b \getsr \bits$. Extraction queries may continue afterwards. $\Adv$ wins if $b' = b$, subject to the one restriction that it never requests $\mathit{sk}_{\mathit{ID}}$ for the challenge identity. Security requires advantage $\negl(\lambda)$ even though $\Adv$ holds the private keys of every other identity in the system.
That last clause is what makes the definition demanding. The keys of all other identities must be useless against the challenge one, so they cannot be derived from each other in any recoverable way.
Let $(\mathbb{G}, \mathbb{G}_T, e, g)$ be a bilinear group of prime order $q$, with hash functions $\Hash_1$ mapping identities into $\mathbb{G}$ and $\Hash_2$ mapping $\mathbb{G}_T$ onto message-length bit strings.
- Setup. Draw $x \getsr \Z_q$; set $\mathit{msk} = x$ and publish $\mathit{params} = (g, h = g^{x})$.
- Extract. $d_{\mathit{ID}} = \Hash_1(\mathit{ID})^{x}$.
- Encrypt. Compute $y_{\mathit{ID}} = e(\Hash_1(\mathit{ID}), h)$, draw $r \getsr \Z_q$ and output $c = (u, v) = \big(g^{r},\; m \oplus \Hash_2(y_{\mathit{ID}}^{\,r})\big)$.
- Decrypt. Output $v \oplus \Hash_2\big(e(d_{\mathit{ID}}, u)\big)$.
Correctness is one application of bilinearity:
$$e(d_{\mathit{ID}}, u) = e\big(\Hash_1(\mathit{ID})^{x},\, g^{r}\big) = e\big(\Hash_1(\mathit{ID}),\, g\big)^{xr} = e\big(\Hash_1(\mathit{ID}),\, g^{x}\big)^{r} = y_{\mathit{ID}}^{\,r}.$$Alice reaches the mask from the public $h = g^{x}$ and her own $r$; Bob reaches the same value from his private $d_{\mathit{ID}}$ and the public $u = g^{r}$. Neither has the other's secret. Security holds under The Bilinear Computational Diffie-Hellman Assumption (BCDH) in the random oracle model.
The tradeoffs against a PKI fall on both sides. In favor:
- no certificates and no directory lookup;
- Alice can encrypt to a party who has not yet enrolled.
Against:
- The KGC knows every private key, so key escrow is inherent to the design. Escrow is an advantage in a corporation that must read its own mail, and a disqualification almost everywhere else. The KGC is correspondingly the highest-value target in the system, mitigable by splitting the master key across several authorities with threshold techniques.
- Keys cannot be revoked, because the identity cannot be changed. The standard workaround is to encrypt to an identity concatenated with a time period, so keys expire by construction and must be reissued.
- Extraction needs a secure authenticated channel from KGC to user, the same kind of secure channel whose absence motivated public-key cryptography in the first place.
IBE removes certificates, while its identity-derived keys require time periods or another mechanism for revocation. The key generation center also knows every private key. Whether those tradeoffs help depends on the deployment. Chapter 4 builds IBE again from lattices, without pairings.
Section 14Further Resources
Free books and sites that cover this chapter's material in depth.
- The Joy of Cryptography (Rosulek). Definitions before constructions, with public-key encryption, RSA and signatures in the same game-based style as this page.
- A Graduate Course in Applied Cryptography (Boneh and Shoup). Free PDF covering Public-Key Encryption (PKE), Chosen-Ciphertext Attack (CCA) security, signatures, Elliptic Curve Cryptography (ECC) and pairings.
- Crypto 101. An attack-first treatment of public-key encryption, key agreement and signatures.
- Practical Cryptography for Developers (Nakov). RSA, Secp256k1, Curve25519 (ECC), ECDSA (Elliptic Curve Digital Signature Algorithm) and EdDSA (Edwards-curve Digital Signature Algorithm), and ECIES (Elliptic Curve Integrated Encryption Scheme) hybrid encryption, with code.
- Elliptic Curve Cryptography: a gentle introduction (Corbellini). The best visual path into ECC, with interactive widgets for the group law.
- SafeCurves (Bernstein and Lange). Criteria and a scorecard for choosing safe elliptic curves.
- Wikipedia: RSA cryptosystem. A fully worked small-number example and the attacks on plain RSA.
- CrypTool-Online. Browser apps that step through RSA key generation, encryption and signing.
Further reading:
- Katz and Lindell (2015), Introduction to Modern Cryptography
- Kościelny, Kurkowski and Srebrny (2013), Modern Cryptography Primer
- Forney, Introduction to Finite Fields, background for the algebra of sections 2 and 3.
Section 15Exercises
Mechanical drills first, then the attacks, then two tied to the exam projects. The answers are worked out in full. The arithmetic in them has been checked against the labs on this page.
Let $p = 11$ and $q = 17$, and take $e = 7$. Compute $\varphi(N)$ and the private exponent $d$, showing the extended Euclidean algorithm. Drill
$N = 11 \cdot 17 = 187$ and $\varphi(N) = 10 \cdot 16 = 160$. Since $\gcd(7, 160) = 1$, the exponent $e = 7$ is admissible. Euclid on $(160, 7)$:
$$160 = 22 \cdot 7 + 6, \qquad 7 = 1 \cdot 6 + 1, \qquad 6 = 6 \cdot 1 + 0,$$so $\gcd = 1$. Back-substituting,
$$1 = 7 - 1 \cdot 6 = 7 - (160 - 22 \cdot 7) = 23 \cdot 7 - 1 \cdot 160,$$giving $(u, v) = (23, -1)$ and hence $d = 23$. Check: $7 \cdot 23 = 161 = 160 + 1 \equiv 1 \pmod{160}$. As a sanity test on the whole key, $5^{7} \bmod 187 = 146$ and $146^{23} \bmod 187 = 5$.
Compute $5^{2024} \bmod 13$ without a calculator, and state which theorem does the work. Drill
$13$ is prime and $13 \nmid 5$, so Fermat's little theorem gives $5^{12} \equiv 1 \pmod{13}$ and exponents may be reduced modulo $12$. Since $2024 = 168 \cdot 12 + 8$, the problem reduces to $5^{8} \bmod 13$. Now $5^{2} = 25 \equiv -1$, so $5^{4} \equiv 1$ and $5^{8} \equiv 1$. Hence $5^{2024} \equiv 1 \pmod{13}$.
The reduction is the substance of the solution. The multiplicative order of $5$ modulo $13$ is $4$, which divides $\varphi(13) = 12$ as Lagrange's theorem requires.
Break textbook RSA in the CCA game with a single decryption query. Attack
Let $\mathit{pk} = (N, e)$ and let $c = m^{e} \bmod N$ be the challenge for an unknown $m$. Pick any $r$ with $\gcd(r, N) = 1$ and $r \not\equiv 1$, and set
$$c' = c \cdot r^{e} \bmod N.$$Then $c' \neq c$, so the query is permitted, and $c' = m^{e} r^{e} = (mr)^{e}$, so the oracle returns $m' = mr \bmod N$. Output $m = m' \cdot r^{-1} \bmod N$, computing $r^{-1}$ with the extended Euclidean algorithm. The advantage is $1/2$: knowing $m$ exactly, the adversary answers the indistinguishability challenge with certainty.
Concretely with $N = 55$, $e = 3$, $d = 27$: for $m = 7$ the ciphertext is $c = 13$; taking $r = 2$ gives $r^{e} = 8$ and $c' = 13 \cdot 8 = 104 \equiv 49$; the oracle returns $49^{27} \equiv 14$; and $14 \cdot 28 \equiv 7 \pmod{55}$ since $2^{-1} = 28$. The attack never uses the size of $N$, so no key length repairs it; only breaking the multiplicative structure does.
A hospital encrypts each patient's blood type under the physician's RSA public key, with no padding. Explain the attack and quantify it. Attack
Textbook RSA is deterministic, so $c = m^{e} \bmod N$ is a function of $m$ alone. There are eight blood types. An eavesdropper who knows $\mathit{pk} = (N, e)$ computes the eight candidate ciphertexts $m_i^{e} \bmod N$ once, at a cost of eight exponentiations, and thereafter reads every record by table lookup. No factoring, no queries, no key material.
In the CPA game this is immediate: submit $m_0, m_1$, receive $c$, output $0$ if $c = m_0^{e} \bmod N$ and $1$ otherwise, winning with probability $1$. Every deterministic public-key scheme fails CPA security; the fix is randomization, giving exponentially many ciphertexts per message (at least $2^{64}$ for PKCS #1 v1.5 with eight random bytes).
Show that RSA signing without the hash is forgeable in two different senses, and identify which hash property blocks each. Attack
Existential forgery, no oracle queries. Choose $\sigma \getsr \Z_N^{*}$ and set $m = \sigma^{e} \bmod N$. Verification checks $\sigma^{e} \equiv m$, which holds by construction, so $(m, \sigma)$ is a valid forgery on a message never queried. Under FDH the same strategy needs an $m$ with $\Hash(m) = \sigma^{e}$, i.e. a preimage under $\Hash$ of a value the forger cannot influence; one-wayness blocks this.
Selective forgery, two queries. Fix a target $m$ and factor it as $m \equiv m_1 m_2 \pmod N$ with $m_1, m_2 \notin \{1, m\}$; for instance take any unit $m_1$ and set $m_2 = m \cdot m_1^{-1}$. Query the signing oracle on $m_1$ and $m_2$, obtaining $\sigma_1 = m_1^{d}$ and $\sigma_2 = m_2^{d}$, and output $\sigma = \sigma_1 \sigma_2 = (m_1 m_2)^{d} = m^{d}$. The target was never queried, so this wins the unforgeability game. FDH kills it because $\Hash(m_1 m_2) \neq \Hash(m_1) \Hash(m_2)$ for any reasonable hash: the multiplicative structure the attack needs is simply not there.
Two further properties matter for FDH. Transferring a legitimate $\sigma$ to a different message needs $m' \neq m$ with $\Hash(m') = \Hash(m)$, blocked by second-preimage resistance; and getting a signer to sign a benign $m$ that also validates a malicious $m'$ needs a colliding pair chosen in advance, blocked by collision resistance. The birthday bound on the latter is why the required $2n$-bit output length is set by the digest, independently of the modulus.
Verify that $561$ is a Carmichael number, then show that Miller-Rabin exposes it with the single base $a = 2$ and extracts a factor while doing so. Attack
$561 = 3 \cdot 11 \cdot 17$ is squarefree, and $n - 1 = 560$ is divisible by each of $p - 1$: $2 \mid 560$, $10 \mid 560$ ($= 56 \cdot 10$) and $16 \mid 560$ ($= 35 \cdot 16$). By Korselt's criterion $561$ is Carmichael, so $a^{560} \equiv 1 \pmod{561}$ for every $a$ coprime to $561$. All $\varphi(561) = 2 \cdot 10 \cdot 16 = 320$ admissible bases are Fermat liars, and repeating the Fermat test cannot help.
Miller-Rabin instead writes $560 = 2^{4} \cdot 35$ and follows the chain of repeated squarings from $a^{35}$:
$$2^{35} \equiv 263, \quad 263^{2} \equiv 166, \quad 166^{2} \equiv 67, \quad 67^{2} \equiv 1 \pmod{561}.$$The chain reaches $1$ from $67$, yet $67 \not\equiv \pm 1$. In a field the only square roots of $1$ are $\pm 1$, so $561$ is not prime. The test outputs composite, correctly, on its first base. The certificate is constructive: $67^{2} - 1 = (67-1)(67+1) \equiv 0 \pmod{561}$ while neither factor is, so
$$\gcd(66, 561) = 33$$is a proper divisor, and $561 = 33 \cdot 17$. Every Miller-Rabin witness of this shape hands over a factorization for free.
Exam project: Primality Testing. Specify what an implementation must contain, and how to argue its error probability. Project
The deliverable needs four pieces. (1) Modular exponentiation by square and multiply on arbitrary-precision integers, $O(\log e)$ multiplications; everything else is built on it. (2) The Fermat test, together with a demonstration of its failure: run it over all $320$ coprime bases of $561$ and report that none is a witness. (3) Miller-Rabin: decompose $n - 1 = 2^{s} d$ with $d$ odd, compute the chain $a^{d}, a^{2d}, \dots, a^{2^{s-1}d}$ and declare composite unless the chain begins at $1$ or passes through $n-1$. (4) A prime generator: draw random odd $\lambda/2$-bit integers, sieve by trial division against the small primes to discard the easy composites cheaply, then run $t$ Miller-Rabin rounds with independent random bases.
The error argument has two halves that must not be conflated. Monier and Rabin's theorem bounds the strong liars: for every odd composite $n > 9$, at most $\varphi(n)/4$ of the bases in $[1, n-1]$ are strong liars. Hence $t$ independent random bases declare a composite prime with probability at most $4^{-t}$. This bound is uniform over inputs, in contrast to the Fermat test, where no such bound exists because Carmichael numbers have no witnesses at all. The second half is that the probability a candidate accepted by the generator is composite is much smaller still, because most composites are rejected by nearly every base; averaged over random candidates the failure rate is far below $4^{-t}$. Report both, and note that $t = 64$ is standard because $4^{-64} = 2^{-128}$.
Optional extras: the Solovay-Strassen test and its relation to the Jacobi symbol; a Miller-Rabin witness reaching $1$ without passing $-1$, which yields a factor via a gcd; and The Agrawal-Kayal-Saxena Primality Test (AKS), which settles the complexity question in polynomial time but is not competitive in practice.
Exam project: Inside RSA. Which components go in, and which three attacks should a report demonstrate? Project
Components. Prime generation via Miller-Rabin; the modulus $N = pq$ with $p, q$ of equal bit length but not too close together, since a small $\abs{p-q}$ opens Fermat's difference-of-squares factorization; selection of $e$ coprime to $\varphi(N)$; the extended Euclidean algorithm for $d = e^{-1} \bmod \varphi(N)$; square-and-multiply exponentiation; and The Chinese Remainder Theorem (CRT) decryption, which computes $m_p = c^{d \bmod (p-1)} \bmod p$ and $m_q = c^{d \bmod (q-1)} \bmod q$ and recombines, roughly a fourfold speedup because the exponent and the modulus both halve.
Attack 1: determinism. Encrypt a small message space and show that identical plaintexts give identical ciphertexts, so a dictionary breaks the CPA game outright.
Attack 2: malleability. Multiply a ciphertext by $r^{e}$ and show the recovered plaintext is $rm$, breaking CCA security with one decryption query. The lab in section 7 does exactly this.
Attack 3: low exponent. With $e = 3$ and $m < N^{1/3}$, no modular reduction occurs, so $c$ is the integer cube of $m$ and an integer cube root recovers the message with no key material. Demonstrate it, then demonstrate that PKCS #1 v1.5 padding defeats it by forcing the encoded integer up near $N$.
The report should be explicit that all three attacks target the encoding and leave the RSA assumption untouched. The distinction between hardness of the primitive and security of the scheme is what the project tests.
These pages are written by a student of the course. The mathematics is stated in the standard way. The formulation is the author's own, taken from no slide. Errors are the author's alone. Prof. Venturi bears no responsibility for them; where this page and the PDFs differ, the PDFs are authoritative and only material in them is examinable.