Part I Chapter 6

Where the key leaks: signal-to-noise ratio

Contents
  1. One sample, many traces
  2. Signal and noise
  3. The SNR curve
  4. What the SNR predicts for an attack
  5. On a masked chip, the peak moves
  6. All three datasets
  7. References

A trace has thousands of samples (2,000 in ASCADr), and only a handful depend on the key byte. The attack in Chapter 3 assumed it knew which one to use. This chapter builds the map it was missing: a score for every sample, called the signal-to-noise ratio (SNR), that says how strongly that sample depends on the label.

The label is the value the attack goes after, worked out for each trace from its plaintext and key. In this chapter it’s the Hamming weight of the S-box output, HW(Sbox[p ⊕ k]): how many of the 8 bits the chip computes are set. Working it out takes the key, so the SNR is computed on the profiling set from Chapter 5, where every trace’s key is recorded.

The map serves twice in this guide: to aim an attack, and later to check whether a trained network looks where the leak is. On an unprotected chip it shows one sharp peak. On a masked chip that peak disappears, and two new ones appear where the chip handles the shares.

One sample, many traces

Take a simulated chip whose traces have 60 samples: six clock cycles of ten samples each. Every cycle draws one current pulse, and the pulse is taller when the byte handled in that cycle has more bits set. In the fourth cycle that byte is the S-box output Sbox[p ⊕ k]; in the other five it’s unrelated data.

Now fix one instant and read it in every trace: one number per trace. Here are eight traces, sorted by label, read at two instants:

Eight traces read at samples 12 and 32tracelabel (bits set)sample 12no pattern02468power at sample 12sample 32climbs with the label02468power at sample 321216.12.81023.73.2334.43.2145.15.1655.94.9463.05.5273.86.236183.27.5
Eight of the 2,000 simulated traces, one per label from 1 to 8, sorted by label. Each bar is the power that trace drew at that instant. Both columns use the same scale.

At sample 32 the values climb with the label, unevenly but clearly. At sample 12 they don’t: a trace with label 1 reads 6.1, one with label 8 reads 3.2. That’s the compare step from Chapter 3 with the roles swapped. There the sample was fixed and 256 key guesses competed; here the key is known, so every label is right, and it’s the samples that compete.

Signal and noise

Eight traces can mislead, so take all 2,000 and group them by label. If the sample depends on the label, each group sits at its own height.

Signal and noise at two samplessample 12SNR = 0.004012345678label: Hamming weight of Sbox[p ⊕ k]noiseaverages flat: no signalsample 32SNR = 2.97012345678label: Hamming weight of Sbox[p ⊕ k]noisesignal
2,000 simulated traces, grouped by label at two samples. At sample 12 the chip handles unrelated data: the group averages are flat and the spread is wide. At sample 32 it handles the S-box output: the averages climb with the Hamming weight, and the spread inside each group is small.

Two numbers describe each panel:

  • Signal is how far apart the group averages sit (the red line). It’s what the label does to the sample.
  • Noise is the spread inside each group, where the label is fixed. It’s everything else: other operations running at the same time, the measurement setup, thermal noise.

At sample 12 the red line is flat: no signal. At sample 32 it climbs about 0.6 for every extra bit, and each group’s spread is narrower than that climb.

The SNR is the ratio of the two, both measured as variances:

SNR(t)=Var⁡( E[ xt∣g ] )E[Var⁡( xt∣g )]\mathrm{SNR}(t) = \frac{\operatorname{Var}\big(\,\mathbb{E}[\,x_t \mid g\,]\,\big)}{\mathbb{E}\big[\operatorname{Var}(\,x_t \mid g\,)\big]}

where xtx_t is the value at sample tt and gg is the label. Sample 32 scores 2.97, sample 12 scores 0.004.

The SNR curve

Computing the SNR at every sample gives the SNR curve. Its peak marks where the chip handles the label:

Traces and their SNR curvepowerthree tracessample 12sample 32SNRthe chip handles Sbox[p ⊕ k] here0102030405060time sample
The same simulated chip draws one current pulse per clock cycle (shaded bands mark every other cycle). The SNR is near zero everywhere except the fourth pulse, where the chip handles Sbox[p ⊕ k].

What the SNR predicts for an attack

When the leak follows the label in a straight line, as it does here, the SNR fixes the correlation CPA reaches with the true key [1]:

ρ=SNR1+SNR\rho = \sqrt{\frac{\mathrm{SNR}}{1 + \mathrm{SNR}}}

Chapter 3’s chip leaked the Hamming weight (variance 2) under noise σ = 2, so its SNR was 2/4 = 0.5 and ρ = 0.58, the value that chapter quoted. Sample 32 here gives 0.86. The traces CPA needs grow roughly as 1/ρ21/\rho^2, which for small SNR is about 1/SNR: cut the SNR by ten and the attack needs about ten times more traces.

