-
Notifications
You must be signed in to change notification settings - Fork 3
/
data-init
executable file
·490 lines (439 loc) · 13.1 KB
/
data-init
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
#!/bin/sh
# supercop/data-init
# D. J. Bernstein
# Public domain.
. ./data-vars
if [ -d supercop-data ]
then
mkdir -p "$top"
else
if ln -s ../supercop-data supercop-data
then
mkdir -p ../supercop-data
else
mkdir -p supercop-data
fi
mkdir -p "$top"
fi
exec </dev/null
exec >"$top/log"
exec 2>&1
exec 6>"$top/$abi/todo"
echo "=== `date` === starting data-init"
echo "=== `date` === building machineinfo"
rm -rf "$top/machineinfo"
mkdir -p "$top/machineinfo"
cp -pR machineinfo/* "$top/machineinfo"
( cd "$top/machineinfo" && sh do )
echo "=== `date` === building scripts"
rm -rf "$top/scripts"
mkdir -p "$top/scripts"
cp -pR scripts/* "$top/scripts"
echo "=== `date` === building okcompilers"
rm -rf "$top/okcompilers"
mkdir -p "$top/okcompilers"
cp -pR okcompilers/* "$top/okcompilers"
( cd "$top/okcompilers" && sh do )
echo "=== `date` === building basic dependencies"
okabi \
| while read abi
do
mkdir -p "$top/$abi"
mkdir -p "$top/$abi/bin"
mkdir -p "$top/$abi/lib"
mkdir -p "$top/$abi/lib/timecop"
mkdir -p "$top/$abi/lib/nontimecop"
mkdir -p "$top/$abi/include/timecop"
mkdir -p "$top/$abi/include/nontimecop"
mkdir -p "$top/$abi/include/constbranchindex"
mkdir -p "$top/$abi/include/timingleaks"
mkdir -p "$top/$abi/security/constbranchindex"
mkdir -p "$top/$abi/security/timingleaks"
echo "=== `date` === cleaning up BUILD in $abi"
find "$top/$abi" -name BUILD | xargs rm -f
echo "=== `date` === cleaning up LOCKED in $abi"
find "$top/$abi" -name LOCKED | xargs rm -f
echo "=== `date` === cleaning up LOCK in $abi"
find "$top/$abi" -name LOCK | xargs rm -f
touch "$top/$abi/lib/LOCK"
mkdir -p "$top/$abi/base"
touch "$top/$abi/base/BUILD"
touch "$top/$abi/base/LOCK"
: > "$top/$abi/base/dep"
echo "$abi/base" >&6
mkdir -p "$top/$abi/cryptopp"
touch "$top/$abi/cryptopp/BUILD"
touch "$top/$abi/cryptopp/LOCK"
: > "$top/$abi/cryptopp/dep"
echo "$abi/cryptopp" >&6
mkdir -p "$top/$abi/openssl"
touch "$top/$abi/openssl/BUILD"
touch "$top/$abi/openssl/LOCK"
: > "$top/$abi/openssl/dep"
echo "$abi/openssl" >&6
mkdir -p "$top/$abi/cryptoint"
touch "$top/$abi/cryptoint/BUILD"
touch "$top/$abi/cryptoint/LOCK"
: > "$top/$abi/cryptoint/dep"
echo "$abi/cryptoint" >&6
mkdir -p "$top/$abi/gmp"
touch "$top/$abi/gmp/BUILD"
touch "$top/$abi/gmp/LOCK"
: > "$top/$abi/gmp/dep"
echo "$abi/gmp" >&6
mkdir -p "$top/$abi/ntl"
touch "$top/$abi/ntl/BUILD"
touch "$top/$abi/ntl/LOCK"
echo gmp > "$top/$abi/ntl/dep"
echo "$abi/ntl" >&6
mkdir -p "$top/$abi/keccak"
touch "$top/$abi/keccak/BUILD"
touch "$top/$abi/keccak/LOCK"
: > "$top/$abi/keccak/dep"
echo "$abi/keccak" >&6
done
echo "=== `date` === building killafter"
rm -rf "$top/killafter"
mkdir -p "$top/killafter"
cp -pR killafter/* "$top/killafter"
( cd "$top/killafter" && sh do )
echo "=== `date` === building compiledinfo"
rm -rf "$top/compiledinfo"
mkdir -p "$top/compiledinfo"
cp -pR compiledinfo/* "$top/compiledinfo"
( cd "$top/compiledinfo" && sh do )
echo "=== `date` === building sinceepoch"
rm -rf "$top/sinceepoch"
mkdir -p "$top/sinceepoch"
cp -pR sinceepoch/* "$top/sinceepoch"
( cd "$top/sinceepoch" && sh do )
echo "=== `date` === building checksum"
rm -rf "$top/checksum"
mkdir -p "$top/checksum"
cp -pR checksum/* "$top/checksum"
( cd "$top/checksum" && sh do )
echo "=== `date` === building baseinclude"
okabi \
| while read abi
do
cp -p include/* "$top/$abi/include/"
done
echo "=== `date` === building cpuid"
rm -rf "$top/cpuid"
mkdir -p "$top/cpuid"
cp -pR cpuid/* "$top/cpuid"
( cd "$top/cpuid" && sh do )
okabi \
| while read abi
do
cp -p "$top/cpuid/include"/* "$top/$abi/include/"
done
echo "=== `date` === building cryptoint"
rm -rf "$top/cryptoint"
mkdir -p "$top/cryptoint"
cp -pR cryptoint/* "$top/cryptoint"
( cd "$top/cryptoint" && sh do )
okabi \
| while read abi
do
cp -p "$top/cryptoint/include/$abi"/* "$top/$abi/include/"
# $top/cryptoint/lib/$abi/* is integrated later into libcryptoint
done
echo "=== `date` === building cpucycles"
rm -rf "$top/cpucycles"
mkdir -p "$top/cpucycles"
cp -pR cpucycles/* "$top/cpucycles"
( cd "$top/cpucycles" && sh do )
okabi \
| while read abi
do
cp -p "$top/cpucycles/include/$abi"/* "$top/$abi/include/nontimecop/"
cp -p "$top/cpucycles/lib/$abi"/* "$top/$abi/lib/nontimecop/"
done
echo "=== `date` === building cpucycles for TIMECOP"
rm -rf "$top/cpucycles"
mkdir -p "$top/cpucycles"
cp -pR cpucycles/* "$top/cpucycles"
( cd "$top/cpucycles" && env CPUCYCLESWRAPPER="killafter 300 valgrind" sh do )
okabi \
| while read abi
do
cp -p "$top/cpucycles/include/$abi"/* "$top/$abi/include/timecop/"
cp -p "$top/cpucycles/lib/$abi"/* "$top/$abi/lib/timecop/"
done
echo "=== `date` === building kernelrandombytes"
rm -rf "$top/kernelrandombytes"
mkdir -p "$top/kernelrandombytes"
cp -pR kernelrandombytes/* "$top/kernelrandombytes"
( cd "$top/kernelrandombytes" && sh do )
okabi \
| while read abi
do
cp -p "$top/kernelrandombytes/lib/$abi"/* "$top/$abi/lib/"
done
okabi \
| while read abi
do
for language in c cpp
do
ok${language}-$abi \
| while read compiler
do
compilerword=`echo "$compiler" | tr ' ' '_'`
echo "=== `date` === todo $abi/compiler/$language/$compilerword"
echo "$abi/compiler/$language/$compilerword" >&6
mkdir -p "$top/$abi/compiler/$language/$compilerword"
touch "$top/$abi/compiler/$language/$compilerword/BUILD"
touch "$top/$abi/compiler/$language/$compilerword/LOCK"
: > "$top/$abi/compiler/$language/$compilerword/dep"
done
done
done
cat OPERATIONS \
| while read o
do
[ -d "$o" ] || continue
[ -k "$o" ] 2>&1 && continue
ls "$o" \
| sort \
| while read p
do
[ -d "$o/$p" ] || continue
[ -k "$o/$p" ] 2>&1 && continue
okabi \
| while read abi
do
find "$o/$p" -follow -name "api.h" \
| sort \
| while read doth
do
implementationdir=`dirname $doth`
opi=`echo "$implementationdir" | tr ./- !!!`
[ -k "$implementationdir" ] 2>&1 && continue
if [ -f "$implementationdir/architectures" ]
then
if grep '^'"$abi"'$' "$implementationdir/architectures" >/dev/null
then
:
else
echo "=== `date` === skipping $abi/implementation/$implementationdir"
continue
fi
fi
echo "=== `date` === todo $abi/implementation/$implementationdir"
echo "$abi/implementation/$implementationdir" >&6
mkdir -p "$top/$abi/implementation/$implementationdir"
touch "$top/$abi/implementation/$implementationdir/BUILD"
touch "$top/$abi/implementation/$implementationdir/LOCK"
(
cat "$o/try.c"
cat "$o/measure.c"
# cat "try-anything.c" # gives false positives for cryptoint
cat "measure-anything.c"
find "$implementationdir" -follow -type f \
| grep -E '\.h$|\.c$|\.s$|\.S$|\.cc$|\.cpp$' \
| xargs cat
) \
| grep '#include' \
| sed 's/#include[ ]*//' \
| sed 's_/.*/__' \
| sed 's_//.*__' \
| tr -d '<>"\040\011\014' \
| sed 's_\.h$__' \
| sort -u \
| while read incl
do
case "$incl" in
openssl*)
echo openssl
;;
cryptopp*)
echo cryptopp
;;
gmp*)
echo gmp
;;
NTL*)
echo gmp
echo ntl
;;
libkeccak.a.headers/*)
echo keccak
;;
crypto_asm_hidden)
;;
crypto_int*|crypto_uint*)
echo cryptoint
;;
crypto_*_*)
op=`echo "$incl" | sed 's/_\(.*\)_/_\1\//'`
if [ -d "$top/$abi/integrate/$op" ]
then
echo "integrate/$op"
fi
;;
esac
done | sort -u > "$top/$abi/implementation/$implementationdir/dep"
userandombytes=0
[ $o = crypto_scalarmult ] && userandombytes=1
[ $o = crypto_box ] && userandombytes=1
[ $o = crypto_dh ] && userandombytes=1
[ $o = crypto_encrypt ] && userandombytes=1
[ $o = crypto_kem ] && userandombytes=1
[ $o = crypto_sign ] && userandombytes=1
if [ $userandombytes = 1 ]
then
echo "knownrandombytes" >> "$top/$abi/implementation/$implementationdir/dep"
echo "fastrandombytes" >> "$top/$abi/implementation/$implementationdir/dep"
fi
(
if [ -f "$implementationdir/goal-constbranch" ]
then
if [ -f "$implementationdir/goal-constindex" ]
then
echo constbranchindex
fi
fi
echo timingleaks
) | while read security
do
echo "=== `date` === todo $abi/try/.../$security/$implementationdir"
opi=`echo "$implementationdir" | tr ./- !!!`
cfiles=`ls "$implementationdir" | grep '\.c$' || :`
sfiles=`ls "$implementationdir" | grep '\.[sS]$' || :`
ccfiles=`ls "$implementationdir" | grep '\.cc$' || :`
cppfiles=`ls "$implementationdir" | grep '\.cpp$' || :`
language=c
[ "x$cppfiles" = x ] || language=cpp
[ "x$ccfiles" = x ] || language=cpp
ok${language}-$abi \
| while read compiler
do
compilerword=`echo "$compiler" | tr ' ' '_'`
mkdir -p "$top/$abi/try/$language/$compilerword/$security/$implementationdir"
touch "$top/$abi/try/$language/$compilerword/$security/$implementationdir/BUILD"
touch "$top/$abi/try/$language/$compilerword/$security/$implementationdir/LOCK"
(
echo "compiler/$language/$compilerword"
echo "implementation/$implementationdir"
) > "$top/$abi/try/$language/$compilerword/$security/$implementationdir/dep"
echo "$abi/try/$language/$compilerword/$security/$implementationdir" >&6
done
done
done
done
okabi \
| while read abi
do
echo "=== `date` === todo $abi/integrate/$o/$p"
echo "$abi/integrate/$o/$p" >&6
mkdir -p "$top/$abi/integrate/$o/$p"
touch "$top/$abi/integrate/$o/$p/BUILD"
touch "$top/$abi/integrate/$o/$p/LOCK"
(
echo base
find "$o/$p" -follow -name "api.h" \
| sort \
| while read doth
do
implementationdir=`dirname $doth`
[ -f "$implementationdir/Cargo.toml" ] && continue
for language in c
do
ok${language}-$abi \
| while read compiler
do
compilerword=`echo "$compiler" | tr ' ' '_'`
for security in constbranchindex timingleaks
do
source="try/$language/$compilerword/$security/$implementationdir"
if [ -d "$top/$abi/$source" ]
then
echo "$source"
fi
done
done
done
done
) > "$top/$abi/integrate/$o/$p/dep"
done
done
if [ $o = crypto_rng ]
then
okabi \
| while read abi
do
echo "=== `date` === todo $abi/knownrandombytes"
echo $abi/knownrandombytes >&6
mkdir -p "$top/$abi/knownrandombytes"
touch "$top/$abi/knownrandombytes/BUILD"
touch "$top/$abi/knownrandombytes/LOCK"
ls $o \
| sort \
| while read p
do
[ -d "$o/$p" ] || continue
echo integrate/$o/$p
done > "$top/$abi/knownrandombytes/dep"
echo "=== `date` === todo $abi/fastrandombytes"
echo $abi/fastrandombytes >&6
mkdir -p "$top/$abi/fastrandombytes"
touch "$top/$abi/fastrandombytes/BUILD"
touch "$top/$abi/fastrandombytes/LOCK"
ls $o \
| sort \
| while read p
do
[ -d "$o/$p" ] || continue
echo integrate/$o/$p
done > "$top/$abi/fastrandombytes/dep"
done
fi
done
cat OPERATIONS \
| while read o
do
[ -d "$o" ] || continue
for m in 1 2 3
do
ls "$o" \
| sort \
| while read p
do
[ -d "$o" ] || continue
okabi \
| while read abi
do
[ -d "$o/$p" ] || continue
echo "=== `date` === todo $abi/measure$m/$o/$p"
echo "$abi/measure$m/$o/$p" >&6
mkdir -p "$top/$abi/measure$m/$o/$p"
touch "$top/$abi/measure$m/$o/$p/BUILD"
touch "$top/$abi/measure$m/$o/$p/LOCK"
find "$o/$p" -follow -name "api.h" \
| sort \
| while read doth
do
implementationdir=`dirname $doth`
for language in c cpp
do
ok${language}-$abi \
| while read compiler
do
compilerword=`echo "$compiler" | tr ' ' '_'`
for security in constbranchindex timingleaks
do
source="try/$language/$compilerword/$security/$implementationdir"
if [ -d "$top/$abi/$source" ]
then
echo "$source"
fi
done
done
done
done > "$top/$abi/measure$m/$o/$p/dep"
done
done
done
done
echo "=== `date` === ending data-init"