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.
 
 
 
 

296 lines
9.7 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. # Hardware optimized targets
  144. if(${ARCH} STREQUAL "ARCH_x86_64")
  145. set(CMAKE_C_FLAGS
  146. "${CMAKE_C_FLAGS} -march=native -mtune=native")
  147. set(SRC_COMMON_AVX2
  148. src/common/keccak4x/KeccakP-1600-times4-SIMD256.c
  149. )
  150. # Sign
  151. add_subdirectory(src/sign/falcon/falcon-512/avx2)
  152. add_subdirectory(src/sign/falcon/falcon-1024/avx2)
  153. add_subdirectory(src/sign/dilithium/dilithium2/avx2)
  154. add_subdirectory(src/sign/dilithium/dilithium3/avx2)
  155. add_subdirectory(src/sign/dilithium/dilithium5/avx2)
  156. add_subdirectory(src/sign/sphincs/sphincs-shake256-128s-simple/avx2)
  157. add_subdirectory(src/sign/sphincs/sphincs-shake256-128f-robust/avx2)
  158. add_subdirectory(src/sign/sphincs/sphincs-shake256-128s-robust/avx2)
  159. add_subdirectory(src/sign/sphincs/sphincs-shake256-128f-simple/avx2)
  160. add_subdirectory(src/sign/sphincs/sphincs-shake256-192s-simple/avx2)
  161. add_subdirectory(src/sign/sphincs/sphincs-shake256-192f-robust/avx2)
  162. add_subdirectory(src/sign/sphincs/sphincs-shake256-192s-robust/avx2)
  163. add_subdirectory(src/sign/sphincs/sphincs-shake256-192f-simple/avx2)
  164. add_subdirectory(src/sign/sphincs/sphincs-shake256-256f-robust/avx2)
  165. add_subdirectory(src/sign/sphincs/sphincs-shake256-256f-simple/avx2)
  166. add_subdirectory(src/sign/sphincs/sphincs-shake256-256s-simple/avx2)
  167. add_subdirectory(src/sign/sphincs/sphincs-shake256-256s-robust/avx2)
  168. add_subdirectory(src/sign/sphincs/sphincs-sha256-128f-robust/avx2)
  169. add_subdirectory(src/sign/sphincs/sphincs-sha256-128s-simple/avx2)
  170. add_subdirectory(src/sign/sphincs/sphincs-sha256-128s-robust/avx2)
  171. add_subdirectory(src/sign/sphincs/sphincs-sha256-128f-simple/avx2)
  172. add_subdirectory(src/sign/sphincs/sphincs-sha256-192s-simple/avx2)
  173. add_subdirectory(src/sign/sphincs/sphincs-sha256-192f-simple/avx2)
  174. add_subdirectory(src/sign/sphincs/sphincs-sha256-192s-robust/avx2)
  175. add_subdirectory(src/sign/sphincs/sphincs-sha256-192f-robust/avx2)
  176. add_subdirectory(src/sign/sphincs/sphincs-sha256-256s-simple/avx2)
  177. add_subdirectory(src/sign/sphincs/sphincs-sha256-256f-robust/avx2)
  178. add_subdirectory(src/sign/sphincs/sphincs-sha256-256f-simple/avx2)
  179. add_subdirectory(src/sign/sphincs/sphincs-sha256-256s-robust/avx2)
  180. # KEMs
  181. add_subdirectory(src/kem/kyber/kyber512/avx2)
  182. add_subdirectory(src/kem/kyber/kyber768/avx2)
  183. add_subdirectory(src/kem/kyber/kyber1024/avx2)
  184. add_subdirectory(src/kem/saber/lightsaber/avx2)
  185. add_subdirectory(src/kem/saber/firesaber/avx2)
  186. add_subdirectory(src/kem/saber/saber/avx2)
  187. add_subdirectory(src/kem/ntru/ntruhps4096821/avx2)
  188. add_subdirectory(src/kem/ntru/ntruhps2048509/avx2)
  189. add_subdirectory(src/kem/ntru/ntruhrss701/avx2)
  190. add_subdirectory(src/kem/ntru/ntruhps2048677/avx2)
  191. add_subdirectory(src/kem/ntru_prime/ntrulpr761/avx2)
  192. add_subdirectory(src/kem/ntru_prime/ntrulpr653/avx2)
  193. add_subdirectory(src/kem/ntru_prime/ntrulpr857/avx2)
  194. add_subdirectory(src/kem/hqc/hqc-rmrs-128/avx2)
  195. add_subdirectory(src/kem/hqc/hqc-rmrs-192/avx2)
  196. add_subdirectory(src/kem/hqc/hqc-rmrs-256/avx2)
  197. endif()
  198. # The rest of the library
  199. set(SRC_COMMON_GENERIC
  200. src/common/aes.c
  201. src/common/fips202.c
  202. src/common/sp800-185.c
  203. src/common/randombytes.c
  204. src/common/sha2.c
  205. src/common/nistseedexpander.c
  206. src/capi/pqapi.c
  207. )
  208. add_library(
  209. common
  210. OBJECT
  211. ${SRC_COMMON_GENERIC}
  212. ${SRC_COMMON_AVX2}
  213. )
  214. add_library(
  215. pqc
  216. SHARED
  217. )
  218. add_library(
  219. pqc_s
  220. STATIC
  221. )
  222. get_property(OBJ_LIBS GLOBAL PROPERTY obj_libs)
  223. target_link_libraries(
  224. pqc
  225. common
  226. ${OBJ_LIBS}
  227. )
  228. target_link_libraries(
  229. pqc_s
  230. common
  231. ${OBJ_LIBS}
  232. )
  233. add_executable(
  234. ut
  235. test/ut.cpp
  236. )
  237. target_link_libraries(
  238. ut
  239. gtest
  240. gtest_main
  241. pqc_s)
  242. target_include_directories(
  243. ut PRIVATE
  244. ${CMAKE_SOURCE_DIR})
  245. if(NOT CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
  246. add_subdirectory(test/bench)
  247. endif()
  248. install(TARGETS pqc pqc_s
  249. PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE WORLD_READ WORLD_WRITE
  250. LIBRARY DESTINATION lib
  251. ARCHIVE DESTINATION lib)
  252. install(FILES
  253. ${QRS_PUBLIC_INC}
  254. DESTINATION include/pqc)