Part V Chapter 20

A chip you can generate

Contents
  1. Six settings
  2. Does it leak what it should?
  3. The same files as a real dataset
  4. Eight chips
  5. Why the second step is missing
  6. What it doesn’t do
  7. What next?

Chapter 19 built a detector and tested it on the curves we had: three real datasets and one simulated chip. To test it, and everything after it, on many chips, we need chips we can make, with the answer known in advance: which values are the shares, in which clock cycle each one leaks, how much noise there is, and how the shares combine.

The simulated chip of Chapter 11 is one such chip, with every setting fixed. This chapter turns it into a generator with six settings, checks that the chips it makes leak what they should and nothing else, writes them in the same files as a real dataset, and trains the network of Chapter 11 on eight of them.

Six settings

The chip handles one byte per clock cycle, six cycles per trace, 10 samples per cycle. Each cycle is a current pulse whose height depends on the byte. Some cycles handle the shares of the secret value y = Sbox[p ⊕ k]; the others handle unrelated random bytes. The label is the Hamming weight of y, which never appears in the trace on its own.

  • Leakage. By default the pulse follows the Hamming weight of the byte, as in Chapter 2. The alternative gives every bit its own weight, from 1.6 for the lowest bit down to 0.5 for the highest, as on a chip where some wires are longer than others. Two bytes with the same Hamming weight then make different pulses, and two with different weights can make the same one.
  • Masking. By default the shares combine with XOR, as in Chapter 4: the chip handles a random mask m and the masked value y ⊕ m. The alternatives combine them by addition: y = m + s modulo 256, or modulo 257, a prime, where the shares are numbers from 0 to 256.
  • Shares. Two, in cycles 2 and 4, or three, in cycles 2, 4 and 6.
  • Noise. Gaussian, added to every sample; 0.3 by default, the value of Chapter 11, in the units where one extra 1 bit raises the top of the pulse by 0.6.
  • Jitter. Each trace shifted by a random number of samples, up to the setting in either direction, as when the oscilloscope’s trigger doesn’t fire at exactly the same moment.
  • Shuffling. The chip handles its six cycles in a random order in each trace, a common countermeasure: the shares are still somewhere in the trace, but not always in the same cycle.

The default settings give exactly the chip of Chapter 11: the same traces, labels and masks, bit for bit, because the generator draws its random numbers in the same order from the same seed. The widget runs the same model in your browser (with its own random numbers):

leaks shares
masking
A generated trace, and where each value leakstrace 1: label weight 2other5mask4other5masked2other2other4SNR over 2,000 traces07.92labelmaskmasked

The label alone peaks at SNR 0.007, the noise level for 2,000 traces: no single sample tells it. Each share leaks in its own cycle.

Play steps through the traces one at a time. Under each cycle is what the chip handled in it and the height of its pulse. The lower panel is the signal-to-noise ratio of Chapter 6, computed over 2,000 generated traces: for the label, and for the Hamming weight of each share. Each share stands out in its own cycle; the label stays flat at every setting. Jitter smears the shares’ peaks; shuffling spreads each share over all six cycles.

Does it leak what it should?

A masked chip should leak each share, and the label only through a combination of shares, never in a single sample. Over 200,000 traces of each kind of chip:

No sample leaks the label. The highest signal-to-noise ratio of the label over the 60 samples is between 0.00007 and 0.00011 for every kind of masking, two shares or three. That is what a value that doesn’t leak at all gives with this many traces: in simulations of pure noise, the highest of 60 samples lands between 0.00008 and 0.00011 eight times out of ten.

Every share leaks. The Hamming weight of each share reaches a ratio of about 8 in its own cycle, whatever the masking. With the bit-weighted leakage it reaches 3.9, because the pulse no longer follows the Hamming weight exactly.

Two shares leak together. Chapter 4 showed the classic way to combine two shares by hand: multiply the two samples, each minus its average. Taking the top of each share’s pulse, that product leaks the label with a signal-to-noise ratio of 0.11 when the shares combine with XOR, 0.021 when they are added modulo 256, and 0.018 modulo 257. The same trick works five times less well against addition.

Three shares leak only all together. With three shares, the product of any two of them gives 0.0001, no more than noise. The product of all three gives 0.011 with XOR and 0.0006 modulo 257.

So the generated chips leak at exactly the order their masking promises, which is what makes them useful: when a network finds something, we know what there was to find.

The same files as a real dataset

