How to use the chipwhisperer.common.utils.util.DictType function in chipwhisperer

To help you get started, we’ve selected a few chipwhisperer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github newaetech / chipwhisperer / software / chipwhisperer / common / results / base.py View on Github external
#
#    You should have received a copy of the GNU General Public License
#    along with chipwhisperer.  If not, see .
#=================================================

from chipwhisperer.common.utils import util
from chipwhisperer.common.utils.parameter import Parameterized, Parameter
from chipwhisperer.common.utils.pluginmanager import getPluginsInDictFromPackage


class ResultsBase(Parameterized):
    """
    Base class for the output widgets:
    To be uses in conjunct with chipwhisperer.common.utils.analysissource/tracesource
    """
    registeredObjects = util.DictType()
    sigRegisteredObjectsChanged = util.Signal()
    __classParameter = None
    __classes = None

    def getWidget(self):
        return None

    # @classmethod  #TODO: Finish this method
    # def deregister(self, name):
    #     if self.registeredObjects.pop(name, None):
    #         self.sigRegisteredObjectsChanged.emit(None)

    @classmethod
    def getClasses(cls):
        if not cls.__classes:
            cls.__classes = getPluginsInDictFromPackage("chipwhisperer.common.results", False, False)
github newaetech / chipwhisperer / software / chipwhisperer / common / results / pgevstrace.py View on Github external
def calculatePGE(self):
        stats = self._stats
        pge = stats.pge_total
        allpge = util.DictType()
        
        for i in pge:
            tnum = i['trace']
            if not tnum in allpge:
                allpge[tnum] = [{'pgesum':0, 'trials':0} for z in range(0,stats.numSubkeys)]

            allpge[tnum][i['subkey']]['pgesum'] += i['pge']
            allpge[tnum][i['subkey']]['trials'] += 1

        for (tnum, plist) in allpge.items():
            for j in plist:
                if j['trials'] > 0:
                    j['pge'] = float(j['pgesum']) / float(j['trials'])
                    # print "%d "%j['trials'],
                else:
                    j['pge'] = None
