Skip to content

Commit

Permalink
[otbn/tvla] add option to configure the used samples per trace
Browse files Browse the repository at this point in the history
This option is currently only tested for otbn traces.

Signed-off-by: Michael Tempelmeier <[email protected]>
  • Loading branch information
m-temp committed Mar 2, 2023
1 parent 07a763d commit f9ed806
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
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
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

0 comments on commit f9ed806

Please sign in to comment.