Skip to content

Commit

Permalink
Merge pull request #13 from igorkh-fb/cmake-build
Browse files Browse the repository at this point in the history
CMake build system
  • Loading branch information
cblokh authored Dec 21, 2023
2 parents cb64940 + 4941a86 commit 2a48865
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 1 deletion.
23 changes: 22 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,25 @@ jobs:
make -C test
- name: Run Tests
run: |
make run-tests
make run-tests
cmake-test:
runs-on: ubuntu-20.04
strategy:
fail-fast: false

steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt-get update && sudo apt install -y build-essential cmake pkg-config uuid-dev libssl-dev
- name: Configure
run: |
mkdir build && cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
- name: Build
run: |
cmake --build build -j $(nproc)
- name: Run Tests
run: |
cd build && ctest --output-on-failure
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.13)
project(mpc-lib LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)

if(NOT TARGET OpenSSL::Crypto)
set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL 1.1.1 EXACT REQUIRED)
endif()

add_subdirectory(src/common)

if(NOT MPC_LIB_SKIP_TESTS)
enable_testing()
add_subdirectory(test)
endif()
52 changes: 52 additions & 0 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
set(COSIGNER_FILES
blockchain/mpc/hd_derive.cpp
crypto/commitments/commitments.c
crypto/commitments/ring_pedersen.c
crypto/drng/drng.c
crypto/ed25519_algebra/ed25519_algebra.c
crypto/GFp_curve_algebra/GFp_curve_algebra.c
crypto/keccak1600/keccak1600.c
crypto/paillier/paillier_zkp.c
crypto/paillier/paillier.c
crypto/shamir_secret_sharing/verifiable_secret_sharing.c
crypto/zero_knowledge_proof/diffie_hellman_log.c
crypto/zero_knowledge_proof/range_proofs.c
crypto/zero_knowledge_proof/schnorr.c
cosigner/asymmetric_eddsa_cosigner_client.cpp
cosigner/asymmetric_eddsa_cosigner_server.cpp
cosigner/asymmetric_eddsa_cosigner.cpp
cosigner/cmp_ecdsa_offline_signing_service.cpp
cosigner/cmp_ecdsa_online_signing_service.cpp
cosigner/cmp_ecdsa_signing_service.cpp
cosigner/cmp_offline_refresh_service.cpp
cosigner/cmp_setup_service.cpp
cosigner/cosigner_exception.cpp
cosigner/eddsa_online_signing_service.cpp
cosigner/mta.cpp
cosigner/utils.cpp
logging/logging_t.c
)

add_library(cosigner SHARED ${COSIGNER_FILES})

target_compile_options(cosigner PRIVATE
-Wall -Wextra -Wvla -Wswitch-enum -Wno-missing-field-initializers -Wno-unknown-pragmas -fstack-protector-strong -fdiagnostics-color=always
$<$<COMPILE_LANGUAGE:CXX>:
-Wno-overloaded-virtual
>
$<$<CONFIG:Debug>:
-Wformat -Wformat-security
>
$<$<NOT:$<CONFIG:Debug>>:
-DNDEBUG -UEDEBUG -UDEBUG
>
)

set(LINKER_VERSION_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/lib.lds)
target_link_options(cosigner PRIVATE
"LINKER:--version-script=${LINKER_VERSION_SCRIPT}"
"LINKER:--no-undefined")
set_target_properties(cosigner PROPERTIES LINK_DEPENDS ${LINKER_VERSION_SCRIPT})

