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.
 
 
 
 

303 lines
9.9 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/falcon-1024/clean)
  98. add_subdirectory(src/sign/falcon/falcon-512/clean)
  99. add_subdirectory(src/sign/rainbow/rainbowV-classic/clean)
  100. add_subdirectory(src/sign/rainbow/rainbowI-classic/clean)
  101. add_subdirectory(src/sign/rainbow/rainbowIII-classic/clean)
  102. add_subdirectory(src/sign/sphincs/sphincs-sha256-192f-simple/clean)
  103. add_subdirectory(src/sign/sphincs/sphincs-shake256-256f-simple/clean)
  104. add_subdirectory(src/sign/sphincs/sphincs-shake256-192f-robust/clean)
  105. add_subdirectory(src/sign/sphincs/sphincs-shake256-128f-simple/clean)
  106. add_subdirectory(src/sign/sphincs/sphincs-shake256-256s-simple/clean)
  107. add_subdirectory(src/sign/sphincs/sphincs-shake256-128s-simple/clean)
  108. add_subdirectory(src/sign/sphincs/sphincs-sha256-128f-robust/clean)
  109. add_subdirectory(src/sign/sphincs/sphincs-sha256-192s-robust/clean)
  110. add_subdirectory(src/sign/sphincs/sphincs-shake256-128f-robust/clean)
  111. add_subdirectory(src/sign/sphincs/sphincs-shake256-128s-robust/clean)
  112. add_subdirectory(src/sign/sphincs/sphincs-shake256-256s-robust/clean)
  113. add_subdirectory(src/sign/sphincs/sphincs-sha256-192s-simple/clean)
  114. add_subdirectory(src/sign/sphincs/sphincs-shake256-192s-simple/clean)
  115. add_subdirectory(src/sign/sphincs/sphincs-shake256-192s-robust/clean)
  116. add_subdirectory(src/sign/sphincs/sphincs-shake256-192f-simple/clean)
  117. add_subdirectory(src/sign/sphincs/sphincs-sha256-256s-simple/clean)
  118. add_subdirectory(src/sign/sphincs/sphincs-sha256-128s-simple/clean)
  119. add_subdirectory(src/sign/sphincs/sphincs-shake256-256f-robust/clean)
  120. add_subdirectory(src/sign/sphincs/sphincs-sha256-256f-robust/clean)
  121. add_subdirectory(src/sign/sphincs/sphincs-sha256-256f-simple/clean)
  122. add_subdirectory(src/sign/sphincs/sphincs-sha256-256s-robust/clean)
  123. add_subdirectory(src/sign/sphincs/sphincs-sha256-128s-robust/clean)
  124. add_subdirectory(src/sign/sphincs/sphincs-sha256-128f-simple/clean)
  125. add_subdirectory(src/sign/sphincs/sphincs-sha256-192f-robust/clean)
  126. add_subdirectory(src/kem/kyber/kyber512/clean)
  127. add_subdirectory(src/kem/kyber/kyber768/clean)
  128. add_subdirectory(src/kem/kyber/kyber1024/clean)
  129. add_subdirectory(src/kem/saber/lightsaber/clean)
  130. add_subdirectory(src/kem/saber/firesaber/clean)
  131. add_subdirectory(src/kem/saber/saber/clean)
  132. add_subdirectory(src/kem/frodo/frodokem640shake/clean)
  133. add_subdirectory(src/kem/frodo/frodokem976shake/clean)
  134. add_subdirectory(src/kem/frodo/frodokem1344shake/clean)
  135. add_subdirectory(src/kem/ntru/ntruhps4096821/clean)
  136. add_subdirectory(src/kem/ntru/ntruhps2048509/clean)
  137. add_subdirectory(src/kem/ntru/ntruhrss701/clean)
  138. add_subdirectory(src/kem/ntru/ntruhps2048677/clean)
  139. add_subdirectory(src/kem/ntru_prime/ntrulpr761/clean)
  140. add_subdirectory(src/kem/ntru_prime/ntrulpr653/clean)
  141. add_subdirectory(src/kem/ntru_prime/ntrulpr857/clean)
  142. add_subdirectory(src/kem/hqc/hqc-rmrs-128/clean)
  143. add_subdirectory(src/kem/hqc/hqc-rmrs-192/clean)
  144. add_subdirectory(src/kem/hqc/hqc-rmrs-256/clean)
  145. add_subdirectory(src/kem/sike)
  146. # Hardware optimized targets
  147. if(${ARCH} STREQUAL "ARCH_x86_64")
  148. set(CMAKE_C_FLAGS
  149. "${CMAKE_C_FLAGS} -march=haswell")
  150. set(SRC_COMMON_AVX2
  151. src/common/keccak4x/KeccakP-1600-times4-SIMD256.c
  152. )
  153. # Sign
  154. add_subdirectory(src/sign/falcon/falcon-512/avx2)
  155. add_subdirectory(src/sign/falcon/falcon-1024/avx2)
  156. add_subdirectory(src/sign/dilithium/dilithium2/avx2)
  157. add_subdirectory(src/sign/dilithium/dilithium3/avx2)
  158. add_subdirectory(src/sign/dilithium/dilithium5/avx2)
  159. add_subdirectory(src/sign/sphincs/sphincs-shake256-128s-simple/avx2)
  160. add_subdirectory(src/sign/sphincs/sphincs-shake256-128f-robust/avx2)
  161. add_subdirectory(src/sign/sphincs/sphincs-shake256-128s-robust/avx2)
  162. add_subdirectory(src/sign/sphincs/sphincs-shake256-128f-simple/avx2)
  163. add_subdirectory(src/sign/sphincs/sphincs-shake256-192s-simple/avx2)
  164. add_subdirectory(src/sign/sphincs/sphincs-shake256-192f-robust/avx2)
  165. add_subdirectory(src/sign/sphincs/sphincs-shake256-192s-robust/avx2)
  166. add_subdirectory(src/sign/sphincs/sphincs-shake256-192f-simple/avx2)
  167. add_subdirectory(src/sign/sphincs/sphincs-shake256-256f-robust/avx2)
  168. add_subdirectory(src/sign/sphincs/sphincs-shake256-256f-simple/avx2)
  169. add_subdirectory(src/sign/sphincs/sphincs-shake256-256s-simple/avx2)
  170. add_subdirectory(src/sign/sphincs/sphincs-shake256-256s-robust/avx2)
  171. add_subdirectory(src/sign/sphincs/sphincs-sha256-128f-robust/avx2)
  172. add_subdirectory(src/sign/sphincs/sphincs-sha256-128s-simple/avx2)
  173. add_subdirectory(src/sign/sphincs/sphincs-sha256-128s-robust/avx2)
  174. add_subdirectory(src/sign/sphincs/sphincs-sha256-128f-simple/avx2)
  175. add_subdirectory(src/sign/sphincs/sphincs-sha256-192s-simple/avx2)
  176. add_subdirectory(src/sign/sphincs/sphincs-sha256-192f-simple/avx2)
  177. add_subdirectory(src/sign/sphincs/sphincs-sha256-192s-robust/avx2)
  178. add_subdirectory(src/sign/sphincs/sphincs-sha256-192f-robust/avx2)
  179. add_subdirectory(src/sign/sphincs/sphincs-sha256-256s-simple/avx2)
  180. add_subdirectory(src/sign/sphincs/sphincs-sha256-256f-robust/avx2)
  181. add_subdirectory(src/sign/sphincs/sphincs-sha256-256f-simple/avx2)
  182. add_subdirectory(src/sign/sphincs/sphincs-sha256-256s-robust/avx2)
  183. # KEMs
  184. add_subdirectory(src/kem/kyber/kyber512/avx2)
  185. add_subdirectory(src/kem/kyber/kyber768/avx2)
  186. add_subdirectory(src/kem/kyber/kyber1024/avx2)
  187. add_subdirectory(src/kem/saber/lightsaber/avx2)
  188. add_subdirectory(src/kem/saber/firesaber/avx2)
  189. add_subdirectory(src/kem/saber/saber/avx2)
  190. add_subdirectory(src/kem/ntru/ntruhps4096821/avx2)
  191. add_subdirectory(src/kem/ntru/ntruhps2048509/avx2)
  192. add_subdirectory(src/kem/ntru/ntruhrss701/avx2)
  193. add_subdirectory(src/kem/ntru/ntruhps2048677/avx2)
  194. add_subdirectory(src/kem/ntru_prime/ntrulpr761/avx2)
  195. add_subdirectory(src/kem/ntru_prime/ntrulpr653/avx2)
  196. add_subdirectory(src/kem/ntru_prime/ntrulpr857/avx2)
  197. add_subdirectory(src/kem/hqc/hqc-rmrs-128/avx2)
  198. add_subdirectory(src/kem/hqc/hqc-rmrs-192/avx2)
  199. add_subdirectory(src/kem/hqc/hqc-rmrs-256/avx2)
  200. endif()
  201. # The rest of the library
  202. set(SRC_COMMON_GENERIC
  203. src/common/aes.c
  204. src/common/fips202.c
  205. src/common/sp800-185.c
  206. src/common/randombytes.c
  207. src/common/sha2.c
  208. src/common/nistseedexpander.c
  209. src/capi/pqapi.c
  210. )
  211. add_library(
  212. common
  213. OBJECT
  214. ${SRC_COMMON_GENERIC}
  215. ${SRC_COMMON_AVX2}
  216. )
  217. add_library(
  218. pqc
  219. SHARED
  220. )
  221. add_library(
  222. pqc_s
  223. STATIC
  224. )
  225. get_property(OBJ_LIBS GLOBAL PROPERTY obj_libs)
  226. target_link_libraries(
  227. pqc
  228. ${OBJ_LIBS}
  229. cpu_features
  230. common
  231. )
  232. target_link_libraries(
  233. pqc_s
  234. cpu_features
  235. common
  236. ${OBJ_LIBS}
  237. )
  238. add_executable(
  239. ut
  240. test/ut.cpp
  241. )
  242. target_link_libraries(
  243. ut
  244. gtest
  245. gtest_main
  246. pqc_s)
  247. target_include_directories(
  248. ut PRIVATE
  249. ${CMAKE_SOURCE_DIR})
  250. if(NOT CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
  251. add_subdirectory(test/bench)
  252. endif()
  253. install(TARGETS pqc pqc_s
  254. PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE WORLD_READ WORLD_WRITE
  255. LIBRARY DESTINATION lib
  256. ARCHIVE DESTINATION lib)
  257. install(FILES
  258. ${QRS_PUBLIC_INC}
  259. DESTINATION include/pqc)