I have tried to use this tutorial wiki.newae.com/Tutorial_B8_Prof … ate_Attack in order to make my first template attack in the first round of an AES.
My first experiment doesn’t give me good results, I have a nice Point of interest, however I don’t find any correct bytes from my secret key. So I decide to modify the template attack in order to attack the last round:
This the code to calculate the intermediate value for the first round and its hamming weight:
[code]# Useful utilities
hw = [bin(x).count(“1”) for x in range(256)]
def cov(x, y):
# Find the covariance between two 1D lists (x and y).
# Note that var(x) = cov(x, x)
return np.cov(x, y)
Start calculating template
1: load data
tempTraces = np.load(r’C:\chipwhisperer\software\temp_attack\rand_key_data\traces\2016.05.24-12.53.15_traces.npy’)
tempPText = np.load(r’C:\chipwhisperer\software\temp_attack\rand_key_data\traces\2016.05.24-12.53.15_textin.npy’)
tempKey = np.load(r’C:\chipwhisperer\software\temp_attack\rand_key_data\traces\2016.05.24-12.53.15_keylist.npy’)
2: Find HW(sbox) to go with each input
Note - we’re only working with the first byte here
tempSbox = [sbox[tempPText[i] ^ tempKey[i]] for i in range(len(tempPText))]
tempHW = [hw[s] for s in tempSbox]
But I don’t find how to modify my code in order to calculate the intermediate value of the last round. As I know that:
The intermediate value of the last round= SubBytes^(-1)[ShiftRows^(-1)[k10♁ciphertext]]
If I suppose that is correct, Mus I just change this equation in my code???
tempSbox = [sbox[Ciphertext[i] ^ key[i]] for i in range(len(Ciphertext))]
I would be very grateful if you could help me please: How to calculate please the intermediate value of the last round in python?