-
Notifications
You must be signed in to change notification settings - Fork 8
/
configure.ac
508 lines (473 loc) · 13.9 KB
/
configure.ac
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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
AC_INIT(myconfig, version-0.1)
main_dir="./"
table_dir="./src/table"
vperm_dir="./src/vperm"
bitslice_dir="./src/bitslice"
AC_CONFIG_FILES([$main_dir/Makefile])
AC_DEFUN(CHECK_OPTION,[
if test "$1" != "yes"; then
if test "$1" != "no"; then
if test "$1" != "default"; then
AC_MSG_ERROR([value $1 is not a proper value for option $2 (use "yes", "no" or "default")])
fi
fi
fi
])
## Default values
w_led="default"
w_present="default"
w_piccolo="default"
w_led64="default"
w_present80="default"
w_piccolo80="default"
w_led128="default"
w_present128="default"
w_piccolo128="default"
w_table="default"
w_vperm="default"
w_bitslice="default"
w_ssse="default"
w_avx="default"
w_threadsafe="default"
w_arch32="default"
w_arch64="default"
curr_arch=""
AC_ARG_WITH(led, [ --with-led LED cipher], w_led="$withval")
AC_ARG_WITH(led64, [ --with-led64 LED cipher/64-bit key variant], w_led64="$withval")
AC_ARG_WITH(led128, [ --with-led128 LED cipher/128-bit key variant], w_led128="$withval")
AC_ARG_WITH(present, [ --with-present PRESENT cipher], w_present="$withval")
AC_ARG_WITH(present80, [ --with-present80 PRESENT cipher/80-bit key variant], w_present80="$withval")
AC_ARG_WITH(present128, [ --with-present128 PRESENT cipher/128-bit key variant], w_present128="$withval")
AC_ARG_WITH(piccolo, [ --with-piccolo Piccolo cipher], w_piccolo="$withval")
AC_ARG_WITH(piccolo80, [ --with-piccolo80 Piccolo cipher/80-bit key variant], w_piccolo80="$withval")
AC_ARG_WITH(piccolo128, [ --with-piccolo128 Piccolo cipher/128-bit key variant], w_piccolo128="$withval")
AC_ARG_WITH(table, [ --with-table Table implementations], w_table="$withval")
AC_ARG_WITH(vperm, [ --with-vperm Vperm implementations], w_vperm="$withval")
AC_ARG_WITH(bitslice, [ --with-bitslice Bitslice implementations], w_bitslice="$withval")
AC_ARG_WITH(ssse, [ --with-ssse SSSE implementations], w_ssse="$withval")
AC_ARG_WITH(avx, [ --with-avx AVX implementations], w_avx="$withval")
AC_ARG_WITH(threadsafe, [ --with-threadsafe Thread safe library (link with pthread)], w_threadsafe="$withval")
AC_ARG_WITH(arch32, [ --with-arch32 Force 32-bit compilation], w_arch32="$withval")
AC_ARG_WITH(arch64, [ --with-arch64 Force 64-bit compilation], w_arch64="$withval")
CHECK_OPTION($w_led, "--with-led")
CHECK_OPTION($w_led64, "--with-led64")
CHECK_OPTION($w_led128, "--with-led128")
CHECK_OPTION($w_present, "--with-present")
CHECK_OPTION($w_present80, "--with-present80")
CHECK_OPTION($w_present128, "--with-present128")
CHECK_OPTION($w_piccolo, "--with-piccolo")
CHECK_OPTION($w_piccolo80, "--with-piccolo80")
CHECK_OPTION($w_piccolo128, "--with-piccolo128")
CHECK_OPTION($w_table, "--with-table")
CHECK_OPTION($w_vperm, "--with-vperm")
CHECK_OPTION($w_bitslice, "--with-bitslice")
CHECK_OPTION($w_ssse, "--with-ssse")
CHECK_OPTION($w_avx, "--with-avx")
CHECK_OPTION($w_threadsafe, "--with-threadsafe")
CHECK_OPTION($w_arch32, "--with-arch32")
CHECK_OPTION($w_arch64, "--with-arch64")
if test "$w_arch32" == "yes"; then
if test "$w_arch64" == "yes"; then
AC_MSG_ERROR([--with-arch32 and --with-arch64 cannot be set to "yes" together!])
fi
if test "$w_vperm" == "yes"; then
AC_MSG_ERROR([--with-arch32 and --with-vperm cannot be set to "yes" together! (vperm code is in x86_64 assembly)])
fi
fi
if test "$w_arch32" == "no"; then
if test "$w_arch64" == "no"; then
AC_MSG_ERROR([--with-arch32 and --with-arch64 cannot be set to "no" together!])
fi
fi
# Summary helpers
AC_DEFUN(WRITE_TO_FILE,[
printf "%-40s: %s\n" $2 $3 >> $1
])
AC_DEFUN(SHOW_SUMMARY,[
cat $1 && rm -f $1
])
# Remove any existing summary file
rm -f ./summary
echo "###########################################" >> ./summary
echo "### SUMMARY ###" >> ./summary
echo "###########################################" >> ./summary
##########
# CHECK Make
case $host_type in
*freebsd*)
AC_CHECK_PROG(MAKEPROG,gmake,gmake,no)
if test "$MAKEPROG" == "no"
then
AC_MSG_ERROR(Cannot find GNU gmake.)
fi
AC_SUBST(MAKEPROG,$MAKEPROG)
;;
*)
AC_CHECK_PROG(MAKEPROG,make,make,no)
if test "$MAKEPROG" == "no"
then
AC_MSG_ERROR(Cannot find GNU make.)
fi
AC_SUBST(MAKEPROG,$MAKEPROG)
;;
esac
AC_PROG_CC(gcc cc)
######### INTERNAL OPTIONS ###########
#########
summary=""
####### CHECKING CPU CAPABILITIES
##################################################################
# Check for CPU arch
AC_DEFUN(CHECK_CPU_ARCH,[
C_FILE="./check_cpu_arch.c"
FILE="./check_cpu_arch"
rm -f $C_FILE $FILE
cat <<EOM >$C_FILE
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]){
#ifdef __i386__
return 1;
#endif
#ifdef __x86_64__
return 2;
#endif
return (sizeof(void*));
}
EOM
$CC $C_FILE -o $FILE &> /dev/null
OUT=$?
if [[ "$OUT" != "0" ]]; then
AC_MSG_ERROR([problem when compiling $C_FILE])
fi
# Check for output value
$FILE
OUT=$?
if [[ "$OUT" == "1" ]]; then
echo "### Detected CPU: x86 32-bit ###" >> ./summary
AC_MSG_NOTICE([---> Your CPU is in 32-bit mode])
if test "$w_vperm" == "default"; then
w_vperm="no"
fi
curr_arch="32-bit"
fi
if [[ "$OUT" == "2" ]]; then
echo "### Detected CPU: x86 64-bit ###" >> ./summary
AC_MSG_NOTICE([---> Your CPU is in 64-bit mode])
curr_arch="64-bit"
fi
if [[ "$OUT" == "4" ]]; then
echo "### Detected CPU: no x86 (32-bit) ###" >> ./summary
AC_MSG_NOTICE([---> Your CPU has a non x86 architecture])
if test "$w_vperm" == "default"; then
w_vperm="no"
fi
if test "$w_bitslice" == "default"; then
w_bitslice="no"
fi
curr_arch="32-bit"
fi
if [[ "$OUT" == "8" ]]; then
echo "### Detected CPU: no x86 (64-bit) ###" >> ./summary
AC_MSG_NOTICE([---> Your CPU has a non x86 architecture])
if test "$w_vperm" == "default"; then
w_vperm="no"
fi
if test "$w_bitslice" == "default"; then
w_bitslice="no"
fi
curr_arch="64-bit"
fi
if [[ "$curr_arch" == "" ]]; then
AC_MSG_ERROR([problem when detecting CPU architecture: unknown architecture!])
fi
# Job done: remove unnecessary files
rm -f $C_FILE $FILE
])
##################################################################
# Check for CPU features
AC_DEFUN(CHECK_CPU_FEATURES,[
C_FILE="./check_cpu_features.c"
FILE="./check_cpu_features"
rm -f $C_FILE $FILE
cat <<EOM >$C_FILE
#include <stdio.h>
#include <stdlib.h>
#include "common/helpers.h"
int main(int argc, char* argv[]){
return 0;
}
EOM
$CC -DBITSLICE -DVPERM -DAVX $C_FILE -I $main_dir/src -o $FILE &> /dev/null
OUT=$?
if [[ "$OUT" != "0" ]]; then
AC_MSG_ERROR([problem when compiling $C_FILE])
fi
# Check for output value
$FILE
OUT=$?
if [[ "$OUT" == "2" ]]; then
echo "### Detected CPU: no SSSE3 ###" >> ./summary
echo "###########################################" >> ./summary
AC_MSG_NOTICE([---> Your CPU does not support SSSE3])
w_avx="no"
w_ssse="no"
if test "$w_vperm" == "default"; then
w_vperm="no"
fi
if test "$w_bitslice" == "default"; then
w_bitslice="no"
fi
fi
if [[ "$OUT" == "3" ]]; then
echo "### Detected CPU: SSSE3, no AVX ###" >> ./summary
echo "###########################################" >> ./summary
AC_MSG_NOTICE([---> Your CPU supports SSSE3 but not AVX])
w_avx="no"
fi
if [[ "$OUT" == "0" ]]; then
echo "### Detected CPU: SSSE3 and AVX ###" >> ./summary
echo "###########################################" >> ./summary
AC_MSG_NOTICE([---> Your CPU supports both SSSE3 and AVX])
fi
# Job done: remove unnecessary files
rm -f $C_FILE $FILE
])
#### Check for CPU architecture and features (instruction set)
CHECK_CPU_ARCH()
CHECK_CPU_FEATURES()
# If we force arch32, we force vperm to be desactivated
if test "$w_arch32" == "yes"; then
w_vperm="no"
w_avx="no"
fi
# table handling
if test "$w_table" != "no"; then
AC_MSG_NOTICE([Using table based functions])
WRITE_TO_FILE(summary, "table", "YES")
AC_SUBST(table_define, "-DTABLE")
else
WRITE_TO_FILE(summary, "table", "NO")
AC_SUBST(table_define, "")
fi
# vperm handling
if test "$w_vperm" != "no"; then
AC_MSG_NOTICE([Using vperm functions])
WRITE_TO_FILE(summary, "vperm", "YES")
AC_SUBST(vperm_define, "-DVPERM")
else
WRITE_TO_FILE(summary, "vperm", "NO")
AC_SUBST(vperm_define, "")
fi
# bitslice handling
if test "$w_bitslice" != "no"; then
AC_MSG_NOTICE([Using bitslice functions])
WRITE_TO_FILE(summary, "bitslice", "YES")
AC_SUBST(bitslice_define, "-DBITSLICE")
else
WRITE_TO_FILE(summary, "bitslice", "NO")
fi
# led handling
led64_log=""
led128_log=""
if test "$w_led64" != "no"; then
if test "$w_led" != "no"; then
led64_log="1"
WRITE_TO_FILE(summary, "LED64", "YES")
AC_SUBST(led64_define, "-DLED64")
else
led64_log="1"
WRITE_TO_FILE(summary, "LED64", "NO")
AC_SUBST(led64_define, "")
fi
else
led64_log="1"
WRITE_TO_FILE(summary, "LED64", "NO")
AC_SUBST(led64_define, "")
fi
if test "$w_led128" != "no"; then
if test "$w_led" != "no"; then
led128_log="1"
WRITE_TO_FILE(summary, "LED128", "YES")
AC_SUBST(led128_define, "-DLED128")
else
led128_log="1"
WRITE_TO_FILE(summary, "LED128", "NO")
AC_SUBST(led128_define, "")
fi
else
led128_log="1"
WRITE_TO_FILE(summary, "LED128", "NO")
AC_SUBST(led128_define, "")
fi
if test "$w_led" != "no"; then
if test "$led64_log" == ""; then
WRITE_TO_FILE(summary, "LED64", "YES")
AC_SUBST(led64_define, "-DLED64")
fi
if test "$led128_log" == ""; then
WRITE_TO_FILE(summary, "LED128", "YES")
AC_SUBST(led128_define, "-DLED128")
fi
else
if test "$led64_log" == ""; then
WRITE_TO_FILE(summary, "LED64", "NO")
AC_SUBST(led64_define, "")
fi
if test "$led128_log" == ""; then
WRITE_TO_FILE(summary, "LED128", "NO")
AC_SUBST(led128_define, "")
fi
fi
# present handling
present80_log=""
present128_log=""
if test "$w_present80" != "no"; then
if test "$w_present" != "no"; then
present80_log="1"
WRITE_TO_FILE(summary, "PRESENT80", "YES")
AC_SUBST(present80_define, "-DPRESENT80")
else
present80_log="1"
WRITE_TO_FILE(summary, "PRESENT80", "NO")
AC_SUBST(present80_define, "")
fi
else
present80_log="1"
WRITE_TO_FILE(summary, "PRESENT80", "NO")
AC_SUBST(present80_define, "")
fi
if test "$w_present128" != "no"; then
if test "$w_present" != "no"; then
present128_log="1"
WRITE_TO_FILE(summary, "PRESENT128", "YES")
AC_SUBST(present128_define, "-DPRESENT128")
else
present128_log="1"
WRITE_TO_FILE(summary, "PRESENT128", "NO")
AC_SUBST(present128_define, "")
fi
else
present128_log="1"
WRITE_TO_FILE(summary, "PRESENT128", "NO")
AC_SUBST(present128_define, "")
fi
if test "$w_present" != "no"; then
if test "$present80_log" == ""; then
WRITE_TO_FILE(summary, "PRESENT80", "YES")
AC_SUBST(present80_define, "-DPRESENT80")
fi
if test "$present128_log" == ""; then
WRITE_TO_FILE(summary, "PRESENT128", "YES")
AC_SUBST(present128_define, "-DPRESENT128")
fi
else
if test "$present80_log" == ""; then
WRITE_TO_FILE(summary, "PRESENT80", "NO")
AC_SUBST(present80_define, "")
fi
if test "$present128_log" == ""; then
WRITE_TO_FILE(summary, "PRESENT128", "NO")
AC_SUBST(present128_define, "")
fi
fi
# piccolo handling
piccolo80_log=""
piccolo128_log=""
if test "$w_piccolo80" != "no"; then
if test "$w_piccolo" != "no"; then
piccolo80_log="1"
WRITE_TO_FILE(summary, "Piccolo80", "YES")
AC_SUBST(piccolo80_define, "-DPiccolo80")
else
piccolo80_log="1"
WRITE_TO_FILE(summary, "Piccolo80", "NO")
AC_SUBST(piccolo80_define, "")
fi
else
piccolo80_log="1"
WRITE_TO_FILE(summary, "Piccolo80", "NO")
AC_SUBST(piccolo80_define, "")
fi
if test "$w_piccolo128" != "no"; then
if test "$w_piccolo" != "no"; then
piccolo128_log="1"
WRITE_TO_FILE(summary, "Piccolo128", "YES")
AC_SUBST(piccolo128_define, "-DPiccolo128")
else
piccolo128_log="1"
WRITE_TO_FILE(summary, "Piccolo128", "NO")
AC_SUBST(piccolo128_define, "")
fi
else
piccolo128_log="1"
WRITE_TO_FILE(summary, "Piccolo128", "NO")
AC_SUBST(piccolo128_define, "")
fi
if test "$w_piccolo" != "no"; then
if test "$piccolo80_log" == ""; then
WRITE_TO_FILE(summary, "Piccolo80", "YES")
AC_SUBST(piccolo80_define, "-DPiccolo80")
fi
if test "$piccolo128_log" == ""; then
WRITE_TO_FILE(summary, "Piccolo128", "YES")
AC_SUBST(piccolo128_define, "-DPiccolo128")
fi
else
if test "$piccolo80_log" == ""; then
WRITE_TO_FILE(summary, "Piccolo80", "NO")
AC_SUBST(piccolo80_define, "")
fi
if test "$piccolo128_log" == ""; then
WRITE_TO_FILE(summary, "Piccolo128", "NO")
AC_SUBST(piccolo128_define, "")
fi
fi
# ssse handling
if test "$w_ssse" != "no"; then
WRITE_TO_FILE(summary, "Using SSSE", "YES")
AC_SUBST(ssse_link, "-mssse3")
else
WRITE_TO_FILE(summary, "Using SSSE", "NO")
AC_SUBST(ssse_link, "")
fi
# avx handling
if test "$w_avx" != "no"; then
WRITE_TO_FILE(summary, "Using AVX", "YES")
AC_SUBST(avx_define, "-DAVX")
else
WRITE_TO_FILE(summary, "Using AVX", "NO")
AC_SUBST(avx_define, "")
fi
# threadsafe handling
if test "$w_threadsafe" != "no"; then
WRITE_TO_FILE(summary, "Using thread-safe functions", "YES")
AC_SUBST(threadsafe_define, "-DTHREAD_SAFE")
AC_SUBST(threadsafe_link, "-lpthread")
else
WRITE_TO_FILE(summary, "Using thread-safe functions", "NO")
AC_SUBST(threadsafe_define, "")
AC_SUBST(threadsafe_link, "")
fi
# arch32 handling
if test "$w_arch32" == "yes"; then
WRITE_TO_FILE(summary, "Compiling for architecture (forced)", "32-bit")
AC_SUBST(arch32_opt, "-m32")
else
AC_SUBST(arch32_opt, "")
fi
# arch64 handling
if test "$w_arch64" == "yes"; then
WRITE_TO_FILE(summary, "Compiling for architecture (forced)", "64-bit")
AC_SUBST(arch64_opt, "-m64")
else
AC_SUBST(arch64_opt, "")
fi
# Default arch
if test "$w_arch32" == "default"; then
if test "$w_arch64" == "default"; then
WRITE_TO_FILE(summary, "Compiling for architecture (detected)", "$curr_arch")
fi
fi
AC_OUTPUT(Makefile)
SHOW_SUMMARY([summary])