Curriculum / Quantum Cryptography / Quantum-Safe Hash Functions

Lesson 7 of 21Code challengePro+125 XP

Quantum-Safe Hash Functions

Understand why hash functions resist quantum attacks and implement a hash-based signature scheme.

Quantum-Safe Hash Functions

Hash functions and hash-based signatures are among the most conservative post-quantum constructions. Their security reduces to the collision resistance of the underlying hash function: a property that Grover's algorithm weakens only quadratically, not exponentially. This makes hash-based signatures like SPHINCS+ a trusted fallback even if lattice assumptions break.

Why Hash Functions Are Quantum-Resistant

Grover's algorithm can find a preimage of a hash function in quantum operations, compared to classically: a quadratic speedup. For SHA-256, this reduces effective security from 256 bits to 128 bits. This is manageable: use SHA-256 at 128-bit post-quantum security, or move to SHA3-512 for 256-bit post-quantum security.

For collision resistance (finding two inputs with the same hash), the BHT algorithm gives a cubic speedup: quantum operations. SHA-256 collision resistance drops from 128-bit to ~85-bit security. SHA3-512 retains 170-bit post-quantum collision resistance.

Crucially, hash functions do not rely on factoring, discrete logarithms, or lattice assumptions. Even if Shor's algorithm is improved or lattice algorithms advance, hash-based signatures remain conservative choices.

Lamport One-Time Signatures

The simplest hash-based signature scheme is Lamport's one-time signature (1979):

Key generation for n-bit messages:

  • Private key: 2n random secrets {s0[i], s1[i]} for i = 0..n-1
  • Public key: 2n hash values {h(s0[i]), h(s1[i])} for i = 0..n-1

Signing message bit string m = m0m1...m(n-1):

  • For each bit position i: reveal
  • The signature is n hash preimages, one per message bit

Verification:

  • For each bit i: check that hash(signature[i]) == pk[m[i]][i]

Security: To forge a signature on a different message, the attacker must find the unrevealed preimage for at least one bit position, finding a SHA-256 preimage requires operations even with Grover.

One-time limitation: Revealing preimages for both values of any bit allows signature forgery. Lamport signatures must never be reused. (XMSS and SPHINCS+ use Merkle trees to build multi-time signatures from many Lamport keys.)

This is the opening of the lesson. The full walkthrough, the interactive circuit, and the graded challenge continue inside myqubit.

How this lesson works

A hands-on coding challenge. You write Qiskit-compatible Python in the browser editor, run it instantly via WebAssembly, watch the circuit and Bloch sphere react, and pass automatic output checks. The AI tutor Qubitus gives Socratic hints if you get stuck.

Part of: Quantum Cryptography

Master quantum key distribution, the threat quantum computers pose to classical cryptography, and post-quantum cryptographic standards.

This lesson is part of Pro

Unlock Quantum Cryptography and all 10 tracks with Pro: $12.99/month, $79/year, or $97 lifetime. Start with the free track first if you are new.