Changes

Training

1,151 bytes added, 21:56, 6 August 2018
no edit summary
plot(diff)
show()
</SyntaxHighlight>
 
<SyntaxHighlight>
#wiki.newae.com/Training
from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI
from matplotlib.pylab import *
import numpy as np
cwapi = CWCoreAPI()
cwapi.openProject(r'/home/cwuser/chipwhisperer/projects/aes_dpa_day1.cwp')
tm = cwapi.project().traceManager()
ntraces = tm.numTraces()
npoints = tm.numPoints()
 
bytenum = 0
##BITWISE GUESS STARTS HERE
guess = 0x00
#Do each trace loop
for bit in range(0, 8):
#We will store 0-guess here
zeroguess = np.zeros((1,npoints))
 
#We will store 1-guess here
oneguess = np.zeros((1,npoints))
 
#Count 1 and 0 for averaging
numone = 0
numzero = 0
 
for n in range(0, ntraces):
trace = tm.getTrace(n)
tin = tm.getTextin(n)
if tin[bytenum] & (1<<bit):
oneguess += trace
numone += 1
else:
zeroguess += trace
numzero += 1
 
oneguess = oneguess / float(numone)
zeroguess = zeroguess / float(numzero)
 
diff = (oneguess - zeroguess).T
 
if (diff[236] > 0):
guess |= (1<<bit)
 
plot(diff)
print "0x%02x"%guess
show()
</SyntaxHighlight>
Approved_users, bureaucrat, administrator
1,956
edits