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.
 
 
 
 

300 lines
9.7 KiB

  1. cmake_minimum_required(VERSION 3.13)
  2. project(cryptocore VERSION 0.0.1 LANGUAGES C)
  3. enable_language(C)
  4. enable_language(CXX)
  5. enable_language(ASM)
  6. add_subdirectory(3rd/gtest)
  7. add_subdirectory(3rd/cpu_features)
  8. set(CMAKE_VERBOSE_MAKEFILE ON)
  9. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "~/.cmake/Modules")
  10. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "3rd/cmake-modules")
  11. set(CMAKE_CXX_STANDARD 11)
  12. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  13. string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
  14. if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
  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 "AMD64")
  19. set(ARCH "ARCH_x86_64")
  20. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
  21. set(ARCH "ARCH_x86")
  22. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
  23. set(ARCH "ARCH_x86")
  24. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
  25. set(ARCH "ARCH_x86")
  26. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
  27. set(ARCH "ARCH_aarch64")
  28. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
  29. set(ARCH "ARCH_aarch64")
  30. else()
  31. message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
  32. endif()
  33. if(NOT CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
  34. # settings below are required by benchmark library
  35. set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
  36. # Target for benchmark - it also builds gtest library
  37. set(BENCHMARK_ENABLE_GTEST_TESTS ON CACHE BOOL "Enable testing of the benchmark library." FORCE)
  38. set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark tests" FORCE)
  39. set(GOOGLETEST_PATH "${CMAKE_SOURCE_DIR}/3rd/gtest" CACHE PATH "Path to the gtest sources" FORCE)
  40. #if (NOT MACOSX)
  41. # set(BENCHMARK_ENABLE_LTO ON CACHE BOOL "Enable link time optim" FORCE)
  42. #endif()
  43. set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
  44. add_subdirectory(${CMAKE_SOURCE_DIR}/3rd/gbench)
  45. endif()
  46. # Arch settings
  47. if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  48. set(MACOSX TRUE)
  49. endif()
  50. if(CMAKE_C_COMPILER_ID MATCHES "Clang")
  51. set(CLANG 1)
  52. endif()
  53. if (MACOSX)
  54. set(CMAKE_C_COMPILER /usr/bin/cc CACHE PATH "" FORCE)
  55. set(CMAKE_CXX_COMPILER /usr/bin/c++ CACHE PATH "" FORCE)
  56. endif()
  57. # Global configuration
  58. set(C_CXX_FLAGS
  59. "-Wno-ignored-qualifiers \
  60. -Wall \
  61. -Werror \
  62. -Wextra \
  63. -Wpedantic \
  64. -Wshadow \
  65. -Wno-variadic-macros \
  66. -Wundef \
  67. -Wunused-result")
  68. if(CLANG)
  69. set(C_CXX_FLAGS
  70. "-Wconditional-uninitialized \
  71. -Wmissing-variable-declarations")
  72. endif()
  73. include(.cmake/common.mk)
  74. # Control Debug/Release mode
  75. if(CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
  76. set(C_CXX_FLAGS "${C_CXX_FLAGS} -g3 -O0 -Wno-unused")
  77. else()
  78. set(C_CXX_FLAGS "${C_CXX_FLAGS} -O3")
  79. endif()
  80. include_directories(
  81. public
  82. src/common/
  83. src
  84. 3rd/cpu_features/include
  85. )
  86. set_property(GLOBAL PROPERTY obj_libs "")
  87. # Set CPU architecture
  88. set(CMAKE_C_FLAGS "${C_CXX_FLAGS} -D${ARCH}")
  89. set(CMAKE_CXX_FLAGS "${C_CXX_FLAGS} -D${ARCH}")
  90. if(PQC_WEAK_RANDOMBYTES)
  91. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPQC_WEAK_RANDOMBYTES")
  92. endif()
  93. # Define sources of the components
  94. add_subdirectory(src/sign/dilithium/dilithium2/clean)
  95. add_subdirectory(src/sign/dilithium/dilithium3/clean)
  96. add_subdirectory(src/sign/dilithium/dilithium5/clean)
  97. add_subdirectory(src/sign/falcon)
  98. add_subdirectory(src/sign/rainbow/rainbowV-classic/clean)
  99. add_subdirectory(src/sign/rainbow/rainbowI-classic/clean)
  100. add_subdirectory(src/sign/rainbow/rainbowIII-classic/clean)
  101. add_subdirectory(src/sign/sphincs/sphincs-sha256-192f-simple/clean)
  102. add_subdirectory(src/sign/sphincs/sphincs-shake256-256f-simple/clean)
  103. add_subdirectory(src/sign/sphincs/sphincs-shake256-192f-robust/clean)
  104. add_subdirectory(src/sign/sphincs/sphincs-shake256-128f-simple/clean)
  105. add_subdirectory(src/sign/sphincs/sphincs-shake256-256s-simple/clean)
  106. add_subdirectory(src/sign/sphincs/sphincs-shake256-128s-simple/clean)
  107. add_subdirectory(src/sign/sphincs/sphincs-sha256-128f-robust/clean)
  108. add_subdirectory(src/sign/sphincs/sphincs-sha256-192s-robust/clean)
  109. add_subdirectory(src/sign/sphincs/sphincs-shake256-128f-robust/clean)
  110. add_subdirectory(src/sign/sphincs/sphincs-shake256-128s-robust/clean)
  111. add_subdirectory(src/sign/sphincs/sphincs-shake256-256s-robust/clean)
  112. add_subdirectory(src/sign/sphincs/sphincs-sha256-192s-simple/clean)
  113. add_subdirectory(src/sign/sphincs/sphincs-shake256-192s-simple/clean)
  114. add_subdirectory(src/sign/sphincs/sphincs-shake256-192s-robust/clean)
  115. add_subdirectory(src/sign/sphincs/sphincs-shake256-192f-simple/clean)
  116. add_subdirectory(src/sign/sphincs/sphincs-sha256-256s-simple/clean)
  117. add_subdirectory(src/sign/sphincs/sphincs-sha256-128s-simple/clean)
  118. add_subdirectory(src/sign/sphincs/sphincs-shake256-256f-robust/clean)
  119. add_subdirectory(src/sign/sphincs/sphincs-sha256-256f-robust/clean)
  120. add_subdirectory(src/sign/sphincs/sphincs-sha256-256f-simple/clean)
  121. add_subdirectory(src/sign/sphincs/sphincs-sha256-256s-robust/clean)
  122. add_subdirectory(src/sign/sphincs/sphincs-sha256-128s-robust/clean)
  123. add_subdirectory(src/sign/sphincs/sphincs-sha256-128f-simple/clean)
  124. add_subdirectory(src/sign/sphincs/sphincs-sha256-192f-robust/clean)
  125. add_subdirectory(src/kem/kyber/kyber512/clean)
  126. add_subdirectory(src/kem/kyber/kyber768/clean)
  127. add_subdirectory(src/kem/kyber/kyber1024/clean)
  128. add_subdirectory(src/kem/saber/lightsaber/clean)
  129. add_subdirectory(src/kem/saber/firesaber/clean)
  130. add_subdirectory(src/kem/saber/saber/clean)
  131. add_subdirectory(src/kem/frodo/frodokem640shake/clean)
  132. add_subdirectory(src/kem/frodo/frodokem976shake/clean)
  133. add_subdirectory(src/kem/frodo/frodokem1344shake/clean)
  134. add_subdirectory(src/kem/ntru/ntruhps4096821/clean)
  135. add_subdirectory(src/kem/ntru/ntruhps2048509/clean)
  136. add_subdirectory(src/kem/ntru/ntruhrss701/clean)
  137. add_subdirectory(src/kem/ntru/ntruhps2048677/clean)
  138. add_subdirectory(src/kem/ntru_prime/ntrulpr761/clean)
  139. add_subdirectory(src/kem/ntru_prime/ntrulpr653/clean)
  140. add_subdirectory(src/kem/ntru_prime/ntrulpr857/clean)
  141. add_subdirectory(src/kem/hqc/hqc-rmrs-128/clean)
  142. add_subdirectory(src/kem/hqc/hqc-rmrs-192/clean)
  143. add_subdirectory(src/kem/hqc/hqc-rmrs-256/clean)
  144. add_subdirectory(src/kem/sike)
  145. # Hardware optimized targets
  146. if(${ARCH} STREQUAL "ARCH_x86_64")
  147. set(CMAKE_C_FLAGS
  148. "${CMAKE_C_FLAGS} -march=haswell")
  149. set(SRC_COMMON_AVX2
  150. src/common/keccak4x/KeccakP-1600-times4-SIMD256.c
  151. )
  152. # Sign
  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. ${OBJ_LIBS}
  226. cpu_features
  227. common
  228. )
  229. target_link_libraries(
  230. pqc_s
  231. cpu_features
  232. common
  233. ${OBJ_LIBS}
  234. )
  235. add_executable(
  236. ut
  237. test/ut.cpp
  238. )
  239. target_link_libraries(
  240. ut
  241. gtest
  242. gtest_main
  243. pqc_s)
  244. target_include_directories(
  245. ut PRIVATE
  246. ${CMAKE_SOURCE_DIR})
  247. if(NOT CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
  248. add_subdirectory(test/bench)
  249. endif()
  250. install(TARGETS pqc pqc_s
  251. PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE WORLD_READ WORLD_WRITE
  252. LIBRARY DESTINATION lib
  253. ARCHIVE DESTINATION lib)
  254. install(FILES
  255. ${QRS_PUBLIC_INC}
  256. DESTINATION include/pqc)