-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenv_parse.py
101 lines (88 loc) · 2.51 KB
/
env_parse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import numpy as np
import argparse
import os
########################## USER PARAMETERS
# Templates parameters:
# Number of POI
npoi_max = 3600 # max number of pois
npoi_min = 3600 # min number of pois
npoi = npoi_max
# Number of dimensions in linear subspace
p = 8
# target memory usage (GB), yet it may consumes a bit more.
memory_limit = 200
# datasets location (use download.py to download them)
dataset_dir = "./traces/"
######################### END OF USER PARAMETERS
# Get command line arguemnets
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--dshares", type=int, default=3, help="Number of shares")
parser.add_argument(
"-n",
"--ntracesattack",
type=str,
default="100",
help="Number of traces for the attack. Must be integer separated with comma",
)
args = parser.parse_args()
D = args.dshares
ntraces_a = args.ntracesattack.replace(" ", "").split(",")
ntraces_a_all = [int(x) for x in ntraces_a]
# directories for traces
profile_dir = f"{dataset_dir}/sw{D}/random_key/"
attack_dir = [f"{dataset_dir}/sw{D}/fixed_key/key_{x}/" for x in range(5)]
# target source files
sw_src_dir = "./spook_sw/"
# where profiling data will be stored
data_dir = f"./data_{D}/"
# where labels will be stored
label_dir = os.path.join(data_dir, "labels")
if not os.path.exists(label_dir):
os.makedirs(label_dir)
# where the final models will be stored
models_file = os.path.join(data_dir, f"models_{D}.pkl")
# files with SNR
snr_file = os.path.join(data_dir, f"snr_{D}.pkl")
# files with SNR only at poi
snr_file_at_poi = os.path.join(data_dir, f"snr_{D}_at_poi.pkl")
# file to compute the attack results
attack_summary_file = os.path.join(data_dir, f"attack_summary_{D}.pkl")
# prefix of profiling traces
profile_prefix = os.path.join(profile_dir, f"rkey_sw{D}_10000")
# base variable labels
variables = [
"a",
"b",
"c",
"d",
"tmp0",
"tmp1",
"tmp2",
"tmp3",
"y0",
"y1",
"y1r",
"y2",
"y3",
]
# number of profiling files
nfiles_profile = 20
# number of traces per profiling file
ntraces_p = 10000
# set traces length for all the D
if D == 3:
ns = 62500
elif D == 4:
ns = 83333
elif D == 6:
ns = 156250
elif D == 8:
ns = 218750
# Set batch parameters
memory_limit *= 1e9
# remove size of a (int16) trace file
memory_limit -= ns * ntraces_p * 2
memory_per_snr = ns * 8 * 2 * 256
np_snr = int(np.floor(memory_limit / memory_per_snr))
memory_per_enc_graph = len(variables) * (D + 1) * 256 * 8 * 3
batch_enc = int(np.floor(memory_limit / (memory_per_enc_graph)))