Attacks classes¶
Scared provides the following ready to use attacks classes.
- class scared.analysis._analysis.CPAAttack(selection_function, model, discriminant, precision='float32', convergence_step=None)[source]¶
Correlation Power Analysis using Pearson coefficients mixin.
- ex¶
traces accumulator with shape (trace_size,)
- Type:
numpy.ndarray
- ex2¶
squared traces accumulator with shape (trace_size,)
- Type:
numpy.ndarray
- ey¶
intermediate data accumulator with shape (data_words,)
- Type:
numpy.ndarray
- ey2¶
squared intermediate data accumulator with shape (data_words,)
- Type:
numpy.ndarray
- exy¶
dot product (intermediate data, traces) accumulator with shape (data_words, trace_size)
- Type:
numpy.ndarray
Base class for all attack analysis processing objects.
This class must be subclassed and combined with a mixin inheriting from
DistinguisherMixin
. It provides the common processing method for a side-channel statistical analysis.- The base class:
initialize the state before processing any traces
provides method, either to process traces and compute results manually, either to run a complete processing of a
Container
instancemanage results attributes: distinguisher method output (results), scores and convergence_traces
- results¶
array containing the latest results obtained from the distinguisher computing.
- Type:
numpy.ndarray
- scores¶
array containing the latest scores obtained by processing results with discriminant.
- Type:
numpy.ndarray
- convergence_step¶
number of traces to process before each computation of results. If convergence_step is provided, all intermediate scores computed are kept in convergence_traces
- Type:
int, default=None
- convergences_traces¶
array containing the scores values at each convergence step defined by convergence_step.
- Type:
numpy.ndarray
Examples
First, you have to use either one the distinguisher mixin available, all create one which inherit from
DistinguisherMixin
:class MyDistinguisherMixin(DistinguisherMixin): # implements the needed method.
Create a new class by inheriting from :class:BaseAttack class and the distinguisher mixin:
- class MyAttack(BaseAttack, MyDistinguisherMixin):
pass
Create your analysis object and run it on a container:
analysis = MyAttack(…) analysis.run(container)
- class scared.analysis._analysis.DPAAttack(*args, **kwargs)[source]¶
Differential Power Analysis mixin.
- accumulator_traces¶
accumulator of all traces with shape (trace_size,)
- Type:
numpy.ndarray
- accumulator_ones¶
accumulator of traces corresponding to intermediate value 1, with shape (trace_size,)
- Type:
numpy.ndarray
- processed_ones¶
number of processed traces in accumulator_ones for each data word considered, with shape (data_words,)
- Type:
numpy.ndarray
Base class for all attack analysis processing objects.
This class must be subclassed and combined with a mixin inheriting from
DistinguisherMixin
. It provides the common processing method for a side-channel statistical analysis.- The base class:
initialize the state before processing any traces
provides method, either to process traces and compute results manually, either to run a complete processing of a
Container
instancemanage results attributes: distinguisher method output (results), scores and convergence_traces
- results¶
array containing the latest results obtained from the distinguisher computing.
- Type:
numpy.ndarray
- scores¶
array containing the latest scores obtained by processing results with discriminant.
- Type:
numpy.ndarray
- convergence_step¶
number of traces to process before each computation of results. If convergence_step is provided, all intermediate scores computed are kept in convergence_traces
- Type:
int, default=None
- convergences_traces¶
array containing the scores values at each convergence step defined by convergence_step.
- Type:
numpy.ndarray
Examples
First, you have to use either one the distinguisher mixin available, all create one which inherit from
DistinguisherMixin
:class MyDistinguisherMixin(DistinguisherMixin): # implements the needed method.
Create a new class by inheriting from :class:BaseAttack class and the distinguisher mixin:
- class MyAttack(BaseAttack, MyDistinguisherMixin):
pass
Create your analysis object and run it on a container:
analysis = MyAttack(…) analysis.run(container)
- __init__(*args, **kwargs)[source]¶
Initialize attack.
- Parameters:
selection_function (
SelectionFunction
) – selection function to compute intermediate values. Must inherit fromSelectionFunction
.model (
Model
) – model instance to compute leakage intermediate values. Must inherit fromModel
.discriminant (function) – a function to compute scores from a distinguisher results array. Must be decorated with
scared.discriminants.discriminant()
.precision (
numpy.dtype
, default=`float32`) – precision which will be used for computations.convergence_step (int, default=None) – if provided, run method will compute and stores scores each time convergence_step traces are processed.
- class scared.analysis._analysis.ANOVAAttack(partitions=None, *args, **kwargs)[source]¶
This standalone partitioned distinguisher applies the ANOVA F-test metric.Base class for all attack analysis processing objects.
This class must be subclassed and combined with a mixin inheriting from
DistinguisherMixin
. It provides the common processing method for a side-channel statistical analysis.- The base class:
initialize the state before processing any traces
provides method, either to process traces and compute results manually, either to run a complete processing of a
Container
instancemanage results attributes: distinguisher method output (results), scores and convergence_traces
- results¶
array containing the latest results obtained from the distinguisher computing.
- Type:
numpy.ndarray
- scores¶
array containing the latest scores obtained by processing results with discriminant.
- Type:
numpy.ndarray
- convergence_step¶
number of traces to process before each computation of results. If convergence_step is provided, all intermediate scores computed are kept in convergence_traces
- Type:
int, default=None
- convergences_traces¶
array containing the scores values at each convergence step defined by convergence_step.
- Type:
numpy.ndarray
Examples
First, you have to use either one the distinguisher mixin available, all create one which inherit from
DistinguisherMixin
:class MyDistinguisherMixin(DistinguisherMixin): # implements the needed method.
Create a new class by inheriting from :class:BaseAttack class and the distinguisher mixin:
- class MyAttack(BaseAttack, MyDistinguisherMixin):
pass
Create your analysis object and run it on a container:
analysis = MyAttack(…) analysis.run(container)
- class scared.analysis._analysis.NICVAttack(partitions=None, *args, **kwargs)[source]¶
This standalone partitioned distinguisher applies the NICV (Normalized Inter-Class Variance) metric.Base class for all attack analysis processing objects.
This class must be subclassed and combined with a mixin inheriting from
DistinguisherMixin
. It provides the common processing method for a side-channel statistical analysis.- The base class:
initialize the state before processing any traces
provides method, either to process traces and compute results manually, either to run a complete processing of a
Container
instancemanage results attributes: distinguisher method output (results), scores and convergence_traces
- results¶
array containing the latest results obtained from the distinguisher computing.
- Type:
numpy.ndarray
- scores¶
array containing the latest scores obtained by processing results with discriminant.
- Type:
numpy.ndarray
- convergence_step¶
number of traces to process before each computation of results. If convergence_step is provided, all intermediate scores computed are kept in convergence_traces
- Type:
int, default=None
- convergences_traces¶
array containing the scores values at each convergence step defined by convergence_step.
- Type:
numpy.ndarray
Examples
First, you have to use either one the distinguisher mixin available, all create one which inherit from
DistinguisherMixin
:class MyDistinguisherMixin(DistinguisherMixin): # implements the needed method.
Create a new class by inheriting from :class:BaseAttack class and the distinguisher mixin:
- class MyAttack(BaseAttack, MyDistinguisherMixin):
pass
Create your analysis object and run it on a container:
analysis = MyAttack(…) analysis.run(container)
- class scared.analysis._analysis.SNRAttack(partitions=None, *args, **kwargs)[source]¶
This standalone partitioned distinguisher applies the SNR (Signal to Noise Ratio) metric.Base class for all attack analysis processing objects.
This class must be subclassed and combined with a mixin inheriting from
DistinguisherMixin
. It provides the common processing method for a side-channel statistical analysis.- The base class:
initialize the state before processing any traces
provides method, either to process traces and compute results manually, either to run a complete processing of a
Container
instancemanage results attributes: distinguisher method output (results), scores and convergence_traces
- results¶
array containing the latest results obtained from the distinguisher computing.
- Type:
numpy.ndarray
- scores¶
array containing the latest scores obtained by processing results with discriminant.
- Type:
numpy.ndarray
- convergence_step¶
number of traces to process before each computation of results. If convergence_step is provided, all intermediate scores computed are kept in convergence_traces
- Type:
int, default=None
- convergences_traces¶
array containing the scores values at each convergence step defined by convergence_step.
- Type:
numpy.ndarray
Examples
First, you have to use either one the distinguisher mixin available, all create one which inherit from
DistinguisherMixin
:class MyDistinguisherMixin(DistinguisherMixin): # implements the needed method.
Create a new class by inheriting from :class:BaseAttack class and the distinguisher mixin:
- class MyAttack(BaseAttack, MyDistinguisherMixin):
pass
Create your analysis object and run it on a container:
analysis = MyAttack(…) analysis.run(container)
- class scared.analysis._analysis.MIAAttack(bins_number=128, bin_edges=None, *args, **kwargs)[source]¶
This partitioned distinguisher mixin applies a mutual information computation.Base class for all attack analysis processing objects.
This class must be subclassed and combined with a mixin inheriting from
DistinguisherMixin
. It provides the common processing method for a side-channel statistical analysis.- The base class:
initialize the state before processing any traces
provides method, either to process traces and compute results manually, either to run a complete processing of a
Container
instancemanage results attributes: distinguisher method output (results), scores and convergence_traces
- results¶
array containing the latest results obtained from the distinguisher computing.
- Type:
numpy.ndarray
- scores¶
array containing the latest scores obtained by processing results with discriminant.
- Type:
numpy.ndarray
- convergence_step¶
number of traces to process before each computation of results. If convergence_step is provided, all intermediate scores computed are kept in convergence_traces
- Type:
int, default=None
- convergences_traces¶
array containing the scores values at each convergence step defined by convergence_step.
- Type:
numpy.ndarray
Examples
First, you have to use either one the distinguisher mixin available, all create one which inherit from
DistinguisherMixin
:class MyDistinguisherMixin(DistinguisherMixin): # implements the needed method.
Create a new class by inheriting from :class:BaseAttack class and the distinguisher mixin:
- class MyAttack(BaseAttack, MyDistinguisherMixin):
pass
Create your analysis object and run it on a container:
analysis = MyAttack(…) analysis.run(container)
- __init__(bins_number=128, bin_edges=None, *args, **kwargs)[source]¶
Initialize attack.
- Parameters:
selection_function (
SelectionFunction
) – selection function to compute intermediate values. Must inherit fromSelectionFunction
.model (
Model
) – model instance to compute leakage intermediate values. Must inherit fromModel
.discriminant (function) – a function to compute scores from a distinguisher results array. Must be decorated with
scared.discriminants.discriminant()
.precision (
numpy.dtype
, default=`float32`) – precision which will be used for computations.convergence_step (int, default=None) – if provided, run method will compute and stores scores each time convergence_step traces are processed.
- class scared.analysis.template.BaseTemplateAttack(container_building, selection_function, reverse_selection_function, model, convergence_step=None, partitions=None, precision='float32')[source]¶
- __init__(container_building, selection_function, reverse_selection_function, model, convergence_step=None, partitions=None, precision='float32')[source]¶
Initialize template attack.
- Parameters:
reverse_selection_function (
SelectionFunction
) – selection function to compute intermediate values for build phase.selection_function (
SelectionFunction
) – attack selection function to compute intermediate values for matching phase.model (
Model
) – model instance to compute leakage intermediate values. Must inherit fromModel
.precision (
numpy.dtype
, default=`float32`) – precision which will be used for computations.convergence_step (int, default=None) – if provided, run method will compute and stores scores each time convergence_step traces are processed.
partitions (range, default=None) – partitions to use for the build phase. If unset, partitions will be determined by the model values.
- class scared.analysis.template.TemplateAttack(container_building, reverse_selection_function, model, convergence_step=None, partitions=None, precision='float32', selection_function=None)[source]¶
Provides a high-level class to proceed to static template attacks.
This class is first for the profiling phase. Once build, matching phase can be run on trace header sets container.
- templates¶
templates array, available once analysis build phase is run.
- Type:
numpy.ndarray
- scores¶
scores resulting from the latest matching phase run on a trace header set.
- Type:
numpy.ndarray
- convergence_step¶
number of traces to process before each computation of results. If convergence_step is provided, all intermediate scores computed are kept in convergence_traces
- Type:
int, default=None
- convergences_traces¶
array containing the scores values at each convergence step defined by convergence_step.
- Type:
numpy.ndarray
Examples
Instantiate by passing a container with building trace header set, a reverse selection function and a model:
>>> template = scared.TemplateAttack( >>> container_building=container, >>> reverse_selection_function=sf, >>> model=scared.Value() >>> )
Use build to build templates:
>>> template.build()
Use run with a trace header set container to process matching:
>>> template.run(container)
- __init__(container_building, reverse_selection_function, model, convergence_step=None, partitions=None, precision='float32', selection_function=None)[source]¶
Initialize template attack.
- Parameters:
reverse_selection_function (
SelectionFunction
) – selection function to compute intermediate values for build phase.selection_function (
SelectionFunction
) – attack selection function to compute intermediate values for matching phase.model (
Model
) – model instance to compute leakage intermediate values. Must inherit fromModel
.precision (
numpy.dtype
, default=`float32`) – precision which will be used for computations.convergence_step (int, default=None) – if provided, run method will compute and stores scores each time convergence_step traces are processed.
partitions (range, default=None) – partitions to use for the build phase. If unset, partitions will be determined by the model values.
- class scared.analysis.template.TemplateDPAAttack(*args, **kwargs)[source]¶
Provides a high-level class to proceed to DPA template attacks.
This class is first for the profiling phase. Once build, matching phase can be run on trace header sets container.
- templates¶
templates array, available once analysis build phase is run.
- Type:
numpy.ndarray
- scores¶
scores resulting from the latest matching phase run on a trace header set.
- Type:
numpy.ndarray
- convergence_step¶
number of traces to process before each computation of results. If convergence_step is provided, all intermediate scores computed are kept in convergence_traces
- Type:
int, default=None
- convergences_traces¶
array containing the scores values at each convergence step defined by convergence_step.
- Type:
numpy.ndarray
Examples
Instantiate by passing a container with building trace header set, a reverse selection function, an attack selection function and a model:
>>> template = scared.TemplateAttack( >>> container_building=container, >>> selection_function=asf, >>> reverse_selection_function=sf, >>> model=scared.Value(), >>> )
Use build to build templates:
>>> template.build()
Use run with a trace header set container to process matching:
>>> template.run(container)
- __init__(*args, **kwargs)[source]¶
Initialize template attack.
- Parameters:
reverse_selection_function (
SelectionFunction
) – selection function to compute intermediate values for build phase.selection_function (
SelectionFunction
) – attack selection function to compute intermediate values for matching phase.model (
Model
) – model instance to compute leakage intermediate values. Must inherit fromModel
.precision (
numpy.dtype
, default=`float32`) – precision which will be used for computations.convergence_step (int, default=None) – if provided, run method will compute and stores scores each time convergence_step traces are processed.
partitions (range, default=None) – partitions to use for the build phase. If unset, partitions will be determined by the model values.