From 65df1f1dc7af4c1067af8bc10008c69f784e7d4e Mon Sep 17 00:00:00 2001 From: yodalee Date: Sun, 3 Nov 2024 15:43:24 +0800 Subject: [PATCH 1/3] Add root CMakeLists and add build to gitignore --- .gitignore | 1 + CMakeLists.txt | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 CMakeLists.txt diff --git a/.gitignore b/.gitignore index 17ace0a..fef73d9 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ PQCsignKAT_Dilithium5.rsp tvecs2 tvecs3 tvecs5 +/build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..95224a0 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,14 @@ +# CMake minimum version and project details +cmake_minimum_required(VERSION 3.16) +project(PQCDilithium VERSION 1.0 LANGUAGES C CXX ASM) + +# Set C++ standard +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +# Option to enable/disable tests +option(ENABLE_TESTS "Enable Unit Tests" ON) + +# Set the output directories for binaries and libraries +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) From 9332d2a32f633438e7cab9d1be073889cee80df0 Mon Sep 17 00:00:00 2001 From: yodalee Date: Sun, 3 Nov 2024 16:02:42 +0800 Subject: [PATCH 2/3] Add Cmake file to build ref directory Tested by nistkat PQCgenKAT_sign, the result of Makefile and Cmake are identical --- CMakeLists.txt | 3 ++ ref/CMakeLists.txt | 93 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 ref/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 95224a0..a228d03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,3 +12,6 @@ option(ENABLE_TESTS "Enable Unit Tests" ON) # Set the output directories for binaries and libraries set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + +find_package(OpenSSL REQUIRED) +add_subdirectory(ref) \ No newline at end of file diff --git a/ref/CMakeLists.txt b/ref/CMakeLists.txt new file mode 100644 index 0000000..cf42a54 --- /dev/null +++ b/ref/CMakeLists.txt @@ -0,0 +1,93 @@ + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpedantic") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-prototypes") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wredundant-decls") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpointer-arith") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -z noexecstack") +set(NISTFLAGS "${NISTFLAGS}" -Wno-unused-result -O3 -fomit-frame-pointer) + +set(securitylevel 2 3 5) + +# build randombytes +add_library(randombytes SHARED randombytes.c) + +# build nist rng +add_library(rng SHARED nistkat/rng.c) +target_link_libraries(rng OpenSSL::Crypto) + +set(SRCS + sign.c + packing.c + polyvec.c + poly.c + ntt.c + reduce.c + rounding.c + symmetric-shake.c +) + +add_library(pqccrystals_fips202_ref SHARED fips202.c) + +# build algorithm shared library +foreach(level IN LISTS securitylevel) + set(name pqccrystals_dilithium${level}_ref) + + add_library(${name} SHARED ${SRCS}) + target_link_libraries(${name} pqccrystals_fips202_ref) + target_compile_definitions(${name} PUBLIC DILITHIUM_MODE=${level}) +endforeach() + +# build test_dilithium +foreach(level IN LISTS securitylevel) + add_executable(test_dilithium${level} test/test_dilithium.c) + target_link_libraries(test_dilithium${level} + pqccrystals_fips202_ref + pqccrystals_dilithium${level}_ref + randombytes) +endforeach() + +# build test_vector +foreach(level IN LISTS securitylevel) + add_executable(test_vectors${level} test/test_vectors.c) + target_link_libraries(test_vectors${level} + pqccrystals_fips202_ref + pqccrystals_dilithium${level}_ref) +endforeach() + +# build test_speed +foreach(level IN LISTS securitylevel) + add_executable(test_speed${level} + test/cpucycles.c + test/speed_print.c + test/test_speed.c + ) + target_link_libraries(test_speed${level} + pqccrystals_fips202_ref + pqccrystals_dilithium${level}_ref + randombytes) +endforeach() + +# build test_mul +add_executable(test_mul + test/test_mul.c +) +target_link_libraries(test_mul + pqccrystals_fips202_ref + pqccrystals_dilithium2_ref + randombytes +) + +# build nistkat +foreach(level IN LISTS securitylevel) + add_compile_options(${NISTFLAGS}) + add_executable(PQCgenKAT_sign${level} nistkat/PQCgenKAT_sign.c) + target_link_libraries(PQCgenKAT_sign${level} + pqccrystals_fips202_ref + pqccrystals_dilithium${level}_ref + rng) +endforeach() From 19b8ce54244c1f09ff6b93a6e4ed6e20a2e84554 Mon Sep 17 00:00:00 2001 From: yodalee Date: Sun, 10 Nov 2024 15:45:59 +0800 Subject: [PATCH 3/3] Add Cmake file to build avx2 directory --- CMakeLists.txt | 3 +- avx2/CMakeLists.txt | 85 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 avx2/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index a228d03..e5f4e60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,4 +14,5 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) find_package(OpenSSL REQUIRED) -add_subdirectory(ref) \ No newline at end of file +add_subdirectory(ref) +add_subdirectory(avx2) \ No newline at end of file diff --git a/avx2/CMakeLists.txt b/avx2/CMakeLists.txt new file mode 100644 index 0000000..e28cd78 --- /dev/null +++ b/avx2/CMakeLists.txt @@ -0,0 +1,85 @@ + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpedantic") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-prototypes") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wredundant-decls") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpointer-arith") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mpopcnt") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=native") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3") + +set(securitylevel 2 3 5) + +# build fips202 shared library +add_library(pqccrystals_fips202x4_avx2 SHARED fips202x4.c f1600x4.S fips202.c) + +set(SRCS + sign.c + packing.c + polyvec.c + poly.c + ntt.S + invntt.S + pointwise.S + shuffle.S + consts.c + rejsample.c + rounding.c + symmetric-shake.c +) + +# build algorithm shared library +foreach(level IN LISTS securitylevel) + set(name pqccrystals_dilithium${level}_avx2) + + add_library(${name} SHARED ${SRCS}) + target_link_libraries(${name} pqccrystals_fips202x4_avx2) + target_compile_definitions(${name} PUBLIC DILITHIUM_MODE=${level}) + target_include_directories(${name} PRIVATE .) +endforeach() + +# build test_dilithium +foreach(level IN LISTS securitylevel) + add_executable(test_dilithium${level}_avx2 test/test_dilithium.c) + target_link_libraries(test_dilithium${level}_avx2 + pqccrystals_fips202x4_avx2 + pqccrystals_dilithium${level}_avx2 + randombytes + ) +endforeach() + +# build test_vector +foreach(level IN LISTS securitylevel) + add_executable(test_vectors${level}_avx2 test/test_vectors.c) + target_link_libraries(test_vectors${level}_avx2 + pqccrystals_fips202x4_avx2 + pqccrystals_dilithium${level}_avx2) +endforeach() + +# build test_speed +foreach(level IN LISTS securitylevel) + add_executable(test_speed${level}_avx2 + test/cpucycles.c + test/speed_print.c + test/test_speed.c + ) + target_link_libraries(test_speed${level}_avx2 + pqccrystals_fips202x4_avx2 + pqccrystals_dilithium${level}_avx2 + randombytes + ) +endforeach() + +# build test_mul +add_executable(test_mul_avx2 + test/test_mul.c +) +target_link_libraries(test_mul_avx2 + pqccrystals_fips202x4_avx2 + pqccrystals_dilithium2_avx2 + randombytes +) \ No newline at end of file