Reference implementations of PQC
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

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