Part I Chapter 2
How a chip leaks its key
Contents
A laptop’s fan spins up when it renders a video and goes quiet when it sits idle; a phone warms up during a game. How much power an electronic device draws depends on what it’s doing, and that stays true down to a single operation inside a chip.
AES is secure on paper, but a chip running AES is a physical object. It draws current, radiates electromagnetic fields, and takes time for each operation, and all three depend on the data being processed. That includes the intermediate value from Chapter 1, which depends on the key. An attack that measures these physical effects instead of attacking the mathematics is a side-channel attack. This chapter follows the leak from one transistor to a file of measurements.
Why changing a bit costs energy
Every bit a chip stores in a register or carries on a wire is a tiny piece of conductor held at one of two voltages: high for 1, low for 0. The conductors and the transistors that drive them are built in layers on a slab of silicon. This is one logic cell, the kind of building block a chip is assembled from by the million:

Modern chips build this logic in CMOS (complementary metal-oxide-semiconductor). Every gate pairs two kinds of transistor, and each works as a switch: a P-type transistor connects the output to the supply voltage, an N-type connects it to ground. The input turns exactly one of them on, so the output is either 1 or 0, and current never has a direct path from supply to ground.
Holding a bit steady draws almost no current. Changing it does. The wire a gate drives, together with the inputs of the gates it feeds, behaves like a small capacitor. When the output goes from 0 to 1, the P switch connects the wire to the supply and current flows in to charge it. When it goes from 1 to 0, the N switch dumps that charge to ground:
Chips do their work in step with a clock: on each tick, registers load new values. Bits that change draw a pulse of current, bits that stay the same draw nothing, and the pulses of every bit that changes on the same tick add up in the chip’s supply line. The more bits flip, the bigger the spike. Here is that rule on one 8-bit register; set the next value and press Clock tick:
From bit flips to a leakage model
The number of bits that differ between a register’s old value and its new value is their Hamming distance. Count the flips and you have a first model of the current drawn at that clock tick.
Often the old value is a constant, for example a bus that is reset to zero before each new value. Then the Hamming distance is just the number of 1 bits in the new value, its Hamming weight. When the first S-box output from Chapter 1, 0xb5 = 1011 0101, is written over zero, five bits flip:
old = 0000 0000
new = 1011 0101
flips: ^ ^^ ^ ^ → Hamming distance 5 = Hamming weight of 0xb5
A value with Hamming weight 5 draws a little more current than one with weight 3. The difference is tiny, but it’s systematic, and it depends on the key.
Real silicon is messier: wires have different capacitances, neighbouring bits interact, and some bits leak more than others. Hamming weight is an approximation that works well enough on many devices. Chapter 3 treats it as what it is: a model the attacker chooses.
Measuring the current from outside
There are two common ways to watch those currents from outside the chip:
- Power: put a small resistor in the chip’s supply line. All the current the chip draws flows through it, and by Ohm’s law the voltage across it is V = I·R, so the current pulses described above become voltage pulses.
- Electromagnetic (EM): a current creates a magnetic field around its wire. When the current changes, so does the field, and a changing field induces a voltage in a nearby coil. A probe with a small coil at its tip, held just above the chip, picks that up without touching the circuit, and it can be moved over the die to the area that does the cryptography.
Both carry information about the same bit flips.
What is a power trace?
An oscilloscope samples that voltage at a fixed rate, millions of times per second, while the chip encrypts. One encryption gives one recording: a list of numbers, one per time step. That recording is a power trace, and each number in it is a sample. The guide uses the same name for EM recordings.
A dataset is this loop run thousands of times. The trigger is what makes the traces comparable: the chip signals the moment it starts encrypting (in a lab, its firmware raises a pin), and the oscilloscope starts recording on that signal. So sample 500 is the same instant of the computation in every trace, which is why the three traces in the table line up. Each trace is stored next to its plaintext because an attack needs both: the trace shows what the chip did, and the plaintext lets the attacker predict what it would have done under each key guess.
Here is one real trace from each of the three datasets in this guide. Each covers the first round of one AES encryption (the files are windows around that round, not whole encryptions; see Chapter 5):
To the eye these look like noise, and mostly they are. Everything else the chip does at the same moment draws current too, and so do the measurement setup and thermal noise. The few samples that depend on the S-box output vary by much less than that background. One trace can’t tell a Hamming weight of 5 from a weight of 3.
Many traces can. Record thousands of encryptions with known plaintexts and the noise averages out, while the part that follows the intermediate value doesn’t.
The simulator below puts the pieces together: it runs a whole AES-128 encryption on a model chip whose current follows its bit flips, like the register above. Step through the operations to see which bits switch at each one, then record a few hundred noisy traces and watch the step that computes the first S-box output stand out.
The attacker’s task is to find which samples leak, then use them to recover the key. Chapter 3 does the second step, assuming the leaking sample is known; Chapter 6 does the first, on real traces.
Why deep learning, and what we are after
The classical attack in Chapter 3 starts from a guess about how the chip leaks, chosen by hand: for example, “the current follows the Hamming weight of the S-box output.” It computes that prediction for every key guess and tests it against every sample of the trace. Where the leak is comes out of the test: it’s the sample where the prediction fits.
That works when one sample is enough, and on the datasets in this guide it isn’t: all three are masked (Chapter 4). Masking splits each secret byte into two random-looking shares, and the chip handles them at different points in the trace. No single sample reveals anything; the leak is only in the pair. The attacker now has to find the right pair as well as the right model, and a 15,000-sample CHES_CTF trace has about 1.1 × 108 pairs.
Deep learning hands both choices to the network. It’s trained on traces from a device whose key is known, each paired with the S-box output it should predict, and it learns on its own which samples matter and how to combine them.
The cost is interpretability. A network that recovers the key proves the leak is there, but doesn’t say which samples it used or how it combined them. Finding that out is what this guide is after.