Debian Codegraph @

src/test/CMakeLists.txt

raw ◀ ▶
Source reconstructed at patch state 2 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 link_libraries(-latomic)
59 endif()
60
61 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
62 add_compile_definitions(SYS_BITS=64)
63 else()
64 add_compile_definitions(SYS_BITS=32)
65 endif()
66
67 if (MSVC)
68 add_compile_definitions(HAVE_INTRIN_H)
69 add_compile_definitions(USE_SSE2)
70 add_compile_definitions(HAVE_WMMINTRIN_H)
71 add_compile_definitions(HAVE_TMMINTRIN_H)
72 else()
73 if (SSE)
74 message(STATUS "Using SSE instructions")
75 add_compile_definitions(HAVE_X86INTRIN_H)
76 add_compile_definitions(HAVE_TMMINTRIN_H)
77 add_compile_options(-mssse3 -mpclmul)
78 endif()
79
80 if (SSE OR AESNI)
81 add_compile_definitions(HAVE_WMMINTRIN_H)
82 endif()
83
84 if (AESNI)
85 add_compile_options(-maes)
86 endif()
87 endif()
88
89 # -------------------------------------------------------------------------
90
91 # montgomery
92 add_library(mont OBJECT ../mont.c)
93
94 add_executable(test_mont test_mont.c $<TARGET_OBJECTS:mont>)
95 add_test(NAME test_mont COMMAND test_mont)
96
97 add_custom_command(
98 OUTPUT test_addmul.c
99 COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_addmul.py > test_addmul.c
100 DEPENDS make_tests_addmul.py
101 )
102 add_executable(test_addmul test_addmul.c $<TARGET_OBJECTS:mont>)
103 add_test(NAME test_addmul COMMAND test_addmul)
104
105 add_custom_command(
106 OUTPUT test_addmul_128.c
107 COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_addmul128.py > test_addmul_128.c
108 DEPENDS make_tests_addmul128.py
109 )
110 add_executable(test_addmul128 ${CMAKE_BINARY_DIR}/test_addmul_128.c)
111 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
112 target_sources(test_addmul128 PUBLIC ../multiply_64.c)
113 else()
114 target_sources(test_addmul128 PUBLIC ../multiply_32.c)
115 endif()
116 add_test(NAME test_addmul128 COMMAND test_addmul128)
117
118 add_custom_command(
119 OUTPUT test_product.c
120 COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_product.py > test_product.c
121 DEPENDS make_tests_product.py
122 )
123 add_executable(test_product test_product.c $<TARGET_OBJECTS:mont>)
124 add_test(NAME test_product COMMAND test_product)
125
126 add_custom_command(
127 OUTPUT test_mont_mult.c
128 COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_mont_mult.py > test_mont_mult.c
129 DEPENDS make_tests_mont_mult.py
130 )
131 add_executable(test_mont_mult test_mont_mult.c $<TARGET_OBJECTS:mont>)
132 add_test(NAME test_mont_mult COMMAND test_mont_mult)
133
134 # ec_ws
135 add_library(tables OBJECT ../p256_table.c ../p384_table.c ../p521_table.c)
136 add_executable(test_ec_ws test_ec_ws.c ../ec_ws.c $<TARGET_OBJECTS:tables> $<TARGET_OBJECTS:mont>)
137 add_test(NAME test_ec_ws COMMAND test_ec_ws)
138
139 # endianess
140 add_executable(test_endianess test_endianess.c)
141 add_test(NAME endianess COMMAND test_endianess)
142
143 # clmul
144 if (SSE)
145 add_executable(test_clmul test_clmul.c ../ghash_clmul.c)
146 add_test(NAME test_clmul COMMAND test_clmul)
147 endif()
148
149 # poly1305
150 add_library(poly1305 OBJECT ../poly1305.c)
151 foreach (f reduce load_r load_m multiply accumulate)
152 add_custom_command(
153 OUTPUT test_poly1305_${f}.c
154 COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_poly1305_${f}.py > test_poly1305_${f}.c
155 DEPENDS make_tests_poly1305_${f}.py
156 )
157 add_executable(test_poly1305_${f} ${CMAKE_BINARY_DIR}/test_poly1305_${f}.c $<TARGET_OBJECTS:poly1305>)
158 add_test(NAME test_poly1305_${f} COMMAND test_poly1305_${f})
159 endforeach()
160
161 # pkcs1
162 add_executable(test_pkcs1 test_pkcs1.c ../pkcs1_decode.c)
163 add_test(NAME test_pkcs1 COMMAND test_pkcs1)
164
165 # curve25519
166 add_library(mod25519 OBJECT ../mod25519.c ../multiply_32.c)
167 add_library(x25519 OBJECT ../x25519.c ../multiply_32.c)
168
169 add_executable(test_mod25519 test_mod25519.c $<TARGET_OBJECTS:mod25519>)
170 add_test(NAME test_mod25519 COMMAND test_mod25519)
171
172 add_custom_command(
173 OUTPUT test_mul_25519.c
174 COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_mul_25519.py > test_mul_25519.c
175 DEPENDS make_tests_mul_25519.py
176 )
177 add_executable(test_mul_25519 test_mul_25519.c $<TARGET_OBJECTS:mod25519>)
178 add_test(NAME test_mul_25519 COMMAND test_mul_25519)
179
180 add_executable(test_x25519 test_x25519.c $<TARGET_OBJECTS:x25519>)
181 add_test(NAME test_x25519 COMMAND test_x25519)
182
183 add_custom_command(
184 OUTPUT tests_ladder_step.c
185 COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_ladder_step.py > tests_ladder_step.c
186 DEPENDS make_tests_ladder_step.py
187 )
188 add_executable(tests_ladder_step tests_ladder_step.c $<TARGET_OBJECTS:x25519>)
189 add_test(NAME tests_ladder_step COMMAND tests_ladder_step)
190
191 # ed25519
192 add_executable(test_ed25519 test_ed25519.c ../ed25519.c ../multiply_32.c)
193 add_test(NAME test_ed25519 COMMAND test_ed25519)
194
195 # ed448
196 add_executable(test_ed448 test_ed448.c ../ed448.c $<TARGET_OBJECTS:mont>)
197 add_test(NAME test_ed448 COMMAND test_ed448)
198
199 # aesni
200 if (AESNI)
201 add_executable(test_aesni test_aesni.c ../AESNI.c)
202 add_test(NAME test_aesni COMMAND test_aesni)
203 endif()