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 available for otbn traces.

Signed-off-by: Michael Tempelmeier <[email protected]>
  • Loading branch information
m-temp committed Feb 28, 2023
1 parent 11d590f commit 4a56bdd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 30 additions & 1 deletion cw/tvla.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,32 @@ 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 (cfg["mode"] != "otbn" and "sample_start" in cfg and cfg["sample_start"] is not None):
raise RuntimeError('Option "sample_start is only supported for otbn!')
if (cfg["mode"] != "otbn" and "num_samples" in cfg and cfg["num_samples"] is not None):
raise RuntimeError('Option "num_samples is only supported for otbn!')

if (cfg["mode"] != "otbn" or cfg["sample_start"] is None):
sample_start = 0
else:
sample_start = cfg["sample_start"]

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

if (cfg["mode"] != "otbn" or cfg["num_samples"] is None):
num_samples = len(project.waves[0]) - sample_start
else:
num_samples = cfg["num_samples"]

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 +574,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

0 comments on commit 4a56bdd

Please sign in to comment.