Beispiel #1
0
    def __init__(self):
        logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
        CWCoreAPI.instance = self
        self.sigNewProject = util.Signal()
        self.sigConnectStatus = util.Signal()
        self.sigAttackChanged = util.Signal()
        self.sigNewInputData = util.Signal()
        self.sigNewTextResponse = util.Signal()
        self.sigTraceDone = util.Signal()
        self.sigCampaignStart = util.Signal()
        self.sigCampaignDone = util.Signal()
        self.executingScripts = util.Observable(False)

        self.valid_scopes = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.scopes", True, True)
        self.valid_targets =  pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.targets", True, True)
        self.valid_traces = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.common.traces", True, True)
        self.valid_aux = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.auxiliary", True, True)
        self.valid_acqPatterns =  pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.acq_patterns", True, False)

        self.settings = Settings()

        # Initialize default values
        self._project = self._scope = self._target = self._traceFormat = self._acqPattern = self._attack = None
        self._acqPattern = self.valid_acqPatterns["Basic"]
        self._auxList = AuxList()
        self._numTraces = 50
        self._numTraceSets = 1


        # Storage for last key/plaintext/ciphertext
        self._lastKey = None
        self._lastTextin = None
        self._lastTextout = None
        self._lastExpected = None

        self.params = Parameter(name='Generic Settings', type='group', addLoadSave=True).register()
        self.params.addChildren([
            {'name':'Scope Module', 'key':'scopeMod', 'type':'list', 'values':self.valid_scopes, 'get':self.getScope, 'set':self.setScope},
            {'name':'Target Module', 'key':'targetMod', 'type':'list', 'values':self.valid_targets, 'get':self.getTarget, 'set':self.setTarget},
            {'name':'Acquisition Settings', 'type':'group', 'children':[
                    {'name':'Number of Traces', 'type':'int', 'limits':(1, 1E9), 'get':self.getNumTraces, 'set':self.setNumTraces, 'linked':['Traces per Set']},
                    {'name':'Number of Sets', 'type':'int', 'limits':(1, 1E6), 'get':self.getNumTraceSets, 'set':self.setNumTraceSets, 'linked':['Traces per Set'], 'tip': 'Break acquisition into N sets, '
                     'which may cause data to be saved more frequently. The default capture driver requires that NTraces/NSets is small enough to avoid running out of system memory '
                     'as each segment is buffered into RAM before being written to disk.'},
                    {'name':'Traces per Set', 'type':'int', 'readonly':True, 'get':self.tracesPerSet},
                    {'name':'Key/Text Pattern', 'type':'list', 'values':self.valid_acqPatterns, 'get':self.getAcqPattern, 'set':self.setAcqPattern},
            ]},
        ])
        self.scopeParam = Parameter(name="Scope Settings", type='group', addLoadSave=True).register()
        self.params.getChild('Scope Module').stealDynamicParameters(self.scopeParam)

        self.targetParam = Parameter(name="Target Settings", type='group', addLoadSave=True).register()
        self.params.getChild('Target Module').stealDynamicParameters(self.targetParam)

        # Aux settings
        self.auxParam = self._auxList.getParams().register()

        # Note: Project settings are set up in setProject()

        self.newProject()
Beispiel #2
0
    def __init__(self):
        TargetTemplate.__init__(self)

        readers = pluginmanager.getPluginsInDictFromPackage(
            "chipwhisperer.capture.targets.smartcard_readers", True, True)
        protocols = pluginmanager.getPluginsInDictFromPackage(
            "chipwhisperer.capture.targets.smartcard_protocols", True, True)
        self.driver = None
        self.protocol = None

        self.params.addChildren([{
            'name': 'Reader Hardware',
            'type': 'list',
            'values': readers,
            'get': self.getConnection,
            'set': self.setConnection
        }, {
            'name': 'SmartCard Protocol',
            'type': 'list',
            'values': protocols,
            'get': self.getProtocol,
            'set': self.setProtocol
        }, {
            'name': 'SmartCard Explorer Dialog',
            'type': 'action',
            'action': lambda _: self.getScgui().show()
        }])
Beispiel #3
0
    def __init__(self):
        TargetTemplate.__init__(self)

        readers = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.targets.smartcard_readers", True, True)
        protocols = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.targets.smartcard_protocols", True, True)
        self.driver = None
        self.protocol = None

        self.params.addChildren([
            {'name':'Reader Hardware', 'type':'list', 'values':readers, 'get':self.getConnection, 'set':self.setConnection},
            {'name':'SmartCard Protocol', 'type':'list', 'values':protocols, 'get':self.getProtocol, 'set':self.setProtocol},
            {'name':'SmartCard Explorer Dialog', 'type':'action', 'action':lambda _: self.getScgui().show()}
        ])
    def __init__(self, api):
        self._api = api
        self.valid_preprocessingModules = pluginmanager.getPluginsInDictFromPackage(
            "chipwhisperer.analyzer.preprocessing", False, False)
        self.params = Parameter(name="Preprocessing Settings", type='group')

        self._moduleParams = [
            Parameter(name='self.ppmod[%d]' % (i), type='group')
            for i in range(self._num_modules)
        ]
        self._initModules()

        self.params.addChildren([
            {
                'name':
                'Selected Modules',
                'type':
                'group',
                'children': [{
                    'name': 'self.ppmod[%d]' % (step),
                    'type': 'list',
                    'values': self.valid_preprocessingModules,
                    'get': partial(self.getModule, step),
                    'set': partial(self.setModule, step)
                } for step in range(0, len(self._modules))]
            },
        ])
        for m in self._moduleParams:
            self.params.append(m)
Beispiel #5
0
    def __init__(self):
        TargetTemplate.__init__(self)

        ser_cons = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.targets.simpleserial_readers", True, False)
        self.ser = ser_cons[SimpleSerial_ChipWhispererLite._name]

        self.keylength = 16
        self.textlength = 16
        self.outputlength = 16
        self.input = ""
        self.params.addChildren([
            {'name':'Connection', 'type':'list', 'key':'con', 'values':ser_cons, 'get':self.getConnection, 'set':self.setConnection},
            {'name':'Key Length (Bytes)', 'type':'list', 'values':[8, 16, 32], 'get':self.keyLen, 'set':self.setKeyLen},
            {'name':'Input Length (Bytes)', 'type':'list', 'values':[8, 16], 'default':16, 'get':self.textLen, 'set':self.setTextLen},
            {'name':'Output Length (Bytes)', 'type':'list', 'values':[8, 16], 'default':16, 'get':self.outputLen, 'set':self.setOutputLen},
            # {'name':'Plaintext Command', 'key':'ptcmd', 'type':'list', 'values':['p', 'h'], 'value':'p'},
            {'name':'Init Command', 'key':'cmdinit', 'type':'str', 'value':''},
            {'name':'Load Key Command', 'key':'cmdkey', 'type':'str', 'value':'k$KEY$\\n'},
            {'name':'Load Input Command', 'key':'cmdinput', 'type':'str', 'value':''},
            {'name':'Go Command','key':'cmdgo', 'type':'str', 'value':'p$TEXT$\\n'},
            {'name':'Output Format', 'key':'cmdout', 'type':'str', 'value':'r$RESPONSE$\\n'},
            #{'name':'Data Format', 'key':'datafmt', 'type':'list', 'values':{'DEADBEEF':'',
            #                                                                 'DE AD BE EF':' ',
            #                                                                 'DE:AD:BE:EF':':',
            #                                                                 'DE-AD-BE-EF':'-'}, 'value':''},
        ])

        self.setConnection(self.ser, blockSignal=True)
