问题描述
我正在尝试在我的 FPGA 板上使用 Chipwhisperer 提供的 TVLA 评估。 (repo tagged as 5.1.3 的克隆)他们为此提供了 PA_TVLA_1-Performing_TVLA_Testing_for_Crypto_Validation.ipynb
Jupyterplaybook。我对其进行了修改以初始化 FPGA,但流程的其余部分是相同的,即捕获轨迹并分析它们。
import holoviews as hv
hv.extension('bokeh')
import numpy as np
import scipy
import scipy.stats
project = cw.open_project('projects/MyProject.cwp')
fixedpy = [0xda,0x39,0xa3,0xee,0x5e,0x6b,0x4b,0x0d,0x32,0x55,0xbf,0xef,0x95,0x60,0x18,0x90]
testouts = []
num_traces = len(project.traces)
num_points = len(project.waves[0])
print(num_traces,num_points)
curve = hv.Curve([])
def do_the_ttvla(project,ntraces=-1):
global curve,line
if ntraces == -1:
ntraces = int(num_traces / 2)
if ntraces * 2 > num_traces:
raise ValueError("Invalid ntraces")
for g in range(0,2):
group = [(list(project.textins[i]) == fixedpy) for i in range(g*ntraces,g*ntraces+ntraces)]
trace = np.zeros((ntraces,num_points))
for n in range(g*ntraces,g*ntraces+ntraces):
trace[n - g*ntraces][:] = project.waves[n]
testout = welch_ttest(group,trace)
curve *= hv.Curve(testout)
testouts.extend(testout)
curve *= hv.Path([(0,-4.5),(num_points,-4.5)]).opts(color="black") * \
hv.Path([(0,4.5),4.5)]).opts(color="black")
def welch_ttest(group,traces):
import warnings
# Compute Welch's t-statistic at each point in time
# Here,group[] must only contain booleans (True/False)
traces_true = traces[np.where(np.array(group))]
traces_false = traces[np.where(~np.array(group))]
if len(traces_true) == 0:
traces_true = np.array([[np.nan for _ in range(len(traces[0]))]])
if len(traces_false) == 0:
traces_false = np.array([[np.nan for _ in range(len(traces[0]))]])
with warnings.catch_warnings():
warnings.simplefilter("ignore")
ttrace = scipy.stats.ttest_ind(traces_true,traces_false,axis=0,equal_var=False)[0]
return np.nan_to_num(ttrace)
do_the_ttvla(project)
(curve).opts(height=600,width=600)
WARNING:param.bokehRenderer: Use method 'params' via param namespace
WARNING:param.bokehRenderer:Use method 'params' via param namespace
---------------------------------------------------------------------------
RecursionError Traceback (most recent call last)
<ipython-input-14-8f71252adeef> in <module>
53 return np.nan_to_num(ttrace)
54
---> 55 do_the_ttvla(project)
56 (curve).opts(height=600,width=600)
<ipython-input-14-8f71252adeef> in do_the_ttvla(project,ntraces)
29
30 testout = welch_ttest(group,trace)
---> 31 curve *= hv.Curve(testout)
32 testouts.extend(testout)
33
~/.local/lib/python3.7/site-packages/holoviews/core/overlay.py in __mul__(self,other)
41 return NotImplemented
42
---> 43 return Overlay([self,other])
44
45
~/.local/lib/python3.7/site-packages/holoviews/core/overlay.py in __init__(self,items,group,label,**params)
141 self.__dict__['_group'] = group
142 self.__dict__['_label'] = label
--> 143 super(Overlay,self).__init__(items,**params)
144
145 def __getitem__(self,key):
~/.local/lib/python3.7/site-packages/holoviews/core/dimension.py in __init__(self,identifier,parent,**kwargs)
1327 if items and all(isinstance(item,Dimensioned) for item in items):
1328 items = self._process_items(items)
-> 1329 params = {p: kwargs.pop(p) for p in list(self.params().keys())+['id','plot_id'] if p in kwargs}
1330
1331 AttrTree.__init__(self,**kwargs)
~/.local/lib/python3.7/site-packages/param/parameterized.py in inner(*args,**kwargs)
1328 get_logger(name=args[0].__class__.__name__).log(
1329 WARNING,'Use method %r via param namespace ' % fn.__name__)
-> 1330 return fn(*args,**kwargs)
1331
1332 inner.__doc__= "Inspect .param.%s method for the full docstring" % fn.__name__
~/.local/lib/python3.7/site-packages/param/parameterized.py in params(cls,parameter_name)
2765 @Parameters.deprecate
2766 def params(cls,parameter_name=None):
-> 2767 return cls.param.params(parameter_name=parameter_name)
2768
2769 @classmethod
~/.local/lib/python3.7/site-packages/param/parameterized.py in params(self_,parameter_name)
1422 superclasses.
1423 """
-> 1424 pdict = self_.objects(instance='existing')
1425 if parameter_name is None:
1426 return pdict
~/.local/lib/python3.7/site-packages/param/parameterized.py in objects(self_,instance)
1511 if instance and self_.self is not None:
1512 if instance == 'existing':
-> 1513 if getattr(self_.self,'initialized',False) and self_.self._instance__params:
1514 return dict(pdict,**self_.self._instance__params)
1515 return pdict
~/.local/lib/python3.7/site-packages/holoviews/core/tree.py in __getattr__(self,identifier)
254 sanitized = identifier
255
--> 256 if sanitized in self.children:
257 return self.__dict__[sanitized]
258
... last 1 frames repeated,from the frame below ...
~/.local/lib/python3.7/site-packages/holoviews/core/tree.py in __getattr__(self,identifier)
254 sanitized = identifier
255
--> 256 if sanitized in self.children:
257 return self.__dict__[sanitized]
258
RecursionError: maximum recursion depth exceeded in comparison
我真的不明白出了什么问题,它似乎是某种参数传递,但它在库本身中,所以我期待有什么改变?
更新:
project.traces
的内容:
[[memmap([ 0.015625,-0.00585938,-0.00097656,0.00878906,0.015625,-0.12402344,-0.11132812,-0.05664062,-0.09863281,-0.06640625,-0.00976562,0.03613281,-0.08007812,-0.06542969,-0.01660156,0.02050781,-0.10351562,-0.08105469,-0.02734375,0.02246094,-0.09765625,-0.07324219,-0.01855469,0.02832031,-0.09082031,-0.06933594,-0.01757812,-0.08789062,-0.015625,-0.09179688,0.02734375,0.02929688,-0.09667969,0.03222656,-0.0859375,-0.05566406,-0.01171875,0.03417969,-0.10058594,-0.07421875,-0.02246094,0.02636719,0.03125,0.04882812,0.05078125,0.04980469,0.,-0.00488281,-0.00195312,0.01269531,-0.00878906,0.00097656,0.01464844,0.03027344,0.00390625,0.00683594,0.02539062,-0.01074219,-0.00683594,0.0078125,0.02441406,-0.00390625,0.02148438,0.00292969,-0.0078125,-0.00292969,0.00976562,0.01171875,0.01660156,0.00488281,0.01074219,0.00195312,-0.01269531,0.02148438])
array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144],dtype=uint8)
array([141,157,188,136,137,251,6,244,97,105,144,241,195,197],dtype=uint8)
array([ 1,35,69,103,171,205,18,52,86,120,154,222,240],dtype=uint8) ]
[memmap([ 0.015625,-0.1015625,-0.04492188,-0.09570312,-0.06347656,-0.07910156,-0.03125,0.01855469,-0.09960938,-0.02441406,-0.06835938,0.0234375,-0.10546875,-0.08300781,-0.09277344,-0.06738281,-0.08984375,-0.02148438,-0.09375,-0.07128906,-0.02050781,-0.07519531,-0.08691406,-0.05957031,0.04199219,0.04589844,0.01367188,0.00585938,-0.01367188,-0.01464844,0.01953125,0.01953125])
array([0,0],dtype=uint8)
array([ 66,199,111,134,28,147,211,45,55,54,186,92,200,179,128],dtype=uint8) ]
[memmap([ 0.02050781,-0.12109375,-0.10253906,-0.04589844,-0.09472656,0.04003906,-0.07714844,-0.0625,-0.05175781,0.03808594,-0.08886719,0.03515625,-0.04394531,0.03710938,-0.07617188,0.0546875,0.05859375,0.05371094,0.01757812,0.02441406])
array([ 66,dtype=uint8)
array([ 81,246,159,240,82,114,237,178,37,123,8,165,187],dtype=uint8) ]
[memmap([ 0.01074219,-0.12988281,-0.11621094,-0.05761719,-0.11035156,-0.02832031,-0.10742188,-0.0703125,-0.08398438,-0.06054688,0.01855469])
array([218,dtype=uint8) ]
[memmap([ 0.0234375,-0.04199219,-0.05859375,0.03320312,-0.07226562,0.0390625,0.05273438,0.05957031,0.02539062])
array([218,-0.0234375,-0.05273438,0.04785156,0.02246094])
array([ 81,dtype=uint8)
array([252,90,176,228,231,213,184,124,217,87,234,192,166],dtype=uint8) ]
[memmap([ 0.01855469,-0.11425781,-0.04980469,-0.01953125,-0.078125,-0.05371094,0.05175781,dtype=uint8) ]]
Result truncated
project.waves[0]
的内容,其中 wave 是 <chipwhisperer.common.api.ProjectFormat.IndividualIterable object at 0x7fe48203b350>
[ 0.015625 -0.00585938 -0.00097656 0.00878906 0.015625 -0.12402344
-0.11132812 -0.05664062 -0.00097656 -0.09863281 -0.06640625 -0.00976562
0.03613281 -0.08007812 -0.06542969 -0.01660156 0.02050781 -0.10351562
-0.08105469 -0.02734375 0.02246094 -0.09765625 -0.07324219 -0.01855469
0.02832031 -0.09082031 -0.06933594 -0.01757812 0.02832031 -0.08789062
-0.06542969 -0.015625 0.02832031 -0.09179688 -0.06933594 -0.01855469
0.02734375 -0.09765625 -0.06933594 -0.01855469 0.02929688 -0.09667969
-0.06933594 -0.01660156 0.03222656 -0.0859375 -0.05566406 -0.01171875
0.03417969 -0.10058594 -0.07421875 -0.02246094 0.02636719 0.03125
0.04882812 0.05078125 0.04980469 0. -0.00488281 -0.00195312
0.01269531 -0.00878906 0.00097656 0.01464844 0.03027344 0.00390625
0.00683594 0.015625 0.02539062 -0.01074219 -0.00683594 0.0078125
0.02246094 -0.00585938 0. 0.01269531 0.02441406 -0.00390625
-0.00195312 0.01269531 0.02148438 -0.00195312 0.00292969 0.01464844
0.02441406 -0.0078125 -0.00292969 0.00976562 0.02050781 -0.00488281
-0.00195312 0.01171875 0.02148438 -0.00878906 -0.00488281 0.00683594
0.02246094 -0.00097656 0.00683594 0.01660156 0.02441406 -0.01171875
-0.00585938 0.00488281 0.02050781 -0.00878906 0. 0.01074219
0.02539062 -0.00390625 0.00195312 0.00976562 0.02246094 -0.0078125
-0.00097656 0.00878906 0.02050781 -0.00878906 -0.00390625 0.00683594
0.02148438 -0.00683594 0. 0.00976562 0.02246094 -0.01269531
-0.00488281 0.00683594 0.02148438]
project.textins[0]
的示例内容
[218 57 163 238 94 107 75 13 50 85 191 239 149 96 24 144]
cw
对象作为 import chipwhisperer as cw
导入并且是chipwhisperer 库的一部分。这里的作用是允许将已经捕获的trace加载到一组数组中。
解决方法
pip install --upgrade holoviews
修复了该问题。
对于面临错误的 VM 用户,这不会起作用:Jupyter 将在启动时崩溃。 我建议在 release 页面(发布标记为 5.5)下载“ChipWhisperer.Jupyter.holoviews.7z”虚拟机。