← Back to section · Foundations of Cryptography
Why Hash Functions Survive: Security Margins in the Quantum Era
Preimage and collision resistance are different security goals, and Grover's algorithm buys only a square-root speedup — an accounting of SHA-256's actual quantum-era margin and the trivial countermeasure.
Quantum computers are an existential threat to public-key cryptography, but for hash functions they merely “apply a discount.” This article explains where the asymmetry comes from: what hash functions are actually required to guarantee, how much Grover’s algorithm really buys an attacker, and the countermeasure already sitting on the shelf.
Two security goals: preimage and collision
A cryptographic hash function such as SHA-256 (output bits) must resist three attacks, of which the first two dominate engineering practice:
- Preimage attack: given a hash value , find any input with . This is one-wayness — password storage and key derivation depend on it.
- Collision attack: find any two distinct inputs with . Digital signatures stand on this one — a collision lets a signature be transplanted from one document to another.
The classical costs are asymmetric: preimage search is brute force, expected trials; collisions benefit from the birthday effect and need only about . So SHA-256’s classical strength is conventionally quoted as 256 bits for preimage and 128 bits for collision. Note that the collision “discount” exists in the classical world already; it has nothing to do with quantum computing.
Grover’s speedup: square root only, and provably so
Grover’s algorithm (1996) searches an unstructured space of candidates in instead of — and it has been proven optimal in the quantum query model: no faster generic quantum search exists. Applied to preimage search, a space becomes about quantum queries. That sounds like a halving of security, but two practical constraints dominate:
- Seriality: Grover iterations are inherently sequential. Even split across many machines, iterations of a deep quantum circuit per machine is an astronomical runtime — the raw query count understates the cost badly.
- Fault-tolerance overhead: each query is a full quantum circuit for SHA-256, and with error correction priced in, resource estimates conclude that a SHA-256 preimage attack is infeasible at any foreseeable engineering scale.
The quantum collision attack (the BHT algorithm) nominally reaches queries, but demands a comparable amount of quantum memory; once memory and time are costed honestly, conservative assessments stay much closer to the classical birthday bound. The summary: quantum attacks halve hash security measured in bits (for preimage), or less — they do not collapse it from exponential to polynomial the way Shor’s algorithm does.
SHA-256’s margin, on the books
| Attack goal | Classical | Quantum (idealised) | Verdict |
|---|---|---|---|
| SHA-256 preimage | Grover queries | Still infeasible | |
| SHA-256 collision | queries (BHT, with enormous quantum memory) | Real-world assessments far more conservative | |
| SHA-512 preimage | queries | Margin to spare |
This table is why migration guidance treats hashes calmly across the board: no algorithm change is required, only a check that output lengths suffice. (Length extension, often raised in the same breath, is a classical construction quirk of Merkle–Damgård designs such as SHA-256 — a reason to use HMAC or SHA-3 at the protocol level, not a quantum concern.) Consistently with this accounting, guidance such as the NSA’s CNSA 2.0 suite already names SHA-384 as the default hash for national security systems — chosen for exactly this margin.
The sponge construction and SHA-3
SHA-3 (FIPS 202, based on Keccak) uses a completely different internal structure from SHA-2: the sponge construction. Input is absorbed block by block into a large state transformed by a permutation; output is then squeezed out, with security governed by the state’s “capacity” portion. The diversity is itself insurance — SHA-2 and SHA-3 are structurally unrelated, so a cryptanalytic breakthrough against one family leaves the other standing. The sponge also natively supports extendable-output functions (SHAKE), which NIST’s post-quantum standards use extensively inside ML-KEM and ML-DSA for sampling and hashing: hash functions not only survive the transition, they supply parts for the post-quantum schemes.
Beyond digests: the other jobs hashes do in a system
In real systems, hashes do far more than compute digests. HMAC uses a keyed hash for message authentication; its security goals resemble preimage and forgery resistance, and the same Grover halving logic applies — HMAC-SHA-256 with a 256-bit key still offers roughly 128 bits of strength in quantum accounting. Key derivation functions (KDFs) are built around hashes, and the entropy ceiling of a derived key is set jointly by the input material and the output length, with the accounting unchanged. Password storage is a special corner: passwords are low-entropy, so the defence rests on salting and deliberately slow, memory-hungry constructions (bcrypt, scrypt, Argon2) that raise the classical cost of each guess; quantum search can take the square root of the number of guesses, but not of the memory-bandwidth cost of each guess — memory-hard functions resist Grover for exactly this reason, so password-hash parameter calibration survives the quantum transition, needing only the same “halve the bits” margin. One correction is often overlooked: multi-target attacks. When an attacker holds a large batch of targets (say, an entire password database) and needs to break only one, the expected cost per target falls in both classical and quantum accounting, and Grover’s real advantage in the multi-target setting exceeds the single-target ledger. This does not overturn the “hashes are basically fine” verdict, but an audit should distinguish single-target strength from batch-scenario strength: genuinely large deployments should size output lengths and salts under the multi-target accounting. Finally, it is worth noting that NIST’s post-quantum security categories are themselves defined against hash and symmetric yardsticks — Category 1 means “at least as hard as AES-128 key search,” Category 3 corresponds to the AES-192 / SHA-384 collision scale. Hash functions are not merely survivors of the transition; they have become the ruler by which the whole post-quantum migration is measured.
One engineering detail deserves mention: the same family offers ready-made “extended” usage. Truncated outputs such as SHA-512/256 and SHA-384 keep the large internal state while shortening the digest, which makes them naturally immune to length extension (the attacker never sees the truncated-away portion of the state), so they can serve as integrity-protected digests in protocols without wrapping everything in HMAC. NIST guidance such as SP 800-107 sets explicit floors for truncation (generally no less than 128 bits of output), and an audit of legacy systems should check field by field: what actually needs fixing is usually not the algorithm’s name but some corner where a digest has been truncated to 64 or 80 bits.
The countermeasure: double the output, nothing more
The complete quantum-era prescription for hashes has three lines. First, plan preimage security as “bits halved”: for 128 bits of post-quantum strength, use outputs of 256 bits or more. Second, existing SHA-256 deployments need no panic replacement, but new systems should prefer SHA-384/512 or SHA-3. Third, the real dangers remain classical cryptanalysis and implementation flaws — the lessons of MD5 and SHA-1 both came from the classical world. Spend the migration energy on the public-key foundation; for hashes, a length audit suffices.
References
- Grover, A fast quantum mechanical algorithm for database search, Proc. 28th ACM STOC, 212 (1996). https://arxiv.org/abs/quant-ph/9605043
- Brassard, Høyer & Tapp, Quantum algorithm for the collision problem, ACM SIGACT News 28 (1997) (the BHT algorithm). https://arxiv.org/abs/quant-ph/9705002
- NIST, FIPS 180-4: Secure Hash Standard (SHS) (2015). https://csrc.nist.gov/pubs/fips/180-4/upd1/final
- NIST, FIPS 202: SHA-3 Standard: Permutation-Based Hash and Extendable-Output Functions (2015). https://csrc.nist.gov/pubs/fips/202/final
- Bertoni et al., The Keccak reference, v3.0 (2011). https://keccak.team/keccak.html
Tags: hash functionsGrover's algorithmSHA-256