Skip to content

Commit

Permalink
repo-sync-2023-09-15T09:12:19+0800 (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinxc authored Sep 15, 2023
1 parent 34f812a commit f05b8c7
Show file tree
Hide file tree
Showing 30 changed files with 278 additions and 134 deletions.
26 changes: 2 additions & 24 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,10 @@ build:macos --host_copt=-Wa,--noexecstack

# platform specific config
# Bazel will automatic pick platform config since we have enable_platform_specific_config set

build:macos --features=-supports_dynamic_linker
build:macos --cxxopt -Wno-deprecated-enum-enum-conversion
build:macos --cxxopt -Wno-deprecated-anon-enum-enum-conversion

build:asan --strip=never
build:asan --copt -fno-sanitize-recover=all
build:asan --copt -fsanitize=address
build:asan --copt -Og
build:asan --copt -g
build:asan --copt -fno-omit-frame-pointer
build:asan --linkopt -fsanitize=address

build:ubsan --strip=never
build:ubsan --copt -fno-sanitize-recover=all
build:ubsan --copt -fsanitize=undefined
build:ubsan --copt -Og
build:ubsan --copt -g
build:ubsan --copt -fno-omit-frame-pointer
build:ubsan --linkopt -fsanitize=undefined

# see https://github.com/bazelbuild/bazel/issues/6932, _FORTIFY_SOURCE=1 is enabled by default
# on Mac OS, which breaks ASAN. bazel has officially added sanitizer support to Apple Platforms,
# see commit: https://github.com/bazelbuild/bazel/commit/6ab161e2d5b8ad9cf191be1b362cd4619f3bb956
build:macos-asan --features=asan
build:macos-ubsan --features=ubsan
build:asan --features=asan
build:ubsan --features=ubsan

test --keep_going
test --test_output=errors
Expand Down
46 changes: 46 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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.

# Install hooks to run automatically on git commit:
# >> pre-commit install
#
# More helps: https://pre-commit.com/

repos:
# Built-in hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.4.0"
hooks:
- id: trailing-whitespace

# buildifier
- repo: local
hooks:
- id: buildifier
name: buildifier
entry: buildifier # -mode check
language: system
files: '^(.*/)?(BUILD\.bazel|BUILD|WORKSPACE|WORKSPACE\.bazel|WORKSPACE\.bzlmod|MODULE\.bazel)$|\.BUILD$|\.bzl$'

# clang-format
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: "v16.0.6"
hooks:
- id: clang-format

# Check for spelling
- repo: https://github.com/codespell-project/codespell
rev: "v2.2.5"
hooks:
- id: codespell
24 changes: 23 additions & 1 deletion bazel/patches/ippcp.patch
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,26 @@ index ea1641d..f98fc2d 100644
# Optimization level = 3, no-debug definition (turns off asserts)
set(CMAKE_C_FLAGS_RELEASE " -O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")


diff --git a/sources/cmake/linux/Clang9.0.0.cmake b/sources/cmake/linux/Clang9.0.0.cmake
index 0015431..f93411c 100644
--- a/sources/cmake/linux/Clang9.0.0.cmake
+++ b/sources/cmake/linux/Clang9.0.0.cmake
@@ -79,7 +79,7 @@ endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcf-protection=full")

# Security flag that adds compile-time and run-time checks
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")

if(NOT NONPIC_LIB)
# Position Independent Execution (PIE)
@@ -107,7 +107,7 @@ if(SANITIZERS)
endif(SANITIZERS)

# Optimization level = 3, no-debug definition (turns off asserts), warnings=errors
-set (CMAKE_C_FLAGS_RELEASE " -O3 -DNDEBUG -Werror")
+set (CMAKE_C_FLAGS_RELEASE " -O3 -DNDEBUG -Werror -Wno-unused-function -Wno-missing-braces -Wno-unused-but-set-variable -Wno-unknown-pragmas")

# DEBUG flags - optimization level = 0, generation GDB information (-g)
set (CMAKE_C_FLAGS_DEBUG " -O0 -g")
6 changes: 3 additions & 3 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ def _com_github_dltcollab_sse2neon():
maybe(
http_archive,
name = "com_github_dltcollab_sse2neon",
sha256 = "06f4693219deccb91b457135d836fc514a1c0a57e9fa66b143982901d2d19677",
strip_prefix = "sse2neon-1.6.0",
sha256 = "66e3d92571bfc9ce05dc1737421ba2f68e1fcb4552def866055676619955bdaa",
strip_prefix = "sse2neon-fb160a53e5a4ba5bc21e1a7cb80d0bd390812442",
type = "tar.gz",
urls = [
"https://github.com/DLTcollab/sse2neon/archive/refs/tags/v1.6.0.tar.gz",
"https://github.com/DLTcollab/sse2neon/archive/fb160a53e5a4ba5bc21e1a7cb80d0bd390812442.tar.gz",
],
build_file = "@yacl//bazel:sse2neon.BUILD",
)
Expand Down
8 changes: 1 addition & 7 deletions bazel/yacl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ WARNING_FLAGS = [
"-Wall",
"-Wextra",
"-Werror",
"-Wno-unused-parameter",
"-Wnon-virtual-dtor",
] + select({
"@bazel_tools//src/conditions:linux_aarch64": ["-Wno-uninitialized"],
"@bazel_tools//src/conditions:darwin": ["-Wunused-const-variable"],
"//conditions:default": ["-Wunused-const-variable=1"],
})
]

