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

[otbn/tvla] add option to configure the used samples per trace #125

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
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
26 changes: 25 additions & 1 deletion cw/tvla.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,27 @@ def run_tvla(ctx: typer.Context):
# Amount of tolerable deviation from average during filtering.
num_sigmas = 3.5

# Slice of wave file
# these options are only tested for otbn
if ("sample_start" in cfg and cfg["sample_start"] is not None):
sample_start = cfg["sample_start"]
else:
sample_start = 0

assert sample_start < len(project.waves[0])

if ("num_samples" in cfg and cfg["num_samples"] is not None):
num_samples = cfg["num_samples"]
else:
num_samples = len(project.waves[0]) - sample_start

if (num_samples + sample_start > len(project.waves[0])):
log.warning(f"Selected sample window {sample_start} to " +
f"{sample_start+num_samples} is out of range!")
num_samples = len(project.waves[0]) - sample_start
log.warning(f"Will use samples from {sample_start} " +
f"to {sample_start+num_samples} instead!")

# Overall number of traces, trace start and end indices.
num_traces_max = len(project.waves)
if cfg["trace_start"] is None:
Expand Down Expand Up @@ -548,8 +569,11 @@ def run_tvla(ctx: typer.Context):
log.info("Converting Traces")
if project.waves[0].dtype == 'uint16':
traces = np.empty((num_traces, num_samples), dtype=np.uint16)
log.info(f"Will use samples from {sample_start} to {sample_start+num_samples}")
for i_trace in range(num_traces):
traces[i_trace] = project.waves[i_trace + trace_start]
traces[i_trace] = project.waves[i_trace +
trace_start][sample_start:sample_start +
num_samples]
else:
traces = np.empty((num_traces, num_samples), dtype=np.double)
for i_trace in range(num_traces):
Expand Down
2 changes: 2 additions & 0 deletions cw/tvla_cfg_otbn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ plot_figures: true
general_test: true
mode: otbn
key_len_bytes: 40
sample_start: null
num_samples : 4000
m-temp marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions cw/tvla_cfg_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ ttest_step_file: null
plot_figures: false
general_test: true
mode: aes
# Only enabled for otbn mode.
sample_start: null
num_samples : null