As of August 2020 the site you are on (wiki.newae.com) is deprecated, and content is now at rtfm.newae.com.

Changes

Jump to: navigation, search

MATLAB Control of CW-Lite

449 bytes removed, 16:35, 1 March 2018
Adding a V4 version of interfacing chipwhisperer with matlab
== Running Examples ==
 To run Since the examplesnew CW 4, you will need 0 API exposes the internals of chipwhisperer the easiest way to get access to ensure you set the chipwhisperer module in MATLAB is to use this API. MATLAB working directory seems to not find certain modules even if they are on the location of python path so just use pythons build in importlib, which MATLAB can find, letting python find the module for MATLAB.m script files. The following shows my example setup:Running this command in MATLAB [[File:api_matlab_path.png]] The <syntaxhighlight lang=matlab files internally will reference a .py file in that same directory. You should be able to simply connect to the ChipWhisperer-Lite with the following:> >> cw = cwconnectpy.importlib.import_module('chipwhisperer')</syntaxhighlight>should give you access to the 4.0 API.
If this works it should print the information about the 'cw' object:
<syntaxhighlight>
cw =
Python CWCoreAPI with properties:
sigNewProject: [1x1 py.chipwhisperer.common.utils.util.Signal]
valid_aux: [1x1 py.collections.OrderedDict]
auxParam: [1x1 py.chipwhisperer.common.utils.parameter.Parameter]
sigConnectStatus: [1x1 py.chipwhisperer.common.utils.util.Signal]
sigNewTextResponse: [1x1 py.chipwhisperer.common.utils.util.Signal]
valid_attacks: [1x1 py.collections.OrderedDict]
sigTraceDone: [1x1 py.chipwhisperer.common.utils.util.Signal]
traceParam: [1x1 py.chipwhisperer.common.utils.parameter.Parameter]
executingScripts: [1x1 py.chipwhisperer.common.utils.util.Observable]
scopeParam: [1x1 py.chipwhisperer.common.utils.parameter.Parameter]
sigCampaignStart: [1x1 py.chipwhisperer.common.utils.util.Signal]
sigNewInputData: [1x1 py.chipwhisperer.common.utils.util.Signal]
params: [1x1 py.chipwhisperer.common.utils.parameter.Parameter]
settings: [1x1 py.chipwhisperer.common.api.settings.Settings]
valid_acqPatterns: [1x1 py.collections.OrderedDict]
valid_scopes: [1x1 py.collections.OrderedDict]
targetParam: [1x1 py.chipwhisperer.common.utils.parameter.Parameter]
valid_traces: [1x1 py.collections.OrderedDict]
valid_targets: [1x1 py.collections.OrderedDict]
sigAttackChanged: [1x1 py.chipwhisperer.common.utils.util.Signal]
sigCampaignDone: [1x1 py.chipwhisperer.common.utils.util.Signal]
valid_preprocessingModules: [1x1 py.collections.OrderedDict]
<chipwhisperer.common.api.CWCoreAPI.CWCoreAPI object at 0x000000013312FD30>
 
 
If this FAILS, you may need to simply unplug/replug the ChipWhisperer-Lite. You may have not closed the connection from the previous test. Note you can actually interact directly with the 'cw' object as in Python. For example we can get information about the current scope module:
 
>> cw.getScope()
 
But you probably just want to run an AES test. To do this, simply perform the following:
 
[cipher, trace] = measure_AES(cw, [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15],[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]);
 
The measure_AES() function passes both the plaintext and key. In this example they are both set to the same array value. It returns the ciphertext resulting & the power trace.
 
You can plot this power trace with:
plot(trace)Python module with properties:
TargetTemplate: [1×1 py.type] createProject: [File1×1 py.function] cwhardware:matlab_plot[1×1 py.png|400pxtype] project: [1×1 py.module] getLastKey: [1×1 py.chipwhisperer.gui_only] scope: [1×1 py.function] hardware: [1×1 py.module] capture: [1×1 py.module] analyzer_gui: [1×1 py.function] analyzer: [1×1 py.module] cwa: [1×1 py.module] CWCoreAPI: [1×1 py.type] cwtarget: [1×1 py.type] captureN: [1×1 py.chipwhisperer.gui_only] updateUI: [1×1 py.function] common: [1×1 py.module] gui: [1×1 py.type] getLastTextin: [1×1 py.chipwhisperer.gui_only] AcquisitionController: [1×1 py.classobj] gui_only: [1×1 py.type] acquisition_controller: [1×1 py.function] capture_gui: [1×1 py.function] Parameter: [1×1 py.type] getLastExpected: [1×1 py.chipwhisperer.gui_only] auxList: [1×1 py.chipwhisperer.gui_only] AcqKeyTextPattern_Basic: [1×1 py.type] trace_container_native: [1×1 py.module] os: [1×1 py.module] ScopeTemplate: [1×1 py.type] getLastTextout: [1×1 py.chipwhisperer.gui_only] target: [1×1 py.function] openProject: [1×1 py.function] BasicKtp: [1×1 py.type] cwc: [1×1 py.module] cw_bytearray: [1×1 py.type]
You can run a number of measure_AES() calls with the same cw object without running cwconnect() again. Note if you want to reconnect, you will first need to run cw.disconnect() to close the USB connection <module 'chipwhisperer' from 'c:\chipwhisperer\software\chipwhisperer\__init__.pyc'></syntaxhighlight>
If you receive 'device in use' error messages, this is likely the problem. You can also FAILS, you may need to simply unplug/replug the USB ChipWhisperer-Lite. You may have not closed the connection from the previous test. Note you can actually interact directly with the 'cw' as in Python, just as you would after running <code> import chipwhisperer as cw </code> in Python. So you can initialize a scope and a target like so:<syntaxhighlight lang=matlab> >> scope = cw.scope() >> target = cw.target(scope)</syntaxhighlight>You can now write scripts in MATLAB similar to force-close any existing connectionsthe scripts in [[Making_Scripts]].
== Usage Notes ==

Navigation menu