# set `SPDLOG_ACTIVE_LEVEL=1(SPDLOG_LEVEL_DEBUG)` to enable debug level log
DEBUG_FLAGS = ["-DSPDLOG_ACTIVE_LEVEL=1", "-O0", "-g"]
Expand Down
27 changes: 22 additions & 5 deletions yacl/base/int128.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,31 @@ std::pair<uint64_t, uint64_t> DecomposeUInt128(uint128_t v);

} // namespace yacl

#ifdef __GNUC__
#if !defined(__GNUC__)
#error "YACL only supports GCC and clang"
#endif

#if defined(__GLIBCXX_TYPE_INT_N_0) && (__GLIBCXX_TYPE_INT_N_0 == __int128)
#define WITH_GLIBCXX_INT128
#endif

#if defined(_LIBCPP_HAS_NO_INT128)
#define WITHOUT_CLANG_INT128
#endif

#ifdef __clang__ // clang mode
#define HAS_INT128_LIMITS
#if defined(__clang__) || \
(defined(__GLIBCXX_TYPE_INT_N_0) && (__GLIBCXX_TYPE_INT_N_0 == __int128))
#if defined(__GLIBCXX__) || defined(__GLIBCPP__) // clang with libstdc++
#ifdef WITH_GLIBCXX_INT128
#define HAS_INT128_TRAITS
#endif
#elif !defined(WITHOUT_CLANG_INT128)
#define HAS_INT128_TRAITS
#endif
#else // gcc
#ifdef WITH_GLIBCXX_INT128
#define HAS_INT128_TRAITS
#endif
#else
#error "YACL only supports GCC and clang"
#endif

