Reference implementations of PQC
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

297 lines
9.8 KiB

  1. cmake_minimum_required(VERSION 3.13)
  2. project(cryptocore NONE)
  3. enable_language(C)
  4. enable_language(CXX)
  5. enable_language(ASM)
  6. set(CMAKE_VERBOSE_MAKEFILE ON)
  7. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "~/.cmake/Modules")
  8. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "3rd/cmake-modules")
  9. set(CMAKE_CXX_STANDARD 11)
  10. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  11. string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
  12. if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
  13. set(ARCH "ARCH_x86_64")
  14. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
  15. set(ARCH "ARCH_x86_64")
  16. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
  17. set(ARCH "ARCH_x86_64")
  18. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
  19. set(ARCH "ARCH_x86")
  20. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
  21. set(ARCH "ARCH_x86")
  22. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
  23. set(ARCH "ARCH_x86")
  24. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
  25. set(ARCH "ARCH_aarch64")
  26. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
  27. set(ARCH "ARCH_aarch64")
  28. else()
  29. message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
  30. endif()
  31. add_subdirectory(${CMAKE_SOURCE_DIR}/3rd/gtest)
  32. if(NOT CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
  33. # settings below are required by benchmark library
  34. set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
  35. # Target for benchmark - it also builds gtest library
  36. set(BENCHMARK_ENABLE_GTEST_TESTS ON CACHE BOOL "Enable testing of the benchmark library." FORCE)
  37. set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark tests" FORCE)
  38. set(GOOGLETEST_PATH "${CMAKE_SOURCE_DIR}/3rd/gtest" CACHE PATH "Path to the gtest sources" FORCE)
  39. #if (NOT MACOSX)
  40. # set(BENCHMARK_ENABLE_LTO ON CACHE BOOL "Enable link time optim" FORCE)
  41. #endif()
  42. set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
  43. add_subdirectory(${CMAKE_SOURCE_DIR}/3rd/gbench)
  44. endif()
  45. # Arch settings
  46. if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  47. set(MACOSX TRUE)
  48. endif()
  49. if(CMAKE_C_COMPILER_ID MATCHES "Clang")
  50. set(CLANG 1)
  51. endif()
  52. if (MACOSX)
  53. set(CMAKE_C_COMPILER /usr/bin/cc CACHE PATH "" FORCE)
  54. set(CMAKE_CXX_COMPILER /usr/bin/c++ CACHE PATH "" FORCE)
  55. endif()
  56. # Global configuration
  57. set(C_CXX_FLAGS
  58. "-Wno-ignored-qualifiers \
  59. -Wall \
  60. -Werror \
  61. -Wextra \
  62. -Wpedantic \
  63. -Wshadow \
  64. -Wno-variadic-macros \
  65. -Wundef \
  66. -Wunused-result")
  67. if(CLANG)
  68. set(C_CXX_FLAGS
  69. "-Wconditional-uninitialized \
  70. -Wmissing-variable-declarations")
  71. endif()
  72. include(.cmake/common.mk)
  73. # Control Debug/Release mode
  74. if(CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
  75. set(C_CXX_FLAGS "${C_CXX_FLAGS} -g3 -O0 -Wno-unused")
  76. else()
  77. set(C_CXX_FLAGS "${C_CXX_FLAGS} -O3")
  78. endif()
  79. include_directories(
  80. public
  81. src/common/
  82. src
  83. )
  84. set_property(GLOBAL PROPERTY obj_libs "")
  85. # Set CPU architecture
  86. set(CMAKE_C_FLAGS "${C_CXX_FLAGS} -D${ARCH}")
  87. set(CMAKE_CXX_FLAGS "${C_CXX_FLAGS} -D${ARCH}")
  88. if(PQC_WEAK_RANDOMBYTES)
  89. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPQC_WEAK_RANDOMBYTES")
  90. endif()
  91. # Define sources of the components
  92. add_subdirectory(src/sign/dilithium/dilithium2/clean)
  93. add_subdirectory(src/sign/dilithium/dilithium3/clean)
  94. add_subdirectory(src/sign/dilithium/dilithium5/clean)
  95. add_subdirectory(src/sign/falcon/falcon-1024/clean)
  96. add_subdirectory(src/sign/falcon/falcon-512/clean)
  97. add_subdirectory(src/sign/rainbow/rainbowV-classic/clean)
  98. add_subdirectory(src/sign/rainbow/rainbowI-classic/clean)
  99. add_subdirectory(src/sign/rainbow/rainbowIII-classic/clean)
  100. add_subdirectory(src/sign/sphincs/sphincs-sha256-192f-simple/clean)
  101. add_subdirectory(src/sign/sphincs/sphincs-shake256-256f-simple/clean)
  102. add_subdirectory(src/sign/sphincs/sphincs-shake256-192f-robust/clean)
  103. add_subdirectory(src/sign/sphincs/sphincs-shake256-128f-simple/clean)
  104. add_subdirectory(src/sign/sphincs/sphincs-shake256-256s-simple/clean)
  105. add_subdirectory(src/sign/sphincs/sphincs-shake256-128s-simple/clean)
  106. add_subdirectory(src/sign/sphincs/sphincs-sha256-128f-robust/clean)
  107. add_subdirectory(src/sign/sphincs/sphincs-sha256-192s-robust/clean)
  108. add_subdirectory(src/sign/sphincs/sphincs-shake256-128f-robust/clean)
  109. add_subdirectory(src/sign/sphincs/sphincs-shake256-128s-robust/clean)
  110. add_subdirectory(src/sign/sphincs/sphincs-shake256-256s-robust/clean)
  111. add_subdirectory(src/sign/sphincs/sphincs-sha256-192s-simple/clean)
  112. add_subdirectory(src/sign/sphincs/sphincs-shake256-192s-simple/clean)
  113. add_subdirectory(src/sign/sphincs/sphincs-shake256-192s-robust/clean)
  114. add_subdirectory(src/sign/sphincs/sphincs-shake256-192f-simple/clean)
  115. add_subdirectory(src/sign/sphincs/sphincs-sha256-256s-simple/clean)
  116. add_subdirectory(src/sign/sphincs/sphincs-sha256-128s-simple/clean)
  117. add_subdirectory(src/sign/sphincs/sphincs-shake256-256f-robust/clean)
  118. add_subdirectory(src/sign/sphincs/sphincs-sha256-256f-robust/clean)
  119. add_subdirectory(src/sign/sphincs/sphincs-sha256-256f-simple/clean)
  120. add_subdirectory(src/sign/sphincs/sphincs-sha256-256s-robust/clean)
  121. add_subdirectory(src/sign/sphincs/sphincs-sha256-128s-robust/clean)
  122. add_subdirectory(src/sign/sphincs/sphincs-sha256-128f-simple/clean)
  123. add_subdirectory(src/sign/sphincs/sphincs-sha256-192f-robust/clean)
  124. add_subdirectory(src/kem/kyber/kyber512/clean)
  125. add_subdirectory(src/kem/kyber/kyber768/clean)
  126. add_subdirectory(src/kem/kyber/kyber1024/clean)
  127. add_subdirectory(src/kem/saber/lightsaber/clean)
  128. add_subdirectory(src/kem/saber/firesaber/clean)
  129. add_subdirectory(src/kem/saber/saber/clean)
  130. add_subdirectory(src/kem/frodo/frodokem640shake/clean)
  131. add_subdirectory(src/kem/frodo/frodokem976shake/clean)
  132. add_subdirectory(src/kem/frodo/frodokem1344shake/clean)
  133. add_subdirectory(src/kem/ntru/ntruhps4096821/clean)
  134. add_subdirectory(src/kem/ntru/ntruhps2048509/clean)
  135. add_subdirectory(src/kem/ntru/ntruhrss701/clean)
  136. add_subdirectory(src/kem/ntru/ntruhps2048677/clean)
  137. add_subdirectory(src/kem/ntru_prime/ntrulpr761/clean)
  138. add_subdirectory(src/kem/ntru_prime/ntrulpr653/clean)
  139. add_subdirectory(src/kem/ntru_prime/ntrulpr857/clean)
  140. add_subdirectory(src/kem/hqc/hqc-rmrs-128/clean)
  141. add_subdirectory(src/kem/hqc/hqc-rmrs-192/clean)
  142. add_subdirectory(src/kem/hqc/hqc-rmrs-256/clean)
  143. add_subdirectory(src/kem/sike)
  144. # Hardware optimized targets
  145. if(${ARCH} STREQUAL "ARCH_x86_64")
  146. set(CMAKE_C_FLAGS
  147. "${CMAKE_C_FLAGS} -march=native -mtune=native")
  148. set(SRC_COMMON_AVX2
  149. src/common/keccak4x/KeccakP-1600-times4-SIMD256.c
  150. )
  151. # Sign
  152. add_subdirectory(src/sign/falcon/falcon-512/avx2)
  153. add_subdirectory(src/sign/falcon/falcon-1024/avx2)
  154. add_subdirectory(src/sign/dilithium/dilithium2/avx2)
  155. add_subdirectory(src/sign/dilithium/dilithium3/avx2)
  156. add_subdirectory(src/sign/dilithium/dilithium5/avx2)
  157. add_subdirectory(src/sign/sphincs/sphincs-shake256-128s-simple/avx2)
  158. add_subdirectory(src/sign/sphincs/sphincs-shake256-128f-robust/avx2)
  159. add_subdirectory(src/sign/sphincs/sphincs-shake256-128s-robust/avx2)
  160. add_subdirectory(src/sign/sphincs/sphincs-shake256-128f-simple/avx2)
  161. add_subdirectory(src/sign/sphincs/sphincs-shake256-192s-simple/avx2)
  162. add_subdirectory(src/sign/sphincs/sphincs-shake256-192f-robust/avx2)
  163. add_subdirectory(src/sign/sphincs/sphincs-shake256-192s-robust/avx2)
  164. add_subdirectory(src/sign/sphincs/sphincs-shake256-192f-simple/avx2)
  165. add_subdirectory(src/sign/sphincs/sphincs-shake256-256f-robust/avx2)
  166. add_subdirectory(src/sign/sphincs/sphincs-shake256-256f-simple/avx2)
  167. add_subdirectory(src/sign/sphincs/sphincs-shake256-256s-simple/avx2)
  168. add_subdirectory(src/sign/sphincs/sphincs-shake256-256s-robust/avx2)
  169. add_subdirectory(src/sign/sphincs/sphincs-sha256-128f-robust/avx2)
  170. add_subdirectory(src/sign/sphincs/sphincs-sha256-128s-simple/avx2)
  171. add_subdirectory(src/sign/sphincs/sphincs-sha256-128s-robust/avx2)
  172. add_subdirectory(src/sign/sphincs/sphincs-sha256-128f-simple/avx2)
  173. add_subdirectory(src/sign/sphincs/sphincs-sha256-192s-simple/avx2)
  174. add_subdirectory(src/sign/sphincs/sphincs-sha256-192f-simple/avx2)
  175. add_subdirectory(src/sign/sphincs/sphincs-sha256-192s-robust/avx2)
  176. add_subdirectory(src/sign/sphincs/sphincs-sha256-192f-robust/avx2)
  177. add_subdirectory(src/sign/sphincs/sphincs-sha256-256s-simple/avx2)
  178. add_subdirectory(src/sign/sphincs/sphincs-sha256-256f-robust/avx2)
  179. add_subdirectory(src/sign/sphincs/sphincs-sha256-256f-simple/avx2)
  180. add_subdirectory(src/sign/sphincs/sphincs-sha256-256s-robust/avx2)
  181. # KEMs
  182. add_subdirectory(src/kem/kyber/kyber512/avx2)
  183. add_subdirectory(src/kem/kyber/kyber768/avx2)
  184. add_subdirectory(src/kem/kyber/kyber1024/avx2)
  185. add_subdirectory(src/kem/saber/lightsaber/avx2)
  186. add_subdirectory(src/kem/saber/firesaber/avx2)
  187. add_subdirectory(src/kem/saber/saber/avx2)
  188. add_subdirectory(src/kem/ntru/ntruhps4096821/avx2)
  189. add_subdirectory(src/kem/ntru/ntruhps2048509/avx2)
  190. add_subdirectory(src/kem/ntru/ntruhrss701/avx2)
  191. add_subdirectory(src/kem/ntru/ntruhps2048677/avx2)
  192. add_subdirectory(src/kem/ntru_prime/ntrulpr761/avx2)
  193. add_subdirectory(src/kem/ntru_prime/ntrulpr653/avx2)
  194. add_subdirectory(src/kem/ntru_prime/ntrulpr857/avx2)
  195. add_subdirectory(src/kem/hqc/hqc-rmrs-128/avx2)
  196. add_subdirectory(src/kem/hqc/hqc-rmrs-192/avx2)
  197. add_subdirectory(src/kem/hqc/hqc-rmrs-256/avx2)
  198. endif()
  199. # The rest of the library
  200. set(SRC_COMMON_GENERIC
  201. src/common/aes.c
  202. src/common/fips202.c
  203. src/common/sp800-185.c
  204. src/common/randombytes.c
  205. src/common/sha2.c
  206. src/common/nistseedexpander.c
  207. src/capi/pqapi.c
  208. )
  209. add_library(
  210. common
  211. OBJECT
  212. ${SRC_COMMON_GENERIC}
  213. ${SRC_COMMON_AVX2}
  214. )
  215. add_library(
  216. pqc
  217. SHARED
  218. )
  219. add_library(
  220. pqc_s
  221. STATIC
  222. )
  223. get_property(OBJ_LIBS GLOBAL PROPERTY obj_libs)
  224. target_link_libraries(
  225. pqc
  226. common
  227. ${OBJ_LIBS}
  228. )
  229. target_link_libraries(
  230. pqc_s
  231. common
  232. ${OBJ_LIBS}
  233. )
  234. add_executable(
  235. ut
  236. test/ut.cpp
  237. )
  238. target_link_libraries(
  239. ut
  240. gtest
  241. gtest_main
  242. pqc_s)
  243. target_include_directories(
  244. ut PRIVATE
  245. ${CMAKE_SOURCE_DIR})
  246. if(NOT CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
  247. add_subdirectory(test/bench)
  248. endif()
  249. install(TARGETS pqc pqc_s
  250. PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE WORLD_READ WORLD_WRITE
  251. LIBRARY DESTINATION lib
  252. ARCHIVE DESTINATION lib)
  253. install(FILES
  254. ${QRS_PUBLIC_INC}
  255. DESTINATION include/pqc)