Skip to content

Commit

Permalink
[tvla] Make trace filtering optional.
Browse files Browse the repository at this point in the history
Before starting the analysis, tvla filters out the noisy traces.
This commit makes trace-filtering optional via input argument.
The default value is True.

Signed-off-by: Vladimir Rozic <[email protected]>
  • Loading branch information
vrozic committed Oct 13, 2023
1 parent a3f1697 commit 8ee4e44
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions cw/tvla.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,17 @@ def run_tvla(ctx: typer.Context):
trace_start] + 0.5) * trace_resolution
traces = traces.astype('uint16')

# Filter out noisy traces.
log.info("Filtering Traces")

# Get the mean and standard deviation.
mean = traces.mean(axis=0)
std = traces.std(axis=0)

# Define upper and lower limits.
max_trace = mean + num_sigmas * std
min_trace = mean - num_sigmas * std
max_trace = trace_resolution
min_trace = 0
if cfg["filter_traces"]:
# Filter out noisy traces.
log.info("Filtering Traces")
# Get the mean and standard deviation.
mean = traces.mean(axis=0)
std = traces.std(axis=0)
max_trace = mean + num_sigmas * std
min_trace = mean - num_sigmas * std

# Filtering of converted traces (len = num_samples). traces_to_use itself can be
# used to index the entire project file (len >= num_samples).
Expand Down Expand Up @@ -936,6 +937,7 @@ def run_tvla(ctx: typer.Context):
default_plot_figures = False
default_general_test = False
default_mode = "aes"
default_filter_traces = True
default_update_cfg_file = False


Expand Down Expand Up @@ -987,6 +989,9 @@ def run_tvla(ctx: typer.Context):
Default: """ + str(default_general_test))
help_mode = inspect.cleandoc("""Select mode: can be either "aes", "kmac", "sha3" or "otbn".
Default: """ + str(default_mode))
help_filter_traces = inspect.cleandoc("""Excludes the outlier traces from the analysis. A trace is
an outlier if any of the points is more than 3.5 sigma away from the mean.
Default: """ + str(default_filter_traces))
help_update_cfg_file = inspect.cleandoc("""Update existing configuration file or create if there
isn't any configuration file. Default: """ + str(default_update_cfg_file))

Expand All @@ -1010,6 +1015,7 @@ def main(ctx: typer.Context,
plot_figures: bool = typer.Option(None, help=help_plot_figures),
general_test: bool = typer.Option(None, help=help_general_test),
mode: str = typer.Option(None, help=help_mode),
filter_traces: bool = typer.Option(None, help=help_filter_traces),
update_cfg_file: bool = typer.Option(None, help=help_update_cfg_file)):
"""A histogram-based TVLA described in "Fast Leakage Assessment" by O. Reparaz, B. Gierlichs and
I. Verbauwhede (https://eprint.iacr.org/2017/624.pdf)."""
Expand All @@ -1020,7 +1026,7 @@ def main(ctx: typer.Context,
for v in ['project_file', 'trace_file', 'trace_start', 'trace_end', 'leakage_file',
'save_to_disk', 'save_to_disk_ttest', 'round_select', 'byte_select',
'input_histogram_file', 'output_histogram_file', 'number_of_steps',
'ttest_step_file', 'plot_figures', 'general_test', 'mode']:
'ttest_step_file', 'plot_figures', 'general_test', 'mode', 'filter_traces']:
run_cmd = f'''cfg[v] = default_{v}'''
exec(run_cmd)

Expand All @@ -1034,7 +1040,7 @@ def main(ctx: typer.Context,
for v in ['project_file', 'trace_file', 'trace_start', 'trace_end', 'leakage_file',
'save_to_disk', 'save_to_disk_ttest', 'round_select', 'byte_select',
'input_histogram_file', 'output_histogram_file', 'number_of_steps',
'ttest_step_file', 'plot_figures', 'general_test', 'mode']:
'ttest_step_file', 'plot_figures', 'general_test', 'mode', 'filter_traces']:
run_cmd = f'''if {v} is not None: cfg[v] = {v}'''
exec(run_cmd)

Expand Down

0 comments on commit 8ee4e44

Please sign in to comment.