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.
 
 
 
 

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