NIST’s Code-Based Backup KEM: How HQC Compares With ML-KEM
Walk through binary quasi-cyclic syndrome decoding by hand and compare NIST’s 2025 HQC backup selection against ML-KEM across sizes, speed, and assumptions.
Prerequisite: Post-Quantum Security
If all deployed post-quantum key exchanges relied on Module-LWE, any unexpected breakthrough in structured Euclidean lattice reduction would force an emergency global migration. To guarantee math-family diversity, NIST ran a fourth standardization round among non-lattice KEMs (BIKE, HQC, and Classic McEliece) and in March 2025 selected HQC (Hamming Quasi-Cyclic) for standardization alongside ML-KEM. Understanding HQC takes five minutes once you already know Ring-LWE — because algebraically, HQC is Ring-LWE translated from Euclidean norm into Hamming weight!
Ring-LWE vs. Quasi-Cyclic Codes: the exact structural parallel
Compare the two public-key equations side by side:
- Ring-LWE (Euclidean metric): Work in . Sample public and small-coefficient secrets (small norm), and publish .
- HQC (Hamming metric): Work in the binary circulant ring for a prime (such as in HQC-128, chosen so is primitive modulo to block algebraic subfield splits). Sample random binary polynomial and sparse binary secret polynomials of fixed tiny Hamming weight ( ones out of 17,669 bits!), and publish .
Lattice reduction (LLL/BKZ) relies completely on Gram–Schmidt projections in Euclidean space; over with XOR addition, Euclidean geometry disappears and the best known attacks are Information Set Decoding (ISD) algorithms (Prange, Stern, BJMM), whose exponential cost has been studied since the 1960s.
Measured size and decryption-failure comparison
| Scheme | Hardness family | Public key | Ciphertext | Combined wire | Decryption failure (DFR) | Typical CPU time |
|---|---|---|---|---|---|---|
| ML-KEM-512 (FIPS 203) | Module-LWE (Lattice) | 800 B | 768 B | 1,568 B | < 2⁻¹³⁹ | ~10–25 µs |
| ML-KEM-768 (FIPS 203) | Module-LWE (Lattice) | 1,184 B | 1,088 B | 2,272 B | < 2⁻¹⁶⁴ | ~15–35 µs |
| ML-KEM-1024 (FIPS 203) | Module-LWE (Lattice) | 1,568 B | 1,568 B | 3,136 B | < 2⁻¹⁷⁴ | ~22–50 µs |
| HQC-128 (NIST 2025) | Quasi-Cyclic Syndrome Decoding (Code) | 2,249 B | 4,497 B | 6,746 B | < 2⁻¹²⁸ | ~90–250 µs |
| HQC-192 (NIST 2025) | Quasi-Cyclic Syndrome Decoding (Code) | 4,522 B | 9,042 B | 13,564 B | < 2⁻¹⁹² | ~250–600 µs |
| HQC-256 (NIST 2025) | Quasi-Cyclic Syndrome Decoding (Code) | 7,245 B | 14,485 B | 21,730 B | < 2⁻²⁵⁶ | ~500–1,200 µs |
Notice HQC's standout engineering advantage over McEliece and BIKE: unlike Classic McEliece (whose Level 1 public key is 261,120 bytes), HQC fits both key and ciphertext into a few kilobytes; and unlike QC-MDPC schemes such as BIKE (whose secret key is the parity-check matrix used for iterative decoding, making DFR proofs delicate), HQC encrypts using a publicly known concatenated Reed–Muller + Reed–Solomon error-correcting code! Because the error-correcting decoder is completely independent of the secret key, HQC achieves a clean, provable decryption failure bound ( for HQC-128), which in turn gives tight IND-CCA2 security under the Fujisaki–Okamoto transform.
Run a toy binary HQC encryption and repetition-code decode in Python
Follow HQC on a tiny binary circulant ring encoding 1 bit via a 31-bit repetition code (, ). When sparse weight-2 polynomials multiply in , their product has Hamming weight at most , so the combined error term flips at most a handful of bits — well below majority-vote decoding's 15-bit error capacity:
n = 31
def poly_from_support(indices: list[int]) -> int:
mask = 0
for idx in indices:
mask ^= 1 << (idx % n)
return mask
def circulant_mul(a: int, b: int) -> int:
"""Multiply binary polynomials in F_2[X]/(X^n - 1)."""
acc = 0
for i in range(n):
if (b >> i) & 1:
acc ^= ((a << i) | (a >> (n - i))) & ((1 << n) - 1)
return acc
# KeyGen: sparse secrets x, y of Hamming weight 2; public h; s = x ^ (h * y)
h = 0b1011001010111001010011010110101
x = poly_from_support([2, 19])
y = poly_from_support([7, 25])
s = x ^ circulant_mul(h, y)
# Encrypt bit m = 1 using sparse ephemeral r1, r2, e of weight 2:
r1, r2, e = poly_from_support([1, 14]), poly_from_support([5, 22]), poly_from_support([11, 29])
encoded_msg = (1 << n) - 1 # bit 1 repeated 31 times
u = r1 ^ circulant_mul(h, r2)
v = encoded_msg ^ circulant_mul(s, r2) ^ e
# Decrypt: compute v ^ (u * y) = encoded_msg ^ (x*r2 ^ y*r1 ^ e) and majority-decode
noisy = v ^ circulant_mul(u, y)
flipped_bits = (noisy ^ encoded_msg).bit_count()
recovered_bit = 1 if noisy.bit_count() > n // 2 else 0
print(f"Bit errors={flipped_bits}/{n} (<= 2*2 + 2*2 + 2 = 10) -> decoded bit={recovered_bit}")Where should teams use HQC vs. ML-KEM? Deploy ML-KEM-768 (or X25519 + ML-KEM-768) as your primary production KEM: it is 3× smaller on the wire and ~6× faster on CPU. Design your wire framing and key-identifier registries with crypto-agility (supporting ciphertexts up to 9–15 kB without 2-byte/MTU assumptions) so switching to HQC-128 or HQC-192 is a configuration toggle rather than a protocol rewrite; see the PQC Migration Checklist.