Tools¶
-
class
lascar.tools.aes.
Aes
[source]¶ Bases:
object
Aes class. Provide methods to perform Aes (128,192 256) (use staticaly)
Handle list of uint8 (instead of char/str)
- Example:
- input = [0]*16 key = [0] * 16 Aes.encrypt( input, key)
-
static
decrypt
(input, key)[source]¶ decrypt and keep all intermediate values
Parameters: - input –
- key_scheduled –
Returns:
-
static
decrypt_keep_iv
(input, key_scheduled)[source]¶ decrypt and keep all intermediate values
Parameters: - input –
- key_scheduled –
Returns:
-
static
encrypt_keep_iv
(input, key_scheduled)[source]¶ encrypt and keep all intermediate values :param input: :param key_scheduled: :return:
-
nr
= {176: 10}¶
This file is an alternative to the Aes class, where every function is JITable by numba. This allows for faster computations of attacks on intermediate values of the AES (eg. a MixColumns output). You can use it in any script instead of the Aes class, by importing it: import lascar.tools.numba_aes as Aes
-
lascar.tools.numba_aes.
decrypt_keep_iv
[source]¶ decrypt and keep all intermediate values
Parameters: - input –
- key_scheduled –
Returns:
-
lascar.tools.numba_aes.
encrypt_keep_iv
[source]¶ encrypt and keep all intermediate values :param input: :param key_scheduled: :return:
Classes for leakage models
-
class
lascar.tools.leakage_model.
BitLeakageModel
(bit)[source]¶ Bases:
lascar.tools.leakage_model.LeakageModel
BitLeakageModel returns the value of a specified bit.
-
class
lascar.tools.leakage_model.
HammingPrecomputedModel
(max=256)[source]¶ Bases:
lascar.tools.leakage_model.LeakageModel
Emulates the hamming weight leakage model by precomputing all the hamming weigths until a given values.
-
class
lascar.tools.leakage_model.
LeakageModel
[source]¶ Bases:
object
LeakageModel is an abstract class. A leakage model is a callable object. It can be defined by a simple function, or by a class (like LeakageModel) overloading
__call__()
-
lascar.tools.leakage_model.
hamming_weight
[source]¶ Compute the hamming weight of an integer
https://www.expobrain.net/2013/07/29/hamming-weights-python-implementation/
Parameters: value – the integer Returns: the hamming weight of the value
processing.py
-
class
lascar.tools.processing.
CenteredProductProcessing
(container, rois=None, order=2, batch_size=1000, filename=None)[source]¶ Bases:
lascar.tools.processing.Processing
CenteredProductProcessing is the processing used when performing High-Order Side-Channel Analysis.
It computes the centered product of “order” leakage samples (“order” being the order chosen by the user).
Let n be the order of the CenteredProductProcessing. n rois are used to indicate which leakage points will be recombinated together. If rois is not specified, all possible combinations for the container will be used.
-
class
lascar.tools.processing.
IcaProcessing
(container, number_of_components, random_state=0, post_section=None, filename=None)[source]¶ Bases:
lascar.tools.processing.Processing
IcaProcessing is the procesisng used when performing Independant Component Analysis on Side-Channel traces. (based on sklearn.decomposition.ICA)
-
class
lascar.tools.processing.
PcaProcessing
(container, number_of_components, random_state=0, post_section=None, filename=None)[source]¶ Bases:
lascar.tools.processing.Processing
PcaProcessing is the procesisng used when performing Principal Component Analysis on Side-Channel Traces. (based on sklearn.decomposition.PCA)
-
class
lascar.tools.processing.
Processing
(filename=None)[source]¶ Bases:
object
Processing is the Base class for implementing processing.
A Processing can be seen as an object whose role is to modify leakages (or values). It has to be callable, and offer some save/load mechanisms.
-
class
lascar.tools.processing.
ReshapeProcessing
(shape, filename=None)[source]¶ Bases:
lascar.tools.processing.Processing
ReshapeProcessing is a processing that will reshape leakages with given shape.
-
class
lascar.tools.processing.
StandardScalerProcessing
(container, filename=None)[source]¶ Bases:
lascar.tools.processing.Processing
StandardScalerProcessing is a processing that will Standardize leakages by removing the mean and scaling to unit variance
-
lascar.tools.signal_processing.
find_offsets_inside_rectangle
(trace, condition, width, ratio=1.0, separation=1)[source]¶ Finds offsets inside trace which fits a condition (boolean function), during a given width.
ratio is for ghost peaks correction
separation is used to bypass adjacent patterns
-
lascar.tools.signal_processing.
get_extrema_window
(data, threshold, window_len=None, comparator=<ufunc 'greater'>, plot=False)[source]¶ extract, from ‘data’, all the samples where there are local extrema with values > ‘threshold’. (the comparator can be set with np.greater, np.less,…) If ‘window_len’ is set, will only ouptut the maximum value within ‘[ extrema - window_len/2, extrema + window_len/2] ‘
-
lascar.tools.signal_processing.
running_max
(x, window=32)[source]¶ Returns max of consecutive windows of x, each max repeated window times
-
lascar.tools.signal_processing.
running_min
(x, window=32)[source]¶ Returns min of consecutive windows of x, each max repeated window times
-
lascar.tools.signal_processing.
smooth
(x, window_len=11, window='hanning')[source]¶ smooth the data using a window with requested size.
This method is based on the convolution of a scaled window with the signal. The signal is prepared by introducing reflected copies of the signal (with the window size) in both ends so that transient parts are minimized in the begining and end part of the output signal.
- input:
- x: the input signal window_len: the dimension of the smoothing window; should be an odd integer window: the type of window from ‘flat’, ‘hanning’, ‘hamming’, ‘bartlett’, ‘blackman’ (flat window will produce a moving average smoothing.)
- output:
- the smoothed signal