Training

This page is used as a scratch-pad. Training related material and updates is posted here.

STM32F415 TVLA Demo

Download this file: File:tvla_stm32f415.zip

DPA Lab Slides

File:3.0 - Differential Power Analysis.pptx

File:3.1 - DPA Lab 1A (Basic AES Attack) Capture Only .pptx

File:3.1 - DPA Lab 1B (Basic AES Attack) DPA Attack.pptx

File:3.2 - DPA Lab 2 (Resync Example).pptx

Bitwise DPA: Starting Example

from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI
from matplotlib.pylab import *
import numpy as np

cwapi = CWCoreAPI()
cwapi.openProject(r'/home/cwuser/chipwhisperer/projects/dpa_dem.cwp')

tm = cwapi.project().traceManager()
ntraces = tm.numTraces()
npoints = tm.numPoints()

#We will store 0-guess here
zeroguess = np.zeros((1,npoints))

#We will store 1-guess here
oneguess = np.zeros((1,npoints))

bytenum = 0
bit = 0
##BITWISE GUESS STARTS HERE

#Count 1 and 0 for averaging
numone = 0
numzero = 0

#Do each trace loop
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

plot(diff)
show()

Bitwise DPA - Full Example

#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()