namespace std {
Expand Down
5 changes: 3 additions & 2 deletions yacl/crypto/base/drbg/nist_aes_drbg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ using ENTROPY_CTX = struct entropy_st {
};

size_t GetEntropy(RAND_DRBG *drbg, unsigned char **pout, int entropy_bits,
size_t min_len, size_t max_len, int prediction_resistance) {
size_t min_len, size_t /*max_len*/,
int /*prediction_resistance*/) {
auto *ctx = reinterpret_cast<ENTROPY_CTX *>(
RAND_DRBG_get_ex_data(drbg, NistAesDrbg::app_data_index_));

Expand All @@ -79,7 +80,7 @@ size_t GetEntropy(RAND_DRBG *drbg, unsigned char **pout, int entropy_bits,
}

size_t GetNonce(RAND_DRBG *drbg, unsigned char **pout, int nonce_bits,
size_t min_len, size_t max_len) {
size_t min_len, size_t /*max_len*/) {
auto *ctx = reinterpret_cast<ENTROPY_CTX *>(
RAND_DRBG_get_ex_data(drbg, NistAesDrbg::app_data_index_));

Expand Down
2 changes: 1 addition & 1 deletion yacl/crypto/base/drbg/sm4_drbg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void Sm4Drbg::RngUpdate() {
return;
}

void Sm4Drbg::ReSeed(absl::Span<const uint8_t> seed,
void Sm4Drbg::ReSeed(absl::Span<const uint8_t> /*seed*/,
absl::Span<const uint8_t> additional_input) {
min_entropy_ = min_length_;
entropy_input_ = entropy_source_->GetEntropy(min_entropy_);
Expand Down
3 changes: 1 addition & 2 deletions yacl/crypto/base/ecc/libsodium/sodium_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ EcPoint SodiumGroup::DeserializePoint(ByteContainerView buf,
return p;
}

EcPoint SodiumGroup::HashToCurve(HashToCurveStrategy strategy,
std::string_view str) const {
EcPoint SodiumGroup::HashToCurve(HashToCurveStrategy, std::string_view) const {
YACL_THROW("not impl");
}

Expand Down
4 changes: 2 additions & 2 deletions yacl/crypto/base/ecc/openssl/openssl_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@ void OpensslGroup::SerializePoint(const EcPoint &point, PointOctetFormat format,
}

EcPoint OpensslGroup::DeserializePoint(ByteContainerView buf,
PointOctetFormat format) const {
PointOctetFormat) const {
auto p = MakeOpensslPoint();
// buf[0] == 0 indicate it's a infinity point, will fail if input len != 1
SSL_RET_1(EC_POINT_oct2point(group_.get(), CastAny<EC_POINT>(p), buf.data(),
buf.size() > 0 && buf[0] != 0 ? buf.length() : 1,
!buf.empty() && buf[0] != 0 ? buf.length() : 1,
ctx_.get()));
return p;
}
Expand Down
2 changes: 1 addition & 1 deletion yacl/crypto/base/ecc/toy/montgomery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ std::string ToyXGroup::ToString() const {
params_.A, params_.p);
}

EcPoint ToyXGroup::Add(const EcPoint &p1, const EcPoint &p2) const {
EcPoint ToyXGroup::Add(const EcPoint &, const EcPoint &) const {
YACL_THROW(
"{} from {} do not support Add, because p1, p2 only has X-coordinate",
GetCurveName(), GetLibraryName());
Expand Down
4 changes: 2 additions & 2 deletions yacl/crypto/base/ecc/toy/weierstrass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ EcPoint ToyWeierstrassGroup::DeserializePoint(ByteContainerView buf,
return op;
}

EcPoint ToyWeierstrassGroup::HashToCurve(HashToCurveStrategy strategy,
std::string_view str) const {
EcPoint ToyWeierstrassGroup::HashToCurve(HashToCurveStrategy,
std::string_view) const {
YACL_THROW("not impl");
}

Expand Down
7 changes: 2 additions & 5 deletions yacl/crypto/base/symmetric_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,9 @@ class Sm4CbcCrypto : public SymmetricCrypto {

// in some asymmetric scene
// may exist parties only need update count by buffer size.
template <typename T,
std::enable_if_t<std::is_standard_layout<T>::value, int> = 0>
inline uint64_t DummyUpdateRandomCount(uint64_t count, absl::Span<T> out) {
inline uint64_t DummyUpdateRandomCount(uint64_t count, size_t buffer_size) {
constexpr size_t block_size = SymmetricCrypto::BlockSize();
const size_t nbytes = out.size() * sizeof(T);
const size_t nblock = (nbytes + block_size - 1) / block_size;
const size_t nblock = (buffer_size + block_size - 1) / block_size;
return count + nblock;
}

Expand Down
38 changes: 24 additions & 14 deletions yacl/crypto/base/test/alg_data_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,24 @@ void AesTestData(std::string &file_name,
SymmetricCrypto crypto(crypto_mode, aes_key, 0);

crypto.Encrypt(
absl::MakeConstSpan((const uint8_t *)aes_plain.data(),
absl::MakeConstSpan(reinterpret_cast<const uint8_t *>(aes_plain.data()),
aes_plain.size()),
absl::MakeSpan((uint8_t *)aes_cipher.data(), aes_cipher.size()));
absl::MakeSpan(reinterpret_cast<uint8_t *>(aes_cipher.data()),
aes_cipher.size()));
crypto.Decrypt(
absl::MakeConstSpan((const uint8_t *)aes_cipher.data(),
aes_cipher.size()),
absl::MakeSpan((uint8_t *)aes_decrypt.data(), aes_decrypt.size()));
absl::MakeConstSpan(
reinterpret_cast<const uint8_t *>(aes_cipher.data()),
aes_cipher.size()),
absl::MakeSpan(reinterpret_cast<uint8_t *>(aes_decrypt.data()),
aes_decrypt.size()));

out_file << std::endl << "=====" << i << "=====" << std::endl;

out_file << "key(" << sizeof(uint128_t) << "): " << std::endl;

out_file << absl::BytesToHexString(absl::string_view((const char *)&aes_key,
sizeof(uint128_t)))
out_file << absl::BytesToHexString(
absl::string_view(reinterpret_cast<const char *>(&aes_key),
sizeof(uint128_t)))
<< std::endl;
out_file << "plain(" << aes_plain.length() << "): " << std::endl;
out_file << absl::BytesToHexString(aes_plain) << std::endl;
Expand Down Expand Up @@ -101,7 +105,8 @@ void Sha256TestData(std::string &file_name) {
out_file << absl::BytesToHexString(hash_data) << std::endl;
out_file << "hash(" << hash_result.size() << "):" << std::endl;
out_file << absl::BytesToHexString(std::string_view(
(const char *)hash_result.data(), hash_result.size()))
reinterpret_cast<const char *>(hash_result.data()),
hash_result.size()))
<< std::endl;
}
}
Expand Down Expand Up @@ -135,30 +140,35 @@ void Curve25519TestData(std::string &file_name) {
out_file << "=====" << i << "=====" << std::endl;
out_file << "private x(" << private_x.size() << "):" << std::endl;
out_file << absl::BytesToHexString(std::string_view(
(const char *)private_x.data(), share_x.size()))
reinterpret_cast<const char *>(private_x.data()),
share_x.size()))
<< std::endl;
out_file << "public x(" << public_x.size() << "):" << std::endl;
out_file << absl::BytesToHexString(std::string_view(
(const char *)public_x.data(), share_x.size()))
reinterpret_cast<const char *>(public_x.data()),
share_x.size()))
<< std::endl;
out_file << "private y(" << private_y.size() << "):" << std::endl;
out_file << absl::BytesToHexString(std::string_view(
(const char *)private_y.data(), share_x.size()))
reinterpret_cast<const char *>(private_y.data()),
share_x.size()))
<< std::endl;
out_file << "public y(" << public_y.size() << "):" << std::endl;
out_file << absl::BytesToHexString(std::string_view(
(const char *)public_y.data(), share_x.size()))
reinterpret_cast<const char *>(public_y.data()),
share_x.size()))
<< std::endl;
out_file << "share y(" << share_x.size() << "):" << std::endl;
out_file << absl::BytesToHexString(std::string_view(
(const char *)share_x.data(), share_x.size()))
reinterpret_cast<const char *>(share_x.data()),
share_x.size()))
<< std::endl;
}
}

} // namespace yacl::crypto

