5
5
6
6
import inspect
7
7
import logging as log
8
+ import math
8
9
import multiprocessing
9
10
import os
10
11
import sys
11
12
from pathlib import Path
12
13
from types import SimpleNamespace
13
14
14
15
import matplotlib .pyplot as plt
15
- import math
16
16
import numpy as np
17
17
import typer
18
18
import yaml
@@ -163,7 +163,8 @@ def compute_histograms_aes(trace_resolution, rnd_list, byte_list, traces, leakag
163
163
return histograms
164
164
165
165
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 ):
167
168
"""Plotting trace in different colors, depending on where the trigger is high
168
169
"""
169
170
c = np .ones (num_samples )
@@ -204,17 +205,17 @@ def tvla_plotting_fnc(axs, num_orders, ttest_trace, single_trace, threshold, num
204
205
axs [1 + i_order ].plot (xaxs , c * threshold , "r" )
205
206
axs [1 + i_order ].plot (xaxs , - threshold * c , "r" )
206
207
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" )
210
211
if trigger_low > trigger_high :
211
212
axs [1 + i_order ].plot (
212
213
xaxs [trigger_high :trigger_low ],
213
214
ttest_trace [i_order , 0 , 0 ][trigger_high :trigger_low ], "k" )
214
215
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" )
218
219
219
220
return axs
220
221
@@ -524,7 +525,10 @@ def run_tvla(ctx: typer.Context):
524
525
# Eventually, we can drop this.
525
526
if i_step == 0 :
526
527
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 ()
528
532
else :
529
533
# Convert all keys from the project file to numpy
530
534
# arrays once.
@@ -758,23 +762,27 @@ def run_tvla(ctx: typer.Context):
758
762
# Catch case where certain metadata isn't saved to project file (e.g. older measurement)
759
763
try :
760
764
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 "
762
767
except KeyError :
763
768
textbox = textbox
764
769
try :
765
770
textbox = textbox + "Masks off:\n " + metadata ['masks_off' ] + "\n \n "
766
771
except KeyError :
767
772
textbox = textbox
768
773
try :
769
- textbox = textbox + "Samples:\n " + str (metadata ['num_samples' ]) + "\n \n "
774
+ textbox = textbox + "Samples:\n " + str (
775
+ metadata ['num_samples' ]) + "\n \n "
770
776
except KeyError :
771
777
textbox = textbox
772
778
try :
773
- textbox = textbox + "Offset:\n " + str (metadata ['offset_samples' ]) + "\n \n "
779
+ textbox = textbox + "Offset:\n " + str (
780
+ metadata ['offset_samples' ]) + "\n \n "
774
781
except KeyError :
775
782
textbox = textbox
776
783
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 "
778
786
except KeyError :
779
787
textbox = textbox
780
788
try :
@@ -793,9 +801,13 @@ def run_tvla(ctx: typer.Context):
793
801
for i_rnd in range (num_rnds ):
794
802
for i_byte in range (num_bytes ):
795
803
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 )
797
808
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)
799
811
try :
800
812
axs [0 ].set_title ("TVLA of " + "aes_t_test_round_" +
801
813
str (rnd_list [i_rnd ]) + "_byte_" +
@@ -813,14 +825,14 @@ def run_tvla(ctx: typer.Context):
813
825
right = left + width
814
826
top = bottom + height
815
827
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 ))
824
836
plt .subplots_adjust (right = 0.84 )
825
837
plt .xlabel ("time [samples]" )
826
838
@@ -833,7 +845,9 @@ def run_tvla(ctx: typer.Context):
833
845
plt .close ()
834
846
835
847
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 )
837
851
838
852
# Catch case where datetime data isn't saved to project file (e.g. older measurement)
839
853
try :
0 commit comments