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.
 
 
 
 

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