forked from IAIK/Picnic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
666 lines (559 loc) · 23.9 KB
/
CMakeLists.txt
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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
# cmake setup
# honor visibility properties
cmake_policy(SET CMP0063 NEW)
# enforce IPO if enabled
cmake_policy(SET CMP0069 NEW)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# project info
set(PICNIC_MAJOR_VERSION 3)
set(PICNIC_MINOR_VERSION 0)
set(PICNIC_PATCH_VERSION 18)
set(PICNIC_VERSION ${PICNIC_MAJOR_VERSION}.${PICNIC_MINOR_VERSION}.${PICNIC_PATCH_VERSION})
project(picnic LANGUAGES C CXX VERSION ${PICNIC_VERSION})
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build." FORCE)
endif()
# set required C standard version
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
# set required C++ standard version
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# cmake checks and tools
include(GNUInstallDirs)
include(CheckSIMD)
include(CheckFunctionExists)
include(CheckCCompilerFlag)
include(CheckIncludeFiles)
include(CheckSymbolExists)
include(CheckTypeSize)
function(check_c_compiler_flag_and_add flag result)
check_c_compiler_flag("${flag}" ${result})
if(${result})
add_compile_options("${flag}")
endif()
endfunction()
# check libraries
find_package(m4ri 20140914)
find_package(valgrind)
find_package(Boost 1.65 OPTIONAL_COMPONENTS unit_test_framework program_options)
if(APPLE)
find_path(SECRUTY_INCLUDE_DIR Security/Security.h)
find_library(SECURITY_LIBRARY Security)
mark_as_advanced(SECURITY_INCLUDE_DIR SECURITY_LIBRARY)
set(HAVE_SECURITY_FRAMEWORK TRUE)
endif()
# check programs
find_program(SED sed)
# check headers
check_include_files(sys/auxv.h HAVE_SYS_AUXV_H)
check_include_files(asm/hwcap.h HAVE_ASM_HWCAP_H)
check_include_files(sys/random.h HAVE_SYS_RANDOM_H)
# check availability of some functions
check_symbol_exists(aligned_alloc stdlib.h HAVE_ALIGNED_ALLOC)
check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
check_symbol_exists(memalign malloc.h HAVE_MEMALIGN)
check_symbol_exists(getrandom sys/random.h HAVE_GETRANDOM)
check_symbol_exists(arc4random_buf stdlib.h HAVE_ARC4RANDOM_BUF)
check_symbol_exists(getline stdio.h HAVE_GETLINE)
check_symbol_exists(explicit_bzero string.h HAVE_EXPLICIT_BZERO)
check_symbol_exists(consttime_memequal string.h HAVE_CONSTTIME_MEMEQUAL)
check_symbol_exists(timingsafe_bcmp string.h HAVE_TIMINGSAFE_BCMP)
# check supported types
check_type_size(ssize_t SSIZE_T LANGUAGE C)
# check supported compiler flags
check_c_compiler_flag(-march=native CC_SUPPORTS_MARCH_NATIVE)
check_c_compiler_flag(-mtune=native CC_SUPPORTS_MTUNE_NATIVE)
check_c_compiler_flag(-O3 CC_SUPPORTS_O3)
check_c_compiler_flag(-fomit-frame-pointer CC_SUPPORTS_FOMIT_FRAME_POINTER)
check_c_compiler_flag_and_add(-Wall CC_SUPPORTS_WALL)
check_c_compiler_flag_and_add(-Wextra CC_SUPPORTS_WEXTRA)
check_c_compiler_flag_and_add(-Wshadow CC_SUPPORTS_WSHADOW)
check_c_compiler_flag_and_add(-Werror=vla CC_SUPPORTS_WERROR_VLA)
# check SIMD instructions set
check_simd(SSE2 CC_SUPPORTS_SSE2)
check_simd(AVX2 CC_SUPPORTS_AVX2)
check_simd(BMI2 CC_SUPPORTS_BMI2)
check_simd(NEON CC_SUPPORTS_NEON)
# user-settable options
if(APPLE AND ${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
# workaround for broken -march=native support on some versions of GCC on OS X.
set(DEFAULT_WITH_MARCH_NATIVE OFF)
else()
set(DEFAULT_WITH_MARCH_NATIVE ON)
endif()
set(DEFAULT_SHA3_IMPL "opt64")
if(NOT DEFINED CMAKE_SIZEOF_VOID_P)
message(WARNING "Unable to set default SHA3 implementation based on the platform since CMAKE_SIZEOF_VOID_P is not defined.")
else()
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(DEFAULT_SHA3_IMPL "plain32")
endif()
endif()
set(WITH_ZKBPP ON CACHE BOOL "Enable Picnic instances based on ZKB++.")
set(WITH_KKW ON CACHE BOOL "Enable Picnic instances based on KKW.")
set(WITH_UNRUH ON CACHE BOOL "Enable Picnic instances based on ZKB++ and Unruh.")
if(NOT WITH_ZKBPP AND NOT WITH_KKW)
message(FATAL_ERROR "At least one of WITH_ZKBPP and WITH_KKW is required.")
endif()
if(NOT WITH_ZKBPP AND WITH_UNRUH)
message(STATUS "WITH_ZKBPP is required for WITH_UNRUH, so assuming WITH_UNRUH=OFF.")
endif()
set(WITH_LOWMC_128_128_20 ON CACHE BOOL "Enable LowMC instance 128-128-20.")
set(WITH_LOWMC_192_192_30 ON CACHE BOOL "Enable LowMC instance 192-192-30.")
set(WITH_LOWMC_256_256_38 ON CACHE BOOL "Enable LowMC instance 256-256-38.")
set(WITH_LOWMC_129_129_4 ON CACHE BOOL "Enable LowMC instance 129-129-4.")
set(WITH_LOWMC_192_192_4 ON CACHE BOOL "Enable LowMC instance 192-192-4.")
set(WITH_LOWMC_255_255_4 ON CACHE BOOL "Enable LowMC instance 255-255-4.")
if(WITH_KKW AND NOT WITH_LOWMC_129_129_4 AND NOT WITH_LOWMC_192_192_4 AND NOT WITH_LOWMC_255_255_4)
message(FATAL_ERROR "At least one of WITH_LOWMC_129_129_4, WITH_LOWMC_192_192_4, and WITH_LOWMC_255_255_4 is required for WITH_KKW.")
endif()
if(NOT WITH_LOWMC_128_128_20 AND NOT WITH_LOWMC_192_192_30 AND NOT WITH_LOWMC_256_256_38 AND NOT WITH_LOWMC_129_129_4 AND NOT WITH_LOWMC_192_192_4 AND NOT WITH_LOWMC_255_255_4)
message(FATAL_ERROR "At least one of the LowMC parameters is required.")
endif()
set(WITH_SIMD_OPT ON CACHE BOOL "Enable optimizations via SIMD.")
set(WITH_AVX2 ON CACHE BOOL "Use AVX2 and BMI2 if available.")
set(WITH_SSE2 ON CACHE BOOL "Use SSE2 if available.")
set(WITH_NEON ON CACHE BOOL "Use NEON if available.")
set(WITH_MARCH_NATIVE ${DEFAULT_WITH_MARCH_NATIVE} CACHE BOOL "Build with -march=native -mtune=native (if supported).")
set(WITH_LTO ON CACHE BOOL "Enable link-time optimization (if supported).")
set(WITH_SHA3_IMPL ${DEFAULT_SHA3_IMPL} CACHE STRING "Select SHA3 implementation.")
set_property(CACHE WITH_SHA3_IMPL PROPERTY STRINGS "opt64" "plain32" "avx2" "armv8a-neon" "s390-cpacf")
set(WITH_EXTRA_RANDOMNESS OFF CACHE BOOL "Feed extra random bytes to KDF (fault attack counter measure).")
set(WITH_CONFIG_H ON CACHE BOOL "Generate config.h. Disabling this option is discouraged. It is only available to test builds produced for SUPERCOP.")
if(MSVC)
set(USE_STATIC_RUNTIME OFF CACHE BOOL "Use MSVC's static runtime for the static library.")
endif()
set(WITH_EXTENDED_TESTS ON CACHE BOOL "Run extended tests.")
set(WITH_KATS_TESTS ON CACHE BOOL "Run known-answer tests.")
set(WITH_VALGRIND_CT_TESTS OFF CACHE BOOL "Build crypto_api tests with constant-time checks. Enabling this option is discouraged. It is only available to test builds for SUPERCOP/TIMECOP.")
# do not build with -rdynamic
string(REGEX REPLACE "-rdynamic" "" CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS}")
string(REGEX REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_C_FLAGS
"${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS}")
# disable some warnings on MSVC
if(MSVC)
# function inlining
list(APPEND WARNINGS 4710 4711)
# padding of structs
list(APPEND WARNINGS 4820 4324)
# .. in include paths
list(APPEND WARNINGS 4464)
# undefined macros evaluating to 0 in MSVC headers
list(APPEND WARNINGS 4668)
# no function prototype in MSVC headers
list(APPEND WARNINGS 4255)
# Spectre mitigation
list(APPEND WARNINGS 5045)
# initialization of aggregate types with non-constant values is valid C99
list(APPEND WARNINGS 4204)
# nameless structs/unions are part of C11
list(APPEND WARNINGS 4201)
# conditional expression is constant
list(APPEND WARNINGS 4127)
# unary minus of unsigned types
list(APPEND WARNINGS 4146)
foreach(warning IN ITEMS ${WARNINGS})
add_compile_options("/wd${warning}")
endforeach(warning)
# "deprecation warnings" of libc functions
add_compile_options(-D_CRT_SECURE_NO_WARNINGS)
endif()
# enable -march=native -mtune=native if supported
if(WITH_MARCH_NATIVE)
if(CC_SUPPORTS_MARCH_NATIVE)
add_compile_options("-march=native")
endif()
if(CC_SUPPORTS_MTUNE_NATIVE)
add_compile_options("-mtune=native")
endif()
endif()
# check if LTO supported
if(WITH_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT LTO_SUPPORTED)
if(LTO_SUPPORTED)
# enable -fomit-frame-pointer
if(CC_SUPPORTS_FOMIT_FRAME_POINTER AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-fomit-frame-pointer)
endif()
else()
message(STATUS "IPO is not supported.")
endif()
else()
set(LTO_SUPPORTED FALSE)
endif()
message(STATUS "Picnic configuration:")
message(STATUS "ZKB++ enabled: ${WITH_ZKBPP}")
message(STATUS "KKW enabled: ${WITH_KKW}")
message(STATUS "SHA3 implementation: ${WITH_SHA3_IMPL}")
message(STATUS "LTO enabled: ${LTO_SUPPORTED}")
message(STATUS "SIMD enabled: ${WITH_SIMD_OPT}")
if(WITH_SIMD_OPT)
message(STATUS "SSE2 supported: ${CC_SUPPORTS_SSE2} enabled: ${WITH_SSE2}")
message(STATUS "AVX2 supported: ${CC_SUPPORTS_AVX2} enabled: ${WITH_AVX2}")
message(STATUS "NEON supported: ${CC_SUPPORTS_NEON} enabled: ${WITH_NEON}")
endif()
# enable -O3
if(CC_SUPPORTS_O3 AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-O3)
endif()
if(WITH_CONFIG_H)
configure_file(config.h.in config.h)
endif()
if(SED)
list(APPEND ALL_PARAMETERS Picnic_L1_FS Picnic_L1_UR Picnic_L1_full Picnic3_L1)
list(APPEND ALL_PARAMETERS Picnic_L3_FS Picnic_L3_UR Picnic_L3_full Picnic3_L3)
list(APPEND ALL_PARAMETERS Picnic_L5_FS Picnic_L5_UR Picnic_L5_full Picnic3_L5)
list(APPEND ALL_DIRECTORIES picnic_L1_FS picnic_L1_UR picnic_L1_full picnic3_L1)
list(APPEND ALL_DIRECTORIES picnic_L3_FS picnic_L3_UR picnic_L3_full picnic3_L3)
list(APPEND ALL_DIRECTORIES picnic_L5_FS picnic_L5_UR picnic_L5_full picnic3_L5)
foreach(idx RANGE 11)
# generate crypto_sign.c for NIST / SUPERCOP
list(GET ALL_PARAMETERS ${idx} param)
list(GET ALL_DIRECTORIES ${idx} dir)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/crypto_sign.c"
COMMAND ${SED}
-n
"s/PICNIC_INSTANCE/${param}/g;w ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/crypto_sign.c"
"${CMAKE_CURRENT_SOURCE_DIR}/crypto_sign.c.in"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/crypto_sign.c.in"
VERBATIM)
endforeach()
function(add_picnic_param_target dir param lowmc)
string(TOLOWER ${param} paraml)
string(TOLOWER ${lowmc} lowmcl)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${paraml}.c"
COMMAND ${SED}
-n
"s/@PARAM@/${param}/g;s/@PARAM_L@/${paraml}/g;s/@LOWMC@/${lowmc}/g;s/@LOWMC_L@/${lowmcl}/g;w ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${paraml}.c"
"${CMAKE_CURRENT_SOURCE_DIR}/picnic_param.c.in"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/picnic_param.c.in" "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${paraml}.h"
VERBATIM)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${paraml}.h"
COMMAND ${SED}
-n
"s/@PARAM@/${param}/g;s/@PARAM_L@/${paraml}/g;w ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${paraml}.h"
"${CMAKE_CURRENT_SOURCE_DIR}/picnic_param.h.in"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/picnic_param.h.in"
VERBATIM)
endfunction()
function(add_picnic3_param_target dir param lowmc)
string(TOLOWER ${param} paraml)
string(TOLOWER ${lowmc} lowmcl)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${paraml}.c"
COMMAND ${SED}
-n
"s/@PARAM@/${param}/g;s/@PARAM_L@/${paraml}/g;s/@LOWMC@/${lowmc}/g;s/@LOWMC_L@/${lowmcl}/g;w ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${paraml}.c"
"${CMAKE_CURRENT_SOURCE_DIR}/picnic3_param.c.in"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/picnic3_param.c.in" "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${paraml}.h"
VERBATIM)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${paraml}.h"
COMMAND ${SED}
-n
"s/@PARAM@/${param}/g;s/@PARAM_L@/${paraml}/g;w ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${paraml}.h"
"${CMAKE_CURRENT_SOURCE_DIR}/picnic_param.h.in"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/picnic_param.h.in"
VERBATIM)
endfunction()
add_picnic_param_target(picnic_L1_FS Picnic_L1_FS LOWMC_128_128_20)
add_picnic_param_target(picnic_L1_UR Picnic_L1_UR LOWMC_128_128_20)
add_picnic_param_target(picnic_L1_full Picnic_L1_full LOWMC_129_129_4)
add_picnic_param_target(picnic_L3_FS Picnic_L3_FS LOWMC_192_192_30)
add_picnic_param_target(picnic_L3_UR Picnic_L3_UR LOWMC_192_192_30)
add_picnic_param_target(picnic_L3_full Picnic_L3_full LOWMC_192_192_4)
add_picnic_param_target(picnic_L5_FS Picnic_L5_FS LOWMC_256_256_38)
add_picnic_param_target(picnic_L5_UR Picnic_L5_UR LOWMC_256_256_38)
add_picnic_param_target(picnic_L5_full Picnic_L5_full LOWMC_255_255_4)
add_picnic3_param_target(picnic3_L1 Picnic3_L1 LOWMC_129_129_4)
add_picnic3_param_target(picnic3_L3 Picnic3_L3 LOWMC_192_192_4)
add_picnic3_param_target(picnic3_L5 Picnic3_L5 LOWMC_255_255_4)
endif()
# SHAKE implementation
if(NOT WITH_SHA3_IMPL STREQUAL "s390-cpacf")
list(APPEND SHA3_SOURCES
sha3/KeccakHash.c
sha3/KeccakSponge.c
sha3/KeccakSpongetimes4.c
sha3/KeccakHashtimes4.c)
if(WITH_SHA3_IMPL STREQUAL "avx2")
list(APPEND SHA3_SOURCES
sha3/avx2/KeccakP-1600-AVX2.s
sha3/avx2/KeccakP-1600-times4-SIMD256.c)
set_property(SOURCE sha3/avx2/KeccakP-1600-AVX2.s PROPERTY LANGUAGE C)
elseif(WITH_SHA3_IMPL STREQUAL "opt64")
list(APPEND SHA3_SOURCES
sha3/opt64/KeccakP-1600-opt64.c
sha3/opt64/KeccakP-1600-times4-on1.c)
elseif(WITH_SHA3_IMPL STREQUAL "plain32")
list(APPEND SHA3_SOURCES
sha3/plain32/KeccakP-1600-inplace32BI.c
sha3/plain32/KeccakP-1600-times4-on1.c)
elseif(WITH_SHA3_IMPL STREQUAL "armv8a-neon")
list(APPEND SHA3_SOURCES
sha3/armv8a-neon/KeccakP-1600-armv8a-neon.s
sha3/opt64/KeccakP-1600-times4-on1.c)
set_property(SOURCE sha3/armv8a-neon/KeccakP-1600-armv8a-neon.s PROPERTY LANGUAGE C)
else()
message(FATAL_ERROR "Unknown SHA3 implementation")
endif()
# 32 bit ARM is in general unhappy with unaligned access, hence disable it in this case
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm" AND(WITH_SHA3_IMPL STREQUAL "opt64" OR WITH_SHA3_IMPL STREQUAL "plain32"))
set(DISABLE_MISALIGNED_ACCESS TRUE)
endif()
endif()
# Picnic implementation
list(APPEND PICNIC_SOURCES
compat.c
cpu.c
io.c
lowmc.c
$<$<BOOL:${WITH_LOWMC_129_129_4}>:lowmc_129_129_4.c>
$<$<BOOL:${WITH_LOWMC_192_192_4}>:lowmc_192_192_4.c>
$<$<BOOL:${WITH_LOWMC_255_255_4}>:lowmc_255_255_4.c>
mzd_additional.c
picnic.c
picnic_instances.c
randomness.c)
list(APPEND PICNIC_HEADERS picnic.h)
# ZKB++ specific source files
if(WITH_ZKBPP)
list(APPEND PICNIC_SOURCES
$<$<BOOL:${WITH_LOWMC_128_128_20}>:lowmc_128_128_20.c picnic_L1_FS/picnic_l1_fs.c>
$<$<BOOL:${WITH_LOWMC_192_192_30}>:lowmc_192_192_30.c picnic_L3_FS/picnic_l3_fs.c>
$<$<BOOL:${WITH_LOWMC_256_256_38}>:lowmc_256_256_38.c picnic_L5_FS/picnic_l5_fs.c>
$<$<AND:$<BOOL:${WITH_UNRUH}>,$<BOOL:${WITH_LOWMC_128_128_20}>>:picnic_L1_UR/picnic_l1_ur.c>
$<$<AND:$<BOOL:${WITH_UNRUH}>,$<BOOL:${WITH_LOWMC_192_192_30}>>:picnic_L3_UR/picnic_l3_ur.c>
$<$<AND:$<BOOL:${WITH_UNRUH}>,$<BOOL:${WITH_LOWMC_256_256_38}>>:picnic_L5_UR/picnic_l5_ur.c>
$<$<BOOL:${WITH_LOWMC_129_129_4}>:picnic_L1_full/picnic_l1_full.c>
$<$<BOOL:${WITH_LOWMC_192_192_4}>:picnic_L3_full/picnic_l3_full.c>
$<$<BOOL:${WITH_LOWMC_255_255_4}>:picnic_L5_full/picnic_l5_full.c>
mpc_lowmc.c
picnic_impl.c)
list(APPEND PICNIC_HEADERS
$<$<BOOL:${WITH_LOWMC_128_128_20}>:${CMAKE_CURRENT_SOURCE_DIR}/picnic_L1_FS/picnic_l1_fs.h>
$<$<BOOL:${WITH_LOWMC_192_192_30}>:${CMAKE_CURRENT_SOURCE_DIR}/picnic_L3_FS/picnic_l3_fs.h>
$<$<BOOL:${WITH_LOWMC_256_256_38}>:${CMAKE_CURRENT_SOURCE_DIR}/picnic_L5_FS/picnic_l5_fs.h>
$<$<AND:$<BOOL:${WITH_UNRUH}>,$<BOOL:${WITH_LOWMC_128_128_20}>>:${CMAKE_CURRENT_SOURCE_DIR}/picnic_L1_UR/picnic_l1_ur.h>
$<$<AND:$<BOOL:${WITH_UNRUH}>,$<BOOL:${WITH_LOWMC_192_192_30}>>:${CMAKE_CURRENT_SOURCE_DIR}/picnic_L3_UR/picnic_l3_ur.h>
$<$<AND:$<BOOL:${WITH_UNRUH}>,$<BOOL:${WITH_LOWMC_256_256_38}>>:${CMAKE_CURRENT_SOURCE_DIR}/picnic_L5_UR/picnic_l5_ur.h>
$<$<BOOL:${WITH_LOWMC_129_129_4}>:${CMAKE_CURRENT_SOURCE_DIR}/picnic_L1_full/picnic_l1_full.h>
$<$<BOOL:${WITH_LOWMC_192_192_4}>:${CMAKE_CURRENT_SOURCE_DIR}/picnic_L3_full/picnic_l3_full.h>
$<$<BOOL:${WITH_LOWMC_255_255_4}>:${CMAKE_CURRENT_SOURCE_DIR}/picnic_L5_full/picnic_l5_full.h>)
endif()
# KKW specific source files
if(WITH_KKW)
list(APPEND PICNIC_SOURCES
$<$<BOOL:${WITH_LOWMC_129_129_4}>:picnic3_L1/picnic3_l1.c>
$<$<BOOL:${WITH_LOWMC_192_192_4}>:picnic3_L3/picnic3_l3.c>
$<$<BOOL:${WITH_LOWMC_255_255_4}>:picnic3_L5/picnic3_l5.c>
picnic3_impl.c
picnic3_simulate.c
picnic3_tree.c
picnic3_types.c)
list(APPEND PICNIC_HEADERS
$<$<BOOL:${WITH_LOWMC_129_129_4}>:${CMAKE_CURRENT_SOURCE_DIR}/picnic3_L1/picnic3_l1.h>
$<$<BOOL:${WITH_LOWMC_192_192_4}>:${CMAKE_CURRENT_SOURCE_DIR}/picnic3_L3/picnic3_l3.h>
$<$<BOOL:${WITH_LOWMC_255_255_4}>:${CMAKE_CURRENT_SOURCE_DIR}/picnic3_L5/picnic3_l5.h>)
endif()
# shared library
add_library(picnic SHARED ${PICNIC_SOURCES} ${SHA3_SOURCES})
set_target_properties(picnic PROPERTIES
VERSION ${PICNIC_VERSION}
SOVERSION ${PICNIC_MAJOR_VERSION}
INTERPROCEDURAL_OPTIMIZATION ${LTO_SUPPORTED})
if(MSVC)
set_target_properties(picnic PROPERTIES OUTPUT_NAME libpicnic)
endif()
# static library
add_library(picnic_static STATIC ${PICNIC_SOURCES} ${SHA3_SOURCES})
set_target_properties(picnic_static PROPERTIES
OUTPUT_NAME picnic
ARCHIVE_OUTPUT_DIRECTORY static
INTERPROCEDURAL_OPTIMIZATION ${LTO_SUPPORTED})
target_compile_definitions(picnic_static PUBLIC PICNIC_STATIC)
# build static library with valgrind if enabled for tests
if(VALGRIND_FOUND AND WITH_VALGRIND_CT_TESTS)
target_compile_definitions(picnic_static PUBLIC WITH_VALGRIND)
endif()
function(apply_base_options lib)
# set common flags
# WITH_ZKBPP if ZKB++ is enabled
# WITH_UNRUH if ZKB++ + Unruh is enabled
# WITH_KKW if KKW is enabled
# HAVE_CONFIG_H if the generation of the config file is enabled
# NO_MISALIGNED_ACCESSES: for SHA3 on certain platforms
target_compile_definitions(${lib} PRIVATE
$<$<BOOL:${WITH_ZKBPP}>:WITH_ZKBPP>
$<$<AND:$<BOOL:${WITH_UNRUH}>,$<BOOL:${WITH_ZKBPP}>>:WITH_UNRUH>
$<$<BOOL:${WITH_KKW}>:WITH_KKW>
$<$<BOOL:${WITH_CONFIG_H}>:HAVE_CONFIG_H>
$<$<BOOL:${DISABLE_MISALIGNED_ACCESS}>:NO_MISALIGNED_ACCESSES>)
target_include_directories(${lib} PRIVATE
"${CMAKE_BINARY_DIR}"
"${CMAKE_SOURCE_DIR}"
"${CMAKE_SOURCE_DIR}/sha3"
"${CMAKE_SOURCE_DIR}/sha3/${WITH_SHA3_IMPL}")
# set flags for enabled ZKB++ specific LowMC instances
if(WITH_ZKBPP)
target_compile_definitions(${lib} PRIVATE
$<$<BOOL:${WITH_LOWMC_128_128_20}>:WITH_LOWMC_128_128_20>
$<$<BOOL:${WITH_LOWMC_192_192_30}>:WITH_LOWMC_192_192_30>
$<$<BOOL:${WITH_LOWMC_256_256_38}>:WITH_LOWMC_256_256_38>)
endif()
# set flags for enabled LowMC instances
target_compile_definitions(${lib} PRIVATE
$<$<BOOL:${WITH_LOWMC_129_129_4}>:WITH_LOWMC_129_129_4>
$<$<BOOL:${WITH_LOWMC_192_192_4}>:WITH_LOWMC_192_192_4>
$<$<BOOL:${WITH_LOWMC_255_255_4}>:WITH_LOWMC_255_255_4>)
# set flag for s390-optimized SHA3 implementation if enabled
if(WITH_SHA3_IMPL STREQUAL "s390-cpacf")
target_compile_definitions(${lib} PRIVATE WITH_SHAKE_S390_CPACF)
else()
target_compile_definitions(${lib} PRIVATE WITH_KECCAK_X4)
endif()
# disable asserts if not building in debug mode
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(${lib} PRIVATE NDEBUG)
endif()
endfunction()
function(apply_opt_options lib)
if(WITH_SIMD_OPT)
target_compile_definitions(${lib} PRIVATE WITH_OPT)
if(CC_SUPPORTS_SSE2 AND WITH_SSE2)
target_compile_definitions(${lib} PRIVATE WITH_SSE2)
if(CC_SUPPORTS_AVX2 AND CC_SUPPORTS_BMI2 AND WITH_AVX2)
target_compile_definitions(${lib} PRIVATE WITH_AVX2)
endif()
endif()
if(CC_SUPPORTS_NEON AND WITH_NEON)
target_compile_definitions(${lib} PRIVATE WITH_NEON)
endif()
endif()
endfunction()
function(apply_picnic_options lib)
apply_base_options(${lib})
apply_opt_options(${lib})
set_target_properties(${lib} PROPERTIES C_VISIBILITY_PRESET hidden)
target_compile_definitions(${lib} PRIVATE $<$<BOOL:${WITH_EXTRA_RANDOMNESS}>:WITH_EXTRA_RANDOMNESS>)
if(WIN32)
# require new enough Windows for bcrypt to be available
target_compile_definitions(${lib} PRIVATE "_WIN32_WINNT=0x0601")
target_link_libraries(${lib} bcrypt)
endif()
if(APPLE)
target_include_directories(${lib} PRIVATE ${SECURTY_INCLUDE_DIR})
target_link_libraries(${lib} PRIVATE ${SECURITY_LIBRARY})
endif()
endfunction(apply_picnic_options)
apply_picnic_options(picnic)
apply_picnic_options(picnic_static)
if(WIN32)
target_compile_definitions(picnic PRIVATE "PICNIC_EXPORT=__declspec(dllexport)")
else()
target_compile_definitions(picnic PRIVATE "PICNIC_EXPORT=__attribute__((visibility(\"default\")))")
endif()
target_compile_definitions(picnic_static PRIVATE PICNIC_EXPORT=)
if(MSVC AND USE_STATIC_RUNTIME)
target_compile_options(picnic_static PUBLIC "/MT$<$<CONFIG:Debug>:d>")
endif()
# pkg-config file
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/picnic.pc.in
${CMAKE_CURRENT_BINARY_DIR}/picnic.pc @ONLY)
add_library(utils STATIC tools/utils.cpp)
target_link_libraries(utils PUBLIC picnic)
target_include_directories(utils PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/tools")
add_library(utils_static STATIC tools/utils.cpp)
target_link_libraries(utils_static PUBLIC picnic_static)
target_include_directories(utils_static PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/tools")
if(Boost_PROGRAM_OPTIONS_FOUND)
# bench exectuable
add_executable(bench tools/bench.cpp)
set_target_properties(bench PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${LTO_SUPPORTED}})
target_link_libraries(bench utils Boost::program_options)
apply_base_options(bench)
# bench lowmc exectuable
add_executable(bench_lowmc tools/bench_lowmc.cpp)
set_target_properties(bench_lowmc PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${LTO_SUPPORTED}})
target_link_libraries(bench_lowmc utils_static Boost::program_options)
apply_base_options(bench_lowmc)
apply_opt_options(bench_lowmc)
endif()
# example executable
add_executable(example tools/example.c)
target_link_libraries(example picnic)
apply_base_options(example)
if(WITH_ZKBPP)
if(WITH_LOWMC_128_128_20)
list(APPEND api_targets picnic_L1_FS)
if(WITH_UNRUH)
list(APPEND api_targets picnic_L1_UR)
endif()
endif()
if(WITH_LOWMC_192_192_30)
list(APPEND api_targets picnic_L3_FS)
if(WITH_UNRUH)
list(APPEND api_targets picnic_L3_UR)
endif()
endif()
if(WITH_LOWMC_256_256_38)
list(APPEND api_targets picnic_L5_FS)
if(WITH_UNRUH)
list(APPEND api_targets picnic_L5_UR)
endif()
endif()
if(WITH_LOWMC_129_129_4)
list(APPEND api_targets picnic_L1_full)
endif()
if(WITH_LOWMC_192_192_4)
list(APPEND api_targets picnic_L3_full)
endif()
if(WITH_LOWMC_255_255_4)
list(APPEND api_targets picnic_L5_full)
endif()
endif()
if(WITH_KKW)
if(WITH_LOWMC_129_129_4)
list(APPEND api_targets picnic3_L1)
endif()
if(WITH_LOWMC_192_192_4)
list(APPEND api_targets picnic3_L3)
endif()
if(WITH_LOWMC_255_255_4)
list(APPEND api_targets picnic3_L5)
endif()
endif()
foreach(target IN ITEMS ${api_targets})
add_library("${target}" STATIC "${target}/crypto_sign.c")
target_include_directories("${target}" PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories("${target}" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${target}")
if(VALGRIND_FOUND AND WITH_VALGRIND_CT_TESTS)
target_link_libraries("${target}" picnic_static)
else()
target_link_libraries("${target}" picnic)
endif()
endforeach(target)
# tests
enable_testing()
add_subdirectory(tests)
# install
install(TARGETS picnic picnic_static
EXPORT picnic-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${PICNIC_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/picnic.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(EXPORT picnic-targets
NAMESPACE picnic::
FILE picnic-config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/picnic)