From 10707d156e1924d4372013b28d27d8c9bbd4e6bf Mon Sep 17 00:00:00 2001 From: Jamie Cui Date: Fri, 22 Nov 2024 19:32:40 +0800 Subject: [PATCH 1/6] feat(engine): add plaintext and gc engine, wip --- .bazelignore | 3 + README.md | 1 - examples/hesm2/BUILD.bazel | 40 ++++++++ yacl/crypto/tools/BUILD.bazel | 21 ++++ yacl/{utils => crypto/tools}/cuckoo_index.cc | 4 +- yacl/{utils => crypto/tools}/cuckoo_index.h | 0 .../tools}/cuckoo_index_test.cc | 2 +- yacl/engine/plaintext/BUILD.bazel | 39 ++++++++ .../plaintext/executor.cc} | 38 +------ yacl/engine/plaintext/executor.h | 99 +++++++++++++++++++ .../plaintext/executor_test.cc} | 48 ++++++--- yacl/io/circuit/bristol_fashion.h | 55 ++++++++++- yacl/kernel/algorithms/BUILD.bazel | 2 +- yacl/kernel/algorithms/ferret_ote.cc | 2 +- yacl/utils/BUILD.bazel | 43 -------- yacl/utils/circuit_executor.h | 50 ---------- 16 files changed, 297 insertions(+), 150 deletions(-) create mode 100644 examples/hesm2/BUILD.bazel rename yacl/{utils => crypto/tools}/cuckoo_index.cc (98%) rename yacl/{utils => crypto/tools}/cuckoo_index.h (100%) rename yacl/{utils => crypto/tools}/cuckoo_index_test.cc (98%) create mode 100644 yacl/engine/plaintext/BUILD.bazel rename yacl/{utils/circuit_executor.cc => engine/plaintext/executor.cc} (69%) create mode 100644 yacl/engine/plaintext/executor.h rename yacl/{utils/circuit_executor_test.cc => engine/plaintext/executor_test.cc} (84%) delete mode 100644 yacl/utils/circuit_executor.h diff --git a/.bazelignore b/.bazelignore index 1e107f5..74ecab7 100644 --- a/.bazelignore +++ b/.bazelignore @@ -1 +1,4 @@ examples +cmake +docs +build diff --git a/README.md b/README.md index 4358234..9026c40 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,6 @@ Yacl-r is a fork and extension of the C++ crypto library [secretflow/yacl](https - **bazel**: [.bazelversion](.bazelversion) file describes the recommended version of bazel. We recommend to use the official [bazelisk](https://github.com/bazelbuild/bazelisk?tab=readme-ov-file#installation) to manage bazel version. - **gcc >= 10.3** -- **[cmake](https://cmake.org/getting-started/)** - **[ninja/ninja-build](https://ninja-build.org/)** - **Perl 5 with core modules** (Required by [OpenSSL](https://github.com/openssl/openssl/blob/master/INSTALL.md#prerequisites)) diff --git a/examples/hesm2/BUILD.bazel b/examples/hesm2/BUILD.bazel new file mode 100644 index 0000000..e97e7de --- /dev/null +++ b/examples/hesm2/BUILD.bazel @@ -0,0 +1,40 @@ +# Copyright 2024 Guowei Ling. +# +# 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("@yacl//bazel:yacl.bzl", "yacl_cc_binary") + +package(default_visibility = ["//visibility:public"]) + +yacl_cc_binary( + name = "sm2_example", + srcs = [ + "ahesm2.cc", + "ahesm2.h", + "ciphertext.h", + "config.cc", + "config.h", + "main.cc", + "private_key.h", + "public_key.h", + "t1.h", + "t2.h", + ], + deps = [ + "@yacl//yacl/crypto/ecc:spi", + "@yacl//yacl/crypto/ecc/openssl", + "@yacl//yacl/crypto/tools:cuckoo_index", # 添加 cuckoo_index 依赖 + "@yacl//yacl/math/mpint", + "@yacl//yacl/utils/spi", + ], +) diff --git a/yacl/crypto/tools/BUILD.bazel b/yacl/crypto/tools/BUILD.bazel index 2ef47cd..ff7bfa5 100644 --- a/yacl/crypto/tools/BUILD.bazel +++ b/yacl/crypto/tools/BUILD.bazel @@ -119,3 +119,24 @@ yacl_cc_binary( "@com_github_google_benchmark//:benchmark_main", ], ) + +yacl_cc_library( + name = "cuckoo_index", + srcs = ["cuckoo_index.cc"], + hdrs = ["cuckoo_index.h"], + linkopts = ["-lm"], + deps = [ + "//yacl/base:exception", + "//yacl/base:int128", + "@com_google_absl//absl/types:span", + ], +) + +yacl_cc_test( + name = "cuckoo_index_test", + srcs = ["cuckoo_index_test.cc"], + deps = [ + ":cuckoo_index", + "//yacl/crypto/rand", + ], +) diff --git a/yacl/utils/cuckoo_index.cc b/yacl/crypto/tools/cuckoo_index.cc similarity index 98% rename from yacl/utils/cuckoo_index.cc rename to yacl/crypto/tools/cuckoo_index.cc index 29850e3..7eff417 100644 --- a/yacl/utils/cuckoo_index.cc +++ b/yacl/crypto/tools/cuckoo_index.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/utils/cuckoo_index.h" +#include "yacl/crypto/tools/cuckoo_index.h" #include #include @@ -147,4 +147,4 @@ uint8_t CuckooIndex::MinCollidingHashIdx(uint64_t bin_index) const { return -1; } -} // namespace yacl \ No newline at end of file +} // namespace yacl diff --git a/yacl/utils/cuckoo_index.h b/yacl/crypto/tools/cuckoo_index.h similarity index 100% rename from yacl/utils/cuckoo_index.h rename to yacl/crypto/tools/cuckoo_index.h diff --git a/yacl/utils/cuckoo_index_test.cc b/yacl/crypto/tools/cuckoo_index_test.cc similarity index 98% rename from yacl/utils/cuckoo_index_test.cc rename to yacl/crypto/tools/cuckoo_index_test.cc index 1912bfb..b3d1cb6 100644 --- a/yacl/utils/cuckoo_index_test.cc +++ b/yacl/crypto/tools/cuckoo_index_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/utils/cuckoo_index.h" +#include "yacl/crypto/tools/cuckoo_index.h" #include diff --git a/yacl/engine/plaintext/BUILD.bazel b/yacl/engine/plaintext/BUILD.bazel new file mode 100644 index 0000000..30d371b --- /dev/null +++ b/yacl/engine/plaintext/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 = "executor", + srcs = ["executor.cc"], + hdrs = ["executor.h"], + deps = [ + "//yacl/base:dynamic_bitset", + "//yacl/base:int128", + "//yacl/io/circuit:bristol_fashion", + ], +) + +yacl_cc_test( + name = "executor_test", + srcs = ["executor_test.cc"], + data = ["//yacl/io/circuit:circuit_data"], + deps = [ + "executor", + "//yacl/crypto/block_cipher:symmetric_crypto", + "//yacl/crypto/rand", + ], +) diff --git a/yacl/utils/circuit_executor.cc b/yacl/engine/plaintext/executor.cc similarity index 69% rename from yacl/utils/circuit_executor.cc rename to yacl/engine/plaintext/executor.cc index 856b8cb..1abf29e 100644 --- a/yacl/utils/circuit_executor.cc +++ b/yacl/engine/plaintext/executor.cc @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/utils/circuit_executor.h" +#include "yacl/engine/plaintext/executor.h" -namespace yacl { +namespace yacl::engine { namespace { class PlaintextCore { @@ -25,24 +25,13 @@ class PlaintextCore { }; } // namespace -template -void PlainExecutor::LoadCircuitFile(const std::string& path) { +void PlainExecutor::LoadCircuitFile(const std::string& path) { io::CircuitReader reader(path); reader.ReadAll(); circ_ = reader.StealCirc(); } -template -void PlainExecutor::SetupInputs(absl::Span inputs) { - YACL_ENFORCE(inputs.size() == circ_->niv); - for (auto input : inputs) { - wires_.append(input); - } - wires_.resize(circ_->nw); -} - -template -void PlainExecutor::Exec() { +void PlainExecutor::Exec() { // Evaluate all gates, sequentially for (const auto& gate : circ_->gates) { switch (gate.op) { @@ -82,22 +71,5 @@ void PlainExecutor::Exec() { } } -template -void PlainExecutor::Finalize(absl::Span outputs) { - YACL_ENFORCE(outputs.size() >= circ_->nov); - - size_t index = wires_.size(); - for (size_t i = 0; i < circ_->nov; ++i) { - dynamic_bitset result(circ_->now[i]); - for (size_t j = 0; j < circ_->now[i]; ++j) { - result[j] = wires_[index - circ_->now[i] + j]; - } - outputs[circ_->nov - i - 1] = *(T*)result.data(); - index -= circ_->now[i]; - } -} - -template class PlainExecutor; -template class PlainExecutor; -} // namespace yacl +} // namespace yacl::engine diff --git a/yacl/engine/plaintext/executor.h b/yacl/engine/plaintext/executor.h new file mode 100644 index 0000000..3028151 --- /dev/null +++ b/yacl/engine/plaintext/executor.h @@ -0,0 +1,99 @@ +// 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. + +#pragma once + +#include + +#include "yacl/base/byte_container_view.h" +#include "yacl/base/dynamic_bitset.h" +#include "yacl/base/int128.h" +#include "yacl/io/circuit/bristol_fashion.h" + +namespace yacl::engine { + +// plaintext protocol that executes everything without link + +class PlainExecutor { + public: + // Constructor + explicit PlainExecutor() = default; + + // Load circuit from file (local operation) + void LoadCircuitFile(const std::string &path); + + // Setup the input wire (local operation) + template + void SetupInputs(absl::Span inputs) { + YACL_ENFORCE(inputs.size() == circ_->niv); + + dynamic_bitset input_wires; + input_wires.resize(sizeof(T) * 8 * inputs.size()); + std::memcpy(input_wires.data(), inputs.data(), inputs.size() * sizeof(T)); + wires_.append(input_wires); + wires_.resize(circ_->nw); + } + + // Setup the input wire + void SetupInputBytes(ByteContainerView bytes) { + wires_.resize(circ_->nw); + std::memcpy(wires_.data(), bytes.data(), bytes.size()); + } + + // Execute the circuit + void Exec(); + + // Finalize and get the result + template + void Finalize(absl::Span outputs) { + YACL_ENFORCE(outputs.size() >= circ_->nov); + size_t index = wires_.size(); + for (size_t i = 0; i < circ_->nov; ++i) { + dynamic_bitset result(circ_->now[i]); + for (size_t j = 0; j < circ_->now[i]; ++j) { + result[j] = wires_[index - circ_->now[i] + j]; + } + outputs[circ_->nov - i - 1] = *(T *)result.data(); + index -= circ_->now[i]; + } + } + + std::vector FinalizeBytes() { + // Count the totoal number of output wires (a.k.a. output bits) + size_t total_out_bitnum = 0; + for (size_t i = 0; i < circ_->nov; ++i) { + total_out_bitnum += circ_->now[i]; + } + + // Make sure that the circuit output wire is full bytes + YACL_ENFORCE(total_out_bitnum % 8 == 0); + + const size_t wire_size = wires_.size(); + dynamic_bitset result(total_out_bitnum); + for (size_t i = 0; i < total_out_bitnum; ++i) { + result[total_out_bitnum - i - 1] = wires_[wire_size - i - 1]; + } + YACL_ENFORCE(result.size() == total_out_bitnum); + std::vector out(total_out_bitnum / 8); + std::memcpy(out.data(), result.data(), out.size()); + return out; + } + + private: + // NOTE: please make sure you use the correct order of wires + dynamic_bitset wires_; // shares + std::shared_ptr circ_; // bristol fashion circuit +}; + +} // namespace yacl::engine diff --git a/yacl/utils/circuit_executor_test.cc b/yacl/engine/plaintext/executor_test.cc similarity index 84% rename from yacl/utils/circuit_executor_test.cc rename to yacl/engine/plaintext/executor_test.cc index 9df0ad4..f51b6d9 100644 --- a/yacl/utils/circuit_executor_test.cc +++ b/yacl/engine/plaintext/executor_test.cc @@ -13,9 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/utils/circuit_executor.h" - -#include +#include "yacl/engine/plaintext/executor.h" #include "absl/strings/escaping.h" #include "gtest/gtest.h" @@ -23,10 +21,11 @@ #include "yacl/base/byte_container_view.h" #include "yacl/base/dynamic_bitset.h" #include "yacl/crypto/block_cipher/symmetric_crypto.h" +#include "yacl/crypto/hash/ssl_hash.h" #include "yacl/crypto/rand/rand.h" #include "yacl/io/circuit/bristol_fashion.h" -namespace yacl { +namespace yacl::engine { namespace { inline uint64_t Add64(uint64_t in1, uint64_t in2) { return in1 + in2; } @@ -64,11 +63,11 @@ uint128_t ReverseBytes(uint128_t x) { TEST(ArithmaticTest, Add64Test) { /* GIVEN */ - std::vector inputs = {crypto::FastRandU64(), crypto::FastRandU64()}; + std::vector inputs = {1, 3}; std::vector result(1); /* WHEN */ - PlainExecutor exec; + PlainExecutor exec; exec.LoadCircuitFile(io::BuiltinBFCircuit::Add64Path()); exec.SetupInputs(absl::MakeSpan(inputs)); exec.Exec(); @@ -84,7 +83,7 @@ TEST(ArithmaticTest, Sub64Test) { std::vector result(1); /* WHEN */ - PlainExecutor exec; + PlainExecutor exec; exec.LoadCircuitFile(io::BuiltinBFCircuit::Sub64Path()); exec.SetupInputs(absl::MakeSpan(inputs)); exec.Exec(); @@ -100,7 +99,7 @@ TEST(ArithmaticTest, Neg64Test) { std::vector result(1); /* WHEN */ - PlainExecutor exec; + PlainExecutor exec; exec.LoadCircuitFile(io::BuiltinBFCircuit::Neg64Path()); exec.SetupInputs(absl::MakeSpan(inputs)); exec.Exec(); @@ -116,7 +115,7 @@ TEST(ArithmaticTest, Mul64Test) { std::vector result(1); /* WHEN */ - PlainExecutor exec; + PlainExecutor exec; exec.LoadCircuitFile(io::BuiltinBFCircuit::Mul64Path()); exec.SetupInputs(absl::MakeSpan(inputs)); exec.Exec(); @@ -132,7 +131,7 @@ TEST(ArithmaticTest, Div64Test) { std::vector result(1); /* WHEN */ - PlainExecutor exec; + PlainExecutor exec; exec.LoadCircuitFile(io::BuiltinBFCircuit::Div64Path()); exec.SetupInputs(absl::MakeSpan(inputs)); exec.Exec(); @@ -149,7 +148,7 @@ TEST(ArithmaticTest, UDiv64Test) { /* WHEN */ - PlainExecutor exec; + PlainExecutor exec; exec.LoadCircuitFile(io::BuiltinBFCircuit::UDiv64Path()); exec.SetupInputs(absl::MakeSpan(inputs)); exec.Exec(); @@ -165,7 +164,7 @@ TEST(ArithmaticTest, EqzTest) { std::vector result(1); /* WHEN */ - PlainExecutor exec; + PlainExecutor exec; exec.LoadCircuitFile(io::BuiltinBFCircuit::EqzPath()); exec.SetupInputs(absl::MakeSpan(inputs)); exec.Exec(); @@ -188,7 +187,7 @@ TEST(CryptoTest, Aes128Test) { std::vector result(1); /* WHEN */ - PlainExecutor exec; + PlainExecutor exec; exec.LoadCircuitFile(io::BuiltinBFCircuit::Aes128Path()); exec.SetupInputs(absl::MakeSpan(inputs)); exec.Exec(); @@ -208,4 +207,25 @@ TEST(CryptoTest, Aes128Test) { EXPECT_EQ(ReverseBytes(result[0]), compare); } -} // namespace yacl +TEST(CryptoTest, Sha256Test) { + /* GIVEN */ + auto input = crypto::FastRandBytes(crypto::RandLtN(10)); + + std::string temp = "1"; + SPDLOG_INFO(absl::BytesToHexString( + ByteContainerView(io::BuiltinBFCircuit::PrepareSha256Input(temp)))); + + /* WHEN */ + // PlainExecutor exec; + // exec.LoadCircuitFile(io::BuiltinBFCircuit::Sha256Path()); + // exec.SetupInputBytes(io::BuiltinBFCircuit::PrepareSha256Input(input)); + // exec.Exec(); + // auto result = exec.FinalizeBytes(); + + /* THEN */ + // auto compare = crypto::Sha256Hash().Update(input).CumulativeHash(); + // SPDLOG_INFO(absl::BytesToHexString(ByteContainerView(result))); + // SPDLOG_INFO(absl::BytesToHexString(ByteContainerView(compare))); +} + +} // namespace yacl::engine diff --git a/yacl/io/circuit/bristol_fashion.h b/yacl/io/circuit/bristol_fashion.h index 3b669ab..2748fed 100644 --- a/yacl/io/circuit/bristol_fashion.h +++ b/yacl/io/circuit/bristol_fashion.h @@ -23,6 +23,7 @@ #include "spdlog/spdlog.h" +#include "yacl/base/byte_container_view.h" #include "yacl/base/exception.h" #include "yacl/io/stream/file_io.h" #include "yacl/io/stream/interface.h" @@ -136,6 +137,52 @@ class BuiltinBFCircuit { std::filesystem::current_path().string()); } + constexpr static std::array GetSha256InitialHashValues() { + return {0x6a, 0x09, 0xe6, 0x67, 0xbb, 0x67, 0xae, 0x85, 0x3c, 0x6e, 0xf3, + 0x72, 0xa5, 0x4f, 0xf5, 0x3a, 0x51, 0x0e, 0x52, 0x7f, 0x9b, 0x05, + 0x68, 0x8c, 0x1f, 0x83, 0xd9, 0xab, 0x5b, 0xe0, 0xcd, 0x19}; + } + + static std::vector PrepareSha256Input(ByteContainerView input) { + constexpr size_t kSha256FixPadSize = 1; // in bytes + constexpr size_t kSha256MessageBlockSize = 64; // in bytes + + uint64_t input_size = input.size(); + constexpr auto kInitSha256Bytes = GetSha256InitialHashValues(); + uint64_t zero_padding_size = + (input_size + kSha256FixPadSize) % kSha256MessageBlockSize == 0 + ? 0 + : kSha256MessageBlockSize - + (input_size + kSha256FixPadSize) % kSha256MessageBlockSize; + uint64_t message_size = input_size + kSha256FixPadSize + zero_padding_size; + uint64_t result_size = message_size + kInitSha256Bytes.size(); + + YACL_ENFORCE(message_size % kSha256MessageBlockSize == 0); + + // Declare the resut byte-vector + std::vector result(result_size); + + // original input message + size_t offset = kInitSha256Bytes.size(); + std::memcpy(result.data() + offset, input.data(), input_size); + + // additional padding (as a mark) + offset = kInitSha256Bytes.size() + input_size; + result[offset] = 0x80; + + // zero padding (result vector has zero initialization) + // ... should doing nothing ... + + // the last 64 bits should be the byte length of input message + offset = kInitSha256Bytes.size() + input_size + kSha256FixPadSize; + std::memcpy(result.data() + offset, &input_size, sizeof(uint64_t)); + + // initial hash values + std::memcpy(result.data(), kInitSha256Bytes.data(), kInitSha256Bytes.size()); + + return result; + } + // NOTE: For AES-128 the wire orders are in the reverse order as used in // the examples given in our earlier `Bristol Format', thus bit 0 becomes bit // 127 etc, for key, plaintext and message. @@ -149,10 +196,10 @@ class BuiltinBFCircuit { // NOTE: sha256 needs two inputs, a 512 bit buffer, and a 256 bit previous // digest value // - // static std::string Sha256Path() { - // return fmt::format("{}/yacl/io/circuit/data/sha256.txt", - // std::filesystem::current_path().string()); - // } + static std::string Sha256Path() { + return fmt::format("{}/yacl/io/circuit/data/sha256.txt", + std::filesystem::current_path().string()); + } }; } // namespace yacl::io diff --git a/yacl/kernel/algorithms/BUILD.bazel b/yacl/kernel/algorithms/BUILD.bazel index 175a995..e649582 100644 --- a/yacl/kernel/algorithms/BUILD.bazel +++ b/yacl/kernel/algorithms/BUILD.bazel @@ -219,6 +219,7 @@ yacl_cc_library( "//yacl/crypto/hash:hash_utils", "//yacl/crypto/rand", "//yacl/crypto/tools:common", + "//yacl/crypto/tools:cuckoo_index", "//yacl/crypto/tools:prg", "//yacl/crypto/tools:rp", "//yacl/kernel/algorithms:gywz_ote", @@ -228,7 +229,6 @@ yacl_cc_library( "//yacl/link", "//yacl/math:gadget", "//yacl/math/galois_field:gf_intrinsic", - "//yacl/utils:cuckoo_index", ], ) diff --git a/yacl/kernel/algorithms/ferret_ote.cc b/yacl/kernel/algorithms/ferret_ote.cc index 7f6535f..af46fd7 100644 --- a/yacl/kernel/algorithms/ferret_ote.cc +++ b/yacl/kernel/algorithms/ferret_ote.cc @@ -20,7 +20,7 @@ #include #include "yacl/base/aligned_vector.h" -#include "yacl/utils/cuckoo_index.h" +#include "yacl/crypto/tools/cuckoo_index.h" #include "yacl/utils/serialize.h" namespace yacl::crypto { diff --git a/yacl/utils/BUILD.bazel b/yacl/utils/BUILD.bazel index e0b3ab4..c203487 100644 --- a/yacl/utils/BUILD.bazel +++ b/yacl/utils/BUILD.bazel @@ -16,28 +16,6 @@ load("//bazel:yacl.bzl", "OMP_CFLAGS", "OMP_DEPS", "OMP_LINKFLAGS", "yacl_cc_bin package(default_visibility = ["//visibility:public"]) -yacl_cc_library( - name = "circuit_executor", - srcs = ["circuit_executor.cc"], - hdrs = ["circuit_executor.h"], - deps = [ - "//yacl/base:dynamic_bitset", - "//yacl/base:int128", - "//yacl/io/circuit:bristol_fashion", - ], -) - -yacl_cc_test( - name = "circuit_executor_test", - srcs = ["circuit_executor_test.cc"], - data = ["//yacl/io/circuit:circuit_data"], - deps = [ - "circuit_executor", - "//yacl/crypto/block_cipher:symmetric_crypto", - "//yacl/crypto/rand", - ], -) - yacl_cc_library( name = "hamming", hdrs = ["hamming.h"], @@ -210,27 +188,6 @@ yacl_cc_binary( ], ) -yacl_cc_library( - name = "cuckoo_index", - srcs = ["cuckoo_index.cc"], - hdrs = ["cuckoo_index.h"], - linkopts = ["-lm"], - deps = [ - "//yacl/base:exception", - "//yacl/base:int128", - "@com_google_absl//absl/types:span", - ], -) - -yacl_cc_test( - name = "cuckoo_index_test", - srcs = ["cuckoo_index_test.cc"], - deps = [ - ":cuckoo_index", - "//yacl/crypto/rand", - ], -) - yacl_cc_library( name = "platform_utils", srcs = ["platform_utils.cc"], diff --git a/yacl/utils/circuit_executor.h b/yacl/utils/circuit_executor.h deleted file mode 100644 index fe824cf..0000000 --- a/yacl/utils/circuit_executor.h +++ /dev/null @@ -1,50 +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. - -#pragma once - -#include - -#include "yacl/base/dynamic_bitset.h" -#include "yacl/io/circuit/bristol_fashion.h" - -namespace yacl { - -// plaintext protocol that executes everything without link - -template -class PlainExecutor { - public: - // Constructor - explicit PlainExecutor() = default; - - // Load circuit from file (local operation) - void LoadCircuitFile(const std::string &path); - - // Setup the input wire (local operation) - void SetupInputs(absl::Span inputs); - - // Execute the circuit - void Exec(); - - // Finalize and get the result - void Finalize(absl::Span outputs); - - private: - // NOTE: please make sure you use the correct order of wires - dynamic_bitset wires_; // shares - std::shared_ptr circ_; // bristol fashion circuit -}; - -} // namespace yacl From 2f3a8d32f978965508a572f26d0d5b29d7c1212e Mon Sep 17 00:00:00 2001 From: Jamie Cui Date: Fri, 22 Nov 2024 19:06:16 +0800 Subject: [PATCH 2/6] feat: now sha256 works --- yacl/engine/plaintext/executor.h | 47 +++++++++++----- yacl/engine/plaintext/executor_test.cc | 24 ++++---- yacl/io/circuit/BUILD.bazel | 1 + yacl/io/circuit/bristol_fashion.h | 77 +++++++++++++++++--------- 4 files changed, 98 insertions(+), 51 deletions(-) diff --git a/yacl/engine/plaintext/executor.h b/yacl/engine/plaintext/executor.h index 3028151..9d71e23 100644 --- a/yacl/engine/plaintext/executor.h +++ b/yacl/engine/plaintext/executor.h @@ -27,6 +27,8 @@ namespace yacl::engine { class PlainExecutor { public: + using BlockType = uint8_t; + // Constructor explicit PlainExecutor() = default; @@ -38,7 +40,7 @@ class PlainExecutor { void SetupInputs(absl::Span inputs) { YACL_ENFORCE(inputs.size() == circ_->niv); - dynamic_bitset input_wires; + dynamic_bitset input_wires; input_wires.resize(sizeof(T) * 8 * inputs.size()); std::memcpy(input_wires.data(), inputs.data(), inputs.size() * sizeof(T)); wires_.append(input_wires); @@ -46,9 +48,13 @@ class PlainExecutor { } // Setup the input wire + // + // NOTE internally this function simply copies the memory of bytes to internal + // dynamic_bitset void SetupInputBytes(ByteContainerView bytes) { - wires_.resize(circ_->nw); + wires_.resize(bytes.size() * 8); std::memcpy(wires_.data(), bytes.data(), bytes.size()); + wires_.resize(circ_->nw); } // Execute the circuit @@ -60,7 +66,7 @@ class PlainExecutor { YACL_ENFORCE(outputs.size() >= circ_->nov); size_t index = wires_.size(); for (size_t i = 0; i < circ_->nov; ++i) { - dynamic_bitset result(circ_->now[i]); + dynamic_bitset result(circ_->now[i]); for (size_t j = 0; j < circ_->now[i]; ++j) { result[j] = wires_[index - circ_->now[i] + j]; } @@ -76,23 +82,38 @@ class PlainExecutor { total_out_bitnum += circ_->now[i]; } - // Make sure that the circuit output wire is full bytes - YACL_ENFORCE(total_out_bitnum % 8 == 0); + // // Make sure that the circuit output wire is full bytes + // YACL_ENFORCE(total_out_bitnum % 8 == 0); + + // const size_t wire_size = wires_.size(); + // dynamic_bitset result(total_out_bitnum); + // for (size_t i = 0; i < total_out_bitnum; ++i) { + // result[total_out_bitnum - i - 1] = wires_[wire_size - i - 1]; + // } + // YACL_ENFORCE(result.size() == total_out_bitnum); + // std::vector out(total_out_bitnum / 8); + // std::memcpy(out.data(), result.data(), out.size()); + // SPDLOG_INFO(result.to_string()); + // return out; - const size_t wire_size = wires_.size(); - dynamic_bitset result(total_out_bitnum); - for (size_t i = 0; i < total_out_bitnum; ++i) { - result[total_out_bitnum - i - 1] = wires_[wire_size - i - 1]; - } - YACL_ENFORCE(result.size() == total_out_bitnum); std::vector out(total_out_bitnum / 8); - std::memcpy(out.data(), result.data(), out.size()); + + size_t index = wires_.size(); + for (size_t i = 0; i < 32; ++i) { + dynamic_bitset result(8); + for (size_t j = 0; j < 8; ++j) { + result[j] = wires_[index - 8 + j]; + } + out[32 - i - 1] = *(uint8_t *)result.data(); + index -= 8; + } + std::reverse(out.begin(), out.end()); return out; } private: // NOTE: please make sure you use the correct order of wires - dynamic_bitset wires_; // shares + dynamic_bitset wires_; // shares std::shared_ptr circ_; // bristol fashion circuit }; diff --git a/yacl/engine/plaintext/executor_test.cc b/yacl/engine/plaintext/executor_test.cc index f51b6d9..c7deac5 100644 --- a/yacl/engine/plaintext/executor_test.cc +++ b/yacl/engine/plaintext/executor_test.cc @@ -211,21 +211,23 @@ TEST(CryptoTest, Sha256Test) { /* GIVEN */ auto input = crypto::FastRandBytes(crypto::RandLtN(10)); - std::string temp = "1"; - SPDLOG_INFO(absl::BytesToHexString( - ByteContainerView(io::BuiltinBFCircuit::PrepareSha256Input(temp)))); + // std::array temp = {'a', 'b', 'c'}; + // std::string temp = "1"; + std::array message = {'1'}; + auto in_buf = io::BuiltinBFCircuit::PrepareSha256Input(message); /* WHEN */ - // PlainExecutor exec; - // exec.LoadCircuitFile(io::BuiltinBFCircuit::Sha256Path()); - // exec.SetupInputBytes(io::BuiltinBFCircuit::PrepareSha256Input(input)); - // exec.Exec(); - // auto result = exec.FinalizeBytes(); + PlainExecutor exec; + exec.LoadCircuitFile(io::BuiltinBFCircuit::Sha256Path()); + exec.SetupInputBytes(in_buf); + exec.Exec(); + auto result = exec.FinalizeBytes(); /* THEN */ - // auto compare = crypto::Sha256Hash().Update(input).CumulativeHash(); - // SPDLOG_INFO(absl::BytesToHexString(ByteContainerView(result))); - // SPDLOG_INFO(absl::BytesToHexString(ByteContainerView(compare))); + auto compare = crypto::Sha256Hash().Update(message).CumulativeHash(); + SPDLOG_INFO(absl::BytesToHexString(ByteContainerView(result))); + SPDLOG_INFO(absl::BytesToHexString(ByteContainerView(compare))); + EXPECT_EQ(compare.size(), result.size()); } } // namespace yacl::engine diff --git a/yacl/io/circuit/BUILD.bazel b/yacl/io/circuit/BUILD.bazel index 707f93c..71f3977 100644 --- a/yacl/io/circuit/BUILD.bazel +++ b/yacl/io/circuit/BUILD.bazel @@ -28,6 +28,7 @@ yacl_cc_library( deps = [ "//yacl/io/stream:file_io", "//yacl/link:context", + "//yacl/utils/spi:type_traits", ], ) diff --git a/yacl/io/circuit/bristol_fashion.h b/yacl/io/circuit/bristol_fashion.h index 2748fed..5561541 100644 --- a/yacl/io/circuit/bristol_fashion.h +++ b/yacl/io/circuit/bristol_fashion.h @@ -21,12 +21,14 @@ #include #include +#include "absl/strings/escaping.h" #include "spdlog/spdlog.h" #include "yacl/base/byte_container_view.h" #include "yacl/base/exception.h" #include "yacl/io/stream/file_io.h" #include "yacl/io/stream/interface.h" +#include "yacl/utils/spi/type_traits.h" namespace yacl::io { @@ -137,48 +139,59 @@ class BuiltinBFCircuit { std::filesystem::current_path().string()); } - constexpr static std::array GetSha256InitialHashValues() { - return {0x6a, 0x09, 0xe6, 0x67, 0xbb, 0x67, 0xae, 0x85, 0x3c, 0x6e, 0xf3, - 0x72, 0xa5, 0x4f, 0xf5, 0x3a, 0x51, 0x0e, 0x52, 0x7f, 0x9b, 0x05, - 0x68, 0x8c, 0x1f, 0x83, 0xd9, 0xab, 0x5b, 0xe0, 0xcd, 0x19}; - } - + // Prepare (append & tweak) the input sha256 message before fed to the sha256 + // bristol circuit. + // + // For more details, please check: + // https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf + // + // NOTE since we are using dynamic_bitset for bristol format circuit + // representation, the actual bit operation here is slightly different from + // the standards. static std::vector PrepareSha256Input(ByteContainerView input) { - constexpr size_t kSha256FixPadSize = 1; // in bytes - constexpr size_t kSha256MessageBlockSize = 64; // in bytes + constexpr size_t kFixPadSize = 1; // in bytes + constexpr size_t kMsgLenSize = sizeof(uint64_t); // in bytes + constexpr size_t kMsgBlockSize = 64; // in bytes + auto kInitSha256Bytes = GetSha256InitialHashValues(); - uint64_t input_size = input.size(); - constexpr auto kInitSha256Bytes = GetSha256InitialHashValues(); + uint64_t input_size = input.size(); // in bits uint64_t zero_padding_size = - (input_size + kSha256FixPadSize) % kSha256MessageBlockSize == 0 + (input_size + kFixPadSize + kMsgLenSize) % kMsgBlockSize == 0 ? 0 - : kSha256MessageBlockSize - - (input_size + kSha256FixPadSize) % kSha256MessageBlockSize; - uint64_t message_size = input_size + kSha256FixPadSize + zero_padding_size; + : kMsgBlockSize - + (input_size + kFixPadSize + kMsgLenSize) % kMsgBlockSize; + uint64_t message_size = + input_size + kFixPadSize + zero_padding_size + kMsgLenSize; uint64_t result_size = message_size + kInitSha256Bytes.size(); - YACL_ENFORCE(message_size % kSha256MessageBlockSize == 0); + YACL_ENFORCE(message_size % kMsgBlockSize == 0); - // Declare the resut byte-vector + // Declare the result byte-vector + size_t offset = 0; std::vector result(result_size); - // original input message - size_t offset = kInitSha256Bytes.size(); - std::memcpy(result.data() + offset, input.data(), input_size); - - // additional padding (as a mark) - offset = kInitSha256Bytes.size() + input_size; - result[offset] = 0x80; + // the next 64 bits should be the byte length of input message + uint64_t input_bitnum = input_size * 8; // in bytes + std::memcpy(result.data() + offset, &input_bitnum, sizeof(input_bitnum)); + offset += sizeof(uint64_t); // zero padding (result vector has zero initialization) // ... should doing nothing ... + offset += zero_padding_size; - // the last 64 bits should be the byte length of input message - offset = kInitSha256Bytes.size() + input_size + kSha256FixPadSize; - std::memcpy(result.data() + offset, &input_size, sizeof(uint64_t)); + // additional padding bit-'1' (as a mark) + result[offset] = 0x80; + offset += kFixPadSize; + + // original input message + // auto input_reverse = ReverseBytes(absl::MakeSpan(input)); // copy here + std::memcpy(result.data() + offset, input.data(), input_size); + offset += input_size; // initial hash values - std::memcpy(result.data(), kInitSha256Bytes.data(), kInitSha256Bytes.size()); + std::memcpy(result.data() + offset, kInitSha256Bytes.data(), + kInitSha256Bytes.size()); + offset += kInitSha256Bytes.size(); return result; } @@ -200,6 +213,16 @@ class BuiltinBFCircuit { return fmt::format("{}/yacl/io/circuit/data/sha256.txt", std::filesystem::current_path().string()); } + + + static std::array GetSha256InitialHashValues() { + std::array standard_init_array = { + 0x6a, 0x09, 0xe6, 0x67, 0xbb, 0x67, 0xae, 0x85, 0x3c, 0x6e, 0xf3, + 0x72, 0xa5, 0x4f, 0xf5, 0x3a, 0x51, 0x0e, 0x52, 0x7f, 0x9b, 0x05, + 0x68, 0x8c, 0x1f, 0x83, 0xd9, 0xab, 0x5b, 0xe0, 0xcd, 0x19}; + std::reverse(standard_init_array.begin(), standard_init_array.end()); + return standard_init_array; + } }; } // namespace yacl::io From d44abc1dcfedba400713951646c0fd3a475e5f47 Mon Sep 17 00:00:00 2001 From: Jamie Cui Date: Fri, 22 Nov 2024 19:25:49 +0800 Subject: [PATCH 3/6] fix: sha256 circuit with multi-bytes input --- yacl/engine/plaintext/executor.h | 13 ------------- yacl/engine/plaintext/executor_test.cc | 8 ++------ yacl/io/circuit/bristol_fashion.h | 5 +++-- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/yacl/engine/plaintext/executor.h b/yacl/engine/plaintext/executor.h index 9d71e23..3e4aae8 100644 --- a/yacl/engine/plaintext/executor.h +++ b/yacl/engine/plaintext/executor.h @@ -82,19 +82,6 @@ class PlainExecutor { total_out_bitnum += circ_->now[i]; } - // // Make sure that the circuit output wire is full bytes - // YACL_ENFORCE(total_out_bitnum % 8 == 0); - - // const size_t wire_size = wires_.size(); - // dynamic_bitset result(total_out_bitnum); - // for (size_t i = 0; i < total_out_bitnum; ++i) { - // result[total_out_bitnum - i - 1] = wires_[wire_size - i - 1]; - // } - // YACL_ENFORCE(result.size() == total_out_bitnum); - // std::vector out(total_out_bitnum / 8); - // std::memcpy(out.data(), result.data(), out.size()); - // SPDLOG_INFO(result.to_string()); - // return out; std::vector out(total_out_bitnum / 8); diff --git a/yacl/engine/plaintext/executor_test.cc b/yacl/engine/plaintext/executor_test.cc index c7deac5..0fa13ff 100644 --- a/yacl/engine/plaintext/executor_test.cc +++ b/yacl/engine/plaintext/executor_test.cc @@ -210,10 +210,7 @@ TEST(CryptoTest, Aes128Test) { TEST(CryptoTest, Sha256Test) { /* GIVEN */ auto input = crypto::FastRandBytes(crypto::RandLtN(10)); - - // std::array temp = {'a', 'b', 'c'}; - // std::string temp = "1"; - std::array message = {'1'}; + auto message = crypto::FastRandBytes(10); auto in_buf = io::BuiltinBFCircuit::PrepareSha256Input(message); /* WHEN */ @@ -225,9 +222,8 @@ TEST(CryptoTest, Sha256Test) { /* THEN */ auto compare = crypto::Sha256Hash().Update(message).CumulativeHash(); - SPDLOG_INFO(absl::BytesToHexString(ByteContainerView(result))); - SPDLOG_INFO(absl::BytesToHexString(ByteContainerView(compare))); EXPECT_EQ(compare.size(), result.size()); + EXPECT_EQ(memcmp(compare.data(), result.data(), compare.size()), 0); } } // namespace yacl::engine diff --git a/yacl/io/circuit/bristol_fashion.h b/yacl/io/circuit/bristol_fashion.h index 5561541..958d1a9 100644 --- a/yacl/io/circuit/bristol_fashion.h +++ b/yacl/io/circuit/bristol_fashion.h @@ -185,7 +185,9 @@ class BuiltinBFCircuit { // original input message // auto input_reverse = ReverseBytes(absl::MakeSpan(input)); // copy here - std::memcpy(result.data() + offset, input.data(), input_size); + auto input_reverse = std::vector(input.begin(), input.end()); + std::reverse(input_reverse.begin(), input_reverse.end()); + std::memcpy(result.data() + offset, input_reverse.data(), input_size); offset += input_size; // initial hash values @@ -214,7 +216,6 @@ class BuiltinBFCircuit { std::filesystem::current_path().string()); } - static std::array GetSha256InitialHashValues() { std::array standard_init_array = { 0x6a, 0x09, 0xe6, 0x67, 0xbb, 0x67, 0xae, 0x85, 0x3c, 0x6e, 0xf3, From 01c76cf0b2d0bcd58b5755c809a3834b96dc9ffe Mon Sep 17 00:00:00 2001 From: Jamie Cui Date: Fri, 22 Nov 2024 19:28:12 +0800 Subject: [PATCH 4/6] fix(engine): sha256 circuit --- yacl/engine/plaintext/executor_test.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/yacl/engine/plaintext/executor_test.cc b/yacl/engine/plaintext/executor_test.cc index 0fa13ff..72ed0c0 100644 --- a/yacl/engine/plaintext/executor_test.cc +++ b/yacl/engine/plaintext/executor_test.cc @@ -209,8 +209,7 @@ TEST(CryptoTest, Aes128Test) { TEST(CryptoTest, Sha256Test) { /* GIVEN */ - auto input = crypto::FastRandBytes(crypto::RandLtN(10)); - auto message = crypto::FastRandBytes(10); + auto message = crypto::FastRandBytes(crypto::RandLtN(10)); auto in_buf = io::BuiltinBFCircuit::PrepareSha256Input(message); /* WHEN */ From 4004172111dfb9592a15f1c22f96bc9cfcb939f7 Mon Sep 17 00:00:00 2001 From: Jamie Cui Date: Fri, 22 Nov 2024 19:40:16 +0800 Subject: [PATCH 5/6] fix(ci): cleanup format and license --- .licenserc.yaml | 3 +++ yacl/crypto/aead/BUILD.bazel | 2 +- yacl/crypto/block_cipher/BUILD.bazel | 2 +- yacl/crypto/hash/BUILD.bazel | 2 +- yacl/crypto/pke/BUILD.bazel | 4 ++-- yacl/crypto/rand/BUILD.bazel | 2 +- yacl/crypto/rand/drbg/BUILD.bazel | 6 +++--- yacl/crypto/tools/BUILD.bazel | 2 +- yacl/engine/plaintext/BUILD.bazel | 2 +- yacl/engine/plaintext/executor.cc | 2 +- yacl/engine/plaintext/executor.h | 14 +++++++++++++- yacl/engine/plaintext/executor_test.cc | 3 +-- yacl/kernel/algorithms/BUILD.bazel | 22 +++++++++++----------- 13 files changed, 40 insertions(+), 26 deletions(-) diff --git a/.licenserc.yaml b/.licenserc.yaml index 84362c9..01db3a1 100644 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -46,6 +46,9 @@ header: # <1> - 'yacl/crypto/aes/aes_opt.h' - 'yacl/io/circuit/data/**.txt' - 'docs/requirements.txt' + - '.whitesource' + - 'MODULE.bazel' + - 'MODULE.bazel.lock' comment: never # <9> diff --git a/yacl/crypto/aead/BUILD.bazel b/yacl/crypto/aead/BUILD.bazel index 6a27d9d..55ed906 100644 --- a/yacl/crypto/aead/BUILD.bazel +++ b/yacl/crypto/aead/BUILD.bazel @@ -21,8 +21,8 @@ yacl_cc_library( srcs = ["all_gcm.cc"], hdrs = ["all_gcm.h"], deps = [ - "//yacl/base:secparam", "//yacl/base:int128", + "//yacl/base:secparam", "//yacl/crypto:key_utils", ], ) diff --git a/yacl/crypto/block_cipher/BUILD.bazel b/yacl/crypto/block_cipher/BUILD.bazel index e370029..35f9752 100644 --- a/yacl/crypto/block_cipher/BUILD.bazel +++ b/yacl/crypto/block_cipher/BUILD.bazel @@ -26,8 +26,8 @@ yacl_cc_library( ], copts = AES_COPT_FLAGS, deps = [ - "//yacl/base:secparam", "//yacl/base:int128", + "//yacl/base:secparam", "//yacl/crypto:ossl_wrappers", ], ) diff --git a/yacl/crypto/hash/BUILD.bazel b/yacl/crypto/hash/BUILD.bazel index 9ee3f42..7b071da 100644 --- a/yacl/crypto/hash/BUILD.bazel +++ b/yacl/crypto/hash/BUILD.bazel @@ -69,8 +69,8 @@ yacl_cc_library( name = "hash_interface", srcs = ["hash_interface.h"], deps = [ - "//yacl/base:secparam", "//yacl/base:byte_container_view", + "//yacl/base:secparam", "//yacl/crypto:ossl_wrappers", ], ) diff --git a/yacl/crypto/pke/BUILD.bazel b/yacl/crypto/pke/BUILD.bazel index ab831a1..bb41e8e 100644 --- a/yacl/crypto/pke/BUILD.bazel +++ b/yacl/crypto/pke/BUILD.bazel @@ -30,8 +30,8 @@ yacl_cc_library( hdrs = ["sm2_enc.h"], deps = [ ":pke_interface", - "//yacl/base:secparam", "//yacl/base:exception", + "//yacl/base:secparam", "//yacl/crypto:key_utils", ], ) @@ -50,8 +50,8 @@ yacl_cc_library( hdrs = ["rsa_enc.h"], deps = [ ":pke_interface", - "//yacl/base:secparam", "//yacl/base:exception", + "//yacl/base:secparam", "//yacl/crypto:key_utils", ], ) diff --git a/yacl/crypto/rand/BUILD.bazel b/yacl/crypto/rand/BUILD.bazel index 005ad00..6d9dbcb 100644 --- a/yacl/crypto/rand/BUILD.bazel +++ b/yacl/crypto/rand/BUILD.bazel @@ -21,10 +21,10 @@ yacl_cc_library( srcs = ["rand.cc"], hdrs = ["rand.h"], deps = [ - "//yacl/base:secparam", "//yacl/base:dynamic_bitset", "//yacl/base:exception", "//yacl/base:int128", + "//yacl/base:secparam", "//yacl/crypto/rand/drbg", "//yacl/crypto/tools:prg", "//yacl/math/mpint", diff --git a/yacl/crypto/rand/drbg/BUILD.bazel b/yacl/crypto/rand/drbg/BUILD.bazel index e657e5a..39fc203 100644 --- a/yacl/crypto/rand/drbg/BUILD.bazel +++ b/yacl/crypto/rand/drbg/BUILD.bazel @@ -32,9 +32,9 @@ yacl_cc_library( ], visibility = ["//visibility:private"], deps = [ - "//yacl/base:secparam", "//yacl/base:byte_container_view", "//yacl/base:int128", + "//yacl/base:secparam", "//yacl/crypto/rand/entropy_source", "//yacl/utils/spi", ], @@ -56,8 +56,8 @@ yacl_cc_library( deps = [ ":spi", "//yacl/crypto:ossl_wrappers", - "//yacl/ossl_provider:helper", # helper "//yacl/crypto/rand/entropy_source", + "//yacl/ossl_provider:helper", # helper ], alwayslink = 1, ) @@ -80,8 +80,8 @@ yacl_cc_library( "//yacl/crypto:ossl_wrappers", "//yacl/crypto/block_cipher:symmetric_crypto", "//yacl/crypto/hash:hash_utils", - "//yacl/ossl_provider:helper", # helper "//yacl/crypto/rand/entropy_source", + "//yacl/ossl_provider:helper", # helper ], alwayslink = 1, ) diff --git a/yacl/crypto/tools/BUILD.bazel b/yacl/crypto/tools/BUILD.bazel index ff7bfa5..86d8a02 100644 --- a/yacl/crypto/tools/BUILD.bazel +++ b/yacl/crypto/tools/BUILD.bazel @@ -31,8 +31,8 @@ yacl_cc_library( srcs = ["prg.cc"], hdrs = ["prg.h"], deps = [ - "//yacl/base:secparam", "//yacl/base:dynamic_bitset", + "//yacl/base:secparam", "//yacl/crypto/block_cipher:symmetric_crypto", "//yacl/math/mpint", ], diff --git a/yacl/engine/plaintext/BUILD.bazel b/yacl/engine/plaintext/BUILD.bazel index 30d371b..17a3527 100644 --- a/yacl/engine/plaintext/BUILD.bazel +++ b/yacl/engine/plaintext/BUILD.bazel @@ -1,4 +1,4 @@ -# Copyright 2022 Ant Group Co., Ltd. +# Copyright 2024 Jamie Cui and 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. diff --git a/yacl/engine/plaintext/executor.cc b/yacl/engine/plaintext/executor.cc index 1abf29e..eb9959d 100644 --- a/yacl/engine/plaintext/executor.cc +++ b/yacl/engine/plaintext/executor.cc @@ -1,4 +1,4 @@ -// Copyright 2024 Ant Group Co., Ltd. +// Copyright 2024 Jamie Cui and 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. diff --git a/yacl/engine/plaintext/executor.h b/yacl/engine/plaintext/executor.h index 3e4aae8..5250f05 100644 --- a/yacl/engine/plaintext/executor.h +++ b/yacl/engine/plaintext/executor.h @@ -1,4 +1,16 @@ -// Copyright 2024 Ant Group Co., Ltd. +// Copyright 2024 Jamie Cui and 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. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/yacl/engine/plaintext/executor_test.cc b/yacl/engine/plaintext/executor_test.cc index 72ed0c0..42e1e1b 100644 --- a/yacl/engine/plaintext/executor_test.cc +++ b/yacl/engine/plaintext/executor_test.cc @@ -1,5 +1,4 @@ - -// Copyright 2024 Ant Group Co., Ltd. +// Copyright 2024 Jamie Cui and 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. diff --git a/yacl/kernel/algorithms/BUILD.bazel b/yacl/kernel/algorithms/BUILD.bazel index e649582..531bd11 100644 --- a/yacl/kernel/algorithms/BUILD.bazel +++ b/yacl/kernel/algorithms/BUILD.bazel @@ -28,8 +28,8 @@ yacl_cc_library( hdrs = ["portable_ot_interface.h"], deps = [ ":base_ot_interface", - "//yacl/base:secparam", "//yacl/base:exception", + "//yacl/base:secparam", "//yacl/crypto/tools:ro", "//yacl/link", "@simplest_ot//:simplest_ot_portable", @@ -46,8 +46,8 @@ yacl_cc_library( ], deps = [ ":base_ot_interface", - "//yacl/base:secparam", "//yacl/base:exception", + "//yacl/base:secparam", "//yacl/crypto/tools:ro", "//yacl/link", "//yacl/math:gadget", @@ -61,8 +61,8 @@ yacl_cc_library( srcs = ["base_ot.cc"], hdrs = ["base_ot.h"], deps = [ - "//yacl/base:secparam", "//yacl/base:exception", + "//yacl/base:secparam", "//yacl/kernel/type:ot_store_utils", "//yacl/link", "@com_google_absl//absl/types:span", @@ -117,9 +117,9 @@ yacl_cc_library( hdrs = ["kkrt_ote.h"], copts = AES_COPT_FLAGS, deps = [ - "//yacl/base:secparam", "//yacl/base:exception", "//yacl/base:int128", + "//yacl/base:secparam", "//yacl/crypto/aes:aes_opt", "//yacl/crypto/hash:hash_utils", "//yacl/crypto/rand", @@ -178,8 +178,8 @@ yacl_cc_library( hdrs = ["gywz_ote.h"], copts = AES_COPT_FLAGS, deps = [ - "//yacl/base:secparam", "//yacl/base:aligned_vector", + "//yacl/base:secparam", "//yacl/crypto/aes:aes_opt", "//yacl/crypto/rand", "//yacl/crypto/tools:crhash", @@ -214,8 +214,8 @@ yacl_cc_library( ], copts = AES_COPT_FLAGS, deps = [ - "//yacl/base:secparam", "//yacl/base:exception", + "//yacl/base:secparam", "//yacl/crypto/hash:hash_utils", "//yacl/crypto/rand", "//yacl/crypto/tools:common", @@ -248,10 +248,10 @@ yacl_cc_library( hdrs = ["kos_ote.h"], copts = AES_COPT_FLAGS, deps = [ - "//yacl/base:secparam", "//yacl/base:dynamic_bitset", "//yacl/base:exception", "//yacl/base:int128", + "//yacl/base:secparam", "//yacl/crypto/rand", "//yacl/crypto/tools:common", "//yacl/crypto/tools:crhash", @@ -316,10 +316,10 @@ yacl_cc_library( hdrs = ["mpfss.h"], copts = AES_COPT_FLAGS, deps = [ - "//yacl/base:secparam", "//yacl/base:aligned_vector", "//yacl/base:dynamic_bitset", "//yacl/base:int128", + "//yacl/base:secparam", "//yacl/crypto/rand", "//yacl/crypto/tools:crhash", "//yacl/kernel/algorithms:gywz_ote", @@ -348,10 +348,10 @@ yacl_cc_library( hdrs = ["base_vole.h"], copts = AES_COPT_FLAGS, deps = [ - "//yacl/base:secparam", "//yacl/base:aligned_vector", "//yacl/base:dynamic_bitset", "//yacl/base:int128", + "//yacl/base:secparam", "//yacl/crypto/rand", "//yacl/kernel/algorithms:softspoken_ote", "//yacl/kernel/type:ot_store_utils", @@ -379,10 +379,10 @@ yacl_cc_library( hdrs = ["mp_vole.h"], copts = AES_COPT_FLAGS, deps = [ - "//yacl/base:secparam", "//yacl/base:aligned_vector", "//yacl/base:dynamic_bitset", "//yacl/base:int128", + "//yacl/base:secparam", "//yacl/crypto/hash:hash_utils", "//yacl/crypto/rand", "//yacl/crypto/tools:common", @@ -415,10 +415,10 @@ yacl_cc_library( deps = [ ":base_vole", ":mp_vole", - "//yacl/base:secparam", "//yacl/base:aligned_vector", "//yacl/base:dynamic_bitset", "//yacl/base:int128", + "//yacl/base:secparam", "//yacl/kernel/algorithms:softspoken_ote", "//yacl/kernel/code:code_interface", "//yacl/kernel/code:ea_code", From 430f5f22d00551e7898a3d37f7c2bceb1e79c3e8 Mon Sep 17 00:00:00 2001 From: Jamie Cui Date: Fri, 22 Nov 2024 19:41:58 +0800 Subject: [PATCH 6/6] fix(ci): add .keep to license ignore --- .licenserc.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.licenserc.yaml b/.licenserc.yaml index 01db3a1..2d405b6 100644 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -49,6 +49,7 @@ header: # <1> - '.whitesource' - 'MODULE.bazel' - 'MODULE.bazel.lock' + - 'examples/cmake-project/.keep' comment: never # <9>