Skip to content

Commit f653abd

Browse files
committed
[tvla] Adjust kmac and sha3 capture and config for tvla plotting
Signed-off-by: Moritz Wettermann <[email protected]>
1 parent e5f8e26 commit f653abd

File tree

6 files changed

+52
-27
lines changed

6 files changed

+52
-27
lines changed

analysis/configs/tvla_cfg_kmac.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project_file: projects/opentitan_simple_kmac.cwp
1+
project_file: ../capture/projects/simple_capture_kmac_sca
22
trace_file: null
33
trace_start: null
44
trace_end: null
@@ -14,3 +14,6 @@ ttest_step_file: null
1414
plot_figures: true
1515
general_test: true
1616
mode: kmac
17+
filter_traces: true
18+
trace_threshold: 1000
19+
trace_db: ot_trace_library

analysis/configs/tvla_cfg_sha3.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project_file: projects/opentitan_simple_sha3.cwp
1+
project_file: ../capture/projects/simple_capture_sha3_sca
22
trace_file: null
33
trace_start: null
44
trace_end: null
@@ -14,3 +14,6 @@ ttest_step_file: null
1414
plot_figures: true
1515
general_test: true
1616
mode: sha3
17+
filter_traces: true
18+
trace_threshold: 1000
19+
trace_db: ot_trace_library

analysis/tvla.py

+38-24
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
import inspect
77
import logging as log
8+
import math
89
import multiprocessing
910
import os
1011
import sys
1112
from pathlib import Path
1213
from types import SimpleNamespace
1314

