Part I Chapter 3
Attacking one key byte
Chapter 1 gave the target, the intermediate value Sbox[plaintext ⊕ key], and showed that each key byte can be attacked on its own. Chapter 2 showed that a chip’s current follows the Hamming weight of the values it handles. Put the two together and you have an attack on one key byte.
Guess, predict, compare
The attacker has many traces, each with a known plaintext byte p and the same unknown key byte k. Assume for now that we know which sample leaks; Chapter 6 shows how to find it. For each of the 256 possible values:
- Guess a key byte
g. - Predict what the chip would have handled if
gwere the key: the Hamming weight ofSbox[p ⊕ g], for every trace. - Compare the predictions with the measurements. The guess whose predictions rise and fall with them is the key.
p | Measured | Predicted Hamming weight | |
|---|---|---|---|
true key 0x3C | wrong guess 0x3D | ||
0x0e | 2.8 | 3 | 4 |
0x34 | 2.9 | 2 | 1 |
0x20 | 3.6 | 4 | 3 |
0x44 | 4.2 | 5 | 5 |
0x5f | 6.4 | 7 | 4 |
0xf1 | 6.6 | 6 | 4 |
One bit of difference in the guess scrambles the prediction, because the S-box spreads it over about four bits of output (Chapter 1). A wrong guess can still match a few traces by luck, so an attack needs many.
The usual score for the compare step is the correlation between a guess’s predictions and the measurements: +1 when they rise and fall together, near 0 when they’re unrelated. On the six traces above, 0x3C scores 0.93 and 0x3D 0.44. Scoring every guess this way is correlation power analysis (CPA).
The prediction is called a label, and the rule that produces it a leakage model. Two are common: Identity (ID), the full S-box output (256 classes), and Hamming weight (HW), its number of 1 bits (9 classes, 0 to 8). For the first ASCADr attack trace used later in this guide (p = 0x8e, key byte 0x22), where popcount counts the 1 bits:
ID label = Sbox[0x8e ⊕ 0x22] = 145
HW label = popcount(145) = 3 (145 = 0b10010001)
A first attack, on simulated traces
The six traces above had little noise. Simulate the same unprotected chip with noise σ = 2, enough to blur the whole 0–8 range of weights, and run CPA with more and more traces:
| Traces | Rank (of 256) | Correlation | |
|---|---|---|---|
true key 0x3C | best wrong guess | ||
| 10 | 37 | 0.41 | 0.90 |
| 30 | 12 | 0.34 | 0.55 |
| 100 | 1 | 0.65 | 0.25 |
| 300 | 1 | 0.55 | 0.29 |
| 1,000 | 1 | 0.55 | 0.15 |
With 10 traces, some of the 255 wrong guesses line up with the measurements by luck, one of them at 0.90. More traces wash that luck out. The true key’s correlation doesn’t grow; it settles near 0.55, close to the 0.58 theory predicts for this much noise: the Hamming weight of a random byte has variance 2, so the expected correlation is √(2 / (2 + σ²)) = 0.58 at σ = 2.
Try it on the same simulated chip. Start with little noise, find the key, then raise the noise to σ = 2 and compare 10 traces with 100.
Real attacks repeat this for every sample in the trace, since nobody knows in advance which samples leak, and then for each of the 16 key bytes.
Hamming weight is a model the attacker picks, and it doesn’t fit every chip. In the Chapter 2 widget, a register that starts at 0x00 flips as many bits as the new value’s Hamming weight. One that overwrites an older value flips the Hamming distance between the two instead. Against that chip, Hamming-weight predictions correlate more weakly, and the attacker switches models.
Every version of this attack rests on two facts about the chip: it handles Sbox[p ⊕ k] itself, and it does so at the same sample in every trace. Can a chip be built that gives up both?