Part II Chapter 9
From probabilities to the key
Contents
The networks of Chapter 8 output, for each trace, a probability for every value of the label. None of them ever names a key byte. Chapter 3 already showed how to get from labels to a key byte: guess the key, predict the label each guess implies, and compare the predictions with the traces. An attack with a network keeps the first two steps and changes the third. The score for a guess is no longer a correlation; it is how much probability the network gave to the label that guess predicts.
The network’s vote for each key guess
Take the first ASCADr attack trace. Its plaintext byte is p = 0x8e, and the network was trained on identity labels, the full value Sbox[p ⊕ k], so it outputs 256 probabilities. For each key guess g, the label it predicts is Sbox[0x8e ⊕ g], and the network’s vote for g is the probability it gave that label:
guess g label Sbox[0x8e ⊕ g] vote
0xb9 154 0.247 ← this trace's favourite
0x15 20 0.194
0x99 240 0.089
…
0x22 145 0.000005 ← the true key, 81st of 256
For a fixed plaintext, each of the 256 guesses predicts a different label, so the vote table is the network’s output reordered by key guess. The network’s favourite value, 154, points to 0xb9, which is wrong. On this trace the true key gets almost nothing. Chapter 7 saw the same thing from the other side: one trace is not enough.
Models with Hamming-weight labels, like those for ESHARD and CHES_CTF, output only 9 probabilities. Then many guesses predict the same weight and share the same vote, so each trace separates the guesses more coarsely.
Adding up the votes
What stays the same from trace to trace is the key. The plaintext changes, so the true label sits at a different value on almost every trace, and averaging the network’s outputs would blur together values that have nothing to do with each other. The votes are already arranged by key guess, so they can be combined directly.
The question for each guess is whether all the traces together fit it. Treating the traces as independent, the chance that they all fit is the product of the votes. A product of hundreds of small numbers underflows to zero on a computer, so attacks add logarithms instead, which gives the same order:
The guess with the most evidence is the attack’s answer, and the rank of the true key, as in Chapter 3, is its place in that order: 1 means the attack found it.
A logarithm punishes near-zero votes hard. A vote of one in a million adds −13.8, about as much as a dozen votes of 0.3 add together. Every guess collects some of those, the true key included. What makes the true key win is that it collects fewer: over the ASCADr attack set, its vote falls below one in a million on 36% of traces, a wrong guess’s on 54%.
Watch the votes add up
These are the real outputs of the trained ASCADr network for its first 150 attack traces. The top panel is the latest trace’s vote for each key guess; the middle panel is the evidence summed so far; the bottom panel tracks the true key’s rank.
In file order, the first trace ranks the true key 81st and five traces bring it to 30th. At 17 traces it leads for the first time, but it doesn’t stay there: a run of unlucky traces pushes it back into the twenties around trace 28, and it only holds first place for good from trace 76. All along, single traces keep ranking it far down; only the sum is steady. Shuffle the order and the path changes: some orders find the key sooner, some later.
Guessing entropy
Because the rank depends on which traces happen to be used, an attack is judged by its average. Guessing entropy (GE) is the mean rank of the true key over many random draws of attack traces. The paper’s code draws 40 random sets of up to 4,000 traces from the 10,000 in each attack set. A GE of 128 is what random guessing gives; a GE near 1 means the key is found almost every time. The count usually quoted, “traces to GE = 1”, is read in the code as the number of traces after which the mean rank stays below 2. The dashed line in the widget is that average for ASCADr.
Running the same procedure on the three published models:
| Dataset | Labels | Model | Traces to GE = 1 |
|---|---|---|---|
| CHES_CTF | Hamming weight (9) | MLP, epoch 200 | 14 |
| ASCADr | Identity (256) | MLP, epoch 100 | 86 |
| ESHARD | Hamming weight (9) | MLP, epoch 100 | 633 |
The number measures how hard a target is for a given attack: how much usable signal each trace leaves after the chip’s countermeasures and the measurement noise. It is a property of the device and the attack together. A better model can lower it without the chip changing, and the three rows aren’t a controlled comparison: the models, labels and trace lengths differ. Still, it is the figure an evaluator reports, and a countermeasure that raises it bought protection against this attacker, even before anyone knows what the network uses.
When does the attack start to work?
The checkpoints let us ask that question for every epoch. Here is ESHARD again, with its attack loss from Chapter 8 on top and, below it, the traces needed to recover the key at each epoch:
For the first four epochs the attack fails: with 4,000 traces the mean rank is still around 130, no better than guessing, and at epoch 4 it only gets to 2.2. From epoch 5 it works, with 1,689 traces, and it improves to 528 at epoch 28. The beginning matches Chapter 8, where the loss crossed below the guessing line at epoch 4. The end does not. After epoch 28 the loss is worse than guessing, yet the attack keeps working with 500 to 900 traces through epoch 100.
The two measure different things. The loss looks only at the probability given to the true label, and an overconfident network that puts near-zero probability on it for a few traces pays heavily. The attack only compares the true key’s evidence with that of the 255 wrong guesses. If the network keeps giving the true label a little more than the wrong ones, the attack works however badly calibrated its probabilities are. Chapter 10 turns this into a measure that counts bits.
There’s also a limit on what the attack tells you. A key that ranks first says the network learned something about the chip; it doesn’t say what. Whether that is the mask, the masked share, or both combined is what the third part of this guide opens the network to find out.
Try it
The attack notebook (opens in a new tab) builds the vote table, sums the evidence and computes guessing entropy for the ASCADr model, on CPU in a few minutes.
Guessing entropy needs hundreds of traces and 40 random draws, and it only says whether the attack works. It can’t say how much a single trace tells about the secret value, or follow that amount epoch by epoch the way the loss does. Chapter 10 builds that measure, in bits.