Reference implementations of PQC
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

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