From e05d26eaf500e10aab9d7fb39160f8b7210ec728 Mon Sep 17 00:00:00 2001 From: Jamie Cui Date: Wed, 30 Oct 2024 20:55:20 +0800 Subject: [PATCH 1/2] chore(build): init cmake support --- .gitignore | 2 + CMakeLists.txt | 132 ++++++++++++++++++ cmake/AddCompilerFlags.cmake | 42 ++++++ cmake/ExternalAbseil.cmake | 25 ++++ cmake/ExternalBlake3.cmake | 25 ++++ cmake/ExternalFmt.cmake | 23 +++ cmake/ExternalFourQ.cmake | 52 +++++++ cmake/ExternalGTest.cmake | 20 +++ cmake/ExternalGflags.cmake | 29 ++++ cmake/ExternalLibSodium.cmake | 37 +++++ cmake/ExternalLibTommath.cmake | 34 +++++ cmake/ExternalMcl.cmake | 23 +++ cmake/ExternalMsgpack.cmake | 30 ++++ cmake/ExternalOpenSSL.cmake | 61 ++++++++ cmake/ExternalSPDLog.cmake | 28 ++++ cmake/ExternalSse2neon.cmake | 27 ++++ yacl/CMakeLists.txt | 29 ++++ yacl/base/CMakeLists.txt | 37 +++++ yacl/crypto/CMakeLists.txt | 44 ++++++ yacl/crypto/aead/CMakeLists.txt | 35 +++++ yacl/crypto/aes/CMakeLists.txt | 30 ++++ yacl/crypto/block_cipher/CMakeLists.txt | 29 ++++ yacl/crypto/ecc/CMakeLists.txt | 47 +++++++ yacl/crypto/ecc/FourQlib/CMakeLists.txt | 31 ++++ yacl/crypto/ecc/lib25519/CMakeLists.txt | 34 +++++ yacl/crypto/ecc/libsodium/CMakeLists.txt | 43 ++++++ yacl/crypto/ecc/mcl/CMakeLists.txt | 32 +++++ yacl/crypto/ecc/openssl/CMakeLists.txt | 30 ++++ yacl/crypto/ecc/toy/CMakeLists.txt | 41 ++++++ yacl/crypto/envelope/CMakeLists.txt | 29 ++++ yacl/crypto/experimental/CMakeLists.txt | 22 +++ yacl/crypto/experimental/dpf/CMakeLists.txt | 44 ++++++ .../experimental/sync_drbg/CMakeLists.txt | 44 ++++++ yacl/crypto/experimental/tpre/CMakeLists.txt | 44 ++++++ yacl/crypto/experimental/vss/CMakeLists.txt | 44 ++++++ yacl/crypto/hash/CMakeLists.txt | 41 ++++++ yacl/crypto/hmac/CMakeLists.txt | 30 ++++ yacl/crypto/pke/CMakeLists.txt | 37 +++++ yacl/crypto/rand/CMakeLists.txt | 33 +++++ yacl/crypto/rand/drbg/CMakeLists.txt | 33 +++++ .../crypto/rand/entropy_source/CMakeLists.txt | 33 +++++ yacl/crypto/sign/CMakeLists.txt | 38 +++++ yacl/crypto/tools/CMakeLists.txt | 50 +++++++ yacl/crypto/tools/ro_test.cc | 13 +- yacl/io/CMakeLists.txt | 7 + yacl/io/msgpack/CMakeLists.txt | 32 +++++ yacl/io/rw/CMakeLists.txt | 38 +++++ yacl/io/stream/CMakeLists.txt | 34 +++++ yacl/math/CMakeLists.txt | 25 ++++ yacl/math/galois_field/CMakeLists.txt | 37 +++++ yacl/math/galois_field/factory/CMakeLists.txt | 50 +++++++ .../galois_field/factory/intel_factory.cc | 12 +- .../factory/intel_factory_test.cc | 4 +- yacl/math/mpint/CMakeLists.txt | 50 +++++++ yacl/math/mpint/mp_int_test.cc | 5 +- yacl/utils/CMakeLists.txt | 37 +++++ yacl/utils/spi/CMakeLists.txt | 49 +++++++ 57 files changed, 1957 insertions(+), 10 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 cmake/AddCompilerFlags.cmake create mode 100644 cmake/ExternalAbseil.cmake create mode 100644 cmake/ExternalBlake3.cmake create mode 100644 cmake/ExternalFmt.cmake create mode 100644 cmake/ExternalFourQ.cmake create mode 100644 cmake/ExternalGTest.cmake create mode 100644 cmake/ExternalGflags.cmake create mode 100644 cmake/ExternalLibSodium.cmake create mode 100644 cmake/ExternalLibTommath.cmake create mode 100644 cmake/ExternalMcl.cmake create mode 100644 cmake/ExternalMsgpack.cmake create mode 100644 cmake/ExternalOpenSSL.cmake create mode 100644 cmake/ExternalSPDLog.cmake create mode 100644 cmake/ExternalSse2neon.cmake create mode 100644 yacl/CMakeLists.txt create mode 100644 yacl/base/CMakeLists.txt create mode 100644 yacl/crypto/CMakeLists.txt create mode 100644 yacl/crypto/aead/CMakeLists.txt create mode 100644 yacl/crypto/aes/CMakeLists.txt create mode 100644 yacl/crypto/block_cipher/CMakeLists.txt create mode 100644 yacl/crypto/ecc/CMakeLists.txt create mode 100644 yacl/crypto/ecc/FourQlib/CMakeLists.txt create mode 100644 yacl/crypto/ecc/lib25519/CMakeLists.txt create mode 100644 yacl/crypto/ecc/libsodium/CMakeLists.txt create mode 100644 yacl/crypto/ecc/mcl/CMakeLists.txt create mode 100644 yacl/crypto/ecc/openssl/CMakeLists.txt create mode 100644 yacl/crypto/ecc/toy/CMakeLists.txt create mode 100644 yacl/crypto/envelope/CMakeLists.txt create mode 100644 yacl/crypto/experimental/CMakeLists.txt create mode 100644 yacl/crypto/experimental/dpf/CMakeLists.txt create mode 100644 yacl/crypto/experimental/sync_drbg/CMakeLists.txt create mode 100644 yacl/crypto/experimental/tpre/CMakeLists.txt create mode 100644 yacl/crypto/experimental/vss/CMakeLists.txt create mode 100644 yacl/crypto/hash/CMakeLists.txt create mode 100644 yacl/crypto/hmac/CMakeLists.txt create mode 100644 yacl/crypto/pke/CMakeLists.txt create mode 100644 yacl/crypto/rand/CMakeLists.txt create mode 100644 yacl/crypto/rand/drbg/CMakeLists.txt create mode 100644 yacl/crypto/rand/entropy_source/CMakeLists.txt create mode 100644 yacl/crypto/sign/CMakeLists.txt create mode 100644 yacl/crypto/tools/CMakeLists.txt create mode 100644 yacl/io/CMakeLists.txt create mode 100644 yacl/io/msgpack/CMakeLists.txt create mode 100644 yacl/io/rw/CMakeLists.txt create mode 100644 yacl/io/stream/CMakeLists.txt create mode 100644 yacl/math/CMakeLists.txt create mode 100644 yacl/math/galois_field/CMakeLists.txt create mode 100644 yacl/math/galois_field/factory/CMakeLists.txt create mode 100644 yacl/math/mpint/CMakeLists.txt create mode 100644 yacl/utils/CMakeLists.txt create mode 100644 yacl/utils/spi/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 839e33a..d299064 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,5 @@ external #brpc rpc_data + +Testing/Temporary/* diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3dd275d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,132 @@ +# 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. + +cmake_minimum_required(VERSION 3.20) + +project( + yacl + VERSION 0.4.5 + DESCRIPTION + "YACL (Yet Another Common crypto library) is a C++ library that contains cryptography, network and io modules which other SecretFlow code depends on." + HOMEPAGE_URL "https://github.com/secretflow/yacl" + LANGUAGES CXX C) + +set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/") +set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE + "Release" + CACHE STRING "Build type" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug" + "MinSizeRel" "RelWithDebInfo") +endif() +message(STATUS "Build type (CMAKE_BUILD_TYPE): ${CMAKE_BUILD_TYPE}") + +# This policy was introduced in CMake 3.13; OLD by default until CMake 3.21 +cmake_policy(SET CMP0077 NEW) +cmake_policy(SET CMP0135 NEW) + +# CMake modules +include(CMakeDependentOption) +include(CheckCXXCompilerFlag) +include(CheckCXXSourceRuns) +include(CheckLanguage) +include(FetchContent) +include(ExternalProject) + +# Always build position-independent-code +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +# Enable C++17 +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_C_STANDARD_REQUIRED YES) +set(CMAKE_EXE_LINKER_FLAGS + "${CMAKE_EXE_LINKER_FLAGS} -undefined dynamic_lookup") + +include(GNUInstallDirs) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) + +include(AddCompilerFlags) + +# make it colorful under ninja-build +if(CMAKE_GENERATOR STREQUAL Ninja) + add_compiler_flags(-fdiagnostics-color=always) +endif() + +# set fetch content base directory +set(FETCHCONTENT_BASE_DIR ${CMAKE_BINARY_DIR}/external_cmake) + +include(ExternalAbseil) +include(ExternalBlake3) +include(ExternalFmt) +include(ExternalSPDLog) +include(ExternalGTest) +include(ExternalGflags) +include(ExternalMsgpack) +include(ExternalOpenSSL) +include(ExternalLibtommath) +include(ExternalSse2neon) +include(ExternalMcl) +include(ExternalFourQ) +include(ExternalLibSodium) + +enable_testing() + +add_library(yacl STATIC) + +target_include_directories( + yacl + PUBLIC + "$" # these dirs are only used + # when building inside the + # build tree + "$" # these dirs are only + # used when linking + # against a prebuilt + # version of your package +) + +target_include_directories(yacl PUBLIC ${CMAKE_BINARY_DIR}/include) + +set(YACL_SOURCE_FILES "") + +add_subdirectory(yacl) +add_subdirectory(yacl/base) +add_subdirectory(yacl/crypto) +add_subdirectory(yacl/io) +add_subdirectory(yacl/utils) +add_subdirectory(yacl/math) + +target_sources(yacl PRIVATE ${YACL_SOURCE_FILES}) + +target_link_libraries( + yacl + PUBLIC fmt::fmt + absl::stacktrace + absl::symbolize + absl::int128 + BLAKE3::blake3 + mcl::mcl + ExtLibsodium::libsodium + ExtLibtommath::libtommath + ExtFourQ::fourq) + +if(YACL_WITH_EXT_OPENSSL) + target_link_libraries(yacl PUBLIC ExtOpenSSL::Crypto ExtOpenSSL::SSL) +else() + target_link_libraries(yacl PUBLIC OpenSSL::Crypto OpenSSL::SSL) +endif() diff --git a/cmake/AddCompilerFlags.cmake b/cmake/AddCompilerFlags.cmake new file mode 100644 index 0000000..94f6072 --- /dev/null +++ b/cmake/AddCompilerFlags.cmake @@ -0,0 +1,42 @@ +# 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(CheckCXXCompilerFlag) + +# For easier adding of CXX compiler flags +function(add_compiler_flags flag) + string(FIND "${CMAKE_CXX_FLAGS}" "${flag}" flag_already_set) + if(flag_already_set EQUAL -1) + message(STATUS "Adding CXX compiler flag: ${flag} ...") + check_cxx_compiler_flag("${flag}" flag_supported) + if(flag_supported) + set(CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} ${flag}" + PARENT_SCOPE) + endif() + unset(flag_supported CACHE) + endif() +endfunction() + +add_compiler_flags("-Wall") +add_compiler_flags("-Wextra") +add_compiler_flags("-Werror") + +# FIXME remove this flag +add_compiler_flags("-Wno-unused-function") + +# For cryptos +add_compiler_flags("-maes") +add_compiler_flags("-mavx") +add_compiler_flags("-mpclmul") diff --git a/cmake/ExternalAbseil.cmake b/cmake/ExternalAbseil.cmake new file mode 100644 index 0000000..12192bf --- /dev/null +++ b/cmake/ExternalAbseil.cmake @@ -0,0 +1,25 @@ +# 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. + +FetchContent_Declare( + abseil + URL https://github.com/abseil/abseil-cpp/archive/refs/tags/20240722.0.tar.gz + URL_HASH SHA256=f50e5ac311a81382da7fa75b97310e4b9006474f9560ac46f54a9967f07d4ae3 +) + +SET(ABSL_PROPAGATE_CXX_STD ON CACHE INTERNAL "") +SET(ABSL_USE_SYSTEM_INCLUDES ON CACHE INTERNAL "") +FetchContent_MakeAvailable(abseil) + +include_directories(${abseil_SOURCE_DIR}) diff --git a/cmake/ExternalBlake3.cmake b/cmake/ExternalBlake3.cmake new file mode 100644 index 0000000..c34f1dc --- /dev/null +++ b/cmake/ExternalBlake3.cmake @@ -0,0 +1,25 @@ +# 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. + +FetchContent_Declare( + blake3 + URL https://github.com/BLAKE3-team/BLAKE3/archive/refs/tags/1.5.4.tar.gz + URL_HASH + SHA256=ddd24f26a31d23373e63d9be2e723263ac46c8b6d49902ab08024b573fd2a416 + SOURCE_SUBDIR c) + +FetchContent_MakeAvailable(blake3) + +include_directories(${blake3_SOURCE_DIR}) + diff --git a/cmake/ExternalFmt.cmake b/cmake/ExternalFmt.cmake new file mode 100644 index 0000000..2166420 --- /dev/null +++ b/cmake/ExternalFmt.cmake @@ -0,0 +1,23 @@ +# 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. + +FetchContent_Declare(fmt + URL https://github.com/fmtlib/fmt/archive/refs/tags/11.0.2.tar.gz + URL_HASH SHA256=6cb1e6d37bdcb756dbbe59be438790db409cdb4868c66e888d5df9f13f7c027f + ) + +SET(FMT_TEST OFF CACHE INTERNAL "") +FetchContent_MakeAvailable(fmt) + +include_directories(${fmt_SOURCE_DIR}/include) diff --git a/cmake/ExternalFourQ.cmake b/cmake/ExternalFourQ.cmake new file mode 100644 index 0000000..fd617a5 --- /dev/null +++ b/cmake/ExternalFourQ.cmake @@ -0,0 +1,52 @@ +# 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. + +set(YACL_EXT_FOURQ_URL + https://github.com/microsoft/FourQlib/archive/1031567f23278e1135b35cc04e5d74c2ac88c029.tar.gz +) + +set(YACL_EXT_FOURQ_SHA256 + 7417c829d7933facda568c7a08924dfefb0c83dd1dab411e597af4c0cc0417f0) + +set(YACL_EXT_FOURQ_BUILD_COMMAND make ARCH=x64 GENERIC=TRUE EXTENDED_SET=FALSE + -C FourQ_64bit_and_portable libFourQ) + +set(YACL_EXT_FOURQ_INSTALL_COMMAND make PREFIX=${CMAKE_BINARY_DIR} -C + FourQ_64bit_and_portable install) + +ExternalProject_Add( + fourq + PREFIX "external_fourq" + URL ${YACL_EXT_FOURQ_URL} + URL_HASH SHA256=${YACL_EXT_FOURQ_SHA256} + BUILD_IN_SOURCE true + PATCH_COMMAND patch -p1 -l -i + ${PROJECT_SOURCE_DIR}/bazel/patches/FourQlib.patch + CONFIGURE_COMMAND "" # no configure + BUILD_COMMAND ${YACL_EXT_FOURQ_BUILD_COMMAND} + INSTALL_COMMAND ${YACL_EXT_FOURQ_INSTALL_COMMAND}) + +add_library(ExtFourQ STATIC IMPORTED) +set_target_properties( + ExtFourQ PROPERTIES IMPORTED_LOCATION + ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libFourQ.a) +add_library(ExtFourQ::fourq ALIAS ExtFourQ) + +ExternalProject_Get_Property(fourq SOURCE_DIR) +include_directories(${SOURCE_DIR}/FourQ_64bit_and_portable) +unset(SOURCE_DIR) + +# HACK add yacl global compiler flag +add_compiler_flags("-D __LINUX__") +add_compiler_flags("-D _ARM64_") diff --git a/cmake/ExternalGTest.cmake b/cmake/ExternalGTest.cmake new file mode 100644 index 0000000..cdae437 --- /dev/null +++ b/cmake/ExternalGTest.cmake @@ -0,0 +1,20 @@ +# 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. + +FetchContent_Declare(googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.15.2.tar.gz + URL_HASH SHA256=7b42b4d6ed48810c5362c265a17faebe90dc2373c885e5216439d37927f02926 + ) + +FetchContent_MakeAvailable(googletest) diff --git a/cmake/ExternalGflags.cmake b/cmake/ExternalGflags.cmake new file mode 100644 index 0000000..49ee05f --- /dev/null +++ b/cmake/ExternalGflags.cmake @@ -0,0 +1,29 @@ +# 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. + +FetchContent_Declare(gflags + URL https://github.com/gflags/gflags/archive/v2.2.2.tar.gz + URL_HASH SHA256=34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf + ) + +set(CMAKE_CXX_FLAGS_OLD "${CMAKE_CXX_FLAGS}") + +# Add other flags here. +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter") +set(BUILD_TESTING OFF CACHE INTERNAL "") + +FetchContent_MakeAvailable(gflags) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_OLD}") +unset(BUILD_TESTING) diff --git a/cmake/ExternalLibSodium.cmake b/cmake/ExternalLibSodium.cmake new file mode 100644 index 0000000..c11b24e --- /dev/null +++ b/cmake/ExternalLibSodium.cmake @@ -0,0 +1,37 @@ +# 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. + +# NOTE download. configure, build, install happens during project make process +ExternalProject_Add( + libsodium + PREFIX "external_libsodium" + URL https://github.com/jedisct1/libsodium/releases/download/1.0.18-RELEASE/libsodium-1.0.18.tar.gz + URL_HASH + SHA256=6f504490b342a4f8a4c4a02fc9b866cbef8622d5df4e5452b46be121e46636c1 + BUILD_IN_SOURCE true + CONFIGURE_COMMAND ./configure --prefix=${CMAKE_BINARY_DIR} + BUILD_COMMAND make + INSTALL_COMMAND make install + EXCLUDE_FROM_ALL) + +add_library(ExtLibsodium STATIC IMPORTED) +set_target_properties( + ExtLibsodium PROPERTIES IMPORTED_LOCATION + ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libsodium.a) +add_library(ExtLibsodium::libsodium ALIAS ExtLibsodium) + +ExternalProject_Get_Property(libsodium SOURCE_DIR) +include_directories(${SOURCE_DIR}/src/libsodium/include) +include_directories(${SOURCE_DIR}/src/libsodium/include/sodium) +unset(SOURCE_DIR) diff --git a/cmake/ExternalLibTommath.cmake b/cmake/ExternalLibTommath.cmake new file mode 100644 index 0000000..ec876d7 --- /dev/null +++ b/cmake/ExternalLibTommath.cmake @@ -0,0 +1,34 @@ +# 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. + +# NOTE download. configure, build, install happens during project make process +ExternalProject_Add( + libtommath + PREFIX "external_libtommath" + URL https://github.com/libtom/libtommath/archive/42b3fb07e7d504f61a04c7fca12e996d76a25251.tar.gz + URL_HASH + SHA256=7cfbdb64431129de4257e7d3349200fdbd4f229b470ff3417b30d0f39beed41f + INSTALL_COMMAND cmake --install . --prefix ${CMAKE_BINARY_DIR} + EXCLUDE_FROM_ALL) + +add_library(ExtLibtommath STATIC IMPORTED) +set_target_properties( + ExtLibtommath PROPERTIES IMPORTED_LOCATION + ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libtommath.a) + +add_library(ExtLibtommath::libtommath ALIAS ExtLibtommath) + +ExternalProject_Get_Property(libtommath SOURCE_DIR) +include_directories(${SOURCE_DIR}/..) +unset(SOURCE_DIR) diff --git a/cmake/ExternalMcl.cmake b/cmake/ExternalMcl.cmake new file mode 100644 index 0000000..e444c85 --- /dev/null +++ b/cmake/ExternalMcl.cmake @@ -0,0 +1,23 @@ +# 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. + +FetchContent_Declare( + mcl + URL https://github.com/herumi/mcl/archive/refs/tags/v1.99.tar.gz + URL_HASH + SHA256=5ff9702c1f1b021925d1334ca0a03c87783174075aeaf87801842d3c08b3d39e) + +FetchContent_MakeAvailable(mcl) + +include_directories(${mcl_SOURCE_DIR}/include) diff --git a/cmake/ExternalMsgpack.cmake b/cmake/ExternalMsgpack.cmake new file mode 100644 index 0000000..2c880d7 --- /dev/null +++ b/cmake/ExternalMsgpack.cmake @@ -0,0 +1,30 @@ +# 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. + +FetchContent_Declare(msgpack + URL https://github.com/msgpack/msgpack-c/archive/refs/tags/cpp-6.1.0.tar.gz + URL_HASH SHA256=5e63e4d9b12ab528fccf197f7e6908031039b1fc89cd8da0e97fbcbf5a6c6d3a + ) + +SET(MSGPACK_CXX17 ON CACHE INTERNAL "") +SET(MSGPACK_USE_BOOST OFF CACHE INTERNAL "") +SET(MSGPACK_BUILD_EXAMPLES OFF CACHE INTERNAL "") +SET(BUILD_SHARED_LIBS OFF CACHE INTERNAL "") +SET(MSGPACK_BUILD_TESTS OFF CACHE INTERNAL "") + +FetchContent_MakeAvailable(msgpack) + +add_definitions(-DMSGPACK_NO_BOOST) +include_directories(${msgpack_SOURCE_DIR}/include) + diff --git a/cmake/ExternalOpenSSL.cmake b/cmake/ExternalOpenSSL.cmake new file mode 100644 index 0000000..d327458 --- /dev/null +++ b/cmake/ExternalOpenSSL.cmake @@ -0,0 +1,61 @@ +# 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. + +set(YACL_EXT_OPENSSL_VERSION 3.3.2) +set(YACL_EXT_OPENSSL_URL + https://github.com/openssl/openssl/archive/refs/tags/openssl-3.3.2.tar.gz) +set(YACL_EXT_OPENSSL_SHA256 + bedbb16955555f99b1a7b1ba90fc97879eb41025081be359ecd6a9fcbdf1c8d2) +set(YACL_WITH_EXT_OPENSSL TRUE) + +# Trying to find system openssl first (failures are allowed) see: +# https://cmake.org/cmake/help/v3.4/module/FindOpenSSL.html +find_package(OpenSSL QUIET) + +if(${OPENSSL_FOUND} AND ${OPENSSL_VERSION} VERSION_GREATER "5.0.0") + message(STATUS "Found system OpenSSL (${OPENSSL_VERSION})") + set(YACL_WITH_EXT_OPENSSL FALSE) +else() + message(STATUS "OpenSSL not found, or its version is incompatiable") + message(STATUS "Use downloaded OpenSSL (${YACL_EXT_OPENSSL_VERSION}) instead") + set(YACL_WITH_EXT_OPENSSL TRUE) +endif() + +if(YACL_WITH_EXT_OPENSSL) + ExternalProject_Add( + openssl + PREFIX "external_openssl" + URL ${YACL_EXT_OPENSSL_URL} + URL_HASH SHA256=${YACL_EXT_OPENSSL_SHA256} + BUILD_IN_SOURCE true + CONFIGURE_COMMAND + ./Configure no-legacy no-weak-ssl-ciphers no-tests no-shared no-ui-console + no-docs no-apps --banner=Finished --release --prefix=${CMAKE_BINARY_DIR} + -w + BUILD_COMMAND make -j4 build_sw + INSTALL_COMMAND make install_sw + EXCLUDE_FROM_ALL) + + add_library(ExtOpenSSL_Crypto STATIC IMPORTED) + set_target_properties( + ExtOpenSSL_Crypto PROPERTIES IMPORTED_LOCATION + ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libcrypto.a) + add_library(ExtOpenSSL::Crypto ALIAS ExtOpenSSL_Crypto) + + add_library(ExtOpenSSL_SSL STATIC IMPORTED) + set_target_properties( + ExtOpenSSL_SSL PROPERTIES IMPORTED_LOCATION + ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libssl.a) + add_library(ExtOpenSSL::SSL ALIAS ExtOpenSSL_SSL) +endif() diff --git a/cmake/ExternalSPDLog.cmake b/cmake/ExternalSPDLog.cmake new file mode 100644 index 0000000..48c7626 --- /dev/null +++ b/cmake/ExternalSPDLog.cmake @@ -0,0 +1,28 @@ +# 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. + +FetchContent_Declare(spdlog + URL https://github.com/gabime/spdlog/archive/refs/tags/v1.14.1.tar.gz + URL_HASH SHA256=1586508029a7d0670dfcb2d97575dcdc242d3868a259742b69f100801ab4e16b + ) + +SET(SPDLOG_BUILD_EXAMPLE OFF CACHE INTERNAL "") +SET(SPDLOG_FMT_EXTERNAL ON CACHE INTERNAL "") +SET(SPDLOG_NO_TLS ON CACHE INTERNAL "") +SET(SPDLOG_BUILD_PIC ON CACHE INTERNAL "") + +FetchContent_MakeAvailable(spdlog) + +include_directories(${spdlog_SOURCE_DIR}/include) +add_definitions(-DSPDLOG_FMT_EXTERNAL) diff --git a/cmake/ExternalSse2neon.cmake b/cmake/ExternalSse2neon.cmake new file mode 100644 index 0000000..3b499d2 --- /dev/null +++ b/cmake/ExternalSse2neon.cmake @@ -0,0 +1,27 @@ +# 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. + +ExternalProject_Add( + sse2neon + PREFIX "external_sse2neon" + URL https://github.com/DLTcollab/sse2neon/archive/8df2f48dbd0674ae5087f7a6281af6f55fa5a8e2.tar.gz + URL_HASH + SHA256=787e0a7a64f1461b48232a7f9b9e9c14fa4a35a30875f2fb91aec6ddeaddfc0f + BUILD_IN_SOURCE true + CONFIGURE_COMMAND "" + INSTALL_COMMAND "") + +ExternalProject_Get_Property(sse2neon SOURCE_DIR) +include_directories(${SOURCE_DIR}) +unset(SOURCE_DIR) diff --git a/yacl/CMakeLists.txt b/yacl/CMakeLists.txt new file mode 100644 index 0000000..9841fd6 --- /dev/null +++ b/yacl/CMakeLists.txt @@ -0,0 +1,29 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/secparam.cc) + +# Add header files for installation +install(FILES ${CMAKE_CURRENT_LIST_DIR}/secparam.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(secparam_test secparam_test.cc) +target_link_libraries(secparam_test PRIVATE yacl gtest_main) +target_link_options(secparam_test PRIVATE "-all_load") # for spi +add_test(NAME secparam_test COMMAND secparam_test) diff --git a/yacl/base/CMakeLists.txt b/yacl/base/CMakeLists.txt new file mode 100644 index 0000000..0df2bf7 --- /dev/null +++ b/yacl/base/CMakeLists.txt @@ -0,0 +1,37 @@ +# 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. + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/exception.cc + ${CMAKE_CURRENT_LIST_DIR}/int128.cc) + +# Add header files for installation +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/aligened_vector.h + ${CMAKE_CURRENT_LIST_DIR}/block.h + ${CMAKE_CURRENT_LIST_DIR}/buffer.h + ${CMAKE_CURRENT_LIST_DIR}/byte_container_view.h + ${CMAKE_CURRENT_LIST_DIR}/dynamic_bitset.h + ${CMAKE_CURRENT_LIST_DIR}/exception.h + ${CMAKE_CURRENT_LIST_DIR}/int128.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/base) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(buffer_test buffer_test.cc) +target_link_libraries(buffer_test PRIVATE yacl gtest_main) +target_link_options(buffer_test PRIVATE "-all_load") # for spi +add_test(NAME buffer_test COMMAND buffer_test) diff --git a/yacl/crypto/CMakeLists.txt b/yacl/crypto/CMakeLists.txt new file mode 100644 index 0000000..19d676a --- /dev/null +++ b/yacl/crypto/CMakeLists.txt @@ -0,0 +1,44 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/key_utils.cc) + +# Add header files for installation +install(FILES ${CMAKE_CURRENT_LIST_DIR}/key_utils.h + ${CMAKE_CURRENT_LIST_DIR}/openssl_wrappers.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto) + +add_subdirectory(aead) +add_subdirectory(aes) +add_subdirectory(block_cipher) +add_subdirectory(ecc) +add_subdirectory(envelope) +# add_subdirectory(experimental) +add_subdirectory(hash) +add_subdirectory(hmac) +# add_subdirectory(pairing) +add_subdirectory(pke) +add_subdirectory(rand) +add_subdirectory(sign) +add_subdirectory(tools) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(key_utils_test key_utils_test.cc) +target_link_libraries(key_utils_test PRIVATE yacl gtest_main) +target_link_options(key_utils_test PRIVATE "-all_load") # for spi +add_test(NAME key_utils_test COMMAND key_utils_test) diff --git a/yacl/crypto/aead/CMakeLists.txt b/yacl/crypto/aead/CMakeLists.txt new file mode 100644 index 0000000..8a17da3 --- /dev/null +++ b/yacl/crypto/aead/CMakeLists.txt @@ -0,0 +1,35 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/all_gcm.cc + ${CMAKE_CURRENT_LIST_DIR}/sm4_mte.cc) + +# Add header files for installation +install(FILES ${CMAKE_CURRENT_LIST_DIR}/all_gcm.h + ${CMAKE_CURRENT_LIST_DIR}/sm4_mte.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/aead) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(all_gcm_test all_gcm_test.cc) +target_link_libraries(all_gcm_test PRIVATE yacl gtest_main) +target_link_options(all_gcm_test PRIVATE "-all_load") # for spi +add_test(NAME all_gcm_test COMMAND all_gcm_test) + +add_executable(sm4_mte_test sm4_mte_test.cc) +target_link_libraries(sm4_mte_test PRIVATE yacl gtest_main) +target_link_options(all_gcm_test PRIVATE "-all_load") # for spi +add_test(NAME sm4_mte_test COMMAND sm4_mte_test) diff --git a/yacl/crypto/aes/CMakeLists.txt b/yacl/crypto/aes/CMakeLists.txt new file mode 100644 index 0000000..addb178 --- /dev/null +++ b/yacl/crypto/aes/CMakeLists.txt @@ -0,0 +1,30 @@ +# 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. + +# Add header files for installation +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/aes_intrinsics.h + ${CMAKE_CURRENT_LIST_DIR}/aes_opt.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/aes) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(aes_test aes_test.cc) +target_link_libraries(aes_test PRIVATE yacl gtest_main) +target_link_options(aes_test PRIVATE "-all_load") # for spi +add_test(NAME aes_test COMMAND aes_test) + +# TODO Add benchmark target diff --git a/yacl/crypto/block_cipher/CMakeLists.txt b/yacl/crypto/block_cipher/CMakeLists.txt new file mode 100644 index 0000000..8f7714b --- /dev/null +++ b/yacl/crypto/block_cipher/CMakeLists.txt @@ -0,0 +1,29 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/symmetric_crypto.cc) + +# Add header files for installation +install(FILES ${CMAKE_CURRENT_LIST_DIR}/symmetric_crypto.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/block_cipher) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(symmetric_crypto_test symmetric_crypto_test.cc) +target_link_libraries(symmetric_crypto_test PRIVATE yacl gtest_main) +target_link_options(symmetric_crypto_test PRIVATE "-all_load") # for spi +add_test(NAME symmetric_crypto_test COMMAND symmetric_crypto_test) diff --git a/yacl/crypto/ecc/CMakeLists.txt b/yacl/crypto/ecc/CMakeLists.txt new file mode 100644 index 0000000..045bb0e --- /dev/null +++ b/yacl/crypto/ecc/CMakeLists.txt @@ -0,0 +1,47 @@ +# 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. + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/curve_meta.cc + ${CMAKE_CURRENT_LIST_DIR}/ec_point.cc ${CMAKE_CURRENT_LIST_DIR}/ecc_spi.cc + ${CMAKE_CURRENT_LIST_DIR}/group_sketch.cc) + +# Add header files for installation +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/curve_meta.h + ${CMAKE_CURRENT_LIST_DIR}/ec_point.h + ${CMAKE_CURRENT_LIST_DIR}/ecc_spi.h + ${CMAKE_CURRENT_LIST_DIR}/group_sketch.h + ${CMAKE_CURRENT_LIST_DIR}/any_ptr.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/ecc) + +# add_subdirectory(benchmark) # TODO + +add_subdirectory(FourQlib) +add_subdirectory(libsodium) +add_subdirectory(mcl) +add_subdirectory(openssl) +add_subdirectory(toy) + +# TODO +# add_subdirectory(lib25519) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(ecc_test ecc_test.cc) +target_link_libraries(ecc_test PRIVATE yacl gtest_main) +target_link_options(ecc_test PRIVATE "-all_load") # for spi +add_test(NAME ecc_test COMMAND ecc_test) diff --git a/yacl/crypto/ecc/FourQlib/CMakeLists.txt b/yacl/crypto/ecc/FourQlib/CMakeLists.txt new file mode 100644 index 0000000..256be1a --- /dev/null +++ b/yacl/crypto/ecc/FourQlib/CMakeLists.txt @@ -0,0 +1,31 @@ +# 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. + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/FourQ_factory.cc + ${CMAKE_CURRENT_LIST_DIR}/FourQ_group.cc) + + +# Add header files for installation +install(FILES ${CMAKE_CURRENT_LIST_DIR}/FourQ_group.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/ecc/FourQlib) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(FourQ_test FourQ_test.cc) +target_link_libraries(FourQ_test PRIVATE yacl gtest_main) +target_link_options(FourQ_test PRIVATE "-all_load") # for spi +add_test(NAME FourQ_test COMMAND FourQ_test) diff --git a/yacl/crypto/ecc/lib25519/CMakeLists.txt b/yacl/crypto/ecc/lib25519/CMakeLists.txt new file mode 100644 index 0000000..999a431 --- /dev/null +++ b/yacl/crypto/ecc/lib25519/CMakeLists.txt @@ -0,0 +1,34 @@ +# 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. + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/lib25519_factory.cc + ${CMAKE_CURRENT_LIST_DIR}/ed25519_group.cc + ${CMAKE_CURRENT_LIST_DIR}/lib25519_group.cc) + +# Add header files for installation +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/ed25519_group.h + ${CMAKE_CURRENT_LIST_DIR}/lib25519_group.h + ${CMAKE_CURRENT_LIST_DIR}/lib25519_private.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/ecc/lib25519) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(ecc_lib25519_ed25519_test ed25519_test.cc) +target_link_libraries(ecc_lib25519_ed25519_test PRIVATE yacl gtest_main) +target_link_options(ecc_lib25519_ed25519_test PRIVATE "-all_load") # for spi +add_test(NAME ecc_lib25519_ed25519_test COMMAND ecc_lib25519_ed25519_test) diff --git a/yacl/crypto/ecc/libsodium/CMakeLists.txt b/yacl/crypto/ecc/libsodium/CMakeLists.txt new file mode 100644 index 0000000..45b69f7 --- /dev/null +++ b/yacl/crypto/ecc/libsodium/CMakeLists.txt @@ -0,0 +1,43 @@ +# 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. + +set(CMAKE_CXX_FLAGS_OLD "${CMAKE_CXX_FLAGS}") + +# Add other flags here. +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function") + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/sodium_factory.cc + ${CMAKE_CURRENT_LIST_DIR}/ed25519_group.cc + ${CMAKE_CURRENT_LIST_DIR}/sodium_group.cc + ${CMAKE_CURRENT_LIST_DIR}/x25519_group.cc) + +# Add header files for installation +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/ed25519_group.h + ${CMAKE_CURRENT_LIST_DIR}/sodium_group.h + ${CMAKE_CURRENT_LIST_DIR}/sodium_private.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/ecc/libsodium) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(ecc_sodium_ed25519_test ed25519_test.cc) +target_link_libraries(ecc_sodium_ed25519_test PRIVATE yacl gtest_main) +target_link_options(ecc_sodium_ed25519_test PRIVATE "-all_load") # for spi +add_test(NAME ecc_sodium_ed25519_test COMMAND ecc_sodium_ed25519_test) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_OLD}") diff --git a/yacl/crypto/ecc/mcl/CMakeLists.txt b/yacl/crypto/ecc/mcl/CMakeLists.txt new file mode 100644 index 0000000..966dc28 --- /dev/null +++ b/yacl/crypto/ecc/mcl/CMakeLists.txt @@ -0,0 +1,32 @@ +# 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. + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/mcl_ec_factory.cc + ${CMAKE_CURRENT_LIST_DIR}/mcl_ec_group.cc + ${CMAKE_CURRENT_LIST_DIR}/mcl_util.cc) + +# Add header files for installation +install(FILES ${CMAKE_CURRENT_LIST_DIR}/mcl_ec_group.h + ${CMAKE_CURRENT_LIST_DIR}/mcl_util.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/ecc/mcl) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(ecc_mcl_test mcl_ec_test.cc) +target_link_libraries(ecc_mcl_test PRIVATE yacl gtest_main) +target_link_options(ecc_mcl_test PRIVATE "-all_load") # for spi +add_test(NAME ecc_mcl_test COMMAND ecc_mcl_test) diff --git a/yacl/crypto/ecc/openssl/CMakeLists.txt b/yacl/crypto/ecc/openssl/CMakeLists.txt new file mode 100644 index 0000000..896b2fc --- /dev/null +++ b/yacl/crypto/ecc/openssl/CMakeLists.txt @@ -0,0 +1,30 @@ +# 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. + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/openssl_factory.cc + ${CMAKE_CURRENT_LIST_DIR}/openssl_group.cc) + +# Add header files for installation +install(FILES ${CMAKE_CURRENT_LIST_DIR}/openssl_group.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/ecc/openssl) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(ecc_openssl_test openssl_test.cc) +target_link_libraries(ecc_openssl_test PRIVATE yacl gtest_main) +target_link_options(ecc_openssl_test PRIVATE "-all_load") # for spi +add_test(NAME ecc_openssl_test COMMAND ecc_openssl_test) diff --git a/yacl/crypto/ecc/toy/CMakeLists.txt b/yacl/crypto/ecc/toy/CMakeLists.txt new file mode 100644 index 0000000..9603604 --- /dev/null +++ b/yacl/crypto/ecc/toy/CMakeLists.txt @@ -0,0 +1,41 @@ +# 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. + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/common.cc + ${CMAKE_CURRENT_LIST_DIR}/factory.cc + ${CMAKE_CURRENT_LIST_DIR}/montgomery.cc + ${CMAKE_CURRENT_LIST_DIR}/weierstrass.cc) + +# Add header files for installation +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/common.h + ${CMAKE_CURRENT_LIST_DIR}/montgomery.h + ${CMAKE_CURRENT_LIST_DIR}/weierstrass.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/ecc/toy) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(ecc_toy_montgomery_test montgomery_test.cc) +target_link_libraries(ecc_toy_montgomery_test PRIVATE yacl gtest_main) +target_link_options(ecc_toy_montgomery_test PRIVATE "-all_load") # for spi +add_test(NAME ecc_toy_montgomery_test COMMAND ecc_toy_montgomery_test) + +add_executable(ecc_toy_weierstrass_test weierstrass_test.cc) +target_link_libraries(ecc_toy_weierstrass_test PRIVATE yacl gtest_main) +target_link_options(ecc_toy_weierstrass_test PRIVATE "-all_load") # for spi +add_test(NAME ecc_toy_weierstrass_test COMMAND ecc_toy_weierstrass_test) diff --git a/yacl/crypto/envelope/CMakeLists.txt b/yacl/crypto/envelope/CMakeLists.txt new file mode 100644 index 0000000..485633f --- /dev/null +++ b/yacl/crypto/envelope/CMakeLists.txt @@ -0,0 +1,29 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/digital_envelope.cc) + +# Add header files for installation +install(FILES ${CMAKE_CURRENT_LIST_DIR}/digital_envelope.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/digital_envelope) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(digital_envelope_test digital_envelope_test.cc) +target_link_libraries(digital_envelope_test PRIVATE yacl gtest_main) +target_link_options(digital_envelope_test PRIVATE "-all_load") # for spi +add_test(NAME digital_envelope_test COMMAND digital_envelope_test) diff --git a/yacl/crypto/experimental/CMakeLists.txt b/yacl/crypto/experimental/CMakeLists.txt new file mode 100644 index 0000000..0a2a3d8 --- /dev/null +++ b/yacl/crypto/experimental/CMakeLists.txt @@ -0,0 +1,22 @@ +# 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. + +add_subdirectory(dpf) +add_subdirectory(sync_drbg) +add_subdirectory(tpre) +add_subdirectory(vss) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) diff --git a/yacl/crypto/experimental/dpf/CMakeLists.txt b/yacl/crypto/experimental/dpf/CMakeLists.txt new file mode 100644 index 0000000..d60a867 --- /dev/null +++ b/yacl/crypto/experimental/dpf/CMakeLists.txt @@ -0,0 +1,44 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/key_utils.cc) + +# Add header files for installation +install(FILES ${CMAKE_CURRENT_LIST_DIR}/key_utils.h + ${CMAKE_CURRENT_LIST_DIR}/openssl_wrappers.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto) + + +add_subdirectory(aead) +add_subdirectory(aes) +add_subdirectory(block_cipher) +# add_subdirectory(ecc) +add_subdirectory(envelope) +# add_subdirectory(experimental) +add_subdirectory(hash) +add_subdirectory(hmac) +# add_subdirectory(pairing) +add_subdirectory(pke) +add_subdirectory(rand) +add_subdirectory(sign) +add_subdirectory(tools) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(key_utils_test key_utils_test.cc) +target_link_libraries(key_utils_test PRIVATE yacl gtest_main) +add_test(NAME key_utils_test COMMAND key_utils_test) diff --git a/yacl/crypto/experimental/sync_drbg/CMakeLists.txt b/yacl/crypto/experimental/sync_drbg/CMakeLists.txt new file mode 100644 index 0000000..d60a867 --- /dev/null +++ b/yacl/crypto/experimental/sync_drbg/CMakeLists.txt @@ -0,0 +1,44 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/key_utils.cc) + +# Add header files for installation +install(FILES ${CMAKE_CURRENT_LIST_DIR}/key_utils.h + ${CMAKE_CURRENT_LIST_DIR}/openssl_wrappers.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto) + + +add_subdirectory(aead) +add_subdirectory(aes) +add_subdirectory(block_cipher) +# add_subdirectory(ecc) +add_subdirectory(envelope) +# add_subdirectory(experimental) +add_subdirectory(hash) +add_subdirectory(hmac) +# add_subdirectory(pairing) +add_subdirectory(pke) +add_subdirectory(rand) +add_subdirectory(sign) +add_subdirectory(tools) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(key_utils_test key_utils_test.cc) +target_link_libraries(key_utils_test PRIVATE yacl gtest_main) +add_test(NAME key_utils_test COMMAND key_utils_test) diff --git a/yacl/crypto/experimental/tpre/CMakeLists.txt b/yacl/crypto/experimental/tpre/CMakeLists.txt new file mode 100644 index 0000000..d60a867 --- /dev/null +++ b/yacl/crypto/experimental/tpre/CMakeLists.txt @@ -0,0 +1,44 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/key_utils.cc) + +# Add header files for installation +install(FILES ${CMAKE_CURRENT_LIST_DIR}/key_utils.h + ${CMAKE_CURRENT_LIST_DIR}/openssl_wrappers.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto) + + +add_subdirectory(aead) +add_subdirectory(aes) +add_subdirectory(block_cipher) +# add_subdirectory(ecc) +add_subdirectory(envelope) +# add_subdirectory(experimental) +add_subdirectory(hash) +add_subdirectory(hmac) +# add_subdirectory(pairing) +add_subdirectory(pke) +add_subdirectory(rand) +add_subdirectory(sign) +add_subdirectory(tools) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(key_utils_test key_utils_test.cc) +target_link_libraries(key_utils_test PRIVATE yacl gtest_main) +add_test(NAME key_utils_test COMMAND key_utils_test) diff --git a/yacl/crypto/experimental/vss/CMakeLists.txt b/yacl/crypto/experimental/vss/CMakeLists.txt new file mode 100644 index 0000000..d60a867 --- /dev/null +++ b/yacl/crypto/experimental/vss/CMakeLists.txt @@ -0,0 +1,44 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/key_utils.cc) + +# Add header files for installation +install(FILES ${CMAKE_CURRENT_LIST_DIR}/key_utils.h + ${CMAKE_CURRENT_LIST_DIR}/openssl_wrappers.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto) + + +add_subdirectory(aead) +add_subdirectory(aes) +add_subdirectory(block_cipher) +# add_subdirectory(ecc) +add_subdirectory(envelope) +# add_subdirectory(experimental) +add_subdirectory(hash) +add_subdirectory(hmac) +# add_subdirectory(pairing) +add_subdirectory(pke) +add_subdirectory(rand) +add_subdirectory(sign) +add_subdirectory(tools) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(key_utils_test key_utils_test.cc) +target_link_libraries(key_utils_test PRIVATE yacl gtest_main) +add_test(NAME key_utils_test COMMAND key_utils_test) diff --git a/yacl/crypto/hash/CMakeLists.txt b/yacl/crypto/hash/CMakeLists.txt new file mode 100644 index 0000000..67f0193 --- /dev/null +++ b/yacl/crypto/hash/CMakeLists.txt @@ -0,0 +1,41 @@ +# 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. + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/ssl_hash.cc + ${CMAKE_CURRENT_LIST_DIR}/blake3.cc ${CMAKE_CURRENT_LIST_DIR}/hash_utils.cc) + +# Add header files for installation +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/ssl_hash.h + ${CMAKE_CURRENT_LIST_DIR}/hash_interface.h + ${CMAKE_CURRENT_LIST_DIR}/hash_utils.h + ${CMAKE_CURRENT_LIST_DIR}/blake3.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/hash) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(blake3_test blake3_test.cc) +target_link_libraries(blake3_test PRIVATE yacl gtest_main) +target_link_options(blake3_test PRIVATE "-all_load") # for spi +add_test(NAME blake3_test COMMAND blake3_test) + +add_executable(ssl_hash_all_test ssl_hash_all_test.cc) +target_link_libraries(ssl_hash_all_test PRIVATE yacl gtest_main) +target_link_options(ssl_hash_all_test PRIVATE "-all_load") # for spi +add_test(NAME ssl_hash_all_test COMMAND ssl_hash_all_test) + +# TODO add benchmark target diff --git a/yacl/crypto/hmac/CMakeLists.txt b/yacl/crypto/hmac/CMakeLists.txt new file mode 100644 index 0000000..df7a0f2 --- /dev/null +++ b/yacl/crypto/hmac/CMakeLists.txt @@ -0,0 +1,30 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/hmac.cc) + +# Add header files for installation +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/hmac.h ${CMAKE_CURRENT_LIST_DIR}/hmac_sha256.h + ${CMAKE_CURRENT_LIST_DIR}/hmac_sm3.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/hmac) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(hmac_all_test hmac_all_test.cc) +target_link_libraries(hmac_all_test PRIVATE yacl gtest_main) +target_link_options(hmac_all_test PRIVATE "-all_load") # for spi +add_test(NAME hmac_all_test COMMAND hmac_all_test) diff --git a/yacl/crypto/pke/CMakeLists.txt b/yacl/crypto/pke/CMakeLists.txt new file mode 100644 index 0000000..ad6d1b1 --- /dev/null +++ b/yacl/crypto/pke/CMakeLists.txt @@ -0,0 +1,37 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/rsa_enc.cc + ${CMAKE_CURRENT_LIST_DIR}/sm2_enc.cc) + +# Add header files for installation +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/rsa_enc.h + ${CMAKE_CURRENT_LIST_DIR}/pke_interface.h + ${CMAKE_CURRENT_LIST_DIR}/sm2_enc.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/pke) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(rsa_enc_test rsa_enc_test.cc) +target_link_libraries(rsa_enc_test PRIVATE yacl gtest_main) +target_link_options(rsa_enc_test PRIVATE "-all_load") # for spi +add_test(NAME rsa_enc_test COMMAND rsa_enc_test) + +add_executable(sm2_enc_test sm2_enc_test.cc) +target_link_libraries(sm2_enc_test PRIVATE yacl gtest_main) +target_link_options(sm2_enc_test PRIVATE "-all_load") # for spi +add_test(NAME sm2_enc_test COMMAND sm2_enc_test) diff --git a/yacl/crypto/rand/CMakeLists.txt b/yacl/crypto/rand/CMakeLists.txt new file mode 100644 index 0000000..b4fc5ee --- /dev/null +++ b/yacl/crypto/rand/CMakeLists.txt @@ -0,0 +1,33 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/rand.cc) + +# Add header files for installation +install(FILES ${CMAKE_CURRENT_LIST_DIR}/rand.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/rand) + +add_subdirectory(drbg) +add_subdirectory(entropy_source) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(rand_test rand_test.cc) +target_link_libraries(rand_test PRIVATE yacl gtest_main) +target_link_options(rand_test PRIVATE "-all_load") # for spi +add_test(NAME rand_test COMMAND rand_test) + +# TODO Add benchmark target diff --git a/yacl/crypto/rand/drbg/CMakeLists.txt b/yacl/crypto/rand/drbg/CMakeLists.txt new file mode 100644 index 0000000..2d53f5c --- /dev/null +++ b/yacl/crypto/rand/drbg/CMakeLists.txt @@ -0,0 +1,33 @@ +# 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. + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/native_factory.cc + ${CMAKE_CURRENT_LIST_DIR}/openssl_factory.cc) + +# Add header files for installation +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/drbg.h + ${CMAKE_CURRENT_LIST_DIR}/native_factory.h + ${CMAKE_CURRENT_LIST_DIR}/openssl_factory.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/rand/drbg) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(drbg_test factory_test.cc) +target_link_libraries(drbg_test PRIVATE yacl gtest_main) +target_link_options(drbg_test PRIVATE "-all_load") # for spi +add_test(NAME drbg_test COMMAND drbg_test) diff --git a/yacl/crypto/rand/entropy_source/CMakeLists.txt b/yacl/crypto/rand/entropy_source/CMakeLists.txt new file mode 100644 index 0000000..331e186 --- /dev/null +++ b/yacl/crypto/rand/entropy_source/CMakeLists.txt @@ -0,0 +1,33 @@ +# 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. + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/urandom_factory.cc + ${CMAKE_CURRENT_LIST_DIR}/rdseed_factory.cc) + +# Add header files for installation +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/entropy_source.h + ${CMAKE_CURRENT_LIST_DIR}/urandom_factory.h + ${CMAKE_CURRENT_LIST_DIR}/rdseed_factory.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/rand/entropy_source) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(es_test factory_test.cc) +target_link_libraries(es_test PRIVATE yacl gtest_main) +target_link_options(es_test PRIVATE "-all_load") # for spi +add_test(NAME es_test COMMAND es_test) diff --git a/yacl/crypto/sign/CMakeLists.txt b/yacl/crypto/sign/CMakeLists.txt new file mode 100644 index 0000000..5d2da8a --- /dev/null +++ b/yacl/crypto/sign/CMakeLists.txt @@ -0,0 +1,38 @@ +# 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. + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/rsa_signing.cc + ${CMAKE_CURRENT_LIST_DIR}/sm2_signing.cc) + +# Add header files for installation +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/rsa_signing.h + ${CMAKE_CURRENT_LIST_DIR}/signing.h + ${CMAKE_CURRENT_LIST_DIR}/sm2_signing.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/sign) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(rsa_signing_test rsa_signing_test.cc) +target_link_libraries(rsa_signing_test PRIVATE yacl gtest_main) +target_link_options(rsa_signing_test PRIVATE "-all_load") # for spi +add_test(NAME rsa_signing_test COMMAND rsa_signing_test) + +add_executable(sm2_signing_test sm2_signing_test.cc) +target_link_libraries(sm2_signing_test PRIVATE yacl gtest_main) +target_link_options(sm2_signing_test PRIVATE "-all_load") # for spi +add_test(NAME sm2_signing_test COMMAND sm2_signing_test) diff --git a/yacl/crypto/tools/CMakeLists.txt b/yacl/crypto/tools/CMakeLists.txt new file mode 100644 index 0000000..665c4b1 --- /dev/null +++ b/yacl/crypto/tools/CMakeLists.txt @@ -0,0 +1,50 @@ +# 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. + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/crhash.cc + ${CMAKE_CURRENT_LIST_DIR}/prg.cc ${CMAKE_CURRENT_LIST_DIR}/rp.cc) + +# Add header files for installation +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/common.h ${CMAKE_CURRENT_LIST_DIR}/crhash.h + ${CMAKE_CURRENT_LIST_DIR}/prg.h ${CMAKE_CURRENT_LIST_DIR}/ro.h + ${CMAKE_CURRENT_LIST_DIR}/rp.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/tools) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(crhash_test crhash_test.cc) +target_link_libraries(crhash_test PRIVATE yacl gtest_main) +target_link_options(crhash_test PRIVATE "-all_load") # for spi +add_test(NAME crhash_test COMMAND crhash_test) + +add_executable(prg_test prg_test.cc) +target_link_libraries(prg_test PRIVATE yacl gtest_main) +target_link_options(prg_test PRIVATE "-all_load") # for spi +add_test(NAME prg_test COMMAND prg_test) + +add_executable(ro_test ro_test.cc) +target_link_libraries(ro_test PRIVATE yacl gtest_main) +target_link_options(ro_test PRIVATE "-all_load") # for spi +add_test(NAME ro_test COMMAND ro_test) + +add_executable(rp_test rp_test.cc) +target_link_libraries(rp_test PRIVATE yacl gtest_main) +target_link_options(rp_test PRIVATE "-all_load") # for spi +add_test(NAME rp_test COMMAND rp_test) + +# TODO add benchmark target diff --git a/yacl/crypto/tools/ro_test.cc b/yacl/crypto/tools/ro_test.cc index de639c2..96d69c7 100644 --- a/yacl/crypto/tools/ro_test.cc +++ b/yacl/crypto/tools/ro_test.cc @@ -14,9 +14,6 @@ #include "yacl/crypto/tools/ro.h" -#include -#include - #include "gtest/gtest.h" #include "yacl/base/byte_container_view.h" @@ -34,14 +31,20 @@ TEST_P(RandomOracleTest, Default) { const auto& param = GetParam(); const auto& RO = RandomOracle::GetDefault(); auto input = FastRandBytes(param); - EXPECT_EQ(RO.Gen(input), RO.Gen(input)); + auto out1 = RO.Gen(input); + auto out2 = RO.Gen(input); + EXPECT_EQ(out1.size(), out2.size()); + EXPECT_EQ(memcmp(out1.data(), out2.data(), out1.size()), 0); } TEST_P(RandomOracleTest, OutLen8) { const auto& param = GetParam(); auto RO = RandomOracle(HashAlgorithm::BLAKE3, 8); auto input = FastRandBytes(param); - EXPECT_EQ(RO.Gen(input), RO.Gen(input)); + auto out1 = RO.Gen(input); + auto out2 = RO.Gen(input); + EXPECT_EQ(out1.size(), out2.size()); + EXPECT_EQ(memcmp(out1.data(), out2.data(), out1.size()), 0); } TEST(RandomOracleTest, EdgeTest1) { diff --git a/yacl/io/CMakeLists.txt b/yacl/io/CMakeLists.txt new file mode 100644 index 0000000..d002cdf --- /dev/null +++ b/yacl/io/CMakeLists.txt @@ -0,0 +1,7 @@ +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES}) + +add_subdirectory(msgpack) +add_subdirectory(rw) +add_subdirectory(stream) + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} PARENT_SCOPE) diff --git a/yacl/io/msgpack/CMakeLists.txt b/yacl/io/msgpack/CMakeLists.txt new file mode 100644 index 0000000..7dc7c53 --- /dev/null +++ b/yacl/io/msgpack/CMakeLists.txt @@ -0,0 +1,32 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/spec_traits.cc +) + +# Add header files for installation +install( + FILES + ${CMAKE_CURRENT_LIST_DIR}/buffer.h + ${CMAKE_CURRENT_LIST_DIR}/spec_traits.h + DESTINATION + ${CMAKE_INSTALL_INCLUDEDIR}/yacl/io/stream +) + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} PARENT_SCOPE) + +add_executable(msgpack_buffer_test buffer_test.cc) +target_link_libraries(msgpack_buffer_test PRIVATE yacl gtest_main) +add_test(NAME msgpack_buffer_test COMMAND msgpack_buffer_test) diff --git a/yacl/io/rw/CMakeLists.txt b/yacl/io/rw/CMakeLists.txt new file mode 100644 index 0000000..a2e718a --- /dev/null +++ b/yacl/io/rw/CMakeLists.txt @@ -0,0 +1,38 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/csv_reader.cc + ${CMAKE_CURRENT_LIST_DIR}/csv_writer.cc + ${CMAKE_CURRENT_LIST_DIR}/mmapped_file.cc +) + +# Add header files for installation +install( + FILES + ${CMAKE_CURRENT_LIST_DIR}/csv_reader.h + ${CMAKE_CURRENT_LIST_DIR}/csv_writer.h + ${CMAKE_CURRENT_LIST_DIR}/mmapped_file.h + ${CMAKE_CURRENT_LIST_DIR}/reader.h + ${CMAKE_CURRENT_LIST_DIR}/writer.h + ${CMAKE_CURRENT_LIST_DIR}/schema.h + DESTINATION + ${CMAKE_INSTALL_INCLUDEDIR}/yacl/io/stream +) + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} PARENT_SCOPE) + +add_executable(rw_test rw_test.cc) +target_link_libraries(rw_test PRIVATE yacl gtest_main gflags) +add_test(NAME rw_test COMMAND rw_test WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) diff --git a/yacl/io/stream/CMakeLists.txt b/yacl/io/stream/CMakeLists.txt new file mode 100644 index 0000000..5055d51 --- /dev/null +++ b/yacl/io/stream/CMakeLists.txt @@ -0,0 +1,34 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/file_io.cc + ${CMAKE_CURRENT_LIST_DIR}/mem_io.cc +) + +# Add header files for installation +install( + FILES + ${CMAKE_CURRENT_LIST_DIR}/file_io.h + ${CMAKE_CURRENT_LIST_DIR}/interface.h + ${CMAKE_CURRENT_LIST_DIR}/mem_io.h + DESTINATION + ${CMAKE_INSTALL_INCLUDEDIR}/yacl/io/stream +) + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} PARENT_SCOPE) + +add_executable(io_stream_test test.cc) +target_link_libraries(io_stream_test PRIVATE yacl gtest_main) +add_test(NAME io_stream_test COMMAND io_stream_test) diff --git a/yacl/math/CMakeLists.txt b/yacl/math/CMakeLists.txt new file mode 100644 index 0000000..819b56c --- /dev/null +++ b/yacl/math/CMakeLists.txt @@ -0,0 +1,25 @@ +# 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. + +# Add header files for installation +install(FILES ${CMAKE_CURRENT_LIST_DIR}/gadget.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/math) + +add_subdirectory(galois_field) +add_subdirectory(mpint) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + diff --git a/yacl/math/galois_field/CMakeLists.txt b/yacl/math/galois_field/CMakeLists.txt new file mode 100644 index 0000000..67fa8cf --- /dev/null +++ b/yacl/math/galois_field/CMakeLists.txt @@ -0,0 +1,37 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/gf_intrinsic.cc) + +# Add header files for installation +install(FILES ${CMAKE_CURRENT_LIST_DIR}/gf.h + ${CMAKE_CURRENT_LIST_DIR}/gf_instrinsic.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/math/galois_field) + +add_subdirectory(factory) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(gf_test gf_test.cc) +target_link_libraries(gf_test PRIVATE yacl gtest_main) +target_link_options(gf_test PRIVATE "-all_load") # for spi +add_test(NAME gf_test COMMAND gf_test) + +add_executable(gf_intrinsic_test gf_intrinsic_test.cc) +target_link_libraries(gf_intrinsic_test PRIVATE yacl gtest_main) +target_link_options(gf_intrinsic_test PRIVATE "-all_load") # for spi +add_test(NAME gf_intrinsic_test COMMAND gf_intrinsic_test) diff --git a/yacl/math/galois_field/factory/CMakeLists.txt b/yacl/math/galois_field/factory/CMakeLists.txt new file mode 100644 index 0000000..a1a5ee9 --- /dev/null +++ b/yacl/math/galois_field/factory/CMakeLists.txt @@ -0,0 +1,50 @@ +# 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. + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/gf_spi.cc + ${CMAKE_CURRENT_LIST_DIR}/mcl_factory.cc + ${CMAKE_CURRENT_LIST_DIR}/intel_factory.cc + ${CMAKE_CURRENT_LIST_DIR}/mpint_factory.cc) + +# Add header files for installation +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/gf_scalar.h + ${CMAKE_CURRENT_LIST_DIR}/gf_vector.h + ${CMAKE_CURRENT_LIST_DIR}/gf_spi.h + ${CMAKE_CURRENT_LIST_DIR}/mcl_factory.h + ${CMAKE_CURRENT_LIST_DIR}/intel_factory.h + ${CMAKE_CURRENT_LIST_DIR}/mpint_factory.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/math/galois_field/factory) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(mcl_factory_test mcl_factory_test.cc) +target_link_libraries(mcl_factory_test PRIVATE yacl gtest_main) +target_link_options(mcl_factory_test PRIVATE "-all_load") # for spi +add_test(NAME mcl_factory_test COMMAND mcl_factory_test) + +add_executable(mpint_factory_test mpint_factory_test.cc) +target_link_libraries(mpint_factory_test PRIVATE yacl gtest_main) +target_link_options(mpint_factory_test PRIVATE "-all_load") # for spi +add_test(NAME mpint_factory_test COMMAND mpint_factory_test) + +add_executable(intel_factory_test intel_factory_test.cc) +target_link_libraries(intel_factory_test PRIVATE yacl gtest_main) +target_link_options(intel_factory_test PRIVATE "-all_load") # for spi +add_link_options("-lc++") # for spi +add_test(NAME intel_factory_test COMMAND intel_factory_test) diff --git a/yacl/math/galois_field/factory/intel_factory.cc b/yacl/math/galois_field/factory/intel_factory.cc index b1d083a..88ed333 100644 --- a/yacl/math/galois_field/factory/intel_factory.cc +++ b/yacl/math/galois_field/factory/intel_factory.cc @@ -18,6 +18,16 @@ #include #include "yacl/base/block.h" +#include "yacl/base/int128.h" +#ifndef __aarch64__ +// sse +#include +#include +// pclmul +#include +#else +#include "sse2neon.h" +#endif namespace yacl::math { @@ -232,4 +242,4 @@ bool IntrinsicFieldFactory::Check(const std::string& field_name, } } -}; // namespace yacl::math +} // namespace yacl::math diff --git a/yacl/math/galois_field/factory/intel_factory_test.cc b/yacl/math/galois_field/factory/intel_factory_test.cc index 59fc7fb..5498ab4 100644 --- a/yacl/math/galois_field/factory/intel_factory_test.cc +++ b/yacl/math/galois_field/factory/intel_factory_test.cc @@ -12,9 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/math/galois_field/factory/intel_factory.h" - -#include +#include "yacl/math/galois_field/gf.h" #include "gtest/gtest.h" diff --git a/yacl/math/mpint/CMakeLists.txt b/yacl/math/mpint/CMakeLists.txt new file mode 100644 index 0000000..755dbfd --- /dev/null +++ b/yacl/math/mpint/CMakeLists.txt @@ -0,0 +1,50 @@ +# 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. + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/montgomery_math.cc + ${CMAKE_CURRENT_LIST_DIR}/mp_int.cc + ${CMAKE_CURRENT_LIST_DIR}/tommath_ext_types.cc + ${CMAKE_CURRENT_LIST_DIR}/tommath_ext_features.cc) + +# Add header files for installation +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/montgomery_math.h + ${CMAKE_CURRENT_LIST_DIR}/mp_int.h + ${CMAKE_CURRENT_LIST_DIR}/mp_int_enforce.h + ${CMAKE_CURRENT_LIST_DIR}/tommath_ext_types.h + ${CMAKE_CURRENT_LIST_DIR}/tommath_ext_features.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/math/mpint) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(montgomery_math_test montgomery_math_test.cc) +target_link_libraries(montgomery_math_test PRIVATE yacl gtest_main) +target_link_options(montgomery_math_test PRIVATE "-all_load") # for spi +add_test(NAME montgomery_math_test COMMAND montgomery_math_test) + +add_executable(mp_int_test mp_int_test.cc) +target_link_libraries(mp_int_test PRIVATE yacl gtest_main) +target_link_options(mp_int_test PRIVATE "-all_load") # for spi +add_test(NAME mp_int_test COMMAND mp_int_test) + +add_executable(tommath_ext_test tommath_ext_test.cc) +target_link_libraries(tommath_ext_test PRIVATE yacl gtest_main) +target_link_options(tommath_ext_test PRIVATE "-all_load") # for spi +add_test(NAME tommath_ext_test COMMAND tommath_ext_test) + +# TODO add benchmark target diff --git a/yacl/math/mpint/mp_int_test.cc b/yacl/math/mpint/mp_int_test.cc index 1eb20b9..eba134f 100644 --- a/yacl/math/mpint/mp_int_test.cc +++ b/yacl/math/mpint/mp_int_test.cc @@ -342,7 +342,10 @@ TEST_F(MPIntTest, ToBytesWorks) { EXPECT_EQ(buf.data()[0], 0x3456); a = MPInt(-1); - EXPECT_EQ(a.ToBytes(10, Endian::little), a.ToBytes(10, Endian::big)); + auto out1 =a.ToBytes(10, Endian::little); + auto out2 =a.ToBytes(10, Endian::big); + EXPECT_EQ(out1.size(), out2.size()); + EXPECT_EQ(memcmp(out1.data(), out2.data(), out1.size()), 0); } TEST_F(MPIntTest, MsgpackWorks) { diff --git a/yacl/utils/CMakeLists.txt b/yacl/utils/CMakeLists.txt new file mode 100644 index 0000000..dda4c53 --- /dev/null +++ b/yacl/utils/CMakeLists.txt @@ -0,0 +1,37 @@ +# 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. + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/parallel.cc + ${CMAKE_CURRENT_LIST_DIR}/thread_pool.cc + ${CMAKE_CURRENT_LIST_DIR}/elapsed_timer.cc +) + +# Add header files for installation +install( + FILES + ${CMAKE_CURRENT_LIST_DIR}/parallel.h + ${CMAKE_CURRENT_LIST_DIR}/thread_pool.h + ${CMAKE_CURRENT_LIST_DIR}/elapsed_timer.h + DESTINATION + ${CMAKE_INSTALL_INCLUDEDIR}/yacl/utils +) + +add_subdirectory(spi) + +set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} PARENT_SCOPE) + +add_executable(parallel_test parallel_test.cc) +target_link_libraries(parallel_test PRIVATE yacl gtest_main) +add_test(NAME parallel_test COMMAND parallel_test) diff --git a/yacl/utils/spi/CMakeLists.txt b/yacl/utils/spi/CMakeLists.txt new file mode 100644 index 0000000..3a0d0f7 --- /dev/null +++ b/yacl/utils/spi/CMakeLists.txt @@ -0,0 +1,49 @@ +# 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. + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + ${CMAKE_CURRENT_LIST_DIR}/item.cc + ${CMAKE_CURRENT_LIST_DIR}/argument/arg_kv.cc + ${CMAKE_CURRENT_LIST_DIR}/argument/arg_set.cc + ${CMAKE_CURRENT_LIST_DIR}/argument/argument.cc + ${CMAKE_CURRENT_LIST_DIR}/argument/util.cc) + +# Add header files for installation +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/item.h + ${CMAKE_CURRENT_LIST_DIR}/spi_factory.h + ${CMAKE_CURRENT_LIST_DIR}/type_traits.h + ${CMAKE_CURRENT_LIST_DIR}/argument/arg_kv.h + ${CMAKE_CURRENT_LIST_DIR}/sketch/scalar_call.h + ${CMAKE_CURRENT_LIST_DIR}/sketch/scalar_define.h + ${CMAKE_CURRENT_LIST_DIR}/sketch/scalar_tools.h + ${CMAKE_CURRENT_LIST_DIR}/argument/arg_k.h + ${CMAKE_CURRENT_LIST_DIR}/argument/arg_set.h + ${CMAKE_CURRENT_LIST_DIR}/argument/argument.h + ${CMAKE_CURRENT_LIST_DIR}/argument/util.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/utils/spi) + +set(YACL_SOURCE_FILES + ${YACL_SOURCE_FILES} + PARENT_SCOPE) + +add_executable(util_test argument/util_test.cc) +target_link_libraries(util_test PRIVATE yacl gtest_main) +add_test(NAME util_test COMMAND util_test) + +add_executable(spi_factory_test spi_factory_test.cc) +target_link_libraries(spi_factory_test PRIVATE yacl gtest_main) +add_test(NAME +spi_factory_test COMMAND spi_factory_test) From b5b29f361efb63b643eaa7345c7efd776582eff0 Mon Sep 17 00:00:00 2001 From: Jamie Cui Date: Wed, 30 Oct 2024 21:00:07 +0800 Subject: [PATCH 2/2] fix: add license for io cmake file --- yacl/io/CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/yacl/io/CMakeLists.txt b/yacl/io/CMakeLists.txt index d002cdf..e3328fb 100644 --- a/yacl/io/CMakeLists.txt +++ b/yacl/io/CMakeLists.txt @@ -1,3 +1,17 @@ +# 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. + set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES}) add_subdirectory(msgpack)