Beispiel #6
0
    def __init__(self):
        AttackBaseClass.__init__(self)
        self._project = None
        self.attack = None

        algos = pluginmanager.getPluginsInDictFromPackage(
            "chipwhisperer.analyzer.attacks.profiling_algorithms", False,
            False, self)
        self.getParams().addChildren([
            {
                'name': 'Algorithm',
                'key': 'Prof_algo',
                'type': 'list',
                'values': algos,
                'value': algos['Template Attack'],
                'action': self.updateAlgorithm
            },  #TODO: Should be called from the AES module to figure out # of bytes
        ])
        AttackGenericParameters.__init__(self)

        # Do not use absolute
        self.useAbs = False
        self.updateAlgorithm()
        self.updateBytesVisible()
        self.setAbsoluteMode(False)
    def __init__(self):
        ScopeTemplate.__init__(self)

        scopes = pluginmanager.getPluginsInDictFromPackage(
            "chipwhisperer.capture.scopes.visascope_interface", True, False)

        self.params.addChildren([
            {
                'name': 'Scope Type',
                'key': 'type',
                'type': 'list',
                'values': scopes,
                'value': scopes[VisaScopeInterface_MSO54831D._name],
                'set': self.setCurrentScope,
                'childmode': 'parent'
            },
            {
                'name': 'Connect String',
                'key': 'connStr',
                'type': 'str',
                'value': ''
            },
            {
                'name': 'Example Strings',
                'type': 'list',
                'values': ['', 'TCPIP0::192.168.2.100::inst0::INSTR'],
                'value': '',
                'set': self.exampleString
            },
        ])
        self.params.init()
        self.scopetype = None
        self.setCurrentScope(self.findParam('type').getValue(type))
Beispiel #8
0
    def __init__(self):
        self._attack = None
        self.valid_attacks = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.analyzer.attacks", True, True)

        self.params = Parameter(name="Attack Settings", type="group")
        self.params.addChildren([
            {'name': 'Attack', 'type':'list', 'values':self.valid_attacks, 'get':self.getAttack, 'set':self.setAttack}
        ])