1415
import matplotlib.pyplot as plt
15-
import math
1616
import numpy as np
1717
import typer
1818
import yaml
@@ -163,7 +163,8 @@ def compute_histograms_aes(trace_resolution, rnd_list, byte_list, traces, leakag
163163
return histograms
164164

165165

166-
def tvla_plotting_fnc(axs, num_orders, ttest_trace, single_trace, threshold, num_samples, sample_start, metadata):
166+
def tvla_plotting_fnc(axs, num_orders, ttest_trace, single_trace, threshold,
167+
num_samples, sample_start, metadata):
167168
"""Plotting trace in different colors, depending on where the trigger is high
168169
"""
169170
c = np.ones(num_samples)
@@ -204,17 +205,17 @@ def tvla_plotting_fnc(axs, num_orders, ttest_trace, single_trace, threshold, num
204205
axs[1 + i_order].plot(xaxs, c * threshold, "r")
205206
axs[1 + i_order].plot(xaxs, -threshold * c, "r")
206207
if trigger_high > 0:
207-
axs[1 + i_order].plot(
208-
xaxs[:trigger_high],
209-
ttest_trace[i_order, 0, 0][:trigger_high], "grey")
208+
axs[1 + i_order].plot(xaxs[:trigger_high],
209+
ttest_trace[i_order, 0,
210+
0][:trigger_high], "grey")
210211
if trigger_low > trigger_high:
211212
axs[1 + i_order].plot(
212213
xaxs[trigger_high:trigger_low],
213214
ttest_trace[i_order, 0, 0][trigger_high:trigger_low], "k")
214215
if trigger_low < num_samples:
215-
axs[1 + i_order].plot(
216-
xaxs[trigger_low:],
217-
ttest_trace[i_order, 0, 0][trigger_low:], "grey")
216+
axs[1 + i_order].plot(xaxs[trigger_low:],
217+
ttest_trace[i_order, 0,
218+
0][trigger_low:], "grey")
218219

219220
return axs
220221

@@ -524,7 +525,10 @@ def run_tvla(ctx: typer.Context):
524525
# Eventually, we can drop this.
525526
if i_step == 0:
526527
if OTTraceLib:
527-
keys_nparrays = project.get_keys()
528+
if cfg["mode"] == "sha3":
529+
keys_nparrays = project.get_plaintexts()
530+
else:
531+
keys_nparrays = project.get_keys()
528532
else:
529533
# Convert all keys from the project file to numpy
530534
# arrays once.
@@ -758,23 +762,27 @@ def run_tvla(ctx: typer.Context):
758762
# Catch case where certain metadata isn't saved to project file (e.g. older measurement)
759763
try:
760764
sampling_rate = float(metadata['sampling_rate']) / 1e6
761-
textbox = textbox + "Sample rate:\n" + str(math.floor(sampling_rate)) + " MS/s\n\n"
765+
textbox = textbox + "Sample rate:\n" + str(
766+
math.floor(sampling_rate)) + " MS/s\n\n"
762767
except KeyError:
763768
textbox = textbox
764769
try:
765770
textbox = textbox + "Masks off:\n" + metadata['masks_off'] + "\n\n"
766771
except KeyError:
767772
textbox = textbox
768773
try:
769-
textbox = textbox + "Samples:\n" + str(metadata['num_samples']) + "\n\n"
774+
textbox = textbox + "Samples:\n" + str(
775+
metadata['num_samples']) + "\n\n"
770776
except KeyError:
771777
textbox = textbox
772778
try:
773-
textbox = textbox + "Offset:\n" + str(metadata['offset_samples']) + "\n\n"
779+
textbox = textbox + "Offset:\n" + str(
780+
metadata['offset_samples']) + "\n\n"
774781
except KeyError:
775782
textbox = textbox
776783
try:
777-
textbox = textbox + "Scope gain:\n" + str(metadata['scope_gain']) + "\n\n"
784+
textbox = textbox + "Scope gain:\n" + str(
785+
metadata['scope_gain']) + "\n\n"
778786
except KeyError:
779787
textbox = textbox
780788
try:
@@ -793,9 +801,13 @@ def run_tvla(ctx: typer.Context):
793801
for i_rnd in range(num_rnds):
794802
for i_byte in range(num_bytes):
795803

796-
axs = tvla_plotting_fnc(axs, num_orders, ttest_trace, single_trace, threshold, num_samples, sample_start, metadata)
804+
axs = tvla_plotting_fnc(axs, num_orders, ttest_trace,
805+
single_trace, threshold,
806+
num_samples, sample_start,
807+
metadata)
797808

798-
# Catch case where datetime data isn't saved to project file (e.g. older measurement)
809+
# Catch case where datetime data isn't saved
810+
# to project file (e.g. older measurement)
799811
try:
800812
axs[0].set_title("TVLA of " + "aes_t_test_round_" +
801813
str(rnd_list[i_rnd]) + "_byte_" +
@@ -813,14 +825,14 @@ def run_tvla(ctx: typer.Context):
813825
right = left + width
814826
top = bottom + height
815827
plt.gcf().text(0.5 * (left + right),
816-
0.5 * (bottom + top),
817-
textbox,
818-
fontsize=9,
819-
horizontalalignment='center',
820-
verticalalignment='center',
821-
bbox=dict(boxstyle='round',
822-
facecolor='w',
823-
linewidth=0.6))
828+
0.5 * (bottom + top),
829+
textbox,
830+
fontsize=9,
831+
horizontalalignment='center',
832+
verticalalignment='center',
833+
bbox=dict(boxstyle='round',
834+
facecolor='w',
835+
linewidth=0.6))
824836
plt.subplots_adjust(right=0.84)
825837
plt.xlabel("time [samples]")
826838

@@ -833,7 +845,9 @@ def run_tvla(ctx: typer.Context):
833845
plt.close()
834846

835847
else:
836-
axs = tvla_plotting_fnc(axs, num_orders, ttest_trace, single_trace, threshold, num_samples, sample_start, metadata)
848+
axs = tvla_plotting_fnc(axs, num_orders, ttest_trace, single_trace,
849+
threshold, num_samples, sample_start,
850+
metadata)
837851

838852
# Catch case where datetime data isn't saved to project file (e.g. older measurement)
839853
try:

capture/capture_kmac.py

+2
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ def main(argv=None):
463463
metadata["cfg"] = cfg
464464
metadata["num_samples"] = scope.scope_cfg.num_samples
465465
metadata["offset_samples"] = scope.scope_cfg.offset_samples
466+
metadata["sampling_rate"] = scope.scope_cfg.sampling_rate
467+
metadata["num_traces"] = capture_cfg.num_traces
466468
metadata["scope_gain"] = scope.scope_cfg.scope_gain
467469
metadata["cfg_file"] = str(args.cfg)
468470
# Store bitstream information.

capture/capture_otbn.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,8 @@ def main(argv=None):
746746
metadata["offset_samples"] = scope.scope_cfg.offset_samples
747747
metadata["scope_gain"] = scope.scope_cfg.scope_gain
748748
if cfg["capture"]["scope_select"] == "husky":
749-
metadata["sampling_rate"] = scope.scope.scope.clock.adc_freq / scope.scope.scope.adc.decimate
749+
metadata[
750+
"sampling_rate"] = scope.scope.scope.clock.adc_freq / scope.scope.scope.adc.decimate
750751
metadata["samples_trigger_high"] = scope.scope.scope.adc.trig_count
751752
else:
752753
metadata["sampling_rate"] = scope.scope_cfg.sampling_rate

capture/capture_sha3.py

+2
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ def main(argv=None):
433433
metadata["cfg"] = cfg
434434
metadata["num_samples"] = scope.scope_cfg.num_samples
435435
metadata["offset_samples"] = scope.scope_cfg.offset_samples
436+
metadata["sampling_rate"] = scope.scope_cfg.sampling_rate
437+
metadata["num_traces"] = capture_cfg.num_traces
436438
metadata["scope_gain"] = scope.scope_cfg.scope_gain
437439
metadata["cfg_file"] = str(args.cfg)
438440
# Store bitstream information.

0 commit comments

Comments
 (0)