Changes

Making Scripts

2,266 bytes added, 17:32, 21 February 2018
Added example of headless script
{{Warningbox|For the older V3.x tools, see [[V3:Making_Scripts]]}}
TODO== Scripting with ChipWhisperer as 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 and get the results as Numpy array ===This script is an example of using the <code>chipwhisperer</code> module for capturing traces during AES encryption. <b>Make sure to have the correct firmware loaded on the target.</b><syntaxhighlight lang=python>import time import numpy as npimport chipwhisperer as cwfrom chipwhisperer.capture.acq_patterns.basic import AcqKeyTextPattern_Basicimport matplotlib.pyplot as plt scope = cw.scope()target = cw.target(scope) # setup scope parametersscope.gain.gain = 45scope.adc.samples = 3000scope.adc.offset = 1250scope.adc.basic_mode = "rising_edge"scope.clock.clkgen_freq = 7370000scope.clock.adc_src = "clkgen_x4"scope.trigger.triggers = "tio4"scope.io.tio1 = "serial_rx"scope.io.tio2 = "serial_tx"scope.io.hs2 = "clkgen" ktp = AcqKeyTextPattern_Basic(target=target) traces = []N = 50 # Number of tracesfor i in range(N): Push key, text = ktp.newPair() # manual creation of a key, text pair can be substituted here  target.reinit()  target.setModeEncrypt() # only does something for targets that support it target.loadEncryptionKey(key) target.loadInput(text)  # run aux stuff that should run before the update scope arms here  scope.arm()  # run aux stuff that should run after the scope arms here  target.go() timeout=50 # wait for V4target to finish while target.isDone() is False and timeout: timeout -= 1 time.sleep(0.01)  try: 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  traces.append(scope.getLastTrace()) trace_array = np.asarray(traces) # if you prefer to work with numpy array for number crunching # show an example traceplt.plot(traces[0])plt.xshow()</syntaxhighlight>