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.
 
 
 
 

180 lines
3.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 "QRS_ARCH_x86_64")
  13. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
  14. set(ARCH "QRS_ARCH_x86_64")
  15. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
  16. set(ARCH "QRS_ARCH_x86_64")
  17. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
  18. set(ARCH "QRS_ARCH_x86")
  19. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
  20. set(ARCH "QRS_ARCH_x86")
  21. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
  22. set(ARCH "QRS_ARCH_x86")
  23. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
  24. set(ARCH "QRS_ARCH_aarch64")
  25. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
  26. set(ARCH "QRS_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. # Control Debug/Release mode
  58. if(CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
  59. set(C_CXX_FLAGS "${C_CXX_FLAGS} -g3 -O0 -Wno-unused")
  60. else()
  61. set(C_CXX_FLAGS "${C_CXX_FLAGS} -O3")
  62. endif()
  63. include_directories(
  64. inc
  65. src
  66. )
  67. # Set CPU architecture
  68. set(CMAKE_C_FLAGS "${C_CXX_FLAGS} -D${ARCH}")
  69. set(CMAKE_CXX_FLAGS "${C_CXX_FLAGS} -D${ARCH}")
  70. add_library(
  71. common
  72. OBJECT
  73. common/fips202.c
  74. common/sp800-185.c
  75. common/randombytes.c
  76. )
  77. function(define_crypto_alg name namespace src inc)
  78. add_library(
  79. pqclean_${name}
  80. OBJECT
  81. ${src}
  82. )
  83. target_include_directories(
  84. pqclean_${name} PRIVATE
  85. common
  86. )
  87. target_compile_definitions(
  88. pqclean_${name} PRIVATE
  89. -DPQCLEAN_NAMESPACE=${namespace}
  90. )
  91. add_library(
  92. pqclean_test_${name}
  93. OBJECT
  94. test/crypto_sign/testvectors.c
  95. )
  96. target_compile_definitions(
  97. pqclean_test_${name} PRIVATE
  98. -DPQCLEAN_NAMESPACE=${namespace}
  99. )
  100. target_include_directories(
  101. pqclean_test_${name} PRIVATE
  102. common
  103. ${inc}
  104. )
  105. endfunction()
  106. set(
  107. SRC_CLEAN_DILITHIUM2
  108. crypto_sign/dilithium2/clean/ntt.c
  109. crypto_sign/dilithium2/clean/packing.c
  110. crypto_sign/dilithium2/clean/poly.c
  111. crypto_sign/dilithium2/clean/polyvec.c
  112. crypto_sign/dilithium2/clean/reduce.c
  113. crypto_sign/dilithium2/clean/rounding.c
  114. crypto_sign/dilithium2/clean/sign.c
  115. crypto_sign/dilithium2/clean/symmetric-shake.c
  116. )
  117. set(
  118. INC_CLEAN_DILITHIUM2
  119. crypto_sign/dilithium2/clean
  120. )
  121. define_crypto_alg(dilithium2_clean
  122. PQCLEAN_DILITHIUM2_CLEAN "${SRC_CLEAN_DILITHIUM2}" "${INC_CLEAN_DILITHIUM2}")
  123. add_library(
  124. pqclean
  125. SHARED
  126. )
  127. add_library(
  128. pqclean_s
  129. STATIC
  130. )
  131. target_link_libraries(
  132. pqclean
  133. common
  134. pqclean_dilithium2_clean
  135. )
  136. target_link_libraries(
  137. pqclean_s
  138. common
  139. pqclean_dilithium2_clean
  140. )
  141. add_executable(
  142. test
  143. )
  144. target_link_libraries(
  145. test
  146. pqclean_s
  147. pqclean_test_dilithium2_clean
  148. )