diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6e3d08a..3119c75 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,4 +22,25 @@ jobs: make -C test - name: Run Tests run: | - make run-tests \ No newline at end of file + 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 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ec4320e --- /dev/null +++ b/CMakeLists.txt @@ -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() diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt new file mode 100644 index 0000000..47227d6 --- /dev/null +++ b/src/common/CMakeLists.txt @@ -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 + $<$: + -Wno-overloaded-virtual + > + $<$: + -Wformat -Wformat-security + > + $<$>: + -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) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..0e6dc5f --- /dev/null +++ b/test/CMakeLists.txt @@ -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) diff --git a/test/cosigner/CMakeLists.txt b/test/cosigner/CMakeLists.txt new file mode 100644 index 0000000..73fa251 --- /dev/null +++ b/test/cosigner/CMakeLists.txt @@ -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) diff --git a/test/crypto/drng/CMakeLists.txt b/test/crypto/drng/CMakeLists.txt new file mode 100644 index 0000000..3aab3cb --- /dev/null +++ b/test/crypto/drng/CMakeLists.txt @@ -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) diff --git a/test/crypto/ed25519_algebra/CMakeLists.txt b/test/crypto/ed25519_algebra/CMakeLists.txt new file mode 100644 index 0000000..483577a --- /dev/null +++ b/test/crypto/ed25519_algebra/CMakeLists.txt @@ -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) diff --git a/test/crypto/paillier/CMakeLists.txt b/test/crypto/paillier/CMakeLists.txt new file mode 100644 index 0000000..4483b1a --- /dev/null +++ b/test/crypto/paillier/CMakeLists.txt @@ -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) diff --git a/test/crypto/secp256k1_algebra/CMakeLists.txt b/test/crypto/secp256k1_algebra/CMakeLists.txt new file mode 100644 index 0000000..b75a345 --- /dev/null +++ b/test/crypto/secp256k1_algebra/CMakeLists.txt @@ -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) diff --git a/test/crypto/shamir_secret_sharing/CMakeLists.txt b/test/crypto/shamir_secret_sharing/CMakeLists.txt new file mode 100644 index 0000000..5559401 --- /dev/null +++ b/test/crypto/shamir_secret_sharing/CMakeLists.txt @@ -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) diff --git a/test/crypto/zero_knowledge_proof/CMakeLists.txt b/test/crypto/zero_knowledge_proof/CMakeLists.txt new file mode 100644 index 0000000..56bd282 --- /dev/null +++ b/test/crypto/zero_knowledge_proof/CMakeLists.txt @@ -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)