int main(int argc, char **argv) {
int main(int /*argc*/, char ** /*argv*/) {
std::string aes_ecb_file_name = "aes_ecb_data.txt";
std::string aes_ctr_file_name = "aes_ctr_data.txt";
std::string sha256_file_name = "sha256_data.txt";
Expand Down
2 changes: 1 addition & 1 deletion yacl/crypto/primitives/ot/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace yacl::crypto {

class OtBench : public benchmark::Fixture {
public:
void SetUp(const ::benchmark::State& state) override {
void SetUp(const ::benchmark::State&) override {
if (lctxs_.empty()) {
// lctxs_ = link::test::SetupBrpcWorld(2);
lctxs_ = link::test::SetupWorld(2);
Expand Down
2 changes: 1 addition & 1 deletion yacl/crypto/primitives/ot/ferret_ote.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ uint128_t GenSyncedSeed(const std::shared_ptr<link::Context>& ctx) {

} // namespace

uint64_t FerretCotHelper(const LpnParam& lpn_param, uint64_t ot_num) {
uint64_t FerretCotHelper(const LpnParam& lpn_param, uint64_t /*ot_num*/) {
uint64_t mpcot_cot = 0;
if (lpn_param.noise_asm == LpnNoiseAsm::RegularNoise) {
// for each mpcot invocation,
Expand Down
2 changes: 1 addition & 1 deletion yacl/crypto/primitives/ot/ot_store_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ inline std::pair<OtRecvStore, std::vector<uint128_t>> RandCompactOtRecvStore(
}

inline std::pair<OtSendStore, std::vector<std::array<uint128_t, 2>>>
RandOtSendStore(uint64_t num) {
RandOtSendStore(uint64_t /*num*/) {
std::vector<std::array<uint128_t, 2>> blocks;
Prg<uint128_t> prg;
for (size_t i = 0; i < 25; i++) {
Expand Down
4 changes: 3 additions & 1 deletion yacl/link/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <chrono>
#include <iostream>
#include <thread>
#include <utility>

#include "fmt/format.h"
#include "spdlog/spdlog.h"
Expand Down Expand Up @@ -93,7 +94,8 @@ Context::Context(const ContextDescProto& desc_pb, size_t rank,
std::vector<std::shared_ptr<transport::IChannel>> channels,
std::shared_ptr<transport::IReceiverLoop> msg_loop,
bool is_sub_world)
: Context(ContextDesc(), rank, channels, msg_loop, is_sub_world) {}
: Context(ContextDesc(desc_pb), rank, std::move(channels),
std::move(msg_loop), is_sub_world) {}

std::string Context::Id() const { return desc_.id; }

Expand Down
Loading

0 comments on commit f05b8c7

Please sign in to comment.