Timing Attack on a Byte-by-Byte Compare: Jitter and Samples Needed

A server rack with one lock dial per secret byte and a bench of timing bars: the right candidate is slightly taller, but jitter makes the bars wobble. Drag to orbit.

Switch to 2D
Controls

Presets

Parameters

Quality

Camera

Model checks

The science

The leak. A comparison that stops at the first wrong byte takes slightly longer the more leading bytes match: T = T0 + δ·k + noise, where k is the length of the correct prefix and the noise on one request is Gaussian with standard deviation σ (network jitter). δ is tiny (tens of nanoseconds), σ is usually far larger, so one request tells the attacker almost nothing. Averaging n requests shrinks the noise to σ/√n.

One byte. For the next byte the attacker tries A candidates; the right one is on average δ slower. With d = δ√n/σ the chance that the right mean is the largest of the A means is the exact integral P = ∫ φ(z - d) Φ(z)A-1 dz. For A = 2 this is Φ(d/√2); for d = 0 it is 1/A, pure guessing. The whole secret of L bytes falls with probability PL, and costs L·A·n requests.

Defence. Compare in constant time (accumulate the XOR of every byte pair, decide once at the end), or compare keyed hashes of both sides. The slider removes part of the leak: even a small remaining δ only needs more samples, because d grows with √n, which is why only a full fix is a fix. Rate limiting and noise injection raise the cost but do not remove the leak.

Simplifications. Independent Gaussian noise with a known, constant σ (real jitter is heavy-tailed, so attackers use the minimum or a percentile, not the mean); the attacker knows the alphabet size; a wrong pick ends the attempt (a real attacker would notice a stalled signal and backtrack); one byte is leaked per step. This is a defensive demonstration of why constant-time comparison matters. Checks: Monte Carlo of the attack against the exact integral, a whole-secret simulation against PL, the closed form for two candidates, the no-leak limit 1/A, and the 95 % sample count against the normal quantile.

Loading model...
Loading Blender model...
-
-
Made with 🟠 Blender · Three.js