-
Notifications
You must be signed in to change notification settings - Fork 276
/
profiling.py
54 lines (48 loc) · 2.39 KB
/
profiling.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014, NewAE Technology Inc
# All rights reserved.
#
# Authors: Colin O'Flynn
#
# Find this and more at newae.com - this file is part of the chipwhisperer
# project, http://www.assembla.com/spaces/chipwhisperer
#
# This file is part of chipwhisperer.
#
# chipwhisperer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (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 <http://www.gnu.org/licenses/>.
#
# ChipWhisperer is a trademark of NewAE Technology Inc.
#===========================================================
import sys
from chipwhisperer.common.utils import pluginmanager
from ._base import AttackBaseClass
class Profiling(AttackBaseClass):
"""Profiling Power Analysis Attack"""
_name = "Profiling"
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
def updateScript(self, _=None):
AttackBaseClass.updateScript(self)
self.importsAppend("from chipwhisperer.analyzer.attacks.profiling import Profiling")
analysAlgoStr = sys.modules[self._analysisAlgorithm.__class__.__module__].__name__ + '.' + self._analysisAlgorithm.__class__.__name__
model_path = sys.modules[self.findParam('Crypto Algorithm').getValue().__class__.__module__].__name__
cryptoalg = model_path + '.' + self.findParam('Crypto Algorithm').getValue().__class__.__name__
hwmodel = model_path + '.' + self.findParam('Crypto Algorithm').getValue().getHwModel().__name__
self.addVariable("init", "leakage_object", "%s(%s)" % (cryptoalg, hwmodel))
self.addFunction("init", "setAnalysisAlgorithm", "%s,leakage_object" % (analysAlgoStr), loc=1)