-
Notifications
You must be signed in to change notification settings - Fork 0
/
record.py
executable file
·41 lines (30 loc) · 1.01 KB
/
record.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
import random
from algorithm5 import *
import numpy as np
from recorder import *
def record(file, order=0, n_traces=256, zero_masks=False):
recorder = Recorder()
d = order
# if n_traces > pow(256, order+1):
# raise Exception("number of traces to be recorded cannot be greater than total possible traces")
recorder.record_order(d)
for i in range(n_traces):
p = i % 256
recorder.record_input(p)
s = np.empty(d+1, dtype=int)
s[0] = p #p stands for plaintext
# state masking
for i in range (1, d+1):
if zero_masks:
s[i] = 0
else:
s[i] = random.randint(0, 255)
s[0] = s[0] ^ s[i]
y = sec_sbox_aes(s, recorder)
recorder.save_trace()
recorder.save_dataset(file)
#record("no_masks")
record("with_masks_1", 1, n_traces=5000)
# record("with_masks_3", 3, n_traces=5000)
#record("with_masks_19", 19, n_traces = 5000)
#record("no_masks_1000traces", n_traces=1000)