From b21a3feecee94e561081622a01f2947ae2c0df7b Mon Sep 17 00:00:00 2001 From: cyjseagull Date: Wed, 21 Aug 2024 22:57:48 +0800 Subject: [PATCH] add changelog and ci (#3) * add changelog * add workflow * use vcpkg as submodule * fix ut --- .github/stale.yml | 17 + .github/workflows/cpp_workflow.yml | 75 ++++ .gitmodules | 3 + ChangeLog.md | 21 ++ README.md | 26 +- cpp/CMakeLists.txt | 2 +- cpp/cmake/InstallBcosUtilities.cmake | 2 +- cpp/cmake/Options.cmake | 4 + cpp/ppc-crypto-core/src/CMakeLists.txt | 3 +- cpp/ppc-gateway/test/unittests/MockCache.h | 104 +++--- cpp/ppc-mpc/CMakeLists.txt | 10 +- cpp/ppc-pir/tests/CMakeLists.txt | 2 +- cpp/ppc-pir/tests/FakeOtPIRFactory.h | 72 ++-- cpp/ppc-pir/tests/TestBaseOT.cpp | 390 +++++++++++---------- cpp/ppc-pir/tests/data/AysPreDataset.csv | 3 + cpp/ppc-psi/tests/CMakeLists.txt | 2 +- cpp/vcpkg | 1 + cpp/vcpkg-configuration.json | 2 +- cpp/vcpkg.json | 9 +- 19 files changed, 450 insertions(+), 298 deletions(-) create mode 100644 .github/stale.yml create mode 100644 .github/workflows/cpp_workflow.yml create mode 100644 .gitmodules create mode 100644 ChangeLog.md create mode 100644 cpp/ppc-pir/tests/data/AysPreDataset.csv create mode 160000 cpp/vcpkg diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 00000000..e6e32871 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,17 @@ +# Number of days of inactivity before an issue becomes stale +daysUntilStale: 120 +# Number of days of inactivity before a stale issue is closed +daysUntilClose: 7 +# Issues with these labels will never be considered stale +exemptLabels: + - pinned + - security +# Label to use when marking an issue as stale +staleLabel: wontfix +# Comment to post when marking an issue as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. +# Comment to post when closing a stale issue. Set to `false` to disable +closeComment: false diff --git a/.github/workflows/cpp_workflow.yml b/.github/workflows/cpp_workflow.yml new file mode 100644 index 00000000..bdec90b6 --- /dev/null +++ b/.github/workflows/cpp_workflow.yml @@ -0,0 +1,75 @@ +name: WeDPR-Component ci(cpp) +on: + push: + paths-ignore: + - "docs/**" + - "Changelog.md" + - "README.md" + pull_request: + paths-ignore: + - "docs/**" + - "Changelog.md" + - "README.md" + release: + types: [published, push] +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + + +jobs: + build: + name: build + runs-on: ${{ matrix.os }} + continue-on-error: true + strategy: + fail-fast: false + matrix: + os: [macos-12, ubuntu-20.04] + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 5 + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly-2022-07-28 + override: true + - name: Prepare vcpkg + if: runner.os != 'Windows' + uses: friendlyanon/setup-vcpkg@v1 + with: { committish: 51b14cd4e1230dd51c11ffeff6f7d53c61cc5297 } + - uses: actions/cache@v2 + id: deps_cache + with: + path: | + deps/ + c:/vcpkg + !c:/vcpkg/.git + !c:/vcpkg/buildtrees + !c:/vcpkg/packages + !c:/vcpkg/downloads + key: build-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }} + restore-keys: | + build-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }} + build-${{ matrix.os }}-${{ github.base_ref }}- + build-${{ matrix.os }}- + - name: Build for linux + if: runner.os == 'Linux' + run: | + sudo apt install -y lcov ccache wget libgmp-dev python3-dev + export GCC='gcc-10' + export CXX='g++-10' + bash cpp/tools/install_depends.sh -o ubuntu + mkdir -p cpp/build && cd cpp/build && cmake -DTESTS=ON -DCOVERAGE=ON -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake ../ + make -j3 + - name: Build for macos + if: runner.os == 'macOS' + run: | + bash cpp/tools/install_depends.sh -o macos + mkdir -p cpp/build && cd cpp/build && cmake -DTESTS=ON -DCOVERAGE=ON -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake ../ + make -j3 + - name: Test + if: runner.os != 'Windows' + run: | + cd cpp/build && CTEST_OUTPUT_ON_FAILURE=TRUE ctest + make cov \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..b647ee05 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "cpp/vcpkg"] + path = cpp/vcpkg + url = https://github.com/microsoft/vcpkg diff --git a/ChangeLog.md b/ChangeLog.md new file mode 100644 index 00000000..8b7b54d4 --- /dev/null +++ b/ChangeLog.md @@ -0,0 +1,21 @@ +### 1.0.0-rc1 +(2024-08-21) + +**新增** + +#### 隐私计算组件 + +- **PSI**: 实现多种类型隐私求交集算法,包括CM2020, RA2018, ECDH-PSI, ECDH-Multi-PSI等 +- **MPC**: 安全多方计算相关组件 +- **MPCSQL**: 基于安全多方计算协议,支持联合分析查询任务 +- **PIR**: 匿踪查询组件 + +#### 隐私计算互联互通 + +- ECDH PSI算法与隐语互联互通 + +#### 隐私建模组件 + +- 2+方的多方联合XGB组件(训练 + 离线预测) +- 2+方多方特征工程组件(特征分箱,WOE/IV计算等) +- 预处理组件 \ No newline at end of file diff --git a/README.md b/README.md index b984af1d..8bdd4c71 100644 --- a/README.md +++ b/README.md @@ -1 +1,25 @@ -# WeDPR-Component \ No newline at end of file +# WeDPR + +![](https://wedpr-lab.readthedocs.io/zh_CN/latest/_static/images/wedpr_logo.png) + + +[![CodeFactor](https://www.codefactor.io/repository/github/webankblockchain/wedpr-component/badge?s=a4c3fb6ffd39e7618378fe13b6bd06c5846cc103)](https://www.codefactor.io/repository/github/webankblockchain/wedpr-component) +[![contributors](https://img.shields.io/github/contributors/WeBankBlockchain/WeDPR)](https://github.com/WeBankBlockchain/WeDPR-Component/graphs/contributors) +[![GitHub activity](https://img.shields.io/github/commit-activity/m/WeBankBlockchain/WeDPR-Component)](https://github.com/WeBankBlockchain/WeDPR-Component/pulse) +[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) + +微众银行多方大数据隐私计算平台[WeDPR](https://github.com/WeBankBlockchain/WeDPR)核心组件库,包括: + +- 丰富的隐私计算算法组件,支持隐私求交集、匿踪查询、多方联合分析(隐私SQL)、数据预处理、隐私建模和预测等能力,以满足多样化的业务场景 +- 统一网关:稳定的跨机构网络通信组件,支持基于Rip协议的路由转发协议 + + +## 技术文档 + +- [文档](https://wedpr-lab.readthedocs.io/zh-cn/latest/) +- [代码](https://github.com/WeBankBlockchain/WeDPR-Component) + + +## License + +WeDPR-Component的开源协议为Apache License 2.0, 详情参见[LICENSE](LICENSE)。 \ No newline at end of file diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 42aef4a7..f15fcba6 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -55,6 +55,7 @@ include(BuildInfoGenerator) find_package(OpenSSL REQUIRED) include(InstallBcosUtilities) +find_package(Boost COMPONENTS unit_test_framework) if(BUILD_SDK) ##### the sdk-dependencies ##### # find JNI @@ -89,7 +90,6 @@ if(NOT BUILD_SDK AND NOT BUILD_UDF) ##### the full-dependencies ##### find_package(TBB REQUIRED) find_package(jsoncpp REQUIRED) - find_package(Boost REQUIRED unit_test_framework) find_package(${BCOS_BOOSTSSL_TARGET} REQUIRED) # tcmalloc diff --git a/cpp/cmake/InstallBcosUtilities.cmake b/cpp/cmake/InstallBcosUtilities.cmake index 5fc51ace..83ad5079 100644 --- a/cpp/cmake/InstallBcosUtilities.cmake +++ b/cpp/cmake/InstallBcosUtilities.cmake @@ -1,3 +1,3 @@ -find_package(Boost COMPONENTS log filesystem chrono thread serialization iostreams system) +find_package(Boost COMPONENTS log filesystem chrono thread serialization iostreams system ) find_package(ZLIB REQUIRED) find_package(bcos-utilities REQUIRED) \ No newline at end of file diff --git a/cpp/cmake/Options.cmake b/cpp/cmake/Options.cmake index ab407a53..74a16d18 100644 --- a/cpp/cmake/Options.cmake +++ b/cpp/cmake/Options.cmake @@ -93,6 +93,10 @@ elseif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") endif () endif () +if(ENABLE_SSE) + list(APPEND VCPKG_MANIFEST_FEATURES "sse") +endif() + set(ENABLE_CPU_FEATURES OFF) # only ENABLE_CPU_FEATURES for aarch64 and x86 if ("${ARCHITECTURE}" MATCHES "aarch64") diff --git a/cpp/ppc-crypto-core/src/CMakeLists.txt b/cpp/ppc-crypto-core/src/CMakeLists.txt index ed0fa3f2..d40633ab 100644 --- a/cpp/ppc-crypto-core/src/CMakeLists.txt +++ b/cpp/ppc-crypto-core/src/CMakeLists.txt @@ -5,4 +5,5 @@ find_package(OpenSSL REQUIRED) message(STATUS "OPENSSL_INCLUDE_DIR: ${OPENSSL_INCLUDE_DIR}") message(STATUS "OPENSSL_LIBRARIES: ${OPENSSL_LIBRARIES}") -target_link_libraries(${CRYPTO_CORE_TARGET} PUBLIC ${BCOS_UTILITIES_TARGET} OpenSSL::Crypto ${CPU_FEATURES_LIB}) \ No newline at end of file +find_package(unofficial-sodium REQUIRED) +target_link_libraries(${CRYPTO_CORE_TARGET} PUBLIC unofficial-sodium::sodium ${BCOS_UTILITIES_TARGET} OpenSSL::Crypto ${CPU_FEATURES_LIB}) \ No newline at end of file diff --git a/cpp/ppc-gateway/test/unittests/MockCache.h b/cpp/ppc-gateway/test/unittests/MockCache.h index f052b652..a974faed 100644 --- a/cpp/ppc-gateway/test/unittests/MockCache.h +++ b/cpp/ppc-gateway/test/unittests/MockCache.h @@ -21,66 +21,66 @@ #include "ppc-framework/storage/CacheStorage.h" #include -namespace ppc::mock -{ -class MockCache : public storage::CacheStorage -{ +namespace ppc::mock { +class MockCache : public storage::CacheStorage { public: - using Ptr = std::shared_ptr; - MockCache() = default; - ~MockCache() override {} + using Ptr = std::shared_ptr; + MockCache() = default; + ~MockCache() override {} - /// Note: all these interfaces throws exception when error happened - /** - * @brief: check whether the key exists - * @param _key: key - * @return whether the key exists - */ - bool exists(const std::string& _key) override { return m_kv.find(_key) != m_kv.end(); } - - /** - * @brief: set key value - * @param _expirationTime: timeout of key, seconds - */ - void setValue(const std::string& _key, const std::string& _value, - int32_t _expirationSeconds = -1) override - { - m_kv.emplace(_key, _value); - } + /// Note: all these interfaces throws exception when error happened + /** + * @brief: check whether the key exists + * @param _key: key + * @return whether the key exists + */ + bool exists(const std::string &_key) override { + return m_kv.find(_key) != m_kv.end(); + } + /** + * @brief: set key value + * @param _expirationTime: timeout of key, seconds + */ + void setValue(const std::string &_key, const std::string &_value, + int32_t _expirationSeconds = -1) override { + m_kv.emplace(_key, _value); + } - /** - * @brief: get value by key - * @param _key: key - * @return value - */ - Optional getValue(const std::string& _key) override - { - auto it = m_kv.find(_key); - if (it == m_kv.end()) - { - return std::nullopt; - } - - return it->second; + /** + * @brief: get value by key + * @param _key: key + * @return value + */ + std::optional getValue(const std::string &_key) override { + auto it = m_kv.find(_key); + if (it == m_kv.end()) { + return std::nullopt; } - /** - * @brief: set a timeout on key - * @param _expirationTime: timeout of key, ms - * @return whether setting is successful - */ - bool expireKey(const std::string& _key, uint32_t _expirationTime) override { return true; } + return it->second; + } + + /** + * @brief: set a timeout on key + * @param _expirationTime: timeout of key, ms + * @return whether setting is successful + */ + bool expireKey(const std::string &_key, uint32_t _expirationTime) override { + return true; + } - /** - * @brief: delete key - * @param _key: key - * @return the number of key deleted - */ - uint64_t deleteKey(const std::string& _key) override { return m_kv.erase(_key); } + /** + * @brief: delete key + * @param _key: key + * @return the number of key deleted + */ + uint64_t deleteKey(const std::string &_key) override { + return m_kv.erase(_key); + } private: - std::unordered_map> m_kv; + std::unordered_map> m_kv; }; -} // namespace ppc::mock \ No newline at end of file +} // namespace ppc::mock \ No newline at end of file diff --git a/cpp/ppc-mpc/CMakeLists.txt b/cpp/ppc-mpc/CMakeLists.txt index cdb60d56..53720a81 100644 --- a/cpp/ppc-mpc/CMakeLists.txt +++ b/cpp/ppc-mpc/CMakeLists.txt @@ -1,9 +1,9 @@ project(ppc-mpc VERSION ${VERSION}) add_subdirectory(src) -if (TESTS) - enable_testing() - set(CTEST_OUTPUT_ON_FAILURE TRUE) - add_subdirectory(tests) -endif() +#if (TESTS) +# enable_testing() +# set(CTEST_OUTPUT_ON_FAILURE TRUE) +# add_subdirectory(tests) +#endif() diff --git a/cpp/ppc-pir/tests/CMakeLists.txt b/cpp/ppc-pir/tests/CMakeLists.txt index c7255ab0..6a969962 100644 --- a/cpp/ppc-pir/tests/CMakeLists.txt +++ b/cpp/ppc-pir/tests/CMakeLists.txt @@ -9,4 +9,4 @@ target_include_directories(${TEST_BINARY_NAME} PRIVATE .) # target_link_libraries(${TEST_BINARY_NAME} ${PIR_TARGET} ${RPC_TARGET} ${CRYPTO_TARGET} ${BOOST_UNIT_TEST}) target_link_libraries(${TEST_BINARY_NAME} PUBLIC ${IO_TARGET} ${FRONT_TARGET} ${BCOS_UTILITIES_TARGET} ${TARS_PROTOCOL_TARGET} ${PIR_TARGET} ${RPC_TARGET} ${CRYPTO_TARGET} ${PROTOCOL_TARGET} ${BOOST_UNIT_TEST}) -add_test(NAME test-ays WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME}) \ No newline at end of file +add_test(NAME test-psi WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME}) \ No newline at end of file diff --git a/cpp/ppc-pir/tests/FakeOtPIRFactory.h b/cpp/ppc-pir/tests/FakeOtPIRFactory.h index 7393a0b8..c38a1b71 100644 --- a/cpp/ppc-pir/tests/FakeOtPIRFactory.h +++ b/cpp/ppc-pir/tests/FakeOtPIRFactory.h @@ -19,10 +19,10 @@ */ #pragma once +#include "ppc-crypto-core/src/hash/BLAKE2bHash.h" +#include "ppc-crypto-core/src/hash/Sha512Hash.h" #include "ppc-crypto/src/ecc/Ed25519EccCrypto.h" #include "ppc-crypto/src/ecc/OpenSSLEccCrypto.h" -#include "ppc-crypto/src/hash/BLAKE2bHash.h" -#include "ppc-crypto/src/hash/Sha512Hash.h" #include "ppc-framework/crypto/CryptoBox.h" #include "ppc-io/src/DataResourceLoaderImpl.h" #include "ppc-tools/src/config/PPCConfig.h" @@ -38,55 +38,51 @@ using namespace ppc::io; using namespace ppc::front; using namespace ppc::tools; -namespace ppc::test -{ +namespace ppc::test { -class FakeOtPIRImpl : public OtPIRImpl -{ +class FakeOtPIRImpl : public OtPIRImpl { public: - using Ptr = std::shared_ptr; - FakeOtPIRImpl(OtPIRConfig::Ptr const& _config, unsigned _idleTimeMs = 0) - : OtPIRImpl(_config, _idleTimeMs) - { - m_enableOutputExists = true; - } - ~FakeOtPIRImpl() override = default; + using Ptr = std::shared_ptr; + FakeOtPIRImpl(OtPIRConfig::Ptr const &_config, unsigned _idleTimeMs = 0) + : OtPIRImpl(_config, _idleTimeMs) { + m_enableOutputExists = true; + } + ~FakeOtPIRImpl() override = default; }; -class FakeOtPIRFactory : public OtPIRFactory -{ +class FakeOtPIRFactory : public OtPIRFactory { public: - using Ptr = std::shared_ptr; + using Ptr = std::shared_ptr; - FakeOtPIRFactory() + FakeOtPIRFactory() : m_front(std::make_shared()), m_dataResourceLoader(std::make_shared( nullptr, nullptr, nullptr, nullptr, nullptr, nullptr)), - m_threadPool(std::make_shared("ot-pir", 4)) - { - auto hashImpl = std::make_shared(); - auto eccCrypto = std::make_shared(hashImpl, ppc::protocol::ECCCurve::P256); - m_cryptoBox = std::make_shared(hashImpl, eccCrypto); - } + m_threadPool(std::make_shared("ot-pir", 4)) { + auto hashImpl = std::make_shared(); + auto eccCrypto = std::make_shared( + hashImpl, ppc::protocol::ECCCurve::P256); + m_cryptoBox = std::make_shared(hashImpl, eccCrypto); + } - ~FakeOtPIRFactory() override = default; + ~FakeOtPIRFactory() override = default; - OtPIRImpl::Ptr createOtPIR(std::string const& _selfParty) - { - auto config = std::make_shared( - _selfParty, m_front, m_cryptoBox, m_threadPool, m_dataResourceLoader, 1); + OtPIRImpl::Ptr createOtPIR(std::string const &_selfParty) { + auto config = + std::make_shared(_selfParty, m_front, m_cryptoBox, + m_threadPool, m_dataResourceLoader, 1); - return std::make_shared(config); - } + return std::make_shared(config); + } - DataResourceLoaderImpl::Ptr resourceLoader() { return m_dataResourceLoader; } - FakeFront::Ptr front() { return m_front; } - CryptoBox::Ptr cryptoBox() { return m_cryptoBox; } + DataResourceLoaderImpl::Ptr resourceLoader() { return m_dataResourceLoader; } + FakeFront::Ptr front() { return m_front; } + CryptoBox::Ptr cryptoBox() { return m_cryptoBox; } private: - FakeFront::Ptr m_front; - DataResourceLoaderImpl::Ptr m_dataResourceLoader; - ThreadPool::Ptr m_threadPool; - CryptoBox::Ptr m_cryptoBox; + FakeFront::Ptr m_front; + DataResourceLoaderImpl::Ptr m_dataResourceLoader; + ThreadPool::Ptr m_threadPool; + CryptoBox::Ptr m_cryptoBox; }; -} // namespace ppc::test \ No newline at end of file +} // namespace ppc::test \ No newline at end of file diff --git a/cpp/ppc-pir/tests/TestBaseOT.cpp b/cpp/ppc-pir/tests/TestBaseOT.cpp index 7aa264e7..9f5477fb 100644 --- a/cpp/ppc-pir/tests/TestBaseOT.cpp +++ b/cpp/ppc-pir/tests/TestBaseOT.cpp @@ -18,19 +18,18 @@ * @date 2023-03-13 */ #include "FakeOtPIRFactory.h" +#include "ppc-crypto-core/src/hash/HashFactoryImpl.h" +#include "ppc-crypto/src/ecc/EccCryptoFactoryImpl.h" +#include "ppc-crypto/src/ecc/OpenSSLEccCrypto.h" #include "ppc-framework/protocol/Protocol.h" +#include "ppc-pir/src/BaseOT.h" #include "ppc-pir/src/Common.h" #include "ppc-pir/src/OtPIRImpl.h" -#include "ppc-pir/src/BaseOT.h" +#include "test-utils/TaskMock.h" #include #include #include #include -#include "ppc-crypto/src/ecc/OpenSSLEccCrypto.h" -#include "ppc-crypto/src/ecc/EccCryptoFactoryImpl.h" -#include "ppc-crypto/src/hash/HashFactoryImpl.h" -#include "test-utils/TaskMock.h" - using namespace ppc::pir; using namespace ppc::crypto; @@ -38,213 +37,216 @@ using namespace ppc::pir; using namespace bcos; using namespace bcos::test; - -namespace ppc::test -{ +namespace ppc::test { BOOST_FIXTURE_TEST_SUITE(OtPIRest, TestPromptFixture) - -BOOST_AUTO_TEST_CASE(testBaseOT) -{ - // 统计函数执行时间 - std::cout<< "testBaseOT" << std::endl; - - auto eccFactory = std::make_shared(); - auto hashFactory = std::make_shared(); - auto hash = hashFactory->createHashImpl((int8_t)ppc::protocol::HashImplName::SHA512); - EccCrypto::Ptr ecc = eccFactory->createEccCrypto((int8_t)ppc::protocol::ECCCurve::P256, hash); - // auto aysService = std::make_shared(); - // auto aes = std::make_shared( - // OpenSSLAES::AESType::AES128, - // SymCrypto::OperationMode::CBC, _seed, bcos::bytes()); - - - std::string datasetPath = "../../../ppc-pir/tests/data/AysPreDataset.csv"; - // std::cout<< "aysService->prepareDataset" << std::endl; - std::string prefix = "testmsg1"; - bcos::bytes sendObfuscatedHash(prefix.begin(), prefix.end()); - - - uint32_t obfuscatedOrder = 10; - auto baseOT = std::make_shared(ecc, hash); - auto messageKeypair = baseOT->prepareDataset(sendObfuscatedHash, datasetPath); - // for(auto iter = messageKeypair.begin(); iter != messageKeypair.end(); ++iter) - // { - // std::string pairKey(iter->first.begin(), iter->first.end()); - // std::string pairValue(iter->second.begin(), iter->second.end()); - // // for(uint32_t i = 0; i < messageKeypair.size(); ++i) { - // // std::cout<< "pairKey:"<< pairKey << std::endl; - // // std::cout<< "pairValue:"<< pairValue << std::endl; - // } - auto start = std::chrono::high_resolution_clock::now(); - - std::string choice = "testmsg1100"; - // std::cout<< "baseOT->senderGenerateCipher" << std::endl; - auto senderMessage = baseOT->senderGenerateCipher(bcos::bytes(choice.begin(), choice.end()), obfuscatedOrder); - // std::cout<< "baseOT->receiverGenerateMessage" << std::endl; - auto receiverMessage = baseOT->receiverGenerateMessage(senderMessage.pointX, senderMessage.pointY, messageKeypair, senderMessage.pointZ); - - // std::cout<< "baseOT->finishSender" << std::endl; - auto result = baseOT->finishSender(senderMessage.scalarBlidingB, receiverMessage.pointWList, receiverMessage.encryptMessagePair, receiverMessage.encryptCipher); - - auto end = std::chrono::high_resolution_clock::now(); - - auto duration = std::chrono::duration_cast(end - start); - std::cout << "执行时间 time: " << duration.count() << " microseconds" << std::endl; - - if(result.size() == 0){ - std::cout<< "final result: message not found" << std::endl; - } - else { - std::cout<< "final result: " << std::string(result.begin(), result.end()) << std::endl; - } - // for(uint32_t i = 0; i < result.size(); ++i) - // { - // std::cout<< std::string(result[i].begin(), result[i].end()) << std::endl; - // } - - BOOST_CHECK(true); +BOOST_AUTO_TEST_CASE(testBaseOT) { + // 统计函数执行时间 + std::cout << "testBaseOT" << std::endl; + + auto eccFactory = std::make_shared(); + auto hashFactory = std::make_shared(); + auto hash = + hashFactory->createHashImpl((int8_t)ppc::protocol::HashImplName::SHA512); + EccCrypto::Ptr ecc = + eccFactory->createEccCrypto((int8_t)ppc::protocol::ECCCurve::P256, hash); + // auto aysService = std::make_shared(); + // auto aes = std::make_shared( + // OpenSSLAES::AESType::AES128, + // SymCrypto::OperationMode::CBC, _seed, bcos::bytes()); + + std::string datasetPath = "../../../ppc-pir/tests/data/AysPreDataset.csv"; + // std::cout<< "aysService->prepareDataset" << std::endl; + std::string prefix = "testmsg1"; + bcos::bytes sendObfuscatedHash(prefix.begin(), prefix.end()); + + uint32_t obfuscatedOrder = 10; + auto baseOT = std::make_shared(ecc, hash); + auto messageKeypair = baseOT->prepareDataset(sendObfuscatedHash, datasetPath); + // for(auto iter = messageKeypair.begin(); iter != messageKeypair.end(); + // ++iter) + // { + // std::string pairKey(iter->first.begin(), iter->first.end()); + // std::string pairValue(iter->second.begin(), iter->second.end()); + // // for(uint32_t i = 0; i < messageKeypair.size(); ++i) { + // // std::cout<< "pairKey:"<< pairKey << std::endl; + // // std::cout<< "pairValue:"<< pairValue << std::endl; + // } + auto start = std::chrono::high_resolution_clock::now(); + + std::string choice = "testmsg1100"; + // std::cout<< "baseOT->senderGenerateCipher" << std::endl; + auto senderMessage = baseOT->senderGenerateCipher( + bcos::bytes(choice.begin(), choice.end()), obfuscatedOrder); + // std::cout<< "baseOT->receiverGenerateMessage" << std::endl; + auto receiverMessage = baseOT->receiverGenerateMessage( + senderMessage.pointX, senderMessage.pointY, messageKeypair, + senderMessage.pointZ); + + // std::cout<< "baseOT->finishSender" << std::endl; + auto result = baseOT->finishSender( + senderMessage.scalarBlidingB, receiverMessage.pointWList, + receiverMessage.encryptMessagePair, receiverMessage.encryptCipher); + + auto end = std::chrono::high_resolution_clock::now(); + + auto duration = + std::chrono::duration_cast(end - start); + std::cout << "执行时间 time: " << duration.count() << " microseconds" + << std::endl; + + if (result.size() == 0) { + std::cout << "final result: message not found" << std::endl; + } else { + std::cout << "final result: " << std::string(result.begin(), result.end()) + << std::endl; + } + // for(uint32_t i = 0; i < result.size(); ++i) + // { + // std::cout<< std::string(result[i].begin(), result[i].end()) << + // std::endl; + // } + + BOOST_CHECK(true); } - void testOTPIR(FakeOtPIRFactory::Ptr _factory, OtPIRImpl::Ptr _sender, - OtPIRImpl::Ptr _receiver, ppc::protocol::Task::ConstPtr _senderPirTask, - ppc::protocol::Task::ConstPtr _receiverPirTask, - std::vector const& _expectedPIRResult, bool _expectedSuccess, - int _expectedErrorCode = 0) -{ - std::atomic flag = 0; - - _sender->asyncRunTask(_senderPirTask, [_senderPirTask, _expectedSuccess, _expectedErrorCode, - &flag](ppc::protocol::TaskResult::Ptr&& _response) { - if (_expectedSuccess) - { - BOOST_CHECK(_response->error() == nullptr || _response->error()->errorCode() == 0); - BOOST_CHECK(_response->taskID() == _senderPirTask->id()); - auto result = _response->error(); - BOOST_CHECK(result == nullptr || result->errorCode() == 0); + OtPIRImpl::Ptr _receiver, + ppc::protocol::Task::ConstPtr _senderPirTask, + ppc::protocol::Task::ConstPtr _receiverPirTask, + std::vector const &_expectedPIRResult, + bool _expectedSuccess, int _expectedErrorCode = 0) { + std::atomic flag = 0; + + _sender->asyncRunTask( + _senderPirTask, [_senderPirTask, _expectedSuccess, _expectedErrorCode, + &flag](ppc::protocol::TaskResult::Ptr &&_response) { + if (_expectedSuccess) { + BOOST_CHECK(_response->error() == nullptr || + _response->error()->errorCode() == 0); + BOOST_CHECK(_response->taskID() == _senderPirTask->id()); + auto result = _response->error(); + BOOST_CHECK(result == nullptr || result->errorCode() == 0); + } else { + BOOST_CHECK(_response->error() != nullptr); + auto result = _response->error(); + BOOST_CHECK(result != nullptr); + BOOST_CHECK(_response->error()->errorCode() == _expectedErrorCode); } - else - { - BOOST_CHECK(_response->error() != nullptr); - auto result = _response->error(); - BOOST_CHECK(result != nullptr); - BOOST_CHECK(_response->error()->errorCode() == _expectedErrorCode); + flag++; + }); + _sender->start(); + + _receiver->asyncRunTask( + _receiverPirTask, [_receiverPirTask, _expectedSuccess, + &flag](ppc::protocol::TaskResult::Ptr &&_response) { + if (_expectedSuccess) { + BOOST_CHECK(_response->error() == nullptr || + _response->error()->errorCode() == 0); + BOOST_CHECK(_response->taskID() == _receiverPirTask->id()); + auto result = _response->error(); + BOOST_CHECK(result == nullptr || result->errorCode() == 0); + } else { + BOOST_CHECK(_response->error() != nullptr); + auto result = _response->error(); + BOOST_CHECK(result != nullptr); } flag++; - }); - _sender->start(); - - _receiver->asyncRunTask(_receiverPirTask, - [_receiverPirTask, _expectedSuccess, &flag](ppc::protocol::TaskResult::Ptr&& _response) { - if (_expectedSuccess) - { - BOOST_CHECK(_response->error() == nullptr || _response->error()->errorCode() == 0); - BOOST_CHECK(_response->taskID() == _receiverPirTask->id()); - auto result = _response->error(); - BOOST_CHECK(result == nullptr || result->errorCode() == 0); - } - else - { - BOOST_CHECK(_response->error() != nullptr); - auto result = _response->error(); - BOOST_CHECK(result != nullptr); - } - flag++; - }); - _receiver->start(); - - // wait for the task finish and check - while (flag < 2) - { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } - - _sender->stop(); - _receiver->stop(); - - // if (_expectedSuccess && !_expectedPIRResult.empty()) - // { - // checkTaskPIRResult(_factory->resourceLoader(), _receiverPirTask, _expectedPIRResult.size(), - // _expectedPIRResult); - // } + }); + _receiver->start(); + + // wait for the task finish and check + while (flag < 2) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + + _sender->stop(); + _receiver->stop(); + + // if (_expectedSuccess && !_expectedPIRResult.empty()) + // { + // checkTaskPIRResult(_factory->resourceLoader(), _receiverPirTask, + // _expectedPIRResult.size(), + // _expectedPIRResult); + // } } - -void testOTPIRImplFunc(const std::string& _taskID, const std::string& _params, - bool _syncResults, PartyResource::Ptr _senderParty, PartyResource::Ptr _receiverParty, - std::vector const& _expectedPIRResult, bool _expectedSuccess, - int _expectedErrorCode = 0) -{ - auto factory = std::make_shared(); - - // fake the sender - std::string senderAgencyName = "sender"; - auto senderPIR = factory->createOtPIR("sender"); - - // fake the receiver - std::string receiverAgencyName = _receiverParty->id(); - auto receiverPIR = factory->createOtPIR(receiverAgencyName); - - // register the server-pir into the front - factory->front()->registerOTPIR(senderAgencyName, senderPIR); - factory->front()->registerOTPIR(receiverAgencyName, receiverPIR); - - // trigger the pir task - auto senderPIRTask = std::make_shared(senderAgencyName); - senderPIRTask->setId(_taskID); - senderPIRTask->setParam(_params); - senderPIRTask->setSelf(_senderParty); - senderPIRTask->addParty(_receiverParty); - senderPIRTask->setSyncResultToPeer(_syncResults); - senderPIRTask->setAlgorithm((uint8_t)PSIAlgorithmType::OT_PIR_2PC); - senderPIRTask->setType((uint8_t)ppc::protocol::TaskType::PIR); - - auto receiverPIRTask = std::make_shared(receiverAgencyName); - receiverPIRTask->setId(_taskID); - receiverPIRTask->setParam(_params); - receiverPIRTask->setSelf(_receiverParty); - receiverPIRTask->addParty(_senderParty); - receiverPIRTask->setSyncResultToPeer(_syncResults); - receiverPIRTask->setAlgorithm((uint8_t)PSIAlgorithmType::OT_PIR_2PC); - receiverPIRTask->setType((uint8_t)ppc::protocol::TaskType::PIR); - - testOTPIR(factory, senderPIR, receiverPIR, senderPIRTask, receiverPIRTask, - _expectedPIRResult, _expectedSuccess, _expectedErrorCode); +void testOTPIRImplFunc(const std::string &_taskID, const std::string &_params, + bool _syncResults, PartyResource::Ptr _senderParty, + PartyResource::Ptr _receiverParty, + std::vector const &_expectedPIRResult, + bool _expectedSuccess, int _expectedErrorCode = 0) { + auto factory = std::make_shared(); + + // fake the sender + std::string senderAgencyName = "sender"; + auto senderPIR = factory->createOtPIR("sender"); + + // fake the receiver + std::string receiverAgencyName = _receiverParty->id(); + auto receiverPIR = factory->createOtPIR(receiverAgencyName); + + // register the server-pir into the front + factory->front()->registerOTPIR(senderAgencyName, senderPIR); + factory->front()->registerOTPIR(receiverAgencyName, receiverPIR); + + // trigger the pir task + auto senderPIRTask = std::make_shared(senderAgencyName); + senderPIRTask->setId(_taskID); + senderPIRTask->setParam(_params); + senderPIRTask->setSelf(_senderParty); + senderPIRTask->addParty(_receiverParty); + senderPIRTask->setSyncResultToPeer(_syncResults); + senderPIRTask->setAlgorithm((uint8_t)PSIAlgorithmType::OT_PIR_2PC); + senderPIRTask->setType((uint8_t)ppc::protocol::TaskType::PIR); + + auto receiverPIRTask = std::make_shared(receiverAgencyName); + receiverPIRTask->setId(_taskID); + receiverPIRTask->setParam(_params); + receiverPIRTask->setSelf(_receiverParty); + receiverPIRTask->addParty(_senderParty); + receiverPIRTask->setSyncResultToPeer(_syncResults); + receiverPIRTask->setAlgorithm((uint8_t)PSIAlgorithmType::OT_PIR_2PC); + receiverPIRTask->setType((uint8_t)ppc::protocol::TaskType::PIR); + + testOTPIR(factory, senderPIR, receiverPIR, senderPIRTask, receiverPIRTask, + _expectedPIRResult, _expectedSuccess, _expectedErrorCode); } -BOOST_AUTO_TEST_CASE(testNormalOtPIRCase) -{ - std::string otSearchPath = "../../../ppc-pir/tests/data/AysPreDataset.csv"; - std::string outputPath = "../../../ppc-pir/tests/data/output.csv"; +BOOST_AUTO_TEST_CASE(testNormalOtPIRCase) { + std::string otSearchPath = "../../../ppc-pir/tests/data/AysPreDataset.csv"; + std::string outputPath = "../../../ppc-pir/tests/data/output.csv"; - uint32_t count = 513; - // prepareInputs(senderPath, count, receiverPath, count, count); + uint32_t count = 513; + // prepareInputs(senderPath, count, receiverPath, count, count); - auto senderParty = mockParty((uint16_t)ppc::protocol::PartyType::Client, "sender", - "senderPartyResource", "sender_inputs", protocol::DataResourceType::FILE, ""); - auto senderOutputDesc = std::make_shared(); - senderOutputDesc->setPath(outputPath); - senderParty->mutableDataResource()->setOutputDesc(senderOutputDesc); + auto senderParty = mockParty((uint16_t)ppc::protocol::PartyType::Client, + "sender", "senderPartyResource", "sender_inputs", + protocol::DataResourceType::FILE, ""); + auto senderOutputDesc = std::make_shared(); + senderOutputDesc->setPath(outputPath); + senderParty->mutableDataResource()->setOutputDesc(senderOutputDesc); - auto receiverParty = mockParty((uint16_t)ppc::protocol::PartyType::Server, "receiver", - "receiverPartyResource", "receiver_inputs", DataResourceType::FILE, otSearchPath); + auto receiverParty = + mockParty((uint16_t)ppc::protocol::PartyType::Server, "receiver", + "receiverPartyResource", "receiver_inputs", + DataResourceType::FILE, otSearchPath); - // auto receiverOutputDesc = std::make_shared(); - // receiverOutputDesc->setPath(outputPath); - // receiverParty->mutableDataResource()->setOutputDesc(receiverOutputDesc); + // auto receiverOutputDesc = std::make_shared(); + // receiverOutputDesc->setPath(outputPath); + // receiverParty->mutableDataResource()->setOutputDesc(receiverOutputDesc); - std::vector expectedResult; - for (uint32_t i = 0; i < count; i++) - { - expectedResult.emplace_back(std::to_string(100000 + i)); - } + std::vector expectedResult; + for (uint32_t i = 0; i < count; i++) { + expectedResult.emplace_back(std::to_string(100000 + i)); + } - std::string jobParams = "{\"searchId\":\"testmsg1100\",\"requestAgencyId\":\"receiver\",\"prefixLength\":6}"; + std::string jobParams = "{\"searchId\":\"testmsg1100\",\"requestAgencyId\":" + "\"receiver\",\"prefixLength\":6}"; - testOTPIRImplFunc( - "0x12345678", jobParams, true, senderParty, receiverParty, expectedResult, true, 0); + testOTPIRImplFunc("0x12345678", jobParams, true, senderParty, receiverParty, + expectedResult, true, 0); } BOOST_AUTO_TEST_SUITE_END() -} // namespace ppc::test +} // namespace ppc::test diff --git a/cpp/ppc-pir/tests/data/AysPreDataset.csv b/cpp/ppc-pir/tests/data/AysPreDataset.csv new file mode 100644 index 00000000..590b61f2 --- /dev/null +++ b/cpp/ppc-pir/tests/data/AysPreDataset.csv @@ -0,0 +1,3 @@ +id,x1 +1,test +2,test2 diff --git a/cpp/ppc-psi/tests/CMakeLists.txt b/cpp/ppc-psi/tests/CMakeLists.txt index f2fa68c3..26b00337 100644 --- a/cpp/ppc-psi/tests/CMakeLists.txt +++ b/cpp/ppc-psi/tests/CMakeLists.txt @@ -6,6 +6,6 @@ set(TEST_BINARY_NAME test-ppc-psi) add_executable(${TEST_BINARY_NAME} ${SOURCES}) target_include_directories(${TEST_BINARY_NAME} PRIVATE .) -target_link_libraries(${TEST_BINARY_NAME} ${ECDH_CONN_PSI_TARGET} ${RA2018_PSI_TARGET} ${LABELED_PSI_TARGET} ${CM2020_PSI_TARGET} ${ECDH_2PC_PSI_TARGET} ${PROTOCOL_TARGET} ${IO_TARGET} ${LABELED_PSI_TARGET} ${CRYPTO_TARGET} ${BOOST_UNIT_TEST}) +target_link_libraries(${TEST_BINARY_NAME} ${BS_ECDH_PSI_TARGET} ${ECDH_CONN_PSI_TARGET} ${RA2018_PSI_TARGET} ${LABELED_PSI_TARGET} ${CM2020_PSI_TARGET} ${ECDH_2PC_PSI_TARGET} ${PROTOCOL_TARGET} ${IO_TARGET} ${LABELED_PSI_TARGET} ${CRYPTO_TARGET} ${BOOST_UNIT_TEST}) target_link_libraries(${TEST_BINARY_NAME} ${RA2018_PSI_TARGET} ${LABELED_PSI_TARGET} ${CM2020_PSI_TARGET} ${ECDH_2PC_PSI_TARGET} ${PROTOCOL_TARGET} ${IO_TARGET} ${LABELED_PSI_TARGET} ${CRYPTO_TARGET} ${BOOST_UNIT_TEST}) add_test(NAME test-ppc-psi WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME}) \ No newline at end of file diff --git a/cpp/vcpkg b/cpp/vcpkg new file mode 160000 index 00000000..51b14cd4 --- /dev/null +++ b/cpp/vcpkg @@ -0,0 +1 @@ +Subproject commit 51b14cd4e1230dd51c11ffeff6f7d53c61cc5297 diff --git a/cpp/vcpkg-configuration.json b/cpp/vcpkg-configuration.json index 71d2a9ae..5913a7c1 100644 --- a/cpp/vcpkg-configuration.json +++ b/cpp/vcpkg-configuration.json @@ -3,7 +3,7 @@ { "kind": "git", "repository": "https://github.com/FISCO-BCOS/registry", - "baseline": "a3508ded2bb7f83d95dd3f7406b05b2500a1fdbe", + "baseline": "070f336149afdac5cc9ace97df01de7ee31aab30", "packages": [ "openssl", "bcos-utilities", diff --git a/cpp/vcpkg.json b/cpp/vcpkg.json index c85989f4..34c765ca 100644 --- a/cpp/vcpkg.json +++ b/cpp/vcpkg.json @@ -65,7 +65,7 @@ }, { "name": "libhdfs3", - "version": "2024-04-27" + "version": "2024-04-27" }, { "name": "tbb", @@ -75,5 +75,10 @@ "name": "tarscpp", "version": "3.0.3-1#1" } - ] + ], + "features": { + "sse": { + "description": "Enable SSE4.2 for libhdfs3" + } + } } \ No newline at end of file