from tqdm import tnrange
import numpy as np
import time
from Crypto.Cipher import AES
ktp = cw.ktp.Basic()
traces = []
textin = []
keys = []
N = 50 # Number of traces
S = 250 # Number of sets
# initialize cipher to verify DUT result:
key, text = ktp.next()
cipher = AES.new(bytes(key), AES.MODE_ECB)
for j in tnrange(S, desc='Set Number'):
tries = 100
scope.clock.adc_phase = j #Update the phase
for i in range(tries):
scope.clock.reset_adc()
time.sleep(0.1)
if scope.clock.adc_locked:
break
if not scope.clock.adc_locked:
print("Couldn't lock")
time.sleep(3)
for i in tnrange(N, desc='Capturing traces'):
#key, text = ktp.next() # Key and text is not updated
textin.append(text)
keys.append(key)
ret = cw.capture_trace(scope, target, text, key)
if not ret:
print("Failed capture")
continue
assert (list(ret.textout) == list(cipher.encrypt(bytes(text)))), "Incorrect encryption result!\nGot {}\nExp {}\n".format(ret.textout, list(text))
#trace += scope.getLastTrace()
traces.append(ret.wave)
project.traces.append(ret)
I ran this code above which takes 50 traces for 250 different phase settings.
I took 50 traces for 250 different phases and averaged them by phase, resulting in 250 different traces. I then took the power of each of these average traces and plotted them to see if there was any noticeable trend. Maybe I am not sampling enough traces per phase setting or my methodology is incorrect but it doesn’t seem like the phase is actually changing.