Definition
A side channel is a path by which information about a secret leaks through a measurable effect of a computation rather than through its intended output. Such effects include the time an operation takes, which memory locations it loads into the processor’s fast cache memory, the power the chip draws, its electromagnetic emissions, and the sizes and timing of its messages. A program can produce exactly the right output, reveal nothing in that output, and still leak its key through a side channel. A side-channel attack exploits such a leak.
The idea
A device checks a 16-byte tag, a value computed from a message and a secret key, by comparing it one byte at a time with the tag it computes itself, and it stops at the first byte that differs. An attacker sends a message with a made-up tag and measures how long the device takes to reject it. A tag whose first byte is right is rejected slightly later than one whose first byte is wrong, because the comparison went one byte further. Trying all 256 values of the first byte and keeping the slowest finds that byte. Repeating this for each byte finds the whole tag, and the attacker has forged a tag without ever learning the key.
The secret steers what the processor does, and whatever the processor does costs time, memory traffic and energy. If those costs differ with the secret and someone can measure them, they carry the secret out. A safe-cracker listening to the clicks of a combination lock is a fair picture: the lock never opens, yet each click says whether one digit is right. The picture stops being accurate in one respect: a computer’s differences can be a few nanoseconds, far below what one measurement shows, and the attacker wins by averaging many measurements.
How it works
Finding side channels starts from the observer and then follows the secret.
Name the observer and what it can measure. A remote client measures response times §9.32 across a network, coarsely and with noise, but can repeat chosen requests. A program on the same processor can find out which cache lines, the small blocks of memory that the processor keeps copies of in fast storage, another program used. Someone holding the device can measure its power use or electromagnetic emissions.
Follow every secret value through the code, and mark each place where it decides a cost:
a branch or loop exit whose condition depends on the secret, such as the early exit above;
a memory access whose address depends on the secret, such as a table lookup with a key byte as the index, which leaves a secret-dependent trace in the cache;
an instruction whose duration depends on its operands, as division does on many processors;
an output size or sending time that depends on the secret, such as data compressed before it is encrypted, whose length shows how repetitive it is;
the data values themselves, which change power use and emissions even when the time and the addresses are fixed.
Decide whether each mark reaches the observer. A difference far smaller than the noise of one measurement still shows if the attacker can repeat the measurement often enough.
Remove the dependence. Constant-time programming §5.36 writes code whose branches, memory addresses and variable-time instructions never depend on secret data; it closes timing and cache channels. Masking, which splits each secret into random parts that are processed separately so that no single intermediate value relates to the secret, works against power and emission channels. Padding messages to fixed sizes hides lengths.
Worked example
A device compares a submitted 16-byte tag with the correct one. Each byte compared takes 4 ns, and the comparison stops at the first mismatch. The rest of the response takes 0.2 ms and varies randomly, with a standard deviation §11.14, the typical size of the variation, of 400 ns.
A guess whose first byte is wrong compares 1 byte: 4 ns. A guess whose first byte is right and second byte wrong compares 2 bytes: ns. The difference is 4 ns, one hundredth of the noise.
Assume that the noise of each measurement is independent of the noise of the others: knowing one noise value tells nothing about another. Then averaging measurements divides the standard deviation of the noise by . Noise that many measurements share, such as a slow drift in network delay, does not shrink this way. With , the noise left in the average is ns, ten times smaller than the 4 ns step, so the right byte stands out.
The attacker tries at most 256 values for each of the 16 bytes: guesses, against for guessing the whole 128-bit tag blindly.
At 1,000,000 measurements per guess, the attack needs measurements. At 0.2 ms each, that is ms, which is 819,200 s, about 9.5 days.
The repair is a constant-time comparison §4.33, which looks at every byte whatever happens. Let and be the -th bytes of the two tags, let be exclusive or (XOR), which gives a 1 bit wherever two bits differ, and let be bitwise OR. Compute ; the tags are equal exactly when . For example, , so one differing bit makes nonzero. The loop always runs 16 times, and its time no longer depends on where the first difference lies.
Stated precisely
Fix an observer and a leakage model: the list of what that observer can measure. Let be what the observer measures when the program runs with secret and public inputs ; because of noise, is a random variable, a quantity with a probability distribution. The program leaks nothing through this channel if, for every and for every two secrets and that give the same intended output on , the distributions of and are equal. This is noninterference §1.42 applied to the observer’s measurements.
Constant-time code meets this condition for one leakage model, in which the observer sees the sequence of instructions executed, the sequence of memory addresses accessed and the operands of variable-time instructions. It does so under two assumptions.
The processor’s timing and cache behavior depend on nothing else.
The compiler and linker §12.4 keep the code’s secret-independent form in the machine code.
Power and emission channels lie outside that leakage model, because they depend on the data values themselves.
Limits and common mistakes
Constant time is not constant power. Code with fixed timing still draws power that depends on the bits it processes.
A compiler can turn branch-free source code back into a branch. Check the machine code, not only the source.
Speculative execution, in which a processor runs instructions ahead of time and discards them if they were not needed, can leave secret-dependent traces in the cache from instructions that the program never officially ran. The Spectre attacks, disclosed in 2018 [252], exploit this, and code that is constant-time in the usual sense does not by itself prevent them.
A test that finds no timing difference does not prove that none exists. More measurements, another processor or another compiler setting can reveal one.
A cost that depends only on public data, such as the length of a message everyone can see, leaks no secret. It matters for denial of service §1.28 instead.
Encryption hides content, not size or timing. Traffic analysis §5.47, inferring information from the sizes and timing of encrypted messages, can reveal what they contain.
A side-channel attack only observes. A fault attack, which disturbs the device with a voltage glitch or a laser so that it computes wrongly, is a separate, active class.
Questions answered
Which observable costs depend on key bytes or secret branches?
The costs of every operation whose control flow, memory address, operand-dependent instruction time or output size is decided by secret data depend on key bytes or secret branches. Each becomes a side channel, a leak through a measurable effect rather than through the output, when the observer can measure it, if necessary by averaging many measurements. Follow each secret value through the code and mark:
branches and loop exits whose condition depends on it, including early returns such as a byte-by-byte comparison that stops at the first mismatch, which change the running time;
memory reads and writes whose address depends on it, such as table lookups indexed by key bytes, which change which data the processor’s cache holds;
instructions whose duration depends on their operands, such as division on many processors;
output lengths and sending times that the secret decides, such as compression before encryption;
power use and electromagnetic emissions, which depend on the secret data values themselves even in code whose timing is fixed.
Code that avoids the first three for all secret data is called constant-time, and it closes the timing and cache channels when the compiler and processor preserve its form. Fixed-size padding addresses the fourth, and masking, splitting secrets into random parts, addresses the fifth.
Related entries: Constant-time cryptographic implementation (§5.36), Constant-time comparison (§4.33), Traffic analysis defenses (§5.47), Noninterference (§1.42), Fault injection (§10.28). Further reading: [252].