Skip to content

Commit f9ed806

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

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

cw/tvla.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,27 @@ 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 ("sample_start" in cfg and cfg["sample_start"] is not None):
494+
sample_start = cfg["sample_start"]
495+
else:
496+
sample_start = 0
497+
498+
assert sample_start < len(project.waves[0])
499+
500+
if ("num_samples" in cfg and cfg["num_samples"] is not None):
501+
num_samples = cfg["num_samples"]
502+
else:
503+
num_samples = len(project.waves[0]) - sample_start
504+
505+
if (num_samples + sample_start > len(project.waves[0])):
506+
log.warning(f"Selected sample window {sample_start} to " +
507+
f"{sample_start+num_samples} is out of range!")
508+
num_samples = len(project.waves[0]) - sample_start
509+
log.warning(f"Will use samples from {sample_start} " +
510+
f"to {sample_start+num_samples} instead!")
511+
491512
# Overall number of traces, trace start and end indices.
492513
num_traces_max = len(project.waves)
493514
if cfg["trace_start"] is None:
@@ -548,8 +569,11 @@ def run_tvla(ctx: typer.Context):
548569
log.info("Converting Traces")
549570
if project.waves[0].dtype == 'uint16':
550571
traces = np.empty((num_traces, num_samples), dtype=np.uint16)
572+
log.info(f"Will use samples from {sample_start} to {sample_start+num_samples}")
551573
for i_trace in range(num_traces):
552-
traces[i_trace] = project.waves[i_trace + trace_start]
574+
traces[i_trace] = project.waves[i_trace +
575+
trace_start][sample_start:sample_start +
576+
num_samples]
553577
else:
554578
traces = np.empty((num_traces, num_samples), dtype=np.double)
555579
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

cw/tvla_cfg_template.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ ttest_step_file: null
1313
plot_figures: false
1414
general_test: true
1515
mode: aes
16+
# Only enabled for otbn mode.
17+
sample_start: null
18+
num_samples : null

0 commit comments

Comments
 (0)