target_include_directories(cosigner PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_link_libraries(cosigner PUBLIC OpenSSL::Crypto)
7 changes: 7 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_subdirectory(cosigner)
add_subdirectory(crypto/drng)
add_subdirectory(crypto/ed25519_algebra)
add_subdirectory(crypto/paillier)
add_subdirectory(crypto/secp256k1_algebra)
add_subdirectory(crypto/shamir_secret_sharing)
add_subdirectory(crypto/zero_knowledge_proof)
17 changes: 17 additions & 0 deletions test/cosigner/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
add_executable(cosigner_test
ecdsa_offline_test.cpp
ecdsa_online_test.cpp
eddsa_offline_test.cpp
eddsa_online_test.cpp
main.cpp
setup_test.cpp
)

find_package(Threads REQUIRED)

include(FindPkgConfig)
pkg_check_modules(UUID REQUIRED IMPORTED_TARGET uuid)

target_link_libraries(cosigner_test PRIVATE cosigner Threads::Threads PkgConfig::UUID)

add_test(NAME cosigner_test COMMAND cosigner_test)
10 changes: 10 additions & 0 deletions test/crypto/drng/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_executable(drng_test
${PROJECT_SOURCE_DIR}/src/common/crypto/drng/drng.c
main.cpp
)

target_include_directories(drng_test PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_compile_options(drng_test PRIVATE -Wall -Wextra)
target_link_libraries(drng_test PRIVATE OpenSSL::Crypto)

add_test(NAME drng_test COMMAND drng_test)
11 changes: 11 additions & 0 deletions test/crypto/ed25519_algebra/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_executable(ed25519_algebra_test
${PROJECT_SOURCE_DIR}/src/common/crypto/ed25519_algebra/ed25519_algebra.c
${PROJECT_SOURCE_DIR}/src/common/crypto/keccak1600/keccak1600.c
main.cpp
)

target_include_directories(ed25519_algebra_test PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_compile_options(ed25519_algebra_test PRIVATE -Wall -Wextra)
target_link_libraries(ed25519_algebra_test PRIVATE OpenSSL::Crypto)

add_test(NAME ed25519_algebra_test COMMAND ed25519_algebra_test)
11 changes: 11 additions & 0 deletions test/crypto/paillier/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_executable(paillier_test
${PROJECT_SOURCE_DIR}/src/common/crypto/paillier/paillier_zkp.c
${PROJECT_SOURCE_DIR}/src/common/crypto/paillier/paillier.c
main.cpp
)

target_include_directories(paillier_test PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_compile_options(paillier_test PRIVATE -Wall -Wextra)
target_link_libraries(paillier_test PRIVATE OpenSSL::Crypto)

add_test(NAME paillier_test COMMAND paillier_test)
10 changes: 10 additions & 0 deletions test/crypto/secp256k1_algebra/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_executable(secp256k1_algebra_test
${PROJECT_SOURCE_DIR}/src/common/crypto/GFp_curve_algebra/GFp_curve_algebra.c
main.cpp
)

target_include_directories(secp256k1_algebra_test PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_compile_options(secp256k1_algebra_test PRIVATE -Wall -Wextra)
target_link_libraries(secp256k1_algebra_test PRIVATE OpenSSL::Crypto)

add_test(NAME secp256k1_algebra_test COMMAND secp256k1_algebra_test)
14 changes: 14 additions & 0 deletions test/crypto/shamir_secret_sharing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_executable(shamir_secret_sharing_test
${PROJECT_SOURCE_DIR}/src/common/crypto/commitments/commitments.c
${PROJECT_SOURCE_DIR}/src/common/crypto/ed25519_algebra/ed25519_algebra.c
${PROJECT_SOURCE_DIR}/src/common/crypto/GFp_curve_algebra/GFp_curve_algebra.c
${PROJECT_SOURCE_DIR}/src/common/crypto/keccak1600/keccak1600.c
${PROJECT_SOURCE_DIR}/src/common/crypto/shamir_secret_sharing/verifiable_secret_sharing.c
main.cpp
)

target_include_directories(shamir_secret_sharing_test PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_compile_options(shamir_secret_sharing_test PRIVATE -Wall -Wextra)
target_link_libraries(shamir_secret_sharing_test PRIVATE OpenSSL::Crypto)

add_test(NAME shamir_secret_sharing_test COMMAND shamir_secret_sharing_test)
18 changes: 18 additions & 0 deletions test/crypto/zero_knowledge_proof/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
add_executable(zero_knowledge_proof_test
${PROJECT_SOURCE_DIR}/src/common/crypto/commitments/ring_pedersen.c
${PROJECT_SOURCE_DIR}/src/common/crypto/drng/drng.c
${PROJECT_SOURCE_DIR}/src/common/crypto/ed25519_algebra/ed25519_algebra.c
${PROJECT_SOURCE_DIR}/src/common/crypto/GFp_curve_algebra/GFp_curve_algebra.c
${PROJECT_SOURCE_DIR}/src/common/crypto/keccak1600/keccak1600.c
${PROJECT_SOURCE_DIR}/src/common/crypto/paillier/paillier.c
${PROJECT_SOURCE_DIR}/src/common/crypto/zero_knowledge_proof/diffie_hellman_log.c
${PROJECT_SOURCE_DIR}/src/common/crypto/zero_knowledge_proof/range_proofs.c
${PROJECT_SOURCE_DIR}/src/common/crypto/zero_knowledge_proof/schnorr.c
main.cpp
)

target_include_directories(zero_knowledge_proof_test PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_compile_options(zero_knowledge_proof_test PRIVATE -Wall -Wextra)
target_link_libraries(zero_knowledge_proof_test PRIVATE OpenSSL::Crypto)

add_test(NAME zero_knowledge_proof_test COMMAND zero_knowledge_proof_test)

0 comments on commit 2a48865

Please sign in to comment.