Debian Codegraph @

src/test/CMakeLists.txt

raw ◀ ▶
3 Debian patches touch this file
1 cmake_minimum_required(VERSION 3.13)
2 project(test_crypto LANGUAGES C)
3 include(CMakePrintHelpers)
4 enable_testing()
5
6 cmake_print_variables(CMAKE_CXX_COMPILER_ID CMAKE_CXX_COMPILER_VERSION CMAKE_SIZEOF_VOID_P CMAKE_SYSTEM_PROCESSOR SSE)
•7 cmake_print_variables(DEB_HOST_ARCH)
8
9 # https://stackoverflow.com/questions/70475665/what-are-the-possible-values-of-cmake-system-processor
10 if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64|i686")
11 set(X86 TRUE)
12 endif()
13
14 if (X86)
15 option(SSE "Enable SSE instructions on Intel targets" ON)
16 option(AESNI "Enable AESNI instructions on Intel targets" ON)
17 endif()
18
19 if (DEFINED ENV{PYTHON})
20 set(PYTHON $ENV{PYTHON})
21 else()
22 set(PYTHON python)
23 endif()
24
25 include_directories("${CMAKE_SOURCE_DIR}/..")
26
27 # Disable any code related to CPython modules
28 # This is only required for MSVC, and it avoids a dependency on the CPython libraries
29 add_compile_definitions(NO_CPYTHON_MODULE)
30
31 # Ensure that private functions can be accessed
32 add_compile_definitions(STATIC=)
33
34 # TODO: add check for big endianess too
35 add_compile_definitions(PYCRYPTO_LITTLE_ENDIAN)
36
37 if (MSVC)
38 add_compile_options(/Wall /sdl)
39 # Disable certain warnings
40 add_compile_options(/wd4100 /wd4820 /wd5045)
41 else()
42 add_compile_definitions(HAVE_STDINT_H)
43 add_compile_definitions(HAVE_POSIX_MEMALIGN)
44 add_compile_options(-O2 -g -fstrict-aliasing -Wall -Werror)
45 if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
46 # Macro HAVE_UINT128 should be defined when __uint128_t type is available,
47 # that is, only on Unix 64 bits. It is not available with MSVC or with Unix 32 bits.
48 add_compile_definitions(HAVE_UINT128)
49 else()
50 if (X86)
51 # On 32-bit x86 platforms, gcc assumes the stack to be aligned to 16
52 # bytes, but the caller may actually only align it to 4 bytes, which
53 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40838
54 add_compile_options(-mstackrealign)
55 endif()
56 endif()
•57 if (DEB_HOST_ARCH MATCHES "^(amd64|arm64|armel|armhf|i386|ppc64|ppc64el|riscv64|s390x|sparc64|x32)$")
•58 add_compile_options(-fsanitize=undefined)
•59 add_link_options(-fsanitize=undefined)
60 link_libraries(-latomic)
61 endif()
62 if (DEB_HOST_ARCH MATCHES "^(amd64|arm64|armel|armhf|i386|ppc64|ppc64el|riscv64|s390x|x32)$")
63 add_compile_options(-fsanitize=address)
64 add_link_options(-fsanitize=address)
65 link_libraries(-latomic)
66 endif()
67 endif()
68
69 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
70 add_compile_definitions(SYS_BITS=64)
71 else()
72 add_compile_definitions(SYS_BITS=32)
73 endif()
74
75 if (MSVC)
76 add_compile_definitions(HAVE_INTRIN_H)
77 add_compile_definitions(USE_SSE2)
78 add_compile_definitions(HAVE_WMMINTRIN_H)
79 add_compile_definitions(HAVE_TMMINTRIN_H)
80 else()
81 if (SSE)
82 message(STATUS "Using SSE instructions")
83 add_compile_definitions(HAVE_X86INTRIN_H)
84 add_compile_definitions(HAVE_TMMINTRIN_H)
85 add_compile_options(-mssse3 -mpclmul)
86 endif()
87
88 if (SSE OR AESNI)
89 add_compile_definitions(HAVE_WMMINTRIN_H)
90 endif()
91
92 if (AESNI)
93 add_compile_options(-maes)
94 endif()
95 endif()
96
97 # -------------------------------------------------------------------------
98
99 # montgomery
100 add_library(mont OBJECT ../mont.c)
101
102 add_executable(test_mont test_mont.c $<TARGET_OBJECTS:mont>)
103 add_test(NAME test_mont COMMAND test_mont)
104
105 add_custom_command(
106 OUTPUT test_addmul.c
107 COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_addmul.py > test_addmul.c
108 DEPENDS make_tests_addmul.py
109 )
110 add_executable(test_addmul test_addmul.c $<TARGET_OBJECTS:mont>)
111 add_test(NAME test_addmul COMMAND test_addmul)
112
113 add_custom_command(
114 OUTPUT test_addmul_128.c
115 COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_addmul128.py > test_addmul_128.c
116 DEPENDS make_tests_addmul128.py
117 )
118 add_executable(test_addmul128 ${CMAKE_BINARY_DIR}/test_addmul_128.c)
119 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
120 target_sources(test_addmul128 PUBLIC ../multiply_64.c)
121 else()
122 target_sources(test_addmul128 PUBLIC ../multiply_32.c)
123 endif()
124 add_test(NAME test_addmul128 COMMAND test_addmul128)
125
126 add_custom_command(
127 OUTPUT test_product.c
128 COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_product.py > test_product.c
129 DEPENDS make_tests_product.py
130 )
131 add_executable(test_product test_product.c $<TARGET_OBJECTS:mont>)
132 add_test(NAME test_product COMMAND test_product)
133
134 add_custom_command(
135 OUTPUT test_mont_mult.c
136 COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_mont_mult.py > test_mont_mult.c
137 DEPENDS make_tests_mont_mult.py
138 )
139 add_executable(test_mont_mult test_mont_mult.c $<TARGET_OBJECTS:mont>)
140 add_test(NAME test_mont_mult COMMAND test_mont_mult)
141
142 # ec_ws
143 add_library(tables OBJECT ../p256_table.c ../p384_table.c ../p521_table.c)
144 add_executable(test_ec_ws test_ec_ws.c ../ec_ws.c $<TARGET_OBJECTS:tables> $<TARGET_OBJECTS:mont>)
145 add_test(NAME test_ec_ws COMMAND test_ec_ws)
146
147 # endianess
148 add_executable(test_endianess test_endianess.c)
149 add_test(NAME endianess COMMAND test_endianess)
150
151 # clmul
152 if (SSE)
153 add_executable(test_clmul test_clmul.c ../ghash_clmul.c)
154 add_test(NAME test_clmul COMMAND test_clmul)
155 endif()
156
157 # poly1305
158 add_library(poly1305 OBJECT ../poly1305.c)
159 foreach (f reduce load_r load_m multiply accumulate)
160 add_custom_command(
161 OUTPUT test_poly1305_${f}.c
162 COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_poly1305_${f}.py > test_poly1305_${f}.c
163 DEPENDS make_tests_poly1305_${f}.py
164 )
165 add_executable(test_poly1305_${f} ${CMAKE_BINARY_DIR}/test_poly1305_${f}.c $<TARGET_OBJECTS:poly1305>)
166 add_test(NAME test_poly1305_${f} COMMAND test_poly1305_${f})
167 endforeach()
168
169 # pkcs1
170 add_executable(test_pkcs1 test_pkcs1.c ../pkcs1_decode.c)
171 add_test(NAME test_pkcs1 COMMAND test_pkcs1)
172
173 # curve25519
174 add_library(mod25519 OBJECT ../mod25519.c ../multiply_32.c)
175 add_library(x25519 OBJECT ../x25519.c ../multiply_32.c)
176
177 add_executable(test_mod25519 test_mod25519.c $<TARGET_OBJECTS:mod25519>)
178 add_test(NAME test_mod25519 COMMAND test_mod25519)
179
180 add_custom_command(
181 OUTPUT test_mul_25519.c
182 COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_mul_25519.py > test_mul_25519.c
183 DEPENDS make_tests_mul_25519.py
184 )
185 add_executable(test_mul_25519 test_mul_25519.c $<TARGET_OBJECTS:mod25519>)
186 add_test(NAME test_mul_25519 COMMAND test_mul_25519)
187
188 add_executable(test_x25519 test_x25519.c $<TARGET_OBJECTS:x25519>)
189 add_test(NAME test_x25519 COMMAND test_x25519)
190
191 add_custom_command(
192 OUTPUT tests_ladder_step.c
193 COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_ladder_step.py > tests_ladder_step.c
194 DEPENDS make_tests_ladder_step.py
195 )
196 add_executable(tests_ladder_step tests_ladder_step.c $<TARGET_OBJECTS:x25519>)
197 add_test(NAME tests_ladder_step COMMAND tests_ladder_step)
198
199 # ed25519
200 add_executable(test_ed25519 test_ed25519.c ../ed25519.c ../multiply_32.c)
201 add_test(NAME test_ed25519 COMMAND test_ed25519)
202
203 # ed448
204 add_executable(test_ed448 test_ed448.c ../ed448.c $<TARGET_OBJECTS:mont>)
205 add_test(NAME test_ed448 COMMAND test_ed448)
206
207 # aesni
208 if (AESNI)
209 add_executable(test_aesni test_aesni.c ../AESNI.c)
210 add_test(NAME test_aesni COMMAND test_aesni)
211 endif()