Beispiel #9
0
    def __init__(self, api):
        super(CWCaptureGUI, self).__init__(api, name=("ChipWhisperer" + u"\u2122" + " Capture " + CWCoreAPI.__version__), icon="cwiconC")
        self.addExampleScripts(pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.scripts", False, False, self))

        # Observers (callback methods)
        self.api.sigNewInputData.connect(self.newTargetData)
        self.api.sigConnectStatus.connect(self.connectStatusChanged)
        self.api.sigTraceDone.connect(self.glitchMonitor.traceDone)
        self.api.sigCampaignStart.connect(self.glitchMonitor.campaignStart)
        self.api.sigCampaignDone.connect(self.glitchMonitor.campaignDone)
Beispiel #10
0
    def __init__(self):
        TargetTemplate.__init__(self)

        spi_cons = pluginmanager.getPluginsInDictFromPackage(
            "chipwhisperer.capture.targets.spiflash_programmers", True, True)

        self.spi = None
        for c in spi_cons:
            if c is not None:
                self.spi = c
                break

        self.input = ""
        self.textlength = 16

        chip_names = []
        for c in self.supported_chips:
            chip_names.append(c['name'])

        self._chip = self.supported_chips[0]

        self.params.addChildren([
            {
                'name': 'Connection',
                'type': 'list',
                'key': 'con',
                'values': spi_cons,
                'get': self.getConnection,
                'set': self.setConnection
            },
            {
                'name': 'Input Length (Bytes)',
                'type': 'int',
                'range': (1, 512),
                'default': 16,
                'get': self.textLen,
                'set': self.setTextLen
            },
            {
                'name': 'Write Address (Hex)',
                'key': 'addr',
                'type': 'str',
                'value': '0x1000'
            },
            {
                'name': 'Flash Chip',
                'type': 'list',
                'values': chip_names,
                'get': self.chipname,
                'set': self.setChipname
            },
        ])

        if self.spi:
            self.setConnection(self.spi, blockSignal=True)
 def __init__(self, api):
     super(CWAnalyzerGUI,
           self).__init__(api,
                          name="ChipWhisperer" + u"\u2122" + " Analyzer " +
                          CWCoreAPI.__version__,
                          icon="cwiconA")
     self.addExampleScripts(
         pluginmanager.getPluginsInDictFromPackage(
             "chipwhisperer.analyzer.scripts", False, False, self))
     CWAnalyzerGUI.instance = self
     self.attackScriptGen.reloadScripts()
Beispiel #12
0
    def __init__(self):
        super(PicoScopeInterface, self).__init__()

        scopes = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.scopes.picoscope_interface", True, False)

        self.getParams().addChildren([
            {'name':'Scope Type', 'key':'type', 'type':'list', 'values':scopes, 'value':scopes["PS5000a"], 'action':self.setCurrentScope_act}
        ])
        self.scopetype = None
        self.advancedSettings = None
        self.setCurrentScope(self.findParam('type').getValue())
Beispiel #13
0
    def __init__(self):
        AttackBaseClass.__init__(self)
        self.attack = None

        algos = pluginmanager.getPluginsInDictFromPackage(
            "chipwhisperer.analyzer.attacks.keeloq_dpa_algorithms", False,
            False)
        self.getParams().addChildren([

            {'name':'Crypto Algorithm',       'key':'hw_algo', 'type':'list', 'values':{'Keeloq':models_keeloq}, 'value':models_keeloq, 'action':self.updateScript},
            {'name':'Attack Algorithm',       'key':'attack_algo', 'type':'list', 'values':algos, 'value':algos[algos.keys()[0]], 'action':self.updateAlgorithm},
            {'name':'Leakage Model',          'key':'hw_leak', 'type':'list', 'values':models_keeloq.leakagemodels, 'value':"LEAK_HW_CIPHERTEXT_BIT", 'action':self.updateScript},

            {'name':'Trace Setup', 'key':'tracesetup', 'type':'group'},   # FIXME: "attack runs" makes no sense for our use
            {'name':'Point Setup', 'key':'pointsetup', 'type':'group'},   # TODO: redundant when round timing is known

            {'name':'Timing Setup (optional for some uses)', 'key':'keeloq_timing', 'type':'group', 'children':[
                # {'name': '', 'type': 'label', 'value':"Position of rounds within traces", 'readonly': True},
                {'name':'Round 528 (pos)',     'key':'round528',   'type':'int', 'value':301, 'default':301, 'action':self.updateScript},
                {'name':'Round width (samples)',    'key':'roundwidth',     'type':'int', 'value':3,   'default':3,   'action':self.updateScript},
            ]},
            {'name':'Analysis Options (for Partition modes)', 'key':'keeloq_analysis', 'type':'group', 'children':[
                {'name':'Depth (rounds)',  'key':'depth',     'type':'int',
                         'help': "Analysis depth (rounds):\n"\
                                 "------------------------\n\n"
                                 "Specifies how many rounds deep to analyze. "\
                                 "Used by certain partition modes in Trace Explorer.\n"\
                                 "\n"\
                                 "Analysis starts with the ciphertext and removes any known keystream. "\
                                 "It will then go N rounds backwards, opening a window of N unknown keybits.\n"\
                                 "\n"\
                                 "**Usage in partition mode: FIXME**\n"\
                                 "\n"\
                                 "Show correlation for each of the 2^N possible keystreams. "\
                                 "Trace number corresponds to the keystream used (ex. trace=5 keystream=0101).\n"\
                                 "\n"\
                                 "NOTE: The cipher applies the keystream over time, not instantly.\n"\
                                 "\n",
                                     'value':4, 'default':4, 'limits':(0, 8), 'action':self.updateScript},
                {'name':'Known keystream',          'key':'keystream', 'type':'text', 'value':'', 'default':'', 'action':self.updateScript},
            ]},


        ])
        self.findParam('hw_leak').hide()

        AttackKeeloqParameters.__init__(self,
                                        hasHardwareModel=False,
                                        hasMultipleRuns=False)
        self.setAnalysisAlgorithm(
            self.findParam('attack_algo').getValue(), None, None)
        #        self.updateBytesVisible()
        self.updateScript()
Beispiel #14
0
    def __init__(self):
        AttackBaseClass.__init__(self)
        self.attack = None

        algos = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.analyzer.attacks.cpa_algorithms", False, False)
        self.getParams().addChildren([
            {'name':'Algorithm', 'key':'CPA_algo', 'type':'list',  'values':algos, 'value':algos["Progressive"], 'action':self.updateAlgorithm}, #TODO: Should be called from the AES module to figure out # of bytes
        ])
        AttackGenericParameters.__init__(self)
        self.setAnalysisAlgorithm(self.findParam('CPA_algo').getValue(), None, None)
        self.updateBytesVisible()
        self.updateScript()
Beispiel #15
0
    def __init__(self):
        AttackBaseClass.__init__(self)
        self.attack = None

        algos = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.analyzer.attacks.cpa_algorithms", False, False)
        self.getParams().addChildren([
            {'name':'Algorithm', 'key':'CPA_algo', 'type':'list',  'values':algos, 'value':algos["Progressive"], 'action':self.updateAlgorithm}, #TODO: Should be called from the AES module to figure out # of bytes
        ])
        AttackGenericParameters.__init__(self)
        self.setAnalysisAlgorithm(self.findParam('CPA_algo').getValue(), None, None)
        self.updateBytesVisible()
        self.updateScript()
Beispiel #16
0
    def __init__(self):
        ScopeTemplate.__init__(self)

        scopes = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.scopes.visascope_interface", True, False)

        self.params.addChildren([
            {'name':'Scope Type', 'key':'type', 'type':'list', 'values':scopes, 'value':scopes[VisaScopeInterface_MSO54831D._name], 'set':self.setCurrentScope, 'childmode':'parent'},
            {'name':'Connect String', 'key':'connStr', 'type':'str', 'value':''},
            {'name':'Example Strings', 'type':'list', 'values':['', 'TCPIP0::192.168.2.100::inst0::INSTR'], 'value':'', 'set':self.exampleString},
        ])
        self.params.init()
        self.scopetype = None
        self.setCurrentScope(self.findParam('type').getValue(type))
Beispiel #17
0
    def __init__(self):
        TargetTemplate.__init__(self)

        ser_cons = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.targets.simpleserial_readers", True, False)
        self.ser = ser_cons[SimpleSerial_ChipWhispererLite._name]

        self._active_ms = 10
        self._delay_ms = 0

        self.params.addChildren([
            {'name':'Crash', 'type':'bool', 'key':'crash', 'default':True, 'get':self.getCrash, 'set':self.setCrash, 'psync': True}
            ])

        self._crash = True
        return
Beispiel #18
0
    def __init__(self, api):
        super(CWCaptureGUI,
              self).__init__(api,
                             name=("ChipWhisperer" + u"\u2122" + " Capture " +
                                   CWCoreAPI.__version__),
                             icon="cwiconC")
        self.addExampleScripts(
            pluginmanager.getPluginsInDictFromPackage(
                "chipwhisperer.capture.scripts", False, False, self))

        # Observers (callback methods)
        self.api.sigNewInputData.connect(self.newTargetData)
        self.api.sigConnectStatus.connect(self.connectStatusChanged)
        self.api.sigTraceDone.connect(self.glitchMonitor.traceDone)
        self.api.sigCampaignStart.connect(self.glitchMonitor.campaignStart)
        self.api.sigCampaignDone.connect(self.glitchMonitor.campaignDone)
    def __init__(self):
        AttackBaseClass.__init__(self)
        self._project = None
        self.attack = None

        algos = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.analyzer.attacks.profiling_algorithms", False, False, self)
        self.getParams().addChildren([
            {'name':'Algorithm', 'key':'Prof_algo', 'type':'list', 'values':algos, 'value':algos['Template Attack'], 'action':lambda p:self.updateAlgorithm(p.getValue())}, #TODO: Should be called from the AES module to figure out # of bytes
        ])
        AttackGenericParameters.__init__(self)

        # Do not use absolute
        self.useAbs = False
        self.updateAlgorithm(self.findParam('Prof_algo').getValue())
        self.updateBytesVisible()
        self.setAbsoluteMode(False)
Beispiel #20
0
    def __init__(self):
        TargetTemplate.__init__(self)

        ser_cons = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.targets.simpleserial_readers", True, False)
        self.ser = ser_cons[SimpleSerial_ChipWhispererLite._name]

        self.keylength = 16
        self.textlength = 16
        self.outputlength = 16
        self.input = ""
        self.protver = ''

        # Preset lists are in the form
        # {'Dropdown Name':['Init Command', 'Load Key Command', 'Load Input Command', 'Go Command', 'Output Format']}
        # If a command is None, it's left unchanged and the text field is editable;
        # Otherwise, it's loaded with the value and set to readonly
        self.presets = {
            'Custom':[None, None, None, None, None],
            'SimpleSerial Encryption':['','k$KEY$\\n', '', 'p$TEXT$\\n', 'r$RESPONSE$\\n'],
            'SimpleSerial Authentication':['','k$KEY$\\n', 't$EXPECTED$\\n', 'p$TEXT$\\n', 'r$RESPONSE$\\n'],
            'Glitching':[None, None, None, None, '$GLITCH$\\n'],
        }
        self._preset = 'Custom'

        self.params.addChildren([
            {'name':'Connection', 'type':'list', 'key':'con', 'values':ser_cons, 'get':self.getConnection, 'set':self.setConnection},
            {'name':'Key Length (Bytes)', 'type':'list', 'values':[8, 16, 32], 'get':self.keyLen, 'set':self.setKeyLen},
            {'name':'Input Length (Bytes)', 'type':'list', 'values':[8, 16], 'default':16, 'get':self.textLen, 'set':self.setTextLen},
            {'name':'Output Length (Bytes)', 'type':'list', 'values':[8, 16], 'default':16, 'get':self.outputLen, 'set':self.setOutputLen},
            # {'name':'Plaintext Command', 'key':'ptcmd', 'type':'list', 'values':['p', 'h'], 'value':'p'},
            {'name':'Protocol Version', 'key':'proto', 'type':'group', 'expanded':True, 'children':[
                {'name':'Version', 'key':'ver', 'type':'list', 'values':['1.0', '1.1', 'auto'], 'value':'auto'},
                {'name':'Timeout (ms)', 'key':'timeout', 'type':'int', 'value':20, 'range':(0, 500), 'step':1},
            ]},
            {'name':'Preset Mode', 'key': 'preset', 'type': 'list', 'values': self.presets, 'get': self.getPreset, 'set': self.setPreset},
            {'name':'Init Command', 'key':'cmdinit', 'type':'str', 'value':''},
            {'name':'Load Key Command', 'key':'cmdkey', 'type':'str', 'value':'k$KEY$\\n'},
            {'name':'Load Input Command', 'key':'cmdinput', 'type':'str', 'value':''},
            {'name':'Go Command','key':'cmdgo', 'type':'str', 'value':'p$TEXT$\\n'},
            {'name':'Output Format', 'key':'cmdout', 'type':'str', 'value':'r$RESPONSE$\\n'},
            #{'name':'Data Format', 'key':'datafmt', 'type':'list', 'values':{'DEADBEEF':'',
            #                                                                 'DE AD BE EF':' ',
            #                                                                 'DE:AD:BE:EF':':',
            #                                                                 'DE-AD-BE-EF':'-'}, 'value':''},
        ])

        self.setConnection(self.ser, blockSignal=True)
Beispiel #21
0
    def __init__(self):
        super(PicoScopeInterface, self).__init__()

        scopes = pluginmanager.getPluginsInDictFromPackage(
            "chipwhisperer.capture.scopes.picoscope_interface", True, False)

        self.getParams().addChildren([{
            'name': 'Scope Type',
            'key': 'type',
            'type': 'list',
            'values': scopes,
            'value': scopes["PS5000a"],
            'action': self.setCurrentScope_act
        }])
        self.scopetype = None
        self.advancedSettings = None
        self.setCurrentScope(self.findParam('type').getValue())
Beispiel #22
0
def do_setup(scope, target):
    # get serial console
    ser_cons = pluginmanager.getPluginsInDictFromPackage(
        "chipwhisperer.capture.targets.simpleserial_readers", True, False)
    ser = ser_cons[SimpleSerial_ChipWhispererLite._name]
    ser.con(scope)
    ser.setBaud(VITA_UART0_BAUD)

    # setup trigger
    scope.advancedSettings.cwEXTRA.setTargetGlitchOut('A', False)
    scope.advancedSettings.cwEXTRA.setTargetGlitchOut('B', False)
    scope.edgeTrigger.setPin(True, scope.edgeTrigger.PIN_PDIC)
    scope.edgeTrigger.setEdgeStyle(scope.edgeTrigger.EDGE_RISING)
    scope.advancedSettings.cwEXTRA.setTriggerModule(
        CWExtraSettings.MODULE_EDGE)

    # set glitch parameters
    # trigger glitches with external trigger
    scope.glitch.resetDcms()
    scope.glitch.trigger_src = 'ext_single'
    scope.glitch.output = 'enable_only'  #'glitch_only'
    scope.glitch.repeat = GLITCH_REPEAT

    # set new clock
    if USE_4X_CLOCK:
        scope.io.hs2 = "disabled"
        scope.clock.clkgen_freq = 4 * VITA_CLK_FREQ
        scope.advancedSettings.cwEXTRA.setClkgenDivider(2)
        scope.io.hs2 = 'clkgen_divided'
    else:
        scope.io.hs2 = 'clkgen'

    # setup target
    if KEY_LEN == 32:
        target.findParam('cmdkey').setValue('K$KEY$\\n')
    else:
        target.findParam('cmdkey').setValue('k$KEY$\\n')
    target.findParam('cmdgo').setValue('p$TEXT$\\n')
    target.findParam('cmdout').setValue('r$RESPONSE$\\n')
    target.key_len = KEY_LEN
    target.init()

    do_set_encrypt(target, ENCRYPT)
Beispiel #23
0
    def __init__(self, parentParam=None):
        ScopeTemplate.__init__(self, parentParam)

        self.qtadc = openadc_qt.OpenADCQt()
        self.qtadc.dataUpdated.connect(self.doDataUpdated)
        # Bonus Modules for ChipWhisperer
        self.advancedSettings = None
        self.advancedSAD = None
        self.digitalPattern = None
        self.refreshTimer = timer.runTask(self.dcmTimeout, 1)

        scopes = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.scopes.openadc_interface", True, False, self, self.qtadc)
        self.scopetype = scopes[OpenADCInterface_NAEUSBChip._name]
        self.params.addChildren([
            {'name':'Connection', 'key':'con', 'type':'list', 'values':scopes, 'get':self.getCurrentScope, 'set':self.setCurrentScope, 'childmode':'parent'},
            {'name':'Auto-Refresh DCM Status', 'type':'bool', 'value':True, 'action':self.setAutorefreshDCM}
        ])
        self.params.init()
        self.params.append(self.qtadc.getParams())
Beispiel #24
0
    def __init__(self, prog_name="ChipWhisperer", prog_ver=""):
        self.valid_traces = pluginmanager.getPluginsInDictFromPackage(
            "chipwhisperer.common.traces", True, True)
        self._trace_format = None

        self.params = Parameter(name="Project Settings", type="group")
        self.params.addChildren([
            {
                'name': 'Trace Format',
                'type': 'list',
                'values': self.valid_traces,
                'get': self.getTraceFormat,
                'set': self.setTraceFormat
            },
        ])

        self.findParam("Trace Format").setValue(TraceContainerNative(),
                                                addToList=True)

        #self.traceParam = Parameter(name="Trace Settings", type='group', addLoadSave=True).register()
        #self.params.getChild('Trace Format').stealDynamicParameters(self.traceParam)

        self.sigFilenameChanged = util.Signal()
        self.sigStatusChanged = util.Signal()
        self.dirty = util.Observable(True)

        self.settingsDict = {
            'Project Name': "Untitled",
            'Project File Version': "1.00",
            'Project Author': "Unknown"
        }
        self.datadirectory = ""
        self.config = ConfigObjProj(callback=self.configObjChanged)
        self._traceManager = TraceManager().register()
        self._traceManager.dirty.connect(self.__dirtyCallback)
        self.setFilename(ProjectFormat.untitledFileName)

        self.setProgramName(prog_name)
        self.setProgramVersion(prog_ver)

        if __debug__:
            logging.debug('Created: ' + str(self))
Beispiel #25
0
    def __init__(self):
        ScopeTemplate.__init__(self)

        self.qtadc = openadc_qt.OpenADCQt()
        self.qtadc.dataUpdated.connect(self.newDataReceived)
        # Bonus Modules for ChipWhisperer
        self.advancedSettings = None
        self.advancedSAD = None
        self.digitalPattern = None

        self._is_connected = False

        scopes = pluginmanager.getPluginsInDictFromPackage(
            "chipwhisperer.capture.scopes.openadc_interface", True, False,
            self.qtadc)
        self.scopetype = scopes[OpenADCInterface_NAEUSBChip._name]
        self.params.addChildren([{
            'name': 'Connection',
            'key': 'con',
            'type': 'list',
            'values': scopes,
            'get': self.getCurrentScope,
            'set': self.setCurrentScope,
            'childmode': 'parent'
        }, {
            'name':
            'Auto-Refresh DCM Status',
            'type':
            'bool',
            'value':
            True,
            'action':
            self.setAutorefreshDCM,
            'help':
            "Refresh status/info automatically every second."
        }])
        self.params.init()
        self.params.append(self.qtadc.getParams())

        self.refreshTimer = timer.runTask(self.dcmTimeout, 1)
        self.refreshTimer.start()
Beispiel #26
0
    def __init__(self):
        AutoScript.__init__(self)
        AnalysisSource.__init__(self)
        PassiveTraceObserver.__init__(self)
        self.getParams().getChild("Input").hide()
        self._traceStart = 0
        self._iterations = 1
        self._tracePerAttack = 1
        self._reportingInterval = 10
        self._pointRange = (0,0)
        self._targetSubkeys = []
        self._project = None
        self.useAbs = True
        self.attack = None

        self.getParams().addChildren([
            {'name':'Attack Algorithm', 'type':'list',  'values':self._algos, 'get':self.getAlgorithm, 'set':self.setAlgorithm, 'action':self.updateScript, 'childmode': 'parent'}
        ])
        models = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.analyzer.attacks.models", True, False)
        self.getParams().addChildren([
            {'name':'Crypto Algorithm', 'type':'list', 'values':models, 'value':models['AES 128'], 'action':self.refreshByteList, 'childmode':'child'},
            {'name':'Points Range', 'key':'prange', 'type':'range', 'get':self.getPointRange, 'set':self.setPointRange, 'action':self.updateScript},
        ])
        for m in models.itervalues():
            m.sigParametersChanged.connect(self.updateScript)

        self.getParams().addChildren([
            {'name':'Starting Trace', 'key':'strace', 'type':'int', 'get':self.getTraceStart, 'set':self.setTraceStart, 'action':self.updateScript},
            {'name':'Traces per Attack', 'key':'atraces', 'type':'int', 'limits':(1, 1E6), 'get':self.getTracesPerAttack, 'set':self.setTracesPerAttack, 'action':self.updateScript},
            {'name':'Iterations', 'key':'runs', 'type':'int', 'limits':(1, 1E6), 'get':self.getIterations, 'set':self.setIterations, 'action':self.updateScript},
            {'name':'Reporting Interval', 'key':'reportinterval', 'type':'int', 'get':self.getReportingInterval, 'set':self.setReportingInterval, 'action':self.updateScript},
        ])
        self.getParams().init()

        self.setAlgorithm(self._analysisAlgorithm)
        self.refreshByteList()
        self.updateScript()
        if __debug__: logging.debug('Created: ' + str(self))
Beispiel #27
0
    def __init__(self):
        AutoScript.__init__(self)
        AnalysisSource.__init__(self)
        PassiveTraceObserver.__init__(self)
        self.getParams().getChild("Input").hide()
        self._traceStart = 0
        self._iterations = 1
        self._tracePerAttack = 1
        self._reportingInterval = 10
        self._pointRange = (0,0)
        self._targetSubkeys = []
        self._project = None
        self.useAbs = True
        self.attack = None

        self.getParams().addChildren([
            {'name':'Attack Algorithm', 'type':'list',  'values':self._algos, 'get':self.getAlgorithm, 'set':self.setAlgorithm, 'action':self.updateScript, 'childmode': 'parent'}
        ])
        models = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.analyzer.attacks.models", True, False)
        self.getParams().addChildren([
            {'name':'Crypto Algorithm', 'type':'list', 'values':models, 'value':models['AES 128'], 'action':self.refreshByteList, 'childmode':'child'},
            {'name':'Points Range', 'key':'prange', 'type':'range', 'get':self.getPointRange, 'set':self.setPointRange, 'action':self.updateScript},
        ])
        for m in models.itervalues():
            m.sigParametersChanged.connect(self.updateScript)

        self.getParams().addChildren([
            {'name':'Starting Trace', 'key':'strace', 'type':'int', 'get':self.getTraceStart, 'set':self.setTraceStart, 'action':self.updateScript},
            {'name':'Traces per Attack', 'key':'atraces', 'type':'int', 'limits':(1, 1E6), 'get':self.getTracesPerAttack, 'set':self.setTracesPerAttack, 'action':self.updateScript},
            {'name':'Iterations', 'key':'runs', 'type':'int', 'limits':(1, 1E6), 'get':self.getIterations, 'set':self.setIterations, 'action':self.updateScript},
            {'name':'Reporting Interval', 'key':'reportinterval', 'type':'int', 'get':self.getReportingInterval, 'set':self.setReportingInterval, 'action':self.updateScript},
        ])
        self.getParams().init()

        self.setAlgorithm(self._analysisAlgorithm)
        self.refreshByteList()
        self.updateScript()
        if __debug__: logging.debug('Created: ' + str(self))
Beispiel #28
0
 def getClasses(cls):
     if not cls.__classes:
         cls.__classes = getPluginsInDictFromPackage("chipwhisperer.common.results", False, False)
     return cls.__classes
Beispiel #29
0
 def __init__(self):
     self._algos = pluginmanager.getPluginsInDictFromPackage(
         "chipwhisperer.analyzer.attacks.cpa_algorithms", True, False)
     self._analysisAlgorithm = self._algos["Progressive"]
     AttackBaseClass.__init__(self)
     self.updateScript()
Beispiel #30
0
 def __init__(self):
     self._algos = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.analyzer.attacks.profiling_algorithms", True, False)
     self._analysisAlgorithm = self._algos["Template Attack"]
     AttackBaseClass.__init__(self)
     self.useAbs = False # Do not use absolute
Beispiel #31
0
    def __init__(self):
        TargetTemplate.__init__(self)

        ser_cons = pluginmanager.getPluginsInDictFromPackage(
            "chipwhisperer.capture.targets.simpleserial_readers", True, False)
        self.ser = ser_cons[SimpleSerial_ChipWhispererLite._name]

        self.keylength = 16
        self.textlength = 16
        self.outputlength = 16
        self.input = ""
        self.params.addChildren([
            {
                'name': 'Connection',
                'type': 'list',
                'key': 'con',
                'values': ser_cons,
                'get': self.getConnection,
                'set': self.setConnection
            },
            {
                'name': 'Key Length (Bytes)',
                'type': 'list',
                'values': [8, 16, 32],
                'get': self.keyLen,
                'set': self.setKeyLen
            },
            {
                'name': 'Input Length (Bytes)',
                'type': 'list',
                'values': [8, 16],
                'default': 16,
                'get': self.textLen,
                'set': self.setTextLen
            },
            {
                'name': 'Output Length (Bytes)',
                'type': 'list',
                'values': [8, 16],
                'default': 16,
                'get': self.outputLen,
                'set': self.setOutputLen
            },
            # {'name':'Plaintext Command', 'key':'ptcmd', 'type':'list', 'values':['p', 'h'], 'value':'p'},
            {
                'name': 'Init Command',
                'key': 'cmdinit',
                'type': 'str',
                'value': ''
            },
            {
                'name': 'Load Key Command',
                'key': 'cmdkey',
                'type': 'str',
                'value': 'k$KEY$\\n'
            },
            {
                'name': 'Load Input Command',
                'key': 'cmdinput',
                'type': 'str',
                'value': ''
            },
            {
                'name': 'Go Command',
                'key': 'cmdgo',
                'type': 'str',
                'value': 'p$TEXT$\\n'
            },
            {
                'name': 'Output Format',
                'key': 'cmdout',
                'type': 'str',
                'value': 'r$RESPONSE$\\n'
            },
            #{'name':'Data Format', 'key':'datafmt', 'type':'list', 'values':{'DEADBEEF':'',
            #                                                                 'DE AD BE EF':' ',
            #                                                                 'DE:AD:BE:EF':':',
            #                                                                 'DE-AD-BE-EF':'-'}, 'value':''},
        ])

        self.setConnection(self.ser, blockSignal=True)
Beispiel #32
0
    def __init__(self):
        CWCoreAPI.instance = self
        self.sigNewProject = util.Signal()
        self.sigNewScopeData = util.Signal()
        self.sigConnectStatus = util.Signal()
        self.sigAttackChanged = util.Signal()
        self.sigNewInputData = util.Signal()
        self.sigNewTextResponse = util.Signal()
        self.sigTraceDone = util.Signal()
        self.sigCampaignStart = util.Signal()
        self.sigCampaignDone = util.Signal()
        self.sigTracesChanged = util.Signal()
        self.executingScripts = util.Observable(False)

        self.valid_scopes = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.scopes", True, True)
        self.valid_targets =  pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.targets", True, True)
        self.valid_traces = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.common.traces", True, True)
        self.valid_aux = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.auxiliary", True, True)
        self.valid_acqPatterns =  pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.acq_patterns", True, False)
        self.valid_attacks = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.analyzer.attacks", True, False)
        self.valid_preprocessingModules = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.analyzer.preprocessing", False, True)

        self.settings = Settings()

        # Initialize default values
        self._project = self._scope = self._target = self._attack =  self._traceFormat = self._acqPattern = None
        self._attack = self.valid_attacks.get("CPA", None)
        self._acqPattern = self.valid_acqPatterns["Basic"]
        self._auxList = [None]  # TODO: implement it as a list in the whole class
        self._numTraces = 50
        self._numTraceSets = 1

        self.params = Parameter(name='Generic Settings', type='group', addLoadSave=True).register()
        self.params.addChildren([
            {'name':'Scope Module', 'key':'scopeMod', 'type':'list', 'values':self.valid_scopes, 'get':self.getScope, 'set':self.setScope},
            {'name':'Target Module', 'key':'targetMod', 'type':'list', 'values':self.valid_targets, 'get':self.getTarget, 'set':self.setTarget},
            {'name':'Trace Format', 'type':'list', 'values':self.valid_traces, 'get':self.getTraceFormat, 'set':self.setTraceFormat},
            {'name':'Auxiliary Module', 'type':'list', 'values':self.valid_aux, 'get':self.getAuxModule, 'set':self.setAux},
            {'name':'Acquisition Settings', 'type':'group', 'children':[
                    {'name':'Number of Traces', 'type':'int', 'limits':(1, 1E9), 'get':self.getNumTraces, 'set':self.setNumTraces, 'linked':['Traces per Set']},
                    {'name':'Number of Sets', 'type':'int', 'limits':(1, 1E6), 'get':self.getNumTraceSets, 'set':self.setNumTraceSets, 'linked':['Traces per Set'], 'tip': 'Break acquisition into N sets, '
                     'which may cause data to be saved more frequently. The default capture driver requires that NTraces/NSets is small enough to avoid running out of system memory '
                     'as each segment is buffered into RAM before being written to disk.'},
                    {'name':'Traces per Set', 'type':'int', 'readonly':True, 'get':self.tracesPerSet},
                    {'name':'Key/Text Pattern', 'type':'list', 'values':self.valid_acqPatterns, 'get':self.getAcqPattern, 'set':self.setAcqPattern},
            ]},
        ])
        self.scopeParam = Parameter(name="Scope Settings", type='group', addLoadSave=True).register()
        self.params.getChild('Scope Module').stealDynamicParameters(self.scopeParam)

        self.targetParam = Parameter(name="Target Settings", type='group', addLoadSave=True).register()
        self.params.getChild('Target Module').stealDynamicParameters(self.targetParam)

        self.traceParam = Parameter(name="Trace Settings", type='group', addLoadSave=True).register()
        self.params.getChild('Trace Format').stealDynamicParameters(self.traceParam)

        self.auxParam = Parameter(name="Aux Settings", type='group', addLoadSave=True).register()
        self.params.getChild('Auxiliary Module').stealDynamicParameters(self.auxParam)

        # self.attackParam = Parameter(name="Attack Settings", type='group')
        # self.params.getChild('Attack Module').getDynamicParameters(self.attackParam)

        self.newProject()
    def __init__(self):
        TargetTemplate.__init__(self)

        ser_cons = pluginmanager.getPluginsInDictFromPackage(
            "chipwhisperer.capture.targets.simpleserial_readers", True, False)
        self.ser = ser_cons[SimpleSerial_ChipWhispererLite._name]

        self.keylength = 16
        self.textlength = 16
        self.outputlength = 16
        self.input = ""
        self.key = ""
        self._protver = 'auto'
        self._read_timeout = 500
        self.maskEnabled = False
        self.masklength = 18
        self._fixedMask = True
        self.initmask = '1F 70 D6 3C 23 EB 1A B8 6A D5 E2 0D 5F D9 58 A3 CA 9D'
        self._mask = util.hexStrToByteArray(self.initmask)
        self.protformat = 'hex'

        # Preset lists are in the form
        # {'Dropdown Name':['Init Command', 'Load Key Command', 'Load Input Command', 'Go Command', 'Output Format']}
        # If a command is None, it's left unchanged and the text field is editable;
        # Otherwise, it's loaded with the value and set to readonly
        self.presets = {
            'Custom': [None, None, None, None, None],
            'SimpleSerial Encryption':
            ['', 'k$KEY$\\n', '', 'p$TEXT$\\n', 'r$RESPONSE$\\n'],
            'SimpleSerial Authentication': [
                '', 'k$KEY$\\n', 't$EXPECTED$\\n', 'p$TEXT$\\n',
                'r$RESPONSE$\\n'
            ],
            'Glitching': [None, None, None, None, '$GLITCH$\\n'],
        }
        self._preset = 'Custom'

        self._linkedmaskgroup = (('maskgroup', 'cmdmask'),
                                 ('maskgroup', 'initmask'), ('maskgroup',
                                                             'masktype'),
                                 ('maskgroup', 'masklen'), ('maskgroup',
                                                            'newmask'))
        self.params.addChildren([
            {
                'name': 'Connection',
                'type': 'list',
                'key': 'con',
                'values': ser_cons,
                'get': self.getConnection,
                'set': self.setConnection
            },
            {
                'name': 'Key Length (Bytes)',
                'type': 'list',
                'values': [8, 16, 32],
                'get': self.keyLen,
                'set': self.setKeyLen
            },
            {
                'name': 'Input Length (Bytes)',
                'type': 'list',
                'values': [1, 2, 4, 8, 16, 32],
                'default': 16,
                'get': self.textLen,
                'set': self.setTextLen
            },
            {
                'name': 'Output Length (Bytes)',
                'type': 'list',
                'values': [8, 16, 32],
                'default': 16,
                'get': self.outputLen,
                'set': self.setOutputLen
            },
            # {'name':'Plaintext Command', 'key':'ptcmd', 'type':'list', 'values':['p', 'h'], 'value':'p'},
            {
                'name':
                'Protocol Version',
                'key':
                'proto',
                'type':
                'group',
                'expanded':
                True,
                'children': [
                    {
                        'name': 'Version',
                        'key': 'ver',
                        'type': 'list',
                        'values': ['1.0', '1.1', 'auto'],
                        'value': 'auto'
                    },
                    {
                        'name': 'Timeout (ms)',
                        'key': 'timeout',
                        'type': 'int',
                        'value': 20,
                        'range': (0, 500),
                        'step': 1
                    },
                ]
            },
            {
                'name': 'Read timeout (ms)',
                'key': 'timeout',
                'type': 'int',
                'get': self.readTimeout,
                'set': self.setReadTimeout,
                'range': (0, 5000),
                'step': 1
            },
            {
                'name': 'Preset Mode',
                'key': 'preset',
                'type': 'list',
                'values': self.presets,
                'get': self.getPreset,
                'set': self.setPreset
            },
            {
                'name': 'Init Command',
                'key': 'cmdinit',
                'type': 'str',
                'value': ''
            },
            {
                'name': 'Load Key Command',
                'key': 'cmdkey',
                'type': 'str',
                'value': 'k$KEY$\\n'
            },
            {
                'name': 'Load Input Command',
                'key': 'cmdinput',
                'type': 'str',
                'value': ''
            },
            {
                'name': 'Go Command',
                'key': 'cmdgo',
                'type': 'str',
                'value': 'p$TEXT$\\n'
            },
            {
                'name': 'Output Format',
                'key': 'cmdout',
                'type': 'str',
                'value': 'r$RESPONSE$\\n'
            },
            {
                'name':
                'Mask',
                'key':
                'maskgroup',
                'type':
                'group',
                'expanded':
                True,
                'children': [
                    {
                        'name': 'Mask Supported',
                        'key': 'maskenabled',
                        'type': 'bool',
                        'get': self.getMaskEnabled,
                        'set': self.setMaskEnabled,
                        'linked': self._linkedmaskgroup,
                        'action': self.changeMaskEnabled
                    },
                    {
                        'name': 'Mask Length (Bytes)',
                        'key': 'masklen',
                        'type': 'list',
                        'values': [18],
                        'default': 18,
                        'get': self.maskLen,
                        'set': self.setMaskLen,
                        'visible': self.getMaskEnabled()
                    },
                    {
                        'name': 'Load Mask Command',
                        'key': 'cmdmask',
                        'type': 'str',
                        'value': 'm$MASK$\\n',
                        'visible': self.getMaskEnabled()
                    },
                    {
                        'name': 'Mask Type',
                        'key': 'masktype',
                        'type': 'list',
                        'values': {
                            'Random': False,
                            'Fixed': True
                        },
                        'get': self.getMaskType,
                        'set': self.setMaskType,
                        'visible': self.getMaskEnabled(),
                        'action': self.changeMaskType
                    },
                    {
                        'name': 'Fixed Mask',
                        'key': 'initmask',
                        'type': 'str',
                        'get': self.getInitialMask,
                        'set': self.setInitialMask,
                        'visible': self.getMaskEnabled()
                        and self.getMaskType()
                    },
                    {
                        'name': 'New Random Mask',
                        'key': 'newmask',
                        'type': 'action',
                        'action': self.newRandMask,
                        'visible': self.getMaskEnabled()
                        and self.getMaskType()
                    },
                ]
            },
            {
                'name':
                'Protocol format',
                'type':
                'list',
                'values': ['bin', 'hex'],
                'get':
                self.protFormat,
                'set':
                self.setProtFormat,
                'help':
                "Assume the protocol to be in the given format. The original SimpleSerial module assumed that the keys where to be sent in hex format but in some situations it is needed to conver the contents to a binary string representation"
            }
            #{'name':'Data Format', 'key':'datafmt', 'type':'list', 'values':{'DEADBEEF':'',
            #                                                                 'DE AD BE EF':' ',
            #                                                                 'DE:AD:BE:EF':':',
            #                                                                 'DE-AD-BE-EF':'-'}, 'value':''},
        ])

        self.outstanding_ack = False

        self.setConnection(self.ser, blockSignal=True)
        self.disable_newattr()
def run_payload(scope, target, master_timeout=0, verbose=0):
    if not hasattr(target, 'mmc'):
        target = cwtarget()
        target.con(scope)
    # setup parameters needed for glitch the stm32f
    scope.glitch.clk_src = 'clkgen'

    scope.io.hs2 = "disabled"
    scope.clock.clkgen_freq = VITA_CLK_FREQ
    scope.io.hs2 = 'clkgen'
    scope.io.tio1 = "serial_tx"
    scope.io.tio2 = "serial_rx"

    # setup MMC trigger to look for READ_SINGLE_BLOCK of 0x0 response

    mmctrigger = scope.mmcTrigger
    mmctrigger.setMatchCmd(True)
    mmctrigger.setCmdIndex(MMCPacket.Cmd.READ_SINGLE_BLOCK.value)
    mmctrigger.setDirection(2)
    mmctrigger.setDataCompareOp(4)
    mmctrigger.setTriggerData('0x800A')
    mmctrigger.setTriggerNext(True)

    # get MMC output
    mmc = target.mmc

    # get serial console
    ser_cons = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.targets.simpleserial_readers", True, False)
    ser = ser_cons[SimpleSerial_ChipWhispererLite._name]
    ser.con(scope)
    ser.setBaud(VITA_UART0_BAUD)

    # format output table
    headers = ['num packets', 'width', 'offset', 'success']
    #glitch_display = GlitchResultsDisplay(headers)

    # setup trigger
    scope.advancedSettings.cwEXTRA.setTargetGlitchOut('A', False)
    scope.advancedSettings.cwEXTRA.setTargetGlitchOut('B', False)
    scope.advancedSettings.cwEXTRA.setTriggerModule(CWExtraSettings.MODULE_MMCTRIGGER)

    # set glitch parameters
    # trigger glitches with external trigger
    scope.glitch.resetDcms()
    scope.glitch.output = 'enable_only'
    scope.glitch.trigger_src = 'ext_continuous'

    # enable trigger
    scope.advancedSettings.cwEXTRA.setTargetGlitchOut('A', True)

    # init
    target.init()

    # power on and hold reset
    if verbose:
        print('Waiting for Vita to power on...')
    scope.io.nrst = 'low'
    scope.io.nrst = 'disabled'
    scope.io.pdid = 'low'
    while mmc.count() == 0:
        pass
    scope.io.pdid = 'disabled'
    scope.io.nrst = 'low'

    if verbose:
        print('Starting glitch...')
    success = False
    tries = 0
    while not success:
        for offset in xrange(MIN_OFFSET, MAX_OFFSET+1, OFFSET_STEP):
            # set offset from trigger
            scope.glitch.ext_offset = offset
            for width in xrange(MIN_WIDTH, MAX_WIDTH+1, WIDTH_STEP):
                if verbose:
                    print('trying offset {}, width {}'.format(offset, width))

                # reset device
                scope.io.nrst = 'low'
                scope.glitch.repeat = width
                #scope.glitch.repeat = 1
                # flush the buffer
                time.sleep(TIME_RESET_HOLD)

                timeout = GLITCH_FIND_TIMEOUT
                # wait for target to finish
                state = States.STARTUP

                last_cnt = 0
                while mmc.count() > 0:
                    pkt = mmc.read()
                    last_cnt = pkt.num
                    if verbose > 1:
                        print(str(pkt))
                count = ser.inWaiting()
                if count > 0:
                    print('WARNING: UART buffer non-empty')
                    ser.read(count)

                scope.io.nrst = 'disabled'
                timestamp = 0
                reads = 0
                while timeout > 0:
                    while mmc.count() > 0:
                        timeout = GLITCH_FIND_TIMEOUT
                        pkt = mmc.read()
                        if pkt.num < last_cnt:
                            timestamp = ((pkt.num + 0x10000 - last_cnt) * 0x100 * 1000.0) / CW_SYSCLK_FREQ
                        else:
                            timestamp = ((pkt.num - last_cnt) * 0x100 * 1000.0) / CW_SYSCLK_FREQ
                        last_cnt = pkt.num
                        if verbose > 1:
                            print('[{:10.5f}ms] {}'.format(timestamp, str(pkt)))
                        if pkt.is_req:
                            if pkt.cmd == MMCPacket.Cmd.READ_SINGLE_BLOCK:
                                reads += 1
                            if state == States.STARTUP:
                                if pkt.cmd == MMCPacket.Cmd.GO_IDLE_STATE:
                                    state = States.IDLE
                            elif state == States.IDLE:
                                if pkt.cmd == MMCPacket.Cmd.READ_SINGLE_BLOCK and pkt.content > 0:
                                    state = States.PAYLOAD_LOADING
                                elif pkt.cmd == MMCPacket.Cmd.GO_IDLE_STATE:
                                    state = States.RESTARTED
                            elif state == States.PAYLOAD_LOADING:
                                if pkt.cmd == MMCPacket.Cmd.SEND_STATUS:
                                    state = States.PAYLOAD_READ
                                elif pkt.cmd == MMCPacket.Cmd.GO_IDLE_STATE:
                                    state = States.RESTARTED
                            elif state == States.PAYLOAD_READ:
                                if pkt.cmd == MMCPacket.Cmd.GO_IDLE_STATE:
                                    state = States.RESTARTED
                        if state == States.RESTARTED:
                            timeout = -1
                            break
                    else:
                        time.sleep(0.1)
                        timeout -= 1

                # for table display purposes
                data = [offset, width, state, reads]
                if verbose:
                    print(data)
                #glitch_display.add_data(data)

                if state == States.PAYLOAD_READ:
                    if verbose:
                        print('Waiting for UART data...')
                    timeout = WAIT_FOR_UART_TIMEOUT
                    count = 0
                    dat = ''
                    while timeout > 0:
                        count = ser.inWaiting()
                        if count > 0:
                            dat = ser.read(count)
                            if verbose:
                                print(dat)
                            break
                        time.sleep(0.1)
                        timeout -= 1

                    success = dat == 'HI\r\n'

                if success:
                    break
            if success:
                break
        tries += 1
        if master_timeout > 0 and tries >= master_timeout:
          return False
    return success
# setup MMC trigger to look for READ_SINGLE_BLOCK of 0x0 response

mmctrigger = scope.mmcTrigger
mmctrigger.setMatchCmd(True)
mmctrigger.setCmdIndex(MMCPacket.Cmd.READ_SINGLE_BLOCK.value)
mmctrigger.setDirection(2)
mmctrigger.setDataCompareOp(1)
mmctrigger.setTriggerData('0x0')
mmctrigger.setTriggerNext(True)

# get MMC output
mmc = target.mmc

# get serial console
ser_cons = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.capture.targets.simpleserial_readers", True, False)
ser = ser_cons[SimpleSerial_ChipWhispererLite._name]
ser.con(scope)
ser.setBaud(VITA_UART0_BAUD)

# format output table
headers = ['num packets', 'width', 'offset', 'success']
#glitch_display = GlitchResultsDisplay(headers)

# set glitch parameters
# trigger glitches with external trigger
scope.glitch.trigger_src = 'ext_continuous'
scope.glitch.output = 'enable_only'
scope.io.hs2 = 'clkgen'

# enable trigger
Beispiel #36
0
 def __init__(self):
     self._algos = pluginmanager.getPluginsInDictFromPackage("chipwhisperer.analyzer.attacks.cpa_algorithms", True, False)
     self._analysisAlgorithm = self._algos["Progressive"]
     AttackBaseClass.__init__(self)
     self.updateScript()
Beispiel #37
0
 def getClasses(cls):
     if not cls.__classes:
         cls.__classes = getPluginsInDictFromPackage(
             "chipwhisperer.common.results", False, False)
     return cls.__classes
Beispiel #38
0
 def __init__(self):
     self._algos = pluginmanager.getPluginsInDictFromPackage(
         "chipwhisperer.analyzer.attacks.profiling_algorithms", True, False)
     self._analysisAlgorithm = self._algos["Template Attack"]
     AttackBaseClass.__init__(self)
     self.useAbs = False  # Do not use absolute
Beispiel #39
0
 def __init__(self, api):
     super(CWAnalyzerGUI, self).__init__(api, name="ChipWhisperer" + u"\u2122" + " Analyzer " + CWCoreAPI.__version__, icon="cwiconA")
     self.addExampleScripts(pluginmanager.getPluginsInDictFromPackage("chipwhisperer.analyzer.scripts", False, False, self))
     CWAnalyzerGUI.instance = self
     self.attackScriptGen.reloadScripts()