Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cmake build #95

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ PQCsignKAT_Dilithium5.rsp
tvecs2
tvecs3
tvecs5
/build
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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)

find_package(OpenSSL REQUIRED)
add_subdirectory(ref)
add_subdirectory(avx2)
85 changes: 85 additions & 0 deletions avx2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
93 changes: 93 additions & 0 deletions ref/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()