Week 6 | the general quadratic speedup, why it is the best possible, and what it really costs an attacker; Lab 3 launches | reading: de Wolf Ch. 7; NIST PQC FAQ
Lecture 11 analysed Grover's algorithm for one marked item. This lecture widens the lens in two directions. Mathematically, the same two-reflection trick speeds up any algorithm that succeeds with small probability, it copes with an unknown number of solutions, and no quantum algorithm can do better. Cryptographically, the question is what all this means for AES and SHA-256. By the end you should be able to state amplitude amplification, explain the randomised iteration-count trick, state and sketch the optimality bound, and give an honest account of Grover's threat to symmetric cryptography, including the limits on parallelism and the cost of the oracle.
Grover's starting state \(|s\rangle\) is the output of one particular algorithm, \(H^{\otimes n}\), which "guesses" a uniformly random string and so succeeds with probability \(1/N\). Nothing in the rotation argument used that specific algorithm.
Let \(\mathcal A\) be a quantum circuit (with no measurements) on \(n\) qubits, and let the basis states be split into "good" and "bad" ones, with a phase oracle \(S_\chi\) that multiplies good basis states by \(-1\). Write
$$\mathcal A|0^n\rangle=\sin\theta\,|\mathrm{good}\rangle+\cos\theta\,|\mathrm{bad}\rangle ,$$where \(|\mathrm{good}\rangle\) and \(|\mathrm{bad}\rangle\) are the normalised projections onto good and bad states and \(p=\sin^2\theta\) is the success probability of \(\mathcal A\). Let \(S_0=I-2|0^n\rangle\langle0^n|\) and define the amplification operator
$$Q=-\,\mathcal A\,S_0\,\mathcal A^{-1}\,S_\chi .$$Classically, boosting \(\mathcal A\) means running it again and again and checking each output. To build \(Q\), amplitude amplification instead needs .
For every \(k\ge0\), measuring \(Q^k\mathcal A|0^n\rangle\) gives a good outcome with probability \(\sin^2\big((2k+1)\theta\big)\). With \(k\approx\tfrac{\pi}{4\theta}\approx\tfrac{\pi}{4\sqrt p}\) the success probability is close to 1, using \(O(1/\sqrt p)\) runs of \(\mathcal A\) and \(\mathcal A^{-1}\), compared with about \(1/p\) independent repetitions of \(\mathcal A\) classically.
It is Theorem 11.2 again. In the plane spanned by \(|\mathrm{bad}\rangle\) and \(|\mathrm{good}\rangle\), \(S_\chi\) is the reflection in the \(|\mathrm{bad}\rangle\) axis, and \(-\mathcal AS_0\mathcal A^{-1}=2\mathcal A|0^n\rangle\langle0^n|\mathcal A^{-1}-I\) is the reflection in the line through \(\mathcal A|0^n\rangle\), which sits at angle \(\theta\). Two reflections in lines at angles \(0\) and \(\theta\) make a rotation by \(2\theta\). Grover's algorithm is the case \(\mathcal A=H^{\otimes n}\), where \(-H^{\otimes n}S_0H^{\otimes n}\) is exactly the diffuser \(D\).
HW6 asks you to specialise this to Grover search with \(M\) marked items and find the best iteration count. The general lesson is the important one: any quantum procedure that succeeds with probability \(p\) can be boosted to near certainty with about \(1/\sqrt p\) repetitions instead of \(1/p\). That is the "quadratic speedup" you will see quoted for quantum Monte Carlo estimation, optimisation heuristics and many other proposals.
A procedure \(\mathcal A\) succeeds with probability \(p=0.01\), so classical repetition needs about 100 runs. About how many rounds of amplitude amplification does Theorem 12.1 suggest?
Let \(\mathcal A=R_y(\pi/3)\) on one qubit, with \(|1\rangle\) good. Find \(p\), \(\theta\) and the success probability after \(k=0,1,2,3\) rounds of amplification.
\(R_y(\pi/3)|0\rangle=\cos\tfrac\pi6|0\rangle+\sin\tfrac\pi6|1\rangle\), so \(\theta=\pi/6=30^\circ\) and \(p=\tfrac14\). The success probability after \(k\) rounds is \(\sin^2((2k+1)30^\circ)\): \(\tfrac14\), \(1\), \(\tfrac14\), \(\tfrac14\) for \(k=0,1,2,3\) (angles \(30^\circ,90^\circ,150^\circ,210^\circ\)). One round turns a one-in-four procedure into a certain one; a second round overshoots. This is the same geometry as Grover with \(N=4\) (Lecture 11, Example 11.1). Section 6 runs it in Qiskit.
The best iteration count depends on \(\theta\), hence on the number of solutions \(M\). If \(M\) is unknown, a fixed count can be badly wrong. With \(N=2^{20}\), the count of 804 designed for \(M=1\) is right for one key, but if there happen to be four solutions it rotates the state about twice too far. The widget shows the effect.
The cure is to randomise. If \(k\) is chosen uniformly from \(\{0,1,\dots,m-1\}\), the average success probability is easy to compute and becomes reliably large once \(m\) is big enough, whatever \(\theta\) is.
If \(k\) is uniform on \(\{0,\dots,m-1\}\), the success probability averaged over \(k\) is
$$\frac1m\sum_{k=0}^{m-1}\sin^2\big((2k+1)\theta\big)=\frac12-\frac{\sin(4m\theta)}{4m\sin(2\theta)} ,$$which is at least \(\tfrac14\) whenever \(m\ge1/\sin(2\theta)\).
Write \(\sin^2u=\tfrac12(1-\cos2u)\), so the sum is \(\tfrac m2-\tfrac12\sum_{k=0}^{m-1}\cos\big((2k+1)\alpha\big)\) with \(\alpha=2\theta\). The cosine sum telescopes: since \(2\sin\alpha\cos((2k+1)\alpha)=\sin((2k+2)\alpha)-\sin(2k\alpha)\), summing over \(k\) gives \(2\sin\alpha\sum_k\cos((2k+1)\alpha)=\sin(2m\alpha)\). Hence the sum of cosines is \(\sin(4m\theta)/(2\sin2\theta)\), and dividing by \(m\) gives the formula. If \(m\sin2\theta\ge1\), the second term has absolute value at most \(\tfrac{1}{4m\sin2\theta}\le\tfrac14\).
Take \(N=2^{16}\) and \(M=1\). About how large must \(m\) be for Proposition 12.2 to guarantee an average success probability of at least \(\tfrac14\)?
The BBHT algorithm exploits this without knowing \(\theta\): start with \(m=1\); repeatedly choose \(k\) at random below \(m\), run \(k\) Grover iterations, measure, and check the answer with one classical query; if it fails, multiply \(m\) by a constant such as \(\tfrac65\). Once \(m\) passes \(1/\sin2\theta\approx\tfrac12\sqrt{N/M}\), each round succeeds with probability at least \(\tfrac14\), and a geometric-series argument shows the expected total number of iterations is \(O(\sqrt{N/M})\), the same order as if \(M\) were known (Boyer et al., 1998). The simulation in Section 6 gives about \(1.2\sqrt{N/M}\). If there is no solution at all, the algorithm never succeeds, so in practice one stops after about \(\sqrt N\) iterations in total and declares "no solution".
Could a cleverer quantum algorithm search faster than \(\sqrt N\)? No.
Every quantum algorithm that finds the marked item of an unstructured search problem with probability at least \(\tfrac12\), for every possible marked item, makes \(\Omega(\sqrt N)\) queries. Zalka (1999) showed that Grover's \(\tfrac\pi4\sqrt N\) is optimal even in the constant.
Run the algorithm with an oracle that marks nothing, and let \(a_{x,t}\) be the amplitude with which query \(t\) asks about input \(x\). The total "query weight" \(\sum_x\sum_{t=1}^T|a_{x,t}|^2\) equals \(T\), so some input \(w\) receives weight at most \(T/N\). Now switch to the oracle that marks \(w\). Each query \(t\) changes the state by at most \(2|a_{w,t}|\), and the changes add up, so the final states of the two runs differ by at most \(2\sum_t|a_{w,t}|\le2\sqrt{T\cdot T/N}=2T/\sqrt N\) by Cauchy–Schwarz. To tell the two oracles apart with constant probability the final states must differ by a constant, so \(T\ge c\sqrt N\). (This is the "hybrid argument" of BBBV; Nielsen–Chuang §6.6 gives the details, and de Wolf Ch. 11 proves the same bound by the polynomial and adversary methods.)
Which of these claims, if true, would contradict Theorem 12.3?
Theorem 12.3 is strong evidence, relative to an oracle, that quantum computers will not solve NP-complete problems efficiently (Lecture 10): a quantum algorithm that ignores the structure of a problem can do no better than Grover, which only halves the exponent.
Key recovery for a \(k\)-bit block cipher, given a known plaintext–ciphertext pair (or a few), is a search over \(N=2^k\) keys with the oracle "does this key encrypt \(p\) to \(c\)?". Lecture 7 showed how to build such an oracle reversibly, and the figure shows its shape.
Grover then needs about \(\tfrac\pi4\,2^{k/2}\) iterations instead of the classical \(2^{k-1}\) trial encryptions on average. In "bits of security", the base-2 logarithm of the work, an idealised quantum attacker halves the key length. As an example, take an 80-bit key (the size of some legacy lightweight ciphers): Grover needs \(\tfrac\pi4\,2^{40}\approx8.6\times10^{11}\) iterations, against \(2^{79}\) classical trials, which at a billion trials per second is about 19 million years.
Three facts make the real threat much smaller than the red bars suggest.
Tick every reason, given in these notes, why Grover is a much weaker attack in practice than the idealised count of \(\tfrac\pi4\,2^{k/2}\) oracle calls suggests.
NIST's post-quantum standardisation process builds the first two facts into its definitions. Its weakest security category is "at least as hard as key search on AES-128", with quantum attacks limited to a maximum circuit depth, MAXDEPTH. NIST suggested three plausible values: \(2^{40}\) (what presently envisioned quantum computers could do serially in a year), \(2^{64}\) (what classical computers can do serially in a decade) and \(2^{96}\) (atomic-scale qubits running for a millennium). Its call for proposals estimates key search on AES-128 at \(2^{170}/\text{MAXDEPTH}\) quantum gates, against \(2^{143}\) classical gates; with MAXDEPTH \(=2^{40}\) that is \(2^{130}\) quantum gates, only \(2^{13}\) times fewer than the classical \(2^{143}\), and each error-corrected quantum gate is vastly more expensive than a classical one. NIST's FAQ concludes that "it is quite likely that Grover's algorithm will provide little or no advantage in attacking AES, and AES 128 will remain secure for decades to come."
Symmetric cryptography needs no new algorithms. The standard guidance is that AES-128 remains acceptable, and that new systems wanting a comfortable long-term margin, especially for data that must stay secret for decades, should use 256-bit keys (HW6 asks you to explain what margin they restore). Compare this with Section 5's table: public-key cryptography based on factoring or discrete logarithms must be replaced outright.
An \(n\)-bit hash function \(H\) must resist two attacks. Preimage search (given \(y\), find \(x\) with \(H(x)=y\)) is unstructured search, so Grover reduces it from \(2^n\) to about \(2^{n/2}\) evaluations, with the same caveats as key search. Collision search (find \(x\neq x'\) with \(H(x)=H(x')\)) already costs only \(2^{n/2}\) classically, by the birthday bound of Lecture 10. The Brassard–Høyer–Tapp algorithm finds collisions with about \(2^{n/3}\) queries, but it needs about \(2^{n/3}\) qubits of quantum random-access memory; once the hardware is counted, Bernstein (2009) found no advantage over classical parallel collision search. So SHA-256 keeps roughly 128-bit collision resistance and, idealised, 128-bit quantum preimage resistance.
SHA-384 has 384-bit outputs. In bits of security, what is its idealised quantum preimage resistance, and its (classical) collision resistance?
| primitive | best quantum attack | effect | response |
|---|---|---|---|
| RSA, Diffie–Hellman, elliptic curves | Shor (Lectures 15–16) | broken in polynomial time | replace with post-quantum schemes (Lecture 17) |
| block ciphers (AES) | Grover | at most halves the bits of security | prefer 256-bit keys for long-term margin |
| hash functions (SHA-2, SHA-3) | Grover (preimage); BHT (collision) | preimage bits at most halved; collisions barely affected | 256-bit outputs remain adequate |
Shor exploits hidden structure (a period) and gains exponentially; Grover exploits nothing and gains only a square root, and Theorem 12.3 says that is all an unstructured attack can ever gain. That single contrast explains why the post-quantum migration replaces public-key algorithms wholesale while leaving symmetric algorithms in place.
Shor's algorithm runs in time polynomial in the key length \(n\), roughly \(n^3\). Doubling an RSA modulus from 2048 to 4096 bits multiplies the cost of Shor's attack by about .
import numpy as np from qiskit import QuantumCircuit from qiskit.quantum_info import Statevector t = np.pi / 3 # A = R_y(pi/3): A|0> = cos(pi/6)|0> + sin(pi/6)|1>, p = 1/4 def A(qc): qc.ry(t, 0) def A_inv(qc): qc.ry(-t, 0) def flip_good(qc): qc.z(0) # S_good = I - 2|1><1| def flip_zero(qc): qc.x(0); qc.z(0); qc.x(0) # S_0 = I - 2|0><0| for rounds in range(4): qc = QuantumCircuit(1) A(qc) for _ in range(rounds): # Q = -A S_0 A^dagger S_good (the sign is a global phase) flip_good(qc); A_inv(qc); flip_zero(qc); A(qc) p = Statevector.from_instruction(qc).probabilities()[1] print(f"{rounds} rounds: P(good) = {p:.4f}")
0 rounds: P(good) = 0.2500 1 rounds: P(good) = 1.0000 2 rounds: P(good) = 0.2500 3 rounds: P(good) = 0.2500
import numpy as np rng = np.random.default_rng(1) N, M = 2 ** 16, 37 # M is unknown to the algorithm theta = np.arcsin(np.sqrt(M / N)) def search_with_unknown_M(): """Boyer-Brassard-Hoyer-Tapp: random iteration counts from a growing range""" m, iterations = 1.0, 0 while True: k = rng.integers(0, int(np.ceil(m))) # k uniform in {0, ..., ceil(m) - 1} iterations += k if rng.random() < np.sin((2 * k + 1) * theta) ** 2: # measure and check the answer return iterations m = min(1.2 * m, np.sqrt(N)) # grow the range by 6/5 runs = [search_with_unknown_M() for _ in range(5000)] print("average Grover iterations:", round(np.mean(runs), 1), " sqrt(N/M) =", round(np.sqrt(N / M), 1))
average Grover iterations: 51.0 sqrt(N/M) = 42.1
This simulates the algorithm's statistics rather than running circuits: each round's success is drawn with the probability \(\sin^2((2k+1)\theta)\) of Theorem 11.2. The average cost is about \(1.2\sqrt{N/M}\) iterations, the same order as an algorithm that knew \(M\) in advance (HW6).
Goal. Build a Grover oracle from a classical function, and connect Grover to cryptanalysis.
Next time: the quantum Fourier transform, the engine of phase estimation and Shor's algorithm. HW6 is due at the start of Week 7; Lab 3 in ten days.
all numbers and figures in these notes are computed in python (verify_L12.py) and follow the page theme