-
Notifications
You must be signed in to change notification settings - Fork 0
/
cttime
232 lines (130 loc) · 3.77 KB
/
cttime
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
Constant-time programming
Pascal Cuoq
TrustInSoft
+
First, an exercise.
Go to:
https://github.com/pascal-cuoq/…
constant-time-exercises
or type:
git clone https://github.com/pascal-cuoq/…
constant-time-exercises.git
Then crack password.Linux
(or password.OSX if using OS X)
Question: what about modern password systems?
“Do not implement your own crypto”
Applied Cryptography, Udacity, David Evans
Lesson 1, slide 3
“Constant-time programming”
“Timing Attacks on …”, Paul Kocher (1996)
“Remote Timing Attacks are Practical”,
David Brumley & Dan Boneh (2003)
“constant-time” = execution time independent of
secret inputs
In the beginning was ctgrind (2010)
Analysis more promising than empirical approach
Taking advantage of Valgrind:
Poison secrets
Detect use as adresses or in conditional jumps
Unexpectedly general for dynamic analysis:
“Execution time does not depend on secrets”
⇒ “For all values of the secrets, …”
No such argument for public inputs
In academia:
A prototype in Frama-C (pathdeps & memdeps)
implemented shortly after ctgrind
advertized in 2011 blog post
CacheAudit: A Tool for the Static Analysis of
Cache Side Channels (2013)
System-level non-interference
for constant-time cryptography (2014)
“Pathdeps” and “memdeps” Frama-C options
Compute dependencies of all “if(e)” and “*p”
Verifying “constant-time” at the C level
We assume a C compiler that makes this possible
Example:
double g(int64_t x, uint32_t y, uint64_t z) {
double d = x;
double e = y;
double f = z;
return d+e+f;
}
“Pathdeps” and “memdeps” Frama-C options
Similar to ctgrind in that no proof is provided
(formal or informal)
But a tool is provided
Limitations of original implementation
(fixed in recent work)
- used values memorized for all calls
- assertions
- quality of messages
Ex-limitation 1:
Usage of values memorized by function
int a, b, c;
void f(int *p) {
a = *p;
}
int main(void) {
f(&b);
f(&c);
if (a) …
}
Ex-limitation 2:
Assertions
void BN_consttime_swap(BN_ULONG condition,
BIGNUM *a, BIGNUM *b, int nwords)
{
…
assert((condition & (condition - 1)) == 0);
…
condition =
((condition - 1) >> (BN_BITS2 - 1)) - 1;
t = (a->top ^ b->top) & condition;
a->top ^= t;
b->top ^= t;
…
Ex-limitation 3:
Quality of messages
Before:
The execution path of f() depends on the input x
After:
The execution path of f() depends on the input x
because of the condition at file.c:42
“Pathdeps” and “memdeps” Frama-C options
Remaining issue: precomputed tables
Example: m-ary method for exponentiation aⁿ
Improvement over exponentiation by squaring:
n = 100 000 110
Table of small powers of a up to a^7
Precomputed tables
Inefficient but obviously constant-time:
bigint tbl[8];
…
bigint access_tbl(int n) {
bigint result = 0;
for (int i = 0; i<8; i++)
result = result | (tbl[i] & (-(i == n)));
return result;
}
Precomputed tables
Actual implementations: bit-slicing
#define S …
bigint_slice tbl[8][S];
…
bigint access_tbl(int n) {
bigint result = 0;
for (int i = 0; i<S; i++)
result = result | (tbl[n][i] << …);
return result;
}
Except!
The execution time of a/b also depends on a and b
“Compiler Mitigations for Time Attacks
on Modern x86 Processors”
Also protocols
Counter-measures against padding oracle attacks
(Vaudenay) in PolarSSL
Conclusion
“We believe it is harder to create and maintain
code where the decryption time is not dependent
upon the ciphertext.” (Brumley & Boneh 2003)