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.
 
 
 
 

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