Debian Codegraph @

src/test/CMakeLists.txt

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