Loading scared/analysis.py +9 −0 Original line number Diff line number Diff line Loading @@ -221,6 +221,15 @@ class BaseAttack(_BaseAnalysis): self.scores = self.discriminant(self.results) logger.info(f'Scores computed.') def __str__(self): template_str = f'''Analysis informations: {self.selection_function} Distinguisher : {self._distinguisher_str} Model : {self.model} Discriminant : {self.discriminant.__name__} ''' return template_str class BaseReverse(_BaseAnalysis): """Base class for all reverse analysis processing objects. Loading scared/container.py +20 −0 Original line number Diff line number Diff line from scared import traces import numpy as _np class Container: Loading Loading @@ -100,6 +101,25 @@ class Container: preprocesses=self.preprocesses ) @property def _frame_str(self): if isinstance(self.frame, _np.ndarray): return f'{str(self.frame)[:20]} ... {str(self.frame)[-20:]}'.replace('\n', '') elif self.frame == ...: return 'All' else: return str(self.frame) def __str__(self): template_str = f'''Traces container: Number of traces: {len(self._ths)} Traces size : {self._ths.samples.shape[1]} Metadata : {list(self._ths.metadatas.keys())} Frame : {self._frame_str} Preprocesses : {[p.__name__ for p in self.preprocesses] if len(self.preprocesses) > 0 else 'None'} ''' return template_str class _TracesBatchWrapper: Loading scared/distinguishers/base.py +5 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,11 @@ class DistinguisherMixin(abc.ABC): def _memory_usage_coefficient(self, trace_size): return 2 * trace_size @property @abc.abstractmethod def _distinguisher_str(self): pass def _set_precision(obj, precision): try: Loading scared/distinguishers/cpa.py +4 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,10 @@ class CPADistinguisherMixin(DistinguisherMixin): result[d] = tmp_result.astype(self.precision) return result @property def _distinguisher_str(self): return 'CPA' class CPAAlternativeDistinguisherMixin(CPADistinguisherMixin): """Correlation Power Analysis using Pearson coefficients mixin. Loading scared/distinguishers/dpa.py +4 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,10 @@ class DPADistinguisherMixin(DistinguisherMixin): normalized_zeros = (accumulator_zeros.swapaxes(0, 1) / processed_zeros).swapaxes(0, 1) return (normalized_ones - normalized_zeros) @property def _distinguisher_str(self): return 'DPA' class DPADistinguisher(_StandaloneDistinguisher, DPADistinguisherMixin): """Standalone distinguisher class using DPA.""" Loading
scared/analysis.py +9 −0 Original line number Diff line number Diff line Loading @@ -221,6 +221,15 @@ class BaseAttack(_BaseAnalysis): self.scores = self.discriminant(self.results) logger.info(f'Scores computed.') def __str__(self): template_str = f'''Analysis informations: {self.selection_function} Distinguisher : {self._distinguisher_str} Model : {self.model} Discriminant : {self.discriminant.__name__} ''' return template_str class BaseReverse(_BaseAnalysis): """Base class for all reverse analysis processing objects. Loading
scared/container.py +20 −0 Original line number Diff line number Diff line from scared import traces import numpy as _np class Container: Loading Loading @@ -100,6 +101,25 @@ class Container: preprocesses=self.preprocesses ) @property def _frame_str(self): if isinstance(self.frame, _np.ndarray): return f'{str(self.frame)[:20]} ... {str(self.frame)[-20:]}'.replace('\n', '') elif self.frame == ...: return 'All' else: return str(self.frame) def __str__(self): template_str = f'''Traces container: Number of traces: {len(self._ths)} Traces size : {self._ths.samples.shape[1]} Metadata : {list(self._ths.metadatas.keys())} Frame : {self._frame_str} Preprocesses : {[p.__name__ for p in self.preprocesses] if len(self.preprocesses) > 0 else 'None'} ''' return template_str class _TracesBatchWrapper: Loading
scared/distinguishers/base.py +5 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,11 @@ class DistinguisherMixin(abc.ABC): def _memory_usage_coefficient(self, trace_size): return 2 * trace_size @property @abc.abstractmethod def _distinguisher_str(self): pass def _set_precision(obj, precision): try: Loading
scared/distinguishers/cpa.py +4 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,10 @@ class CPADistinguisherMixin(DistinguisherMixin): result[d] = tmp_result.astype(self.precision) return result @property def _distinguisher_str(self): return 'CPA' class CPAAlternativeDistinguisherMixin(CPADistinguisherMixin): """Correlation Power Analysis using Pearson coefficients mixin. Loading
scared/distinguishers/dpa.py +4 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,10 @@ class DPADistinguisherMixin(DistinguisherMixin): normalized_zeros = (accumulator_zeros.swapaxes(0, 1) / processed_zeros).swapaxes(0, 1) return (normalized_ones - normalized_zeros) @property def _distinguisher_str(self): return 'DPA' class DPADistinguisher(_StandaloneDistinguisher, DPADistinguisherMixin): """Standalone distinguisher class using DPA."""