The generator also writes its traces to an HDF5 file in the layout of ESHARD’s (Appendix: the datasets): profiling and attack traces, each with its plaintext, key and masks. The paper’s code reads it with the same loader it uses for ESHARD, unchanged. Read back, the traces, the labels and both shares match what the generator made.

One detail had to follow the real dataset: that loader assumes ESHARD’s key when it ranks key guesses, so the generator uses the same key. Only XOR masking with two shares fits that layout, since it has room for one output mask and no more.

Training also matches. The network of Chapter 11, trained on the default chip with the same seed, gives the same perceived information at every epoch, to the three decimals Chapter 11 published.

Eight chips

We trained the network of Chapter 11 on eight chips, each one changing a single setting from the default, three times each from different random starts, for 40 epochs as in Chapter 11. The detector of Chapter 19 ran on every curve.

The network on eight generated chipsdefault chip00.250.5110203040bit-weighted leakage110203040addition mod 25600.250.5110203040addition mod 257110203040three shares00.250.5110203040jitter of ±2 samples110203040shuffled cycles00.250.5110203040twice the noise110203040epoch
Perceived information on 5,000 test traces, per epoch, for the network of Chapter 11 trained on eight generated chips, each changing one setting from the default. Solid: seed 0; faint: seeds 1 and 2. Shaded: the jumps the detector of Chapter 19 marks in seed 0. Values below −0.05 are drawn at −0.05.

The default chip shows the two steps of Chapter 11 in every run: a small first step in the first few epochs, and the jump, at epochs 10 to 16, 7 to 10 and 10 to 14. Each run ends between 0.45 and 0.47 bits.

Jitter of up to 2 samples keeps both steps but slows the second: it spreads over epochs 14 to 20, 11 to 21 and 11 to 20, and the runs end between 0.40 and 0.42 bits. The network still finds the shares when they move a little.

Bit-weighted leakage, addition modulo 256 or 257, and twice the noise keep only the first step. The detector marks it in 10 of these 12 runs. Its size depends on the chip: at its highest, 0.11 bits with bit-weighted leakage, 0.05 to 0.06 with addition, and 0.07 with twice the noise. Then nothing more comes in 40 epochs. Perceived information on the test traces slowly falls while on the training traces it keeps rising: the network starts memorizing.

Three shares and shuffling give nothing at all. Perceived information on the test traces is below zero from the first epochs and falls to between −0.03 and −0.05 bits by epoch 40, while on the training traces it reaches 0.05 to 0.06: memorizing from the start.

Why the second step is missing

Chapter 12 found what the jump brings on the default chip: parity. The label HW(y) is always even when HW(m) + HW(y ⊕ m) is even, and odd when it is odd, so a network that reads both weights exactly can tell whether the label is even or odd. Chapter 13 found that parity inside the network, arriving with the jump.

How much parity is there to find on each chip? Given the two share cycles of a trace, the chip’s settings fix exactly how likely each pair of share values is, so the best possible guess of the label’s parity can be computed. Over 20,000 traces of each chip, the best possible guess is right:

ChipBest possible guess of parity
default81%
bit-weighted leakage53%
addition modulo 25653%
addition modulo 25753%
twice the noise53%

On the default chip the network’s own parity, read by Chapter 13’s probe, reached 79%, close to that ceiling. On the four chips where the second step never came, it is barely better than a coin. The network isn’t failing to make the jump on these chips; the piece the jump delivers on the default chip is almost absent from them.

The reasons differ. With addition, the parity rule itself breaks: adding two bytes carries bits from one position to the next, and how many carries there are depends on the bytes, not just on their weights. Even with almost no noise (0.05), the best guess is right only 55% of the time. With bit-weighted leakage, the pulse no longer tells the weight: different weights can make pulses of the same height. With twice the noise, each weight is read less precisely, and parity needs both exactly; one weight read one off flips the answer.

Whether a longer training or a larger network finds some other route on these chips is a question for Chapter 22.

What it doesn’t do

It is a simulation. Real chips leak the change between consecutive values as well as the values themselves, their noise isn’t the same at every sample, and their pulses overlap. The generator models none of that.

Its masks are perfectly random. Real implementations sometimes reuse masks or draw them from a weak generator, which leaks in ways a perfect mask doesn’t.

It protects one byte. The other 15 bytes of the state, and the rest of AES, aren’t in the trace.

What next?

We now have chips with known shares, a detector that says when a network learns, and, from Chapter 14, a way to check which parts of a network carry the masks. On the default chip a person picked the parts to look at. Can a program go from “there is a jump” to “these are the masks” alone? Chapter 21 tries.