-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_security.c
172 lines (146 loc) · 5.4 KB
/
check_security.c
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <immintrin.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include "combinations.h"
#include "prob_desc.h"
#include "checker.h"
#ifdef VECT
int main(int argc, char **argv)
{
uint64_t k;
uint64_t nb_internal;
int64_t i;
uint16_t to_del, to_add;
uint64_t comb[D + 1];
uint64_t probes_r_curr;
int attack_sni = 0;
int attack_ni = 0;
int check_sni = 0;
uint64_t c = 0;
__m256i probes_a_curr;
__m256i probes_b_curr;
__m256i probes_a_all[NB_PR];
__m256i probes_b_all[NB_PR];
init_sh_all(probes_a_all, probes_b_all);
printf("Checking security for %s...\n", filename);
printf("Stopping at first NI attack\n");
if (argc > 1 && !strncmp(argv[1], "--sni", 5)) {
check_sni = 1;
printf("Stopping at first SNI attack\n");
}
for (k = 1; k <= D; k++) {
printf("\nAttacks with %lu probes:\n", k);
init_combination(comb, k, NB_PR);
init_sh_curr(&probes_a_curr, probes_a_all, comb, k);
init_sh_curr(&probes_b_curr, probes_b_all, comb, k);
init_r_curr(&probes_r_curr, comb, k);
c = 0;
nb_internal = k;
while (!attack_ni && !attack_sni) {
c++;
if (!(c % 100000000)) {
printf("\rSets of probes already visited: %lu", c);
fflush(stdout);
}
if (check_sni)
attack_sni = check_attack_sni(k, nb_internal, probes_r_curr, probes_a_curr, probes_b_curr);
attack_ni = check_attack_ni(k, probes_r_curr, probes_a_curr, probes_b_curr);
i = next_combination(comb, k);
if (i == 0) break;
to_del = (uint16_t) ((i >> 16) & 0xFFFF);
to_add = (uint16_t) (i & 0xFFFF);
// Adjust the number of internal probes
if (to_del < NB_PR - NB_SH) nb_internal--;
if (to_add < NB_PR - NB_SH) nb_internal++;
probes_a_curr = _mm256_xor_si256(probes_a_curr, probes_a_all[to_del]);
probes_a_curr = _mm256_xor_si256(probes_a_curr, probes_a_all[to_add]);
probes_b_curr = _mm256_xor_si256(probes_b_curr, probes_b_all[to_del]);
probes_b_curr = _mm256_xor_si256(probes_b_curr, probes_b_all[to_add]);
probes_r_curr ^= probes_r[to_del] ^ probes_r[to_add];
}
if (attack_ni || attack_sni) {
printf("\n");
print_combination(comb, k);
printf("to_del=%d\n", to_del);
printf("to_add=%d\n", to_add);
printf("\n------- UNSAFE -------\n");
if (attack_ni) printf("ATTACK NI FOUND\n");
if (attack_sni) printf("ATTACK SNI FOUND\n");
return 1;
}
printf("\rSets of probes already visited: %lu", c);
fflush(stdout);
}
printf("\n------- SAFE -------\n");
return 0;
}
#else
int main(int argc, char **argv)
{
uint64_t k;
uint64_t nb_internal;
int64_t i;
uint16_t to_del, to_add;
uint64_t comb[D + 1];
uint64_t probes_r_curr[SIZE_R];
int attack_sni = 0;
int attack_ni = 0;
int check_sni = 0;
uint64_t c = 0;
uint64_t probes_a_curr[NB_SH][SIZE_SH];
uint64_t probes_b_curr[NB_SH][SIZE_SH];
printf("Checking security for %s...\n", filename);
printf("Stopping at first NI attack\n");
if (argc > 1 && !strncmp(argv[1], "--sni", 5)) {
check_sni = 1;
printf("Stopping at first SNI attack\n");
}
for (k = 1; k <= D; k++) {
printf("\nAttacks with %lu probes:\n", k);
init_combination(comb, k, NB_PR);
init_sh_curr(probes_a_curr, probes_sh_a, comb, k);
init_sh_curr(probes_b_curr, probes_sh_b, comb, k);
init_r_curr(probes_r_curr, comb, k);
c = 0;
nb_internal = k;
while (!attack_ni && !attack_sni) {
c++;
if (!(c % 100000000)) {
printf("\rSets of probes already visited: %lu", c);
fflush(stdout);
}
if (check_sni)
attack_sni = check_attack_sni(k, nb_internal, probes_r_curr, probes_a_curr, probes_b_curr);
attack_ni = check_attack_ni(k, probes_r_curr, probes_a_curr, probes_b_curr);
i = next_combination(comb, k);
if (i == 0) break;
to_del = (uint16_t) ((i >> 16) & 0xFFFF);
to_add = (uint16_t) (i & 0xFFFF);
// Adjust the number of internal probes
if (to_del < NB_PR - NB_SH) nb_internal--;
if (to_add < NB_PR - NB_SH) nb_internal++;
probes_sh_xor(probes_a_curr, probes_sh_a[to_del]);
probes_sh_xor(probes_a_curr, probes_sh_a[to_add]);
probes_sh_xor(probes_b_curr, probes_sh_b[to_del]);
probes_sh_xor(probes_b_curr, probes_sh_b[to_add]);
probes_r_xor(probes_r_curr, probes_r[to_del]);
probes_r_xor(probes_r_curr, probes_r[to_add]);
}
if (attack_ni || attack_sni) {
printf("\n");
print_combination(comb, k);
printf("to_del=%d\n", to_del);
printf("to_add=%d\n", to_add);
printf("\n------- UNSAFE -------\n");
if (attack_ni) printf("ATTACK NI FOUND\n");
if (attack_sni) printf("ATTACK SNI FOUND\n");
return 1;
}
printf("\rSets of probes already visited: %lu", c);
fflush(stdout);
}
printf("\n------- SAFE -------\n");
return 0;
}
#endif /* VECT */