Sample 12’s 0.004 is not a tiny leak. Nothing at sample 12 depends on the label; the score is how far nine group averages scatter by chance when the smallest groups hold fewer than ten traces. That floor shrinks with more traces and grows with more groups, so a real leak has to stand clear of it, not just above zero.

The widget below runs the same chip with the same random draws, so it starts from the numbers above. Two settings are worth trying. At noise σ = 1.5 the peak drops to 0.35 and the correlation at sample 32 to about 0.5, as √(SNR/(1+SNR)) predicts. At 200 traces the flat samples climb to around 0.04: the floor, with ten times fewer traces.

sample t = 32
Traces, cursor and SNR per samplecycle 1cycle 2cycle 3cycle 4cycle 5cycle 6power123SNR0102030405059time sample (drag the red line) Traces at sample 32, grouped by label02468noisesignal012345678label: Hamming weight of Sbox[p ⊕ k]
signal
0.74
noise
0.25

SNR = signal ÷ noise = 2.97. Correlation with the label: 0.86; √(SNR/(1+SNR)) predicts 0.86.

Drag the red line along the traces, or scan every sample. Below, the traces at that sample are grouped by label: where the red averages climb, the sample leaks.

chip
group by
traces

On a masked chip, the peak moves

Before measuring, predict. The SNR only finds samples that depend on the value you group by. On a masked chip (Chapter 4) the S-box output never appears in the circuit: the chip handles the mask m and the masked share Sbox[p ⊕ k] ⊕ m, and each of those, on its own, is a uniform random byte. So grouping by the S-box output should give a flat curve everywhere, and grouping by either share should give a peak where the chip handles it.

The widget’s masked chip tests this on the simulation: it handles the mask in the second cycle and the masked share in the fourth. Scan it grouped by Sbox[p ⊕ k], then by each share.

ASCADr lets us test it on real traces, because its metadata store the mask of every trace. Take 20,000 ASCADr profiling traces and compute the SNR three times, grouping by the Hamming weight of a different value each time:

Masking moves the SNR into the shares01234SNR2.0 at sample 970grouped by the mask, HW(m)3.8 at sample 1,526grouped by the masked share, HW(Sbox[p ⊕ k] ⊕ m)at most 0.0011grouped by the unmasked output,HW(Sbox[p ⊕ k]): flat on the axis02505007501,0001,2501,5001,7502,000time sample
SNR of 20,000 ASCADr profiling traces at every sample, computed three times on one scale: grouped by the mask, by the masked share, and by the unmasked S-box output. The smaller peaks are other samples that also depend on the same value.

The prediction holds. Against the unmasked output, the SNR never leaves the noise floor; its maximum is 0.0011. Against the masked share it peaks at 3.8 near sample 1,526, over three thousand times higher. The mask leaks too, at a different moment: 2.0 near sample 970. Each share leaks on its own, at its own sample, and the unmasked value only shows up when the two are combined.

Drawing this figure took the true masks, which only the lab has. An attack has to reach the same combination without them.

All three datasets

The flat half of the story holds in every dataset. Grouped by the Hamming weight of the S-box output, no sample in any of the three rises above 0.0015:

No sample leaks the unmasked label, in any datasetASCADr, grouped by HW(Sbox[p ⊕ k])00.00050.0010.001505001,0001,5002,000ESHARD, grouped by HW(Sbox[p ⊕ k])00.00050.0010.001502004006008001,0001,2001,400CHES_CTF, grouped by HW(Sbox[p ⊕ k])00.00050.0010.001502,5005,0007,50010,00012,50015,000
SNR grouped by HW(Sbox[p ⊕ k]) in each dataset, on one scale from 0 to 0.0015, from 20,000 profiling traces (30,000 for CHES_CTF). For comparison, the masked share above peaks at 3.8.

The curves hover a few ten-thousandths above zero, the scatter nine group averages show by chance with this many traces, and a few samples spike to about 0.001. Nothing comes close to the masked share’s 3.8.

That gives the map this guide uses from here on. In ASCADr the leak peaks at two places, sample 970 for the mask and sample 1,526 for the masked share, and nowhere for the S-box output itself. Can a model trained on traces and S-box labels, never shown the masks, learn to combine those two samples on its own? Chapter 7 introduces the network that tries.

References

  1. S. Mangard, E. Oswald, T. Popp, Power Analysis Attacks: Revealing the Secrets of Smart Cards, Springer 2007 (opens in a new tab). Chapter 4 defines the SNR of a power trace; Chapter 6 relates it to the correlation of a CPA attack and to the number of traces it needs.