|Name||Last Update||Last Commit 99f992dab35 – Scale_float_to_uint: Round before converting fl...||history|
|.gitignore||Loading commit data...|
|README.md||Loading commit data...|
|average.py||Loading commit data...|
|contiguify.py||Loading commit data...|
|csv_plot.py||Loading commit data...|
|dispatch_against_plaintexts.py||Loading commit data...|
|downsample.py||Loading commit data...|
|filter_highest_variance.py||Loading commit data...|
|get_mat_dim.py||Loading commit data...|
|group_process.py||Loading commit data...|
|keep.py||Loading commit data...|
|merge.py||Loading commit data...|
|npy_to_bin.py||Loading commit data...|
|npy_to_hex.py||Loading commit data...|
|npy_to_raw.py||Loading commit data...|
|pairwise_operation.py||Loading commit data...|
|plot.py||Loading commit data...|
|realign.py||Loading commit data...|
|remove_window.py||Loading commit data...|
|scale_float_to_uinttype.py||Loading commit data...|
|shorten.py||Loading commit data...|
|split.py||Loading commit data...|
|step_average.py||Loading commit data...|
Scripts for preprocessing power traces
The following preprocessing scripts are available:
Reduce the size of the traces by keeping only every nth sample in the trace starting at a specified offset.
Identify points of interest in the trace by keeping only a ratio of the samples with the highest variance.
Apply the same function to multiples trace files.
Merge multiple trace files into one.
Combine pairs of samples.
The possible pairs of samples are taken inside a sliding window over the trace.
The operation used to combine the samples can be chosen.
Thanks to Python
multiprocessingpackage, the trace is split into blocks that are processed in parallel.
Combining pairs of samples allows to launch a first-order CPA on a first-order masked implementation, which would otherwise require a second-order CPA.
Plot the n first traces from a traces file.
Realigns the traces in a file against a reference trace from this file.
Remove a window from the traces. Can plot the traces before removing.
Shorten the traces by removing the head and/or the tail.
Split a traces file into multiple files.
Group samples from a trace into chunks and compute the mean for each chunk.
This is not a moving average.
# Download sources git clone firstname.lastname@example.org:brice.colombier/traces-preprocessing.git cd traces-preprocessing # Download and build dependencies: # On Windows pip install scikit-image # On Ubuntu sudo apt-get install python-skimage
These scripts take one positional parameter and multiple keyword arguments.
The positional parameter is the file in which the traces are stored in
Keep only every 4th sample starting from sample 10.
python downsample.py traces.npy --factor=4 --offset=10
Keep only the 1% samples with the highest variance:
python filter_highest_variance.py traces.npy --ratio=0.01
Keep only the 100 samples with the highest variance:
python filter_highest_variance.py traces.npy --nsamples=100
Perform parallel multiplication of samples on 4 cores using a sliding window of 5 samples and all possible pairs of samples:
python pairwise_operation.py masked_traces.npy --op=multiplication --window_size=5 --min_dist=1 --dtype=float64 --ncores=4
Perform parallel absolute difference of samples on 16 cores using a sliding window of 100 samples and pairs of samples that are at least 80 samples away from one another:
python pairwise_operation.py masked_traces.npy --op=absolute_difference --window_size=100 --min_dist=80 --dtype=float64 --ncores=16
Plot the first trace in a the file:
python plot.py traces.npy
Plot the first ten traces in a the file:
python plot.py traces.npy -n=10
Realign all the traces in a file on the 1st trace from this file:
python realign.py traces.npy
Realign all the traces in a file on the 21st trace from this file:
python realign.py traces.npy -r=21
Plot the trace with the window from samples 500 to 1000 in red:
python remove_window.py --start_index=500 --stop_index=1000 --plot_only=True traces.npy
Remove from sample 500 to sample 1000 from the trace:
python remove_window.py --start_index=500 --stop_index=1000 traces.npy
Keep only from sample 500 to sample 1000 in the trace:
python shorten.py --start_index=500 --stop_index=1000 traces.npy
Split the traces file into four files:
python split.py --nb_shares=4 traces.npy
Compute the average of every block of four samples in the trace, reducing the size of the file by four:
python step_average.py --step_size=4 traces.npy
Compute the average of every block of four samples in the trace starting at sample 100:
python step_average.py --step_size=4 --offset=100 traces.npy
Keyword arguments can be listed by calling script with
pyhton *script*.py -h
--factor: the downsampling factor n, to keep only every nth sample
--offset: the offset at which downsampling starts
--ratio: the ratio of samples with highest variance to keep
--nsamples: the number of samples with highest variance to keep
--prefix: prefix of the name of the files to process
--nb_shares: number of files to process
--function: operation to apply on the files
--output_format: data format for the binary file
--op: the operation to compute on the pair of samples. It should belong to
In DPA book it is said that
absolute differenceis a good choice for second-order CPA attacks that leak the Hamming weight
--window_size: the width of the sliding window
--min_dist: the minimum distance between two samples in a pair
numpythe data type for the samples of the processed trace
--ncores: the number of cores to use for the parallel computation
-n: number of traces to plot
-r: index of the trace to use as reference
--start_index: start index of the window to remove
--stop_index: stop index of the window to remove
--plot_only: set to
Trueto plot only
--start_index: start index of the window to keep
--stop_index: stop index of the window to keep
--nb_shares: number of files into which the file is split
--step_size: size of the chunk on which the average is computed
--offset: start index