How Sure Can You Be? Fault Replay for AES-GCM

The detailed reasoning behind trusting a fault-injection match: base rates, why GHASH's linearity is a trap, equivalent faults, and controls.

This is the long version of the “how sure can you be?” section in Proving Mercurial CPU Cores Offline. The setup: you have the exact inputs to an AES-GCM encryption, the corrupted output, and an emulator that can replay the computation with one injected hardware fault at a time. Some fault reproduces the corrupted output exactly. How much should you believe it?

“The emulator found a fault that explains it” is only convincing if a wrong explanation is unlikely to match too.

The base rate

Suppose the corruption was caused by something other than any fault in your model: a software bug, a memory error, anything. Then relative to what each candidate fault predicts, the observed tag is effectively a random 128-bit value. Each candidate matches by chance with probability 2⁻¹²⁸, so across the whole search:

P(false match) ≤ |F| / 2¹²⁸

where |F| is the number of candidate faults: executed instructions × fault sites × patterns × positions.

That’s generous to the skeptic. Say there are a few thousand instructions, a handful of sites, ten patterns, and 128 positions each: around 2²⁴ candidates. The chance of a coincidental match is still around 2⁻¹⁰⁴, less likely than winning the Powerball jackpot three times in a row.

A useful way to think about it: you have roughly 128 − log₂|F| bits of evidence. Trying more fault models costs you very little. Doubling the search space spends one bit.

Specific faults (single-bit, word flips, …) · |F| ≈ 2²⁴

24 bits spent on the search 104 bits of evidence left

Arbitrary GHASH-state corruption · |F| = 2¹²⁸

all 128 bits spent: it explains every tag, so it proves nothing

The tag carries 128 bits. Every bit of freedom you give the fault model is one bit less of evidence.

The trap: a fault model that explains everything

Here’s the subtle part, and it’s specific to how GCM works.

GHASH is linear over GF(2¹²⁸). If some error δ is XORed into the GHASH accumulator with k multiplications by H still to go, the final tag changes by exactly:

Δ = δ · Hᵏ

H is nonzero, so it’s invertible. That means for any observed tag error Δ, there’s a δ = Δ · H⁻ᵏ that explains it. A fault model of “arbitrary corruption of the GHASH state” will reproduce every corrupted tag you ever feed it. It has 128 bits of freedom against 128 bits of evidence, so there are zero bits left over. It proves nothing.

The certainty comes entirely from the fault model being specific. A single-bit flip in one instruction’s output is one of 128 possibilities per site, not 2¹²⁸. The less your model can explain, the more a match means. Be suspicious of any fault model expressive enough to “find” an explanation every time, and run the negative control below to make sure yours isn’t.

Where the match lands matters

Not every match implicates the CPU. A bit flip in the final store of the tag is indistinguishable from the tag being corrupted later in memory or on disk. The tag error Δ is a single bit either way.

A fault inside GHASH is different. It gets multiplied through the remaining rounds, so the resulting Δ looks like 128 random bits. A memory or storage error after the fact could scramble the tag, but it has no reason to land on the exact value a single upstream bit flip predicts. Only a fault in the computation itself can. When the matching fault is deep in the GHASH multiply, there’s no “it got corrupted afterwards” explanation left.

Equivalent faults

Several faults can produce identical outputs. Flipping bit 3 of instruction N’s output is the same as flipping bit 3 of instruction N+1’s input when N+1 is the only instruction that reads that register before it’s overwritten. So the honest result isn’t “the fault was X”, it’s “the fault is in this equivalence class”. In practice the class is small and sits on a single data-flow path. If that path runs through one PCLMULQDQ, you’ve found your instruction.

Multiple samples

One matched sample shows a single hardware fault is a consistent explanation. Several samples matched by the same fault (same instruction, same bit) show something much stronger: a repeatable defect. That’s the signature of a mercurial core, and it separates it from a one-off random event like a particle strike, which would land somewhere different each time.

Controls

To trust any of this, you need three checks:

  • Emulator correctness. With no fault, the output must match a reference implementation bit-for-bit on many inputs. Otherwise every result is meaningless.
  • Positive control. Inject a known fault in the emulator, take that output, and confirm the search finds that fault.
  • Negative control. Feed the search corrupted outputs with random tags. It should find nothing. If it does, your fault model is too expressive.

Asymmetry

A match is strong evidence of a CPU fault. No match is weak evidence of anything: the real fault might be outside your model, involve two instructions, or be in code you didn’t emulate. The technique can convict; it can’t really acquit. An empty search means “not one of these faults”, never “not the CPU”.