As of August 2020 the site you are on ( is deprecated, and content is now at

Difference between revisions of "Making Scripts"

From ChipWhisperer Wiki
Jump to: navigation, search
(Scripting with ChipWhisperer as python module)
m (added cleanup)
Line 70: Line 70:
# cleanup the connection to the target and scope

Revision as of 10:56, 21 February 2018

For the older V3.x tools, see V3:Making_Scripts

Scripting with ChipWhisperer as a python module

When used without the GUI, the 4.0 API removes much of the high level abstractions so you can have more control over the capture process. It also answers questions like--when I capture a trace in what order are things happening? The following example scripts will give you a starting point when scripting with the ChipWhisperer tool.

Perform Some Traces during AES encryption and get the results as Numpy array

This script is an example of using the chipwhisperer module for capturing traces during AES encryption. Make sure to have the correct firmware loaded on the target.

import time

import numpy as np
import chipwhisperer as cw
from chipwhisperer.capture.acq_patterns.basic import AcqKeyTextPattern_Basic
import matplotlib.pyplot as plt

scope = cw.scope()
target =

# setup scope parameters
scope.gain.gain = 45
scope.adc.samples = 3000
scope.adc.offset = 1250
scope.adc.basic_mode = "rising_edge"
scope.clock.clkgen_freq = 7370000
scope.clock.adc_src = "clkgen_x4"
scope.trigger.triggers = "tio4" = "serial_rx" = "serial_tx" = "clkgen"

ktp = AcqKeyTextPattern_Basic(target=target)

traces = []
N = 50 # Number of traces
for i in range(N):
    key, text = ktp.newPair() # manual creation of a key, text pair can be substituted here


    target.setModeEncrypt() # only does something for targets that support it

    # run aux stuff that should run before the scope arms here


    # run aux stuff that should run after the scope arms here

    # wait for target to finish
    while target.isDone() is False and timeout:
        timeout -= 1

        ret = scope.capture()
        if ret:
            print('Timeout happened during acquisition')
    except IOError as e:
        print('IOError: %s' % str(e))

    # run aux stuff that should happen after trace here


trace_array = np.asarray(traces) # if you prefer to work with numpy array for number crunching

# show an example trace

# cleanup the connection to the target and scope