Wrong key in DPA on AES using CW1200

I am running example provided in the jupyter notebook an getting wrong key. My code is also attached in Codes.zip file, kindly help me out regarding this. Following is output:

AssertionError Traceback (most recent call last)
Cell In[52], line 1
----> 1 assert key_guess == known_key, “Failed to break key, expected vs got:\n{}\n{}”.format(known_key, key_guess)

AssertionError: Failed to break key, expected vs got:
[43, 126, 21, 22, 40, 174, 210, 166, 171, 247, 21, 136, 9, 207, 79, 60]
[99, 52, 162, 88, 184, 177, 31, 154, 244, 129, 202, 27, 166, 175, 82, 139]

Link: Codes

Kindly guide me what I am doing wrong in these code.!

It looks like you’re not capturing valid power traces. Have you connected the SMA cable between the MEASURE port and the target’s SMA port?

Alex

Thanks @Alex_Dewar, after connecting cable I was able to get right key. But " Windowing Peaks" code is giving me one bit error (one bit of key is incorrect). Kindly guide me to resolve this issue as well.

Code:

Add your code here

from tqdm.notebook import trange
import numpy as np

#Store your key_guess here, compare to known_key
key_guess = []
known_key = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]

#Which bit to target
bitnum = 0

full_diffs_list = []

for subkey in trange(0, 16, desc=“Attacking Subkey”):

max_diffs = [0]*256
full_diffs = [0]*256

for guess in range(0, 256):
    full_diff_trace = calculate_diffs(guess, subkey, bitnum)
    full_diff_trace = full_diff_trace[(1010 + subkey*60):]
    max_diffs[guess] = np.max(full_diff_trace)
    full_diffs[guess] = full_diff_trace

#Make copy of the list
full_diffs_list.append(full_diffs[:])

#Get argument sort, as each index is the actual key guess.
sorted_args = np.argsort(max_diffs)[::-1]

#Keep most likely
key_guess.append(sorted_args[0])

#Print results
print("Subkey %2d - most likely %02X (actual %02X)"%(subkey, key_guess[subkey], known_key[subkey]))

#Print other top guesses
print(" Top 5 guesses: ")
for i in range(0, 5):
    g = sorted_args[i]
    print("   %02X - Diff = %f"%(g, max_diffs[g]))

print("\n")

Output:
A Jupyter widget could not be displayed because the widget state could not be found. This could happen if the kernel storing the widget is no longer available, or if the widget state was not saved in the notebook. You may be able to create the widget by running the appropriate cells.

Subkey 0 - most likely 2B (actual 2B)
Top 5 guesses:
2B - Diff = 0.005082
C7 - Diff = 0.002788
34 - Diff = 0.002343
0A - Diff = 0.002229
B9 - Diff = 0.002209

Subkey 1 - most likely 7E (actual 7E)
Top 5 guesses:
7E - Diff = 0.002993
15 - Diff = 0.001826
C3 - Diff = 0.001786
D7 - Diff = 0.001730
8C - Diff = 0.001701

Subkey 2 - most likely 15 (actual 15)
Top 5 guesses:
15 - Diff = 0.004600
A8 - Diff = 0.002572
7C - Diff = 0.002455
8C - Diff = 0.002243
C1 - Diff = 0.002229

Subkey 3 - most likely 16 (actual 16)
Top 5 guesses:
16 - Diff = 0.003873
AB - Diff = 0.002311
E8 - Diff = 0.002096
84 - Diff = 0.002014
7D - Diff = 0.001988

Subkey 4 - most likely 28 (actual 28)
Top 5 guesses:
28 - Diff = 0.003309
43 - Diff = 0.002131
95 - Diff = 0.002110
36 - Diff = 0.002066
BA - Diff = 0.002016

Subkey 5 - most likely AE (actual AE)
Top 5 guesses:
AE - Diff = 0.003236
13 - Diff = 0.001965
3C - Diff = 0.001891
C5 - Diff = 0.001870
E4 - Diff = 0.001795

Subkey 6 - most likely D2 (actual D2)
Top 5 guesses:
D2 - Diff = 0.004389
6F - Diff = 0.002824
06 - Diff = 0.002534
FA - Diff = 0.002333
4B - Diff = 0.002279

Subkey 7 - most likely A6 (actual A6)
Top 5 guesses:
A6 - Diff = 0.003852
1B - Diff = 0.002403
CD - Diff = 0.002151
B9 - Diff = 0.002050
72 - Diff = 0.002034

Subkey 8 - most likely 13 (actual AB)
Top 5 guesses:
13 - Diff = 0.001291
84 - Diff = 0.001273
46 - Diff = 0.001124
8A - Diff = 0.001093
E5 - Diff = 0.001093

Subkey 9 - most likely F7 (actual F7)
Top 5 guesses:
F7 - Diff = 0.004008
65 - Diff = 0.002271
4A - Diff = 0.002168
6E - Diff = 0.002072
9C - Diff = 0.001992

Subkey 10 - most likely 15 (actual 15)
Top 5 guesses:
15 - Diff = 0.004077
A8 - Diff = 0.003517
87 - Diff = 0.002796
C1 - Diff = 0.002744
8C - Diff = 0.002650

Subkey 11 - most likely 88 (actual 88)
Top 5 guesses:
88 - Diff = 0.004684
5C - Diff = 0.002638
35 - Diff = 0.002166
45 - Diff = 0.002122
E3 - Diff = 0.002060

Subkey 12 - most likely 09 (actual 09)
Top 5 guesses:
09 - Diff = 0.001319
16 - Diff = 0.001284
B4 - Diff = 0.001274
0F - Diff = 0.001248
17 - Diff = 0.001217

Subkey 13 - most likely CF (actual CF)
Top 5 guesses:
CF - Diff = 0.003203
72 - Diff = 0.001876
31 - Diff = 0.001853
56 - Diff = 0.001782
F1 - Diff = 0.001748

Subkey 14 - most likely 4F (actual 4F)
Top 5 guesses:
4F - Diff = 0.002923
24 - Diff = 0.001822
D6 - Diff = 0.001548
2A - Diff = 0.001501
FE - Diff = 0.001478

Subkey 15 - most likely 3C (actual 3C)
Top 5 guesses:
3C - Diff = 0.003147
57 - Diff = 0.002191
DB - Diff = 0.002017
76 - Diff = 0.001879
22 - Diff = 0.001871

Try capturing more traces.

Thanks @Alex_Dewar for guiding.