Skip to content

Commit

Permalink
[tvla] Enable passing lists of selected rounds/bytes for specific AES
Browse files Browse the repository at this point in the history
Previously, we could only:
- compute all rounds and all bytes
- select individual rounds but all bytes and vice versa
- select one round and one byte

This commit enables passing a list of bytes and rounds. All
combinations of the combined lists are then evaluated, e.g.
--round-select 0 --round-select 1 --byte-select 0 --byte-select 15
will evaluate Bytes 0 and 15 in both Round 0 and Round 1, i.e., there
will be for tests.

This is helps reducing the memory consumption and compute load if only
few rounds or bytes need to be analyzed as well as for CI.

Signed-off-by: Pirmin Vogel <[email protected]>
  • Loading branch information
vogelpi committed Jan 12, 2024
1 parent 47b9626 commit 8e78d84
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions analysis/configs/tvla_cfg_aes_specific_byte0_rnd0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ trace_end: null
leakage_file: null
save_to_disk: null
save_to_disk_ttest: null
round_select: 0
byte_select: 0
round_select: [0]
byte_select: [0]
input_histogram_file: null
output_histogram_file: null
number_of_steps: 1
Expand Down
28 changes: 17 additions & 11 deletions analysis/tvla.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ def run_tvla(ctx: typer.Context):
rnd_list = [0]
byte_list = [0]
else:
if cfg["round_select"] is None:
if not cfg["round_select"]:
rnd_list = list(range(11))
else:
rnd_list = [int(cfg["round_select"])]
if cfg["byte_select"] is None:
rnd_list = cfg["round_select"]
if not cfg["byte_select"]:
byte_list = list(range(16))
else:
byte_list = [int(cfg["byte_select"])]
byte_list = cfg["byte_select"]
assert all(rnd >= 0 and rnd < 11 for rnd in rnd_list)
assert all(byte >= 0 and byte < 16 for byte in byte_list)

Expand Down Expand Up @@ -1021,11 +1021,13 @@ def run_tvla(ctx: typer.Context):
help_save_to_disk_ttest = inspect.cleandoc("""Save t-test files to disk. Ignored when
ttset-step-file is not None. Default: """ + str(default_save_to_disk_ttest))
help_round_select = inspect.cleandoc("""Index of the AES round for which the histograms are to be
computed: 0-10. If not provided, the histograms for all AES rounds are computed. Default:
""" + str(default_round_select))
computed: 0-10. If not provided, the histograms for all AES rounds are computed. To select
multiple but not all rounds, specify the argument once per selected round, e.g.,
"--round-select 0 --round-select 1". Default: """ + str(default_round_select))
help_byte_select = inspect.cleandoc("""Index of the AES state byte for which the histograms are to
be computed: 0-15. If not provided, the histograms for all AES state bytes are computed.
Default: """ + str(default_byte_select))
be computed: 0-15. If not provided, the histograms for all AES state bytes are computed. To
select multiple but not all bytes, specify the argument once per selected byte, e.g.,
"--byte-select 0 --byte-select 1". Default: """ + str(default_byte_select))
help_input_histogram_file = inspect.cleandoc("""Name of the input file containing the histograms.
Not required. If both -input_histogram_file and -output_histogram_file are provided, the input
file is appended with more data to produce the output file.
Expand Down Expand Up @@ -1066,8 +1068,8 @@ def main(ctx: typer.Context,
leakage_file: str = typer.Option(None, help=help_leakage_file),
save_to_disk: bool = typer.Option(None, help=help_save_to_disk),
save_to_disk_ttest: bool = typer.Option(None, help=help_save_to_disk_ttest),
round_select: int = typer.Option(None, help=help_round_select),
byte_select: int = typer.Option(None, help=help_byte_select),
round_select: list[int] = typer.Option(None, help=help_round_select),
byte_select: list[int] = typer.Option(None, help=help_byte_select),
input_histogram_file: str = typer.Option(None, help=help_input_histogram_file),
output_histogram_file: str = typer.Option(None, help=help_output_histogram_file),
number_of_steps: int = typer.Option(None, help=help_number_of_steps),
Expand Down Expand Up @@ -1098,11 +1100,15 @@ def main(ctx: typer.Context,

# Overwrite options from CLI, if provided.
for v in ['project_file', 'trace_file', 'trace_start', 'trace_end', 'leakage_file',
'save_to_disk', 'save_to_disk_ttest', 'round_select', 'byte_select',
'save_to_disk', 'save_to_disk_ttest',
'input_histogram_file', 'output_histogram_file', 'number_of_steps',
'ttest_step_file', 'plot_figures', 'general_test', 'mode', 'filter_traces']:
run_cmd = f'''if {v} is not None: cfg[v] = {v}'''
exec(run_cmd)
# The list arguments need to be handled a bit differently.
for v in ['round_select', 'byte_select']:
run_cmd = f'''if {v}: cfg[v] = {v}'''
exec(run_cmd)

if not os.path.exists(str(script_dir) + "/tmp"):
os.makedirs(str(script_dir) + "/tmp")
Expand Down
4 changes: 2 additions & 2 deletions ci/cfg/ci_tvla_cfg_aes_specific_byte0_rnd0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ trace_end: null
leakage_file: null
save_to_disk: null
save_to_disk_ttest: null
round_select: 0
byte_select: 0
round_select: [0]
byte_select: [0]
input_histogram_file: null
output_histogram_file: null
number_of_steps: 1
Expand Down

0 comments on commit 8e78d84

Please sign in to comment.