Skip to content

Commit 4a56bdd

Browse files
committed
[otbn/tvla] add option to configure the used samples per trace
This option is currently only available for otbn traces. Signed-off-by: Michael Tempelmeier <[email protected]>
1 parent 11d590f commit 4a56bdd

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

cw/tvla.py

+30-1
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,32 @@ def run_tvla(ctx: typer.Context):
488488
# Amount of tolerable deviation from average during filtering.
489489
num_sigmas = 3.5
490490

491+
# Slice of wave file
492+
# these options are only tested for otbn
493+
if (cfg["mode"] != "otbn" and "sample_start" in cfg and cfg["sample_start"] is not None):
494+
raise RuntimeError('Option "sample_start is only supported for otbn!')
495+
if (cfg["mode"] != "otbn" and "num_samples" in cfg and cfg["num_samples"] is not None):
496+
raise RuntimeError('Option "num_samples is only supported for otbn!')
497+
498+
if (cfg["mode"] != "otbn" or cfg["sample_start"] is None):
499+
sample_start = 0
500+
else:
501+
sample_start = cfg["sample_start"]
502+
503+
assert sample_start < len(project.waves[0])
504+
505+
if (cfg["mode"] != "otbn" or cfg["num_samples"] is None):
506+
num_samples = len(project.waves[0]) - sample_start
507+
else:
508+
num_samples = cfg["num_samples"]
509+
510+
if (num_samples + sample_start > len(project.waves[0])):
511+
log.warning(f"Selected sample window {sample_start} to " +
512+
f"{sample_start+num_samples} is out of range!")
513+
num_samples = len(project.waves[0]) - sample_start
514+
log.warning(f"Will use samples from {sample_start} " +
515+
f"to {sample_start+num_samples} instead!")
516+
491517
# Overall number of traces, trace start and end indices.
492518
num_traces_max = len(project.waves)
493519
if cfg["trace_start"] is None:
@@ -548,8 +574,11 @@ def run_tvla(ctx: typer.Context):
548574
log.info("Converting Traces")
549575
if project.waves[0].dtype == 'uint16':
550576
traces = np.empty((num_traces, num_samples), dtype=np.uint16)
577+
log.info(f"Will use samples from {sample_start} to {sample_start+num_samples}")
551578
for i_trace in range(num_traces):
552-
traces[i_trace] = project.waves[i_trace + trace_start]
579+
traces[i_trace] = project.waves[i_trace +
580+
trace_start][sample_start:sample_start +
581+
num_samples]
553582
else:
554583
traces = np.empty((num_traces, num_samples), dtype=np.double)
555584
for i_trace in range(num_traces):

cw/tvla_cfg_otbn.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ plot_figures: true
1414
general_test: true
1515
mode: otbn
1616
key_len_bytes: 40
17+
sample_start: null
18+
num_samples : 4000

0 commit comments

Comments
 (0)