← Back to section · Research & Analysis

Experiment Design: Setting Up a Timing Side-Channel Measurement

Constant time is not established by reading code; it is measured. This design covers input grouping, clock choice and statistical testing for timing-leakage experiments — and why failing to detect a leak is not the same as there being none.

Published 22 November 2026 · 5 min read · PQ Frontier

Experiment Design: Setting Up a Timing Side-Channel Measurement
AI-generated site artwork
Video explainer · Experimental Research: Reproducible Designs

The research question: turn “constant time” into a testable claim

Code review often concludes that an implementation “looks constant-time”: no secret-dependent branches, no variable-length loops. But compilers rewrite, caches intervene, and speculative execution opens another path — a whole toolchain sits between source-level judgement and machine-level behaviour. The experimental claim for timing side channels must therefore live at machine level: under controlled conditions, are the execution-time distributions of the implementation under test statistically distinguishable between two classes of secret-related inputs?

Three elements are indispensable. Controlled conditions mean environmental noise is suppressed to a known level. Secret-related inputs mean the grouping must genuinely correspond to a secret property — one bit of a key, say, or the Hamming weight of a plaintext. Statistical distinguishability means the verdict comes from a test, not from two mean curves that “look separated”. With all three, the conclusion means something; missing any one, you have measured noise or an illusion.

Input grouping: half the experiment is the grouping

The grouping principle is to vary only the target secret property and randomise everything else. The classic design is fixed-versus-random: the fixed group executes the same target input repeatedly while the random group uses fresh random inputs; if the code has input-dependent timing, the fixed group’s distribution comes out sharper or shifted relative to the random group. Finer designs stratify by the secret property itself: split inputs by the value of one key bit, or bucket them by the Hamming weight of an intermediate value, and compare bucket by bucket.

For post-quantum implementations, the properties worth grouping first include: whether decapsulation of a ciphertext triggers a decryption failure, the number of rejections along a sampling path, and the number of non-zero entries in a sparse secret. Each corresponds to well-defined secret information in the algorithm specification, and before measuring you should write down, on paper, what an attacker could infer if this grouping proved distinguishable. If that sentence cannot be written, the property is not worth measuring — measurement effort belongs on properties with clear leakage semantics.

Sample size must be planned in advance. Timing differences often live at the scale of cycles or below; with too few samples the test lacks power and a negative result carries no information. Run a small pilot to estimate the noise level, back-derive the formal sample size from the target detectable difference, and write both numbers into the experiment record.

Clock and environment: resolution is the experiment’s floor

Prefer the processor’s cycle counter over a wall clock: wall-clock granularity and scheduling jitter drown cycle-level signals. Keep the measured region narrow — bracket only the function under test, not input construction, allocation or output handling, or you will time the scaffolding instead of the target code.

Environmental controls include fixing the CPU frequency or logging its variation, pinning to a core, silencing unrelated load on the machine, and warming caches and branch predictors before collection starts. Extra care is needed on virtual machines and shared cloud hosts: a neighbour’s load contaminates a few percent of samples with a long tail, which at best dilutes the signal and at worst manufactures false distinguishability — because contamination correlated with collection order becomes correlated with grouping. Interleave the two groups’ samples so that any slow environmental drift lands evenly on both; it is the cheapest, highest-yield move in the whole design. The total duration of a collection run also needs control: over a run of several hours, room and chip temperature changes are enough to create measurable slow drift, so collect in segments where necessary, re-warming and re-baselining between segments.

Statistical testing and interpretation

The primary test is Welch’s t-test comparing the two groups’ means, the most mature tool in timing-leakage detection: an absolute t value above the conventional threshold (4.5 in practice) marks the groups as distinguishable. Two interpretation disciplines apply. First, guard against false positives across many measurement points: testing dozens of points makes a chance crossing inevitable, so a conclusion requires the crossing to reproduce in an independent repeat experiment. Second, significant is not exploitable: a statistically distinguishable difference of a few cycles is still a long way from an attacker recovering a key under real network noise, so the report should state “leakage detected” and “assessment of exploitability” separately — the latter needs a separate attack experiment and lies outside this one’s evidence.

A negative result must report its detection floor: below how many cycles of group difference this experiment, at its sample size and noise level, cannot rule out. A negative result with a stated floor is valid evidence; one that merely says “no leakage found” should be treated in review as if the experiment had not been run.

Common pitfalls

First, timing cycle-level differences with a millisecond wall clock from a high-level language — measuring hair with a metre stick. Second, collecting the groups in separate blocks: run all of the fixed group, then all of the random group, and thermal or frequency drift gets booked as a group difference. Third, measuring only the warmed-up steady state: real attacks face cold caches and first executions, and steady-state-only testing misses an entire class of leakage. Fourth, equating detected leakage with a useless implementation: the correct output is locating the leak’s source and feeding it back to the implementer, not a death sentence. Fifth, forgetting to test the fixed version: half the value of a timing experiment is regression — rerun the same setup after every implementation change, or leaks quietly return.

Tags: Side ChannelsConstant TimeTiming MeasurementExperiment Design