diff --git a/.bazelrc b/.bazelrc index 3d29c78a..d332aaf1 100644 --- a/.bazelrc +++ b/.bazelrc @@ -23,9 +23,6 @@ build --cxxopt=-std=c++17 build --host_cxxopt=-std=c++17 build --linkopt -lm -# HACK -build:linux --cxxopt -Wno-error=mismatched-new-delete - # Binary safety flags build --host_copt=-fPIE build --host_copt=-fstack-protector-strong diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 3f59c5cd..4eeceb05 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -81,6 +81,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@05963f47d870e2cb19a537396c1f668a348c7d8f # v3.24.8 + uses: github/codeql-action/upload-sarif@3ab4101902695724f9365a384f86c1074d94e18c # v3.24.7 with: sarif_file: results.sarif diff --git a/README.md b/README.md index 9969b41e..eedb0e95 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,8 @@ Supported platforms: ## Repo Layout - [base](yacl/base/): some basic types and utils in yacl. -- [crypto](yacl/crypto/): a crypto library desigend for secure computation and so on. - - [base](yacl/crypto/base): **basic/standarized crypto**, i.e. AES, hashing. - - [primitives](yacl/crypto/primitives/): **crypto primitives**, i.e. OT, DPF. - - [tools](yacl/crypto/tools/): **theoretical crypto tools**, i.e. Random Oracle (RO), PRG. - - [utils](yacl/crypto/utils/): easy-to-use **crypto utilities**. +- [crypto](yacl/crypto/): **crypto algorithms** without [link](yacl/link/). +- [kernels](yacl/kernels/): **crypto kernels** that includes [link](yacl/link/) with multi-thread support, i.e. OT, DPF. - [io](yacl/io/): a simple streaming-based io library. - [link](yacl/link/): a simple rpc-based MPI framework, providing the [SPMD](https://en.wikipedia.org/wiki/SPMD) parallel programming capability. diff --git a/bazel/patches/brpc.patch b/bazel/patches/brpc.patch index 2e9a9b98..5104aa53 100644 --- a/bazel/patches/brpc.patch +++ b/bazel/patches/brpc.patch @@ -157,5 +157,5 @@ index 0bdaa4d3..43597f63 100644 + "@bazel_tools//src/conditions:linux_aarch64": ["-O1"], + "//conditions:default": [""], }) - + LINKOPTS = [ diff --git a/bazel/patches/msgpack.patch b/bazel/patches/msgpack.patch new file mode 100644 index 00000000..05dcffa1 --- /dev/null +++ b/bazel/patches/msgpack.patch @@ -0,0 +1,17 @@ +diff --git a/include/msgpack/v1/detail/cpp11_zone.hpp b/include/msgpack/v1/detail/cpp11_zone.hpp +index 2586f275..e325ee3b 100644 +--- a/include/msgpack/v1/detail/cpp11_zone.hpp ++++ b/include/msgpack/v1/detail/cpp11_zone.hpp +@@ -20,6 +20,12 @@ + #include + #include + ++#if (defined __arm__ || defined __aarch64__) && \ ++ (defined(linux) || defined(__linux) || defined(__linux__)) && \ ++ (defined(__GNUC__) || defined(__GNUG__)) ++// This is a bug of arm linux gcc, suppressing false positives. ++#pragma GCC diagnostic ignored "-Wmismatched-new-delete" ++#endif + namespace msgpack { + + /// @cond diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index bf3b3d81..bd32e1a3 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -60,10 +60,10 @@ def _org_interconnection(): http_archive, name = "org_interconnection", urls = [ - "https://github.com/secretflow/interconnection/archive/70672ae363614fddbdece4db719e0957b64fcae3.tar.gz", + "https://github.com/secretflow/interconnection/archive/32ec6f51aeb662f84c4d06fd8a0c3675a1e801a6.tar.gz", ], - strip_prefix = "interconnection-70672ae363614fddbdece4db719e0957b64fcae3", - sha256 = "82ad4a5c8d40e2ebbdc35db86b594bebe1fa89b0e06a7f5f4cb9a9fba91003da", + strip_prefix = "interconnection-32ec6f51aeb662f84c4d06fd8a0c3675a1e801a6", + sha256 = "a6b65900c36f1f9bc9c5bfa4fbf1b66fb1045f09eca8beb3a09c4be4c80b85f3", ) # Add homebrew openmp for macOS, somehow..homebrew installs to different location on Apple Silcon/Intel macs.. so we need two rules here @@ -339,6 +339,10 @@ def _com_github_msgpack_msgpack(): type = "tar.gz", strip_prefix = "msgpack-c-cpp-6.1.0", sha256 = "5e63e4d9b12ab528fccf197f7e6908031039b1fc89cd8da0e97fbcbf5a6c6d3a", + patches = [ + "@yacl//bazel:patches/msgpack.patch", + ], + patch_args = ["-p1"], urls = [ "https://github.com/msgpack/msgpack-c/archive/refs/tags/cpp-6.1.0.tar.gz", ], diff --git a/yacl/crypto/primitives/psu/BUILD.bazel b/examples/psu/BUILD.bazel similarity index 83% rename from yacl/crypto/primitives/psu/BUILD.bazel rename to examples/psu/BUILD.bazel index 3c46ea68..cab47525 100644 --- a/yacl/crypto/primitives/psu/BUILD.bazel +++ b/examples/psu/BUILD.bazel @@ -28,11 +28,11 @@ yacl_cc_library( deps = [ "//yacl/base:exception", "//yacl/base:int128", - "//yacl/crypto/base/hash:hash_utils", - "//yacl/crypto/primitives/ot:base_ot", - "//yacl/crypto/primitives/ot:iknp_ote", - "//yacl/crypto/primitives/ot:kkrt_ote", - "//yacl/crypto/utils:rand", + "//yacl/crypto/hash:hash_utils", + "//yacl/crypto/rand", + "//yacl/kernels/algorithms:base_ot", + "//yacl/kernels/algorithms:iknp_ote", + "//yacl/kernels/algorithms:kkrt_ote", "//yacl/link", "//yacl/math/f2k", "@com_google_absl//absl/types:span", diff --git a/yacl/crypto/primitives/psu/krtw19_psu.cc b/examples/psu/krtw19_psu.cc similarity index 79% rename from yacl/crypto/primitives/psu/krtw19_psu.cc rename to examples/psu/krtw19_psu.cc index 7a3f69ec..946ceb2d 100644 --- a/yacl/crypto/primitives/psu/krtw19_psu.cc +++ b/examples/psu/krtw19_psu.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/psu/krtw19_psu.h" +#include "examples/psu/krtw19_psu.h" #include #include @@ -22,7 +22,7 @@ #include "yacl/utils/serialize.h" -namespace yacl::crypto { +namespace examples::psu { namespace { @@ -32,12 +32,11 @@ constexpr size_t kBinSize{64ul}; // m+1 constexpr uint128_t kBot{}; constexpr size_t kNumBinsPerBatch{16ul}; constexpr size_t kBatchSize{kNumBinsPerBatch * kBinSize}; - constexpr size_t kNumBaseOT{128ul}; constexpr size_t kNumInkpOT{512ul}; static auto HashToSizeT = [](const uint128_t& x) { - auto hash = Blake3_128({&x, sizeof x}); + auto hash = yacl::crypto::Blake3_128({&x, sizeof x}); size_t ret; std::memcpy(&ret, &hash, sizeof ret); return ret; @@ -56,7 +55,7 @@ auto HashInputs(const std::vector& elem_hashes, size_t count) { uint64_t Evaluate(const std::vector& coeffs, uint64_t x) { uint64_t y{coeffs.back()}; for (auto it = std::next(coeffs.rbegin()); it != coeffs.rend(); ++it) { - y = GfMul64(y, x) ^ *it; + y = yacl::GfMul64(y, x) ^ *it; } return y; } @@ -72,15 +71,16 @@ auto Interpolate(const std::vector& xs, uint64_t prod{1}; for (size_t j{}; j != size; ++j) { if (xs[i] != xs[j]) { - prod = GfMul64(prod, xs[i] ^ xs[j]); + prod = yacl::GfMul64(prod, xs[i] ^ xs[j]); uint64_t sum{}; for (size_t k{}; k != size; ++k) { - sum = std::exchange(Li_coeffs[k], GfMul64(Li_coeffs[k], xs[j]) ^ sum); + sum = std::exchange(Li_coeffs[k], + yacl::GfMul64(Li_coeffs[k], xs[j]) ^ sum); } } } for (size_t k{}; k != size; ++k) { - L_coeffs[k] ^= GfMul64(Li_coeffs[k], Inv64(prod)); + L_coeffs[k] ^= yacl::GfMul64(Li_coeffs[k], yacl::Inv64(prod)); } } return L_coeffs; @@ -90,7 +90,7 @@ auto Interpolate(const std::vector& xs, void KrtwPsuSend(const std::shared_ptr& ctx, const std::vector& elem_hashes) { - ctx->SendAsync(ctx->NextRank(), SerializeUint128(elem_hashes.size()), + ctx->SendAsync(ctx->NextRank(), yacl::SerializeUint128(elem_hashes.size()), "Send set size"); size_t peer_count = DeserializeUint128(ctx->Recv(ctx->PrevRank(), "Receive set size")); @@ -102,11 +102,11 @@ void KrtwPsuSend(const std::shared_ptr& ctx, auto hashing = HashInputs(elem_hashes, count); // Step 2. Prepares OPRF - KkrtOtExtReceiver receiver; + yacl::crypto::KkrtOtExtReceiver receiver; size_t num_ot{hashing.size() * kBinSize}; - auto choice = RandBits(kNumBaseOT); - auto base_ot = BaseOtRecv(ctx, choice, kNumBaseOT); - auto store = IknpOtExtSend(ctx, base_ot, kNumInkpOT); + auto choice = yacl::crypto::RandBits(kNumBaseOT); + auto base_ot = yacl::crypto::BaseOtRecv(ctx, choice, kNumBaseOT); + auto store = yacl::crypto::IknpOtExtSend(ctx, base_ot, kNumInkpOT); receiver.Init(ctx, store, num_ot); receiver.SetBatchSize(kBatchSize); @@ -130,15 +130,16 @@ void KrtwPsuSend(const std::shared_ptr& ctx, auto buf = ctx->Recv(ctx->PrevRank(), "Receive coefficients"); std::memcpy(coeffs.data(), buf.data(), buf.size()); auto y = Evaluate(coeffs, HashToSizeT(elem)) ^ eval; - ctx->SendAsync(ctx->NextRank(), SerializeUint128(y), "Send evaluation"); + ctx->SendAsync(ctx->NextRank(), yacl::SerializeUint128(y), + "Send evaluation"); } } // Step 4. Sends new elements through OT std::vector> keys(num_ot); - choice = SecureRandBits(kNumBaseOT); - base_ot = BaseOtRecv(ctx, choice, kNumBaseOT); - IknpOtExtSend(ctx, base_ot, absl::MakeSpan(keys)); + choice = yacl::crypto::SecureRandBits(kNumBaseOT); + base_ot = yacl::crypto::BaseOtRecv(ctx, choice, kNumBaseOT); + yacl::crypto::IknpOtExtSend(ctx, base_ot, absl::MakeSpan(keys)); std::vector ciphers(num_ot); for (size_t i{}; i != num_ot; ++i) { ciphers[i] = elems[i] ^ keys[i][0]; @@ -154,7 +155,7 @@ std::vector KrtwPsuRecv( const std::vector& elem_hashes) { size_t peer_count = DeserializeUint128(ctx->Recv(ctx->PrevRank(), "Receive set size")); - ctx->SendAsync(ctx->NextRank(), SerializeUint128(elem_hashes.size()), + ctx->SendAsync(ctx->NextRank(), yacl::SerializeUint128(elem_hashes.size()), "Send set size"); auto count = std::max(elem_hashes.size(), peer_count); if (count == 0) { @@ -164,11 +165,11 @@ std::vector KrtwPsuRecv( auto hashing = HashInputs(elem_hashes, count); // Step 2. Prepares OPRF - KkrtOtExtSender sender; + yacl::crypto::KkrtOtExtSender sender; size_t num_ot{hashing.size() * kBinSize}; - auto base_ot = BaseOtSend(ctx, kNumBaseOT); - auto choice = RandBits(kNumInkpOT); - auto store = IknpOtExtRecv(ctx, base_ot, choice, kNumInkpOT); + auto base_ot = yacl::crypto::BaseOtSend(ctx, kNumBaseOT); + auto choice = yacl::crypto::RandBits(kNumInkpOT); + auto store = yacl::crypto::IknpOtExtRecv(ctx, base_ot, choice, kNumInkpOT); sender.Init(ctx, store, num_ot); sender.SetBatchSize(kBatchSize); auto oprf = sender.GetOprf(); @@ -183,27 +184,27 @@ std::vector KrtwPsuRecv( } auto bin_size = hashing[bin_idx].size(); for (size_t elem_idx{}; elem_idx != kBinSize; ++elem_idx, ++oprf_idx) { - auto seed = FastRandU64(); + auto seed = yacl::crypto::FastRandU64(); std::vector xs(kBinSize), ys(kBinSize); for (size_t i{}; i != kBinSize; ++i) { xs[i] = (i < bin_size ? HashToSizeT(hashing[bin_idx][i]) - : i > bin_size ? FastRandU64() + : i > bin_size ? yacl::crypto::FastRandU64() : kBot); ys[i] = oprf->Eval(oprf_idx, xs[i]) ^ seed; } auto coeffs = Interpolate(xs, ys); yacl::Buffer buf(coeffs.data(), coeffs.size() * sizeof(uint64_t)); ctx->SendAsync(ctx->NextRank(), buf, "Send coefficients"); - auto eval = - DeserializeUint128(ctx->Recv(ctx->PrevRank(), "Receive evaluation")); + auto eval = yacl::DeserializeUint128( + ctx->Recv(ctx->PrevRank(), "Receive evaluation")); ot_choice[oprf_idx] = eval == seed; } } // Step 4. Receives new elements through OT std::vector keys(num_ot); - base_ot = BaseOtSend(ctx, kNumBaseOT); - IknpOtExtRecv(ctx, base_ot, ot_choice, absl::MakeSpan(keys)); + base_ot = yacl::crypto::BaseOtSend(ctx, kNumBaseOT); + yacl::crypto::IknpOtExtRecv(ctx, base_ot, ot_choice, absl::MakeSpan(keys)); std::vector ciphers(num_ot); auto buf = ctx->Recv(ctx->PrevRank(), "Receive ciphertexts"); std::memcpy(ciphers.data(), buf.data(), buf.size()); @@ -219,4 +220,4 @@ std::vector KrtwPsuRecv( return std::vector(set_union.begin(), set_union.end()); } -} // namespace yacl::crypto +} // namespace examples::psu diff --git a/yacl/crypto/primitives/psu/krtw19_psu.h b/examples/psu/krtw19_psu.h similarity index 79% rename from yacl/crypto/primitives/psu/krtw19_psu.h rename to examples/psu/krtw19_psu.h index c06535b1..3acdf41a 100644 --- a/yacl/crypto/primitives/psu/krtw19_psu.h +++ b/examples/psu/krtw19_psu.h @@ -18,21 +18,21 @@ #include #include "yacl/base/int128.h" -#include "yacl/crypto/utils/secparam.h" #include "yacl/link/link.h" #include "yacl/math/f2k/f2k.h" +#include "yacl/secparam.h" /* submodules */ -#include "yacl/crypto/base/hash/hash_utils.h" -#include "yacl/crypto/primitives/ot/base_ot.h" -#include "yacl/crypto/primitives/ot/iknp_ote.h" -#include "yacl/crypto/primitives/ot/kkrt_ote.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/hash/hash_utils.h" +#include "yacl/crypto/rand/rand.h" +#include "yacl/kernels/algorithms/base_ot.h" +#include "yacl/kernels/algorithms/iknp_ote.h" +#include "yacl/kernels/algorithms/kkrt_ote.h" /* security parameter declaration */ YACL_MODULE_DECLARE("krtw_psu", SecParam::C::k128, SecParam::S::k40); -namespace yacl::crypto { +namespace examples::psu { // Scalable Private Set Union from Symmetric-Key Techniques // https://eprint.iacr.org/2019/776.pdf (Figure 10) @@ -43,4 +43,4 @@ void KrtwPsuSend(const std::shared_ptr&, std::vector KrtwPsuRecv(const std::shared_ptr&, const std::vector&); -} // namespace yacl::crypto +} // namespace examples::psu diff --git a/yacl/crypto/primitives/psu/krtw19_psu_test.cc b/examples/psu/krtw19_psu_test.cc similarity index 83% rename from yacl/crypto/primitives/psu/krtw19_psu_test.cc rename to examples/psu/krtw19_psu_test.cc index c498b930..915f08be 100644 --- a/yacl/crypto/primitives/psu/krtw19_psu_test.cc +++ b/examples/psu/krtw19_psu_test.cc @@ -12,8 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/psu/krtw19_psu.h" +#include "examples/psu/krtw19_psu.h" +#include #include #include #include @@ -22,16 +23,16 @@ #include "gtest/gtest.h" #include "yacl/base/exception.h" -#include "yacl/crypto/base/hash/hash_utils.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/crypto/hash/hash_utils.h" #include "yacl/link/test_util.h" +#include "yacl/secparam.h" struct TestParams { std::vector items_a; std::vector items_b; }; -namespace yacl::crypto { +namespace examples::psu { class KrtwPsuTest : public testing::TestWithParam {}; @@ -60,7 +61,7 @@ TEST_P(KrtwPsuTest, Works) { std::vector CreateRangeItems(size_t begin, size_t size) { std::vector ret; for (size_t i = 0; i < size; i++) { - ret.push_back(Blake3_128(std::to_string(begin + i))); + ret.push_back(yacl::crypto::Blake3_128(std::to_string(begin + i))); } return ret; } @@ -68,9 +69,9 @@ std::vector CreateRangeItems(size_t begin, size_t size) { INSTANTIATE_TEST_SUITE_P( Works_Instances, KrtwPsuTest, testing::Values( - TestParams{{}, {}}, // - TestParams{{}, {Blake3_128("a")}}, // - TestParams{{Blake3_128("a")}, {}}, // + TestParams{{}, {}}, // + TestParams{{}, {yacl::crypto::Blake3_128("a")}}, // + TestParams{{yacl::crypto::Blake3_128("a")}, {}}, // // No overlap TestParams{CreateRangeItems(0, 1024), CreateRangeItems(1024, 1024)}, // // Partial overlap @@ -79,4 +80,4 @@ INSTANTIATE_TEST_SUITE_P( TestParams{CreateRangeItems(0, 1024), CreateRangeItems(0, 1024)} // )); -} // namespace yacl::crypto +} // namespace examples::psu diff --git a/yacl/BUILD.bazel b/yacl/BUILD.bazel new file mode 100644 index 00000000..77d192f0 --- /dev/null +++ b/yacl/BUILD.bazel @@ -0,0 +1,39 @@ +# Copyright 2022 Ant Group Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("//bazel:yacl.bzl", "yacl_cc_library", "yacl_cc_test") + +package(default_visibility = ["//visibility:public"]) + +yacl_cc_library( + name = "secparam", + srcs = ["secparam.cc"], + hdrs = [ + "secparam.h", + ], + deps = [ + "//yacl/base:exception", + "//yacl/base:int128", + "//yacl/math:gadget", + "//yacl/utils:compile_time_utils", + ], +) + +yacl_cc_test( + name = "secparam_test", + srcs = ["secparam_test.cc"], + deps = [ + ":secparam", + ], +) diff --git a/yacl/base/BUILD.bazel b/yacl/base/BUILD.bazel index d218a616..163ad110 100644 --- a/yacl/base/BUILD.bazel +++ b/yacl/base/BUILD.bazel @@ -147,8 +147,8 @@ yacl_cc_test( # copts = ["-fno-rtti"], # for testing uint128_t deps = [ ":dynamic_bitset", + "//yacl/crypto/rand", "//yacl/crypto/tools:prg", - "//yacl/crypto/utils:rand", ], ) diff --git a/yacl/base/dynamic_bitset_test.cc b/yacl/base/dynamic_bitset_test.cc index 352207a0..d0dcd501 100644 --- a/yacl/base/dynamic_bitset_test.cc +++ b/yacl/base/dynamic_bitset_test.cc @@ -19,8 +19,8 @@ #include "gtest/gtest.h" #include "yacl/base/exception.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/prg.h" -#include "yacl/crypto/utils/rand.h" namespace yacl { diff --git a/yacl/base/exception.h b/yacl/base/exception.h index c3ea26e3..f7aa9929 100644 --- a/yacl/base/exception.h +++ b/yacl/base/exception.h @@ -135,6 +135,10 @@ class InvalidFormat : public IoError { using IoError::IoError; }; +class LinkAborted : public IoError { + using IoError::IoError; +}; + class NetworkError : public IoError { using IoError::IoError; }; @@ -193,6 +197,9 @@ std::string GetStacktraceString(); #define YACL_THROW_IO_ERROR(...) \ YACL_THROW_HELPER(::yacl::IoError, false, __VA_ARGS__) +#define YACL_THROW_LINK_ABORTED(...) \ + YACL_THROW_HELPER(::yacl::LinkAborted, false, __VA_ARGS__) + #define YACL_THROW_NETWORK_ERROR(...) \ YACL_THROW_HELPER(::yacl::NetworkError, false, __VA_ARGS__) diff --git a/yacl/crypto/base/BUILD.bazel b/yacl/crypto/BUILD.bazel similarity index 85% rename from yacl/crypto/base/BUILD.bazel rename to yacl/crypto/BUILD.bazel index 80e9a13d..31c0f59e 100644 --- a/yacl/crypto/base/BUILD.bazel +++ b/yacl/crypto/BUILD.bazel @@ -24,7 +24,7 @@ yacl_cc_library( deps = [ "//yacl/base:byte_container_view", "//yacl/base:exception", - "//yacl/crypto/base/hash:hash_interface", + "//yacl/crypto/hash:hash_interface", "//yacl/utils:scope_guard", "@com_github_openssl_openssl//:openssl", ], @@ -38,7 +38,7 @@ yacl_cc_library( ], deps = [ ":openssl_wrappers", - "//yacl/crypto/utils:secparam", + "//yacl:secparam", "//yacl/io/stream", ], ) @@ -48,7 +48,7 @@ yacl_cc_test( srcs = ["key_utils_test.cc"], deps = [ ":key_utils", - "//yacl/crypto/base/pke:asymmetric_rsa_crypto", # for test - "//yacl/crypto/base/sign:rsa_signing", # for test + "//yacl/crypto/pke:asymmetric_rsa_crypto", # for test + "//yacl/crypto/sign:rsa_signing", # for test ], ) diff --git a/yacl/crypto/base/aead/BUILD.bazel b/yacl/crypto/aead/BUILD.bazel similarity index 81% rename from yacl/crypto/base/aead/BUILD.bazel rename to yacl/crypto/aead/BUILD.bazel index c736b531..9775456b 100644 --- a/yacl/crypto/base/aead/BUILD.bazel +++ b/yacl/crypto/aead/BUILD.bazel @@ -21,9 +21,9 @@ yacl_cc_library( srcs = ["gcm_crypto.cc"], hdrs = ["gcm_crypto.h"], deps = [ + "//yacl:secparam", "//yacl/base:int128", - "//yacl/crypto/base:key_utils", - "//yacl/crypto/utils:secparam", + "//yacl/crypto:key_utils", ], ) @@ -40,10 +40,10 @@ yacl_cc_library( srcs = ["sm4_mac.cc"], hdrs = ["sm4_mac.h"], deps = [ - "//yacl/crypto/base/block_cipher:symmetric_crypto", - "//yacl/crypto/base/hash:ssl_hash", - "//yacl/crypto/base/hmac:hmac_sm3", - "//yacl/crypto/utils:secparam", + "//yacl:secparam", + "//yacl/crypto/block_cipher:symmetric_crypto", + "//yacl/crypto/hash:ssl_hash", + "//yacl/crypto/hmac:hmac_sm3", ], ) diff --git a/yacl/crypto/base/aead/gcm_crypto.cc b/yacl/crypto/aead/gcm_crypto.cc similarity index 97% rename from yacl/crypto/base/aead/gcm_crypto.cc rename to yacl/crypto/aead/gcm_crypto.cc index c183879e..92df763a 100644 --- a/yacl/crypto/base/aead/gcm_crypto.cc +++ b/yacl/crypto/aead/gcm_crypto.cc @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/aead/gcm_crypto.h" +#include "yacl/crypto/aead/gcm_crypto.h" -#include "yacl/crypto/base/openssl_wrappers.h" +#include "yacl/crypto/openssl_wrappers.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/aead/gcm_crypto.h b/yacl/crypto/aead/gcm_crypto.h similarity index 98% rename from yacl/crypto/base/aead/gcm_crypto.h rename to yacl/crypto/aead/gcm_crypto.h index 61cc8edf..031bd912 100644 --- a/yacl/crypto/base/aead/gcm_crypto.h +++ b/yacl/crypto/aead/gcm_crypto.h @@ -19,7 +19,7 @@ #include "absl/types/span.h" #include "yacl/base/byte_container_view.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/secparam.h" /* security parameter declaration */ YACL_MODULE_DECLARE("aes_gcm", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/base/aead/gcm_crypto_test.cc b/yacl/crypto/aead/gcm_crypto_test.cc similarity index 98% rename from yacl/crypto/base/aead/gcm_crypto_test.cc rename to yacl/crypto/aead/gcm_crypto_test.cc index f4247ec5..821f885d 100644 --- a/yacl/crypto/base/aead/gcm_crypto_test.cc +++ b/yacl/crypto/aead/gcm_crypto_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/aead/gcm_crypto.h" +#include "yacl/crypto/aead/gcm_crypto.h" #include #include diff --git a/yacl/crypto/base/aead/sm4_mac.cc b/yacl/crypto/aead/sm4_mac.cc similarity index 98% rename from yacl/crypto/base/aead/sm4_mac.cc rename to yacl/crypto/aead/sm4_mac.cc index e170f211..bd94c5e5 100644 --- a/yacl/crypto/base/aead/sm4_mac.cc +++ b/yacl/crypto/aead/sm4_mac.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/aead/sm4_mac.h" +#include "yacl/crypto/aead/sm4_mac.h" #include "yacl/base/exception.h" diff --git a/yacl/crypto/base/aead/sm4_mac.h b/yacl/crypto/aead/sm4_mac.h similarity index 89% rename from yacl/crypto/base/aead/sm4_mac.h rename to yacl/crypto/aead/sm4_mac.h index f0fffd25..ff7b72d3 100644 --- a/yacl/crypto/base/aead/sm4_mac.h +++ b/yacl/crypto/aead/sm4_mac.h @@ -17,12 +17,12 @@ #include #include "yacl/base/byte_container_view.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/secparam.h" /* submodules */ -#include "yacl/crypto/base/block_cipher/symmetric_crypto.h" -#include "yacl/crypto/base/hash/ssl_hash.h" -#include "yacl/crypto/base/hmac/hmac_sm3.h" +#include "yacl/crypto/block_cipher/symmetric_crypto.h" +#include "yacl/crypto/hash/ssl_hash.h" +#include "yacl/crypto/hmac/hmac_sm3.h" /* security parameter declaration */ YACL_MODULE_DECLARE("sm4_mac", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/base/aead/sm4_mac_test.cc b/yacl/crypto/aead/sm4_mac_test.cc similarity index 96% rename from yacl/crypto/base/aead/sm4_mac_test.cc rename to yacl/crypto/aead/sm4_mac_test.cc index 034c03e4..9184bb61 100644 --- a/yacl/crypto/base/aead/sm4_mac_test.cc +++ b/yacl/crypto/aead/sm4_mac_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/aead/sm4_mac.h" +#include "yacl/crypto/aead/sm4_mac.h" #include "gtest/gtest.h" diff --git a/yacl/crypto/base/aes/BUILD.bazel b/yacl/crypto/aes/BUILD.bazel similarity index 95% rename from yacl/crypto/base/aes/BUILD.bazel rename to yacl/crypto/aes/BUILD.bazel index 2b262a5e..537b06fa 100644 --- a/yacl/crypto/base/aes/BUILD.bazel +++ b/yacl/crypto/aes/BUILD.bazel @@ -22,8 +22,8 @@ yacl_cc_binary( copts = AES_COPT_FLAGS, deps = [ ":aes_opt", + "//yacl/crypto/rand", "//yacl/crypto/tools:prg", - "//yacl/crypto/utils:rand", "@com_github_google_benchmark//:benchmark_main", ], ) @@ -35,8 +35,8 @@ yacl_cc_library( ], copts = AES_COPT_FLAGS, deps = [ + "//yacl:secparam", "//yacl/base:int128", - "//yacl/crypto/utils:secparam", ] + select({ "@platforms//cpu:aarch64": [ "@com_github_dltcollab_sse2neon//:sse2neon", diff --git a/yacl/crypto/base/aes/aes_bench.cc b/yacl/crypto/aes/aes_bench.cc similarity index 97% rename from yacl/crypto/base/aes/aes_bench.cc rename to yacl/crypto/aes/aes_bench.cc index b364b22a..54ce234e 100644 --- a/yacl/crypto/base/aes/aes_bench.cc +++ b/yacl/crypto/aes/aes_bench.cc @@ -18,9 +18,9 @@ #include "benchmark/benchmark.h" -#include "yacl/crypto/base/aes/aes_opt.h" +#include "yacl/crypto/aes/aes_opt.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/prg.h" -#include "yacl/crypto/utils/rand.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/aes/aes_intrinsics.h b/yacl/crypto/aes/aes_intrinsics.h similarity index 99% rename from yacl/crypto/base/aes/aes_intrinsics.h rename to yacl/crypto/aes/aes_intrinsics.h index dde69d7c..d075b364 100644 --- a/yacl/crypto/base/aes/aes_intrinsics.h +++ b/yacl/crypto/aes/aes_intrinsics.h @@ -56,7 +56,7 @@ #include "yacl/base/exception.h" #include "yacl/base/int128.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/secparam.h" #ifndef __aarch64__ // sse diff --git a/yacl/crypto/base/aes/aes_opt.h b/yacl/crypto/aes/aes_opt.h similarity index 99% rename from yacl/crypto/base/aes/aes_opt.h rename to yacl/crypto/aes/aes_opt.h index b2805303..fe92e349 100644 --- a/yacl/crypto/base/aes/aes_opt.h +++ b/yacl/crypto/aes/aes_opt.h @@ -28,7 +28,7 @@ #pragma once -#include "yacl/crypto/base/aes/aes_intrinsics.h" +#include "yacl/crypto/aes/aes_intrinsics.h" namespace yacl::crypto { template diff --git a/yacl/crypto/base/aes/aes_test.cc b/yacl/crypto/aes/aes_test.cc similarity index 98% rename from yacl/crypto/base/aes/aes_test.cc rename to yacl/crypto/aes/aes_test.cc index 09c3b453..c63e38d4 100644 --- a/yacl/crypto/base/aes/aes_test.cc +++ b/yacl/crypto/aes/aes_test.cc @@ -18,7 +18,7 @@ #include "gtest/gtest.h" #include "yacl/base/exception.h" -#include "yacl/crypto/base/aes/aes_intrinsics.h" +#include "yacl/crypto/aes/aes_intrinsics.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/block_cipher/BUILD.bazel b/yacl/crypto/block_cipher/BUILD.bazel similarity index 92% rename from yacl/crypto/base/block_cipher/BUILD.bazel rename to yacl/crypto/block_cipher/BUILD.bazel index 741568b6..2addcd4e 100644 --- a/yacl/crypto/base/block_cipher/BUILD.bazel +++ b/yacl/crypto/block_cipher/BUILD.bazel @@ -26,9 +26,9 @@ yacl_cc_library( ], copts = AES_COPT_FLAGS, deps = [ + "//yacl:secparam", "//yacl/base:int128", - "//yacl/crypto/base:openssl_wrappers", - "//yacl/crypto/utils:secparam", + "//yacl/crypto:openssl_wrappers", ], ) diff --git a/yacl/crypto/base/block_cipher/symmetric_crypto.cc b/yacl/crypto/block_cipher/symmetric_crypto.cc similarity index 98% rename from yacl/crypto/base/block_cipher/symmetric_crypto.cc rename to yacl/crypto/block_cipher/symmetric_crypto.cc index 7cfb0457..6bec5c3f 100644 --- a/yacl/crypto/base/block_cipher/symmetric_crypto.cc +++ b/yacl/crypto/block_cipher/symmetric_crypto.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/block_cipher/symmetric_crypto.h" +#include "yacl/crypto/block_cipher/symmetric_crypto.h" #include #include @@ -21,7 +21,7 @@ #include "spdlog/spdlog.h" #include "yacl/base/exception.h" -#include "yacl/crypto/base/openssl_wrappers.h" +#include "yacl/crypto/openssl_wrappers.h" namespace yacl::crypto { namespace { diff --git a/yacl/crypto/base/block_cipher/symmetric_crypto.h b/yacl/crypto/block_cipher/symmetric_crypto.h similarity index 97% rename from yacl/crypto/base/block_cipher/symmetric_crypto.h rename to yacl/crypto/block_cipher/symmetric_crypto.h index 863852e8..004d9f77 100644 --- a/yacl/crypto/base/block_cipher/symmetric_crypto.h +++ b/yacl/crypto/block_cipher/symmetric_crypto.h @@ -25,8 +25,8 @@ #include "yacl/base/byte_container_view.h" #include "yacl/base/int128.h" -#include "yacl/crypto/base/openssl_wrappers.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/secparam.h" /* security parameter declaration */ YACL_MODULE_DECLARE("aes_all_modes", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/base/block_cipher/symmetric_crypto_test.cc b/yacl/crypto/block_cipher/symmetric_crypto_test.cc similarity index 99% rename from yacl/crypto/base/block_cipher/symmetric_crypto_test.cc rename to yacl/crypto/block_cipher/symmetric_crypto_test.cc index 720ae2fd..d943936a 100644 --- a/yacl/crypto/base/block_cipher/symmetric_crypto_test.cc +++ b/yacl/crypto/block_cipher/symmetric_crypto_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/block_cipher/symmetric_crypto.h" +#include "yacl/crypto/block_cipher/symmetric_crypto.h" #include #include diff --git a/yacl/crypto/dpf/BUILD.bazel b/yacl/crypto/dpf/BUILD.bazel new file mode 100644 index 00000000..6bafccff --- /dev/null +++ b/yacl/crypto/dpf/BUILD.bazel @@ -0,0 +1,36 @@ +# Copyright 2022 Ant Group Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("//bazel:yacl.bzl", "yacl_cc_library", "yacl_cc_test") + +package(default_visibility = ["//visibility:public"]) + +yacl_cc_library( + name = "dpf", + srcs = ["dpf.cc"], + hdrs = ["dpf.h"], + deps = [ + "//yacl/base:int128", + "//yacl/crypto/tools:prg", + "//yacl/link", + ], +) + +yacl_cc_test( + name = "dpf_test", + srcs = ["dpf_test.cc"], + deps = [ + ":dpf", + ], +) diff --git a/yacl/crypto/primitives/dpf/dpf.cc b/yacl/crypto/dpf/dpf.cc similarity index 99% rename from yacl/crypto/primitives/dpf/dpf.cc rename to yacl/crypto/dpf/dpf.cc index dd0c7650..de27e5c3 100644 --- a/yacl/crypto/primitives/dpf/dpf.cc +++ b/yacl/crypto/dpf/dpf.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/dpf/dpf.h" +#include "yacl/crypto/dpf/dpf.h" #include diff --git a/yacl/crypto/primitives/dpf/dpf.h b/yacl/crypto/dpf/dpf.h similarity index 100% rename from yacl/crypto/primitives/dpf/dpf.h rename to yacl/crypto/dpf/dpf.h diff --git a/yacl/crypto/primitives/dpf/dpf_test.cc b/yacl/crypto/dpf/dpf_test.cc similarity index 99% rename from yacl/crypto/primitives/dpf/dpf_test.cc rename to yacl/crypto/dpf/dpf_test.cc index 01132366..f7cd0dd4 100644 --- a/yacl/crypto/primitives/dpf/dpf_test.cc +++ b/yacl/crypto/dpf/dpf_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/dpf/dpf.h" +#include "yacl/crypto/dpf/dpf.h" #include #include diff --git a/yacl/crypto/base/ecc/BUILD.bazel b/yacl/crypto/ecc/BUILD.bazel similarity index 91% rename from yacl/crypto/base/ecc/BUILD.bazel rename to yacl/crypto/ecc/BUILD.bazel index 9cc97893..0ce5416d 100644 --- a/yacl/crypto/base/ecc/BUILD.bazel +++ b/yacl/crypto/ecc/BUILD.bazel @@ -19,10 +19,10 @@ package(default_visibility = ["//visibility:public"]) yacl_cc_library( name = "ecc", deps = [ - "//yacl/crypto/base/ecc/libsodium", - "//yacl/crypto/base/ecc/mcl:ecc", - "//yacl/crypto/base/ecc/openssl", - "//yacl/crypto/base/ecc/toy", + "//yacl/crypto/ecc/libsodium", + "//yacl/crypto/ecc/mcl:ecc", + "//yacl/crypto/ecc/openssl", + "//yacl/crypto/ecc/toy", ], ) diff --git a/yacl/crypto/base/ecc/any_ptr.h b/yacl/crypto/ecc/any_ptr.h similarity index 100% rename from yacl/crypto/base/ecc/any_ptr.h rename to yacl/crypto/ecc/any_ptr.h diff --git a/yacl/crypto/base/ecc/benchmark/BUILD.bazel b/yacl/crypto/ecc/benchmark/BUILD.bazel similarity index 90% rename from yacl/crypto/base/ecc/benchmark/BUILD.bazel rename to yacl/crypto/ecc/benchmark/BUILD.bazel index 4587e050..8c0c3685 100644 --- a/yacl/crypto/base/ecc/benchmark/BUILD.bazel +++ b/yacl/crypto/ecc/benchmark/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//bazel:yacl.bzl", "yacl_cc_binary", "yacl_cc_library") +load("//bazel:yacl.bzl", "yacl_cc_binary") package(default_visibility = ["//visibility:public"]) @@ -20,7 +20,7 @@ yacl_cc_binary( name = "benchmark", srcs = ["bench_ecc.cc"], deps = [ - "//yacl/crypto/base/ecc", + "//yacl/crypto/ecc", "@com_github_gflags_gflags//:gflags", "@com_github_google_benchmark//:benchmark", "@com_google_absl//absl/strings", diff --git a/yacl/crypto/base/ecc/benchmark/bench_ecc.cc b/yacl/crypto/ecc/benchmark/bench_ecc.cc similarity index 99% rename from yacl/crypto/base/ecc/benchmark/bench_ecc.cc rename to yacl/crypto/ecc/benchmark/bench_ecc.cc index e9c6c03d..8b77e4a7 100644 --- a/yacl/crypto/base/ecc/benchmark/bench_ecc.cc +++ b/yacl/crypto/ecc/benchmark/bench_ecc.cc @@ -16,7 +16,7 @@ #include "benchmark/benchmark.h" #include "gflags/gflags.h" -#include "yacl/crypto/base/ecc/ecc_spi.h" +#include "yacl/crypto/ecc/ecc_spi.h" #include "yacl/utils/spi/spi_factory.h" namespace yacl::crypto::bench { diff --git a/yacl/crypto/base/ecc/curve_meta.cc b/yacl/crypto/ecc/curve_meta.cc similarity index 99% rename from yacl/crypto/base/ecc/curve_meta.cc rename to yacl/crypto/ecc/curve_meta.cc index a9ce1624..a3e3d710 100644 --- a/yacl/crypto/base/ecc/curve_meta.cc +++ b/yacl/crypto/ecc/curve_meta.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/ecc/curve_meta.h" +#include "yacl/crypto/ecc/curve_meta.h" #include diff --git a/yacl/crypto/base/ecc/curve_meta.h b/yacl/crypto/ecc/curve_meta.h similarity index 100% rename from yacl/crypto/base/ecc/curve_meta.h rename to yacl/crypto/ecc/curve_meta.h diff --git a/yacl/crypto/base/ecc/ec_point.cc b/yacl/crypto/ecc/ec_point.cc similarity index 97% rename from yacl/crypto/base/ecc/ec_point.cc rename to yacl/crypto/ecc/ec_point.cc index 474a5a3e..6df498e3 100644 --- a/yacl/crypto/base/ecc/ec_point.cc +++ b/yacl/crypto/ecc/ec_point.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/ecc/ec_point.h" +#include "yacl/crypto/ecc/ec_point.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/ecc/ec_point.h b/yacl/crypto/ecc/ec_point.h similarity index 98% rename from yacl/crypto/base/ecc/ec_point.h rename to yacl/crypto/ecc/ec_point.h index 83d9d6d1..907299b8 100644 --- a/yacl/crypto/base/ecc/ec_point.h +++ b/yacl/crypto/ecc/ec_point.h @@ -17,7 +17,7 @@ #include #include -#include "yacl/crypto/base/ecc/any_ptr.h" +#include "yacl/crypto/ecc/any_ptr.h" #include "yacl/math/mpint/mp_int.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/ecc/ecc_spi.cc b/yacl/crypto/ecc/ecc_spi.cc similarity index 97% rename from yacl/crypto/base/ecc/ecc_spi.cc rename to yacl/crypto/ecc/ecc_spi.cc index 2b3f066d..8408038e 100644 --- a/yacl/crypto/base/ecc/ecc_spi.cc +++ b/yacl/crypto/ecc/ecc_spi.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/ecc/ecc_spi.h" +#include "yacl/crypto/ecc/ecc_spi.h" #include "absl/strings/ascii.h" diff --git a/yacl/crypto/base/ecc/ecc_spi.h b/yacl/crypto/ecc/ecc_spi.h similarity index 98% rename from yacl/crypto/base/ecc/ecc_spi.h rename to yacl/crypto/ecc/ecc_spi.h index b5a91c0f..19c2dc13 100644 --- a/yacl/crypto/base/ecc/ecc_spi.h +++ b/yacl/crypto/ecc/ecc_spi.h @@ -20,8 +20,8 @@ #include #include "yacl/base/byte_container_view.h" -#include "yacl/crypto/base/ecc/curve_meta.h" -#include "yacl/crypto/base/ecc/ec_point.h" +#include "yacl/crypto/ecc/curve_meta.h" +#include "yacl/crypto/ecc/ec_point.h" #include "yacl/math/mpint/mp_int.h" #include "yacl/utils/spi/spi_factory.h" @@ -316,7 +316,7 @@ class EcGroupFactory final : public SpiFactoryBase { }; // Please run bazel run -// > yacl/crypto/base/ecc/benchmark -c opt -- --curve CURVE_NAME +// > yacl/crypto/ecc/benchmark -c opt -- --curve CURVE_NAME // to test your lib's performance. // We assume that the performance of OpenSSL is 100, if your library is better // than OpenSSL, please increase the 'performance' value. diff --git a/yacl/crypto/base/ecc/ecc_test.cc b/yacl/crypto/ecc/ecc_test.cc similarity index 99% rename from yacl/crypto/base/ecc/ecc_test.cc rename to yacl/crypto/ecc/ecc_test.cc index 5a999d39..d0eaf358 100644 --- a/yacl/crypto/base/ecc/ecc_test.cc +++ b/yacl/crypto/ecc/ecc_test.cc @@ -20,7 +20,7 @@ #include "fmt/ranges.h" #include "gtest/gtest.h" -#include "yacl/crypto/base/ecc/ecc_spi.h" +#include "yacl/crypto/ecc/ecc_spi.h" #include "yacl/utils/parallel.h" #include "yacl/utils/spi/spi_factory.h" diff --git a/yacl/crypto/base/ecc/group_sketch.cc b/yacl/crypto/ecc/group_sketch.cc similarity index 97% rename from yacl/crypto/base/ecc/group_sketch.cc rename to yacl/crypto/ecc/group_sketch.cc index 41d97158..8a2f85f4 100644 --- a/yacl/crypto/base/ecc/group_sketch.cc +++ b/yacl/crypto/ecc/group_sketch.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/ecc/group_sketch.h" +#include "yacl/crypto/ecc/group_sketch.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/ecc/group_sketch.h b/yacl/crypto/ecc/group_sketch.h similarity index 98% rename from yacl/crypto/base/ecc/group_sketch.h rename to yacl/crypto/ecc/group_sketch.h index 5dce8b04..7f810728 100644 --- a/yacl/crypto/base/ecc/group_sketch.h +++ b/yacl/crypto/ecc/group_sketch.h @@ -13,7 +13,7 @@ // limitations under the License. #pragma once -#include "yacl/crypto/base/ecc/ecc_spi.h" +#include "yacl/crypto/ecc/ecc_spi.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/ecc/libsodium/BUILD.bazel b/yacl/crypto/ecc/libsodium/BUILD.bazel similarity index 94% rename from yacl/crypto/base/ecc/libsodium/BUILD.bazel rename to yacl/crypto/ecc/libsodium/BUILD.bazel index 383b73e8..f6b9af5f 100644 --- a/yacl/crypto/base/ecc/libsodium/BUILD.bazel +++ b/yacl/crypto/ecc/libsodium/BUILD.bazel @@ -37,8 +37,8 @@ yacl_cc_library( "sodium_private.h", ], deps = [ - "//yacl/crypto/base/ecc:spi", - "//yacl/crypto/base/hash:ssl_hash", + "//yacl/crypto/ecc:spi", + "//yacl/crypto/hash:ssl_hash", "@com_github_libsodium//:libsodium", "@yacl//yacl/utils:parallel", ], diff --git a/yacl/crypto/base/ecc/libsodium/ed25519_group.cc b/yacl/crypto/ecc/libsodium/ed25519_group.cc similarity index 98% rename from yacl/crypto/base/ecc/libsodium/ed25519_group.cc rename to yacl/crypto/ecc/libsodium/ed25519_group.cc index 52d9be8c..f23c52f8 100644 --- a/yacl/crypto/base/ecc/libsodium/ed25519_group.cc +++ b/yacl/crypto/ecc/libsodium/ed25519_group.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/ecc/libsodium/ed25519_group.h" +#include "yacl/crypto/ecc/libsodium/ed25519_group.h" #include diff --git a/yacl/crypto/base/ecc/libsodium/ed25519_group.h b/yacl/crypto/ecc/libsodium/ed25519_group.h similarity index 95% rename from yacl/crypto/base/ecc/libsodium/ed25519_group.h rename to yacl/crypto/ecc/libsodium/ed25519_group.h index f60079fb..10ebe9a8 100644 --- a/yacl/crypto/base/ecc/libsodium/ed25519_group.h +++ b/yacl/crypto/ecc/libsodium/ed25519_group.h @@ -14,8 +14,8 @@ #pragma once -#include "yacl/crypto/base/ecc/ec_point.h" -#include "yacl/crypto/base/ecc/libsodium/sodium_group.h" +#include "yacl/crypto/ecc/ec_point.h" +#include "yacl/crypto/ecc/libsodium/sodium_group.h" namespace yacl::crypto::sodium { diff --git a/yacl/crypto/base/ecc/libsodium/ed25519_test.cc b/yacl/crypto/ecc/libsodium/ed25519_test.cc similarity index 97% rename from yacl/crypto/base/ecc/libsodium/ed25519_test.cc rename to yacl/crypto/ecc/libsodium/ed25519_test.cc index 4b026d21..34ae5697 100644 --- a/yacl/crypto/base/ecc/libsodium/ed25519_test.cc +++ b/yacl/crypto/ecc/libsodium/ed25519_test.cc @@ -19,9 +19,9 @@ #include "gtest/gtest.h" #include "sodium/crypto_scalarmult_ed25519.h" -#include "yacl/crypto/base/ecc/ec_point.h" -#include "yacl/crypto/base/ecc/ecc_spi.h" -#include "yacl/crypto/base/ecc/libsodium/ed25519_group.h" +#include "yacl/crypto/ecc/ec_point.h" +#include "yacl/crypto/ecc/ecc_spi.h" +#include "yacl/crypto/ecc/libsodium/ed25519_group.h" #include "yacl/utils/spi/spi_factory.h" namespace yacl::crypto::sodium { diff --git a/yacl/crypto/base/ecc/libsodium/sodium_factory.cc b/yacl/crypto/ecc/libsodium/sodium_factory.cc similarity index 96% rename from yacl/crypto/base/ecc/libsodium/sodium_factory.cc rename to yacl/crypto/ecc/libsodium/sodium_factory.cc index 912e12fa..6b910a6a 100644 --- a/yacl/crypto/base/ecc/libsodium/sodium_factory.cc +++ b/yacl/crypto/ecc/libsodium/sodium_factory.cc @@ -14,7 +14,7 @@ #include -#include "yacl/crypto/base/ecc/libsodium/ed25519_group.h" +#include "yacl/crypto/ecc/libsodium/ed25519_group.h" namespace yacl::crypto::sodium { diff --git a/yacl/crypto/base/ecc/libsodium/sodium_group.cc b/yacl/crypto/ecc/libsodium/sodium_group.cc similarity index 99% rename from yacl/crypto/base/ecc/libsodium/sodium_group.cc rename to yacl/crypto/ecc/libsodium/sodium_group.cc index 7f79cab3..f57bd326 100644 --- a/yacl/crypto/base/ecc/libsodium/sodium_group.cc +++ b/yacl/crypto/ecc/libsodium/sodium_group.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/ecc/libsodium/sodium_group.h" +#include "yacl/crypto/ecc/libsodium/sodium_group.h" #include #include diff --git a/yacl/crypto/base/ecc/libsodium/sodium_group.h b/yacl/crypto/ecc/libsodium/sodium_group.h similarity index 93% rename from yacl/crypto/base/ecc/libsodium/sodium_group.h rename to yacl/crypto/ecc/libsodium/sodium_group.h index 11c18165..7fdeee46 100644 --- a/yacl/crypto/base/ecc/libsodium/sodium_group.h +++ b/yacl/crypto/ecc/libsodium/sodium_group.h @@ -18,9 +18,9 @@ #include #include "yacl/base/buffer.h" -#include "yacl/crypto/base/ecc/ec_point.h" -#include "yacl/crypto/base/ecc/group_sketch.h" -#include "yacl/crypto/base/ecc/libsodium/sodium_private.h" +#include "yacl/crypto/ecc/ec_point.h" +#include "yacl/crypto/ecc/group_sketch.h" +#include "yacl/crypto/ecc/libsodium/sodium_private.h" namespace yacl::crypto::sodium { diff --git a/yacl/crypto/base/ecc/libsodium/sodium_private.h b/yacl/crypto/ecc/libsodium/sodium_private.h similarity index 100% rename from yacl/crypto/base/ecc/libsodium/sodium_private.h rename to yacl/crypto/ecc/libsodium/sodium_private.h diff --git a/yacl/crypto/base/ecc/mcl/BUILD.bazel b/yacl/crypto/ecc/mcl/BUILD.bazel similarity index 87% rename from yacl/crypto/base/ecc/mcl/BUILD.bazel rename to yacl/crypto/ecc/mcl/BUILD.bazel index 3ff1d7e8..5d5de5fa 100644 --- a/yacl/crypto/base/ecc/mcl/BUILD.bazel +++ b/yacl/crypto/ecc/mcl/BUILD.bazel @@ -25,10 +25,10 @@ yacl_cc_library( hdrs = ["mcl_ec_group.h"], deps = [ ":util", - "//yacl/crypto/base/ecc:spi", - "//yacl/crypto/base/hash:blake3", - "//yacl/crypto/base/hash:ssl_hash", - "//yacl/crypto/base/pairing/mcl:pairing_header", + "//yacl/crypto/ecc:spi", + "//yacl/crypto/hash:blake3", + "//yacl/crypto/hash:ssl_hash", + "//yacl/crypto/pairing/mcl:pairing_header", ], alwayslink = 1, ) diff --git a/yacl/crypto/base/ecc/mcl/mcl_ec_factory.cc b/yacl/crypto/ecc/mcl/mcl_ec_factory.cc similarity index 95% rename from yacl/crypto/base/ecc/mcl/mcl_ec_factory.cc rename to yacl/crypto/ecc/mcl/mcl_ec_factory.cc index fac546cb..b9cf14e9 100644 --- a/yacl/crypto/base/ecc/mcl/mcl_ec_factory.cc +++ b/yacl/crypto/ecc/mcl/mcl_ec_factory.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/ecc/mcl/mcl_ec_group.h" +#include "yacl/crypto/ecc/mcl/mcl_ec_group.h" namespace yacl::crypto::hmcl { @@ -20,7 +20,7 @@ std::map Name2MclCurveEnum = { {"secp192k1", MCL_SECP192K1}, {"secp224k1", MCL_SECP224K1}, {"secp256k1", MCL_SECP256K1}, - // Same as NIST_P384, more info see yacl/crypto/base/ecc/curve_meta.cc + // Same as NIST_P384, more info see yacl/crypto/ecc/curve_meta.cc {"secp384r1", MCL_SECP384R1}, {"secp192r1", MCL_NIST_P192}, {"secp224r1", MCL_NIST_P224}, diff --git a/yacl/crypto/base/ecc/mcl/mcl_ec_group.cc b/yacl/crypto/ecc/mcl/mcl_ec_group.cc similarity index 98% rename from yacl/crypto/base/ecc/mcl/mcl_ec_group.cc rename to yacl/crypto/ecc/mcl/mcl_ec_group.cc index 7fa2d129..50564e5b 100644 --- a/yacl/crypto/base/ecc/mcl/mcl_ec_group.cc +++ b/yacl/crypto/ecc/mcl/mcl_ec_group.cc @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/ecc/mcl/mcl_ec_group.h" +#include "yacl/crypto/ecc/mcl/mcl_ec_group.h" -#include "yacl/crypto/base/ecc/mcl/mcl_util.h" -#include "yacl/crypto/base/hash/blake3.h" -#include "yacl/crypto/base/pairing/mcl/pairing_header.h" +#include "yacl/crypto/ecc/mcl/mcl_util.h" +#include "yacl/crypto/hash/blake3.h" +#include "yacl/crypto/pairing/mcl/pairing_header.h" namespace yacl::crypto::hmcl { diff --git a/yacl/crypto/base/ecc/mcl/mcl_ec_group.h b/yacl/crypto/ecc/mcl/mcl_ec_group.h similarity index 98% rename from yacl/crypto/base/ecc/mcl/mcl_ec_group.h rename to yacl/crypto/ecc/mcl/mcl_ec_group.h index c383f3aa..d8314089 100644 --- a/yacl/crypto/base/ecc/mcl/mcl_ec_group.h +++ b/yacl/crypto/ecc/mcl/mcl_ec_group.h @@ -16,8 +16,8 @@ #include "mcl/ec.hpp" -#include "yacl/crypto/base/ecc/group_sketch.h" -#include "yacl/crypto/base/hash/ssl_hash.h" +#include "yacl/crypto/ecc/group_sketch.h" +#include "yacl/crypto/hash/ssl_hash.h" // hmcl = herumi_mcl namespace yacl::crypto::hmcl { diff --git a/yacl/crypto/base/ecc/mcl/mcl_ec_test.cc b/yacl/crypto/ecc/mcl/mcl_ec_test.cc similarity index 98% rename from yacl/crypto/base/ecc/mcl/mcl_ec_test.cc rename to yacl/crypto/ecc/mcl/mcl_ec_test.cc index 1c1e8a5b..7f246c4b 100644 --- a/yacl/crypto/base/ecc/mcl/mcl_ec_test.cc +++ b/yacl/crypto/ecc/mcl/mcl_ec_test.cc @@ -14,7 +14,7 @@ #include "gtest/gtest.h" -#include "yacl/crypto/base/ecc/mcl/mcl_ec_group.h" +#include "yacl/crypto/ecc/mcl/mcl_ec_group.h" namespace yacl::crypto::hmcl { // for test diff --git a/yacl/crypto/base/ecc/mcl/mcl_util.cc b/yacl/crypto/ecc/mcl/mcl_util.cc similarity index 96% rename from yacl/crypto/base/ecc/mcl/mcl_util.cc rename to yacl/crypto/ecc/mcl/mcl_util.cc index b8506b99..f0ecd83a 100644 --- a/yacl/crypto/base/ecc/mcl/mcl_util.cc +++ b/yacl/crypto/ecc/mcl/mcl_util.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/ecc/mcl/mcl_util.h" +#include "yacl/crypto/ecc/mcl/mcl_util.h" #include "mcl/gmp_util.hpp" diff --git a/yacl/crypto/base/ecc/mcl/mcl_util.h b/yacl/crypto/ecc/mcl/mcl_util.h similarity index 100% rename from yacl/crypto/base/ecc/mcl/mcl_util.h rename to yacl/crypto/ecc/mcl/mcl_util.h diff --git a/yacl/crypto/base/ecc/mcl/mcl_util_test.cc b/yacl/crypto/ecc/mcl/mcl_util_test.cc similarity index 96% rename from yacl/crypto/base/ecc/mcl/mcl_util_test.cc rename to yacl/crypto/ecc/mcl/mcl_util_test.cc index b0d8c103..e3499386 100644 --- a/yacl/crypto/base/ecc/mcl/mcl_util_test.cc +++ b/yacl/crypto/ecc/mcl/mcl_util_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/ecc/mcl/mcl_util.h" +#include "yacl/crypto/ecc/mcl/mcl_util.h" #include "gtest/gtest.h" diff --git a/yacl/crypto/base/ecc/openssl/BUILD.bazel b/yacl/crypto/ecc/openssl/BUILD.bazel similarity index 86% rename from yacl/crypto/base/ecc/openssl/BUILD.bazel rename to yacl/crypto/ecc/openssl/BUILD.bazel index 340f7f91..6be9a1b0 100644 --- a/yacl/crypto/base/ecc/openssl/BUILD.bazel +++ b/yacl/crypto/ecc/openssl/BUILD.bazel @@ -26,10 +26,10 @@ yacl_cc_library( "openssl_group.h", ], deps = [ - "//yacl/crypto/base:openssl_wrappers", - "//yacl/crypto/base/ecc:spi", - "//yacl/crypto/base/hash:blake3", - "//yacl/crypto/base/hash:ssl_hash", + "//yacl/crypto:openssl_wrappers", + "//yacl/crypto/ecc:spi", + "//yacl/crypto/hash:blake3", + "//yacl/crypto/hash:ssl_hash", "@com_github_openssl_openssl//:openssl", "@yacl//yacl/utils:parallel", ], diff --git a/yacl/crypto/base/ecc/openssl/openssl_factory.cc b/yacl/crypto/ecc/openssl/openssl_factory.cc similarity index 99% rename from yacl/crypto/base/ecc/openssl/openssl_factory.cc rename to yacl/crypto/ecc/openssl/openssl_factory.cc index 8b0375d8..363d28b5 100644 --- a/yacl/crypto/base/ecc/openssl/openssl_factory.cc +++ b/yacl/crypto/ecc/openssl/openssl_factory.cc @@ -17,7 +17,7 @@ #include "openssl/err.h" #include "openssl/evp.h" -#include "yacl/crypto/base/ecc/openssl/openssl_group.h" +#include "yacl/crypto/ecc/openssl/openssl_group.h" namespace yacl::crypto::openssl { diff --git a/yacl/crypto/base/ecc/openssl/openssl_group.cc b/yacl/crypto/ecc/openssl/openssl_group.cc similarity index 98% rename from yacl/crypto/base/ecc/openssl/openssl_group.cc rename to yacl/crypto/ecc/openssl/openssl_group.cc index 0957b6af..f171d7f0 100644 --- a/yacl/crypto/base/ecc/openssl/openssl_group.cc +++ b/yacl/crypto/ecc/openssl/openssl_group.cc @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/ecc/openssl/openssl_group.h" +#include "yacl/crypto/ecc/openssl/openssl_group.h" #include -#include "yacl/crypto/base/hash/blake3.h" -#include "yacl/crypto/base/hash/ssl_hash.h" -#include "yacl/crypto/base/openssl_wrappers.h" +#include "yacl/crypto/hash/blake3.h" +#include "yacl/crypto/hash/ssl_hash.h" +#include "yacl/crypto/openssl_wrappers.h" #include "yacl/utils/scope_guard.h" #include "yacl/utils/spi/type_traits.h" diff --git a/yacl/crypto/base/ecc/openssl/openssl_group.h b/yacl/crypto/ecc/openssl/openssl_group.h similarity index 97% rename from yacl/crypto/base/ecc/openssl/openssl_group.h rename to yacl/crypto/ecc/openssl/openssl_group.h index fa84e839..d151bd37 100644 --- a/yacl/crypto/base/ecc/openssl/openssl_group.h +++ b/yacl/crypto/ecc/openssl/openssl_group.h @@ -17,8 +17,8 @@ #include #include -#include "yacl/crypto/base/ecc/group_sketch.h" -#include "yacl/crypto/base/openssl_wrappers.h" +#include "yacl/crypto/ecc/group_sketch.h" +#include "yacl/crypto/openssl_wrappers.h" namespace yacl::crypto::openssl { diff --git a/yacl/crypto/base/ecc/openssl/openssl_test.cc b/yacl/crypto/ecc/openssl/openssl_test.cc similarity index 98% rename from yacl/crypto/base/ecc/openssl/openssl_test.cc rename to yacl/crypto/ecc/openssl/openssl_test.cc index a1f9c02f..76c25dc0 100644 --- a/yacl/crypto/base/ecc/openssl/openssl_test.cc +++ b/yacl/crypto/ecc/openssl/openssl_test.cc @@ -16,7 +16,7 @@ #include "gtest/gtest.h" -#include "yacl/crypto/base/ecc/openssl/openssl_group.h" +#include "yacl/crypto/ecc/openssl/openssl_group.h" #include "yacl/utils/parallel.h" #include "yacl/utils/spi/spi_factory.h" diff --git a/yacl/crypto/base/ecc/toy/BUILD.bazel b/yacl/crypto/ecc/toy/BUILD.bazel similarity index 92% rename from yacl/crypto/base/ecc/toy/BUILD.bazel rename to yacl/crypto/ecc/toy/BUILD.bazel index ae7a78bc..6704a209 100644 --- a/yacl/crypto/base/ecc/toy/BUILD.bazel +++ b/yacl/crypto/ecc/toy/BUILD.bazel @@ -37,8 +37,8 @@ yacl_cc_library( "common.h", ], deps = [ - "//yacl/crypto/base/ecc:spi", - "//yacl/crypto/base/hash:ssl_hash", + "//yacl/crypto/ecc:spi", + "//yacl/crypto/hash:ssl_hash", ], ) @@ -52,7 +52,7 @@ yacl_cc_library( ], deps = [ ":common", - "//yacl/crypto/base/hash:blake3", + "//yacl/crypto/hash:blake3", ], ) diff --git a/yacl/crypto/base/ecc/toy/common.cc b/yacl/crypto/ecc/toy/common.cc similarity index 97% rename from yacl/crypto/base/ecc/toy/common.cc rename to yacl/crypto/ecc/toy/common.cc index dca262a1..f0018563 100644 --- a/yacl/crypto/base/ecc/toy/common.cc +++ b/yacl/crypto/ecc/toy/common.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/ecc/toy/common.h" +#include "yacl/crypto/ecc/toy/common.h" #include diff --git a/yacl/crypto/base/ecc/toy/common.h b/yacl/crypto/ecc/toy/common.h similarity index 97% rename from yacl/crypto/base/ecc/toy/common.h rename to yacl/crypto/ecc/toy/common.h index 17dd8785..592210de 100644 --- a/yacl/crypto/base/ecc/toy/common.h +++ b/yacl/crypto/ecc/toy/common.h @@ -14,7 +14,7 @@ #pragma once -#include "yacl/crypto/base/ecc/group_sketch.h" +#include "yacl/crypto/ecc/group_sketch.h" namespace yacl::crypto::toy { diff --git a/yacl/crypto/base/ecc/toy/factory.cc b/yacl/crypto/ecc/toy/factory.cc similarity index 96% rename from yacl/crypto/base/ecc/toy/factory.cc rename to yacl/crypto/ecc/toy/factory.cc index 9cbf933f..2044b455 100644 --- a/yacl/crypto/base/ecc/toy/factory.cc +++ b/yacl/crypto/ecc/toy/factory.cc @@ -14,8 +14,8 @@ #include -#include "yacl/crypto/base/ecc/toy/montgomery.h" -#include "yacl/crypto/base/ecc/toy/weierstrass.h" +#include "yacl/crypto/ecc/toy/montgomery.h" +#include "yacl/crypto/ecc/toy/weierstrass.h" namespace yacl::crypto::toy { diff --git a/yacl/crypto/base/ecc/toy/montgomery.cc b/yacl/crypto/ecc/toy/montgomery.cc similarity index 98% rename from yacl/crypto/base/ecc/toy/montgomery.cc rename to yacl/crypto/ecc/toy/montgomery.cc index cf8efe42..35251951 100644 --- a/yacl/crypto/base/ecc/toy/montgomery.cc +++ b/yacl/crypto/ecc/toy/montgomery.cc @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/ecc/toy/montgomery.h" +#include "yacl/crypto/ecc/toy/montgomery.h" #include "absl/strings/escaping.h" -#include "yacl/crypto/base/hash/blake3.h" -#include "yacl/crypto/base/hash/ssl_hash.h" +#include "yacl/crypto/hash/blake3.h" +#include "yacl/crypto/hash/ssl_hash.h" namespace yacl::crypto::toy { diff --git a/yacl/crypto/base/ecc/toy/montgomery.h b/yacl/crypto/ecc/toy/montgomery.h similarity index 98% rename from yacl/crypto/base/ecc/toy/montgomery.h rename to yacl/crypto/ecc/toy/montgomery.h index 0980afc2..de16d7b2 100644 --- a/yacl/crypto/base/ecc/toy/montgomery.h +++ b/yacl/crypto/ecc/toy/montgomery.h @@ -14,7 +14,7 @@ #pragma once -#include "yacl/crypto/base/ecc/toy/common.h" +#include "yacl/crypto/ecc/toy/common.h" namespace yacl::crypto::toy { diff --git a/yacl/crypto/base/ecc/toy/montgomery_test.cc b/yacl/crypto/ecc/toy/montgomery_test.cc similarity index 98% rename from yacl/crypto/base/ecc/toy/montgomery_test.cc rename to yacl/crypto/ecc/toy/montgomery_test.cc index d7880651..2a3b73b4 100644 --- a/yacl/crypto/base/ecc/toy/montgomery_test.cc +++ b/yacl/crypto/ecc/toy/montgomery_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/ecc/toy/montgomery.h" +#include "yacl/crypto/ecc/toy/montgomery.h" #include "gtest/gtest.h" diff --git a/yacl/crypto/base/ecc/toy/weierstrass.cc b/yacl/crypto/ecc/toy/weierstrass.cc similarity index 99% rename from yacl/crypto/base/ecc/toy/weierstrass.cc rename to yacl/crypto/ecc/toy/weierstrass.cc index 354cd563..c925c953 100644 --- a/yacl/crypto/base/ecc/toy/weierstrass.cc +++ b/yacl/crypto/ecc/toy/weierstrass.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/ecc/toy/weierstrass.h" +#include "yacl/crypto/ecc/toy/weierstrass.h" namespace yacl::crypto::toy { diff --git a/yacl/crypto/base/ecc/toy/weierstrass.h b/yacl/crypto/ecc/toy/weierstrass.h similarity index 97% rename from yacl/crypto/base/ecc/toy/weierstrass.h rename to yacl/crypto/ecc/toy/weierstrass.h index 8087972f..92e03caa 100644 --- a/yacl/crypto/base/ecc/toy/weierstrass.h +++ b/yacl/crypto/ecc/toy/weierstrass.h @@ -14,7 +14,7 @@ #pragma once -#include "yacl/crypto/base/ecc/toy/common.h" +#include "yacl/crypto/ecc/toy/common.h" namespace yacl::crypto::toy { diff --git a/yacl/crypto/base/ecc/toy/weierstrass_test.cc b/yacl/crypto/ecc/toy/weierstrass_test.cc similarity index 98% rename from yacl/crypto/base/ecc/toy/weierstrass_test.cc rename to yacl/crypto/ecc/toy/weierstrass_test.cc index 882b3b57..cc63cf3d 100644 --- a/yacl/crypto/base/ecc/toy/weierstrass_test.cc +++ b/yacl/crypto/ecc/toy/weierstrass_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/ecc/toy/weierstrass.h" +#include "yacl/crypto/ecc/toy/weierstrass.h" #include "gtest/gtest.h" diff --git a/yacl/crypto/base/envelope/BUILD.bazel b/yacl/crypto/envelope/BUILD.bazel similarity index 73% rename from yacl/crypto/base/envelope/BUILD.bazel rename to yacl/crypto/envelope/BUILD.bazel index c1c4dc74..c6fcfbab 100644 --- a/yacl/crypto/base/envelope/BUILD.bazel +++ b/yacl/crypto/envelope/BUILD.bazel @@ -21,14 +21,14 @@ yacl_cc_library( srcs = ["digital_envelope.cc"], hdrs = ["digital_envelope.h"], deps = [ - "//yacl/crypto/base/aead:gcm_crypto", - "//yacl/crypto/base/aead:sm4_mac", - "//yacl/crypto/base/block_cipher:symmetric_crypto", - "//yacl/crypto/base/hash:ssl_hash", - "//yacl/crypto/base/hmac:hmac_sm3", - "//yacl/crypto/base/pke:asymmetric_rsa_crypto", - "//yacl/crypto/base/pke:asymmetric_sm2_crypto", - "//yacl/crypto/utils:rand", + "//yacl/crypto/aead:gcm_crypto", + "//yacl/crypto/aead:sm4_mac", + "//yacl/crypto/block_cipher:symmetric_crypto", + "//yacl/crypto/hash:ssl_hash", + "//yacl/crypto/hmac:hmac_sm3", + "//yacl/crypto/pke:asymmetric_rsa_crypto", + "//yacl/crypto/pke:asymmetric_sm2_crypto", + "//yacl/crypto/rand", "@com_google_absl//absl/strings", "@com_google_absl//absl/types:span", ], diff --git a/yacl/crypto/base/envelope/digital_envelope.cc b/yacl/crypto/envelope/digital_envelope.cc similarity index 97% rename from yacl/crypto/base/envelope/digital_envelope.cc rename to yacl/crypto/envelope/digital_envelope.cc index 4974484d..a7f1d0d9 100644 --- a/yacl/crypto/base/envelope/digital_envelope.cc +++ b/yacl/crypto/envelope/digital_envelope.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/envelope/digital_envelope.h" +#include "yacl/crypto/envelope/digital_envelope.h" #include "absl/types/span.h" diff --git a/yacl/crypto/base/envelope/digital_envelope.h b/yacl/crypto/envelope/digital_envelope.h similarity index 88% rename from yacl/crypto/base/envelope/digital_envelope.h rename to yacl/crypto/envelope/digital_envelope.h index c0428a57..d717da4a 100644 --- a/yacl/crypto/base/envelope/digital_envelope.h +++ b/yacl/crypto/envelope/digital_envelope.h @@ -19,14 +19,14 @@ #include "yacl/base/byte_container_view.h" /* submodules */ -#include "yacl/crypto/base/aead/gcm_crypto.h" -#include "yacl/crypto/base/aead/sm4_mac.h" -#include "yacl/crypto/base/block_cipher/symmetric_crypto.h" -#include "yacl/crypto/base/hash/ssl_hash.h" -#include "yacl/crypto/base/hmac/hmac_sm3.h" -#include "yacl/crypto/base/pke/asymmetric_rsa_crypto.h" -#include "yacl/crypto/base/pke/asymmetric_sm2_crypto.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/aead/gcm_crypto.h" +#include "yacl/crypto/aead/sm4_mac.h" +#include "yacl/crypto/block_cipher/symmetric_crypto.h" +#include "yacl/crypto/hash/ssl_hash.h" +#include "yacl/crypto/hmac/hmac_sm3.h" +#include "yacl/crypto/pke/asymmetric_rsa_crypto.h" +#include "yacl/crypto/pke/asymmetric_sm2_crypto.h" +#include "yacl/crypto/rand/rand.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/envelope/digital_envelope_test.cc b/yacl/crypto/envelope/digital_envelope_test.cc similarity index 94% rename from yacl/crypto/base/envelope/digital_envelope_test.cc rename to yacl/crypto/envelope/digital_envelope_test.cc index 029a1049..e588720e 100644 --- a/yacl/crypto/base/envelope/digital_envelope_test.cc +++ b/yacl/crypto/envelope/digital_envelope_test.cc @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/envelope/digital_envelope.h" +#include "yacl/crypto/envelope/digital_envelope.h" #include "gtest/gtest.h" -#include "yacl/crypto/base/key_utils.h" +#include "yacl/crypto/key_utils.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/hash/BUILD.bazel b/yacl/crypto/hash/BUILD.bazel similarity index 95% rename from yacl/crypto/base/hash/BUILD.bazel rename to yacl/crypto/hash/BUILD.bazel index 10466f33..dc9b0a59 100644 --- a/yacl/crypto/base/hash/BUILD.bazel +++ b/yacl/crypto/hash/BUILD.bazel @@ -23,7 +23,7 @@ yacl_cc_library( deps = [ ":hash_interface", "//yacl/base:exception", - "//yacl/crypto/base:openssl_wrappers", + "//yacl/crypto:openssl_wrappers", "//yacl/utils:scope_guard", "@com_github_openssl_openssl//:openssl", ], @@ -70,8 +70,8 @@ yacl_cc_library( name = "hash_interface", srcs = ["hash_interface.h"], deps = [ + "//yacl:secparam", "//yacl/base:byte_container_view", - "//yacl/crypto/utils:secparam", "@com_github_openssl_openssl//:openssl", ], ) diff --git a/yacl/crypto/base/hash/blake3.cc b/yacl/crypto/hash/blake3.cc similarity index 97% rename from yacl/crypto/base/hash/blake3.cc rename to yacl/crypto/hash/blake3.cc index 133a8a48..2b9c8545 100644 --- a/yacl/crypto/base/hash/blake3.cc +++ b/yacl/crypto/hash/blake3.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/hash/blake3.h" +#include "yacl/crypto/hash/blake3.h" #include diff --git a/yacl/crypto/base/hash/blake3.h b/yacl/crypto/hash/blake3.h similarity index 97% rename from yacl/crypto/base/hash/blake3.h rename to yacl/crypto/hash/blake3.h index ca8f8933..05a3e8ce 100644 --- a/yacl/crypto/base/hash/blake3.h +++ b/yacl/crypto/hash/blake3.h @@ -19,7 +19,7 @@ #include "c/blake3.h" #include "yacl/base/byte_container_view.h" -#include "yacl/crypto/base/hash/hash_interface.h" +#include "yacl/crypto/hash/hash_interface.h" namespace yacl::crypto { // specification document of the blake3 hash function diff --git a/yacl/crypto/base/hash/blake3_bench.cc b/yacl/crypto/hash/blake3_bench.cc similarity index 96% rename from yacl/crypto/base/hash/blake3_bench.cc rename to yacl/crypto/hash/blake3_bench.cc index fd928e4f..a3500758 100644 --- a/yacl/crypto/base/hash/blake3_bench.cc +++ b/yacl/crypto/hash/blake3_bench.cc @@ -18,7 +18,7 @@ #include "benchmark/benchmark.h" #include "yacl/base/exception.h" -#include "yacl/crypto/base/hash/blake3.h" +#include "yacl/crypto/hash/blake3.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/hash/blake3_test.cc b/yacl/crypto/hash/blake3_test.cc similarity index 98% rename from yacl/crypto/base/hash/blake3_test.cc rename to yacl/crypto/hash/blake3_test.cc index 905065e1..64f170ba 100644 --- a/yacl/crypto/base/hash/blake3_test.cc +++ b/yacl/crypto/hash/blake3_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/hash/blake3.h" +#include "yacl/crypto/hash/blake3.h" #include #include @@ -110,7 +110,7 @@ TEST(Blake3HashTest, MultipleUpdates) { // The blow testing would set the output length from 1 byte (8-bit) to 8 * 32 = // 256 bytes (2048-bit). // Besdies, the output length would affect the security level, see -// yacl/crypto/base/hash/blake3.h for more details. +// yacl/crypto/hash/blake3.h for more details. TEST(Blake3HashTest, CustomOutLength) { for (size_t i = 0; i <= (8 * BLAKE3_OUT_LEN); i++) { Blake3Hash blake3(i); diff --git a/yacl/crypto/base/hash/hash_interface.h b/yacl/crypto/hash/hash_interface.h similarity index 98% rename from yacl/crypto/base/hash/hash_interface.h rename to yacl/crypto/hash/hash_interface.h index fcf8714b..e8dd72a7 100644 --- a/yacl/crypto/base/hash/hash_interface.h +++ b/yacl/crypto/hash/hash_interface.h @@ -19,7 +19,7 @@ #include "openssl/evp.h" /* for evp type conversions */ #include "yacl/base/byte_container_view.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/secparam.h" /* security parameter declaration */ YACL_MODULE_DECLARE("hash_all", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/base/hash/hash_utils.cc b/yacl/crypto/hash/hash_utils.cc similarity index 97% rename from yacl/crypto/base/hash/hash_utils.cc rename to yacl/crypto/hash/hash_utils.cc index d8d02593..c95838b4 100644 --- a/yacl/crypto/base/hash/hash_utils.cc +++ b/yacl/crypto/hash/hash_utils.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/hash/hash_utils.h" +#include "yacl/crypto/hash/hash_utils.h" #include #include diff --git a/yacl/crypto/base/hash/hash_utils.h b/yacl/crypto/hash/hash_utils.h similarity index 97% rename from yacl/crypto/base/hash/hash_utils.h rename to yacl/crypto/hash/hash_utils.h index 4873550b..b0e94512 100644 --- a/yacl/crypto/base/hash/hash_utils.h +++ b/yacl/crypto/hash/hash_utils.h @@ -17,7 +17,7 @@ #include #include "yacl/base/int128.h" -#include "yacl/crypto/base/hash/ssl_hash.h" +#include "yacl/crypto/hash/ssl_hash.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/hash/ssl_hash.cc b/yacl/crypto/hash/ssl_hash.cc similarity index 95% rename from yacl/crypto/base/hash/ssl_hash.cc rename to yacl/crypto/hash/ssl_hash.cc index 9e353114..42c44e38 100644 --- a/yacl/crypto/base/hash/ssl_hash.cc +++ b/yacl/crypto/hash/ssl_hash.cc @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/hash/ssl_hash.h" +#include "yacl/crypto/hash/ssl_hash.h" #include "yacl/base/exception.h" -#include "yacl/crypto/base/openssl_wrappers.h" +#include "yacl/crypto/openssl_wrappers.h" #include "yacl/utils/scope_guard.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/hash/ssl_hash.h b/yacl/crypto/hash/ssl_hash.h similarity index 94% rename from yacl/crypto/base/hash/ssl_hash.h rename to yacl/crypto/hash/ssl_hash.h index 0757bbec..4287457c 100644 --- a/yacl/crypto/base/hash/ssl_hash.h +++ b/yacl/crypto/hash/ssl_hash.h @@ -17,8 +17,8 @@ #include #include "yacl/base/byte_container_view.h" -#include "yacl/crypto/base/hash/hash_interface.h" -#include "yacl/crypto/base/openssl_wrappers.h" +#include "yacl/crypto/hash/hash_interface.h" +#include "yacl/crypto/openssl_wrappers.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/hash/ssl_hash_all_test.cc b/yacl/crypto/hash/ssl_hash_all_test.cc similarity index 99% rename from yacl/crypto/base/hash/ssl_hash_all_test.cc rename to yacl/crypto/hash/ssl_hash_all_test.cc index 8b9126b7..56c4b900 100644 --- a/yacl/crypto/base/hash/ssl_hash_all_test.cc +++ b/yacl/crypto/hash/ssl_hash_all_test.cc @@ -16,7 +16,7 @@ #include "gtest/gtest.h" #include "yacl/base/exception.h" -#include "yacl/crypto/base/hash/ssl_hash.h" +#include "yacl/crypto/hash/ssl_hash.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/hmac/BUILD.bazel b/yacl/crypto/hmac/BUILD.bazel similarity index 86% rename from yacl/crypto/base/hmac/BUILD.bazel rename to yacl/crypto/hmac/BUILD.bazel index 6ca96c8b..2211ce3a 100644 --- a/yacl/crypto/base/hmac/BUILD.bazel +++ b/yacl/crypto/hmac/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//bazel:yacl.bzl", "AES_COPT_FLAGS", "yacl_cc_library", "yacl_cc_test") +load("//bazel:yacl.bzl", "yacl_cc_library", "yacl_cc_test") package(default_visibility = ["//visibility:public"]) @@ -22,8 +22,8 @@ yacl_cc_library( hdrs = ["hmac.h"], deps = [ "//yacl/base:exception", - "//yacl/crypto/base:openssl_wrappers", - "//yacl/crypto/base/hash:hash_interface", + "//yacl/crypto:openssl_wrappers", + "//yacl/crypto/hash:hash_interface", ], ) diff --git a/yacl/crypto/base/hmac/hmac.cc b/yacl/crypto/hmac/hmac.cc similarity index 96% rename from yacl/crypto/base/hmac/hmac.cc rename to yacl/crypto/hmac/hmac.cc index 47a6b3ed..2b2f4efe 100644 --- a/yacl/crypto/base/hmac/hmac.cc +++ b/yacl/crypto/hmac/hmac.cc @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/hmac/hmac.h" +#include "yacl/crypto/hmac/hmac.h" #include "yacl/base/exception.h" -#include "yacl/crypto/base/openssl_wrappers.h" +#include "yacl/crypto/openssl_wrappers.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/hmac/hmac.h b/yacl/crypto/hmac/hmac.h similarity index 95% rename from yacl/crypto/base/hmac/hmac.h rename to yacl/crypto/hmac/hmac.h index 81c49940..e15a4732 100644 --- a/yacl/crypto/base/hmac/hmac.h +++ b/yacl/crypto/hmac/hmac.h @@ -17,10 +17,10 @@ #include #include "yacl/base/byte_container_view.h" -#include "yacl/crypto/base/openssl_wrappers.h" +#include "yacl/crypto/openssl_wrappers.h" /* submodules */ -#include "yacl/crypto/base/hash/hash_interface.h" +#include "yacl/crypto/hash/hash_interface.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/hmac/hmac_all_test.cc b/yacl/crypto/hmac/hmac_all_test.cc similarity index 97% rename from yacl/crypto/base/hmac/hmac_all_test.cc rename to yacl/crypto/hmac/hmac_all_test.cc index 83c1bd10..589b8ba7 100644 --- a/yacl/crypto/base/hmac/hmac_all_test.cc +++ b/yacl/crypto/hmac/hmac_all_test.cc @@ -16,8 +16,8 @@ #include "gtest/gtest.h" #include "yacl/base/exception.h" -#include "yacl/crypto/base/hmac/hmac_sha256.h" -#include "yacl/crypto/base/hmac/hmac_sm3.h" +#include "yacl/crypto/hmac/hmac_sha256.h" +#include "yacl/crypto/hmac/hmac_sm3.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/hmac/hmac_sha256.h b/yacl/crypto/hmac/hmac_sha256.h similarity index 95% rename from yacl/crypto/base/hmac/hmac_sha256.h rename to yacl/crypto/hmac/hmac_sha256.h index b7bd178a..a6e65d3b 100644 --- a/yacl/crypto/base/hmac/hmac_sha256.h +++ b/yacl/crypto/hmac/hmac_sha256.h @@ -14,7 +14,7 @@ #pragma once -#include "yacl/crypto/base/hmac/hmac.h" +#include "yacl/crypto/hmac/hmac.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/hmac/hmac_sm3.h b/yacl/crypto/hmac/hmac_sm3.h similarity index 95% rename from yacl/crypto/base/hmac/hmac_sm3.h rename to yacl/crypto/hmac/hmac_sm3.h index 838def79..2c4557d9 100644 --- a/yacl/crypto/base/hmac/hmac_sm3.h +++ b/yacl/crypto/hmac/hmac_sm3.h @@ -14,7 +14,7 @@ #pragma once -#include "yacl/crypto/base/hmac/hmac.h" +#include "yacl/crypto/hmac/hmac.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/key_utils.cc b/yacl/crypto/key_utils.cc similarity index 99% rename from yacl/crypto/base/key_utils.cc rename to yacl/crypto/key_utils.cc index 9ebd3835..843e0bf9 100644 --- a/yacl/crypto/base/key_utils.cc +++ b/yacl/crypto/key_utils.cc @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/key_utils.h" +#include "yacl/crypto/key_utils.h" #include -#include "yacl/crypto/base/openssl_wrappers.h" +#include "yacl/crypto/openssl_wrappers.h" #include "yacl/io/stream/file_io.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/key_utils.h b/yacl/crypto/key_utils.h similarity index 99% rename from yacl/crypto/base/key_utils.h rename to yacl/crypto/key_utils.h index 36c79466..4e3b1667 100644 --- a/yacl/crypto/base/key_utils.h +++ b/yacl/crypto/key_utils.h @@ -18,7 +18,7 @@ #include #include -#include "yacl/crypto/base/openssl_wrappers.h" +#include "yacl/crypto/openssl_wrappers.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/key_utils_test.cc b/yacl/crypto/key_utils_test.cc similarity index 94% rename from yacl/crypto/base/key_utils_test.cc rename to yacl/crypto/key_utils_test.cc index d5fed805..26f8e2c6 100644 --- a/yacl/crypto/base/key_utils_test.cc +++ b/yacl/crypto/key_utils_test.cc @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/key_utils.h" +#include "yacl/crypto/key_utils.h" #include "gtest/gtest.h" -#include "yacl/crypto/base/pke/asymmetric_rsa_crypto.h" -#include "yacl/crypto/base/sign/rsa_signing.h" +#include "yacl/crypto/pke/asymmetric_rsa_crypto.h" +#include "yacl/crypto/sign/rsa_signing.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/openssl_wrappers.h b/yacl/crypto/openssl_wrappers.h similarity index 100% rename from yacl/crypto/base/openssl_wrappers.h rename to yacl/crypto/openssl_wrappers.h diff --git a/yacl/crypto/ossl-provider/BUILD.bazel b/yacl/crypto/ossl-provider/BUILD.bazel index 7fe4d2fb..957e2f64 100644 --- a/yacl/crypto/ossl-provider/BUILD.bazel +++ b/yacl/crypto/ossl-provider/BUILD.bazel @@ -47,7 +47,7 @@ yacl_cc_library( ], visibility = ["//visibility:public"], # public deps = [ - "//yacl/crypto/base:openssl_wrappers", # openssl here + "//yacl/crypto:openssl_wrappers", # openssl here "@com_google_absl//absl/strings", ], ) @@ -64,8 +64,8 @@ yacl_cc_library( ], visibility = ["//visibility:private"], deps = [ - "//yacl/crypto/base:openssl_wrappers", # openssl here - "//yacl/crypto/utils/entropy_source", # use yacl es + "//yacl/crypto:openssl_wrappers", # openssl here + "//yacl/crypto/rand/entropy_source", # use yacl es ], alwayslink = True, # DO NOT DELETE THIS ) diff --git a/yacl/crypto/ossl-provider/provider_test.cc b/yacl/crypto/ossl-provider/provider_test.cc index db96e5ea..da63f55f 100644 --- a/yacl/crypto/ossl-provider/provider_test.cc +++ b/yacl/crypto/ossl-provider/provider_test.cc @@ -23,7 +23,7 @@ #include "openssl/rand.h" #include "openssl/randerr.h" -#include "yacl/crypto/base/openssl_wrappers.h" +#include "yacl/crypto/openssl_wrappers.h" #include "yacl/crypto/ossl-provider/helper.h" namespace yacl::crypto { diff --git a/yacl/crypto/ossl-provider/rand_impl.h b/yacl/crypto/ossl-provider/rand_impl.h index 4bd6365d..f6022d0f 100644 --- a/yacl/crypto/ossl-provider/rand_impl.h +++ b/yacl/crypto/ossl-provider/rand_impl.h @@ -23,8 +23,8 @@ #include "openssl/randerr.h" #include "spdlog/spdlog.h" -#include "yacl/crypto/base/openssl_wrappers.h" -#include "yacl/crypto/utils/entropy_source/entropy_source.h" +#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/rand/entropy_source/entropy_source.h" namespace yc = yacl::crypto; diff --git a/yacl/crypto/base/pairing/BUILD.bazel b/yacl/crypto/pairing/BUILD.bazel similarity index 92% rename from yacl/crypto/base/pairing/BUILD.bazel rename to yacl/crypto/pairing/BUILD.bazel index d7e070b0..8f806d63 100644 --- a/yacl/crypto/base/pairing/BUILD.bazel +++ b/yacl/crypto/pairing/BUILD.bazel @@ -19,7 +19,7 @@ package(default_visibility = ["//visibility:public"]) yacl_cc_library( name = "pairing", deps = [ - "//yacl/crypto/base/pairing/mcl:pairing", + "//yacl/crypto/pairing/mcl:pairing", ], ) @@ -28,7 +28,7 @@ yacl_cc_library( srcs = ["pairing_spi.cc"], hdrs = ["pairing_spi.h"], deps = [ - "//yacl/crypto/base/ecc:spi", + "//yacl/crypto/ecc:spi", "//yacl/math/galois_field:spi", "@com_google_absl//absl/strings", ], diff --git a/yacl/crypto/base/pairing/mcl/BUILD.bazel b/yacl/crypto/pairing/mcl/BUILD.bazel similarity index 93% rename from yacl/crypto/base/pairing/mcl/BUILD.bazel rename to yacl/crypto/pairing/mcl/BUILD.bazel index 3ef04df6..2a1fdee2 100644 --- a/yacl/crypto/base/pairing/mcl/BUILD.bazel +++ b/yacl/crypto/pairing/mcl/BUILD.bazel @@ -47,8 +47,8 @@ yacl_cc_library( ], deps = [ ":pairing_header", - "//yacl/crypto/base/ecc", - "//yacl/crypto/base/pairing:pairing_spi", + "//yacl/crypto/ecc", + "//yacl/crypto/pairing:pairing_spi", "//yacl/math/galois_field/mcl_field:field", ], alwayslink = 1, @@ -59,6 +59,6 @@ yacl_cc_test( srcs = ["mcl_pairing_test.cc"], deps = [ ":pairing", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", ], ) diff --git a/yacl/crypto/base/pairing/mcl/mcl_pairing_bls12_381.cc b/yacl/crypto/pairing/mcl/mcl_pairing_bls12_381.cc similarity index 97% rename from yacl/crypto/base/pairing/mcl/mcl_pairing_bls12_381.cc rename to yacl/crypto/pairing/mcl/mcl_pairing_bls12_381.cc index 6b53f56c..69adf1bd 100644 --- a/yacl/crypto/base/pairing/mcl/mcl_pairing_bls12_381.cc +++ b/yacl/crypto/pairing/mcl/mcl_pairing_bls12_381.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/pairing/mcl/mcl_pairing_bls12_381.h" +#include "yacl/crypto/pairing/mcl/mcl_pairing_bls12_381.h" namespace yacl::crypto::hmcl { diff --git a/yacl/crypto/base/pairing/mcl/mcl_pairing_bls12_381.h b/yacl/crypto/pairing/mcl/mcl_pairing_bls12_381.h similarity index 95% rename from yacl/crypto/base/pairing/mcl/mcl_pairing_bls12_381.h rename to yacl/crypto/pairing/mcl/mcl_pairing_bls12_381.h index 795f0443..a1e29600 100644 --- a/yacl/crypto/base/pairing/mcl/mcl_pairing_bls12_381.h +++ b/yacl/crypto/pairing/mcl/mcl_pairing_bls12_381.h @@ -16,8 +16,8 @@ #include "mcl/bls12_381.hpp" -#include "yacl/crypto/base/ecc/mcl/mcl_ec_group.h" -#include "yacl/crypto/base/pairing/pairing_spi.h" +#include "yacl/crypto/ecc/mcl/mcl_ec_group.h" +#include "yacl/crypto/pairing/pairing_spi.h" #include "yacl/math/galois_field/mcl_field/mcl_field.h" namespace yacl::crypto::hmcl { diff --git a/yacl/crypto/base/pairing/mcl/mcl_pairing_factory.cc b/yacl/crypto/pairing/mcl/mcl_pairing_factory.cc similarity index 99% rename from yacl/crypto/base/pairing/mcl/mcl_pairing_factory.cc rename to yacl/crypto/pairing/mcl/mcl_pairing_factory.cc index ec6a3457..02e030f0 100644 --- a/yacl/crypto/base/pairing/mcl/mcl_pairing_factory.cc +++ b/yacl/crypto/pairing/mcl/mcl_pairing_factory.cc @@ -14,7 +14,7 @@ #include "absl/strings/ascii.h" -#include "yacl/crypto/base/pairing/mcl/mcl_pairing_group.h" +#include "yacl/crypto/pairing/mcl/mcl_pairing_group.h" namespace yacl::crypto::hmcl { diff --git a/yacl/crypto/base/pairing/mcl/mcl_pairing_group.cc b/yacl/crypto/pairing/mcl/mcl_pairing_group.cc similarity index 98% rename from yacl/crypto/base/pairing/mcl/mcl_pairing_group.cc rename to yacl/crypto/pairing/mcl/mcl_pairing_group.cc index 3bd2ecfe..c19273e6 100644 --- a/yacl/crypto/base/pairing/mcl/mcl_pairing_group.cc +++ b/yacl/crypto/pairing/mcl/mcl_pairing_group.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/pairing/mcl/mcl_pairing_group.h" +#include "yacl/crypto/pairing/mcl/mcl_pairing_group.h" #ifdef MCL_ALL_PAIRING_FOR_YACL namespace yacl::crypto::hmcl { diff --git a/yacl/crypto/base/pairing/mcl/mcl_pairing_group.h b/yacl/crypto/pairing/mcl/mcl_pairing_group.h similarity index 94% rename from yacl/crypto/base/pairing/mcl/mcl_pairing_group.h rename to yacl/crypto/pairing/mcl/mcl_pairing_group.h index 63bc8121..40163f48 100644 --- a/yacl/crypto/base/pairing/mcl/mcl_pairing_group.h +++ b/yacl/crypto/pairing/mcl/mcl_pairing_group.h @@ -14,10 +14,10 @@ #pragma once -#include "yacl/crypto/base/ecc/mcl/mcl_ec_group.h" -#include "yacl/crypto/base/pairing/mcl/mcl_pairing_bls12_381.h" -#include "yacl/crypto/base/pairing/mcl/pairing_header.h" -#include "yacl/crypto/base/pairing/pairing_spi.h" +#include "yacl/crypto/ecc/mcl/mcl_ec_group.h" +#include "yacl/crypto/pairing/mcl/mcl_pairing_bls12_381.h" +#include "yacl/crypto/pairing/mcl/pairing_header.h" +#include "yacl/crypto/pairing/pairing_spi.h" #include "yacl/math/galois_field/mcl_field/mcl_field.h" namespace yacl::crypto::hmcl { diff --git a/yacl/crypto/base/pairing/mcl/mcl_pairing_test.cc b/yacl/crypto/pairing/mcl/mcl_pairing_test.cc similarity index 97% rename from yacl/crypto/base/pairing/mcl/mcl_pairing_test.cc rename to yacl/crypto/pairing/mcl/mcl_pairing_test.cc index 27a5f9e3..a1c96ab9 100644 --- a/yacl/crypto/base/pairing/mcl/mcl_pairing_test.cc +++ b/yacl/crypto/pairing/mcl/mcl_pairing_test.cc @@ -14,8 +14,8 @@ #include "gtest/gtest.h" -#include "yacl/crypto/base/pairing/mcl/mcl_pairing_group.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/pairing/mcl/mcl_pairing_group.h" +#include "yacl/crypto/rand/rand.h" namespace yacl::crypto::hmcl { extern std::map Name2MclPairingEnum; diff --git a/yacl/crypto/base/pairing/mcl/pairing_header.h b/yacl/crypto/pairing/mcl/pairing_header.h similarity index 100% rename from yacl/crypto/base/pairing/mcl/pairing_header.h rename to yacl/crypto/pairing/mcl/pairing_header.h diff --git a/yacl/crypto/base/pairing/pairing_spi.cc b/yacl/crypto/pairing/pairing_spi.cc similarity index 96% rename from yacl/crypto/base/pairing/pairing_spi.cc rename to yacl/crypto/pairing/pairing_spi.cc index 54983181..975211d7 100644 --- a/yacl/crypto/base/pairing/pairing_spi.cc +++ b/yacl/crypto/pairing/pairing_spi.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/pairing/pairing_spi.h" +#include "yacl/crypto/pairing/pairing_spi.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/pairing/pairing_spi.h b/yacl/crypto/pairing/pairing_spi.h similarity index 98% rename from yacl/crypto/base/pairing/pairing_spi.h rename to yacl/crypto/pairing/pairing_spi.h index 7b5662b1..d2afd5da 100644 --- a/yacl/crypto/base/pairing/pairing_spi.h +++ b/yacl/crypto/pairing/pairing_spi.h @@ -14,7 +14,7 @@ #pragma once -#include "yacl/crypto/base/ecc/ecc_spi.h" +#include "yacl/crypto/ecc/ecc_spi.h" #include "yacl/math/galois_field/gf_spi.h" #include "yacl/utils/spi/spi_factory.h" diff --git a/yacl/crypto/base/pairing/pairing_test.cc b/yacl/crypto/pairing/pairing_test.cc similarity index 99% rename from yacl/crypto/base/pairing/pairing_test.cc rename to yacl/crypto/pairing/pairing_test.cc index e43fffc4..3a173ad4 100644 --- a/yacl/crypto/base/pairing/pairing_test.cc +++ b/yacl/crypto/pairing/pairing_test.cc @@ -17,7 +17,7 @@ #include "fmt/ranges.h" #include "gtest/gtest.h" -#include "yacl/crypto/base/pairing/pairing_spi.h" +#include "yacl/crypto/pairing/pairing_spi.h" #include "yacl/utils/parallel.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/pke/BUILD.bazel b/yacl/crypto/pke/BUILD.bazel similarity index 90% rename from yacl/crypto/base/pke/BUILD.bazel rename to yacl/crypto/pke/BUILD.bazel index b15f5cc0..0be1b148 100644 --- a/yacl/crypto/base/pke/BUILD.bazel +++ b/yacl/crypto/pke/BUILD.bazel @@ -30,9 +30,9 @@ yacl_cc_library( hdrs = ["asymmetric_sm2_crypto.h"], deps = [ ":asymmetric_crypto", + "//yacl:secparam", "//yacl/base:exception", - "//yacl/crypto/base:key_utils", - "//yacl/crypto/utils:secparam", + "//yacl/crypto:key_utils", ], ) @@ -50,9 +50,9 @@ yacl_cc_library( hdrs = ["asymmetric_rsa_crypto.h"], deps = [ ":asymmetric_crypto", + "//yacl:secparam", "//yacl/base:exception", - "//yacl/crypto/base:key_utils", - "//yacl/crypto/utils:secparam", + "//yacl/crypto:key_utils", ], ) diff --git a/yacl/crypto/base/pke/asymmetric_crypto.h b/yacl/crypto/pke/asymmetric_crypto.h similarity index 100% rename from yacl/crypto/base/pke/asymmetric_crypto.h rename to yacl/crypto/pke/asymmetric_crypto.h diff --git a/yacl/crypto/base/pke/asymmetric_rsa_crypto.cc b/yacl/crypto/pke/asymmetric_rsa_crypto.cc similarity index 98% rename from yacl/crypto/base/pke/asymmetric_rsa_crypto.cc rename to yacl/crypto/pke/asymmetric_rsa_crypto.cc index 71f7df8e..04c641d9 100644 --- a/yacl/crypto/base/pke/asymmetric_rsa_crypto.cc +++ b/yacl/crypto/pke/asymmetric_rsa_crypto.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/pke/asymmetric_rsa_crypto.h" +#include "yacl/crypto/pke/asymmetric_rsa_crypto.h" #include diff --git a/yacl/crypto/base/pke/asymmetric_rsa_crypto.h b/yacl/crypto/pke/asymmetric_rsa_crypto.h similarity index 93% rename from yacl/crypto/base/pke/asymmetric_rsa_crypto.h rename to yacl/crypto/pke/asymmetric_rsa_crypto.h index bcec1096..dece8746 100644 --- a/yacl/crypto/base/pke/asymmetric_rsa_crypto.h +++ b/yacl/crypto/pke/asymmetric_rsa_crypto.h @@ -18,9 +18,9 @@ #include #include -#include "yacl/crypto/base/key_utils.h" -#include "yacl/crypto/base/pke/asymmetric_crypto.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/crypto/key_utils.h" +#include "yacl/crypto/pke/asymmetric_crypto.h" +#include "yacl/secparam.h" /* security parameter declaration */ YACL_MODULE_DECLARE("rsa_enc", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/base/pke/asymmetric_rsa_crypto_test.cc b/yacl/crypto/pke/asymmetric_rsa_crypto_test.cc similarity index 91% rename from yacl/crypto/base/pke/asymmetric_rsa_crypto_test.cc rename to yacl/crypto/pke/asymmetric_rsa_crypto_test.cc index c23ee8bb..df8fb88b 100644 --- a/yacl/crypto/base/pke/asymmetric_rsa_crypto_test.cc +++ b/yacl/crypto/pke/asymmetric_rsa_crypto_test.cc @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/pke/asymmetric_rsa_crypto.h" +#include "yacl/crypto/pke/asymmetric_rsa_crypto.h" #include #include "gtest/gtest.h" -#include "yacl/crypto/base/openssl_wrappers.h" +#include "yacl/crypto/openssl_wrappers.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/pke/asymmetric_sm2_crypto.cc b/yacl/crypto/pke/asymmetric_sm2_crypto.cc similarity index 97% rename from yacl/crypto/base/pke/asymmetric_sm2_crypto.cc rename to yacl/crypto/pke/asymmetric_sm2_crypto.cc index 6d010384..e81c6c2b 100644 --- a/yacl/crypto/base/pke/asymmetric_sm2_crypto.cc +++ b/yacl/crypto/pke/asymmetric_sm2_crypto.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/pke/asymmetric_sm2_crypto.h" +#include "yacl/crypto/pke/asymmetric_sm2_crypto.h" #include diff --git a/yacl/crypto/base/pke/asymmetric_sm2_crypto.h b/yacl/crypto/pke/asymmetric_sm2_crypto.h similarity index 93% rename from yacl/crypto/base/pke/asymmetric_sm2_crypto.h rename to yacl/crypto/pke/asymmetric_sm2_crypto.h index 8ef3757b..0fd069de 100644 --- a/yacl/crypto/base/pke/asymmetric_sm2_crypto.h +++ b/yacl/crypto/pke/asymmetric_sm2_crypto.h @@ -18,9 +18,9 @@ #include #include -#include "yacl/crypto/base/key_utils.h" -#include "yacl/crypto/base/pke/asymmetric_crypto.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/crypto/key_utils.h" +#include "yacl/crypto/pke/asymmetric_crypto.h" +#include "yacl/secparam.h" /* security parameter declaration */ YACL_MODULE_DECLARE("sm2_enc", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/base/pke/asymmetric_sm2_crypto_test.cc b/yacl/crypto/pke/asymmetric_sm2_crypto_test.cc similarity index 91% rename from yacl/crypto/base/pke/asymmetric_sm2_crypto_test.cc rename to yacl/crypto/pke/asymmetric_sm2_crypto_test.cc index b2d6b64d..ddc16c4f 100644 --- a/yacl/crypto/base/pke/asymmetric_sm2_crypto_test.cc +++ b/yacl/crypto/pke/asymmetric_sm2_crypto_test.cc @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/pke/asymmetric_sm2_crypto.h" +#include "yacl/crypto/pke/asymmetric_sm2_crypto.h" #include #include "gtest/gtest.h" -#include "yacl/crypto/base/openssl_wrappers.h" +#include "yacl/crypto/openssl_wrappers.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/dpf/BUILD.bazel b/yacl/crypto/primitives/dpf/BUILD.bazel deleted file mode 100644 index 2e8ddb5c..00000000 --- a/yacl/crypto/primitives/dpf/BUILD.bazel +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright 2022 Ant Group Co., Ltd. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -load("//bazel:yacl.bzl", "AES_COPT_FLAGS", "yacl_cc_library", "yacl_cc_test") - -package(default_visibility = ["//visibility:public"]) - -yacl_cc_library( - name = "dpf", - srcs = ["dpf.cc"], - hdrs = ["dpf.h"], - deps = [ - "//yacl/base:int128", - "//yacl/crypto/tools:prg", - "//yacl/link", - ], -) - -yacl_cc_test( - name = "dpf_test", - srcs = ["dpf_test.cc"], - deps = [ - ":dpf", - ], -) - -yacl_cc_library( - name = "mpfss", - srcs = ["mpfss.cc"], - hdrs = ["mpfss.h"], - copts = AES_COPT_FLAGS, - deps = [ - "//yacl/base:aligned_vector", - "//yacl/base:dynamic_bitset", - "//yacl/base:int128", - "//yacl/crypto/primitives/ot:gywz_ote", - "//yacl/crypto/primitives/ot:ot_store", - "//yacl/crypto/primitives/ot:sgrr_ote", - "//yacl/crypto/tools:crhash", - "//yacl/crypto/utils:rand", - "//yacl/crypto/utils:secparam", - "//yacl/math:gadget", - "//yacl/math/f2k", - ], -) - -yacl_cc_test( - name = "mpfss_test", - srcs = ["mpfss_test.cc"], - copts = AES_COPT_FLAGS, - deps = [ - ":mpfss", - "//yacl/crypto/utils:rand", - "//yacl/link:test_util", - "//yacl/math:gadget", - "//yacl/math/f2k", - ], -) diff --git a/yacl/crypto/primitives/vole/BUILD.bazel b/yacl/crypto/primitives/vole/BUILD.bazel deleted file mode 100644 index 63d7ea2a..00000000 --- a/yacl/crypto/primitives/vole/BUILD.bazel +++ /dev/null @@ -1,130 +0,0 @@ -# Copyright 2022 Ant Group Co., Ltd. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -load("//bazel:yacl.bzl", "AES_COPT_FLAGS", "yacl_cc_binary", "yacl_cc_library", "yacl_cc_test") - -package(default_visibility = ["//visibility:public"]) - -yacl_cc_library( - name = "base_vole", - hdrs = ["base_vole.h"], - copts = AES_COPT_FLAGS, - deps = [ - "//yacl/base:aligned_vector", - "//yacl/base:dynamic_bitset", - "//yacl/base:int128", - "//yacl/crypto/primitives/ot:ot_store", - "//yacl/crypto/primitives/ot:softspoken_ote", - "//yacl/crypto/utils:rand", - "//yacl/crypto/utils:secparam", - "//yacl/math:gadget", - "//yacl/utils:serialize", - ], -) - -yacl_cc_test( - name = "base_vole_test", - srcs = ["base_vole_test.cc"], - copts = AES_COPT_FLAGS, - deps = [ - ":base_vole", - "//yacl/crypto/utils:rand", - "//yacl/link:test_util", - "//yacl/math:gadget", - "//yacl/math/f2k", - ], -) - -yacl_cc_library( - name = "mp_vole", - hdrs = ["mp_vole.h"], - copts = AES_COPT_FLAGS, - deps = [ - "//yacl/base:aligned_vector", - "//yacl/base:dynamic_bitset", - "//yacl/base:int128", - "//yacl/crypto/base/hash:hash_utils", - "//yacl/crypto/primitives/dpf:mpfss", - "//yacl/crypto/primitives/ot:ot_store", - "//yacl/crypto/tools:common", - "//yacl/crypto/utils:rand", - "//yacl/crypto/utils:secparam", - "//yacl/math:gadget", - "//yacl/math/f2k", - "//yacl/utils:serialize", - ], -) - -yacl_cc_test( - name = "mp_vole_test", - srcs = ["mp_vole_test.cc"], - copts = AES_COPT_FLAGS, - deps = [ - ":mp_vole", - "//yacl/crypto/utils:rand", - "//yacl/link:test_util", - "//yacl/math:gadget", - "//yacl/math/f2k", - ], -) - -yacl_cc_library( - name = "silent_vole", - srcs = ["silent_vole.cc"], - hdrs = ["silent_vole.h"], - copts = AES_COPT_FLAGS, - deps = [ - ":base_vole", - ":mp_vole", - "//yacl/base:aligned_vector", - "//yacl/base:dynamic_bitset", - "//yacl/base:int128", - "//yacl/crypto/primitives/code:code_interface", - "//yacl/crypto/primitives/code:ea_code", - "//yacl/crypto/primitives/code:silver_code", - "//yacl/crypto/primitives/ot:ot_store", - "//yacl/crypto/primitives/ot:softspoken_ote", - "//yacl/crypto/utils:secparam", - "//yacl/link:context", - ], -) - -yacl_cc_test( - name = "silent_vole_test", - srcs = ["silent_vole_test.cc"], - copts = AES_COPT_FLAGS, - deps = [ - ":silent_vole", - "//yacl/crypto/utils:rand", - "//yacl/link:test_util", - "//yacl/math:gadget", - "//yacl/math/f2k", - ], -) - -yacl_cc_binary( - name = "benchmark", - srcs = [ - "benchmark.cc", - ], - copts = AES_COPT_FLAGS, - deps = [ - ":base_vole", - ":silent_vole", - "//yacl/crypto/utils:rand", - "//yacl/link:test_util", - "@com_github_google_benchmark//:benchmark_main", - "@com_google_absl//absl/numeric:bits", - ], -) diff --git a/yacl/crypto/utils/BUILD.bazel b/yacl/crypto/rand/BUILD.bazel similarity index 73% rename from yacl/crypto/utils/BUILD.bazel rename to yacl/crypto/rand/BUILD.bazel index 9f40739c..8e289f65 100644 --- a/yacl/crypto/utils/BUILD.bazel +++ b/yacl/crypto/rand/BUILD.bazel @@ -21,12 +21,12 @@ yacl_cc_library( srcs = ["rand.cc"], hdrs = ["rand.h"], deps = [ - ":secparam", + "//yacl:secparam", "//yacl/base:dynamic_bitset", "//yacl/base:exception", "//yacl/base:int128", + "//yacl/crypto/rand/drbg", "//yacl/crypto/tools:prg", - "//yacl/crypto/utils/drbg", ], ) @@ -46,25 +46,3 @@ yacl_cc_binary( "@com_github_google_benchmark//:benchmark_main", ], ) - -yacl_cc_library( - name = "secparam", - srcs = ["secparam.cc"], - hdrs = [ - "compile_time_utils.h", - "secparam.h", - ], - deps = [ - "//yacl/base:exception", - "//yacl/base:int128", - "//yacl/math:gadget", - ], -) - -yacl_cc_test( - name = "secparam_test", - srcs = ["secparam_test.cc"], - deps = [ - ":secparam", - ], -) diff --git a/yacl/crypto/utils/drbg/BUILD.bazel b/yacl/crypto/rand/drbg/BUILD.bazel similarity index 88% rename from yacl/crypto/utils/drbg/BUILD.bazel rename to yacl/crypto/rand/drbg/BUILD.bazel index f4b649b9..cf5b0247 100644 --- a/yacl/crypto/utils/drbg/BUILD.bazel +++ b/yacl/crypto/rand/drbg/BUILD.bazel @@ -32,10 +32,10 @@ yacl_cc_library( ], visibility = ["//visibility:private"], deps = [ + "//yacl:secparam", "//yacl/base:byte_container_view", "//yacl/base:int128", - "//yacl/crypto/utils:secparam", - "//yacl/crypto/utils/entropy_source", + "//yacl/crypto/rand/entropy_source", "//yacl/utils/spi", ], ) @@ -55,9 +55,9 @@ yacl_cc_library( visibility = ["//visibility:private"], deps = [ ":spi", - "//yacl/crypto/base:openssl_wrappers", + "//yacl/crypto:openssl_wrappers", "//yacl/crypto/ossl-provider:helper", # helper - "//yacl/crypto/utils/entropy_source", + "//yacl/crypto/rand/entropy_source", ], alwayslink = 1, ) @@ -77,9 +77,9 @@ yacl_cc_library( visibility = ["//visibility:private"], deps = [ ":spi", - "//yacl/crypto/base:openssl_wrappers", + "//yacl/crypto:openssl_wrappers", "//yacl/crypto/ossl-provider:helper", # helper - "//yacl/crypto/utils/entropy_source", + "//yacl/crypto/rand/entropy_source", "@com_github_greendow_hash_drbg//:hash_drbg", ], alwayslink = 1, diff --git a/yacl/crypto/utils/drbg/drbg.h b/yacl/crypto/rand/drbg/drbg.h similarity index 96% rename from yacl/crypto/utils/drbg/drbg.h rename to yacl/crypto/rand/drbg/drbg.h index 66f2c670..8b0865ae 100644 --- a/yacl/crypto/utils/drbg/drbg.h +++ b/yacl/crypto/rand/drbg/drbg.h @@ -20,8 +20,8 @@ #include "yacl/base/exception.h" #include "yacl/base/int128.h" -#include "yacl/crypto/utils/entropy_source/entropy_source.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/crypto/rand/entropy_source/entropy_source.h" +#include "yacl/secparam.h" #include "yacl/utils/spi/spi_factory.h" namespace yacl::crypto { diff --git a/yacl/crypto/utils/drbg/factory_test.cc b/yacl/crypto/rand/drbg/factory_test.cc similarity index 98% rename from yacl/crypto/utils/drbg/factory_test.cc rename to yacl/crypto/rand/drbg/factory_test.cc index dc9150e4..9bcdbe12 100644 --- a/yacl/crypto/utils/drbg/factory_test.cc +++ b/yacl/crypto/rand/drbg/factory_test.cc @@ -15,7 +15,7 @@ #include "gtest/gtest.h" #include "yacl/base/byte_container_view.h" -#include "yacl/crypto/utils/drbg/drbg.h" +#include "yacl/crypto/rand/drbg/drbg.h" namespace yacl::crypto { diff --git a/yacl/crypto/utils/drbg/ic_factory.cc b/yacl/crypto/rand/drbg/ic_factory.cc similarity index 98% rename from yacl/crypto/utils/drbg/ic_factory.cc rename to yacl/crypto/rand/drbg/ic_factory.cc index 4346ba73..f49452a1 100644 --- a/yacl/crypto/utils/drbg/ic_factory.cc +++ b/yacl/crypto/rand/drbg/ic_factory.cc @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/utils/drbg/ic_factory.h" +#include "yacl/crypto/rand/drbg/ic_factory.h" #include #include diff --git a/yacl/crypto/utils/drbg/ic_factory.h b/yacl/crypto/rand/drbg/ic_factory.h similarity index 94% rename from yacl/crypto/utils/drbg/ic_factory.h rename to yacl/crypto/rand/drbg/ic_factory.h index 55c2cccc..76199998 100644 --- a/yacl/crypto/utils/drbg/ic_factory.h +++ b/yacl/crypto/rand/drbg/ic_factory.h @@ -22,9 +22,9 @@ #include "hash_drbg.h" // from @com_github_greendow_hash_drbg//:hash_drbg #include "yacl/base/int128.h" -#include "yacl/crypto/utils/drbg/drbg.h" -#include "yacl/crypto/utils/entropy_source/entropy_source.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/crypto/rand/drbg/drbg.h" +#include "yacl/crypto/rand/entropy_source/entropy_source.h" +#include "yacl/secparam.h" #include "yacl/utils/spi/argument/arg_set.h" namespace yacl::crypto { diff --git a/yacl/crypto/utils/drbg/openssl_factory.cc b/yacl/crypto/rand/drbg/openssl_factory.cc similarity index 97% rename from yacl/crypto/utils/drbg/openssl_factory.cc rename to yacl/crypto/rand/drbg/openssl_factory.cc index b5704672..3a9a166e 100644 --- a/yacl/crypto/utils/drbg/openssl_factory.cc +++ b/yacl/crypto/rand/drbg/openssl_factory.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/utils/drbg/openssl_factory.h" +#include "yacl/crypto/rand/drbg/openssl_factory.h" #include #include @@ -23,7 +23,7 @@ #include "yacl/base/exception.h" #include "yacl/crypto/ossl-provider/helper.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/secparam.h" namespace yacl::crypto { diff --git a/yacl/crypto/utils/drbg/openssl_factory.h b/yacl/crypto/rand/drbg/openssl_factory.h similarity index 92% rename from yacl/crypto/utils/drbg/openssl_factory.h rename to yacl/crypto/rand/drbg/openssl_factory.h index 477a71b2..7f2e2c11 100644 --- a/yacl/crypto/utils/drbg/openssl_factory.h +++ b/yacl/crypto/rand/drbg/openssl_factory.h @@ -20,10 +20,10 @@ #include #include "yacl/base/int128.h" -#include "yacl/crypto/base/openssl_wrappers.h" -#include "yacl/crypto/utils/drbg/drbg.h" -#include "yacl/crypto/utils/entropy_source/entropy_source.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/rand/drbg/drbg.h" +#include "yacl/crypto/rand/entropy_source/entropy_source.h" +#include "yacl/secparam.h" #include "yacl/utils/spi/argument/arg_set.h" namespace yacl::crypto { diff --git a/yacl/crypto/utils/entropy_source/BUILD.bazel b/yacl/crypto/rand/entropy_source/BUILD.bazel similarity index 97% rename from yacl/crypto/utils/entropy_source/BUILD.bazel rename to yacl/crypto/rand/entropy_source/BUILD.bazel index 645674f9..51acd656 100644 --- a/yacl/crypto/utils/entropy_source/BUILD.bazel +++ b/yacl/crypto/rand/entropy_source/BUILD.bazel @@ -36,7 +36,7 @@ yacl_cc_library( ], visibility = ["//visibility:private"], deps = [ - "//yacl/crypto/utils:secparam", + "//yacl:secparam", "//yacl/utils/spi", ], ) diff --git a/yacl/crypto/utils/entropy_source/entropy_source.h b/yacl/crypto/rand/entropy_source/entropy_source.h similarity index 98% rename from yacl/crypto/utils/entropy_source/entropy_source.h rename to yacl/crypto/rand/entropy_source/entropy_source.h index c83dc2bf..288e2721 100644 --- a/yacl/crypto/utils/entropy_source/entropy_source.h +++ b/yacl/crypto/rand/entropy_source/entropy_source.h @@ -18,7 +18,7 @@ #include #include "yacl/base/buffer.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/secparam.h" #include "yacl/utils/spi/spi_factory.h" namespace yacl::crypto { diff --git a/yacl/crypto/utils/entropy_source/factory_test.cc b/yacl/crypto/rand/entropy_source/factory_test.cc similarity index 96% rename from yacl/crypto/utils/entropy_source/factory_test.cc rename to yacl/crypto/rand/entropy_source/factory_test.cc index 33bdfe6c..08c6a2b3 100644 --- a/yacl/crypto/utils/entropy_source/factory_test.cc +++ b/yacl/crypto/rand/entropy_source/factory_test.cc @@ -14,7 +14,7 @@ #include "gtest/gtest.h" -#include "yacl/crypto/utils/entropy_source/entropy_source.h" +#include "yacl/crypto/rand/entropy_source/entropy_source.h" namespace yacl::crypto { diff --git a/yacl/crypto/utils/entropy_source/intel_factory.cc b/yacl/crypto/rand/entropy_source/intel_factory.cc similarity index 97% rename from yacl/crypto/utils/entropy_source/intel_factory.cc rename to yacl/crypto/rand/entropy_source/intel_factory.cc index 1bb88d58..7b0c67bd 100644 --- a/yacl/crypto/utils/entropy_source/intel_factory.cc +++ b/yacl/crypto/rand/entropy_source/intel_factory.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/utils/entropy_source/intel_factory.h" +#include "yacl/crypto/rand/entropy_source/intel_factory.h" #include diff --git a/yacl/crypto/utils/entropy_source/intel_factory.h b/yacl/crypto/rand/entropy_source/intel_factory.h similarity index 96% rename from yacl/crypto/utils/entropy_source/intel_factory.h rename to yacl/crypto/rand/entropy_source/intel_factory.h index dc23a474..065d7724 100644 --- a/yacl/crypto/utils/entropy_source/intel_factory.h +++ b/yacl/crypto/rand/entropy_source/intel_factory.h @@ -18,7 +18,7 @@ #include #include -#include "yacl/crypto/utils/entropy_source/entropy_source.h" +#include "yacl/crypto/rand/entropy_source/entropy_source.h" #ifdef __x86_64 #include diff --git a/yacl/crypto/utils/entropy_source/urandom_factory.cc b/yacl/crypto/rand/entropy_source/urandom_factory.cc similarity index 96% rename from yacl/crypto/utils/entropy_source/urandom_factory.cc rename to yacl/crypto/rand/entropy_source/urandom_factory.cc index 2cc95d19..37ec94c4 100644 --- a/yacl/crypto/utils/entropy_source/urandom_factory.cc +++ b/yacl/crypto/rand/entropy_source/urandom_factory.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/utils/entropy_source/urandom_factory.h" +#include "yacl/crypto/rand/entropy_source/urandom_factory.h" #include #include diff --git a/yacl/crypto/utils/entropy_source/urandom_factory.h b/yacl/crypto/rand/entropy_source/urandom_factory.h similarity index 96% rename from yacl/crypto/utils/entropy_source/urandom_factory.h rename to yacl/crypto/rand/entropy_source/urandom_factory.h index e493c8b8..8ad8a3dc 100644 --- a/yacl/crypto/utils/entropy_source/urandom_factory.h +++ b/yacl/crypto/rand/entropy_source/urandom_factory.h @@ -18,7 +18,7 @@ #include #include -#include "yacl/crypto/utils/entropy_source/entropy_source.h" +#include "yacl/crypto/rand/entropy_source/entropy_source.h" namespace yacl::crypto { diff --git a/yacl/crypto/utils/rand.cc b/yacl/crypto/rand/rand.cc similarity index 97% rename from yacl/crypto/utils/rand.cc rename to yacl/crypto/rand/rand.cc index 73346d65..eab1edbd 100644 --- a/yacl/crypto/utils/rand.cc +++ b/yacl/crypto/rand/rand.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" #include #include @@ -20,7 +20,7 @@ #include "yacl/base/byte_container_view.h" #include "yacl/base/dynamic_bitset.h" #include "yacl/crypto/ossl-provider/helper.h" -#include "yacl/crypto/utils/entropy_source/entropy_source.h" +#include "yacl/crypto/rand/entropy_source/entropy_source.h" namespace yacl::crypto { diff --git a/yacl/crypto/utils/rand.h b/yacl/crypto/rand/rand.h similarity index 97% rename from yacl/crypto/utils/rand.h rename to yacl/crypto/rand/rand.h index a07cc1ce..5cadde2b 100644 --- a/yacl/crypto/utils/rand.h +++ b/yacl/crypto/rand/rand.h @@ -24,9 +24,9 @@ #include "yacl/base/dynamic_bitset.h" #include "yacl/base/int128.h" -#include "yacl/crypto/base/openssl_wrappers.h" -#include "yacl/crypto/utils/drbg/drbg.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/rand/drbg/drbg.h" +#include "yacl/secparam.h" YACL_MODULE_DECLARE("rand", SecParam::C::k256, SecParam::S::INF); diff --git a/yacl/crypto/utils/rand_bench.cc b/yacl/crypto/rand/rand_bench.cc similarity index 97% rename from yacl/crypto/utils/rand_bench.cc rename to yacl/crypto/rand/rand_bench.cc index 4aff8af0..b6e60d5b 100644 --- a/yacl/crypto/utils/rand_bench.cc +++ b/yacl/crypto/rand/rand_bench.cc @@ -18,8 +18,8 @@ #include "benchmark/benchmark.h" -#include "yacl/crypto/utils/rand.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/crypto/rand/rand.h" +#include "yacl/secparam.h" namespace yacl::crypto { diff --git a/yacl/crypto/utils/rand_test.cc b/yacl/crypto/rand/rand_test.cc similarity index 97% rename from yacl/crypto/utils/rand_test.cc rename to yacl/crypto/rand/rand_test.cc index 57782bf4..496f51bf 100644 --- a/yacl/crypto/utils/rand_test.cc +++ b/yacl/crypto/rand/rand_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" #include "gtest/gtest.h" diff --git a/yacl/crypto/base/sign/BUILD.bazel b/yacl/crypto/sign/BUILD.bazel similarity index 84% rename from yacl/crypto/base/sign/BUILD.bazel rename to yacl/crypto/sign/BUILD.bazel index 16823f2f..6d2bc43b 100644 --- a/yacl/crypto/base/sign/BUILD.bazel +++ b/yacl/crypto/sign/BUILD.bazel @@ -30,9 +30,9 @@ yacl_cc_library( hdrs = ["sm2_signing.h"], deps = [ ":signing", - "//yacl/crypto/base:key_utils", - "//yacl/crypto/base/hash:hash_utils", - "//yacl/crypto/utils:secparam", + "//yacl:secparam", + "//yacl/crypto:key_utils", + "//yacl/crypto/hash:hash_utils", ], ) @@ -50,9 +50,9 @@ yacl_cc_library( hdrs = ["rsa_signing.h"], deps = [ ":signing", - "//yacl/crypto/base:key_utils", - "//yacl/crypto/base/hash:hash_utils", - "//yacl/crypto/utils:secparam", + "//yacl:secparam", + "//yacl/crypto:key_utils", + "//yacl/crypto/hash:hash_utils", ], ) diff --git a/yacl/crypto/base/sign/rsa_signing.cc b/yacl/crypto/sign/rsa_signing.cc similarity index 98% rename from yacl/crypto/base/sign/rsa_signing.cc rename to yacl/crypto/sign/rsa_signing.cc index e4ff4ef3..e4a48b86 100644 --- a/yacl/crypto/base/sign/rsa_signing.cc +++ b/yacl/crypto/sign/rsa_signing.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/sign/rsa_signing.h" +#include "yacl/crypto/sign/rsa_signing.h" #include diff --git a/yacl/crypto/base/sign/rsa_signing.h b/yacl/crypto/sign/rsa_signing.h similarity index 92% rename from yacl/crypto/base/sign/rsa_signing.h rename to yacl/crypto/sign/rsa_signing.h index ca48537a..5dca75f9 100644 --- a/yacl/crypto/base/sign/rsa_signing.h +++ b/yacl/crypto/sign/rsa_signing.h @@ -17,12 +17,12 @@ #include #include -#include "yacl/crypto/base/key_utils.h" -#include "yacl/crypto/base/sign/signing.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/crypto/key_utils.h" +#include "yacl/crypto/sign/signing.h" +#include "yacl/secparam.h" /* submodules */ -#include "yacl/crypto/base/hash/hash_utils.h" +#include "yacl/crypto/hash/hash_utils.h" /* security parameter declaration */ YACL_MODULE_DECLARE("rsa_sign", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/base/sign/rsa_signing_test.cc b/yacl/crypto/sign/rsa_signing_test.cc similarity index 97% rename from yacl/crypto/base/sign/rsa_signing_test.cc rename to yacl/crypto/sign/rsa_signing_test.cc index e7642728..159e2a1e 100644 --- a/yacl/crypto/base/sign/rsa_signing_test.cc +++ b/yacl/crypto/sign/rsa_signing_test.cc @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/sign/rsa_signing.h" +#include "yacl/crypto/sign/rsa_signing.h" #include #include "gtest/gtest.h" -#include "yacl/crypto/base/openssl_wrappers.h" +#include "yacl/crypto/openssl_wrappers.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/sign/signing.h b/yacl/crypto/sign/signing.h similarity index 100% rename from yacl/crypto/base/sign/signing.h rename to yacl/crypto/sign/signing.h diff --git a/yacl/crypto/base/sign/sm2_signing.cc b/yacl/crypto/sign/sm2_signing.cc similarity index 98% rename from yacl/crypto/base/sign/sm2_signing.cc rename to yacl/crypto/sign/sm2_signing.cc index e80a4c46..7e69c285 100644 --- a/yacl/crypto/base/sign/sm2_signing.cc +++ b/yacl/crypto/sign/sm2_signing.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/sign/sm2_signing.h" +#include "yacl/crypto/sign/sm2_signing.h" namespace yacl::crypto { diff --git a/yacl/crypto/base/sign/sm2_signing.h b/yacl/crypto/sign/sm2_signing.h similarity index 92% rename from yacl/crypto/base/sign/sm2_signing.h rename to yacl/crypto/sign/sm2_signing.h index 6a8c342e..9a65f8ec 100644 --- a/yacl/crypto/base/sign/sm2_signing.h +++ b/yacl/crypto/sign/sm2_signing.h @@ -17,12 +17,12 @@ #include #include -#include "yacl/crypto/base/key_utils.h" -#include "yacl/crypto/base/sign/signing.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/crypto/key_utils.h" +#include "yacl/crypto/sign/signing.h" +#include "yacl/secparam.h" /* submodules */ -#include "yacl/crypto/base/hash/hash_utils.h" +#include "yacl/crypto/hash/hash_utils.h" /* security parameter declaration */ YACL_MODULE_DECLARE("sm2_sign", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/base/sign/sm2_signing_test.cc b/yacl/crypto/sign/sm2_signing_test.cc similarity index 97% rename from yacl/crypto/base/sign/sm2_signing_test.cc rename to yacl/crypto/sign/sm2_signing_test.cc index ec01a0c6..65826679 100644 --- a/yacl/crypto/base/sign/sm2_signing_test.cc +++ b/yacl/crypto/sign/sm2_signing_test.cc @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/base/sign/sm2_signing.h" +#include "yacl/crypto/sign/sm2_signing.h" #include #include "gtest/gtest.h" -#include "yacl/crypto/base/openssl_wrappers.h" +#include "yacl/crypto/openssl_wrappers.h" namespace yacl::crypto { diff --git a/yacl/crypto/tools/BUILD.bazel b/yacl/crypto/tools/BUILD.bazel index 594d7e62..81ad9a00 100644 --- a/yacl/crypto/tools/BUILD.bazel +++ b/yacl/crypto/tools/BUILD.bazel @@ -30,9 +30,9 @@ yacl_cc_library( srcs = ["prg.cc"], hdrs = ["prg.h"], deps = [ + "//yacl:secparam", "//yacl/base:dynamic_bitset", - "//yacl/crypto/base/block_cipher:symmetric_crypto", - "//yacl/crypto/utils:secparam", + "//yacl/crypto/block_cipher:symmetric_crypto", ], ) @@ -48,7 +48,7 @@ yacl_cc_library( name = "ro", hdrs = ["ro.h"], deps = [ - "//yacl/crypto/base/hash:hash_utils", + "//yacl/crypto/hash:hash_utils", ], ) @@ -57,7 +57,7 @@ yacl_cc_test( srcs = ["ro_test.cc"], deps = [ ":ro", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", ], ) @@ -66,7 +66,7 @@ yacl_cc_library( srcs = ["rp.cc"], hdrs = ["rp.h"], deps = [ - "//yacl/crypto/base/block_cipher:symmetric_crypto", + "//yacl/crypto/block_cipher:symmetric_crypto", ], ) @@ -76,7 +76,7 @@ yacl_cc_test( deps = [ ":prg", ":rp", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", ], ) @@ -86,8 +86,8 @@ yacl_cc_library( hdrs = ["crhash.h"], deps = [ ":rp", - "//yacl/crypto/base/aes:aes_intrinsics", - "//yacl/crypto/utils:rand", + "//yacl/crypto/aes:aes_intrinsics", + "//yacl/crypto/rand", ], ) @@ -112,7 +112,7 @@ yacl_cc_binary( ":ro", ":rp", "//yacl/base:aligned_vector", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", "@com_github_google_benchmark//:benchmark_main", ], ) diff --git a/yacl/crypto/tools/benchmark.h b/yacl/crypto/tools/benchmark.h index 6f17395f..34bea4a5 100644 --- a/yacl/crypto/tools/benchmark.h +++ b/yacl/crypto/tools/benchmark.h @@ -19,11 +19,11 @@ #include "benchmark/benchmark.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/crhash.h" #include "yacl/crypto/tools/prg.h" #include "yacl/crypto/tools/ro.h" #include "yacl/crypto/tools/rp.h" -#include "yacl/crypto/utils/rand.h" namespace yacl::crypto { diff --git a/yacl/crypto/tools/crhash_test.cc b/yacl/crypto/tools/crhash_test.cc index 0571bb52..40d19a46 100644 --- a/yacl/crypto/tools/crhash_test.cc +++ b/yacl/crypto/tools/crhash_test.cc @@ -19,8 +19,8 @@ #include "gtest/gtest.h" #include "yacl/base/exception.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/prg.h" -#include "yacl/crypto/utils/rand.h" namespace yacl::crypto { diff --git a/yacl/crypto/tools/prg.h b/yacl/crypto/tools/prg.h index b479131e..a75d3311 100644 --- a/yacl/crypto/tools/prg.h +++ b/yacl/crypto/tools/prg.h @@ -22,10 +22,10 @@ #include "yacl/base/dynamic_bitset.h" #include "yacl/base/int128.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/secparam.h" /* submodules */ -#include "yacl/crypto/base/block_cipher/symmetric_crypto.h" +#include "yacl/crypto/block_cipher/symmetric_crypto.h" /* security parameter declaration */ YACL_MODULE_DECLARE("prg", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/tools/ro.h b/yacl/crypto/tools/ro.h index 4c51af2f..7c9dacb0 100644 --- a/yacl/crypto/tools/ro.h +++ b/yacl/crypto/tools/ro.h @@ -22,7 +22,7 @@ #include "yacl/base/exception.h" /* submodules */ -#include "yacl/crypto/base/hash/hash_utils.h" +#include "yacl/crypto/hash/hash_utils.h" namespace yacl::crypto { diff --git a/yacl/crypto/tools/ro_test.cc b/yacl/crypto/tools/ro_test.cc index da78f87b..8f926f40 100644 --- a/yacl/crypto/tools/ro_test.cc +++ b/yacl/crypto/tools/ro_test.cc @@ -21,7 +21,7 @@ #include "yacl/base/byte_container_view.h" #include "yacl/base/exception.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" namespace yacl::crypto { diff --git a/yacl/crypto/tools/rp.h b/yacl/crypto/tools/rp.h index 4fe871e1..c391abbc 100644 --- a/yacl/crypto/tools/rp.h +++ b/yacl/crypto/tools/rp.h @@ -22,8 +22,8 @@ #include "yacl/base/int128.h" /* submodules */ -// #include "yacl/crypto/base/aes/aes_intrinsics.h" -#include "yacl/crypto/base/block_cipher/symmetric_crypto.h" +// #include "yacl/crypto/aes/aes_intrinsics.h" +#include "yacl/crypto/block_cipher/symmetric_crypto.h" namespace yacl::crypto { diff --git a/yacl/crypto/tools/rp_test.cc b/yacl/crypto/tools/rp_test.cc index bf2e161e..a45fbdce 100644 --- a/yacl/crypto/tools/rp_test.cc +++ b/yacl/crypto/tools/rp_test.cc @@ -20,8 +20,8 @@ #include "gtest/gtest.h" #include "yacl/base/exception.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/prg.h" -#include "yacl/crypto/utils/rand.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/tpre/BUILD.bazel b/yacl/crypto/tpre/BUILD.bazel similarity index 79% rename from yacl/crypto/primitives/tpre/BUILD.bazel rename to yacl/crypto/tpre/BUILD.bazel index 260d8b52..80abf768 100644 --- a/yacl/crypto/primitives/tpre/BUILD.bazel +++ b/yacl/crypto/tpre/BUILD.bazel @@ -20,7 +20,7 @@ yacl_cc_library( name = "kdf", srcs = ["kdf.cc"], hdrs = ["kdf.h"], - deps = ["//yacl/crypto/base/hash:hash_utils"], + deps = ["//yacl/crypto/hash:hash_utils"], ) yacl_cc_test( @@ -35,8 +35,8 @@ yacl_cc_library( hdrs = ["hash.h"], deps = [ ":kdf", - "//yacl/crypto/base/ecc:spi", - "//yacl/crypto/base/hash:hash_utils", + "//yacl/crypto/ecc:spi", + "//yacl/crypto/hash:hash_utils", "//yacl/math/mpint", ], ) @@ -46,7 +46,7 @@ yacl_cc_test( srcs = ["hash_test.cc"], deps = [ ":hash", - "//yacl/crypto/base/ecc", + "//yacl/crypto/ecc", "//yacl/math/mpint", ], ) @@ -57,7 +57,7 @@ yacl_cc_library( hdrs = ["keys.h"], deps = [ ":hash", - "//yacl/crypto/base/ecc:spi", + "//yacl/crypto/ecc:spi", "//yacl/math/mpint", ], ) @@ -67,8 +67,8 @@ yacl_cc_test( srcs = ["keys_test.cc"], deps = [ ":keys", - "//yacl/crypto/base/ecc", - "//yacl/crypto/base/ecc:spi", + "//yacl/crypto/ecc", + "//yacl/crypto/ecc:spi", "//yacl/math/mpint", ], ) @@ -83,8 +83,8 @@ yacl_cc_library( deps = [ ":hash", ":kdf", - "//yacl/crypto/base/ecc:spi", - "//yacl/crypto/base/hash:hash_utils", + "//yacl/crypto/ecc:spi", + "//yacl/crypto/hash:hash_utils", "//yacl/math/mpint", ], ) @@ -96,8 +96,8 @@ yacl_cc_test( ":capsule", ":keys", "//yacl/base:exception", - "//yacl/crypto/base/ecc", - "//yacl/crypto/base/ecc:spi", + "//yacl/crypto/ecc", + "//yacl/crypto/ecc:spi", "//yacl/math/mpint", "//yacl/utils:scope_guard", "@com_google_absl//absl/strings", @@ -115,8 +115,8 @@ yacl_cc_library( deps = [ ":capsule", ":keys", - "//yacl/crypto/base/aead:sm4_mac", - "//yacl/crypto/base/ecc:spi", + "//yacl/crypto/aead:sm4_mac", + "//yacl/crypto/ecc:spi", ], ) @@ -127,8 +127,8 @@ yacl_cc_test( ":capsule", ":keys", ":tpre", - "//yacl/crypto/base/ecc", - "//yacl/crypto/base/ecc:spi", + "//yacl/crypto/ecc", + "//yacl/crypto/ecc:spi", "@com_google_absl//absl/strings", ], ) diff --git a/yacl/crypto/primitives/tpre/README.md b/yacl/crypto/tpre/README.md similarity index 100% rename from yacl/crypto/primitives/tpre/README.md rename to yacl/crypto/tpre/README.md diff --git a/yacl/crypto/primitives/tpre/capsule.cc b/yacl/crypto/tpre/capsule.cc similarity index 96% rename from yacl/crypto/primitives/tpre/capsule.cc rename to yacl/crypto/tpre/capsule.cc index 200ecb20..e634754a 100644 --- a/yacl/crypto/primitives/tpre/capsule.cc +++ b/yacl/crypto/tpre/capsule.cc @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/tpre/capsule.h" +#include "yacl/crypto/tpre/capsule.h" #include "yacl/base/exception.h" -#include "yacl/crypto/base/hash/hash_utils.h" -#include "yacl/crypto/primitives/tpre/hash.h" -#include "yacl/crypto/primitives/tpre/kdf.h" +#include "yacl/crypto/hash/hash_utils.h" +#include "yacl/crypto/tpre/hash.h" +#include "yacl/crypto/tpre/kdf.h" #include "yacl/utils/scope_guard.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/tpre/capsule.h b/yacl/crypto/tpre/capsule.h similarity index 97% rename from yacl/crypto/primitives/tpre/capsule.h rename to yacl/crypto/tpre/capsule.h index cf0e838d..46eafd86 100644 --- a/yacl/crypto/primitives/tpre/capsule.h +++ b/yacl/crypto/tpre/capsule.h @@ -20,8 +20,8 @@ #include #include -#include "yacl/crypto/base/ecc/ec_point.h" -#include "yacl/crypto/primitives/tpre/keys.h" +#include "yacl/crypto/ecc/ec_point.h" +#include "yacl/crypto/tpre/keys.h" #include "yacl/math/mpint/mp_int.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/tpre/capsule_test.cc b/yacl/crypto/tpre/capsule_test.cc similarity index 95% rename from yacl/crypto/primitives/tpre/capsule_test.cc rename to yacl/crypto/tpre/capsule_test.cc index 62b1f3ff..294741c6 100644 --- a/yacl/crypto/primitives/tpre/capsule_test.cc +++ b/yacl/crypto/tpre/capsule_test.cc @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/tpre/capsule.h" +#include "yacl/crypto/tpre/capsule.h" #include "absl/strings/escaping.h" #include "absl/strings/string_view.h" #include "gtest/gtest.h" -#include "yacl/crypto/primitives/tpre/keys.h" +#include "yacl/crypto/tpre/keys.h" namespace yacl::crypto::test { diff --git a/yacl/crypto/primitives/tpre/hash.cc b/yacl/crypto/tpre/hash.cc similarity index 92% rename from yacl/crypto/primitives/tpre/hash.cc rename to yacl/crypto/tpre/hash.cc index 6b7eb79e..f6574686 100644 --- a/yacl/crypto/primitives/tpre/hash.cc +++ b/yacl/crypto/tpre/hash.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/tpre/hash.h" +#include "yacl/crypto/tpre/hash.h" #include #include @@ -21,8 +21,8 @@ #include #include -#include "yacl/crypto/base/hash/hash_utils.h" -#include "yacl/crypto/primitives/tpre/kdf.h" +#include "yacl/crypto/hash/hash_utils.h" +#include "yacl/crypto/tpre/kdf.h" namespace yacl::crypto { // h_x = 1 + Bignum(sm3(x)||sm3(sm3(x))) mod n-1 diff --git a/yacl/crypto/primitives/tpre/hash.h b/yacl/crypto/tpre/hash.h similarity index 96% rename from yacl/crypto/primitives/tpre/hash.h rename to yacl/crypto/tpre/hash.h index 6c25f9e9..a0bacfce 100644 --- a/yacl/crypto/primitives/tpre/hash.h +++ b/yacl/crypto/tpre/hash.h @@ -16,7 +16,7 @@ #include -#include "yacl/crypto/base/ecc/ecc_spi.h" +#include "yacl/crypto/ecc/ecc_spi.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/tpre/hash_test.cc b/yacl/crypto/tpre/hash_test.cc similarity index 97% rename from yacl/crypto/primitives/tpre/hash_test.cc rename to yacl/crypto/tpre/hash_test.cc index b37eca04..a3318b89 100644 --- a/yacl/crypto/primitives/tpre/hash_test.cc +++ b/yacl/crypto/tpre/hash_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/tpre/hash.h" +#include "yacl/crypto/tpre/hash.h" #include "gtest/gtest.h" diff --git a/yacl/crypto/primitives/tpre/kdf.cc b/yacl/crypto/tpre/kdf.cc similarity index 97% rename from yacl/crypto/primitives/tpre/kdf.cc rename to yacl/crypto/tpre/kdf.cc index 6c0529b2..3e5e36b9 100644 --- a/yacl/crypto/primitives/tpre/kdf.cc +++ b/yacl/crypto/tpre/kdf.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/tpre/kdf.h" +#include "yacl/crypto/tpre/kdf.h" #include diff --git a/yacl/crypto/primitives/tpre/kdf.h b/yacl/crypto/tpre/kdf.h similarity index 96% rename from yacl/crypto/primitives/tpre/kdf.h rename to yacl/crypto/tpre/kdf.h index 80806988..fe1e9926 100644 --- a/yacl/crypto/primitives/tpre/kdf.h +++ b/yacl/crypto/tpre/kdf.h @@ -17,7 +17,7 @@ #include #include -#include "yacl/crypto/base/hash/hash_utils.h" +#include "yacl/crypto/hash/hash_utils.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/tpre/kdf_test.cc b/yacl/crypto/tpre/kdf_test.cc similarity index 95% rename from yacl/crypto/primitives/tpre/kdf_test.cc rename to yacl/crypto/tpre/kdf_test.cc index 3ae38b17..f2f890a3 100644 --- a/yacl/crypto/primitives/tpre/kdf_test.cc +++ b/yacl/crypto/tpre/kdf_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/tpre/kdf.h" +#include "yacl/crypto/tpre/kdf.h" #include #include diff --git a/yacl/crypto/primitives/tpre/keys.cc b/yacl/crypto/tpre/keys.cc similarity index 99% rename from yacl/crypto/primitives/tpre/keys.cc rename to yacl/crypto/tpre/keys.cc index 47d88b2f..b86615d4 100644 --- a/yacl/crypto/primitives/tpre/keys.cc +++ b/yacl/crypto/tpre/keys.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/tpre/keys.h" +#include "yacl/crypto/tpre/keys.h" #include diff --git a/yacl/crypto/primitives/tpre/keys.h b/yacl/crypto/tpre/keys.h similarity index 97% rename from yacl/crypto/primitives/tpre/keys.h rename to yacl/crypto/tpre/keys.h index f48365bd..e79da75b 100644 --- a/yacl/crypto/primitives/tpre/keys.h +++ b/yacl/crypto/tpre/keys.h @@ -20,8 +20,8 @@ #include #include -#include "yacl/crypto/base/ecc/ec_point.h" -#include "yacl/crypto/primitives/tpre/hash.h" +#include "yacl/crypto/ecc/ec_point.h" +#include "yacl/crypto/tpre/hash.h" #include "yacl/math/mpint/mp_int.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/tpre/keys_test.cc b/yacl/crypto/tpre/keys_test.cc similarity index 97% rename from yacl/crypto/primitives/tpre/keys_test.cc rename to yacl/crypto/tpre/keys_test.cc index 0818ae45..cf2553b6 100644 --- a/yacl/crypto/primitives/tpre/keys_test.cc +++ b/yacl/crypto/tpre/keys_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/tpre/keys.h" +#include "yacl/crypto/tpre/keys.h" #include diff --git a/yacl/crypto/primitives/tpre/tpre.cc b/yacl/crypto/tpre/tpre.cc similarity index 95% rename from yacl/crypto/primitives/tpre/tpre.cc rename to yacl/crypto/tpre/tpre.cc index 3eab8a01..0362f048 100644 --- a/yacl/crypto/primitives/tpre/tpre.cc +++ b/yacl/crypto/tpre/tpre.cc @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/tpre/tpre.h" +#include "yacl/crypto/tpre/tpre.h" #include -#include "yacl/crypto/base/aead/sm4_mac.h" -#include "yacl/crypto/primitives/tpre/capsule.h" +#include "yacl/crypto/aead/sm4_mac.h" +#include "yacl/crypto/tpre/capsule.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/tpre/tpre.h b/yacl/crypto/tpre/tpre.h similarity index 98% rename from yacl/crypto/primitives/tpre/tpre.h rename to yacl/crypto/tpre/tpre.h index 7a98e5d4..82de7a3d 100644 --- a/yacl/crypto/primitives/tpre/tpre.h +++ b/yacl/crypto/tpre/tpre.h @@ -20,8 +20,8 @@ #include #include -#include "yacl/crypto/primitives/tpre/capsule.h" -#include "yacl/crypto/primitives/tpre/keys.h" +#include "yacl/crypto/tpre/capsule.h" +#include "yacl/crypto/tpre/keys.h" namespace yacl::crypto { /** diff --git a/yacl/crypto/primitives/tpre/tpre_test.cc b/yacl/crypto/tpre/tpre_test.cc similarity index 98% rename from yacl/crypto/primitives/tpre/tpre_test.cc rename to yacl/crypto/tpre/tpre_test.cc index c7131d92..e1cac440 100644 --- a/yacl/crypto/primitives/tpre/tpre_test.cc +++ b/yacl/crypto/tpre/tpre_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/tpre/tpre.h" +#include "yacl/crypto/tpre/tpre.h" #include "absl/strings/escaping.h" #include "gtest/gtest.h" diff --git a/yacl/crypto/primitives/vss/BUILD.bazel b/yacl/crypto/vss/BUILD.bazel similarity index 94% rename from yacl/crypto/primitives/vss/BUILD.bazel rename to yacl/crypto/vss/BUILD.bazel index 6f51b969..6cd9f668 100644 --- a/yacl/crypto/primitives/vss/BUILD.bazel +++ b/yacl/crypto/vss/BUILD.bazel @@ -31,7 +31,7 @@ yacl_cc_library( hdrs = ["vss.h"], deps = [ ":poly", - "//yacl/crypto/base/ecc", + "//yacl/crypto/ecc", "//yacl/math/mpint", ], ) @@ -42,7 +42,7 @@ yacl_cc_test( deps = [ ":poly", ":vss", - "//yacl/crypto/base/ecc", + "//yacl/crypto/ecc", "//yacl/math/mpint", ], ) diff --git a/yacl/crypto/primitives/vss/poly.cc b/yacl/crypto/vss/poly.cc similarity index 99% rename from yacl/crypto/primitives/vss/poly.cc rename to yacl/crypto/vss/poly.cc index 2e9e8b4c..7f7048fa 100644 --- a/yacl/crypto/primitives/vss/poly.cc +++ b/yacl/crypto/vss/poly.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/vss/poly.h" +#include "yacl/crypto/vss/poly.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/vss/poly.h b/yacl/crypto/vss/poly.h similarity index 100% rename from yacl/crypto/primitives/vss/poly.h rename to yacl/crypto/vss/poly.h diff --git a/yacl/crypto/primitives/vss/vss.cc b/yacl/crypto/vss/vss.cc similarity index 99% rename from yacl/crypto/primitives/vss/vss.cc rename to yacl/crypto/vss/vss.cc index 1003df35..b1393165 100644 --- a/yacl/crypto/primitives/vss/vss.cc +++ b/yacl/crypto/vss/vss.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/vss/vss.h" +#include "yacl/crypto/vss/vss.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/vss/vss.h b/yacl/crypto/vss/vss.h similarity index 98% rename from yacl/crypto/primitives/vss/vss.h rename to yacl/crypto/vss/vss.h index 937cbd02..8c0a3160 100644 --- a/yacl/crypto/primitives/vss/vss.h +++ b/yacl/crypto/vss/vss.h @@ -20,8 +20,8 @@ #include #include -#include "yacl/crypto/base/ecc/ecc_spi.h" -#include "yacl/crypto/primitives/vss/poly.h" +#include "yacl/crypto/ecc/ecc_spi.h" +#include "yacl/crypto/vss/poly.h" #include "yacl/math/mpint/mp_int.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/vss/vss_test.cc b/yacl/crypto/vss/vss_test.cc similarity index 95% rename from yacl/crypto/primitives/vss/vss_test.cc rename to yacl/crypto/vss/vss_test.cc index 67ebdb44..931af00f 100644 --- a/yacl/crypto/primitives/vss/vss_test.cc +++ b/yacl/crypto/vss/vss_test.cc @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/vss/vss.h" +#include "yacl/crypto/vss/vss.h" #include "gtest/gtest.h" #include "spdlog/spdlog.h" -#include "yacl/crypto/base/ecc/ecc_spi.h" -#include "yacl/crypto/primitives/vss/poly.h" +#include "yacl/crypto/ecc/ecc_spi.h" +#include "yacl/crypto/vss/poly.h" #include "yacl/math/mpint/mp_int.h" namespace yacl::crypto::test { diff --git a/yacl/crypto/primitives/zkp/BUILD.bazel b/yacl/crypto/zkp/BUILD.bazel similarity index 87% rename from yacl/crypto/primitives/zkp/BUILD.bazel rename to yacl/crypto/zkp/BUILD.bazel index 65f7cdff..fc851718 100644 --- a/yacl/crypto/primitives/zkp/BUILD.bazel +++ b/yacl/crypto/zkp/BUILD.bazel @@ -23,8 +23,8 @@ yacl_cc_library( "sigma_config.h", ], deps = [ - "//yacl/crypto/base/ecc", - "//yacl/crypto/base/hash:hash_interface", + "//yacl/crypto/ecc", + "//yacl/crypto/hash:hash_interface", ], ) @@ -36,7 +36,7 @@ yacl_cc_library( ], deps = [ ":sigma_config", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", ], ) @@ -58,7 +58,7 @@ yacl_cc_test( deps = [ ":sigma", ":sigma_owh", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", ], ) @@ -69,7 +69,7 @@ yacl_cc_library( ], deps = [ ":sigma_owh", - "//yacl/crypto/base/hash:hash_utils", + "//yacl/crypto/hash:hash_utils", ], ) @@ -78,6 +78,6 @@ yacl_cc_test( srcs = ["pedersen_commit_test.cc"], deps = [ ":pedersen_commit", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", ], ) diff --git a/yacl/crypto/primitives/zkp/pedersen_commit.h b/yacl/crypto/zkp/pedersen_commit.h similarity index 97% rename from yacl/crypto/primitives/zkp/pedersen_commit.h rename to yacl/crypto/zkp/pedersen_commit.h index af6992d2..c2517e6a 100644 --- a/yacl/crypto/primitives/zkp/pedersen_commit.h +++ b/yacl/crypto/zkp/pedersen_commit.h @@ -14,8 +14,8 @@ #pragma once -#include "yacl/crypto/base/hash/hash_utils.h" -#include "yacl/crypto/primitives/zkp/sigma_owh.h" +#include "yacl/crypto/hash/hash_utils.h" +#include "yacl/crypto/zkp/sigma_owh.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/zkp/pedersen_commit_test.cc b/yacl/crypto/zkp/pedersen_commit_test.cc similarity index 95% rename from yacl/crypto/primitives/zkp/pedersen_commit_test.cc rename to yacl/crypto/zkp/pedersen_commit_test.cc index a1b032a1..81502c67 100644 --- a/yacl/crypto/primitives/zkp/pedersen_commit_test.cc +++ b/yacl/crypto/zkp/pedersen_commit_test.cc @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/zkp/pedersen_commit.h" +#include "yacl/crypto/zkp/pedersen_commit.h" #include "gtest/gtest.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/zkp/sigma.cc b/yacl/crypto/zkp/sigma.cc similarity index 99% rename from yacl/crypto/primitives/zkp/sigma.cc rename to yacl/crypto/zkp/sigma.cc index 14958593..247f6fbe 100644 --- a/yacl/crypto/primitives/zkp/sigma.cc +++ b/yacl/crypto/zkp/sigma.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/zkp/sigma.h" +#include "yacl/crypto/zkp/sigma.h" #include "yacl/crypto/tools/ro.h" diff --git a/yacl/crypto/primitives/zkp/sigma.h b/yacl/crypto/zkp/sigma.h similarity index 98% rename from yacl/crypto/primitives/zkp/sigma.h rename to yacl/crypto/zkp/sigma.h index 6cdac92b..a51f4683 100644 --- a/yacl/crypto/primitives/zkp/sigma.h +++ b/yacl/crypto/zkp/sigma.h @@ -14,8 +14,8 @@ #pragma once -#include "yacl/crypto/primitives/zkp/sigma_config.h" -#include "yacl/crypto/primitives/zkp/sigma_owh.h" +#include "yacl/crypto/zkp/sigma_config.h" +#include "yacl/crypto/zkp/sigma_owh.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/zkp/sigma_config.cc b/yacl/crypto/zkp/sigma_config.cc similarity index 98% rename from yacl/crypto/primitives/zkp/sigma_config.cc rename to yacl/crypto/zkp/sigma_config.cc index 0af3f31a..60155426 100644 --- a/yacl/crypto/primitives/zkp/sigma_config.cc +++ b/yacl/crypto/zkp/sigma_config.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/zkp/sigma_config.h" +#include "yacl/crypto/zkp/sigma_config.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/zkp/sigma_config.h b/yacl/crypto/zkp/sigma_config.h similarity index 98% rename from yacl/crypto/primitives/zkp/sigma_config.h rename to yacl/crypto/zkp/sigma_config.h index ec5115bb..f9e7f367 100644 --- a/yacl/crypto/primitives/zkp/sigma_config.h +++ b/yacl/crypto/zkp/sigma_config.h @@ -14,8 +14,8 @@ #pragma once -#include "yacl/crypto/base/ecc/ecc_spi.h" -#include "yacl/crypto/base/hash/hash_interface.h" +#include "yacl/crypto/ecc/ecc_spi.h" +#include "yacl/crypto/hash/hash_interface.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/zkp/sigma_owh.cc b/yacl/crypto/zkp/sigma_owh.cc similarity index 98% rename from yacl/crypto/primitives/zkp/sigma_owh.cc rename to yacl/crypto/zkp/sigma_owh.cc index ef422708..41672191 100644 --- a/yacl/crypto/primitives/zkp/sigma_owh.cc +++ b/yacl/crypto/zkp/sigma_owh.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/zkp/sigma_owh.h" +#include "yacl/crypto/zkp/sigma_owh.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/zkp/sigma_owh.h b/yacl/crypto/zkp/sigma_owh.h similarity index 91% rename from yacl/crypto/primitives/zkp/sigma_owh.h rename to yacl/crypto/zkp/sigma_owh.h index bb4f73cd..b3dc2b96 100644 --- a/yacl/crypto/primitives/zkp/sigma_owh.h +++ b/yacl/crypto/zkp/sigma_owh.h @@ -14,9 +14,9 @@ #pragma once -#include "yacl/crypto/base/ecc/group_sketch.h" -#include "yacl/crypto/primitives/zkp/sigma_config.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/ecc/group_sketch.h" +#include "yacl/crypto/rand/rand.h" +#include "yacl/crypto/zkp/sigma_config.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/zkp/sigma_test.cc b/yacl/crypto/zkp/sigma_test.cc similarity index 98% rename from yacl/crypto/primitives/zkp/sigma_test.cc rename to yacl/crypto/zkp/sigma_test.cc index f3b156dd..acca6719 100644 --- a/yacl/crypto/primitives/zkp/sigma_test.cc +++ b/yacl/crypto/zkp/sigma_test.cc @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/zkp/sigma.h" +#include "yacl/crypto/zkp/sigma.h" #include "gtest/gtest.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" namespace yacl::crypto { diff --git a/yacl/kernels/BUILD.bazel b/yacl/kernels/BUILD.bazel new file mode 100644 index 00000000..014c85f2 --- /dev/null +++ b/yacl/kernels/BUILD.bazel @@ -0,0 +1,57 @@ +# Copyright 2022 Ant Group Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("//bazel:yacl.bzl", "AES_COPT_FLAGS", "yacl_cc_binary", "yacl_cc_library", "yacl_cc_test") + +package(default_visibility = ["//visibility:public"]) + +yacl_cc_library( + name = "kernel", + srcs = ["kernel.h"], + deps = [ + "//yacl/link:context", + ], +) + +yacl_cc_library( + name = "svole_kernel", + srcs = [ + "svole_kernel.cc", + ], + hdrs = ["svole_kernel.h"], + deps = [ + ":kernel", + "//yacl/kernels/algorithms:silent_vole", + ], +) + +yacl_cc_binary( + name = "svole_kernel_bench", + srcs = ["svole_kernel_bench.cc"], + deps = [ + ":svole_kernel", + "//yacl/link:test_util", + "@com_github_google_benchmark//:benchmark", + ], +) + +yacl_cc_test( + name = "svole_kernel_test", + srcs = ["svole_kernel_test.cc"], + copts = AES_COPT_FLAGS, + deps = [ + ":svole_kernel", + "//yacl/link:test_util", + ], +) diff --git a/yacl/crypto/primitives/ot/BUILD.bazel b/yacl/kernels/algorithms/BUILD.bazel similarity index 61% rename from yacl/crypto/primitives/ot/BUILD.bazel rename to yacl/kernels/algorithms/BUILD.bazel index 86870e55..c02e87b0 100644 --- a/yacl/crypto/primitives/ot/BUILD.bazel +++ b/yacl/kernels/algorithms/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//bazel:yacl.bzl", "AES_COPT_FLAGS", "yacl_cc_binary", "yacl_cc_library", "yacl_cc_test") +load("//bazel:yacl.bzl", "AES_COPT_FLAGS", "yacl_cc_library", "yacl_cc_test") package(default_visibility = ["//visibility:public"]) @@ -24,8 +24,8 @@ yacl_cc_library( "//yacl/base:aligned_vector", "//yacl/base:dynamic_bitset", "//yacl/base:int128", + "//yacl/crypto/rand", "//yacl/crypto/tools:prg", - "//yacl/crypto/utils:rand", "//yacl/link:context", ], ) @@ -51,9 +51,9 @@ yacl_cc_library( hdrs = ["portable_ot_interface.h"], deps = [ ":base_ot_interface", + "//yacl:secparam", "//yacl/base:exception", "//yacl/crypto/tools:ro", - "//yacl/crypto/utils:secparam", "//yacl/link", "@simplest_ot//:simplest_ot_portable", ], @@ -69,9 +69,9 @@ yacl_cc_library( ], deps = [ ":base_ot_interface", + "//yacl:secparam", "//yacl/base:exception", "//yacl/crypto/tools:ro", - "//yacl/crypto/utils:secparam", "//yacl/link", "//yacl/math:gadget", "@simplest_ot//:simplest_ot_x86_asm", @@ -83,9 +83,9 @@ yacl_cc_library( srcs = ["base_ot.cc"], hdrs = ["base_ot.h"], deps = [ + "//yacl:secparam", "//yacl/base:exception", - "//yacl/crypto/primitives/ot:ot_store", - "//yacl/crypto/utils:secparam", + "//yacl/kernels/algorithms:ot_store", "//yacl/link", "@com_google_absl//absl/types:span", ] + select({ @@ -103,7 +103,7 @@ yacl_cc_test( srcs = ["base_ot_test.cc"], deps = [ ":base_ot", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", "//yacl/link:test_util", ], ) @@ -114,10 +114,10 @@ yacl_cc_library( hdrs = ["iknp_ote.h"], deps = [ ":ot_store", + "//yacl:secparam", "//yacl/crypto/tools:crhash", "//yacl/crypto/tools:prg", "//yacl/crypto/tools:rp", - "//yacl/crypto/utils:secparam", "//yacl/link", "//yacl/utils:matrix_utils", ], @@ -128,7 +128,7 @@ yacl_cc_test( srcs = ["iknp_ote_test.cc"], deps = [ ":iknp_ote", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", "//yacl/link:test_util", ], ) @@ -140,15 +140,15 @@ yacl_cc_library( copts = AES_COPT_FLAGS, deps = [ ":ot_store", + "//yacl:secparam", "//yacl/base:exception", "//yacl/base:int128", - "//yacl/crypto/base/aes:aes_opt", - "//yacl/crypto/base/hash:hash_utils", + "//yacl/crypto/aes:aes_opt", + "//yacl/crypto/hash:hash_utils", + "//yacl/crypto/rand", "//yacl/crypto/tools:prg", "//yacl/crypto/tools:ro", "//yacl/crypto/tools:rp", - "//yacl/crypto/utils:rand", - "//yacl/crypto/utils:secparam", "//yacl/link", "//yacl/utils:matrix_utils", ], @@ -159,7 +159,7 @@ yacl_cc_test( srcs = ["kkrt_ote_test.cc"], deps = [ ":kkrt_ote", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", "//yacl/link:test_util", ], ) @@ -171,13 +171,13 @@ yacl_cc_library( copts = AES_COPT_FLAGS, deps = [ ":ot_store", - "//yacl/crypto/base/aes:aes_opt", + "//yacl:secparam", + "//yacl/crypto/aes:aes_opt", + "//yacl/crypto/rand", "//yacl/crypto/tools:crhash", "//yacl/crypto/tools:prg", "//yacl/crypto/tools:ro", "//yacl/crypto/tools:rp", - "//yacl/crypto/utils:rand", - "//yacl/crypto/utils:secparam", "//yacl/link", "//yacl/math:gadget", "@com_google_absl//absl/numeric:bits", @@ -189,7 +189,7 @@ yacl_cc_test( srcs = ["sgrr_ote_test.cc"], deps = [ ":sgrr_ote", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", "//yacl/link:test_util", ], ) @@ -201,13 +201,13 @@ yacl_cc_library( copts = AES_COPT_FLAGS, deps = [ ":ot_store", + "//yacl:secparam", "//yacl/base:aligned_vector", - "//yacl/crypto/base/aes:aes_opt", + "//yacl/crypto/aes:aes_opt", + "//yacl/crypto/rand", "//yacl/crypto/tools:crhash", "//yacl/crypto/tools:prg", "//yacl/crypto/tools:rp", - "//yacl/crypto/utils:rand", - "//yacl/crypto/utils:secparam", "//yacl/link", "//yacl/math:gadget", "@com_google_absl//absl/numeric:bits", @@ -219,7 +219,7 @@ yacl_cc_test( srcs = ["gywz_ote_test.cc"], deps = [ ":gywz_ote", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", "//yacl/link:test_util", ], ) @@ -236,14 +236,14 @@ yacl_cc_library( ], deps = [ ":ot_store", + "//yacl:secparam", "//yacl/base:exception", - "//yacl/crypto/primitives/code:linear_code", - "//yacl/crypto/primitives/ot:gywz_ote", - "//yacl/crypto/primitives/ot:sgrr_ote", + "//yacl/crypto/rand", "//yacl/crypto/tools:prg", "//yacl/crypto/tools:rp", - "//yacl/crypto/utils:rand", - "//yacl/crypto/utils:secparam", + "//yacl/kernels/algorithms:gywz_ote", + "//yacl/kernels/algorithms:sgrr_ote", + "//yacl/kernels/code:linear_code", "//yacl/link", "//yacl/math:gadget", "//yacl/utils:cuckoo_index", @@ -255,7 +255,7 @@ yacl_cc_test( srcs = ["ferret_ote_test.cc"], deps = [ ":ferret_ote", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", "//yacl/link:test_util", ], ) @@ -267,14 +267,14 @@ yacl_cc_library( copts = AES_COPT_FLAGS, deps = [ ":ot_store", + "//yacl:secparam", "//yacl/base:dynamic_bitset", "//yacl/base:exception", "//yacl/base:int128", + "//yacl/crypto/rand", "//yacl/crypto/tools:crhash", "//yacl/crypto/tools:prg", "//yacl/crypto/tools:rp", - "//yacl/crypto/utils:rand", - "//yacl/crypto/utils:secparam", "//yacl/link", "//yacl/math/f2k", "//yacl/utils:matrix_utils", @@ -286,7 +286,7 @@ yacl_cc_test( srcs = ["kos_ote_test.cc"], deps = [ ":kos_ote", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", "//yacl/link:test_util", ], ) @@ -321,29 +321,137 @@ yacl_cc_test( srcs = ["softspoken_ote_test.cc"], deps = [ ":softspoken_ote", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", "//yacl/link:test_util", ], ) -yacl_cc_binary( - name = "benchmark", - srcs = [ - "benchmark.cc", - "benchmark.h", +yacl_cc_library( + name = "mpfss", + srcs = ["mpfss.cc"], + hdrs = ["mpfss.h"], + copts = AES_COPT_FLAGS, + deps = [ + "//yacl:secparam", + "//yacl/base:aligned_vector", + "//yacl/base:dynamic_bitset", + "//yacl/base:int128", + "//yacl/crypto/rand", + "//yacl/crypto/tools:crhash", + "//yacl/kernels/algorithms:gywz_ote", + "//yacl/kernels/algorithms:ot_store", + "//yacl/kernels/algorithms:sgrr_ote", + "//yacl/math:gadget", + "//yacl/math/f2k", ], +) + +yacl_cc_test( + name = "mpfss_test", + srcs = ["mpfss_test.cc"], + copts = AES_COPT_FLAGS, deps = [ - ":base_ot", - ":ferret_ote", - ":gywz_ote", - ":iknp_ote", - ":kkrt_ote", - ":kos_ote", - ":sgrr_ote", - ":softspoken_ote", - "//yacl/crypto/utils:rand", + ":mpfss", + "//yacl/crypto/rand", "//yacl/link:test_util", - "@com_github_google_benchmark//:benchmark_main", - "@com_google_absl//absl/numeric:bits", + "//yacl/math:gadget", + "//yacl/math/f2k", + ], +) + +yacl_cc_library( + name = "base_vole", + hdrs = ["base_vole.h"], + copts = AES_COPT_FLAGS, + deps = [ + "//yacl:secparam", + "//yacl/base:aligned_vector", + "//yacl/base:dynamic_bitset", + "//yacl/base:int128", + "//yacl/crypto/rand", + "//yacl/kernels/algorithms:ot_store", + "//yacl/kernels/algorithms:softspoken_ote", + "//yacl/math:gadget", + "//yacl/utils:serialize", + ], +) + +yacl_cc_test( + name = "base_vole_test", + srcs = ["base_vole_test.cc"], + copts = AES_COPT_FLAGS, + deps = [ + ":base_vole", + "//yacl/crypto/rand", + "//yacl/link:test_util", + "//yacl/math:gadget", + "//yacl/math/f2k", + ], +) + +yacl_cc_library( + name = "mp_vole", + hdrs = ["mp_vole.h"], + copts = AES_COPT_FLAGS, + deps = [ + "//yacl:secparam", + "//yacl/base:aligned_vector", + "//yacl/base:dynamic_bitset", + "//yacl/base:int128", + "//yacl/crypto/hash:hash_utils", + "//yacl/crypto/rand", + "//yacl/crypto/tools:common", + "//yacl/kernels/algorithms:mpfss", + "//yacl/kernels/algorithms:ot_store", + "//yacl/math:gadget", + "//yacl/math/f2k", + "//yacl/utils:serialize", + ], +) + +yacl_cc_test( + name = "mp_vole_test", + srcs = ["mp_vole_test.cc"], + copts = AES_COPT_FLAGS, + deps = [ + ":mp_vole", + "//yacl/crypto/rand", + "//yacl/link:test_util", + "//yacl/math:gadget", + "//yacl/math/f2k", + ], +) + +yacl_cc_library( + name = "silent_vole", + srcs = ["silent_vole.cc"], + hdrs = ["silent_vole.h"], + copts = AES_COPT_FLAGS, + deps = [ + ":base_vole", + ":mp_vole", + "//yacl:secparam", + "//yacl/base:aligned_vector", + "//yacl/base:dynamic_bitset", + "//yacl/base:int128", + "//yacl/kernels/algorithms:ot_store", + "//yacl/kernels/algorithms:softspoken_ote", + "//yacl/kernels/code:code_interface", + "//yacl/kernels/code:ea_code", + "//yacl/kernels/code:silver_code", + "//yacl/link:context", + ], +) + +yacl_cc_test( + name = "silent_vole_test", + srcs = ["silent_vole_test.cc"], + copts = AES_COPT_FLAGS, + deps = [ + ":silent_vole", + "//yacl/crypto/rand", + "//yacl/link:test_util", + "//yacl/math:gadget", + "//yacl/math/f2k", ], ) diff --git a/yacl/crypto/primitives/ot/base_ot.cc b/yacl/kernels/algorithms/base_ot.cc similarity index 97% rename from yacl/crypto/primitives/ot/base_ot.cc rename to yacl/kernels/algorithms/base_ot.cc index 42800cfa..5ae2e07b 100644 --- a/yacl/crypto/primitives/ot/base_ot.cc +++ b/yacl/kernels/algorithms/base_ot.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/base_ot.h" +#include "yacl/kernels/algorithms/base_ot.h" #include "yacl/base/exception.h" diff --git a/yacl/crypto/primitives/ot/base_ot.h b/yacl/kernels/algorithms/base_ot.h similarity index 90% rename from yacl/crypto/primitives/ot/base_ot.h rename to yacl/kernels/algorithms/base_ot.h index 26586057..55c69a5c 100644 --- a/yacl/crypto/primitives/ot/base_ot.h +++ b/yacl/kernels/algorithms/base_ot.h @@ -21,15 +21,15 @@ #include "yacl/base/dynamic_bitset.h" #include "yacl/base/int128.h" -#include "yacl/crypto/primitives/ot/ot_store.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/kernels/algorithms/ot_store.h" #include "yacl/link/link.h" +#include "yacl/secparam.h" /* submodules */ #if defined(__linux__) && defined(__x86_64) -#include "yacl/crypto/primitives/ot/x86_asm_ot_interface.h" +#include "yacl/kernels/algorithms/x86_asm_ot_interface.h" #else -#include "yacl/crypto/primitives/ot/portable_ot_interface.h" +#include "yacl/kernels/algorithms/portable_ot_interface.h" #endif /* security parameter declaration */ diff --git a/yacl/crypto/primitives/ot/base_ot_interface.h b/yacl/kernels/algorithms/base_ot_interface.h similarity index 100% rename from yacl/crypto/primitives/ot/base_ot_interface.h rename to yacl/kernels/algorithms/base_ot_interface.h diff --git a/yacl/crypto/primitives/ot/base_ot_test.cc b/yacl/kernels/algorithms/base_ot_test.cc similarity index 97% rename from yacl/crypto/primitives/ot/base_ot_test.cc rename to yacl/kernels/algorithms/base_ot_test.cc index 7e697016..e15e87bb 100644 --- a/yacl/crypto/primitives/ot/base_ot_test.cc +++ b/yacl/kernels/algorithms/base_ot_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/base_ot.h" +#include "yacl/kernels/algorithms/base_ot.h" #include #include @@ -21,7 +21,7 @@ #include "gtest/gtest.h" #include "yacl/base/exception.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/link/test_util.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/vole/base_vole.h b/yacl/kernels/algorithms/base_vole.h similarity index 97% rename from yacl/crypto/primitives/vole/base_vole.h rename to yacl/kernels/algorithms/base_vole.h index 2aee5d94..6198ec8f 100644 --- a/yacl/crypto/primitives/vole/base_vole.h +++ b/yacl/kernels/algorithms/base_vole.h @@ -20,9 +20,9 @@ #include "yacl/math/gadget.h" /* submodules */ -#include "yacl/crypto/primitives/ot/ot_store.h" -#include "yacl/crypto/primitives/ot/softspoken_ote.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/kernels/algorithms/ot_store.h" +#include "yacl/kernels/algorithms/softspoken_ote.h" +#include "yacl/secparam.h" YACL_MODULE_DECLARE("base_vole", SecParam::C::INF, SecParam::S::INF); namespace yacl::crypto { diff --git a/yacl/crypto/primitives/vole/base_vole_test.cc b/yacl/kernels/algorithms/base_vole_test.cc similarity index 98% rename from yacl/crypto/primitives/vole/base_vole_test.cc rename to yacl/kernels/algorithms/base_vole_test.cc index 3f30ce79..0f5cefcc 100644 --- a/yacl/crypto/primitives/vole/base_vole_test.cc +++ b/yacl/kernels/algorithms/base_vole_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/vole/base_vole.h" +#include "yacl/kernels/algorithms/base_vole.h" #include @@ -23,7 +23,7 @@ #include "yacl/base/exception.h" #include "yacl/base/int128.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/link/test_util.h" #include "yacl/math/f2k/f2k.h" #include "yacl/math/gadget.h" diff --git a/yacl/crypto/primitives/ot/ferret_ote.cc b/yacl/kernels/algorithms/ferret_ote.cc similarity index 99% rename from yacl/crypto/primitives/ot/ferret_ote.cc rename to yacl/kernels/algorithms/ferret_ote.cc index 1bb52324..9178eeb4 100644 --- a/yacl/crypto/primitives/ot/ferret_ote.cc +++ b/yacl/kernels/algorithms/ferret_ote.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/ferret_ote.h" +#include "yacl/kernels/algorithms/ferret_ote.h" #include #include diff --git a/yacl/crypto/primitives/ot/ferret_ote.h b/yacl/kernels/algorithms/ferret_ote.h similarity index 91% rename from yacl/crypto/primitives/ot/ferret_ote.h rename to yacl/kernels/algorithms/ferret_ote.h index f8868123..3588a0cc 100644 --- a/yacl/crypto/primitives/ot/ferret_ote.h +++ b/yacl/kernels/algorithms/ferret_ote.h @@ -19,16 +19,16 @@ #include #include -#include "yacl/crypto/primitives/ot/ot_store.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/kernels/algorithms/ot_store.h" #include "yacl/math/gadget.h" +#include "yacl/secparam.h" #include "yacl/utils/cuckoo_index.h" /* submodules */ -#include "yacl/crypto/primitives/code/linear_code.h" -#include "yacl/crypto/primitives/ot/ferret_ote_rn.h" -#include "yacl/crypto/primitives/ot/ferret_ote_un.h" -#include "yacl/crypto/primitives/ot/gywz_ote.h" +#include "yacl/kernels/algorithms/ferret_ote_rn.h" +#include "yacl/kernels/algorithms/ferret_ote_un.h" +#include "yacl/kernels/algorithms/gywz_ote.h" +#include "yacl/kernels/code/linear_code.h" /* security parameter declaration */ // this module is only a wrapper, no need for security parameter definition diff --git a/yacl/crypto/primitives/ot/ferret_ote_rn.h b/yacl/kernels/algorithms/ferret_ote_rn.h similarity index 97% rename from yacl/crypto/primitives/ot/ferret_ote_rn.h rename to yacl/kernels/algorithms/ferret_ote_rn.h index f746a48f..fe396dda 100644 --- a/yacl/crypto/primitives/ot/ferret_ote_rn.h +++ b/yacl/kernels/algorithms/ferret_ote_rn.h @@ -18,11 +18,11 @@ #include #include -#include "yacl/crypto/utils/secparam.h" #include "yacl/math/gadget.h" +#include "yacl/secparam.h" /* submodules */ -#include "yacl/crypto/primitives/ot/gywz_ote.h" +#include "yacl/kernels/algorithms/gywz_ote.h" /* security parameter declaration */ YACL_MODULE_DECLARE("ferret_ote_rn", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/primitives/ot/ferret_ote_test.cc b/yacl/kernels/algorithms/ferret_ote_test.cc similarity index 98% rename from yacl/crypto/primitives/ot/ferret_ote_test.cc rename to yacl/kernels/algorithms/ferret_ote_test.cc index e6402ffb..c98fdcc9 100644 --- a/yacl/crypto/primitives/ot/ferret_ote_test.cc +++ b/yacl/kernels/algorithms/ferret_ote_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/ferret_ote.h" +#include "yacl/kernels/algorithms/ferret_ote.h" #include #include @@ -25,9 +25,9 @@ #include "yacl/base/dynamic_bitset.h" #include "yacl/base/exception.h" #include "yacl/base/int128.h" -#include "yacl/crypto/primitives/ot/ot_store.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/prg.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/kernels/algorithms/ot_store.h" #include "yacl/link/test_util.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/ot/ferret_ote_un.h b/yacl/kernels/algorithms/ferret_ote_un.h similarity index 98% rename from yacl/crypto/primitives/ot/ferret_ote_un.h rename to yacl/kernels/algorithms/ferret_ote_un.h index 208ca1fb..80421d04 100644 --- a/yacl/crypto/primitives/ot/ferret_ote_un.h +++ b/yacl/kernels/algorithms/ferret_ote_un.h @@ -19,13 +19,13 @@ #include #include -#include "yacl/crypto/utils/secparam.h" #include "yacl/math/gadget.h" +#include "yacl/secparam.h" #include "yacl/utils/cuckoo_index.h" /* submodules */ -#include "yacl/crypto/primitives/ot/gywz_ote.h" #include "yacl/crypto/tools/rp.h" +#include "yacl/kernels/algorithms/gywz_ote.h" /* security parameter declaration */ YACL_MODULE_DECLARE("ferret_ote_un", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/primitives/ot/gywz_ote.cc b/yacl/kernels/algorithms/gywz_ote.cc similarity index 99% rename from yacl/crypto/primitives/ot/gywz_ote.cc rename to yacl/kernels/algorithms/gywz_ote.cc index 04b54a23..4ad72116 100644 --- a/yacl/crypto/primitives/ot/gywz_ote.cc +++ b/yacl/kernels/algorithms/gywz_ote.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/gywz_ote.h" +#include "yacl/kernels/algorithms/gywz_ote.h" #include diff --git a/yacl/crypto/primitives/ot/gywz_ote.h b/yacl/kernels/algorithms/gywz_ote.h similarity index 95% rename from yacl/crypto/primitives/ot/gywz_ote.h rename to yacl/kernels/algorithms/gywz_ote.h index 24249355..d9c05dd1 100644 --- a/yacl/crypto/primitives/ot/gywz_ote.h +++ b/yacl/kernels/algorithms/gywz_ote.h @@ -19,15 +19,15 @@ #include "absl/types/span.h" #include "yacl/base/int128.h" -#include "yacl/crypto/utils/secparam.h" #include "yacl/link/link.h" +#include "yacl/secparam.h" /* submodules */ -#include "yacl/crypto/base/aes/aes_opt.h" -#include "yacl/crypto/primitives/ot/ot_store.h" +#include "yacl/crypto/aes/aes_opt.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/crhash.h" #include "yacl/crypto/tools/prg.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/kernels/algorithms/ot_store.h" /* security parameter declaration */ YACL_MODULE_DECLARE("gywz_ote", SecParam::C::INF, SecParam::S::INF); diff --git a/yacl/crypto/primitives/ot/gywz_ote_test.cc b/yacl/kernels/algorithms/gywz_ote_test.cc similarity index 97% rename from yacl/crypto/primitives/ot/gywz_ote_test.cc rename to yacl/kernels/algorithms/gywz_ote_test.cc index 3e8f2510..acea74b6 100644 --- a/yacl/crypto/primitives/ot/gywz_ote_test.cc +++ b/yacl/kernels/algorithms/gywz_ote_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/gywz_ote.h" +#include "yacl/kernels/algorithms/gywz_ote.h" #include #include @@ -21,8 +21,8 @@ #include "gtest/gtest.h" #include "yacl/base/exception.h" -#include "yacl/crypto/primitives/ot/ot_store.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" +#include "yacl/kernels/algorithms/ot_store.h" #include "yacl/link/test_util.h" #include "yacl/math/gadget.h" diff --git a/yacl/crypto/primitives/ot/iknp_ote.cc b/yacl/kernels/algorithms/iknp_ote.cc similarity index 99% rename from yacl/crypto/primitives/ot/iknp_ote.cc rename to yacl/kernels/algorithms/iknp_ote.cc index f43cca78..f217674c 100644 --- a/yacl/crypto/primitives/ot/iknp_ote.cc +++ b/yacl/kernels/algorithms/iknp_ote.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/iknp_ote.h" +#include "yacl/kernels/algorithms/iknp_ote.h" #include #include diff --git a/yacl/crypto/primitives/ot/iknp_ote.h b/yacl/kernels/algorithms/iknp_ote.h similarity index 97% rename from yacl/crypto/primitives/ot/iknp_ote.h rename to yacl/kernels/algorithms/iknp_ote.h index 07f4e33c..ee017153 100644 --- a/yacl/crypto/primitives/ot/iknp_ote.h +++ b/yacl/kernels/algorithms/iknp_ote.h @@ -20,9 +20,9 @@ #include "absl/types/span.h" #include "yacl/base/dynamic_bitset.h" -#include "yacl/crypto/primitives/ot/ot_store.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/kernels/algorithms/ot_store.h" #include "yacl/link/link.h" +#include "yacl/secparam.h" #include "yacl/utils/matrix_utils.h" /* submodules */ diff --git a/yacl/crypto/primitives/ot/iknp_ote_test.cc b/yacl/kernels/algorithms/iknp_ote_test.cc similarity index 98% rename from yacl/crypto/primitives/ot/iknp_ote_test.cc rename to yacl/kernels/algorithms/iknp_ote_test.cc index 25901340..67e51a00 100644 --- a/yacl/crypto/primitives/ot/iknp_ote_test.cc +++ b/yacl/kernels/algorithms/iknp_ote_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/iknp_ote.h" +#include "yacl/kernels/algorithms/iknp_ote.h" #include @@ -22,7 +22,7 @@ #include #include "yacl/base/exception.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/link/test_util.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/ot/kkrt_ote.cc b/yacl/kernels/algorithms/kkrt_ote.cc similarity index 99% rename from yacl/crypto/primitives/ot/kkrt_ote.cc rename to yacl/kernels/algorithms/kkrt_ote.cc index 3a125d46..11cdf980 100644 --- a/yacl/crypto/primitives/ot/kkrt_ote.cc +++ b/yacl/kernels/algorithms/kkrt_ote.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/kkrt_ote.h" +#include "yacl/kernels/algorithms/kkrt_ote.h" #include #include diff --git a/yacl/crypto/primitives/ot/kkrt_ote.h b/yacl/kernels/algorithms/kkrt_ote.h similarity index 95% rename from yacl/crypto/primitives/ot/kkrt_ote.h rename to yacl/kernels/algorithms/kkrt_ote.h index ad7209d1..d3e6a1ca 100644 --- a/yacl/crypto/primitives/ot/kkrt_ote.h +++ b/yacl/kernels/algorithms/kkrt_ote.h @@ -19,18 +19,18 @@ #include "absl/types/span.h" -#include "yacl/crypto/primitives/ot/ot_store.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/kernels/algorithms/ot_store.h" #include "yacl/link/link.h" +#include "yacl/secparam.h" /* submodules */ -#include "yacl/crypto/base/aes/aes_intrinsics.h" -#include "yacl/crypto/base/aes/aes_opt.h" -#include "yacl/crypto/base/block_cipher/symmetric_crypto.h" -#include "yacl/crypto/base/hash/hash_utils.h" +#include "yacl/crypto/aes/aes_intrinsics.h" +#include "yacl/crypto/aes/aes_opt.h" +#include "yacl/crypto/block_cipher/symmetric_crypto.h" +#include "yacl/crypto/hash/hash_utils.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/prg.h" #include "yacl/crypto/tools/ro.h" -#include "yacl/crypto/utils/rand.h" /* security parameter declaration */ YACL_MODULE_DECLARE("kkrt_ote", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/primitives/ot/kkrt_ote_test.cc b/yacl/kernels/algorithms/kkrt_ote_test.cc similarity index 98% rename from yacl/crypto/primitives/ot/kkrt_ote_test.cc rename to yacl/kernels/algorithms/kkrt_ote_test.cc index ecf209e7..57c7193d 100644 --- a/yacl/crypto/primitives/ot/kkrt_ote_test.cc +++ b/yacl/kernels/algorithms/kkrt_ote_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/kkrt_ote.h" +#include "yacl/kernels/algorithms/kkrt_ote.h" #include #include @@ -22,9 +22,9 @@ #include #include "yacl/base/exception.h" -#include "yacl/crypto/primitives/ot/ot_store.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/prg.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/kernels/algorithms/ot_store.h" #include "yacl/link/test_util.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/ot/kos_ote.cc b/yacl/kernels/algorithms/kos_ote.cc similarity index 99% rename from yacl/crypto/primitives/ot/kos_ote.cc rename to yacl/kernels/algorithms/kos_ote.cc index 84465734..4fe5499a 100644 --- a/yacl/crypto/primitives/ot/kos_ote.cc +++ b/yacl/kernels/algorithms/kos_ote.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/kos_ote.h" +#include "yacl/kernels/algorithms/kos_ote.h" #include #include diff --git a/yacl/crypto/primitives/ot/kos_ote.h b/yacl/kernels/algorithms/kos_ote.h similarity index 96% rename from yacl/crypto/primitives/ot/kos_ote.h rename to yacl/kernels/algorithms/kos_ote.h index 21c84a31..0d53fef0 100644 --- a/yacl/crypto/primitives/ot/kos_ote.h +++ b/yacl/kernels/algorithms/kos_ote.h @@ -19,15 +19,15 @@ #include "absl/types/span.h" #include "yacl/base/dynamic_bitset.h" -#include "yacl/crypto/primitives/ot/ot_store.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/kernels/algorithms/ot_store.h" #include "yacl/link/link.h" +#include "yacl/secparam.h" /* submodules */ +#include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/crhash.h" #include "yacl/crypto/tools/prg.h" #include "yacl/crypto/tools/rp.h" -#include "yacl/crypto/utils/rand.h" /* security parameter declaration */ YACL_MODULE_DECLARE("kos_ote", SecParam::C::k128, SecParam::S::k64); diff --git a/yacl/crypto/primitives/ot/kos_ote_test.cc b/yacl/kernels/algorithms/kos_ote_test.cc similarity index 98% rename from yacl/crypto/primitives/ot/kos_ote_test.cc rename to yacl/kernels/algorithms/kos_ote_test.cc index b6a005d6..c2c0cebe 100644 --- a/yacl/crypto/primitives/ot/kos_ote_test.cc +++ b/yacl/kernels/algorithms/kos_ote_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/kos_ote.h" +#include "yacl/kernels/algorithms/kos_ote.h" #include @@ -22,7 +22,7 @@ #include #include "yacl/base/int128.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/link/test_util.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/vole/mp_vole.h b/yacl/kernels/algorithms/mp_vole.h similarity index 96% rename from yacl/crypto/primitives/vole/mp_vole.h rename to yacl/kernels/algorithms/mp_vole.h index 4010e169..17256376 100644 --- a/yacl/crypto/primitives/vole/mp_vole.h +++ b/yacl/kernels/algorithms/mp_vole.h @@ -17,15 +17,16 @@ #include /* submodules */ -#include "yacl/crypto/base/hash/hash_utils.h" -#include "yacl/crypto/primitives/dpf/mpfss.h" -#include "yacl/crypto/primitives/ot/ot_store.h" +#include "yacl/crypto/hash/hash_utils.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/common.h" -#include "yacl/crypto/utils/rand.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/kernels/algorithms/mpfss.h" +#include "yacl/kernels/algorithms/ot_store.h" #include "yacl/math/gadget.h" +#include "yacl/secparam.h" YACL_MODULE_DECLARE("mp_vole", SecParam::C::INF, SecParam::S::INF); + namespace yacl::crypto { using MpVoleParam = MpFssParam; diff --git a/yacl/crypto/primitives/vole/mp_vole_test.cc b/yacl/kernels/algorithms/mp_vole_test.cc similarity index 99% rename from yacl/crypto/primitives/vole/mp_vole_test.cc rename to yacl/kernels/algorithms/mp_vole_test.cc index b15a597f..fe5f4277 100644 --- a/yacl/crypto/primitives/vole/mp_vole_test.cc +++ b/yacl/kernels/algorithms/mp_vole_test.cc @@ -22,7 +22,7 @@ #include #include "yacl/base/exception.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/link/test_util.h" #include "yacl/math/f2k/f2k.h" #include "yacl/math/gadget.h" diff --git a/yacl/crypto/primitives/dpf/mpfss.cc b/yacl/kernels/algorithms/mpfss.cc similarity index 99% rename from yacl/crypto/primitives/dpf/mpfss.cc rename to yacl/kernels/algorithms/mpfss.cc index 208b72ea..f6b45bb9 100644 --- a/yacl/crypto/primitives/dpf/mpfss.cc +++ b/yacl/kernels/algorithms/mpfss.cc @@ -20,9 +20,9 @@ #include "yacl/base/aligned_vector.h" #include "yacl/base/byte_container_view.h" #include "yacl/base/int128.h" -#include "yacl/crypto/primitives/ot/gywz_ote.h" -#include "yacl/crypto/primitives/ot/sgrr_ote.h" #include "yacl/crypto/tools/crhash.h" +#include "yacl/kernels/algorithms/gywz_ote.h" +#include "yacl/kernels/algorithms/sgrr_ote.h" #include "yacl/math/f2k/f2k.h" #include "yacl/math/gadget.h" diff --git a/yacl/crypto/primitives/dpf/mpfss.h b/yacl/kernels/algorithms/mpfss.h similarity index 98% rename from yacl/crypto/primitives/dpf/mpfss.h rename to yacl/kernels/algorithms/mpfss.h index 70cc8778..47321496 100644 --- a/yacl/crypto/primitives/dpf/mpfss.h +++ b/yacl/kernels/algorithms/mpfss.h @@ -18,9 +18,9 @@ #include /* submodules */ -#include "yacl/crypto/primitives/ot/ot_store.h" -#include "yacl/crypto/utils/rand.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/crypto/rand/rand.h" +#include "yacl/kernels/algorithms/ot_store.h" +#include "yacl/secparam.h" /* security parameter declaration */ // this module is only a wrapper, no need for security parameter definition diff --git a/yacl/crypto/primitives/dpf/mpfss_test.cc b/yacl/kernels/algorithms/mpfss_test.cc similarity index 99% rename from yacl/crypto/primitives/dpf/mpfss_test.cc rename to yacl/kernels/algorithms/mpfss_test.cc index 2925c0b4..b746f1af 100644 --- a/yacl/crypto/primitives/dpf/mpfss_test.cc +++ b/yacl/kernels/algorithms/mpfss_test.cc @@ -23,7 +23,7 @@ #include #include "yacl/base/exception.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/link/test_util.h" #include "yacl/math/f2k/f2k.h" #include "yacl/math/gadget.h" diff --git a/yacl/crypto/primitives/ot/ot_store.cc b/yacl/kernels/algorithms/ot_store.cc similarity index 99% rename from yacl/crypto/primitives/ot/ot_store.cc rename to yacl/kernels/algorithms/ot_store.cc index 52fe066f..4a33fe0a 100644 --- a/yacl/crypto/primitives/ot/ot_store.cc +++ b/yacl/kernels/algorithms/ot_store.cc @@ -12,15 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/ot_store.h" +#include "yacl/kernels/algorithms/ot_store.h" #include #include #include #include "yacl/base/exception.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/prg.h" -#include "yacl/crypto/utils/rand.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/ot/ot_store.h b/yacl/kernels/algorithms/ot_store.h similarity index 100% rename from yacl/crypto/primitives/ot/ot_store.h rename to yacl/kernels/algorithms/ot_store.h diff --git a/yacl/crypto/primitives/ot/ot_store_test.cc b/yacl/kernels/algorithms/ot_store_test.cc similarity index 99% rename from yacl/crypto/primitives/ot/ot_store_test.cc rename to yacl/kernels/algorithms/ot_store_test.cc index 5a40be8f..5add55c7 100644 --- a/yacl/crypto/primitives/ot/ot_store_test.cc +++ b/yacl/kernels/algorithms/ot_store_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/ot_store.h" +#include "yacl/kernels/algorithms/ot_store.h" #include #include @@ -25,8 +25,8 @@ #include "gtest/gtest.h" #include "yacl/base/exception.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/prg.h" -#include "yacl/crypto/utils/rand.h" #include "yacl/link/test_util.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/ot/portable_ot_interface.cc b/yacl/kernels/algorithms/portable_ot_interface.cc similarity index 98% rename from yacl/crypto/primitives/ot/portable_ot_interface.cc rename to yacl/kernels/algorithms/portable_ot_interface.cc index bdf83c2d..9db11fff 100644 --- a/yacl/crypto/primitives/ot/portable_ot_interface.cc +++ b/yacl/kernels/algorithms/portable_ot_interface.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/portable_ot_interface.h" +#include "yacl/kernels/algorithms/portable_ot_interface.h" #include "simplest_ot_portable/ot_receiver.h" #include "simplest_ot_portable/ot_sender.h" diff --git a/yacl/crypto/primitives/ot/portable_ot_interface.h b/yacl/kernels/algorithms/portable_ot_interface.h similarity index 93% rename from yacl/crypto/primitives/ot/portable_ot_interface.h rename to yacl/kernels/algorithms/portable_ot_interface.h index 8ce2c788..53ad309c 100644 --- a/yacl/crypto/primitives/ot/portable_ot_interface.h +++ b/yacl/kernels/algorithms/portable_ot_interface.h @@ -22,8 +22,8 @@ #error "OT interface already defined" #endif -#include "yacl/crypto/primitives/ot/base_ot_interface.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/kernels/algorithms/base_ot_interface.h" +#include "yacl/secparam.h" /* security parameter declaration */ YACL_MODULE_DECLARE("base_ot_portable", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/primitives/ot/sgrr_ote.cc b/yacl/kernels/algorithms/sgrr_ote.cc similarity index 99% rename from yacl/crypto/primitives/ot/sgrr_ote.cc rename to yacl/kernels/algorithms/sgrr_ote.cc index 357de34d..92e3c9af 100644 --- a/yacl/crypto/primitives/ot/sgrr_ote.cc +++ b/yacl/kernels/algorithms/sgrr_ote.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/sgrr_ote.h" +#include "yacl/kernels/algorithms/sgrr_ote.h" #include #include diff --git a/yacl/crypto/primitives/ot/sgrr_ote.h b/yacl/kernels/algorithms/sgrr_ote.h similarity index 94% rename from yacl/crypto/primitives/ot/sgrr_ote.h rename to yacl/kernels/algorithms/sgrr_ote.h index 31f04e85..e8e900e5 100644 --- a/yacl/crypto/primitives/ot/sgrr_ote.h +++ b/yacl/kernels/algorithms/sgrr_ote.h @@ -18,17 +18,17 @@ #include "absl/types/span.h" -#include "yacl/crypto/primitives/ot/ot_store.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/kernels/algorithms/ot_store.h" #include "yacl/link/link.h" +#include "yacl/secparam.h" /* submodules */ -#include "yacl/crypto/base/aes/aes_opt.h" +#include "yacl/crypto/aes/aes_opt.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/crhash.h" #include "yacl/crypto/tools/prg.h" #include "yacl/crypto/tools/ro.h" #include "yacl/crypto/tools/rp.h" -#include "yacl/crypto/utils/rand.h" /* security parameter declaration */ YACL_MODULE_DECLARE("sgrr_ote", SecParam::C::INF, SecParam::S::INF); @@ -56,7 +56,7 @@ namespace yacl::crypto { // // Security assumptions: // - Correlation-robust Hash, but here we use two-key PRF with AES key -// scheduling to optimize CrHash, see yacl/crypto/base/aes/aes_opt.h for more +// scheduling to optimize CrHash, see yacl/crypto/aes/aes_opt.h for more // details. // // Some Discussions in the community: diff --git a/yacl/crypto/primitives/ot/sgrr_ote_test.cc b/yacl/kernels/algorithms/sgrr_ote_test.cc similarity index 98% rename from yacl/crypto/primitives/ot/sgrr_ote_test.cc rename to yacl/kernels/algorithms/sgrr_ote_test.cc index 576be7a6..f02edaa0 100644 --- a/yacl/crypto/primitives/ot/sgrr_ote_test.cc +++ b/yacl/kernels/algorithms/sgrr_ote_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/sgrr_ote.h" +#include "yacl/kernels/algorithms/sgrr_ote.h" #include #include @@ -23,7 +23,7 @@ #include "gtest/gtest.h" #include "yacl/base/exception.h" -#include "yacl/crypto/primitives/ot/ot_store.h" +#include "yacl/kernels/algorithms/ot_store.h" #include "yacl/link/test_util.h" #include "yacl/math/gadget.h" diff --git a/yacl/crypto/primitives/vole/silent_vole.cc b/yacl/kernels/algorithms/silent_vole.cc similarity index 99% rename from yacl/crypto/primitives/vole/silent_vole.cc rename to yacl/kernels/algorithms/silent_vole.cc index d548ed10..55e8dbcb 100644 --- a/yacl/crypto/primitives/vole/silent_vole.cc +++ b/yacl/kernels/algorithms/silent_vole.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/vole/silent_vole.h" +#include "yacl/kernels/algorithms/silent_vole.h" #include #include diff --git a/yacl/crypto/primitives/vole/silent_vole.h b/yacl/kernels/algorithms/silent_vole.h similarity index 91% rename from yacl/crypto/primitives/vole/silent_vole.h rename to yacl/kernels/algorithms/silent_vole.h index f0efdb2a..66c59fff 100644 --- a/yacl/crypto/primitives/vole/silent_vole.h +++ b/yacl/kernels/algorithms/silent_vole.h @@ -16,16 +16,16 @@ #include "yacl/base/exception.h" #include "yacl/base/int128.h" -#include "yacl/crypto/utils/secparam.h" #include "yacl/link/context.h" +#include "yacl/secparam.h" /* submodules */ -#include "yacl/crypto/primitives/code/code_interface.h" -#include "yacl/crypto/primitives/code/ea_code.h" -#include "yacl/crypto/primitives/code/silver_code.h" -#include "yacl/crypto/primitives/vole/base_vole.h" -#include "yacl/crypto/primitives/vole/mp_vole.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" +#include "yacl/kernels/algorithms/base_vole.h" +#include "yacl/kernels/algorithms/mp_vole.h" +#include "yacl/kernels/code/code_interface.h" +#include "yacl/kernels/code/ea_code.h" +#include "yacl/kernels/code/silver_code.h" /* security parameter declaration */ YACL_MODULE_DECLARE("silent_vole", SecParam::C::k128, SecParam::S::INF); @@ -49,9 +49,9 @@ namespace yacl::crypto { // // Security assumptions: // > OT extension functionality, for more details about its implementation, see -// `yacl/crypto/primitives/ot/softspoken_ote.h` +// `yacl/kernels/algorithms/softspoken_ote.h` // > base VOLE and multi-point VOLE functionalities, for more details about its -// implementation, see `yacl/crypto/primitives/vole/mp_vole.h` +// implementation, see `yacl/kernels/algorithms/mp_vole.h` // > Dual LPN problem, for more details, please see the original papers // 1) Silver (https://eprint.iacr.org/2021/1150.pdf) Most // efficiency, but not recommended to use due to its security flaw. @@ -122,6 +122,8 @@ class SilentVoleSender { CodeType GetCodeType() const { return codetype_; } + void SetOTCounter(uint64_t counter) { ss_sender_.SetCounter(counter); } + private: bool is_inited_{false}; bool is_mal_{false}; @@ -162,6 +164,8 @@ class SilentVoleReceiver { CodeType GetCodeType() const { return codetype_; } + void SetOTCounter(uint64_t counter) { ss_receiver_.SetCounter(counter); } + private: bool is_inited_{false}; bool is_mal_{false}; diff --git a/yacl/crypto/primitives/vole/silent_vole_test.cc b/yacl/kernels/algorithms/silent_vole_test.cc similarity index 98% rename from yacl/crypto/primitives/vole/silent_vole_test.cc rename to yacl/kernels/algorithms/silent_vole_test.cc index 42e65779..5f057bbb 100644 --- a/yacl/crypto/primitives/vole/silent_vole_test.cc +++ b/yacl/kernels/algorithms/silent_vole_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/vole/silent_vole.h" +#include "yacl/kernels/algorithms/silent_vole.h" #include diff --git a/yacl/crypto/primitives/ot/softspoken_ote.cc b/yacl/kernels/algorithms/softspoken_ote.cc similarity index 99% rename from yacl/crypto/primitives/ot/softspoken_ote.cc rename to yacl/kernels/algorithms/softspoken_ote.cc index b4cc28f2..7515b591 100644 --- a/yacl/crypto/primitives/ot/softspoken_ote.cc +++ b/yacl/kernels/algorithms/softspoken_ote.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/softspoken_ote.h" +#include "yacl/kernels/algorithms/softspoken_ote.h" #include diff --git a/yacl/crypto/primitives/ot/softspoken_ote.h b/yacl/kernels/algorithms/softspoken_ote.h similarity index 96% rename from yacl/crypto/primitives/ot/softspoken_ote.h rename to yacl/kernels/algorithms/softspoken_ote.h index 5d5dd36d..d2ac47f4 100644 --- a/yacl/crypto/primitives/ot/softspoken_ote.h +++ b/yacl/kernels/algorithms/softspoken_ote.h @@ -22,18 +22,18 @@ #include "yacl/base/dynamic_bitset.h" #include "yacl/base/exception.h" #include "yacl/base/int128.h" -#include "yacl/crypto/utils/secparam.h" #include "yacl/link/context.h" #include "yacl/link/link.h" +#include "yacl/secparam.h" /* submodules */ -#include "yacl/crypto/primitives/ot/base_ot.h" -#include "yacl/crypto/primitives/ot/ot_store.h" -#include "yacl/crypto/primitives/ot/sgrr_ote.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/crhash.h" #include "yacl/crypto/tools/prg.h" #include "yacl/crypto/tools/rp.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/kernels/algorithms/base_ot.h" +#include "yacl/kernels/algorithms/ot_store.h" +#include "yacl/kernels/algorithms/sgrr_ote.h" /* security parameter declaration */ YACL_MODULE_DECLARE("softspoken_ote", SecParam::C::k128, SecParam::S::INF); @@ -114,6 +114,8 @@ class SoftspokenOtExtSender { void SetStep(uint64_t step) { step_ = step; } + void SetCounter(uint64_t counter) { counter_ = counter; } + private: void GenSfVole(absl::Span hash_buff, absl::Span xor_buff, absl::Span u, @@ -186,6 +188,8 @@ class SoftspokenOtExtReceiver { void SetStep(uint64_t step) { step_ = step; } + void SetCounter(uint64_t counter) { counter_ = counter; } + private: // Generate Subfield VOLE void GenSfVole(uint128_t choice, absl::Span xor_buff, diff --git a/yacl/crypto/primitives/ot/softspoken_ote_test.cc b/yacl/kernels/algorithms/softspoken_ote_test.cc similarity index 99% rename from yacl/crypto/primitives/ot/softspoken_ote_test.cc rename to yacl/kernels/algorithms/softspoken_ote_test.cc index c6f89c13..b2ce606f 100644 --- a/yacl/crypto/primitives/ot/softspoken_ote_test.cc +++ b/yacl/kernels/algorithms/softspoken_ote_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/softspoken_ote.h" +#include "yacl/kernels/algorithms/softspoken_ote.h" #include @@ -22,8 +22,8 @@ #include #include "yacl/base/exception.h" -#include "yacl/crypto/primitives/ot/ot_store.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" +#include "yacl/kernels/algorithms/ot_store.h" #include "yacl/link/test_util.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/ot/x86_asm_ot_interface.cc b/yacl/kernels/algorithms/x86_asm_ot_interface.cc similarity index 98% rename from yacl/crypto/primitives/ot/x86_asm_ot_interface.cc rename to yacl/kernels/algorithms/x86_asm_ot_interface.cc index d0ad7d11..e7a3def6 100644 --- a/yacl/crypto/primitives/ot/x86_asm_ot_interface.cc +++ b/yacl/kernels/algorithms/x86_asm_ot_interface.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/x86_asm_ot_interface.h" +#include "yacl/kernels/algorithms/x86_asm_ot_interface.h" #include #include diff --git a/yacl/crypto/primitives/ot/x86_asm_ot_interface.h b/yacl/kernels/algorithms/x86_asm_ot_interface.h similarity index 92% rename from yacl/crypto/primitives/ot/x86_asm_ot_interface.h rename to yacl/kernels/algorithms/x86_asm_ot_interface.h index b50a5915..81806c63 100644 --- a/yacl/crypto/primitives/ot/x86_asm_ot_interface.h +++ b/yacl/kernels/algorithms/x86_asm_ot_interface.h @@ -22,8 +22,8 @@ #include -#include "yacl/crypto/primitives/ot/base_ot_interface.h" -#include "yacl/crypto/utils/secparam.h" +#include "yacl/kernels/algorithms/base_ot_interface.h" +#include "yacl/secparam.h" /* security parameter declaration */ YACL_MODULE_DECLARE("base_ot_x86_asm", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/kernels/benchmark/BUILD.bazel b/yacl/kernels/benchmark/BUILD.bazel new file mode 100644 index 00000000..faf33860 --- /dev/null +++ b/yacl/kernels/benchmark/BUILD.bazel @@ -0,0 +1,55 @@ +# Copyright 2022 Ant Group Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("//bazel:yacl.bzl", "AES_COPT_FLAGS", "yacl_cc_binary") + +package(default_visibility = ["//visibility:public"]) + +yacl_cc_binary( + name = "ot_bench", + srcs = [ + "ot_bench.cc", + "ot_bench.h", + ], + deps = [ + "//yacl/crypto/rand", + "//yacl/kernels/algorithms:base_ot", + "//yacl/kernels/algorithms:ferret_ote", + "//yacl/kernels/algorithms:gywz_ote", + "//yacl/kernels/algorithms:iknp_ote", + "//yacl/kernels/algorithms:kkrt_ote", + "//yacl/kernels/algorithms:kos_ote", + "//yacl/kernels/algorithms:sgrr_ote", + "//yacl/kernels/algorithms:softspoken_ote", + "//yacl/link:test_util", + "@com_github_google_benchmark//:benchmark_main", + "@com_google_absl//absl/numeric:bits", + ], +) + +yacl_cc_binary( + name = "vole_bench", + srcs = [ + "vole_bench.cc", + ], + copts = AES_COPT_FLAGS, + deps = [ + "//yacl/crypto/rand", + "//yacl/kernels/algorithms:base_vole", + "//yacl/kernels/algorithms:silent_vole", + "//yacl/link:test_util", + "@com_github_google_benchmark//:benchmark_main", + "@com_google_absl//absl/numeric:bits", + ], +) diff --git a/yacl/crypto/primitives/ot/benchmark.cc b/yacl/kernels/benchmark/ot_bench.cc similarity index 97% rename from yacl/crypto/primitives/ot/benchmark.cc rename to yacl/kernels/benchmark/ot_bench.cc index 280dd9f2..36414009 100644 --- a/yacl/crypto/primitives/ot/benchmark.cc +++ b/yacl/kernels/benchmark/ot_bench.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/ot/benchmark.h" +#include "yacl/kernels/benchmark/ot_bench.h" #include #include diff --git a/yacl/crypto/primitives/ot/benchmark.h b/yacl/kernels/benchmark/ot_bench.h similarity index 97% rename from yacl/crypto/primitives/ot/benchmark.h rename to yacl/kernels/benchmark/ot_bench.h index b069ac1c..48804eb8 100644 --- a/yacl/crypto/primitives/ot/benchmark.h +++ b/yacl/kernels/benchmark/ot_bench.h @@ -24,16 +24,16 @@ #include "yacl/base/aligned_vector.h" #include "yacl/base/exception.h" #include "yacl/base/int128.h" -#include "yacl/crypto/primitives/ot/base_ot.h" -#include "yacl/crypto/primitives/ot/ferret_ote.h" -#include "yacl/crypto/primitives/ot/gywz_ote.h" -#include "yacl/crypto/primitives/ot/iknp_ote.h" -#include "yacl/crypto/primitives/ot/kkrt_ote.h" -#include "yacl/crypto/primitives/ot/kos_ote.h" -#include "yacl/crypto/primitives/ot/ot_store.h" -#include "yacl/crypto/primitives/ot/sgrr_ote.h" -#include "yacl/crypto/primitives/ot/softspoken_ote.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" +#include "yacl/kernels/algorithms/base_ot.h" +#include "yacl/kernels/algorithms/ferret_ote.h" +#include "yacl/kernels/algorithms/gywz_ote.h" +#include "yacl/kernels/algorithms/iknp_ote.h" +#include "yacl/kernels/algorithms/kkrt_ote.h" +#include "yacl/kernels/algorithms/kos_ote.h" +#include "yacl/kernels/algorithms/ot_store.h" +#include "yacl/kernels/algorithms/sgrr_ote.h" +#include "yacl/kernels/algorithms/softspoken_ote.h" #include "yacl/link/test_util.h" #include "yacl/utils/matrix_utils.h" diff --git a/yacl/crypto/primitives/vole/benchmark.cc b/yacl/kernels/benchmark/vole_bench.cc similarity index 98% rename from yacl/crypto/primitives/vole/benchmark.cc rename to yacl/kernels/benchmark/vole_bench.cc index 4378721a..70f0b62e 100644 --- a/yacl/crypto/primitives/vole/benchmark.cc +++ b/yacl/kernels/benchmark/vole_bench.cc @@ -12,19 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "benchmark/benchmark.h" - #include #include #include +#include "benchmark/benchmark.h" + #include "yacl/base/exception.h" -#include "yacl/crypto/primitives/vole/base_vole.h" -#include "yacl/crypto/primitives/vole/silent_vole.h" +#include "yacl/kernels/algorithms/base_vole.h" +#include "yacl/kernels/algorithms/silent_vole.h" #include "yacl/link/test_util.h" // -// bazel run //yacl/crypto/primitives/vole/f2k:benchmark -c opt -- +// bazel run //yacl/kernelsle/f2k:benchmark -c opt -- // --benchmark_counters_tabular=true // // User Counters: diff --git a/yacl/crypto/primitives/code/BUILD.bazel b/yacl/kernels/code/BUILD.bazel similarity index 94% rename from yacl/crypto/primitives/code/BUILD.bazel rename to yacl/kernels/code/BUILD.bazel index 87e4daa3..72d64bc4 100644 --- a/yacl/crypto/primitives/code/BUILD.bazel +++ b/yacl/kernels/code/BUILD.bazel @@ -42,7 +42,7 @@ yacl_cc_test( srcs = ["linear_code_test.cc"], deps = [ ":linear_code", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", ], ) @@ -68,7 +68,7 @@ yacl_cc_test( srcs = ["silver_code_test.cc"], deps = [ ":silver_code", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", ], ) @@ -94,7 +94,7 @@ yacl_cc_test( srcs = ["ea_code_test.cc"], deps = [ ":ea_code", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", ], ) @@ -109,7 +109,7 @@ yacl_cc_binary( ":linear_code", ":silver_code", "//yacl/base:aligned_vector", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", "@com_github_google_benchmark//:benchmark_main", ], ) diff --git a/yacl/crypto/primitives/code/benchmark.cc b/yacl/kernels/code/benchmark.cc similarity index 97% rename from yacl/crypto/primitives/code/benchmark.cc rename to yacl/kernels/code/benchmark.cc index 9075f128..19590198 100644 --- a/yacl/crypto/primitives/code/benchmark.cc +++ b/yacl/kernels/code/benchmark.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/code/benchmark.h" +#include "yacl/kernels/code/benchmark.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/code/benchmark.h b/yacl/kernels/code/benchmark.h similarity index 96% rename from yacl/crypto/primitives/code/benchmark.h rename to yacl/kernels/code/benchmark.h index 914dc3f9..c6b6ad87 100644 --- a/yacl/crypto/primitives/code/benchmark.h +++ b/yacl/kernels/code/benchmark.h @@ -20,10 +20,10 @@ #include "benchmark/benchmark.h" #include "yacl/base/aligned_vector.h" -#include "yacl/crypto/primitives/code/ea_code.h" -#include "yacl/crypto/primitives/code/linear_code.h" -#include "yacl/crypto/primitives/code/silver_code.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" +#include "yacl/kernels/code/ea_code.h" +#include "yacl/kernels/code/linear_code.h" +#include "yacl/kernels/code/silver_code.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/code/code_interface.h b/yacl/kernels/code/code_interface.h similarity index 100% rename from yacl/crypto/primitives/code/code_interface.h rename to yacl/kernels/code/code_interface.h diff --git a/yacl/crypto/primitives/code/ea_code.h b/yacl/kernels/code/ea_code.h similarity index 98% rename from yacl/crypto/primitives/code/ea_code.h rename to yacl/kernels/code/ea_code.h index a18e7cbf..48490515 100644 --- a/yacl/crypto/primitives/code/ea_code.h +++ b/yacl/kernels/code/ea_code.h @@ -29,8 +29,8 @@ #include "yacl/base/block.h" #include "yacl/base/exception.h" #include "yacl/base/int128.h" -#include "yacl/crypto/primitives/code/code_interface.h" -#include "yacl/crypto/primitives/code/linear_code.h" +#include "yacl/kernels/code/code_interface.h" +#include "yacl/kernels/code/linear_code.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/code/ea_code_test.cc b/yacl/kernels/code/ea_code_test.cc similarity index 98% rename from yacl/crypto/primitives/code/ea_code_test.cc rename to yacl/kernels/code/ea_code_test.cc index 1de220eb..08393aef 100644 --- a/yacl/crypto/primitives/code/ea_code_test.cc +++ b/yacl/kernels/code/ea_code_test.cc @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/code/ea_code.h" +#include "yacl/kernels/code/ea_code.h" #include #include "gtest/gtest.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/code/linear_code.h b/yacl/kernels/code/linear_code.h similarity index 99% rename from yacl/crypto/primitives/code/linear_code.h rename to yacl/kernels/code/linear_code.h index a940ce20..7fddf370 100644 --- a/yacl/crypto/primitives/code/linear_code.h +++ b/yacl/kernels/code/linear_code.h @@ -21,8 +21,8 @@ #include "yacl/base/exception.h" #include "yacl/base/int128.h" -#include "yacl/crypto/primitives/code/code_interface.h" #include "yacl/crypto/tools/rp.h" +#include "yacl/kernels/code/code_interface.h" #include "yacl/math/gadget.h" #ifndef __aarch64__ diff --git a/yacl/crypto/primitives/code/linear_code_test.cc b/yacl/kernels/code/linear_code_test.cc similarity index 94% rename from yacl/crypto/primitives/code/linear_code_test.cc rename to yacl/kernels/code/linear_code_test.cc index 5a1f36f1..64fcae49 100644 --- a/yacl/crypto/primitives/code/linear_code_test.cc +++ b/yacl/kernels/code/linear_code_test.cc @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/code/linear_code.h" +#include "yacl/kernels/code/linear_code.h" #include #include "gtest/gtest.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/code/silver_code.cc b/yacl/kernels/code/silver_code.cc similarity index 99% rename from yacl/crypto/primitives/code/silver_code.cc rename to yacl/kernels/code/silver_code.cc index 2e522ebf..93f858f0 100644 --- a/yacl/crypto/primitives/code/silver_code.cc +++ b/yacl/kernels/code/silver_code.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/code/silver_code.h" +#include "yacl/kernels/code/silver_code.h" #include #include diff --git a/yacl/crypto/primitives/code/silver_code.h b/yacl/kernels/code/silver_code.h similarity index 98% rename from yacl/crypto/primitives/code/silver_code.h rename to yacl/kernels/code/silver_code.h index 246dfea7..ee87f451 100644 --- a/yacl/crypto/primitives/code/silver_code.h +++ b/yacl/kernels/code/silver_code.h @@ -27,7 +27,7 @@ #include "yacl/base/block.h" #include "yacl/base/exception.h" #include "yacl/base/int128.h" -#include "yacl/crypto/primitives/code/code_interface.h" +#include "yacl/kernels/code/code_interface.h" namespace yacl::crypto { diff --git a/yacl/crypto/primitives/code/silver_code_test.cc b/yacl/kernels/code/silver_code_test.cc similarity index 98% rename from yacl/crypto/primitives/code/silver_code_test.cc rename to yacl/kernels/code/silver_code_test.cc index 94388d76..b9e578eb 100644 --- a/yacl/crypto/primitives/code/silver_code_test.cc +++ b/yacl/kernels/code/silver_code_test.cc @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/primitives/code/silver_code.h" +#include "yacl/kernels/code/silver_code.h" #include #include "gtest/gtest.h" #include "yacl/base/int128.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" namespace yacl::crypto { diff --git a/yacl/kernels/kernel.h b/yacl/kernels/kernel.h new file mode 100644 index 00000000..6867390c --- /dev/null +++ b/yacl/kernels/kernel.h @@ -0,0 +1,44 @@ +// Copyright 2023 Ant Group Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +#include "yacl/link/context.h" + +namespace yacl::crypto { + +class Kernel { + public: + enum class Kind { SingleThread, MultiThread }; + + virtual ~Kernel() = default; + + virtual Kind kind() const = 0; + + // virtual void latency(); + + // virtual void comm(); + + // virtual void eval(); +}; + +// Stream kernels +class StreamKernel : public Kernel { + public: + Kind kind() const override { return Kind::SingleThread; } +}; + +} // namespace yacl::crypto diff --git a/yacl/kernels/svole_kernel.cc b/yacl/kernels/svole_kernel.cc new file mode 100644 index 00000000..0d47c0e0 --- /dev/null +++ b/yacl/kernels/svole_kernel.cc @@ -0,0 +1,175 @@ +// Copyright 2023 Ant Group Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "yacl/kernels/svole_kernel.h" + +#include +#include +#include + +#include "yacl/base/byte_container_view.h" +#include "yacl/base/exception.h" +#include "yacl/crypto/tools/common.h" +#include "yacl/crypto/tools/ro.h" +#include "yacl/kernels/algorithms/silent_vole.h" +#include "yacl/link/context.h" +#include "yacl/utils/thread_pool.h" + +namespace yacl::crypto { + +namespace { +inline std::vector> SetupLink( + const std::shared_ptr& lctx, int threads) { + std::vector> out_threads(threads); + for (int i = 0; i < threads; ++i) { + out_threads[i] = lctx->Spawn(); + } + return out_threads; +} + +} // namespace + +void SVoleKernel::init(const std::shared_ptr& lctx, + CodeType code) { + if (role_ == Role::Sender) { + core_ = SilentVoleSender(code, false); + + // run the one-time setup (the result is cached into impl) + std::get(core_).OneTimeSetup(lctx); + } else { + core_ = SilentVoleReceiver(code, false); + + // run the one-time setup (the result is cached into impl) + std::get(core_).OneTimeSetup(lctx); + } +} + +void SVoleKernel::eval(const std::shared_ptr& lctx, + uint128_t* out_delta, absl::Span out_c) { + YACL_ENFORCE(std::holds_alternative(core_)); + std::get(core_).SfSend(lctx, out_c); + *out_delta = std::get(core_).GetDelta(); +} + +void SVoleKernel::eval(const std::shared_ptr& lctx, + absl::Span out_a, + absl::Span out_b) { + YACL_ENFORCE(std::holds_alternative(core_)); + std::get(core_).SfRecv(lctx, out_a, out_b); +} + +void SVoleKernel::eval_multithread(const std::shared_ptr& lctx, + uint128_t* out_delta, + absl::Span out_c, int threads) { + YACL_ENFORCE(std::holds_alternative(core_)); + YACL_ENFORCE(threads >= 1); + + const size_t iter_size = out_c.size() / threads; + const size_t last_size = out_c.size() - iter_size * (threads - 1); + + std::vector> tl_c(threads); /*thread-local c spans*/ + for (int i = 0; i < threads - 1; ++i) { + tl_c[i] = out_c.subspan(iter_size * i, iter_size); + } + tl_c[threads - 1] = out_c.subspan(iter_size * (threads - 1), last_size); + + uint128_t shared_seed = SyncSeedSend(lctx); + + auto lctx_tl = SetupLink(lctx, threads); /* thread-local link */ + ThreadPool pool(threads); // the destructor joins all threads + auto task = [&](size_t i) { + auto tl_seed = RandomOracle::GetDefault().Gen( + ByteContainerView(&shared_seed, sizeof(shared_seed)), i); + auto tl_core = core_; + std::get(tl_core).SetOTCounter(tl_seed); + std::get(tl_core).SfSend(lctx_tl[i], tl_c[i]); + *out_delta = std::get(tl_core).GetDelta(); + }; + for (int i = 0; i < threads; ++i) { + pool.Submit(task, i); + } + + // the destructor of thread-pool joins all threads +} + +void SVoleKernel::eval_multithread(const std::shared_ptr& lctx, + absl::Span out_a, + absl::Span out_b, int threads) { + YACL_ENFORCE(std::holds_alternative(core_)); + YACL_ENFORCE(out_a.size() == out_b.size()); + YACL_ENFORCE(threads >= 1); + + const size_t iter_size = out_a.size() / threads; + const size_t last_size = out_a.size() - iter_size * (threads - 1); + + std::vector> tl_a(threads); /*thread-local a spans*/ + std::vector> tl_b(threads); /*thread-local b spans*/ + for (int i = 0; i < threads - 1; ++i) { + tl_a[i] = out_a.subspan(iter_size * i, iter_size); + tl_b[i] = out_b.subspan(iter_size * i, iter_size); + } + tl_a[threads - 1] = out_a.subspan(iter_size * (threads - 1), last_size); + tl_b[threads - 1] = out_b.subspan(iter_size * (threads - 1), last_size); + + uint128_t shared_seed = SyncSeedRecv(lctx); + + auto lctx_tl = SetupLink(lctx, threads); /* thread-local link */ + ThreadPool pool(threads); + auto task = [&](size_t i) { + auto tl_seed = RandomOracle::GetDefault().Gen( + ByteContainerView(&shared_seed, sizeof(shared_seed)), i); + auto tl_core = core_; + std::get(tl_core).SetOTCounter(tl_seed); + std::get(tl_core).SfRecv(lctx_tl[i], tl_a[i], tl_b[i]); + }; + for (int i = 0; i < threads; ++i) { + pool.Submit(task, i); + } + + // the destructor of thread-pool joins all threads +} + +void SVoleKernel::eval_streaming(const std::shared_ptr& lctx, + uint128_t* out_delta, + absl::Span out_c, int threads, + int step_size) { + const size_t step_num = (out_c.size() + step_size - 1) / step_size; + for (size_t i = 0; i < step_num; ++i) { + auto local_step_size = (i == ((size_t)step_num - 1)) + ? out_c.size() - step_size * (step_num - 1) + : step_size; + eval_multithread(lctx, out_delta, + out_c.subspan(step_size * (step_num - 1), local_step_size), + threads); + } + + *out_delta = std::get(core_).GetDelta(); +} + +void SVoleKernel::eval_streaming(const std::shared_ptr& lctx, + absl::Span out_a, + absl::Span out_b, int threads, + int step_size) { + YACL_ENFORCE(out_a.size() == out_b.size()); + const size_t step_num = (out_a.size() + step_size - 1) / step_size; + for (size_t i = 0; i < step_num; ++i) { + auto local_step_size = (i == ((size_t)step_num - 1)) + ? out_a.size() - step_size * (step_num - 1) + : step_size; + eval_multithread(lctx, out_a.subspan(step_size * i, local_step_size), + out_b.subspan(step_size * i, local_step_size), threads); + } +} + +} // namespace yacl::crypto diff --git a/yacl/kernels/svole_kernel.h b/yacl/kernels/svole_kernel.h new file mode 100644 index 00000000..cb9b7eb7 --- /dev/null +++ b/yacl/kernels/svole_kernel.h @@ -0,0 +1,79 @@ +// Copyright 2023 Ant Group Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include +#include + +#include "yacl/kernels/kernel.h" + +/* submodules */ +#include "yacl/kernels/algorithms/silent_vole.h" +#include "yacl/kernels/code/silver_code.h" + +namespace yacl::crypto { + +// --------------------- +// Kernel: Subfield VOLE +// --------------------- +// c = a * delta + b +// - where a is in GF(2^64), delta, b, c are in GF(2^128) +// Sender receives: c, delta +// Receiver receives: a, b +class SVoleKernel : StreamKernel { + public: + enum class Role { Sender, Receiver }; + + // constructor + explicit SVoleKernel(Role role) : role_(role) {} + + // the one-time setup + void init(const std::shared_ptr& lctx, + CodeType code = CodeType::Silver11); + + // evaluate function for sender + void eval(const std::shared_ptr& lctx, uint128_t* out_delta, + absl::Span out_c); + void eval_multithread(const std::shared_ptr& lctx, + uint128_t* out_delta, absl::Span out_c, + int threads); + void eval_streaming(const std::shared_ptr& lctx, + uint128_t* out_delta, absl::Span out_c, + int threads, int step_size); + + // evaluate function for receiver + void eval(const std::shared_ptr& lctx, + absl::Span out_a, absl::Span out_b); + + void eval_multithread(const std::shared_ptr& lctx, + absl::Span out_a, absl::Span out_b, + int threads); + + void eval_streaming(const std::shared_ptr& lctx, + absl::Span out_a, absl::Span out_b, + int threads, int step_size); + + private: + // use config + const Role role_; /* you should not change that after init */ + + // kernel's internal status + bool inited_ = false; + using CoreTy = + std::variant; + CoreTy core_; +}; + +} // namespace yacl::crypto diff --git a/yacl/kernels/svole_kernel_bench.cc b/yacl/kernels/svole_kernel_bench.cc new file mode 100644 index 00000000..bea0d9ad --- /dev/null +++ b/yacl/kernels/svole_kernel_bench.cc @@ -0,0 +1,136 @@ +// Copyright 2024 Ant Group Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include "benchmark/benchmark.h" + +#include "yacl/kernels/svole_kernel.h" +#include "yacl/link/test_util.h" + +namespace yacl::crypto { + +static void BM_SVOLE_single_thread(benchmark::State& state) { + auto lctxs = link::test::SetupWorld(2); + for (auto _ : state) { + state.PauseTiming(); + { + const size_t num_vole = 1 << 24; + uint128_t delta = 0; + std::vector a(num_vole); + std::vector b(num_vole); + std::vector c(num_vole); + SVoleKernel kernel0(SVoleKernel::Role::Sender); + SVoleKernel kernel1(SVoleKernel::Role::Receiver); + + // WHEN + state.ResumeTiming(); + auto sender = std::async([&] { + kernel0.init(lctxs[0]); + kernel0.eval(lctxs[0], &delta, absl::MakeSpan(c)); + }); + auto receiver = std::async([&] { + kernel1.init(lctxs[1]); + kernel1.eval(lctxs[1], absl::MakeSpan(a), absl::MakeSpan(b)); + }); + sender.get(); + receiver.get(); + state.PauseTiming(); + } + state.ResumeTiming(); + } +} + +static void BM_SVOLE_multi_thread(benchmark::State& state) { + auto lctxs = link::test::SetupWorld(2); + for (auto _ : state) { + state.PauseTiming(); + { + const size_t num_vole = 1 << 24; + const size_t threads = 16; + + uint128_t delta = 0; + std::vector a(num_vole); + std::vector b(num_vole); + std::vector c(num_vole); + SVoleKernel kernel0(SVoleKernel::Role::Sender); + SVoleKernel kernel1(SVoleKernel::Role::Receiver); + + // WHEN + state.ResumeTiming(); + auto sender = std::async([&] { + kernel0.init(lctxs[0]); + kernel0.eval_multithread(lctxs[0], &delta, absl::MakeSpan(c), threads); + }); + auto receiver = std::async([&] { + kernel1.init(lctxs[1]); + kernel1.eval_multithread(lctxs[1], absl::MakeSpan(a), absl::MakeSpan(b), + threads); + }); + sender.get(); + receiver.get(); + state.PauseTiming(); + } + state.ResumeTiming(); + } +} + +static void BM_SVOLE_streaming(benchmark::State& state) { + auto lctxs = link::test::SetupWorld(2); + for (auto _ : state) { + state.PauseTiming(); + { + const size_t num_vole = 1 << 24; + const size_t threads = 16; + const size_t step_size = 1 << 10; + + uint128_t delta = 0; + std::vector a(num_vole); + std::vector b(num_vole); + std::vector c(num_vole); + SVoleKernel kernel0(SVoleKernel::Role::Sender); + SVoleKernel kernel1(SVoleKernel::Role::Receiver); + + // WHEN + state.ResumeTiming(); + auto sender = std::async([&] { + kernel0.init(lctxs[0]); + kernel0.eval_streaming(lctxs[0], &delta, absl::MakeSpan(c), threads, + step_size); + }); + auto receiver = std::async([&] { + kernel1.init(lctxs[1]); + kernel1.eval_streaming(lctxs[1], absl::MakeSpan(a), absl::MakeSpan(b), + threads, step_size); + }); + sender.get(); + receiver.get(); + state.PauseTiming(); + } + state.ResumeTiming(); + } +} +} // namespace yacl::crypto + +BENCHMARK(yacl::crypto::BM_SVOLE_single_thread) + ->Iterations(1) + ->Unit(benchmark::kMillisecond); +BENCHMARK(yacl::crypto::BM_SVOLE_multi_thread) + ->Iterations(1) + ->Unit(benchmark::kMillisecond); +BENCHMARK(yacl::crypto::BM_SVOLE_streaming) + ->Iterations(1) + ->Unit(benchmark::kMillisecond); + +BENCHMARK_MAIN(); diff --git a/yacl/kernels/svole_kernel_test.cc b/yacl/kernels/svole_kernel_test.cc new file mode 100644 index 00000000..83d642e3 --- /dev/null +++ b/yacl/kernels/svole_kernel_test.cc @@ -0,0 +1,110 @@ +// Copyright 2023 Ant Group Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "yacl/kernels/svole_kernel.h" + +#include + +#include +#include + +#include "gtest/gtest.h" + +#include "yacl/link/test_util.h" + +namespace yacl::crypto { + +struct TestParams { + size_t num_vole; + int threads = 1; + // int step_size; +}; + +class SVoleTest : public ::testing::TestWithParam {}; + +TEST(SVoleTest, SingleThreadShouldWork) { + auto lctxs = link::test::SetupWorld(2); + + const size_t num_vole = 1 << 10; + + uint128_t delta = 0; + std::vector a(num_vole); + std::vector b(num_vole); + std::vector c(num_vole); + SVoleKernel kernel0(SVoleKernel::Role::Sender); + SVoleKernel kernel1(SVoleKernel::Role::Receiver); + + // WHEN + auto sender = std::async([&] { + kernel0.init(lctxs[0]); + kernel0.eval(lctxs[0], &delta, absl::MakeSpan(c)); + }); + auto receiver = std::async([&] { + kernel1.init(lctxs[1]); + kernel1.eval(lctxs[1], absl::MakeSpan(a), absl::MakeSpan(b)); + }); + sender.get(); + receiver.get(); + + for (uint64_t i = 0; i < num_vole; ++i) { + EXPECT_EQ(math::GfMul(a[i], delta) ^ b[i], c[i]); + } +} + +TEST_P(SVoleTest, MultiThreadShouldWork) { + auto lctxs = link::test::SetupWorld(2); + + const size_t num_vole = GetParam().num_vole; + const size_t threads = GetParam().threads; + + uint128_t delta = 0; + std::vector a(num_vole); + std::vector b(num_vole); + std::vector c(num_vole); + SVoleKernel kernel0(SVoleKernel::Role::Sender); + SVoleKernel kernel1(SVoleKernel::Role::Receiver); + + // WHEN + auto sender = std::async([&] { + kernel0.init(lctxs[0]); + kernel0.eval_multithread(lctxs[0], &delta, absl::MakeSpan(c), threads); + }); + auto receiver = std::async([&] { + kernel1.init(lctxs[1]); + kernel1.eval_multithread(lctxs[1], absl::MakeSpan(a), absl::MakeSpan(b), + threads); + }); + sender.get(); + receiver.get(); + + for (uint64_t i = 0; i < num_vole; ++i) { + EXPECT_EQ(math::GfMul(a[i], delta) ^ b[i], c[i]); + // if ((math::GfMul(a[i], delta) ^ b[i]) != c[i]) { + // SPDLOG_INFO("ERROR: a[{}]={}, delta={}, b[{}]={}, c[{}]={}", i, a[i], + // delta, i, b[i], i, c[i]); + // SPDLOG_INFO("ERROR: expect c[{}]={}, but c[{}]={}", i, + // math::GfMul(a[i], delta) ^ b[i], i, c[i]); + // break; + // } + } +} + +INSTANTIATE_TEST_SUITE_P(Works_Instances, SVoleTest, + testing::Values(TestParams{1 << 10, 1}, // + TestParams{1 << 10, 2}, // + TestParams{1 << 10, 3}, // + TestParams{1 << 10, 4} // + )); + +} // namespace yacl::crypto diff --git a/yacl/link/context.cc b/yacl/link/context.cc index 7ab05577..e7b5c7f3 100644 --- a/yacl/link/context.cc +++ b/yacl/link/context.cc @@ -137,6 +137,16 @@ void Context::WaitLinkTaskFinish() { } } +void Context::AbortLink() { + YACL_ENFORCE(is_sub_world_ == false, + "DO NOT call AbortLink on sub world link"); + for (const auto& l : channels_) { + if (l) { + l->Abort(); + } + } +} + void Context::ConnectToMesh(spdlog::level::level_enum connect_log_level) { SPDLOG_COND(connect_log_level, "connecting to mesh, id={}, self={}", Id(), Rank()); diff --git a/yacl/link/context.h b/yacl/link/context.h index 67f886ae..6029cebe 100644 --- a/yacl/link/context.h +++ b/yacl/link/context.h @@ -280,6 +280,8 @@ class Context { void WaitLinkTaskFinish(); + void AbortLink(); + void SetThrottleWindowSize(size_t); void SetChunkParallelSendSize(size_t); diff --git a/yacl/link/context_test.cc b/yacl/link/context_test.cc index 0f82c7dd..1320069a 100644 --- a/yacl/link/context_test.cc +++ b/yacl/link/context_test.cc @@ -50,6 +50,7 @@ class MockChannel : public transport::IChannel { void SetRecvTimeout(uint64_t timeout_ms) override { timeout_ = timeout_ms; } uint64_t GetRecvTimeout() const override { return timeout_; } void WaitLinkTaskFinish() override {} + void Abort() override {} void SetThrottleWindowSize(size_t) override {} void SetChunkParallelSendSize(size_t) override {} diff --git a/yacl/link/transport/channel.cc b/yacl/link/transport/channel.cc index 52b38388..a8c3fb22 100644 --- a/yacl/link/transport/channel.cc +++ b/yacl/link/transport/channel.cc @@ -163,6 +163,10 @@ void Channel::SendThread() { ThrottleWindowWait(seq_id); } + if (aborting_.load()) { + return; // stop send thread immediately + } + // link is closing, send all pending msgs while (true) { auto msg = send_msgs_.Pop(false); @@ -316,6 +320,9 @@ void Channel::SendRequestWithRetry(const ::google::protobuf::Message& request, spdlog::level::level_enum log_level) const { uint32_t retry_count = 0; while (true) { + if (aborting_.load()) { + YACL_THROW_LINK_ABORTED("channel is aborting"); + } try { link_->SendRequest(request, timeout_override_ms); break; @@ -376,6 +383,9 @@ void Channel::SendTaskSynchronizer::SendTaskFinishedNotify(size_t seq_id) { void Channel::SendTaskSynchronizer::WaitSeqIdSendFinished(size_t seq_id) { std::unique_lock lock(mutex_); while (!finished_ids_.Contains(seq_id)) { + if (task_aborting_.load()) { + YACL_THROW_LINK_ABORTED("aborting task, skip waiting"); + } finished_cond_.wait(lock); } } @@ -388,6 +398,9 @@ void Channel::SendTaskSynchronizer::WaitAllSendFinished() { } Buffer Channel::Recv(const std::string& msg_key) { + if (aborting_.load()) { + YACL_THROW_LINK_ABORTED("Recv is not allowed when aborting channel"); + } NormalMessageKeyEnforce(msg_key); Buffer value; @@ -405,6 +418,9 @@ Buffer Channel::Recv(const std::string& msg_key) { } }; while (!stop_waiting()) { + if (aborting_.load()) { + YACL_THROW_LINK_ABORTED("Aborting channel, skip waiting"); + } // timeout_us if (msg_db_cond_.wait_for(lock, static_cast(recv_timeout_ms_) * 1000) == ETIMEDOUT) { @@ -559,6 +575,10 @@ void Channel::MessageQueue::Push(Message&& msg) { } void Channel::SendAsync(const std::string& msg_key, Buffer&& value) { + if (aborting_.load()) { + YACL_THROW_LINK_ABORTED( + "SendAsync is not allowed when channel is aborting"); + } YACL_ENFORCE(!waiting_finish_.load(), "SendAsync is not allowed when channel is closing"); NormalMessageKeyEnforce(msg_key); @@ -575,6 +595,9 @@ void Channel::SendAsync(const std::string& msg_key, Buffer&& value) { } void Channel::Send(const std::string& msg_key, ByteContainerView value) { + if (aborting_.load()) { + YACL_THROW_LINK_ABORTED("Send is not allowed when channel is aborting"); + } if (YACL_UNLIKELY(disable_msg_seq_id_)) { YACL_THROW("Send is not allowed when msg_seq_id is disabled"); } @@ -594,6 +617,10 @@ void Channel::SendAsyncThrottled(const std::string& msg_key, } void Channel::SendAsyncThrottled(const std::string& msg_key, Buffer&& value) { + if (aborting_.load()) { + YACL_THROW_LINK_ABORTED( + "SendAsyncThrottled is not allowed when channel is aborting"); + } if (YACL_UNLIKELY(disable_msg_seq_id_)) { return SendAsync(msg_key, value); } @@ -608,6 +635,9 @@ void Channel::SendAsyncThrottled(const std::string& msg_key, Buffer&& value) { } void Channel::TestSend(uint32_t timeout) { + if (aborting_.load()) { + YACL_THROW_LINK_ABORTED("TestSend is not allowed when channel is aborting"); + } YACL_ENFORCE(!waiting_finish_.load(), "TestSend is not allowed when channel is closing"); const auto msg_key = fmt::format("connect_{}", link_->LocalRank()); @@ -628,6 +658,9 @@ void Channel::ThrottleWindowWait(size_t wait_count) { std::unique_lock lock(msg_mutex_); while ((throttle_window_size_ != 0) && (received_ack_ids_.Count() + throttle_window_size_ <= wait_count)) { + if (aborting_.load()) { + YACL_THROW_LINK_ABORTED("Aborting channel, skip waiting"); + } // timeout_us if (ack_fin_cond_.wait_for( lock, static_cast(recv_timeout_ms_) * 1000) == ETIMEDOUT) { @@ -702,6 +735,10 @@ void Channel::WaitForFlyingAck() { } void Channel::WaitLinkTaskFinish() { + if (aborting_.load()) { + SPDLOG_WARN("channel aborted, can not wait for link task finish"); + return; + } // 4 steps to total stop link. // send ack for msg exist in recv_msgs_ that unread by up layer logic. // stop OnMessage & auto ack all normal msg from now on. @@ -718,8 +755,28 @@ void Channel::WaitLinkTaskFinish() { // after all, we can safely close server port and exit. } +void Channel::Abort() { + SPDLOG_INFO("channel aborting"); + aborting_.store(true); + // notify for Recv to stop. + msg_db_cond_.notify_all(); + // notify for ThrottleWindowWait to stop. + ack_fin_cond_.notify_all(); + // stop SendTaskSynchronizer to avoid blocking in Send + send_sync_.Abort(); + // stop send thread + send_thread_stopped_.store(true); + send_msgs_.EmptyNotify(); + send_thread_.join(); + + SPDLOG_INFO("channel aborted"); +} + void Channel::OnRequest(const ::google::protobuf::Message& request, ::google::protobuf::Message* response) { + if (aborting_.load()) { + YACL_THROW_LINK_ABORTED("OnRequest is not allowed when aborting channel"); + } YACL_ENFORCE(response != nullptr, "response should not be null"); YACL_ENFORCE(link_ != nullptr, "delegate should not be null"); diff --git a/yacl/link/transport/channel.h b/yacl/link/transport/channel.h index 9d386ee9..4b404c3b 100644 --- a/yacl/link/transport/channel.h +++ b/yacl/link/transport/channel.h @@ -79,6 +79,9 @@ class IChannel { // wait for all send and rev msg finish virtual void WaitLinkTaskFinish() = 0; + // abort channel immediately + virtual void Abort() = 0; + // set send throttle window size virtual void SetThrottleWindowSize(size_t) = 0; @@ -195,6 +198,11 @@ class Channel : public IChannel, public std::enable_shared_from_this { void WaitLinkTaskFinish() final; + // Note: the channel can no longer be used after aborted, otherwise + // SendAsync/SendAsyncThrottled/Send/Recv/TestSend/TestRecv will throw + // yacl::LinkAborted. + void Abort() final; + void SetThrottleWindowSize(size_t size) final { throttle_window_size_ = size; } @@ -296,12 +304,17 @@ class Channel : public IChannel, public std::enable_shared_from_this { void SendTaskFinishedNotify(size_t seq_id); void WaitSeqIdSendFinished(size_t seq_id); void WaitAllSendFinished(); + void Abort() { + task_aborting_.store(true); + finished_cond_.notify_all(); + } private: bthread::Mutex mutex_; size_t running_tasks_ = 0; utils::SegmentTree finished_ids_; bthread::ConditionVariable finished_cond_; + std::atomic task_aborting_ = false; }; class MessageQueue { @@ -342,6 +355,8 @@ class Channel : public IChannel, public std::enable_shared_from_this { // if WaitLinkTaskFinish is called. // auto ack all normal msg if true. std::atomic waiting_finish_ = false; + // for Abort + std::atomic aborting_ = false; // id count for normal msg sent to peer. std::atomic msg_seq_id_ = 0; // ids for received normal msg from peer. diff --git a/yacl/link/transport/channel_mem.h b/yacl/link/transport/channel_mem.h index 54b241f3..1f4ec64b 100644 --- a/yacl/link/transport/channel_mem.h +++ b/yacl/link/transport/channel_mem.h @@ -80,6 +80,8 @@ class ChannelMem final : public IChannel { void WaitLinkTaskFinish() final; + void Abort() override { YACL_THROW("not supported yet"); } + // do nothing void SetThrottleWindowSize(size_t) final {} void TestSend(uint32_t /*timeout*/) final {} diff --git a/yacl/math/f2k/BUILD.bazel b/yacl/math/f2k/BUILD.bazel index f7f068ff..e3e88702 100644 --- a/yacl/math/f2k/BUILD.bazel +++ b/yacl/math/f2k/BUILD.bazel @@ -33,7 +33,7 @@ yacl_cc_test( copts = AES_COPT_FLAGS, deps = [ ":f2k", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", ], ) @@ -43,7 +43,7 @@ yacl_cc_binary( copts = AES_COPT_FLAGS, deps = [ ":f2k", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", "@com_github_google_benchmark//:benchmark_main", ], ) diff --git a/yacl/math/f2k/f2k_bench.cc b/yacl/math/f2k/f2k_bench.cc index 92256435..6e39480b 100644 --- a/yacl/math/f2k/f2k_bench.cc +++ b/yacl/math/f2k/f2k_bench.cc @@ -17,7 +17,7 @@ #include "benchmark/benchmark.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/math/f2k/f2k.h" static void BM_ClMul128_block(benchmark::State& state) { diff --git a/yacl/math/f2k/f2k_test.cc b/yacl/math/f2k/f2k_test.cc index 493e0521..cbb20588 100644 --- a/yacl/math/f2k/f2k_test.cc +++ b/yacl/math/f2k/f2k_test.cc @@ -23,7 +23,7 @@ #include "yacl/base/block.h" #include "yacl/base/int128.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" namespace { template diff --git a/yacl/math/galois_field/mcl_field/BUILD.bazel b/yacl/math/galois_field/mcl_field/BUILD.bazel index 0269651c..aae18b5f 100644 --- a/yacl/math/galois_field/mcl_field/BUILD.bazel +++ b/yacl/math/galois_field/mcl_field/BUILD.bazel @@ -31,8 +31,8 @@ yacl_cc_library( "//conditions:default": [], }), deps = [ - "//yacl/crypto/base/ecc/mcl:util", - "//yacl/crypto/base/pairing/mcl:pairing_header", + "//yacl/crypto/ecc/mcl:util", + "//yacl/crypto/pairing/mcl:pairing_header", "//yacl/math/galois_field:sketch", ], ) @@ -42,7 +42,7 @@ yacl_cc_test( srcs = ["mcl_field_test.cc"], deps = [ ":field", - "//yacl/crypto/base/pairing/mcl:pairing", - "//yacl/crypto/utils:rand", + "//yacl/crypto/pairing/mcl:pairing", + "//yacl/crypto/rand", ], ) diff --git a/yacl/math/galois_field/mcl_field/mcl_field.cc b/yacl/math/galois_field/mcl_field/mcl_field.cc index e6d83ab0..3fdec702 100644 --- a/yacl/math/galois_field/mcl_field/mcl_field.cc +++ b/yacl/math/galois_field/mcl_field/mcl_field.cc @@ -19,8 +19,8 @@ #include "mcl/fp_tower.hpp" #include "mcl/op.hpp" -#include "yacl/crypto/base/ecc/mcl/mcl_util.h" -#include "yacl/crypto/base/pairing/mcl/pairing_header.h" +#include "yacl/crypto/ecc/mcl/mcl_util.h" +#include "yacl/crypto/pairing/mcl/pairing_header.h" #include "yacl/math/galois_field/gf_configs.h" namespace yacl::math::hmcl { diff --git a/yacl/math/galois_field/mcl_field/mcl_field.h b/yacl/math/galois_field/mcl_field/mcl_field.h index eb23ced8..4c0a5a88 100644 --- a/yacl/math/galois_field/mcl_field/mcl_field.h +++ b/yacl/math/galois_field/mcl_field/mcl_field.h @@ -17,7 +17,7 @@ #include "mcl/fp.hpp" #include "mcl/fp_tower.hpp" -#include "yacl/crypto/base/pairing/mcl/pairing_header.h" +#include "yacl/crypto/pairing/mcl/pairing_header.h" #include "yacl/math/galois_field/gf_scalar.h" namespace yacl::math::hmcl { diff --git a/yacl/math/galois_field/mcl_field/mcl_field_test.cc b/yacl/math/galois_field/mcl_field/mcl_field_test.cc index 7dfc4cb9..4b4e79f2 100644 --- a/yacl/math/galois_field/mcl_field/mcl_field_test.cc +++ b/yacl/math/galois_field/mcl_field/mcl_field_test.cc @@ -16,9 +16,9 @@ #include "gtest/gtest.h" -#include "yacl/crypto/base/ecc/mcl/mcl_util.h" -#include "yacl/crypto/base/pairing/mcl/mcl_pairing_group.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/ecc/mcl/mcl_util.h" +#include "yacl/crypto/pairing/mcl/mcl_pairing_group.h" +#include "yacl/crypto/rand/rand.h" #include "yacl/math/galois_field/gf_configs.h" namespace yacl::math::hmcl::test { diff --git a/yacl/crypto/utils/secparam.cc b/yacl/secparam.cc similarity index 95% rename from yacl/crypto/utils/secparam.cc rename to yacl/secparam.cc index a769e796..71db57fa 100644 --- a/yacl/crypto/utils/secparam.cc +++ b/yacl/secparam.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/utils/secparam.h" +#include "yacl/secparam.h" namespace yacl::crypto { SecParam::C SecParam::glob_c = SecParam::C::INF; // init to infinity diff --git a/yacl/crypto/utils/secparam.h b/yacl/secparam.h similarity index 99% rename from yacl/crypto/utils/secparam.h rename to yacl/secparam.h index 79793b83..8adf449c 100644 --- a/yacl/crypto/utils/secparam.h +++ b/yacl/secparam.h @@ -22,8 +22,8 @@ #include "fmt/color.h" #include "yacl/base/exception.h" -#include "yacl/crypto/utils/compile_time_utils.h" #include "yacl/math/gadget.h" +#include "yacl/utils/compile_time_utils.h" namespace yacl::crypto { diff --git a/yacl/crypto/utils/secparam_test.cc b/yacl/secparam_test.cc similarity index 97% rename from yacl/crypto/utils/secparam_test.cc rename to yacl/secparam_test.cc index deeb9898..369870e1 100644 --- a/yacl/crypto/utils/secparam_test.cc +++ b/yacl/secparam_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/utils/secparam.h" +#include "yacl/secparam.h" #include "gtest/gtest.h" @@ -38,4 +38,5 @@ TEST(DeclareTest, Test) { YACL_PRINT_MODULE_SUMMARY(); } + } // namespace yacl::crypto diff --git a/yacl/utils/BUILD.bazel b/yacl/utils/BUILD.bazel index 68ab8322..f4191f95 100644 --- a/yacl/utils/BUILD.bazel +++ b/yacl/utils/BUILD.bazel @@ -86,7 +86,6 @@ yacl_cc_library( yacl_cc_library( name = "serializer", - srcs = ["serializer.cc"], hdrs = [ "serializer.h", "serializer_adapter.h", @@ -206,7 +205,7 @@ yacl_cc_test( srcs = ["cuckoo_index_test.cc"], deps = [ ":cuckoo_index", - "//yacl/crypto/utils:rand", + "//yacl/crypto/rand", ], ) @@ -265,3 +264,10 @@ yacl_cc_library( "//yacl/base:exception", ], ) + +yacl_cc_library( + name = "compile_time_utils", + hdrs = [ + "compile_time_utils.h", + ], +) diff --git a/yacl/crypto/utils/compile_time_utils.h b/yacl/utils/compile_time_utils.h similarity index 100% rename from yacl/crypto/utils/compile_time_utils.h rename to yacl/utils/compile_time_utils.h diff --git a/yacl/utils/cuckoo_index_test.cc b/yacl/utils/cuckoo_index_test.cc index da633ecc..1912bfb9 100644 --- a/yacl/utils/cuckoo_index_test.cc +++ b/yacl/utils/cuckoo_index_test.cc @@ -18,7 +18,7 @@ #include "gtest/gtest.h" -#include "yacl/crypto/utils/rand.h" +#include "yacl/crypto/rand/rand.h" namespace yacl { diff --git a/yacl/utils/serializer.cc b/yacl/utils/serializer.cc deleted file mode 100644 index 9b1ab21a..00000000 --- a/yacl/utils/serializer.cc +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2024 Ant Group Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "yacl/utils/serializer.h" - -namespace yacl { - -bool internal::ref_or_copy(msgpack::type::object_type type, std::size_t length, - void *) { - switch (type) { - case msgpack::type::STR: - // Small strings are copied. - return length >= 32; - case msgpack::type::BIN: - // BIN is always referenced. - return true; - case msgpack::type::EXT: - // EXT is always copied. - return false; - default: - YACL_THROW("unexpected type {}", static_cast(type)); - } -} - -} // namespace yacl diff --git a/yacl/utils/serializer.h b/yacl/utils/serializer.h index 11b4bfdd..a2567049 100644 --- a/yacl/utils/serializer.h +++ b/yacl/utils/serializer.h @@ -92,7 +92,10 @@ inline size_t SerializeVarsTo(uint8_t *buf, size_t buf_len, const Ts &...obj) { namespace internal { -bool ref_or_copy(msgpack::type::object_type type, std::size_t length, void *); +inline bool ref_or_copy(msgpack::type::object_type, std::size_t, void *) { + // Always use reference mode to avoid pointers pointing to illegal addresses. + return true; +} template std::tuple DoDeserializeAsTuple(std::index_sequence, diff --git a/yacl/utils/serializer_test.cc b/yacl/utils/serializer_test.cc index 68631e2b..94b40617 100644 --- a/yacl/utils/serializer_test.cc +++ b/yacl/utils/serializer_test.cc @@ -79,7 +79,7 @@ TEST(SerializerTest, Buffer) { auto buf = SerializeVars(hello, hello); auto [f1, f2] = DeserializeVars(buf); - EXPECT_STREQ(f1.data(), "hello"); + EXPECT_EQ(std::string(f1.data(), f1.size()), "hello"); EXPECT_EQ((std::string_view)f2, "hello"); ByteContainerView view1, view2;