9. Codes
Draft
Correcting errors on purpose
The lattice schemes of Sections 3 to 7 hide a secret behind errors that are small in size; the schemes of this part hide one behind errors that are few in number. It is the same idea under another notion of distance, used in two ways: publishing a scrambled copy of a code that only its owner can decode (McEliece, 1978), or masking a codeword under heavy binary noise that only the private key can cancel down to a correctable level (HQC, chosen in 2025 as the second standard for key encapsulation, by which two parties establish a shared secret key). The mathematics of few errors comes from error-correcting codes, built to carry messages across noisy lines, and one of its smallest examples uses seven bits: four message bits and three check bits set so that each of three overlapping circles holds an even number of ones. If a noisy channel flips any single bit in transit, the pattern of circles whose parity turns odd pinpoints which bit flipped.
circles seven bits in three overlapping circles A, B, C; each circle must hold an even number of ones
bit 1 2 3 4 5 6 7
sent 0 1 1 0 0 1 1 the message 1011 and three check bits (bits 1, 2 and 4)
received 0 1 1 0 1 1 1 bit 5 was flipped on the way
matrix circle A 1 0 1 0 1 0 1 odd: 1 the check matrix H: a row to a circle,
circle B 0 1 1 0 0 1 1 even: 0 a 1 where the circle holds the bit
circle C 0 0 0 1 1 1 1 odd: 1
the syndrome (1, 0, 1) is column 5 of H, so the decoder flips bit 5 back, whatever the message
two each column of H is also the syndrome of 3 pairs of flipped bits (column 5: 1+4, 2+7, 3+6), so
flips after two flips the decoder flips a third bit: all 7 single flips are put right, all 21 double
flips end with three wrong bits
real the ciphertext of Classic McEliece is a syndrome of 768 bits that names 64 flipped bits among 3,488
(the live figure needs JavaScript; it loads no data)
Two properties of this seven-bit machine drive every code-based scheme that follows. First, the three parity checks never reveal the message: flip the same bit in any of the 16 valid codewords (the words that pass all three checks) and the exact same circles turn odd, so the pattern of failed checks, called the syndrome, is a fingerprint of the error alone. Second, in this carefully arranged code, that fingerprint directly names the damaged coordinate: bit number \(j\) belongs to the circles that spell \(j\) in binary, so flipping bit 5 makes the first and third checks fail, reading 101, or five. Because checking whether a circle holds an even number of ones is simply adding its bits modulo 2, linear algebra over \(\mathbb F_2\) captures both encoding and parity checking as matrix multiplication: a generator matrix maps short messages to valid codewords, while a parity-check matrix maps every valid codeword to zero and isolates the error.
Definition 9.1.1 (linear code, syndrome). A binary linear code of length \(n\) and dimension \(k\) is a \(k\)-dimensional subspace of \(\mathbb F_2^n\), the vectors of \(n\) bits with addition modulo 2. Its elements are the codewords, and \(k/n\) is its rate. A generator matrix \(G\), of \(k\) rows and \(n\) columns, has the code as its row space: the codewords are the products \(mG\) with \(m \in \mathbb F_2^k\). A parity-check matrix \(H\), of \(n - k\) rows, has the code as its kernel: the codewords are the \(c\) with \(Hc^{\top} = 0\). The weight of a word is the number of its ones. The syndrome of a word \(w\) is \(Hw^{\top}\), and if \(w = c + e\) with \(c\) a codeword, then
\[s \;=\; H w^{\top} \;=\; H c^{\top} + H e^{\top} \;=\; H e^{\top} . \tag{9.1}\]The seven-bit example is the Hamming code with \(n = 7\) and \(k = 4\): its three parity checks form the rows of \(H\), and column \(j\) of \(H\) writes the number \(j\) in binary. Because the error vector \(e\) has ones only at the flipped coordinates, the product \(He^{\top}\) in (9.1) sums the columns of \(H\) at those coordinates, so a single flip at position \(j\) returns column \(j\) itself. In the JavaScript that runs this decoder on the page, one loop builds \(H\) and two lines correct the bit (counting array positions from 0, hence j + 1):
for (b = 0; b < r; b++) for (j = 0; j < n; j++) if (((j + 1) >> b) & 1) set(H, b, j, 1);
// ...
function syndromeValue(s) { return s[0] + 2 * s[1] + 4 * s[2]; }
/* syndrome decoding: the syndrome names the position to flip (0 means nothing to flip) */
function decode(word) {
var s = syndrome(H, word), value = syndromeValue(s), corrected = Uint8Array.from(word);
if (value) corrected[value - 1] ^= 1;
// ...
}
Three syndrome bits provide eight distinct patterns: all zeros when nothing flipped, plus one pattern for each of the seven bit positions. That leaves no spare pattern for two flips at once: the sum of two columns of \(H\) modulo 2 equals some third column, so the decoder misreads a double error as a single error at that third position and flips a good bit, leaving three wrong bits where there were two. All 21 pairs of flips fail in this way. Correcting more errors requires more parity checks. Under the smallest parameter set of Classic McEliece (Section 9.3), codewords have 3,488 bits and 768 parity checks, allowing the syndrome to identify up to 64 flipped bits: 12 bits of syndrome per error, roughly what it takes to write down one coordinate among 3,488.
Now read (9.1) from an attacker's perspective, when the parity-check matrix \(H\) has no tidy binary-counting layout. Knowing \(s = He^{\top}\) gives \(n - k\) linear equations in the \(n\) unknown bits of \(e\). Without any constraint on how many ones \(e\) may contain, Gaussian elimination solves those underdetermined equations effortlessly. Adding the requirement that \(e\) has very few ones turns routine linear algebra into a hard combinatorial search, playing the exact role for codes that finding the closest lattice point played in Sections 3 and 4.
Decoding a code with no structure
To see why a random check matrix resists direct decoding, draw \(H\) at random with 80 parity checks on 160 bits, and compute the syndrome of an error vector with six flipped bits. Gaussian elimination solves the 80 linear equations at once, leaving 80 free bits and therefore \(2^{80}\) binary vectors that all produce the same syndrome. Almost all of those \(2^{80}\) vectors have roughly half their bits set to one; the planted error with only six ones sits hidden among them, and nothing in the syndrome spells out coordinates directly. Since 1962, the best known strategy has been to turn the underdetermined system into a uniquely solvable one by guessing a large set of coordinates where no error occurred.
strips a random code of 160 positions with 6 errors (green); an attempt chooses 80 positions (ink)
and solves for the rest
attempt 1 2 errors among the chosen positions: the rest solves to a word of weight 47, not 6
attempt 222 no error among them: the rest solves to the 6 errors: found
the closed form expects 244 attempts: 1 set in 70.5 holds no error, 29 % of sets can be solved
real Classic McEliece's smallest parameter set: 3,488 positions, 2,720 chosen, 64 errors; the first
size attempt made in the page has 53 of the 64 errors among its chosen positions
chart across, the attempts the closed form expects; up, the attempts measured: every size on the diagonal
rate 1/2 78 sizes, 27,503 runs one error more: ×2.0 to ×2.1 the attempts
rate 0.78 10 sizes, 3,600 runs one error more: ×4.8
far along the same diagonal, computed, not run, in attempts: 2^144.6 for mceliece348864, up to
2^301.9 for mceliece8192128; one core makes 2^36.3 attempts in a year
table published for Prange's algorithm, in operations as its estimator counts them: 2^173.4 for
mceliece348864, that is 2^28.8 of those operations for one attempt
(the live figure needs JavaScript and loads about 0.2 MB of data)
One trial of that strategy works as follows. Pick \(k\) of the \(n\) bit positions at random and assume that none of the flipped bits landed among them. Setting \(e = 0\) on those \(k\) coordinates collapses (9.1) to \(n - k\) linear equations in the remaining \(n - k\) unknown bits, a square system. If that square matrix is invertible and its unique solution has weight at most \(t\), the solver has found the error vector (or, rarely at cryptographic sizes, another vector just as light). Otherwise the trial is discarded: either the square matrix was singular, or at least one error sat inside the guessed \(k\) positions and forced the remaining coordinates to solve to a heavy vector. This procedure is Prange's algorithm. Any subset of \(k\) coordinates whose remaining \(n - k\) columns form an invertible square matrix is called an information set (because knowing a codeword on those \(k\) bits determines the rest of the codeword uniquely), and the family of algorithms built on Prange's idea is called information-set decoding.E. Prange, "The use of information sets in decoding cyclic codes", IRE Transactions on Information Theory IT-8, S5 to S9, 1962. Every algorithm in this family attacks the same underlying search problem.
Definition 9.2.1 (syndrome decoding). Given a parity-check matrix \(H \in \mathbb F_2^{(n-k) \times n}\), a syndrome \(s \in \mathbb F_2^{n-k}\) and a number \(t\), find \(e \in \mathbb F_2^n\) of weight at most \(t\) with \(He^{\top} = s\).
Viewed through a generator matrix \(G\) instead of \(H\), the same task asks for the codeword \(mG\) nearest in Hamming distance to a received noisy word \(w = mG + e\). For arbitrary linear codes, the yes-or-no version of this decoding problem is NP-complete, meaning as hard in the worst case as any problem whose solutions can be verified efficiently. Worst-case completeness, however, says nothing about whether randomly drawn codes are hard on average; that random instances resist fast decoding is an unproved assumption whose main support is how little headway sixty years of attacks have made.Berlekamp, McEliece and van Tilborg, "On the inherent intractability of certain coding problems", IEEE Transactions on Information Theory, 1978. NIST's report on the third round of its process, quoted below, restates the result in its Section 3.2.1 and adds that it does not guarantee that the instances a scheme uses are hard.
How many random trials does Prange's guessing require on average? A chosen set of \(k\) coordinates dodges all \(t\) errors precisely when every error lands inside the \(n - k\) unchosen positions, which happens for \(\binom{n-k}{t}\) of the \(\binom{n}{t}\) possible error patterns, and a large random square binary matrix is invertible with probability 0.2888. Because independent trials repeat until one both dodges all errors and yields an invertible matrix, the expected number of attempts is
\[\frac{1}{0.2888} \cdot \binom{n}{t} \Big/ \binom{n-k}{t} , \tag{9.2}\]and one more error multiplies it by \((n-t)/(n-k-t)\). Every error has to fall among the \(n - k\) positions that were not chosen, and the fewer of those there are, the sooner they run out. For few errors in a long code the factor is close to \(1/(1-R)\), where \(R = k/n\) is the rate: 2 at rate 1/2, 4.5 at rate 0.78.
Example 9.2.2 (the attack, measured). To check how closely actual runs follow formula (9.2), random codes were generated across 88 parameter sizes: lengths of 64 to 320 positions with 1 to 13 errors at rate 1/2, and lengths of 128 and 256 positions with up to six errors at rate 0.78. Each size used between 43 and 400 random instances (31,103 in all), and the plain JavaScript from this page ran Prange's algorithm on a 16-core server until it found the planted error or, in 28 instances, another word just as light. Running for 18.7 minutes across four threads at rate 1/2 and 5.4 minutes across two threads at rate 0.78, the experiment recorded the number of attempts each instance took.
For 160 positions, 80 of them chosen, and six errors, formula (9.2) gives 244 attempts: one set in 70.5 misses every error. The mean of 400 runs was 250. A single run says little, since the count is geometric and its spread is as large as its mean, so the comparison is of means, and all 88 lie on the formula: of the 78 at rate 1/2, 73 are within two standard errors of it, about what chance allows, and so are all ten at rate 0.78. One more error multiplied the attempts by 2.0 to 2.1 at rate 1/2 and by 4.8 at rate 0.78. ◁
The cost is exponential in the number of errors, and the base of the exponential grows with the rate. Rate 0.78 was measured because it is the rate of Classic McEliece's smallest parameter set: 3,488 positions, 2,720 of them chosen at each attempt, 64 errors. For that set (9.2) gives \(2^{144.6}\) attempts: computed, not run. One attempt at that size took 75 to 90 milliseconds in a headless browser on the same server, so the attempts alone would take between \(8 \times 10^{34}\) and \(10^{35}\) years.
Two caveats qualify that number. First, it comes from evaluating formula (9.2) at length 3,488 after confirming it up to length 320; no search anywhere near the standardized size was run or could be. Second, it counts trials of the simplest algorithm in the family. Later variants permit a small handful of errors inside the guessed \(k\) coordinates and search for them with meet-in-the-middle tables, trading large amounts of memory for fewer trials. In the reference table that the Classic McEliece team publishes for reviewers, Prange's algorithm against this smallest parameter set costs \(2^{173.4}\) operations once each of the \(2^{144.6}\) attempts is charged \(2^{28.8}\) operations for Gaussian elimination on a \(768 \times 3{,}488\) binary matrix. Across all eight ISD variants priced in that table, the cheapest drops the cost to \(2^{140.8}\) operations if memory access is counted as free, or \(2^{158.6}\) under the stricter of two models for the cost of reading large tables in memory."Classic McEliece: conservative code-based cryptography: guide for security reviewers", 23 October 2022, Section 3.5, Table 1 (page 10): the output of an estimator by Esser and Bellini for eight algorithms, with memory free and at two prices. It counts a vector operation as one operation, so its numbers understate bit operations: by the guide's account \(2^{140.8}\) stands for more than \(2^{143}\) bit operations, NIST's estimate for finding an AES-128 key by search. At the higher price of memory Prange's own figure is \(2^{178.3}\). The project's web page gives a third unit, bit operations by another tool: \(2^{156.96}\) with the techniques of the 1980s and \(2^{150.59}\) with today's, for the same size (Section 9.3 has the reference).
NIST, the United States' National Institute of Standards and Technology, whose process chose the post-quantum standards, summed up sixty years of work on this attack in its report on the third round. A KEM is a key-encapsulation mechanism, the interface of Section 1.1, and ISD is information-set decoding.
The most effective known attacks against code-based KEMs are based on information set decoding (ISD). This approach ignores the structure of the binary code and seeks to recover the error vector based on its low Hamming weight. These techniques originated with Prange’s algorithm in 1962 [115] and have since undergone a series of improvements (e.g., [116–129]). The net effect of all these improvements has been fairly modest, and most of the changes in concrete security were due to results from more than 30 years ago. Quantum versions of ISD algorithms have also been studied [130–133]. These results represent a generic Grover-based speedup of classical ISD algorithms and indicate that ISD can be sped up nearly as much as brute-force search.
—G. Alagic and others, NIST IR 8413, "Status Report on the Third Round of the NIST Post-Quantum Cryptography Standardization Process" (2022). Section 3.2.1, on the code-based candidates, in the updated edition of the report (NIST IR 8413-upd1). The numbers in brackets are the report's references.
The last two sentences of the passage are the quantum half of the story. Guessing is a search, and a quantum computer speeds up a search by a square root at most (Grover's algorithm, Section 2.6); nothing periodic is known in a random code for it to find. Section 10.4 sets the largest decoding problems solved in public beside the sizes in use.
A code only its owner can decode
A decoding problem that nobody knows how to solve is half of a public-key scheme. The other half is one person who does, and the proposal McEliece made in 1978 is the plainest there could be: take a code that comes with a fast decoder, publish it scrambled, and let the sender add errors on purpose, which the owner knows how to remove.
key three private matrices and their product, a pixel to a bit
S 40 × 40 a random invertible matrix private
G 40 × 64 a Goppa code that corrects 4 errors: a diagonal shows private
P 64 × 64 a permutation of the 64 positions private
G′ = S·G·P 40 × 64 = 2,560 bits = 320 bytes: the public key, in which nothing shows
ladder the sender the message m (40 bits), encoded as m·G′, with 4 positions flipped (26, 30, 44
and 62): the ciphertext, 8 bytes
the owner undoes P (the errors now stand at 25, 8, 49 and 11), lets the Goppa decoder find
the 4 errors, reads m·S at 40 positions, undoes S: m again
with 5 errors the decoder finds no codeword and nothing comes out
attacker has G′ and the ciphertext: guesses 40 positions that hold no error and solves for the rest;
found at attempt 157, where the closed form expects 207; for Classic McEliece's smallest
parameter set (3,488 positions, 64 errors) the same form gives 2^144.6: computed, not run
scale Classic McEliece public key 261,120 bytes (32 rows of 8,192) its ciphertext 96 bytes
ML-KEM-768 encapsulation key 1,184 bytes its ciphertext 1,088 bytes
(the live figure needs JavaScript and loads about 0.2 MB of data)
The hidden code is a binary Goppa code, defined by an irreducible degree-\(t\) polynomial over a finite field together with \(n\) distinct elements of that field, one labeling each bit position. Anyone who knows that polynomial and the ordered list of field elements can correct up to \(t\) bit flips rapidly: an algebraic algorithm due to Patterson converts the received noisy word into a polynomial over the field whose roots directly reveal the flipped positions. To let anyone encode messages while keeping Patterson's decoder private, the owner multiplies the Goppa generator matrix \(G\) on the left by a random invertible matrix \(S\) (which mixes the basis rows without changing the subspace of codewords) and on the right by a random permutation matrix \(P\) (which shuffles the bit positions so their field-element labels are hidden).
Definition 9.3.1 (McEliece's scheme). Let \(G\) be a generator matrix, of \(k\) rows and \(n\) columns, of a binary Goppa code that corrects \(t\) errors, \(S\) a random invertible \(k \times k\) matrix of bits and \(P\) a random \(n \times n\) permutation matrix. The private key is \((S, G, P)\) with the decoder of the code; the public key is \(G^{\prime} = SGP\) with the number \(t\). To encrypt \(m \in \mathbb F_2^k\), draw \(e \in \mathbb F_2^n\) of weight \(t\) at random and send \(c = mG^{\prime} + e\). To decrypt, compute
\[c P^{-1} \;=\; (mS)\, G + e P^{-1} , \tag{9.3}\]which is a codeword of the private code plus an error that still has weight \(t\); decode it to \(mS\), and multiply by \(S^{-1}\).
Multiplying \(c\) by \(P^{-1}\) unshuffles the coordinates without changing how many bits were flipped, so \(eP^{-1}\) still has weight \(t\) and Patterson's decoder strips it off to recover \(mS\). Meanwhile, the \(t\) deliberate bit flips act as the lock against eavesdroppers: without \(e\), anyone could recover \(m\) from \(mG^{\prime}\) by Gaussian elimination, whereas adding even one flip beyond \(t\) causes Patterson's decoder to fail. In the JavaScript that runs the toy scheme on this page, decryption follows (9.3) step by step from left to right:
function decrypt(sk, c, trace) {
var y = C.permuteVector(c, sk.permutationInverse); // 1. c P^-1
var d = decode(sk.code, y, trace); // 2. Patterson: m S G and e P^-1
if (!d.ok) return { ok: false, message: null, error: null };
var mS = new Uint8Array(sk.code.k);
for (var i = 0; i < mS.length; i++) mS[i] = d.codeword[sk.code.informationSet[i]]; // 3. m S
var message = C.vectorTimesMatrix(mS, sk.Sinv); // 4. m = (m S) S^-1
// ...
}
The paper's own account of the key is where the word scramble comes from.
Having generated G, the system designer now “scrambles” G by selecting a random dense k × k nonsingular matrix S, and a random n × n permutation matrix P. He then computes G′=SGP, which generates a linear code with the same rate and minimum distance as the code generated by G. We call G′ the public generator matrix, since it will be made known to the outside world.
—R. J. McEliece, "A public-key cryptosystem based on algebraic coding theory" (1978). DSN Progress Report 42-44, Jet Propulsion Laboratory, January and February 1978, pp. 114 to 116; this is a paragraph of Section II, which begins at the foot of p. 114 and ends on p. 115. The report survives as a scan, and the passages here are transcribed from it.
Remark 9.3.2 (the form in use). Classic McEliece, the modern specification of the scheme, presents the same hidden Goppa code from its parity-check side, in the dual form Niederreiter gave it in 1986 to shrink both public key and ciphertext. Key generation takes a parity-check matrix of the Goppa code, shuffles its columns via the secret ordering of field elements (playing the role of \(P\)), and uses row operations (playing the role of \(S\)) to reduce it to systematic form \([\,I \mid T\,]\), publishing only \(T\). Instead of sending an \(n\)-bit noisy codeword, encapsulation draws a random weight-\(t\) error vector \(e\), sends only its syndrome \(He^{\top}\), and hashes \(e\) into the shared secret key. At the smallest parameter set, \(T\) has 768 rows and 2,720 columns of bits (261,120 bytes), while the ciphertext is the 768-bit syndrome (96 bytes). Recovering \(e\) from \(T\) and that syndrome is Definition 9.2.1 verbatim.H. Niederreiter, "Knapsack-type cryptosystems and algebraic coding theory", Problems of Control and Information Theory 15, 1986. "Classic McEliece: conservative code-based cryptography: cryptosystem specification", 23 October 2022, whose key encapsulation also expands seeds and hashes; the code of these pages leaves both out, so what it makes at real size is a key of that size, not a key of the specification.
What this costs is in the key. Section 5 shrank the public matrix of a lattice scheme by giving it a structure in which one row determines the rest. Here the matrix must show no structure, because structure is what it hides, so all of it is published: 261,120 bytes at the smallest parameter set, 524,160 at the next, and between 1,044,992 and 1,357,824 at the three largest, for ciphertexts of 96 to 208 bytes, the smallest of any candidate in NIST's process. NIST sorts parameter sets into security categories: a set of category 1, 3 or 5 should cost at least as much to break as finding the key of the cipher AES-128, AES-192 or AES-256 by search. These five sets are assigned to categories 1, 3, 5, 5 and 5.Sizes: the specification's, as listed in NIST IR 8545 (cited below), Table 8. The assignment to categories is the submission's own and charges for access to memory; counting bit operations with memory free, its guide for security reviewers says (pages 10 and 11), the right categories would be 1, 2, 4, 4 and 5. The page makes a key pair of the smallest size in under a second (0.5 to 0.9 seconds in a headless browser on the server of Example 9.2.2), from a seed fixed so that the first try succeeds. A try fails when the 768 columns that are to become \(I\) are dependent, about as often as the square systems of Section 9.2 were degenerate, so a fresh seed needs about 3.5 tries. The 64 errors of a ciphertext are decoded in 15 to 30 milliseconds.
What the security rests on was worked out in the same three pages. This is the paper's estimate for the parameters it proposed.
In particular, suppose we chose n = 1024 = 210, t = 50; then there will be about 10149 possible Goppa polynomials, and an astronomical number of choices for S and P. The dimension of the code will be about k = 1024-50·10 = 524. Hence, a brute-force approach to decoding based on comparing x to each codeword has a work factor of about 2524 = 10158; and a brute-force approach based on coset leaders has a work factor of about 2500 = 10151. A more promising attack is to select k of the n coordinates randomly in hope that none of the k are in error, and based on this assumption, to calculate u. The probability of no error, however, is about (1 - t/n)k, and the amount of work involved in solving the k simultaneous equations in k unknown is about k3. Hence, before finding u using this attack one expects a work factor of k3 · (1 - t/n)-k. For n = 1024, k = 524, t = 50 this is about 1019 ≈ 265.
—R. J. McEliece, "A public-key cryptosystem based on algebraic coding theory" (1978). Section III, p. 115. McEliece writes \(u\) for the message and \(x\) for the ciphertext; the dimension is \(1024 - 50 \cdot 10\) because the field has \(2^{10}\) elements, so that each error costs ten checks. The two expressions with the bracket stand on lines of their own in the report, with \(t\) over \(n\) as a built-up fraction, and are set on the line here.
The final attack in McEliece's passage is Prange's information-set decoding from Section 9.2, and \(2^{65}\) is a rough analytical estimate rather than an exact count. McEliece approximated the chance of picking \(k\) error-free positions as \((1 - t/n)^k\), as though coordinates were sampled with replacement, which gives \(2^{-37.8}\) for these parameters. Because the \(k\) coordinates are actually chosen without repeats, each clean coordinate drawn shrinks the remaining pool of clean coordinates, dropping the true success probability to \(2^{-53.6}\) and raising formula (9.2) to \(2^{55.4}\) Gaussian-elimination trials. Prange's guessing was therefore costlier than McEliece's back-of-the-envelope estimate, and sixty years of algorithmic refinements have not pushed the total cost below \(2^{65}\): the Classic McEliece team's estimator counts \(2^{69.78}\) bit operations for these 1978 parameters using modern ISD techniques, compared with \(2^{70.05}\) using those of the 1980s. What grew instead was hardware speed. By the same team's account, optimized attack software finishes that search in roughly \(2^{60}\) processor cycles, about a dozen years on one 3 GHz core.Classic McEliece website, comparison page, section "Stability of McEliece attack costs", with estimates from the tool CryptAttackTester (Bernstein and Chou, Crypto 2024); read on 30 November 2026. The team is an interested party. The core cryptanalytic idea has barely moved since 1978, while parameter sizes have scaled up to 3,488 through 8,192 positions and 64 through 128 errors. For the toy Goppa code running on this page (64 positions and four errors), formula (9.2) expects 207 attempts, about a millisecond of work.
Both halves of the scheme are beliefs. That a random code cannot be decoded is the belief of Section 9.2. That the public matrix is as good as random is a belief about Goppa codes in particular. Other families of codes were proposed in their place to make the key smaller, and many of those proposals fell to attacks that recovered the private key."Classic McEliece: conservative code-based cryptography: design rationale", 23 October 2022, Section 1. Against Goppa codes NIST's report of March 2025 finds such attacks still far from the parameter sets, but it records significant progress on telling a Goppa code from a random one, and says that this somewhat weakens the argument from the scheme's long history.G. Alagic and others, NIST IR 8545, "Status Report on the Fourth Round of the NIST Post-Quantum Cryptography Standardization Process", March 2025, Section 3.3.
Remark 9.3.3 (large is not broken, and unbroken is not unattacked). Two things often said of this scheme are not so. The size of its key is not a weakness that someone found; it is the price of the disguise and was there in 1978. And the scheme has not gone unattacked: the Classic McEliece team lists 30 publications on attacks between 1981 and 2022. What has held for forty-eight years is the scheme itself, at larger sizes, with the generic decoding of Section 9.2 still the most effective attack known against it.
The same idea in two metrics
Put Sections 3 and 4 beside this and the outline is the same. There a public matrix and a secret gave a point of a lattice, the published vector was that point moved by a small error, and the problem was to find the lattice point nearest to it. Here a public matrix and a message give a codeword, the ciphertext is that codeword with a few bits flipped, and the problem is to find the codeword nearest to it. The points of Section 4 are themselves a linear code, over the integers modulo \(q\) instead of the bits, and the lattice drawn in Section 4.2 is that code repeated with period \(q\) in every coordinate.The parallel is worked out in the slides "Codes and lattices in cryptography: real twins or distant cousins?" by M. Bombar and ten others (CAIPI symposium, 2 December 2024), which file both families under error-based cryptography. Lifting a code to a lattice in this way is known as construction A. What changes is the meaning of nearest: what counts as a small error.
Two metrics, one ideaa row to a part of a scheme: left, where the error is small in size; right, where the errors are few in number
- a small error
small in size Every coordinate may be off, each by one or two modulo 3,329. Distance is ordinary length.
9.4few in number Only t of the n bits are wrong. Distance is the number of positions where two words differ.
- the hard problem
learning with errors Section 4.2 · A public matrix and a secret give a lattice point. Find the point nearest to the published vector.
syndrome decoding Section 9.2 · A public check matrix and a syndrome. Find the few flipped bits, which is to find the codeword nearest to a word.
- the best attack known
lattice reduction Section 3.5 · Hunts for short vectors, and slows down exponentially as its block size grows.
information-set decoding Section 9.2 · Guesses where the errors are not, and slows down exponentially as their number grows.
- publish a disguise
a short basis kept private Section 3.3; FN-DSA, Section 7.5 · The owner decodes with a short basis. The public sees a long basis of the same lattice.
a decodable code, scrambled McEliece, Section 9.3 · The owner decodes a Goppa code. The public sees a matrix in which its structure does not show.
- publish noisy equations
ML-KEM Section 6 · Nothing is disguised. Decryption leaves the message plus small noise, removed by rounding. A key of 1,184 bytes and a ciphertext of 1,088.
HQC Section 9.5 · Nothing is disguised. Decryption leaves a codeword plus noise, removed by a public decoder. A key of 4,514 bytes and a ciphertext of 8,978.
green: what makes an error small
A bit leaves no room for an error that is small in size: it is wrong or it is right. Over bits, then, a small error has to be a rare one, and the distance between two words is the number of positions where they differ. Modulo 3,329 every coordinate can be off by one or two and the error is still small; distance there is ordinary length. The metric decides what an attack looks like. Lattice reduction hunts for short vectors and slows down exponentially as its block size grows (Section 3.5); information-set decoding guesses where the errors are not and slows down exponentially as their number grows.
Lattices hide a secret behind errors that are small, codes behind errors that are few. In either metric a scheme can publish a disguised copy of something its owner knows how to decode, or publish noisy equations in which nothing is disguised and the noise is the only secret.
The first design is McEliece's, mirrored among lattices by the private short basis of Section 3.3 and FN-DSA (Falcon, Section 7.5). The second is learning with errors and ML-KEM (Kyber), mirrored among codes by HQC (Section 9.5). Two properties, however, do not carry across from lattices to codes. One is the kind of theoretical evidence: learning with errors has a reduction tying random instances to worst-case lattice problems (Section 4.5 states both the theorem and its limits), whereas for codes the NP-completeness theorem covers only the worst case (Section 9.2), and HQC's specification notes among its own limitations that structured codes lack the search-to-decision reduction enjoyed by structured lattices. Confidence in code-based schemes rests directly on their record against attacks. The second difference is bandwidth: over \(\mathbb Z_{3329}\), each coordinate packs nearly twelve bits and small integers stay small when multiplied, whereas binary sparse polynomials multiply into much denser bit patterns that demand far longer blocks to decode.
Structured codes: HQC and BIKE
Public keys of a quarter of a megabyte or more are the price of publishing an unstructured matrix in full. Section 5 cut that cost for lattices by building matrices from polynomials so that a single first row determines an entire block. Codes can use the exact same trick, yet giving a hidden Goppa-like code extra cyclic symmetry has repeatedly exposed its private decoder to key-recovery attacks. HQC avoids that trap by hiding no private decoder at all: instead of scrambling a private algebraic code as McEliece does, it pairs a completely public error-correcting code with noisy polynomial equations whose only secret is sparse random noise.
plane the public key (across) against the ciphertext (up), in bytes, both scales logarithmic; a dot a scheme,
a line a family through its security categories 1, 3 and 5
category 1 category 3 category 5
Classic McEliece 261,120 / 96 524,160 / 156 1,044,992 / 208 a huge key, a tiny ciphertext
HQC 2,241 / 4,433 4,514 / 8,978 7,237 / 14,421 a few kilobytes of both
BIKE 1,541 / 1,573 3,083 / 3,115 5,122 / 5,154
ML-KEM 800 / 768 1,184 / 1,088 1,568 / 1,568 about one kilobyte of each
X25519, today's 32 / 32
lanes the bytes one key agreement sends, the key one way and the ciphertext back, a lane to a family:
X25519 64; ML-KEM-768 2,272, which is 35.5 times as many; HQC-3 13,492; Classic McEliece's
parameter set of category 3 524,316
(the live figure needs JavaScript and loads about 0.2 MB of data)
Almost every scheme sends a key and a ciphertext of about the same size, and each family keeps to a corner of its own. At security category 3, ML-KEM-768 sends an encapsulation key, as its standard calls the public key, of 1,184 bytes and gets back a ciphertext of 1,088; Classic McEliece's parameter set sends 524,160 and gets back 156; HQC-3, the structured code, sends 4,514 and gets back 8,978. Structure makes the key 116 times smaller than Classic McEliece's and leaves it several times ML-KEM's. Nothing of HQC, or of BIKE below, runs in these pages: every number for them is from their specifications or from NIST's report.
The polynomial structure mirrors Section 5.2, with bits in place of integers modulo \(q\). Take binary polynomials in \(\mathbb F_2[X]/(X^n - 1)\) for a prime length \(n\): multiplying any polynomial by \(X\) rotates its \(n\) bit coefficients by one step, so a single polynomial \(h\) compactly represents an \(n \times n\) circulant matrix whose rows are the cyclic shifts of its first row, compressing \(n^2\) matrix bits into \(n\). Codes built from such blocks are called quasi-cyclic, the QC in HQC (Hamming Quasi-Cyclic). Because sparse binary polynomials produce substantial residual bit flips when multiplied together, HQC also uses a fixed, publicly known error-correcting code \(G\) to cushion the message bits before masking them under polynomial noise, playing the role that scaling by \(\lceil q/2 \rfloor\) plays in ML-KEM. NIST's fourth-round status report introduces the resulting scheme through that parallel.
Design. HQC is similar in structure to Learning with Errors (LWE)-based cryptosystems, like Regev [29], LPR (Lyubashevsky, Peikert, Regev) [30], and ML-KEM [14]. The IND-CPA-secure public-key encryption (PKE) can be described as follows.
—G. Alagic and others, NIST IR 8545, "Status Report on the Fourth Round of the NIST Post-Quantum Cryptography Standardization Process" (2025). Section 3.1. Regev's scheme is that of Section 4.3, and LPR is its version over a ring of polynomials (Section 5.3). IND-CPA security is security against an eavesdropper who only watches; the stronger kind a key encapsulation needs comes from a wrapper, as in Section 6.5.
Definition 9.5.1 (HQC's encryption). Let \(R = \mathbb F_2[X]/(X^n - 1)\) for a prime \(n\) such that \(X^n - 1\) has only two irreducible factors. Fix a code of dimension \(k\) with generator matrix \(G\) and a decoder, both public, and weights \(\omega\), \(\omega_r\) and \(\omega_e\). Key generation draws \(h \in R\) uniformly and \(x, y \in R\) of weight \(\omega\); the public key is \(h\) with \(s = x + h\,y\), and the private key is \((x, y)\). To encrypt \(m \in \mathbb F_2^k\), draw \(r_1, r_2 \in R\) of weight \(\omega_r\) and \(e \in R\) of weight \(\omega_e\), and send
\[u = r_1 + h\, r_2 , \qquad v = mG + s\, r_2 + e . \tag{9.4}\]To decrypt, run the decoder on
\[v - u\,y \;=\; mG + \bigl(x\, r_2 - r_1\, y + e\bigr) . \tag{9.5}\]Set beside the encryption inside ML-KEM, it is the same scheme with the words changed.HQC team, "Hamming Quasi-Cyclic (HQC)", specification version 5.1 of 9 November 2026; the scheme is from Aguilar-Melchor, Blazy, Deneuville, Gaborit and Zémor, "Efficient encryption from random quasi-cyclic codes", IEEE Transactions on Information Theory 64(5), 2018. Definition 9.5.1 follows the summary in NIST IR 8545, Section 3.1. The condition on \(n\) shuts out attacks that work through the factors of \(X^n - 1\); the specification takes the first such prime above the length of the public code and cuts \(v\) back to the code's length, 5, 11 and 37 bits short of \(n\) in its three parameter sets.
| ML-KEM (Section 6.1) | HQC | |
|---|---|---|
| words | polynomials modulo \(X^{256} + 1\), coefficients modulo 3,329 | polynomials modulo \(X^n - 1\), coefficients bits |
| small means | every coefficient close to zero | few coefficients equal to one |
| public key | \(A\) and \(t = As + e\) | \(h\) and \(s = x + h\,y\) |
| ciphertext | \(u = A^{\top} r + e_1\), \(\;v = t^{\top} r + e_2 + \lceil q/2 \rfloor\, m\) | \(u = r_1 + h\,r_2\), \(\;v = mG + s\,r_2 + e\) |
| decryption | \(v - s^{\top} u = \lceil q/2 \rfloor\, m + (e^{\top} r + e_2 - s^{\top} e_1)\), then round | \(v - u\,y = mG + (x\,r_2 - r_1\,y + e)\), then decode |
| the message rides on | a scaling: zero or half the modulus in each coefficient | a public code: 128 bits spread over 17,664 in HQC-1 |
Remark 9.5.2 (nothing is hidden in the code). HQC is built on codes, and it is not McEliece's idea. The code it decodes with is public: for HQC-1 a Reed-Solomon code that turns the 16 bytes of the message into 46, each of which a Reed-Muller code then spreads over 384 bits, two classical codes with a decoder anyone can run. The private key is the sparse pair \((x, y)\), and the public \(s\) is its syndrome in the sense of (9.1), under the check matrix made of the identity and the rotations of \(h\). Recovering the key is syndrome decoding as it stands in Definition 9.2.1, and the specification says of its code that, unlike in many code-based schemes, it need not be indistinguishable from a random one.
How hard is that key to find? In HQC-1 the polynomials have 17,669 coefficients and \(x\) and \(y\) have 67 ones each, so the key is an error of weight 134 in a code of length 35,338 and rate 1/2, the rate at which Example 9.2.2 found each error to double the attempts. The rotations help the attacker by a factor of about \(\sqrt n\): each of the \(n\) rotations of the key is as good as the key, and an attack that may stop at any one of \(n\) targets saves about the square root of their number. The specification gives the cost of the best attacks as a formula of this kind and assigns its three sets to categories 1, 3 and 5; it publishes no count of operations.HQC specification, version 5.1, Section 6.3. What its security proof assumes is that this decoding problem is hard in its decision form and for quasi-cyclic codes: an assumption about structured codes that goes beyond the random codes of Section 9.2, as the module structure of ML-KEM goes beyond plain learning with errors (Section 5.6).
In (9.5), multiplying by the receiver's sparse polynomial \(y\) plays the exact role of the short secret in ML-KEM: it cancels the dense masking term \(h\,r_2\,y\) and leaves behind only combinations of sparse polynomials. Over bits, however, sparseness expands rapidly under multiplication. In HQC-1, \(x\) and \(y\) have 67 ones each while \(r_1\), \(r_2\) and \(e\) have 76 ones each. Multiplying a 67-one polynomial by a 76-one polynomial can set up to \(67 \times 76 = 5{,}092\) positions to one; after overlaps cancel modulo 2 across \(x\,r_2 - r_1\,y + e\), each bit of the residual noise in (9.5) equals one with probability 0.3449, flipping just over a third of all bits.HQC specification, version 5.1, Section 6.1: Proposition 6.1.2 gives the probability and Table 12 its value for HQC-1 (0.3636 for HQC-3 and 0.3750 for HQC-5, Table 14). The codes are in its Tables 6 and 7, the weights and sizes in Tables 8 and 9. To an eavesdropper without \(y\), the codeword \(mG\) sits under \(s\,r_2\), which by the scheme's security assumption looks like fair coin tosses with half of its bits flipped. Knowing \(y\) lowers the bit-flip rate only from one half to roughly one third, and that gap between 50% and 34.5% is the entire advantage of holding the private key. Recovering the message across a channel that flips a third of its bits requires heavy redundancy: HQC-1 spreads a 128-bit message across 17,664 bits. That redundancy explains the byte counts: a ciphertext sends two polynomials (\(u\) and \(v\)) of roughly 17,669 bits each, while a public key sends one polynomial (\(s\)) alongside a 32-byte seed that regenerates \(h\). By contrast, ML-KEM-768 carries 256 message bits inside a single 256-coefficient polynomial.
Decryption fails when the noise of (9.5) is more than the public code corrects. How often is a property of the parameters, and the specification bounds it: below \(2^{-127}\) for HQC-1, \(2^{-192}\) for HQC-3 and \(2^{-256}\) for HQC-5. Classic McEliece has no such number, since its sender adds exactly as many errors as the decoder removes; ML-KEM has one (Section 6.3). The bound has to be that small for two reasons. The proof that the wrapper of Section 6.5 turns an encryption scheme into a safe key encapsulation needs failures to be about as rare as a successful attack is meant to be, one in \(2^{\lambda}\) at a security level of \(\lambda\) bits. And a failure that an attacker can observe is not a harmless glitch: whether decryption fails depends on the private key, as it did in the attack of Section 6.4. This is how an attack of that kind on a code-based scheme describes itself; the scheme used QC-MDPC codes, quasi-cyclic codes with a sparse parity-check matrix.
In this work we present a very efficient key recovery attack on the QC-MDPC scheme using the fact that decryption uses an iterative decoding step and this can fail with some small probability. We identify a dependence between the secret key and the failure in decoding. This can be used to build what we refer to as a distance spectrum for the secret key, which is the set of all distances between any two ones in the secret key. In a reconstruction step we then determine the secret key from the distance spectrum. The attack has been implemented and tested on a proposed instance of QC-MDPC for 80 bit security. It successfully recovers the secret key in minutes.
—Q. Guo, T. Johansson and P. Stankovski, "A key recovery attack on MDPC with CCA security using decoding errors" (2016). Asiacrypt 2016, ePrint 2016/858; the passage is the second of the abstract's three paragraphs. An attack of the same kind on HQC followed (Guo and Johansson, "A new decryption failure attack against HQC", Asiacrypt 2020, as cited in NIST IR 8545), and NIST IR 8545 dates HQC's dropping of the parameter sets that aimed at a higher failure rate to May 2020.
BIKE (Bit Flipping Key Encapsulation), the other structured-code candidate in NIST's fourth round, takes the hidden-code route instead using QC-MDPC codes of the kind just quoted: its private key is a sparse quasi-cyclic parity-check matrix, published in systematic form as in Remark 9.3.2, and its iterative decoder flips suspect bits round after round until every parity check passes or the decoder gives up. Its keys and ciphertexts are smaller than HQC's, at 1,541 and 1,573 bytes for category 1 compared with 2,241 and 4,433. Rigorously bounding how often an iterative bit-flipping decoder gives up, however, proved difficult. In 2023 researchers found a class of weak keys that raises BIKE's average category 1 failure rate to at least \(2^{-117}\), above its \(2^{-128}\) target, and NIST's fourth-round report cites HQC's firmer decryption-failure analysis as the decisive reason for selecting HQC over BIKE.NIST IR 8545, Sections 3.1 and 3.2; the weak keys are from Wang, Wang and Wang (CRYPTO 2023). BIKE's sizes are those of its round-4 specification.
Why a second key-encapsulation standard
On 11 March 2025 NIST chose HQC to stand beside ML-KEM.
NIST has chosen a new algorithm for post-quantum encryption called HQC, which will serve as a backup for ML-KEM, the main algorithm for general encryption. HQC is based on different math than ML-KEM, which could be important if a weakness were discovered in ML-KEM. NIST plans to issue a draft standard incorporating the HQC algorithm in about a year, with a finalized standard expected in 2027.
—NIST, "NIST Selects HQC as Fifth Algorithm for Post-Quantum Encryption" (2025). The opening lines of the news release of 11 March 2025. The report behind the choice is NIST IR 8545.
The reason is in the word backup. As of November 2026 ML-KEM is NIST's only post-quantum standard for key encapsulation, and it rests on structured lattices; the report says that NIST values a variety of hardness assumptions and wants to reduce the risk that a single cryptanalytic breakthrough leaves it with no viable standard for key establishment.NIST IR 8545, Section 2.2.1. The parallel of Section 9.4 is one of outline. The best attacks known on the two problems are different algorithms, and that difference is what a hedge needs.
Why NIST chose HQC among the three fourth-round code-based candidates comes down to the three trade-offs traced in this part. Classic McEliece pays in public-key size: NIST's report found limited appetite for keys of hundreds of kilobytes, judged the scheme a poor fit for web connections under TLS, and noted that commenters saw it suited mainly to settings where a public key is fetched once and reused many times, such as file encryption or virtual private networks. BIKE keeps both keys and ciphertexts compact, yet pays in uncertainty over its decryption-failure rate. HQC combines a clean failure bound with moderate keys, paying instead in total handshake bandwidth: at category 3, one key exchange sends 13,492 bytes (public key and ciphertext together), 5.9 times the 2,272 bytes of ML-KEM-768.
As of November 2026 none of the three is a NIST standard. For HQC the year of the announcement has passed: the standard has a number in NIST's series of federal standards, FIPS 207, and on 30 November 2026 NIST's pages listed no draft of it; the list of selected algorithms said "FIPS coming soon".NIST's pages of selected algorithms and of news (both updated on 27 October 2026) and its list of drafts open for comment, read on 30 November 2026. The number is from a NIST presentation of 25 September 2025, "FIPS 207: HQC-KEM". The specification is still moving: version 5.1, of 9 November 2026, raised weights by one and made the private key a 32-byte seed, and its sizes, the ones used in this part, differ by less than 2% from those in NIST's report. Classic McEliece is out of NIST's process. ISO, the International Organization for Standardization, standardized it in June 2026, by its team's account, and NIST said in 2025 that once ISO was done it might consider a standard of its own based on ISO's.NIST IR 8545, Section 2.3. The news of the ISO standard is from the Classic McEliece team's own page (version of 15 June 2026), which lists the four larger parameter sets as included and not the smallest, the one drawn in this part.
The thread of the series runs through this part unchanged: a problem that is linear algebra until a few errors are added, a secret that takes the errors away, and a price in bytes and in care. Section 10 turns to the candidates that did not hold and to what speaks for the ones that did; Section 11 to what these sizes do to a real connection.