github newaetech / chipwhisperer / software / chipwhisperer / capture / scopes / picoscope_interface / picoscopes.py View on Github external
def __init__(self, psClass=None):
        self.ps = psClass
        self.dataUpdated = util.Signal()

        chlist = {}
        for t in self.ps.CHANNELS:
            if self.ps.CHANNELS[t] < self.ps.CHANNELS['MaxChannels']:
                chlist[t] = self.ps.CHANNELS[t]

        # Rebuild channel range as string + api value
        chRange = util.DictType()
        for key in sorted(self.ps.CHANNEL_RANGE):
            chRange[ key['rangeStr'] ] = key['rangeV']

        self.getParams().addChildren([
            {'name':'Trace Measurement', 'key':'trace', 'type':'group', 'children':[
                {'name':'Source', 'key':'tracesource', 'type':'list', 'values':chlist, 'value':0, 'action':self.updateCurrentSettings},
                {'name':'Probe Att.', 'key':'traceprobe', 'type':'list', 'values':{'1:1':1, '1:10':10}, 'value':1, 'action':self.updateCurrentSettings},
                {'name':'Coupling', 'key':'tracecouple', 'type':'list', 'values':self.ps.CHANNEL_COUPLINGS, 'value':0, 'action':self.updateCurrentSettings},
                {'name':'Y-Range', 'key':'traceyrange', 'type':'list', 'values':chRange, 'value':1.0, 'action':self.updateCurrentSettings},
            ]},
            {'name':'Trigger', 'key':'trig', 'type':'group', 'children':[
                {'name':'Source', 'key':'trigsource', 'type':'list', 'values':chlist, 'value':1, 'action':self.updateCurrentSettings},
                {'name':'Probe Att.', 'key':'trigprobe', 'type':'list', 'values':{'1:1':1, '1:10':10}, 'value':10, 'action':self.updateCurrentSettings},
                {'name':'Coupling', 'key':'trigcouple', 'type':'list', 'values':self.ps.CHANNEL_COUPLINGS, 'value':1, 'action':self.updateCurrentSettings},
                {'name':'Y-Range', 'key':'trigrange', 'type':'list', 'values':chRange, 'value':5.0, 'action':self.updateCurrentSettings},
                {'name':'Trigger Direction', 'key':'trigtype', 'type':'list', 'values':self.ps.THRESHOLD_TYPE, 'value':self.ps.THRESHOLD_TYPE["Rising"], 'action':self.updateCurrentSettings},
github newaetech / chipwhisperer / software / chipwhisperer / common / utils / tracesource.py View on Github external
#    GNU Lesser General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with chipwhisperer.  If not, see .
#=================================================

from chipwhisperer.common.utils import util
from chipwhisperer.common.utils.parameter import Parameterized, setupSetParam


class TraceSource(object):
    """
    It has traces as output
    Keeps a dictionary with all the registered objets and emits a signal when a new one is added
    """
    registeredObjects = util.DictType()
    registeredObjects["None"] = None
    sigRegisteredObjectsChanged = util.Signal()

    def __init__(self, name="Unknown"):
        self.sigTracesChanged = util.Signal()
        self.name = name
        self.register()

    def getTrace(self, n):
        return None

    def numPoints(self):
        return 0

    def numTraces(self):
        return 0
github newaetech / chipwhisperer / software / chipwhisperer / common / results / pgevstraceplot.py View on Github external
def calculatePGE(self):
        """Calculate the Partial Guessing Entropy (PGE)"""
        if not self._analysisSource:
            raise Warning("Attack not set/executed yet")

        stats = self._analysisSource.getStatistics()
        pge = stats.pge_total
        allpge = util.DictType()

        for i in pge:
            tnum = i['trace']
            if not tnum in allpge:
                allpge[tnum] = [{'pgesum':0, 'trials':0} for z in range(0,stats.numSubkeys)]

            allpge[tnum][i['subkey']]['pgesum'] += i['pge']
            allpge[tnum][i['subkey']]['trials'] += 1

        for (tnum, plist) in allpge.items():
            for j in plist:
                if j['trials'] > 0:
                    j['pge'] = float(j['pgesum']) / float(j['trials'])
                    # print "%d "%j['trials'],
                else:
                    j['pge'] = None
github newaetech / chipwhisperer / software / chipwhisperer / common / utils / parameters.py View on Github external
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Lesser General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with chipwhisperer.  If not, see .
#=================================================

from pyqtgraph.parametertree import ParameterTree
from chipwhisperer.common.utils import util
from chipwhisperer.common.utils.parameter import Parameter


class CWParameterTree(object):
    _helpWidget = None
    _allParameterTrees = util.DictType()
    sigParamTreeUpdated = util.Signal()

    def __init__(self, groupName="Default", parameterizedObjs=None):
        self.parameterLists = []
        self.extend(parameterizedObjs)
        self._allParameterTrees[groupName] = self

    def getPyQtGraphParamTree(self):
        if not hasattr(self, "PyQtGraphParamTree"):
            self.PyQtGraphParamTree = ParameterTree()
        return self.PyQtGraphParamTree

    def replace(self, parameterLists):
        self.parameterLists = []
        self.extend(parameterLists)
        self.reloadParams()
github newaetech / chipwhisperer / software / chipwhisperer / capture / scopes / openadc_interface / naeusbchip.py View on Github external
def con(self, sn=None):
        if self.ser is None:
            self.dev = CWL.CWLiteUSB()

            try:
                nae_products = [0xACE2, 0xACE3]
                possible_sn = self.dev.get_possible_devices(nae_products)
                serial_numbers = []
                if len(possible_sn) > 1:
                    #Update list...
                    if sn is None:
                        snlist = DictType({'Select Device to Connect':None})
                        for d in possible_sn:
                            snlist[str(d['sn']) + " (" + str(d['product']) + ")"] = d['sn']
                            serial_numbers.append("sn = {} ({})".format(str(d['sn']), str(d['product'])))
                            pass
                        raise Warning("Multiple ChipWhisperers detected. Please specify device from the following list using cw.scope(sn=): \n{}".format(serial_numbers))
                else:
                    pass
                    #if possible_sn[0]['sn'] !=
                    #sn = None
                found_id = self.dev.con(idProduct=nae_products, serial_number=sn)
            except (IOError, ValueError):
                raise Warning('Could not connect to "%s". It may have been disconnected, is in an error state, or is being used by another tool.' % self.getName())

            if found_id != self.last_id:
                logging.info("Detected ChipWhisperer with USB ID %x - switching firmware loader" % found_id)
            self.last_id = found_id
github newaetech / chipwhisperer / software / chipwhisperer / common / utils / tracesource.py View on Github external
#    GNU Lesser General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with chipwhisperer.  If not, see .
#=================================================
import logging
import uuid
from chipwhisperer.common.utils import util
from chipwhisperer.common.utils.parameter import Parameterized, setupSetParam

class TraceSource(object):
    """
    It has traces as output
    Keeps a dictionary with all the registered objets and emits a signal when a new one is added
    """
    registeredObjects = util.DictType()
    registeredObjects["None"] = None
    sigRegisteredObjectsChanged = util.Signal()

    def __init__(self, name="Unknown"):
        self.sigTracesChanged = util.Signal()
        self.name = name
        self.uuid = str(uuid.uuid4())

    def getTrace(self, n):
        """Return the trace with number n in the current TraceSource object"""
        return None

    def numPoints(self):
        return 0

    def numTraces(self):
github newaetech / chipwhisperer / software / chipwhisperer / analyzer / attacks / models / base.py View on Github external
5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3,
       3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2,
       3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
       4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5,
       6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5,
       5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6,
       7, 7, 8]

def getHW(byte):
    return _HW[byte]


class ModelsBase(Parameterized):
    _name = 'Crypto Model'

    hwModels = util.DictType()
    hwModels_toStr = []

    ##Generate this table with:
    #HW = []
    #for n in range(0, 256):
    #    HW = HW + [bin(n).count("1")]
    HW = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3,
          4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4,
          4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2,
          3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5,
          4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4,
          5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3,
          3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2,
          3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
          4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5,
          6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5,
github newaetech / chipwhisperer / software / chipwhisperer / capture / targets / SAKURAG.py View on Github external
def __init__(self):
        TargetTemplate.__init__(self)
        self.hw = None

        conntypes = util.DictType()
        conntypes['Select Interface type...'] = None
        conntypes['CW Bitstream, with OpenADC'] = ChipWhispererComm(standalone=False)
        conntypes['CW Bitstream, no OpenADC'] = ChipWhispererComm(standalone=True)
        conntypes['Original Bitstream'] = FTDIComm()

        self.fixedStart = True
        self.hw = None
        self.getParams().addChildren([
            {'name':'Connection via:', 'key':'conn', 'type':'list', 'values':conntypes, 'set':self.setConn, 'get':self.getConn, 'default':None},
            {'name':'Reset FPGA', 'key':'reset', 'type':'action', 'action': self.reset, 'visible':False},
            {'name':'USB Serial #:', 'key':'serno', 'type':'list', 'values':['Press Refresh'], 'value':'Press Refresh', 'visible':False},
            {'name':'Enumerate Attached Devices', 'key':'pushsno', 'type':'action', 'action': self.refreshSerial, 'visible':False},
        ])