Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if TraceSource.registeredObjects.pop(self.name, None):
TraceSource.sigRegisteredObjectsChanged.emit()
except KeyError:
pass
@classmethod
def deregisterObject(cls, name, uuid = None):
"""Deregister the TraceSource and emit a signal to inform this event"""
try:
if (uuid is None) or (cls.registeredObjects[name].uuid == uuid):
if cls.registeredObjects.pop(name, None):
cls.sigRegisteredObjectsChanged.emit()
except KeyError:
pass
class PassiveTraceObserver(Parameterized):
"""Processes data from a TraceSource when requested """
def __init__(self):
self._traceSource = None
self.getParams().addChildren([
{'name':'Input', 'key':'input', 'type':'list', 'values':TraceSource.registeredObjects, 'default':None, 'get':self.getTraceSource, 'set':self.setTraceSource}
])
@setupSetParam('Input')
def set_trace_source(self, traceSource):
if self._traceSource:
self._traceSource.sigTracesChanged.disconnect(self.tracesUpdated)
if traceSource:
traceSource.sigTracesChanged.connect(self.tracesUpdated)
self._traceSource = traceSource
self.tracesUpdated()
else:
raise ValueError("modeltype invalid")
self.diff[key] += logpdf[tnum][hypint]
if progressBar:
progressBar.setValue(pbcnt)
progressBar.updateStatus((self.totalTraces - numtraces, self.totalTraces), bnum)
if progressBar.wasAborted():
break
pbcnt = pbcnt + 1
return (self.diff, pbcnt)
class CPAExperimentalChannelinfo(Parameterized, Plugin):
_name = "CPA Experimental Channel Info"
def __init__(self, targetModel, leakageFunction):
self.getParams().addChildren([
{'name':'Reporting Interval', 'key':'reportinterval', 'type':'int', 'value':100},
{'name':'Iteration Mode', 'key':'itmode', 'type':'list', 'values':{'Depth-First':'df', 'Breadth-First':'bf'}, 'value':'bf'},
{'name':'Skip when PGE=0', 'key':'checkpge', 'type':'bool', 'value':False},
])
self.model = targetModel
self.sr = None
self.stats = DataTypeDiffs()
def setByteList(self, brange):
self.brange = brange
#
# chipwhisperer is distributed in the hope that it will be useful,
# 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 .
#=================================================
import logging
from chipwhisperer.common.utils.pluginmanager import Plugin
from chipwhisperer.common.utils.parameter import Parameterized, Parameter
class AuxiliaryTemplate(Parameterized, Plugin):
_name = "None"
def __init__(self):
self.getParams()
self.prefix = ""
if __debug__: logging.debug('Created: ' + str(self))
def __del__(self):
"""Close system if needed"""
self.close()
if __debug__: logging.debug('Deleted: ' + str(self))
def close(self):
"""Close target, disconnect if required"""
pass
from ..base import ScopeTemplate
from chipwhisperer.common.utils import util, timer
from chipwhisperer.common.utils.parameter import setupSetParam, Parameterized
from chipwhisperer.common.utils.pluginmanager import Plugin
"""
This module has an interface to the PicoTech PicoScope device. It uses the
picoscope library at https://github.com/colinoflynn/pico-python which you
must install
"""
from picoscope import ps2000
from picoscope import ps5000a
from picoscope import ps6000
class PicoScopeBase(Parameterized):
_name = 'Pico Scope'
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']
STATUS_EXT_MASK = 0x04
STATUS_DCM_MASK = 0x08
STATUS_DDRCAL_MASK = 0x10
STATUS_DDRERR_MASK = 0x20
STATUS_DDRMODE_MASK= 0x40
STATUS_OVERFLOW_MASK = 0x80
# sign extend b low bits in x
# from "Bit Twiddling Hacks"
def SIGNEXT(x, b):
m = 1 << (b - 1)
x = x & ((1 << b) - 1)
return (x ^ m) - m
class HWInformation(Parameterized):
_name = 'HW Information'
def __init__(self, oaiface):
self.oa = oaiface
self.oa.hwInfo = self
self.sysFreq = 0
self.params = Parameter(name=self.getName(), type='group')
self.params.addChildren([
{'name': 'Version', 'type': 'str', 'get':self.versions, 'readonly':True},
{'name': 'Synth Date', 'type': 'str', 'get':self.synthDate, 'readonly':True},
{'name': 'System Freq', 'type': 'int', 'siPrefix':True, 'suffix': 'Hz', 'get':self.sysFrequency, 'readonly':True},
{'name': 'Max Samples', 'type': 'int', 'get':self.maxSamples, 'readonly':True}
])
self.vers = None
# (at your option) any later version.
#
# chipwhisperer is distributed in the hope that it will be useful,
# 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 ._stats import Results
from chipwhisperer.common.utils.parameter import Parameterized
class AlgorithmsBase(Parameterized):
def __init__(self):
self.sr = None
self.stats = None
self._project = None
def setProject(self, proj):
self._project = proj
def project(self):
return self._project
def tracesUpdated(self, traceSource):
pass
def updateScript(self, ignored=None):
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,
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,
mode = "falling edge"
elif case == SETTINGS_TRIG_HIGH | SETTINGS_WAIT_NO:
mode = "high"
else:
mode = "low"
return mode
def extTriggerPin(self):
if (self.oa is not None) and (self.oa.getStatus() & STATUS_EXT_MASK):
return True
else:
return False
class ClockSettings(Parameterized):
_name = 'Clock Setup'
readMask = [0x1f, 0xff, 0xff, 0xfd]
def __init__(self, oaiface, hwinfo=None):
self.oa = oaiface
self._hwinfo = hwinfo
self.params = Parameter(name=self.getName(), type='group')
self.params.addChildren([
{'name':'Refresh Status', 'type':'action', 'linked':[('ADC Clock', 'DCM Locked'), ('ADC Clock', 'ADC Freq'), ('CLKGEN Settings', 'DCM Locked'), 'Freq Counter'],
'help':'%namehdr%' +
'Update if the Digital Clock Manager (DCM) are "locked" and their operating frequency.'},
{'name':'Reset DCMs', 'type':'action', 'action':self.resetDcms, 'linked':[('CLKGEN Settings', 'Multiply'), ('CLKGEN Settings', 'Divide')],
'help':'%namehdr%' +
'When the input frequency to the DCM blocks changes, it can cause them to become "unlocked". When they are "unlocked" they are NOT ' +
'generating a reliable output frequency. You must press the "Reset" button to cause them to re-lock. This is currently not automatically ' +
'done as during regular operation they shouldn\'t become unlocked.\n\nHowever every time you change the DCM block source, it will cause ' +
def gainDB(self):
#GAIN (dB) = 50 (dB/V) * VGAIN - 6.5 dB, (HILO = LO)
# GAIN (dB) = 50 (dB/V) * VGAIN + 5.5 dB, (HILO = HI)
gainV = (float(self.gain_cached) / 256.0) * 3.3
if self.gainlow_cached:
gaindb = 50.0 * gainV - 6.5
else:
gaindb = 50.0 * gainV + 5.5
return gaindb
class TriggerSettings(Parameterized):
_name = 'Trigger Setup'
def __init__(self, oaiface):
self.oa = oaiface
self.maxsamples = 0
self.presamples_desired = 0
self.presamples_actual = 0
self.presampleTempMargin = 24
self._timeout = 2
self._stream_mode = False
self.params = Parameter(name=self.getName(), type='group')
child_list = [
{'name': 'Refresh Status', 'type':'action', 'linked':['Trigger Pin State'], 'visible':False,
'help':'%namehdr%'+
'Refreshes the "Trigger Pin State" status.'},