Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tvla] Enable passing lists of selected rounds/bytes for byte-specific AES, add new CI job #289

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -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
39 changes: 24 additions & 15 deletions analysis/tvla.py
Original file line number Diff line number Diff line change
@@ -255,22 +255,25 @@ def run_tvla(ctx: typer.Context):
general_test = (cfg["mode"] == "kmac" or cfg["mode"] == "otbn" or cfg["mode"] == "sha3" or
cfg["general_test"] is True)

aes_num_rnds = 11
aes_num_bytes = 16

if general_test:
# We don't care about the round select or byte select in this mode.
# Set them to 0 for code compatibility.
rnd_list = [0]
byte_list = [0]
else:
if cfg["round_select"] is None:
rnd_list = list(range(11))
if not cfg["round_select"]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for that change?

In a new PR (#294), I've made exactly the opposite change. If cfg["round_select"] could be None (i.e., the entry is not in the cfg dictionary), then I think the is None check should be better?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, this change is necessary because round_select is now a list instead of an int. To find out if the list is empty (no round_select) specified, we have to use not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be best practice:

Suggested change
if not cfg["round_select"]:
if cfg.get("round_select") is not None:

if the key (i.e., round_select) does not exist, the get() returns None.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. As answered above, the not tells us if the list round_select is empty. Previously, we just needed to check if it was defined or not.

rnd_list = list(range(aes_num_rnds))
else:
rnd_list = [int(cfg["round_select"])]
if cfg["byte_select"] is None:
byte_list = list(range(16))
rnd_list = cfg["round_select"]
if not cfg["byte_select"]:
byte_list = list(range(aes_num_bytes))
else:
byte_list = [int(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)
byte_list = cfg["byte_select"]
assert all(rnd >= 0 and rnd < aes_num_rnds for rnd in rnd_list)
assert all(byte >= 0 and byte < aes_num_bytes for byte in byte_list)

num_rnds = len(rnd_list)
num_bytes = len(byte_list)
@@ -1021,11 +1024,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.
@@ -1066,8 +1071,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),
@@ -1098,11 +1103,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")
10 changes: 10 additions & 0 deletions ci/azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -154,6 +154,16 @@ jobs:
- publish: ./ci/projects/aes_sca_random_cw305.html
artifact: traces_aes_random_cw305
displayName: "Upload AES Random traces"
- bash: |
set -e
pushd ci
../analysis/tvla.py --cfg-file cfg/ci_tvla_cfg_aes_specific_byte_0_15_rnd_0_1.yaml run-tvla
popd
displayName: "Perform specific TVLA on AES Random traces"
continueOnError: True
- publish: ./ci/tmp/figures
artifact: tvla_figures_aes_specific
displayName: "Upload figures of specific TVLA for AES."
- job: kmac_sca_capture_cw310
displayName: "Capture KMAC SCA traces (CW310)"
timeoutInMinutes: 30
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
@@ -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
19 changes: 19 additions & 0 deletions ci/cfg/ci_tvla_cfg_aes_specific_byte_0_15_rnd_0_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
project_file: projects/aes_sca_random_cw305
trace_file: null
trace_start: null
trace_end: null
leakage_file: null
save_to_disk: null
save_to_disk_ttest: true
round_select: [0, 1]
byte_select: [0, 15]
input_histogram_file: null
output_histogram_file: null
number_of_steps: 4
ttest_step_file: null
plot_figures: true
general_test: false
mode: aes
filter_traces: false
sample_start: 0
num_samples: 300