From db0668feb0722bc90244a742b9676cfe237cb2f8 Mon Sep 17 00:00:00 2001 From: Jamie Cui Date: Fri, 15 Nov 2024 17:25:10 +0800 Subject: [PATCH] chore(XXXXL): huge cleanup --- CMakeLists.txt | 4 +- bazel/hash_drbg.BUILD | 2 +- cmake/ExternalOpenSSL.cmake | 4 +- examples/cmake-project/.keep | 0 yacl/BUILD.bazel | 39 -------- yacl/CMakeLists.txt | 29 ------ yacl/base/BUILD.bazel | 22 +++++ yacl/base/CMakeLists.txt | 9 +- yacl/{ => base}/secparam.cc | 2 +- yacl/{ => base}/secparam.h | 0 yacl/{ => base}/secparam_test.cc | 2 +- yacl/crypto/BUILD.bazel | 8 +- yacl/crypto/CMakeLists.txt | 2 +- yacl/crypto/aead/BUILD.bazel | 4 +- yacl/crypto/aead/all_gcm.cc | 10 +-- yacl/crypto/aead/all_gcm.h | 2 +- yacl/crypto/aead/sm4_mte.h | 2 +- yacl/crypto/aes/BUILD.bazel | 2 +- yacl/crypto/aes/aes_intrinsics.h | 2 +- yacl/crypto/block_cipher/BUILD.bazel | 4 +- yacl/crypto/block_cipher/symmetric_crypto.cc | 14 +-- yacl/crypto/block_cipher/symmetric_crypto.h | 8 +- yacl/crypto/ecc/openssl/BUILD.bazel | 2 +- yacl/crypto/ecc/openssl/openssl_factory.cc | 4 +- yacl/crypto/ecc/openssl/openssl_group.cc | 6 +- yacl/crypto/ecc/openssl/openssl_group.h | 6 +- yacl/crypto/ecc/openssl/openssl_test.cc | 8 +- yacl/crypto/experimental/dpf/CMakeLists.txt | 2 +- yacl/crypto/experimental/dpf/dcf.cc | 2 +- yacl/crypto/experimental/dpf/dcf.h | 2 +- yacl/crypto/experimental/dpf/dpf.cc | 2 +- yacl/crypto/experimental/dpf/dpf.h | 2 +- .../crypto/experimental/sync_drbg/BUILD.bazel | 4 +- .../experimental/sync_drbg/CMakeLists.txt | 2 +- .../crypto/experimental/sync_drbg/sync_drbg.h | 6 +- yacl/crypto/experimental/tpre/CMakeLists.txt | 2 +- yacl/crypto/experimental/vss/CMakeLists.txt | 2 +- yacl/crypto/hash/BUILD.bazel | 6 +- yacl/crypto/hash/hash_interface.h | 2 +- yacl/crypto/hash/ssl_hash.cc | 8 +- yacl/crypto/hash/ssl_hash.h | 6 +- yacl/crypto/hmac/BUILD.bazel | 2 +- yacl/crypto/hmac/hmac.cc | 8 +- yacl/crypto/hmac/hmac.h | 6 +- yacl/crypto/key_utils.cc | 90 +++++++++---------- yacl/crypto/key_utils.h | 58 ++++++------ .../{openssl_wrappers.h => ossl_wrappers.h} | 6 +- yacl/crypto/pke/BUILD.bazel | 4 +- yacl/crypto/pke/rsa_enc.cc | 4 +- yacl/crypto/pke/rsa_enc.h | 10 +-- yacl/crypto/pke/rsa_enc_test.cc | 2 +- yacl/crypto/pke/sm2_enc.cc | 4 +- yacl/crypto/pke/sm2_enc.h | 10 +-- yacl/crypto/pke/sm2_enc_test.cc | 2 +- yacl/crypto/rand/BUILD.bazel | 2 +- yacl/crypto/rand/drbg/BUILD.bazel | 14 +-- yacl/crypto/rand/drbg/drbg.h | 2 +- yacl/crypto/rand/drbg/native_factory.cc | 10 +-- yacl/crypto/rand/drbg/native_factory.h | 8 +- yacl/crypto/rand/drbg/openssl_factory.cc | 18 ++-- yacl/crypto/rand/drbg/openssl_factory.h | 4 +- yacl/crypto/rand/entropy_source/BUILD.bazel | 2 +- .../rand/entropy_source/entropy_source.h | 2 +- yacl/crypto/rand/rand.cc | 2 +- yacl/crypto/rand/rand.h | 4 +- yacl/crypto/rand/rand_bench.cc | 2 +- yacl/crypto/sign/BUILD.bazel | 4 +- yacl/crypto/sign/rsa_signing.cc | 4 +- yacl/crypto/sign/rsa_signing.h | 10 +-- yacl/crypto/sign/rsa_signing_test.cc | 2 +- yacl/crypto/sign/sm2_signing.cc | 8 +- yacl/crypto/sign/sm2_signing.h | 10 +-- yacl/crypto/sign/sm2_signing_test.cc | 2 +- yacl/crypto/tools/BUILD.bazel | 2 +- yacl/crypto/tools/prg.h | 2 +- yacl/kernel/algorithms/BUILD.bazel | 26 +++--- yacl/kernel/algorithms/base_ot.h | 2 +- yacl/kernel/algorithms/base_vole.h | 2 +- yacl/kernel/algorithms/ferret_ote.h | 2 +- yacl/kernel/algorithms/ferret_ote_rn.h | 2 +- yacl/kernel/algorithms/ferret_ote_un.h | 2 +- yacl/kernel/algorithms/gywz_ote.h | 2 +- yacl/kernel/algorithms/iknp_ote.h | 2 +- yacl/kernel/algorithms/kkrt_ote.h | 2 +- yacl/kernel/algorithms/kos_ote.h | 2 +- yacl/kernel/algorithms/mp_vole.h | 2 +- yacl/kernel/algorithms/mpfss.h | 2 +- .../kernel/algorithms/portable_ot_interface.h | 2 +- yacl/kernel/algorithms/sgrr_ote.h | 2 +- yacl/kernel/algorithms/silent_vole.h | 2 +- yacl/kernel/algorithms/softspoken_ote.h | 2 +- yacl/kernel/algorithms/x86_asm_ot_interface.h | 2 +- yacl/kernel/ot_kernel.cc | 2 +- yacl/kernel/ot_kernel.h | 2 +- yacl/{crypto => }/ossl_provider/BUILD.bazel | 4 +- yacl/{crypto => }/ossl_provider/helper.h | 2 +- .../ossl_provider/linux_exported_syms.lds | 0 .../ossl_provider/macos_exported_syms.lds | 0 yacl/{crypto => }/ossl_provider/provider.cc | 4 +- .../ossl_provider/provider_test.cc | 8 +- yacl/{crypto => }/ossl_provider/rand_impl.h | 2 +- yacl/{crypto => }/ossl_provider/version.h | 0 102 files changed, 304 insertions(+), 343 deletions(-) create mode 100644 examples/cmake-project/.keep delete mode 100644 yacl/BUILD.bazel delete mode 100644 yacl/CMakeLists.txt rename yacl/{ => base}/secparam.cc (96%) rename yacl/{ => base}/secparam.h (100%) rename yacl/{ => base}/secparam_test.cc (98%) rename yacl/crypto/{openssl_wrappers.h => ossl_wrappers.h} (96%) rename yacl/{crypto => }/ossl_provider/BUILD.bazel (95%) rename yacl/{crypto => }/ossl_provider/helper.h (96%) rename yacl/{crypto => }/ossl_provider/linux_exported_syms.lds (100%) rename yacl/{crypto => }/ossl_provider/macos_exported_syms.lds (100%) rename yacl/{crypto => }/ossl_provider/provider.cc (97%) rename yacl/{crypto => }/ossl_provider/provider_test.cc (96%) rename yacl/{crypto => }/ossl_provider/rand_impl.h (99%) rename yacl/{crypto => }/ossl_provider/version.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a4f69c5..8d8f668 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,7 +130,7 @@ target_link_libraries( ExtFourQ::fourq) if(YACL_WITH_EXT_OPENSSL) - target_link_libraries(yacl PUBLIC ExtOpenSSL::Crypto ExtOpenSSL::SSL) + target_link_libraries(yacl PUBLIC Extossl::Crypto Extossl::SSL) else() - target_link_libraries(yacl PUBLIC OpenSSL::Crypto OpenSSL::SSL) + target_link_libraries(yacl PUBLIC ossl::Crypto ossl::SSL) endif() diff --git a/bazel/hash_drbg.BUILD b/bazel/hash_drbg.BUILD index 025628c..50870c3 100644 --- a/bazel/hash_drbg.BUILD +++ b/bazel/hash_drbg.BUILD @@ -24,6 +24,6 @@ cc_library( copts = ["-Wno-parentheses"], visibility = ["//visibility:public"], deps = [ - "@yacl//yacl/crypto:openssl_wrappers", + "@yacl//yacl/crypto:ossl_wrappers", ], ) diff --git a/cmake/ExternalOpenSSL.cmake b/cmake/ExternalOpenSSL.cmake index 14f47be..a7fc751 100644 --- a/cmake/ExternalOpenSSL.cmake +++ b/cmake/ExternalOpenSSL.cmake @@ -53,11 +53,11 @@ if(YACL_WITH_EXT_OPENSSL) set_target_properties( ExtOpenSSL_Crypto PROPERTIES IMPORTED_LOCATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libcrypto.a) - add_library(ExtOpenSSL::Crypto ALIAS ExtOpenSSL_Crypto) + add_library(Extossl::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) + add_library(Extossl::SSL ALIAS ExtOpenSSL_SSL) endif() diff --git a/examples/cmake-project/.keep b/examples/cmake-project/.keep new file mode 100644 index 0000000..e69de29 diff --git a/yacl/BUILD.bazel b/yacl/BUILD.bazel deleted file mode 100644 index 77d192f..0000000 --- a/yacl/BUILD.bazel +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2022 Ant Group Co., Ltd. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -load("//bazel:yacl.bzl", "yacl_cc_library", "yacl_cc_test") - -package(default_visibility = ["//visibility:public"]) - -yacl_cc_library( - name = "secparam", - srcs = ["secparam.cc"], - hdrs = [ - "secparam.h", - ], - deps = [ - "//yacl/base:exception", - "//yacl/base:int128", - "//yacl/math:gadget", - "//yacl/utils:compile_time_utils", - ], -) - -yacl_cc_test( - name = "secparam_test", - srcs = ["secparam_test.cc"], - deps = [ - ":secparam", - ], -) diff --git a/yacl/CMakeLists.txt b/yacl/CMakeLists.txt deleted file mode 100644 index 9841fd6..0000000 --- a/yacl/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2024 Ant Group Co., Ltd. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. - -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/BUILD.bazel b/yacl/base/BUILD.bazel index a4afa04..de17005 100644 --- a/yacl/base/BUILD.bazel +++ b/yacl/base/BUILD.bazel @@ -158,3 +158,25 @@ yacl_cc_library( name = "aligned_vector", srcs = ["aligned_vector.h"], ) + +yacl_cc_library( + name = "secparam", + srcs = ["secparam.cc"], + hdrs = [ + "secparam.h", + ], + deps = [ + ":exception", + ":int128", + "//yacl/math:gadget", + "//yacl/utils:compile_time_utils", + ], +) + +yacl_cc_test( + name = "secparam_test", + srcs = ["secparam_test.cc"], + deps = [ + ":secparam", + ], +) diff --git a/yacl/base/CMakeLists.txt b/yacl/base/CMakeLists.txt index 0df2bf7..a80cbed 100644 --- a/yacl/base/CMakeLists.txt +++ b/yacl/base/CMakeLists.txt @@ -14,12 +14,14 @@ set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/exception.cc - ${CMAKE_CURRENT_LIST_DIR}/int128.cc) + ${CMAKE_CURRENT_LIST_DIR}/int128.cc + ${CMAKE_CURRENT_LIST_DIR}/secparam.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}/secparam.h ${CMAKE_CURRENT_LIST_DIR}/buffer.h ${CMAKE_CURRENT_LIST_DIR}/byte_container_view.h ${CMAKE_CURRENT_LIST_DIR}/dynamic_bitset.h @@ -35,3 +37,8 @@ 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) + +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/secparam.cc b/yacl/base/secparam.cc similarity index 96% rename from yacl/secparam.cc rename to yacl/base/secparam.cc index 71db57f..39df8b0 100644 --- a/yacl/secparam.cc +++ b/yacl/base/secparam.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" namespace yacl::crypto { SecParam::C SecParam::glob_c = SecParam::C::INF; // init to infinity diff --git a/yacl/secparam.h b/yacl/base/secparam.h similarity index 100% rename from yacl/secparam.h rename to yacl/base/secparam.h diff --git a/yacl/secparam_test.cc b/yacl/base/secparam_test.cc similarity index 98% rename from yacl/secparam_test.cc rename to yacl/base/secparam_test.cc index 369870e..949e6bb 100644 --- a/yacl/secparam_test.cc +++ b/yacl/base/secparam_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" #include "gtest/gtest.h" diff --git a/yacl/crypto/BUILD.bazel b/yacl/crypto/BUILD.bazel index ae77c7c..10ea643 100644 --- a/yacl/crypto/BUILD.bazel +++ b/yacl/crypto/BUILD.bazel @@ -17,9 +17,9 @@ load("//bazel:yacl.bzl", "yacl_cc_library", "yacl_cc_test") package(default_visibility = ["//visibility:public"]) yacl_cc_library( - name = "openssl_wrappers", + name = "ossl_wrappers", hdrs = [ - "openssl_wrappers.h", + "ossl_wrappers.h", ], deps = [ "//yacl/base:byte_container_view", @@ -38,8 +38,8 @@ yacl_cc_library( "key_utils.h", ], deps = [ - ":openssl_wrappers", - "//yacl:secparam", + ":ossl_wrappers", + "//yacl/base:secparam", "//yacl/crypto/hash:hash_interface", "//yacl/io/stream", ], diff --git a/yacl/crypto/CMakeLists.txt b/yacl/crypto/CMakeLists.txt index 19d676a..0f713df 100644 --- a/yacl/crypto/CMakeLists.txt +++ b/yacl/crypto/CMakeLists.txt @@ -17,7 +17,7 @@ set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} # Add header files for installation install(FILES ${CMAKE_CURRENT_LIST_DIR}/key_utils.h - ${CMAKE_CURRENT_LIST_DIR}/openssl_wrappers.h + ${CMAKE_CURRENT_LIST_DIR}/ossl_wrappers.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto) add_subdirectory(aead) diff --git a/yacl/crypto/aead/BUILD.bazel b/yacl/crypto/aead/BUILD.bazel index 42c0095..6a27d9d 100644 --- a/yacl/crypto/aead/BUILD.bazel +++ b/yacl/crypto/aead/BUILD.bazel @@ -21,7 +21,7 @@ yacl_cc_library( srcs = ["all_gcm.cc"], hdrs = ["all_gcm.h"], deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:int128", "//yacl/crypto:key_utils", ], @@ -40,7 +40,7 @@ yacl_cc_library( srcs = ["sm4_mte.cc"], hdrs = ["sm4_mte.h"], deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/crypto/block_cipher:symmetric_crypto", "//yacl/crypto/hash:ssl_hash", "//yacl/crypto/hmac:hmac_sm3", diff --git a/yacl/crypto/aead/all_gcm.cc b/yacl/crypto/aead/all_gcm.cc index 390560e..63cfeba 100644 --- a/yacl/crypto/aead/all_gcm.cc +++ b/yacl/crypto/aead/all_gcm.cc @@ -14,7 +14,7 @@ #include "yacl/crypto/aead/all_gcm.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" namespace yacl::crypto { @@ -47,9 +47,9 @@ void GcmCrypto::Encrypt(ByteContainerView plaintext, ByteContainerView aad, YACL_ENFORCE_EQ(mac.size(), GetMacSize(schema_)); // init openssl evp cipher context - auto ctx = openssl::UniqueCipherCtx(EVP_CIPHER_CTX_new()); + auto ctx = ossl::UniqueCipherCtx(EVP_CIPHER_CTX_new()); YACL_ENFORCE(ctx != nullptr, "Failed to new evp cipher context."); - const auto cipher = openssl::FetchEvpCipher(ToString(schema_)); + const auto cipher = ossl::FetchEvpCipher(ToString(schema_)); YACL_ENFORCE(cipher != nullptr); YACL_ENFORCE(key_.size() == (size_t)EVP_CIPHER_key_length(cipher.get())); YACL_ENFORCE(iv_.size() == (size_t)EVP_CIPHER_iv_length(cipher.get())); @@ -83,11 +83,11 @@ void GcmCrypto::Decrypt(ByteContainerView ciphertext, ByteContainerView aad, YACL_ENFORCE_EQ(mac.size(), GetMacSize(schema_)); // init openssl evp cipher context - auto ctx = openssl::UniqueCipherCtx(EVP_CIPHER_CTX_new()); + auto ctx = ossl::UniqueCipherCtx(EVP_CIPHER_CTX_new()); YACL_ENFORCE(ctx.get(), "Failed to new evp cipher context."); - const auto cipher = openssl::FetchEvpCipher(ToString(schema_)); + const auto cipher = ossl::FetchEvpCipher(ToString(schema_)); YACL_ENFORCE_EQ(key_.size(), (size_t)EVP_CIPHER_key_length(cipher.get())); YACL_ENFORCE_EQ(iv_.size(), (size_t)EVP_CIPHER_iv_length(cipher.get())); YACL_ENFORCE(EVP_DecryptInit_ex(ctx.get(), cipher.get(), nullptr, key_.data(), diff --git a/yacl/crypto/aead/all_gcm.h b/yacl/crypto/aead/all_gcm.h index 601cbc3..647d2c4 100644 --- a/yacl/crypto/aead/all_gcm.h +++ b/yacl/crypto/aead/all_gcm.h @@ -19,7 +19,7 @@ #include "absl/types/span.h" #include "yacl/base/byte_container_view.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* security parameter declaration */ YACL_MODULE_DECLARE("all_gcm", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/aead/sm4_mte.h b/yacl/crypto/aead/sm4_mte.h index ff7b72d..0b5e211 100644 --- a/yacl/crypto/aead/sm4_mte.h +++ b/yacl/crypto/aead/sm4_mte.h @@ -17,7 +17,7 @@ #include #include "yacl/base/byte_container_view.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* submodules */ #include "yacl/crypto/block_cipher/symmetric_crypto.h" diff --git a/yacl/crypto/aes/BUILD.bazel b/yacl/crypto/aes/BUILD.bazel index 537b06f..1da62b2 100644 --- a/yacl/crypto/aes/BUILD.bazel +++ b/yacl/crypto/aes/BUILD.bazel @@ -35,7 +35,7 @@ yacl_cc_library( ], copts = AES_COPT_FLAGS, deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:int128", ] + select({ "@platforms//cpu:aarch64": [ diff --git a/yacl/crypto/aes/aes_intrinsics.h b/yacl/crypto/aes/aes_intrinsics.h index d075b36..a8191f0 100644 --- a/yacl/crypto/aes/aes_intrinsics.h +++ b/yacl/crypto/aes/aes_intrinsics.h @@ -56,7 +56,7 @@ #include "yacl/base/exception.h" #include "yacl/base/int128.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" #ifndef __aarch64__ // sse diff --git a/yacl/crypto/block_cipher/BUILD.bazel b/yacl/crypto/block_cipher/BUILD.bazel index 2addcd4..e370029 100644 --- a/yacl/crypto/block_cipher/BUILD.bazel +++ b/yacl/crypto/block_cipher/BUILD.bazel @@ -26,9 +26,9 @@ yacl_cc_library( ], copts = AES_COPT_FLAGS, deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:int128", - "//yacl/crypto:openssl_wrappers", + "//yacl/crypto:ossl_wrappers", ], ) diff --git a/yacl/crypto/block_cipher/symmetric_crypto.cc b/yacl/crypto/block_cipher/symmetric_crypto.cc index 4b62d96..5ea4d94 100644 --- a/yacl/crypto/block_cipher/symmetric_crypto.cc +++ b/yacl/crypto/block_cipher/symmetric_crypto.cc @@ -21,16 +21,16 @@ #include "spdlog/spdlog.h" #include "yacl/base/exception.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" namespace yacl::crypto { namespace { -void SetupEVPCipherCtx(openssl::UniqueCipherCtx* ctx, +void SetupEVPCipherCtx(ossl::UniqueCipherCtx* ctx, SymmetricCrypto::CryptoType type, uint128_t key, uint128_t iv, int enc) { // This uses AES-128, so the key must be 128 bits. - const auto cipher = openssl::FetchEvpCipher(ToString(type)); + const auto cipher = ossl::FetchEvpCipher(ToString(type)); YACL_ENFORCE(sizeof(key) == EVP_CIPHER_key_length(cipher.get())); const auto* key_data = reinterpret_cast(&key); const auto* iv_data = reinterpret_cast(&iv); @@ -72,8 +72,8 @@ uint128_t CopyDataAsUint128(const uint8_t* data) { SymmetricCrypto::SymmetricCrypto(CryptoType type, uint128_t key, uint128_t iv) : type_(type), key_(key), iv_(iv) { // Init openssl encryption/decryption context - enc_ctx_ = openssl::UniqueCipherCtx(EVP_CIPHER_CTX_new()); - dec_ctx_ = openssl::UniqueCipherCtx(EVP_CIPHER_CTX_new()); + enc_ctx_ = ossl::UniqueCipherCtx(EVP_CIPHER_CTX_new()); + dec_ctx_ = ossl::UniqueCipherCtx(EVP_CIPHER_CTX_new()); SetupEVPCipherCtx(&enc_ctx_, type_, key_, iv_, 1); SetupEVPCipherCtx(&dec_ctx_, type_, key_, iv_, 0); @@ -85,8 +85,8 @@ SymmetricCrypto::SymmetricCrypto(CryptoType type, ByteContainerView key, key_(CopyDataAsUint128(key.data())), iv_(CopyDataAsUint128(iv.data())) { // Init openssl encryption/decryption context - enc_ctx_ = openssl::UniqueCipherCtx(EVP_CIPHER_CTX_new()); - dec_ctx_ = openssl::UniqueCipherCtx(EVP_CIPHER_CTX_new()); + enc_ctx_ = ossl::UniqueCipherCtx(EVP_CIPHER_CTX_new()); + dec_ctx_ = ossl::UniqueCipherCtx(EVP_CIPHER_CTX_new()); SetupEVPCipherCtx(&enc_ctx_, type_, key_, iv_, 1); SetupEVPCipherCtx(&dec_ctx_, type_, key_, iv_, 0); diff --git a/yacl/crypto/block_cipher/symmetric_crypto.h b/yacl/crypto/block_cipher/symmetric_crypto.h index 6ac6e8f..b452678 100644 --- a/yacl/crypto/block_cipher/symmetric_crypto.h +++ b/yacl/crypto/block_cipher/symmetric_crypto.h @@ -25,8 +25,8 @@ #include "yacl/base/byte_container_view.h" #include "yacl/base/int128.h" -#include "yacl/crypto/openssl_wrappers.h" -#include "yacl/secparam.h" +#include "yacl/crypto/ossl_wrappers.h" +#include "yacl/base/secparam.h" /* security parameter declaration */ YACL_MODULE_DECLARE("aes_all_modes", SecParam::C::k128, SecParam::S::INF); @@ -91,8 +91,8 @@ class SymmetricCrypto { const uint128_t iv_; // Initialize vector // openssl cipher contexts - openssl::UniqueCipherCtx enc_ctx_; - openssl::UniqueCipherCtx dec_ctx_; + ossl::UniqueCipherCtx enc_ctx_; + ossl::UniqueCipherCtx dec_ctx_; }; class AesCbcCrypto : public SymmetricCrypto { diff --git a/yacl/crypto/ecc/openssl/BUILD.bazel b/yacl/crypto/ecc/openssl/BUILD.bazel index 6d13828..4f958f9 100644 --- a/yacl/crypto/ecc/openssl/BUILD.bazel +++ b/yacl/crypto/ecc/openssl/BUILD.bazel @@ -26,7 +26,7 @@ yacl_cc_library( "openssl_group.h", ], deps = [ - "//yacl/crypto:openssl_wrappers", + "//yacl/crypto:ossl_wrappers", "//yacl/crypto/ecc:spi", "//yacl/crypto/hash:blake3", "//yacl/crypto/hash:ssl_hash", diff --git a/yacl/crypto/ecc/openssl/openssl_factory.cc b/yacl/crypto/ecc/openssl/openssl_factory.cc index 363d28b..a112669 100644 --- a/yacl/crypto/ecc/openssl/openssl_factory.cc +++ b/yacl/crypto/ecc/openssl/openssl_factory.cc @@ -19,7 +19,7 @@ #include "yacl/crypto/ecc/openssl/openssl_group.h" -namespace yacl::crypto::openssl { +namespace yacl::crypto::ossl { static const std::string kLibName = "OpenSSL"; @@ -156,4 +156,4 @@ bool OpensslGroup::IsSupported(const CurveMeta &meta) { std::string OpensslGroup::GetLibraryName() const { return kLibName; } -} // namespace yacl::crypto::openssl +} // namespace yacl::crypto::ossl diff --git a/yacl/crypto/ecc/openssl/openssl_group.cc b/yacl/crypto/ecc/openssl/openssl_group.cc index c2df7a5..947ee7e 100644 --- a/yacl/crypto/ecc/openssl/openssl_group.cc +++ b/yacl/crypto/ecc/openssl/openssl_group.cc @@ -18,11 +18,11 @@ #include "yacl/crypto/hash/blake3.h" #include "yacl/crypto/hash/ssl_hash.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" #include "yacl/utils/scope_guard.h" #include "yacl/utils/spi/type_traits.h" -namespace yacl::crypto::openssl { +namespace yacl::crypto::ossl { static constexpr size_t kHashToCurveCounterGuard = 100; @@ -403,4 +403,4 @@ bool OpensslGroup::IsInfinity(const EcPoint &point) const { return EC_POINT_is_at_infinity(group_.get(), CastAny(point)) == 1; } -} // namespace yacl::crypto::openssl +} // namespace yacl::crypto::ossl diff --git a/yacl/crypto/ecc/openssl/openssl_group.h b/yacl/crypto/ecc/openssl/openssl_group.h index d151bd3..b2055d7 100644 --- a/yacl/crypto/ecc/openssl/openssl_group.h +++ b/yacl/crypto/ecc/openssl/openssl_group.h @@ -18,9 +18,9 @@ #include #include "yacl/crypto/ecc/group_sketch.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" -namespace yacl::crypto::openssl { +namespace yacl::crypto::ossl { class OpensslGroup : public EcGroupSketch { public: @@ -91,4 +91,4 @@ class OpensslGroup : public EcGroupSketch { static thread_local UniqueBnCtx ctx_; }; -} // namespace yacl::crypto::openssl +} // namespace yacl::crypto::ossl diff --git a/yacl/crypto/ecc/openssl/openssl_test.cc b/yacl/crypto/ecc/openssl/openssl_test.cc index 76c25dc..e443fcb 100644 --- a/yacl/crypto/ecc/openssl/openssl_test.cc +++ b/yacl/crypto/ecc/openssl/openssl_test.cc @@ -20,14 +20,14 @@ #include "yacl/utils/parallel.h" #include "yacl/utils/spi/spi_factory.h" -namespace yacl::crypto::openssl { +namespace yacl::crypto::ossl { // We only need to test these two functions, other functions will be tested by // SPI UniqueBn Mp2Bn(const MPInt &mp); MPInt Bn2Mp(const BIGNUM *bn); -} // namespace yacl::crypto::openssl +} // namespace yacl::crypto::ossl -namespace yacl::crypto::openssl::test { +namespace yacl::crypto::ossl::test { TEST(OpensslTest, BnWorks) { // small case @@ -111,4 +111,4 @@ TEST(OpensslMemLeakTest, MulBaseLeaks) { }); } -} // namespace yacl::crypto::openssl::test +} // namespace yacl::crypto::ossl::test diff --git a/yacl/crypto/experimental/dpf/CMakeLists.txt b/yacl/crypto/experimental/dpf/CMakeLists.txt index d60a867..ae9fd95 100644 --- a/yacl/crypto/experimental/dpf/CMakeLists.txt +++ b/yacl/crypto/experimental/dpf/CMakeLists.txt @@ -17,7 +17,7 @@ set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} # Add header files for installation install(FILES ${CMAKE_CURRENT_LIST_DIR}/key_utils.h - ${CMAKE_CURRENT_LIST_DIR}/openssl_wrappers.h + ${CMAKE_CURRENT_LIST_DIR}/ossl_wrappers.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto) diff --git a/yacl/crypto/experimental/dpf/dcf.cc b/yacl/crypto/experimental/dpf/dcf.cc index 10ba759..abc55a3 100644 --- a/yacl/crypto/experimental/dpf/dcf.cc +++ b/yacl/crypto/experimental/dpf/dcf.cc @@ -17,7 +17,7 @@ #include #include "yacl/crypto/experimental/dpf/ge2n.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" #include "yacl/utils/serializer.h" #include "yacl/utils/serializer_adapter.h" diff --git a/yacl/crypto/experimental/dpf/dcf.h b/yacl/crypto/experimental/dpf/dcf.h index 447f362..db512c5 100644 --- a/yacl/crypto/experimental/dpf/dcf.h +++ b/yacl/crypto/experimental/dpf/dcf.h @@ -32,7 +32,7 @@ /* submodules */ #include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/prg.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" YACL_MODULE_DECLARE("dcf", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/experimental/dpf/dpf.cc b/yacl/crypto/experimental/dpf/dpf.cc index b512595..e8b11c1 100644 --- a/yacl/crypto/experimental/dpf/dpf.cc +++ b/yacl/crypto/experimental/dpf/dpf.cc @@ -17,7 +17,7 @@ #include #include "yacl/crypto/experimental/dpf/ge2n.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" #include "yacl/utils/serializer.h" #include "yacl/utils/serializer_adapter.h" diff --git a/yacl/crypto/experimental/dpf/dpf.h b/yacl/crypto/experimental/dpf/dpf.h index bbd3cb4..00a9772 100644 --- a/yacl/crypto/experimental/dpf/dpf.h +++ b/yacl/crypto/experimental/dpf/dpf.h @@ -32,7 +32,7 @@ /* submodules */ #include "yacl/crypto/rand/rand.h" #include "yacl/crypto/tools/prg.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" YACL_MODULE_DECLARE("dpf", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/experimental/sync_drbg/BUILD.bazel b/yacl/crypto/experimental/sync_drbg/BUILD.bazel index f702628..a51e24e 100644 --- a/yacl/crypto/experimental/sync_drbg/BUILD.bazel +++ b/yacl/crypto/experimental/sync_drbg/BUILD.bazel @@ -21,8 +21,8 @@ yacl_cc_library( srcs = ["sync_drbg.cc"], hdrs = ["sync_drbg.h"], deps = [ - "//yacl:secparam", - "//yacl/crypto:openssl_wrappers", + "//yacl/base:secparam", + "//yacl/crypto:ossl_wrappers", "//yacl/crypto/block_cipher:symmetric_crypto", "//yacl/crypto/rand/entropy_source", "//yacl/link:context", diff --git a/yacl/crypto/experimental/sync_drbg/CMakeLists.txt b/yacl/crypto/experimental/sync_drbg/CMakeLists.txt index d60a867..ae9fd95 100644 --- a/yacl/crypto/experimental/sync_drbg/CMakeLists.txt +++ b/yacl/crypto/experimental/sync_drbg/CMakeLists.txt @@ -17,7 +17,7 @@ set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} # Add header files for installation install(FILES ${CMAKE_CURRENT_LIST_DIR}/key_utils.h - ${CMAKE_CURRENT_LIST_DIR}/openssl_wrappers.h + ${CMAKE_CURRENT_LIST_DIR}/ossl_wrappers.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto) diff --git a/yacl/crypto/experimental/sync_drbg/sync_drbg.h b/yacl/crypto/experimental/sync_drbg/sync_drbg.h index 7c9697e..f07998b 100644 --- a/yacl/crypto/experimental/sync_drbg/sync_drbg.h +++ b/yacl/crypto/experimental/sync_drbg/sync_drbg.h @@ -27,9 +27,9 @@ #include "yacl/base/byte_container_view.h" #include "yacl/base/int128.h" -#include "yacl/crypto/openssl_wrappers.h" // for TyHelper +#include "yacl/crypto/ossl_wrappers.h" // for TyHelper #include "yacl/link/context.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" #include "yacl/utils/serializer.h" #include "yacl/utils/serializer_adapter.h" @@ -88,7 +88,7 @@ class SyncDrbg { public: // define general types using HashDrbgCtx = - openssl::internal::TyHelper; + ossl::internal::TyHelper; // Instantiate Sync Drbg. // diff --git a/yacl/crypto/experimental/tpre/CMakeLists.txt b/yacl/crypto/experimental/tpre/CMakeLists.txt index d60a867..ae9fd95 100644 --- a/yacl/crypto/experimental/tpre/CMakeLists.txt +++ b/yacl/crypto/experimental/tpre/CMakeLists.txt @@ -17,7 +17,7 @@ set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} # Add header files for installation install(FILES ${CMAKE_CURRENT_LIST_DIR}/key_utils.h - ${CMAKE_CURRENT_LIST_DIR}/openssl_wrappers.h + ${CMAKE_CURRENT_LIST_DIR}/ossl_wrappers.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto) diff --git a/yacl/crypto/experimental/vss/CMakeLists.txt b/yacl/crypto/experimental/vss/CMakeLists.txt index d60a867..ae9fd95 100644 --- a/yacl/crypto/experimental/vss/CMakeLists.txt +++ b/yacl/crypto/experimental/vss/CMakeLists.txt @@ -17,7 +17,7 @@ set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} # Add header files for installation install(FILES ${CMAKE_CURRENT_LIST_DIR}/key_utils.h - ${CMAKE_CURRENT_LIST_DIR}/openssl_wrappers.h + ${CMAKE_CURRENT_LIST_DIR}/ossl_wrappers.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto) diff --git a/yacl/crypto/hash/BUILD.bazel b/yacl/crypto/hash/BUILD.bazel index 292a9a6..9ee3f42 100644 --- a/yacl/crypto/hash/BUILD.bazel +++ b/yacl/crypto/hash/BUILD.bazel @@ -23,7 +23,7 @@ yacl_cc_library( deps = [ ":hash_interface", "//yacl/base:exception", - "//yacl/crypto:openssl_wrappers", + "//yacl/crypto:ossl_wrappers", "//yacl/utils:scope_guard", ], ) @@ -69,9 +69,9 @@ yacl_cc_library( name = "hash_interface", srcs = ["hash_interface.h"], deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:byte_container_view", - "//yacl/crypto:openssl_wrappers", + "//yacl/crypto:ossl_wrappers", ], ) diff --git a/yacl/crypto/hash/hash_interface.h b/yacl/crypto/hash/hash_interface.h index 322e29e..d2dfcd4 100644 --- a/yacl/crypto/hash/hash_interface.h +++ b/yacl/crypto/hash/hash_interface.h @@ -19,7 +19,7 @@ #include "openssl/evp.h" /* for evp type conversions */ #include "yacl/base/byte_container_view.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* security parameter declaration */ YACL_MODULE_DECLARE("hash_all", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/crypto/hash/ssl_hash.cc b/yacl/crypto/hash/ssl_hash.cc index e3f325f..227477d 100644 --- a/yacl/crypto/hash/ssl_hash.cc +++ b/yacl/crypto/hash/ssl_hash.cc @@ -15,14 +15,14 @@ #include "yacl/crypto/hash/ssl_hash.h" #include "yacl/base/exception.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" #include "yacl/utils/scope_guard.h" namespace yacl::crypto { SslHash::SslHash(HashAlgorithm hash_algo) : hash_algo_(hash_algo), - md_(openssl::FetchEvpMd(ToString(hash_algo))), + md_(ossl::FetchEvpMd(ToString(hash_algo))), context_(EVP_MD_CTX_new()), digest_size_(EVP_MD_size(md_.get())) { Reset(); @@ -35,7 +35,7 @@ size_t SslHash::DigestSize() const { return digest_size_; } SslHash& SslHash::Reset() { OSSL_RET_1(EVP_MD_CTX_reset(context_.get())); int res = 0; - const auto md = openssl::FetchEvpMd(ToString(hash_algo_)); + const auto md = ossl::FetchEvpMd(ToString(hash_algo_)); res = EVP_DigestInit_ex(context_.get(), md.get(), nullptr); OSSL_RET_1(res); @@ -53,7 +53,7 @@ std::vector SslHash::CumulativeHash() const { // Do not finalize the internally stored hash context. Instead, finalize a // copy of the current context so that the current context can be updated in // future calls to Update. - auto ctx_snapshot = openssl::UniqueMdCtx(EVP_MD_CTX_new()); + auto ctx_snapshot = ossl::UniqueMdCtx(EVP_MD_CTX_new()); YACL_ENFORCE(ctx_snapshot != nullptr); EVP_MD_CTX_init(ctx_snapshot.get()); // no return value diff --git a/yacl/crypto/hash/ssl_hash.h b/yacl/crypto/hash/ssl_hash.h index 78e97d2..6041a95 100644 --- a/yacl/crypto/hash/ssl_hash.h +++ b/yacl/crypto/hash/ssl_hash.h @@ -18,7 +18,7 @@ #include "yacl/base/byte_container_view.h" #include "yacl/crypto/hash/hash_interface.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" namespace yacl::crypto { @@ -36,8 +36,8 @@ class SslHash : public HashInterface { private: const HashAlgorithm hash_algo_; - openssl::UniqueMd md_; - openssl::UniqueMdCtx context_; + ossl::UniqueMd md_; + ossl::UniqueMdCtx context_; const size_t digest_size_; }; diff --git a/yacl/crypto/hmac/BUILD.bazel b/yacl/crypto/hmac/BUILD.bazel index 2211ce3..aba3502 100644 --- a/yacl/crypto/hmac/BUILD.bazel +++ b/yacl/crypto/hmac/BUILD.bazel @@ -22,7 +22,7 @@ yacl_cc_library( hdrs = ["hmac.h"], deps = [ "//yacl/base:exception", - "//yacl/crypto:openssl_wrappers", + "//yacl/crypto:ossl_wrappers", "//yacl/crypto/hash:hash_interface", ], ) diff --git a/yacl/crypto/hmac/hmac.cc b/yacl/crypto/hmac/hmac.cc index 2b2f4ef..8e217cb 100644 --- a/yacl/crypto/hmac/hmac.cc +++ b/yacl/crypto/hmac/hmac.cc @@ -15,14 +15,14 @@ #include "yacl/crypto/hmac/hmac.h" #include "yacl/base/exception.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" namespace yacl::crypto { Hmac::Hmac(HashAlgorithm hash_algo, ByteContainerView key) : hash_algo_(hash_algo), key_(key.begin(), key.end()) { - mac_ = openssl::FetchEvpHmac(); - ctx_ = openssl::UniqueMacCtx(EVP_MAC_CTX_new(mac_.get())); + mac_ = ossl::FetchEvpHmac(); + ctx_ = ossl::UniqueMacCtx(EVP_MAC_CTX_new(mac_.get())); YACL_ENFORCE(ctx_ != nullptr); // Set up the underlying context ctx with information given via the key @@ -60,7 +60,7 @@ std::vector Hmac::CumulativeMac() const { // Do not finalize the internally stored hash context. Instead, finalize a // copy of the current context so that the current context can be updated in // future calls to Update. - auto ctx_copy = openssl::UniqueMacCtx(EVP_MAC_CTX_dup(ctx_.get())); + auto ctx_copy = ossl::UniqueMacCtx(EVP_MAC_CTX_dup(ctx_.get())); YACL_ENFORCE(ctx_copy != nullptr); // get the outptut size diff --git a/yacl/crypto/hmac/hmac.h b/yacl/crypto/hmac/hmac.h index e15a473..0e7310d 100644 --- a/yacl/crypto/hmac/hmac.h +++ b/yacl/crypto/hmac/hmac.h @@ -17,7 +17,7 @@ #include #include "yacl/base/byte_container_view.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" /* submodules */ #include "yacl/crypto/hash/hash_interface.h" @@ -62,8 +62,8 @@ class Hmac { private: const HashAlgorithm hash_algo_; const std::vector key_; - openssl::UniqueMac mac_; - openssl::UniqueMacCtx ctx_; + ossl::UniqueMac mac_; + ossl::UniqueMacCtx ctx_; }; } // namespace yacl::crypto diff --git a/yacl/crypto/key_utils.cc b/yacl/crypto/key_utils.cc index 8b79b9e..cded01e 100644 --- a/yacl/crypto/key_utils.cc +++ b/yacl/crypto/key_utils.cc @@ -16,7 +16,7 @@ #include -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" #include "yacl/io/stream/file_io.h" namespace yacl::crypto { @@ -41,14 +41,14 @@ inline void AddX509Extension(X509* cert, int nid, char* value) { // self signed X509V3_set_ctx(&ctx, cert, cert, nullptr, nullptr, 0); auto ex = - openssl::UniqueX509Ext(X509V3_EXT_nconf_nid(nullptr, &ctx, nid, value)); + ossl::UniqueX509Ext(X509V3_EXT_nconf_nid(nullptr, &ctx, nid, value)); YACL_ENFORCE(ex != nullptr); X509_add_ext(cert, ex.get(), -1); } // convert bio file to yacl::Buffer -inline Buffer BioToBuf(const openssl::UniqueBio& bio) { +inline Buffer BioToBuf(const ossl::UniqueBio& bio) { int num_bytes = BIO_pending(bio.get()); YACL_ENFORCE_GT(num_bytes, 0, "BIO_pending failed."); @@ -79,11 +79,11 @@ inline void ExportBufToFile(Buffer&& buf, const std::string& file_path) { // Key Pair Generation // ------------------- -openssl::UniquePkey GenRsaKeyPair(unsigned rsa_keylen) { +ossl::UniquePkey GenRsaKeyPair(unsigned rsa_keylen) { /* EVP_RSA_gen() may be set deprecated by later version of OpenSSL */ EVP_PKEY* pkey = EVP_PKEY_new(); // placeholder - openssl::UniquePkeyCtx ctx( + ossl::UniquePkeyCtx ctx( EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, /* engine = default */ nullptr)); YACL_ENFORCE(ctx != nullptr); OSSL_RET_1(EVP_PKEY_keygen_init(ctx.get())); @@ -93,13 +93,13 @@ openssl::UniquePkey GenRsaKeyPair(unsigned rsa_keylen) { // generate keys OSSL_RET_1(EVP_PKEY_keygen(ctx.get(), &pkey)); - return openssl::UniquePkey(pkey); + return ossl::UniquePkey(pkey); } -openssl::UniquePkey GenSm2KeyPair() { +ossl::UniquePkey GenSm2KeyPair() { EVP_PKEY* pkey = EVP_PKEY_new(); // placeholder - openssl::UniquePkeyCtx ctx( + ossl::UniquePkeyCtx ctx( EVP_PKEY_CTX_new_id(EVP_PKEY_SM2, /* engine = default */ nullptr)); YACL_ENFORCE(ctx != nullptr); OSSL_RET_1(EVP_PKEY_keygen_init(ctx.get())); @@ -111,7 +111,7 @@ openssl::UniquePkey GenSm2KeyPair() { // generate keys OSSL_RET_1(EVP_PKEY_keygen(ctx.get(), &pkey)); - return openssl::UniquePkey(pkey); + return ossl::UniquePkey(pkey); } std::pair GenRsaKeyPairToPemBuf(unsigned rsa_keygen) { @@ -133,16 +133,16 @@ std::pair GenSm2KeyPairToPemBuf() { // ------------------- // load pem from buffer -openssl::UniquePkey LoadKeyFromBuf(ByteContainerView buf) { +ossl::UniquePkey LoadKeyFromBuf(ByteContainerView buf) { // load the buffer to bio - openssl::UniqueBio bio(BIO_new_mem_buf(buf.data(), buf.size())); + ossl::UniqueBio bio(BIO_new_mem_buf(buf.data(), buf.size())); // create pkey EVP_PKEY* pkey = nullptr; // decoding, see // https://www.openssl.org/docs/manmaster/man7/provider-decoder.html - auto decoder = openssl::UniqueDecoder(OSSL_DECODER_CTX_new_for_pkey( + auto decoder = ossl::UniqueDecoder(OSSL_DECODER_CTX_new_for_pkey( /* EVP_PKEY */ &pkey, /* pkey format */ nullptr, // any format /* pkey structure */ nullptr, // any structure @@ -154,10 +154,10 @@ openssl::UniquePkey LoadKeyFromBuf(ByteContainerView buf) { OSSL_RET_1(OSSL_DECODER_from_bio(decoder.get(), bio.get())); // OSSL_RET_1(OSSL_DECODER_from_bio(decoder.get(), bio.get())); - return openssl::UniquePkey(pkey); + return ossl::UniquePkey(pkey); } -openssl::UniquePkey LoadKeyFromFile(const std::string& file_path) { +ossl::UniquePkey LoadKeyFromFile(const std::string& file_path) { return LoadKeyFromBuf(LoadBufFromFile(file_path)); } @@ -167,14 +167,14 @@ openssl::UniquePkey LoadKeyFromFile(const std::string& file_path) { // export public key to pem Buffer ExportPublicKeyToPemBuf( - /* public key */ const openssl::UniquePkey& pkey) { - openssl::UniqueBio bio(BIO_new(BIO_s_mem())); // create an empty bio + /* public key */ const ossl::UniquePkey& pkey) { + ossl::UniqueBio bio(BIO_new(BIO_s_mem())); // create an empty bio // export public key to bio OSSL_RET_1(PEM_write_bio_PUBKEY(bio.get(), pkey.get())); return BioToBuf(bio); } -void ExportPublicKeyToPemFile(const openssl::UniquePkey& pkey, +void ExportPublicKeyToPemFile(const ossl::UniquePkey& pkey, const std::string& file_path) { ExportBufToFile(ExportPublicKeyToPemBuf(pkey), file_path); } @@ -182,8 +182,8 @@ void ExportPublicKeyToPemFile(const openssl::UniquePkey& pkey, // export secret key to pem (different from publick key since they may not have // the same structure) Buffer ExportSecretKeyToPemBuf( - /* secret key */ const openssl::UniquePkey& pkey) { - openssl::UniqueBio bio(BIO_new(BIO_s_mem())); // create an empty bio + /* secret key */ const ossl::UniquePkey& pkey) { + ossl::UniqueBio bio(BIO_new(BIO_s_mem())); // create an empty bio // export secret key to bio using PKCS#8 private key format, equivalent to // PEM_write_bio_PKCS8PrivateKey() @@ -192,7 +192,7 @@ Buffer ExportSecretKeyToPemBuf( return BioToBuf(bio); } -void ExportSecretKeyToPemBuf(const openssl::UniquePkey& pkey, +void ExportSecretKeyToPemBuf(const ossl::UniquePkey& pkey, const std::string& file_path) { ExportBufToFile(ExportSecretKeyToPemBuf(pkey), file_path); } @@ -203,10 +203,10 @@ void ExportSecretKeyToPemBuf(const openssl::UniquePkey& pkey, // export public key to pem Buffer ExportPublicKeyToDerBuf( - /* public key */ const openssl::UniquePkey& pkey) { - openssl::UniqueBio bio(BIO_new(BIO_s_mem())); // create an empty bio + /* public key */ const ossl::UniquePkey& pkey) { + ossl::UniqueBio bio(BIO_new(BIO_s_mem())); // create an empty bio // export pkey to bio - auto encoder = openssl::UniqueEncoder(OSSL_ENCODER_CTX_new_for_pkey( + auto encoder = ossl::UniqueEncoder(OSSL_ENCODER_CTX_new_for_pkey( pkey.get(), /* selection: pk and params */ EVP_PKEY_PUBLIC_KEY, /* format */ "DER", @@ -216,7 +216,7 @@ Buffer ExportPublicKeyToDerBuf( return BioToBuf(bio); } -void ExportPublicKeyToDerFile(const openssl::UniquePkey& pkey, +void ExportPublicKeyToDerFile(const ossl::UniquePkey& pkey, const std::string& file_path) { ExportBufToFile(ExportPublicKeyToPemBuf(pkey), file_path); } @@ -224,10 +224,10 @@ void ExportPublicKeyToDerFile(const openssl::UniquePkey& pkey, // export secret key to pem (different from publick key since they may not have // the same structure) Buffer ExportSecretKeyToDerBuf( - /* secret key */ const openssl::UniquePkey& pkey) { - openssl::UniqueBio bio(BIO_new(BIO_s_mem())); // create an empty bio + /* secret key */ const ossl::UniquePkey& pkey) { + ossl::UniqueBio bio(BIO_new(BIO_s_mem())); // create an empty bio // export pkey to bio - auto encoder = openssl::UniqueEncoder(OSSL_ENCODER_CTX_new_for_pkey( + auto encoder = ossl::UniqueEncoder(OSSL_ENCODER_CTX_new_for_pkey( pkey.get(), /* selection: pk, sk and params */ EVP_PKEY_KEYPAIR, /* format */ "DER", @@ -237,7 +237,7 @@ Buffer ExportSecretKeyToDerBuf( return BioToBuf(bio); } -void ExportSecretKeyToDerFile(const openssl::UniquePkey& pkey, +void ExportSecretKeyToDerFile(const ossl::UniquePkey& pkey, const std::string& file_path) { ExportBufToFile(ExportSecretKeyToPemBuf(pkey), file_path); } @@ -246,9 +246,9 @@ void ExportSecretKeyToDerFile(const openssl::UniquePkey& pkey, // Gen/Load/Export X509 Certificate // ------------------------------- -openssl::UniqueX509 MakeX509Cert( - /* issuer's pk */ const openssl::UniquePkey& pk, - /* issuer's sk */ const openssl::UniquePkey& sk, +ossl::UniqueX509 MakeX509Cert( + /* issuer's pk */ const ossl::UniquePkey& pk, + /* issuer's sk */ const ossl::UniquePkey& sk, /* subjects info */ const std::unordered_map& subjects, /* time */ unsigned days, HashAlgorithm hash) { @@ -268,14 +268,14 @@ openssl::UniqueX509 MakeX509Cert( // ** Subject Public Key Info <= auto filled // ** Public Key Algorithm <= auto filled // ** Subject Public Key - // ** Issuer openssl::Unique Identifier (optional) - // ** Subject openssl::Unique Identifier (optional) + // ** Issuer ossl::Unique Identifier (optional) + // ** Subject ossl::Unique Identifier (optional) // ** Extensions (optional) // ** ... // * Certificate Signature Algorithm // * Certificate Signature // ++++++++++++++++++++++++++++++ - openssl::UniqueX509 x509(X509_new()); + ossl::UniqueX509 x509(X509_new()); /* version */ OSSL_RET_1(X509_set_version(x509.get(), kX509Version)); @@ -313,46 +313,46 @@ openssl::UniqueX509 MakeX509Cert( /* self signing with digest algorithm */ auto sign_bytes = X509_sign(x509.get(), sk.get(), - openssl::FetchEvpMd(ToString(hash)).get()); + ossl::FetchEvpMd(ToString(hash)).get()); YACL_ENFORCE(sign_bytes > 0, "Perform self-signing failed."); return x509; } // load x509 certificate from buffer -openssl::UniqueX509 LoadX509Cert(ByteContainerView buf) { +ossl::UniqueX509 LoadX509Cert(ByteContainerView buf) { // load the buffer to bio - openssl::UniqueBio bio(BIO_new_mem_buf(buf.data(), buf.size())); + ossl::UniqueBio bio(BIO_new_mem_buf(buf.data(), buf.size())); // bio to x509 [warning]: this may be made deprecated in the future version of // OpenSSL, it is recommended to use OSSL_ENCODER and OSSL_DECODER instead. - auto cert = openssl::UniqueX509( + auto cert = ossl::UniqueX509( PEM_read_bio_X509(/* bio */ bio.get(), /* x509 ptr (optional) */ nullptr, /* password */ nullptr, /* addition */ nullptr)); YACL_ENFORCE(cert != nullptr, "No X509 from cert generated."); return cert; } -openssl::UniqueX509 LoadX509CertFromFile(const std::string& file_path) { +ossl::UniqueX509 LoadX509CertFromFile(const std::string& file_path) { return LoadX509Cert(LoadBufFromFile(file_path)); } // load x509 pk from buffer -openssl::UniquePkey LoadX509CertPublicKeyFromBuf(ByteContainerView buf) { +ossl::UniquePkey LoadX509CertPublicKeyFromBuf(ByteContainerView buf) { auto x509 = LoadX509Cert(buf); - auto pkey = openssl::UniquePkey(X509_get_pubkey(x509.get())); + auto pkey = ossl::UniquePkey(X509_get_pubkey(x509.get())); YACL_ENFORCE(pkey != nullptr, "Error when reading public key in X509 certificate."); return pkey; // public key only } -openssl::UniquePkey LoadX509CertPublicKeyFromFile( +ossl::UniquePkey LoadX509CertPublicKeyFromFile( const std::string& file_path) { return LoadX509CertPublicKeyFromBuf(LoadBufFromFile(file_path)); } // export x509 certificate to buffer -Buffer ExportX509CertToBuf(const openssl::UniqueX509& x509) { - openssl::UniqueBio bio(BIO_new(BIO_s_mem())); // create an empty bio +Buffer ExportX509CertToBuf(const ossl::UniqueX509& x509) { + ossl::UniqueBio bio(BIO_new(BIO_s_mem())); // create an empty bio // export certificate to bio OSSL_RET_1(PEM_write_bio_X509(bio.get(), x509.get())); @@ -360,7 +360,7 @@ Buffer ExportX509CertToBuf(const openssl::UniqueX509& x509) { return BioToBuf(bio); } -void ExportX509CertToFile(const openssl::UniqueX509& x509, +void ExportX509CertToFile(const ossl::UniqueX509& x509, const std::string& file_path) { ExportBufToFile(ExportX509CertToBuf(x509), file_path); } diff --git a/yacl/crypto/key_utils.h b/yacl/crypto/key_utils.h index 65798ab..4012c67 100644 --- a/yacl/crypto/key_utils.h +++ b/yacl/crypto/key_utils.h @@ -19,7 +19,7 @@ #include #include "yacl/crypto/hash/hash_interface.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" namespace yacl::crypto { @@ -34,11 +34,11 @@ namespace yacl::crypto { // Generate RSA secret key and public key pair, the resulting key pair is stored // in a single UniquePkey object -[[nodiscard]] openssl::UniquePkey GenRsaKeyPair(unsigned rsa_keylen = 2048); +[[nodiscard]] ossl::UniquePkey GenRsaKeyPair(unsigned rsa_keylen = 2048); // Generate SM2 secret key and public key pair, the resulting key pair is stored // in a single UniquePkey object -[[nodiscard]] openssl::UniquePkey GenSm2KeyPair(); +[[nodiscard]] ossl::UniquePkey GenSm2KeyPair(); // Generate RSA key pair, and convert the secret key (sk) and public key (pk) // into "PEM" format buffers, separately @@ -60,11 +60,11 @@ namespace yacl::crypto { // structure, but some crypto algorithms (such as SM2) require to load both // secret key and public key to the pkey structure, in that case, you should // call LoadKeyFromBufs(buf1, buf2) instead. -[[nodiscard]] openssl::UniquePkey LoadKeyFromBuf(ByteContainerView buf); +[[nodiscard]] ossl::UniquePkey LoadKeyFromBuf(ByteContainerView buf); // Load any (format/type/structure) key from buffer, and return a UniquePkey // object -[[nodiscard]] openssl::UniquePkey LoadKeyFromBufs(ByteContainerView sk_buf, +[[nodiscard]] ossl::UniquePkey LoadKeyFromBufs(ByteContainerView sk_buf, ByteContainerView pk_buf); // load any (format/type/structure) key from file, and return a UniquePkey @@ -74,44 +74,44 @@ namespace yacl::crypto { // structure, but some crypto algorithms (such as SM2) require to load both // secret key and public key to the pkey structure, in that case, you should // call LoadKeyFromFiles(path1, path2) instead. -[[nodiscard]] openssl::UniquePkey LoadKeyFromFile(const std::string& file_path); +[[nodiscard]] ossl::UniquePkey LoadKeyFromFile(const std::string& file_path); // ------------------ // Load/Export PEM Key // ------------------ // Function alias: load pem key from buffer -[[nodiscard]] inline openssl::UniquePkey LoadPemKey(ByteContainerView buf) { +[[nodiscard]] inline ossl::UniquePkey LoadPemKey(ByteContainerView buf) { return LoadKeyFromBuf(buf); } -[[nodiscard]] inline openssl::UniquePkey LoadPemKeys(ByteContainerView sk_buf, +[[nodiscard]] inline ossl::UniquePkey LoadPemKeys(ByteContainerView sk_buf, ByteContainerView pk_buf) { return LoadKeyFromBufs(sk_buf, pk_buf); } // Function alias: load pem key from file -[[nodiscard]] inline openssl::UniquePkey LoadPemKeyFromFile( +[[nodiscard]] inline ossl::UniquePkey LoadPemKeyFromFile( const std::string& file_path) { return LoadKeyFromFile(file_path); } // Export public key and key parameter to buffer bytes, in pem format [[nodiscard]] Buffer ExportPublicKeyToPemBuf( - /* public key */ const openssl::UniquePkey& pkey); + /* public key */ const ossl::UniquePkey& pkey); // Export public key and key parameter to file, in pem format -void ExportPublicKeyToPemFile(/* public key */ const openssl::UniquePkey& pkey, +void ExportPublicKeyToPemFile(/* public key */ const ossl::UniquePkey& pkey, const std::string& file_path); // Export secret key, public key and key parameter to buffer bytes, in pem // format [[nodiscard]] Buffer ExportSecretKeyToPemBuf( - /* secret key, or key pair */ const openssl::UniquePkey& pkey); + /* secret key, or key pair */ const ossl::UniquePkey& pkey); // Export secret key, public key and key parameter to file, in pem format void ExportSecretKeyToPemBuf( - /* secret key, or key pair */ const openssl::UniquePkey& pkey, + /* secret key, or key pair */ const ossl::UniquePkey& pkey, const std::string& file_path); // ------------------ @@ -119,37 +119,37 @@ void ExportSecretKeyToPemBuf( // ------------------ // Function alias: load der key from buffer -[[nodiscard]] inline openssl::UniquePkey LoadDerKey(ByteContainerView buf) { +[[nodiscard]] inline ossl::UniquePkey LoadDerKey(ByteContainerView buf) { return LoadKeyFromBuf(buf); } -[[nodiscard]] inline openssl::UniquePkey LoadDerKeys(ByteContainerView sk_buf, +[[nodiscard]] inline ossl::UniquePkey LoadDerKeys(ByteContainerView sk_buf, ByteContainerView pk_buf) { return LoadKeyFromBufs(sk_buf, pk_buf); } // Function alias: load der key from file -[[nodiscard]] inline openssl::UniquePkey LoadDerKeyFromFile( +[[nodiscard]] inline ossl::UniquePkey LoadDerKeyFromFile( const std::string& file_path) { return LoadKeyFromFile(file_path); } // Export public key and key parameter to buffer bytes, in der format [[nodiscard]] Buffer ExportPublicKeyToDerBuf( - /* public key */ const openssl::UniquePkey& pkey); + /* public key */ const ossl::UniquePkey& pkey); // Export public key and key parameter to file, in der format -void ExportPublicKeyToDerFile(/* public key */ const openssl::UniquePkey& pkey, +void ExportPublicKeyToDerFile(/* public key */ const ossl::UniquePkey& pkey, const std::string& file_path); // Export secret key, public key and key parameter to buffer bytes, in der // format [[nodiscard]] Buffer ExportSecretKeyToDerBuf( - /* secret key or key pair */ const openssl::UniquePkey& pkey); + /* secret key or key pair */ const ossl::UniquePkey& pkey); // Export secret key, public key and key parameter to file, in der format void ExportSecretKeyToDerFile( - /* secret key or key pair */ const openssl::UniquePkey& pkey, + /* secret key or key pair */ const ossl::UniquePkey& pkey, const std::string& file_path); // ------------------------------- @@ -157,31 +157,31 @@ void ExportSecretKeyToDerFile( // ------------------------------- // Self-sign a X509 certificate -[[nodiscard]] openssl::UniqueX509 MakeX509Cert( - /* issuer's pk */ const openssl::UniquePkey& pk, - /* issuer's sk */ const openssl::UniquePkey& sk, +[[nodiscard]] ossl::UniqueX509 MakeX509Cert( + /* issuer's pk */ const ossl::UniquePkey& pk, + /* issuer's sk */ const ossl::UniquePkey& sk, /* subjects info */ const std::unordered_map& subjects, /* time */ unsigned days, HashAlgorithm hash); // Load x509 certificate from buffer -[[nodiscard]] openssl::UniqueX509 LoadX509Cert(ByteContainerView buf); +[[nodiscard]] ossl::UniqueX509 LoadX509Cert(ByteContainerView buf); // Load x509 certificate from file -[[nodiscard]] openssl::UniqueX509 LoadX509CertFromFile( +[[nodiscard]] ossl::UniqueX509 LoadX509CertFromFile( const std::string& file_path); // Load x509 public key from buffer -[[nodiscard]] openssl::UniquePkey LoadX509CertPublicKeyFromBuf( +[[nodiscard]] ossl::UniquePkey LoadX509CertPublicKeyFromBuf( ByteContainerView buf); // Load x509 public key from file -[[nodiscard]] openssl::UniquePkey LoadX509CertPublicKeyFromFile( +[[nodiscard]] ossl::UniquePkey LoadX509CertPublicKeyFromFile( const std::string& file_path); // export x509 certificate to buffer -[[nodiscard]] Buffer ExportX509CertToBuf(const openssl::UniqueX509& x509); -void ExportX509CertToFile(const openssl::UniqueX509& x509, +[[nodiscard]] Buffer ExportX509CertToBuf(const ossl::UniqueX509& x509); +void ExportX509CertToFile(const ossl::UniqueX509& x509, const std::string& file_path); } // namespace yacl::crypto diff --git a/yacl/crypto/openssl_wrappers.h b/yacl/crypto/ossl_wrappers.h similarity index 96% rename from yacl/crypto/openssl_wrappers.h rename to yacl/crypto/ossl_wrappers.h index d94caf8..77241b9 100644 --- a/yacl/crypto/openssl_wrappers.h +++ b/yacl/crypto/ossl_wrappers.h @@ -35,7 +35,7 @@ #include "yacl/base/byte_container_view.h" #include "yacl/utils/scope_guard.h" -namespace yacl::crypto::openssl { +namespace yacl::crypto::ossl { namespace internal { @@ -127,6 +127,6 @@ inline std::string GetOSSLErr() { // --------------------------------- /* enforce return code == 1 */ #define OSSL_RET_1(MP_ERR) \ - YACL_ENFORCE_EQ((MP_ERR), 1, ::yacl::crypto::openssl::GetOSSLErr()) + YACL_ENFORCE_EQ((MP_ERR), 1, ::yacl::crypto::ossl::GetOSSLErr()) -} // namespace yacl::crypto::openssl +} // namespace yacl::crypto::ossl diff --git a/yacl/crypto/pke/BUILD.bazel b/yacl/crypto/pke/BUILD.bazel index bf3773b..ab831a1 100644 --- a/yacl/crypto/pke/BUILD.bazel +++ b/yacl/crypto/pke/BUILD.bazel @@ -30,7 +30,7 @@ yacl_cc_library( hdrs = ["sm2_enc.h"], deps = [ ":pke_interface", - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:exception", "//yacl/crypto:key_utils", ], @@ -50,7 +50,7 @@ yacl_cc_library( hdrs = ["rsa_enc.h"], deps = [ ":pke_interface", - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:exception", "//yacl/crypto:key_utils", ], diff --git a/yacl/crypto/pke/rsa_enc.cc b/yacl/crypto/pke/rsa_enc.cc index b51399f..7c87dfc 100644 --- a/yacl/crypto/pke/rsa_enc.cc +++ b/yacl/crypto/pke/rsa_enc.cc @@ -30,7 +30,7 @@ constexpr int kRsaPadding = RSA_PKCS1_OAEP_PADDING; std::vector RsaEncryptor::Encrypt(ByteContainerView plaintext) { // see: https://www.openssl.org/docs/man3.0/man3/EVP_PKEY_encrypt.html - auto ctx = openssl::UniquePkeyCtx( + auto ctx = ossl::UniquePkeyCtx( EVP_PKEY_CTX_new(pk_.get(), /* engine = default */ nullptr)); YACL_ENFORCE(ctx != nullptr); @@ -56,7 +56,7 @@ std::vector RsaEncryptor::Encrypt(ByteContainerView plaintext) { std::vector RsaDecryptor::Decrypt(ByteContainerView ciphertext) { // see: https://www.openssl.org/docs/man3.0/man3/EVP_PKEY_encrypt.html - auto ctx = openssl::UniquePkeyCtx( + auto ctx = ossl::UniquePkeyCtx( EVP_PKEY_CTX_new(sk_.get(), /* engine = default */ nullptr)); YACL_ENFORCE(ctx != nullptr); diff --git a/yacl/crypto/pke/rsa_enc.h b/yacl/crypto/pke/rsa_enc.h index 5fc03ba..427abb1 100644 --- a/yacl/crypto/pke/rsa_enc.h +++ b/yacl/crypto/pke/rsa_enc.h @@ -20,7 +20,7 @@ #include "yacl/crypto/key_utils.h" #include "yacl/crypto/pke/pke_interface.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* security parameter declaration */ YACL_MODULE_DECLARE("rsa_enc", SecParam::C::k128, SecParam::S::INF); @@ -30,7 +30,7 @@ namespace yacl::crypto { // RSA with OAEP class RsaEncryptor : public PkeEncryptor { public: - explicit RsaEncryptor(openssl::UniquePkey&& pk) : pk_(std::move(pk)) {} + explicit RsaEncryptor(ossl::UniquePkey&& pk) : pk_(std::move(pk)) {} explicit RsaEncryptor(/* pem key */ ByteContainerView pk_buf) : pk_(LoadKeyFromBuf(pk_buf)) {} @@ -38,13 +38,13 @@ class RsaEncryptor : public PkeEncryptor { std::vector Encrypt(ByteContainerView plaintext) override; private: - const openssl::UniquePkey pk_; + const ossl::UniquePkey pk_; const PkeScheme scheme_ = PkeScheme::RSA2048_OAEP; }; class RsaDecryptor : public PkeDecryptor { public: - explicit RsaDecryptor(openssl::UniquePkey&& sk) : sk_(std::move(sk)) {} + explicit RsaDecryptor(ossl::UniquePkey&& sk) : sk_(std::move(sk)) {} explicit RsaDecryptor(/* pem key */ ByteContainerView sk_buf) : sk_(LoadKeyFromBuf(sk_buf)) {} @@ -52,7 +52,7 @@ class RsaDecryptor : public PkeDecryptor { std::vector Decrypt(ByteContainerView ciphertext) override; private: - const openssl::UniquePkey sk_; + const ossl::UniquePkey sk_; const PkeScheme scheme_ = PkeScheme::RSA2048_OAEP; }; diff --git a/yacl/crypto/pke/rsa_enc_test.cc b/yacl/crypto/pke/rsa_enc_test.cc index 843769e..0ea53b7 100644 --- a/yacl/crypto/pke/rsa_enc_test.cc +++ b/yacl/crypto/pke/rsa_enc_test.cc @@ -19,7 +19,7 @@ #include "gtest/gtest.h" #include "yacl/base/exception.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" namespace yacl::crypto { diff --git a/yacl/crypto/pke/sm2_enc.cc b/yacl/crypto/pke/sm2_enc.cc index b86ea58..d437799 100644 --- a/yacl/crypto/pke/sm2_enc.cc +++ b/yacl/crypto/pke/sm2_enc.cc @@ -28,7 +28,7 @@ constexpr std::string_view kDefaultSm2Id = {"1234567812345678"}; std::vector Sm2Encryptor::Encrypt(ByteContainerView plaintext) { // see: https://www.openssl.org/docs/man3.0/man3/EVP_PKEY_encrypt.html - auto ctx = openssl::UniquePkeyCtx( + auto ctx = ossl::UniquePkeyCtx( EVP_PKEY_CTX_new(pk_.get(), /* engine = default */ nullptr)); YACL_ENFORCE(ctx != nullptr); EVP_PKEY_CTX_set1_id(ctx.get(), kDefaultSm2Id.data(), kDefaultSm2Id.size()); @@ -51,7 +51,7 @@ std::vector Sm2Encryptor::Encrypt(ByteContainerView plaintext) { std::vector Sm2Decryptor::Decrypt(ByteContainerView ciphertext) { // see: https://www.openssl.org/docs/man3.0/man3/EVP_PKEY_encrypt.html - auto ctx = openssl::UniquePkeyCtx( + auto ctx = ossl::UniquePkeyCtx( EVP_PKEY_CTX_new(sk_.get(), /* engine = default */ nullptr)); YACL_ENFORCE(ctx != nullptr); EVP_PKEY_CTX_set1_id(ctx.get(), kDefaultSm2Id.data(), kDefaultSm2Id.size()); diff --git a/yacl/crypto/pke/sm2_enc.h b/yacl/crypto/pke/sm2_enc.h index 8509c2c..1a905a4 100644 --- a/yacl/crypto/pke/sm2_enc.h +++ b/yacl/crypto/pke/sm2_enc.h @@ -20,7 +20,7 @@ #include "yacl/crypto/key_utils.h" #include "yacl/crypto/pke/pke_interface.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* security parameter declaration */ YACL_MODULE_DECLARE("sm2_enc", SecParam::C::k128, SecParam::S::INF); @@ -30,7 +30,7 @@ namespace yacl::crypto { // SM2 class Sm2Encryptor : public PkeEncryptor { public: - explicit Sm2Encryptor(openssl::UniquePkey&& pk) : pk_(std::move(pk)) {} + explicit Sm2Encryptor(ossl::UniquePkey&& pk) : pk_(std::move(pk)) {} explicit Sm2Encryptor(ByteContainerView pk_buf) : pk_(LoadKeyFromBuf(pk_buf)) {} @@ -38,14 +38,14 @@ class Sm2Encryptor : public PkeEncryptor { std::vector Encrypt(ByteContainerView plaintext) override; private: - const openssl::UniquePkey pk_; + const ossl::UniquePkey pk_; const PkeScheme scheme_ = PkeScheme::SM2; }; class Sm2Decryptor : public PkeDecryptor { public: explicit Sm2Decryptor( - openssl::UniquePkey&& sk /* should contain (sk, pk) pair */) + ossl::UniquePkey&& sk /* should contain (sk, pk) pair */) : sk_(std::move(sk)) {} explicit Sm2Decryptor(ByteContainerView sk_buf) : sk_(LoadKeyFromBuf(sk_buf)) {} @@ -54,7 +54,7 @@ class Sm2Decryptor : public PkeDecryptor { std::vector Decrypt(ByteContainerView ciphertext) override; private: - const openssl::UniquePkey sk_; + const ossl::UniquePkey sk_; const PkeScheme scheme_ = PkeScheme::SM2; }; diff --git a/yacl/crypto/pke/sm2_enc_test.cc b/yacl/crypto/pke/sm2_enc_test.cc index 550e4c3..65086e1 100644 --- a/yacl/crypto/pke/sm2_enc_test.cc +++ b/yacl/crypto/pke/sm2_enc_test.cc @@ -16,7 +16,7 @@ #include "gtest/gtest.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" namespace yacl::crypto { diff --git a/yacl/crypto/rand/BUILD.bazel b/yacl/crypto/rand/BUILD.bazel index 9bbfc21..005ad00 100644 --- a/yacl/crypto/rand/BUILD.bazel +++ b/yacl/crypto/rand/BUILD.bazel @@ -21,7 +21,7 @@ yacl_cc_library( srcs = ["rand.cc"], hdrs = ["rand.h"], deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:dynamic_bitset", "//yacl/base:exception", "//yacl/base:int128", diff --git a/yacl/crypto/rand/drbg/BUILD.bazel b/yacl/crypto/rand/drbg/BUILD.bazel index b4f8e85..e657e5a 100644 --- a/yacl/crypto/rand/drbg/BUILD.bazel +++ b/yacl/crypto/rand/drbg/BUILD.bazel @@ -32,7 +32,7 @@ yacl_cc_library( ], visibility = ["//visibility:private"], deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:byte_container_view", "//yacl/base:int128", "//yacl/crypto/rand/entropy_source", @@ -50,13 +50,13 @@ yacl_cc_library( "openssl_factory.h", ], data = [ - "//yacl/crypto/ossl_provider:prov_shared", # openssl provider shared lib + "//yacl/ossl_provider:prov_shared", # openssl provider shared lib ], visibility = ["//visibility:private"], deps = [ ":spi", - "//yacl/crypto:openssl_wrappers", - "//yacl/crypto/ossl_provider:helper", # helper + "//yacl/crypto:ossl_wrappers", + "//yacl/ossl_provider:helper", # helper "//yacl/crypto/rand/entropy_source", ], alwayslink = 1, @@ -72,15 +72,15 @@ yacl_cc_library( "native_factory.h", ], data = [ - "//yacl/crypto/ossl_provider:prov_shared", # openssl provider shared lib + "//yacl/ossl_provider:prov_shared", # openssl provider shared lib ], visibility = ["//visibility:private"], deps = [ ":spi", - "//yacl/crypto:openssl_wrappers", + "//yacl/crypto:ossl_wrappers", "//yacl/crypto/block_cipher:symmetric_crypto", "//yacl/crypto/hash:hash_utils", - "//yacl/crypto/ossl_provider:helper", # helper + "//yacl/ossl_provider:helper", # helper "//yacl/crypto/rand/entropy_source", ], alwayslink = 1, diff --git a/yacl/crypto/rand/drbg/drbg.h b/yacl/crypto/rand/drbg/drbg.h index 755f771..4815bff 100644 --- a/yacl/crypto/rand/drbg/drbg.h +++ b/yacl/crypto/rand/drbg/drbg.h @@ -18,7 +18,7 @@ #include #include "yacl/crypto/rand/entropy_source/entropy_source.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" #include "yacl/utils/spi/spi_factory.h" YACL_MODULE_DECLARE("drbg", SecParam::C::k256, SecParam::S::INF); diff --git a/yacl/crypto/rand/drbg/native_factory.cc b/yacl/crypto/rand/drbg/native_factory.cc index 019c731..8af6ef2 100644 --- a/yacl/crypto/rand/drbg/native_factory.cc +++ b/yacl/crypto/rand/drbg/native_factory.cc @@ -28,9 +28,9 @@ #include "yacl/base/int128.h" #include "yacl/crypto/block_cipher/symmetric_crypto.h" #include "yacl/crypto/hash/hash_utils.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" #include "yacl/crypto/rand/entropy_source/entropy_source.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" namespace yacl::crypto { @@ -69,8 +69,8 @@ void Sm4Drbg::Instantiate(ByteContainerView nonce, YACL_ENFORCE(entropy_buf.size() <= kMaxEntropySize); // initialize SM4 entryption context - cipher_ = openssl::FetchEvpCipher(ToString(kCodeType)); - cipher_ctx_ = openssl::UniqueCipherCtx(EVP_CIPHER_CTX_new()); + cipher_ = ossl::FetchEvpCipher(ToString(kCodeType)); + cipher_ctx_ = ossl::UniqueCipherCtx(EVP_CIPHER_CTX_new()); // entropy_buf xor {H(nonce) || H(personal_string)} uint128_t lhf = Blake3_128(nonce); @@ -216,7 +216,7 @@ std::array Sm4Drbg::cbc_mac( /* init openssl cipher contex */ OSSL_RET_1(EVP_CIPHER_CTX_reset(cipher_ctx_.get())); - auto local_ctx = openssl::UniqueCipherCtx(EVP_CIPHER_CTX_new()); + auto local_ctx = ossl::UniqueCipherCtx(EVP_CIPHER_CTX_new()); YACL_ENFORCE(EVP_CipherInit(local_ctx.get(), cipher_.get(), (const unsigned char*)&key, /* iv */ nullptr, /* 1 = enc, 0 = dec */ 1)); diff --git a/yacl/crypto/rand/drbg/native_factory.h b/yacl/crypto/rand/drbg/native_factory.h index a3c358a..2d1dcd9 100644 --- a/yacl/crypto/rand/drbg/native_factory.h +++ b/yacl/crypto/rand/drbg/native_factory.h @@ -22,9 +22,9 @@ #include "yacl/base/byte_container_view.h" #include "yacl/base/int128.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" #include "yacl/crypto/rand/drbg/drbg.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" #include "yacl/utils/spi/argument/arg_set.h" /* submodules */ @@ -95,8 +95,8 @@ class Sm4Drbg { // A: SymmetricCrypto is originally designed to be use to entrypt large amount // of plaintexts with the same key, and in DRBG we need to change the key // oftenly. It's more efficient to use openssl's native APIs. - openssl::UniqueCipher cipher_; - openssl::UniqueCipherCtx cipher_ctx_; + ossl::UniqueCipher cipher_; + ossl::UniqueCipherCtx cipher_ctx_; std::shared_ptr es_; InteralWorkingState internal_state_; }; diff --git a/yacl/crypto/rand/drbg/openssl_factory.cc b/yacl/crypto/rand/drbg/openssl_factory.cc index 5d51354..404857f 100644 --- a/yacl/crypto/rand/drbg/openssl_factory.cc +++ b/yacl/crypto/rand/drbg/openssl_factory.cc @@ -20,8 +20,8 @@ #include #include "yacl/base/exception.h" -#include "yacl/crypto/ossl_provider/helper.h" -#include "yacl/secparam.h" +#include "yacl/ossl_provider/helper.h" +#include "yacl/base/secparam.h" namespace yacl::crypto { @@ -61,20 +61,20 @@ OpensslDrbg::OpensslDrbg(std::string type, const std::shared_ptr& es) : Drbg(es), type_(std::move(type)) { // new entropy_source context - openssl::UniqueRandCtx es_ctx = nullptr; + ossl::UniqueRandCtx es_ctx = nullptr; // load openssl provider - auto libctx = openssl::UniqueLib(OSSL_LIB_CTX_new()); - auto prov = openssl::UniqueProv( + auto libctx = ossl::UniqueLib(OSSL_LIB_CTX_new()); + auto prov = ossl::UniqueProv( OSSL_PROVIDER_load(libctx.get(), GetProviderPath().c_str())); if (prov != nullptr) { // fetch provider's entropy_source algorithm - auto es = openssl::UniqueRand(EVP_RAND_fetch(libctx.get(), "Yes", nullptr)); + auto es = ossl::UniqueRand(EVP_RAND_fetch(libctx.get(), "Yes", nullptr)); YACL_ENFORCE(es != nullptr); // give es_ctx the fetched es algorithm - es_ctx = openssl::UniqueRandCtx(EVP_RAND_CTX_new(es.get(), nullptr)); + es_ctx = ossl::UniqueRandCtx(EVP_RAND_CTX_new(es.get(), nullptr)); YACL_ENFORCE(es_ctx != nullptr); // instantiate the es_ctx @@ -86,11 +86,11 @@ OpensslDrbg::OpensslDrbg(std::string type, // fetch rand (drbg with the specified type) algorithm from OpenSSL's default // provider auto rand = - openssl::UniqueRand(EVP_RAND_fetch(nullptr, type_.c_str(), nullptr)); + ossl::UniqueRand(EVP_RAND_fetch(nullptr, type_.c_str(), nullptr)); YACL_ENFORCE(rand != nullptr); // give ctx_ the fetched algorithm - ctx_ = openssl::UniqueRandCtx(EVP_RAND_CTX_new(rand.get(), es_ctx.get())); + ctx_ = ossl::UniqueRandCtx(EVP_RAND_CTX_new(rand.get(), es_ctx.get())); YACL_ENFORCE(ctx_ != nullptr); // setup parameters diff --git a/yacl/crypto/rand/drbg/openssl_factory.h b/yacl/crypto/rand/drbg/openssl_factory.h index e6ccc5c..39243ce 100644 --- a/yacl/crypto/rand/drbg/openssl_factory.h +++ b/yacl/crypto/rand/drbg/openssl_factory.h @@ -19,7 +19,7 @@ #include #include -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" #include "yacl/crypto/rand/drbg/drbg.h" #include "yacl/utils/spi/argument/arg_set.h" @@ -71,7 +71,7 @@ class OpensslDrbg : public Drbg { private: const std::string type_; - openssl::UniqueRandCtx ctx_; + ossl::UniqueRandCtx ctx_; }; } // namespace yacl::crypto diff --git a/yacl/crypto/rand/entropy_source/BUILD.bazel b/yacl/crypto/rand/entropy_source/BUILD.bazel index 040bd02..a7c5258 100644 --- a/yacl/crypto/rand/entropy_source/BUILD.bazel +++ b/yacl/crypto/rand/entropy_source/BUILD.bazel @@ -36,7 +36,7 @@ yacl_cc_library( ], visibility = ["//visibility:private"], deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/utils/spi", ], ) diff --git a/yacl/crypto/rand/entropy_source/entropy_source.h b/yacl/crypto/rand/entropy_source/entropy_source.h index 476380c..3ce306c 100644 --- a/yacl/crypto/rand/entropy_source/entropy_source.h +++ b/yacl/crypto/rand/entropy_source/entropy_source.h @@ -18,7 +18,7 @@ #include #include "yacl/base/buffer.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" #include "yacl/utils/spi/spi_factory.h" namespace yacl::crypto { diff --git a/yacl/crypto/rand/rand.cc b/yacl/crypto/rand/rand.cc index ec93d1e..babcdf1 100644 --- a/yacl/crypto/rand/rand.cc +++ b/yacl/crypto/rand/rand.cc @@ -19,7 +19,7 @@ #include "yacl/base/byte_container_view.h" #include "yacl/base/dynamic_bitset.h" -#include "yacl/crypto/ossl_provider/helper.h" +#include "yacl/ossl_provider/helper.h" #include "yacl/crypto/rand/entropy_source/entropy_source.h" #include "yacl/math/gadget.h" diff --git a/yacl/crypto/rand/rand.h b/yacl/crypto/rand/rand.h index f5948b5..f489715 100644 --- a/yacl/crypto/rand/rand.h +++ b/yacl/crypto/rand/rand.h @@ -26,11 +26,11 @@ #include "yacl/base/dynamic_bitset.h" #include "yacl/base/int128.h" #include "yacl/crypto/block_cipher/symmetric_crypto.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" #include "yacl/crypto/rand/drbg/drbg.h" #include "yacl/crypto/tools/prg.h" #include "yacl/math/mpint/mp_int.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* security parameter declaration */ YACL_MODULE_DECLARE("rand", SecParam::C::k128, SecParam::S::k64); diff --git a/yacl/crypto/rand/rand_bench.cc b/yacl/crypto/rand/rand_bench.cc index d555711..5ed2a55 100644 --- a/yacl/crypto/rand/rand_bench.cc +++ b/yacl/crypto/rand/rand_bench.cc @@ -19,7 +19,7 @@ #include "benchmark/benchmark.h" #include "yacl/crypto/rand/rand.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" namespace yacl::crypto { diff --git a/yacl/crypto/sign/BUILD.bazel b/yacl/crypto/sign/BUILD.bazel index 6d2bc43..f33335d 100644 --- a/yacl/crypto/sign/BUILD.bazel +++ b/yacl/crypto/sign/BUILD.bazel @@ -30,7 +30,7 @@ yacl_cc_library( hdrs = ["sm2_signing.h"], deps = [ ":signing", - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/crypto:key_utils", "//yacl/crypto/hash:hash_utils", ], @@ -50,7 +50,7 @@ yacl_cc_library( hdrs = ["rsa_signing.h"], deps = [ ":signing", - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/crypto:key_utils", "//yacl/crypto/hash:hash_utils", ], diff --git a/yacl/crypto/sign/rsa_signing.cc b/yacl/crypto/sign/rsa_signing.cc index e4a48b8..02ebb2a 100644 --- a/yacl/crypto/sign/rsa_signing.cc +++ b/yacl/crypto/sign/rsa_signing.cc @@ -28,7 +28,7 @@ constexpr int kRsaPadding = RSA_PKCS1_PADDING; std::vector RsaSigner::Sign(ByteContainerView message) const { // see: https://www.openssl.org/docs/man3.0/man3/EVP_PKEY_sign.html - auto ctx = openssl::UniquePkeyCtx( + auto ctx = ossl::UniquePkeyCtx( EVP_PKEY_CTX_new(sk_.get(), /* engine = default */ nullptr)); YACL_ENFORCE(ctx != nullptr); @@ -62,7 +62,7 @@ std::vector RsaSigner::Sign(ByteContainerView message) const { bool RsaVerifier::Verify(ByteContainerView message, ByteContainerView signature) const { // see: https://www.openssl.org/docs/man3.0/man3/EVP_PKEY_sign.html - auto ctx = openssl::UniquePkeyCtx( + auto ctx = ossl::UniquePkeyCtx( EVP_PKEY_CTX_new(pk_.get(), /* engine = default */ nullptr)); YACL_ENFORCE(ctx != nullptr); diff --git a/yacl/crypto/sign/rsa_signing.h b/yacl/crypto/sign/rsa_signing.h index 5dca75f..fecaadd 100644 --- a/yacl/crypto/sign/rsa_signing.h +++ b/yacl/crypto/sign/rsa_signing.h @@ -19,7 +19,7 @@ #include "yacl/crypto/key_utils.h" #include "yacl/crypto/sign/signing.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* submodules */ #include "yacl/crypto/hash/hash_utils.h" @@ -33,7 +33,7 @@ namespace yacl::crypto { class RsaSigner final : public AsymmetricSigner { public: // constructors and destrucors - explicit RsaSigner(openssl::UniquePkey&& sk) : sk_(std::move(sk)) {} + explicit RsaSigner(ossl::UniquePkey&& sk) : sk_(std::move(sk)) {} explicit RsaSigner(/* pem key */ ByteContainerView sk_buf) : sk_(LoadKeyFromBuf(sk_buf)) {} @@ -44,7 +44,7 @@ class RsaSigner final : public AsymmetricSigner { std::vector Sign(ByteContainerView message) const override; private: - const openssl::UniquePkey sk_; + const ossl::UniquePkey sk_; const SignatureScheme scheme_ = SignatureScheme::RSA_SIGNING_SHA256_HASH; }; @@ -52,7 +52,7 @@ class RsaSigner final : public AsymmetricSigner { class RsaVerifier final : public AsymmetricVerifier { public: // constructors and destrucors - explicit RsaVerifier(openssl::UniquePkey&& pk) : pk_(std::move(pk)) {} + explicit RsaVerifier(ossl::UniquePkey&& pk) : pk_(std::move(pk)) {} explicit RsaVerifier(/* pem key */ ByteContainerView pk_buf) : pk_(LoadKeyFromBuf(pk_buf)) {} @@ -64,7 +64,7 @@ class RsaVerifier final : public AsymmetricVerifier { ByteContainerView signature) const override; private: - const openssl::UniquePkey pk_; + const ossl::UniquePkey pk_; const SignatureScheme scheme_ = SignatureScheme::RSA_SIGNING_SHA256_HASH; }; diff --git a/yacl/crypto/sign/rsa_signing_test.cc b/yacl/crypto/sign/rsa_signing_test.cc index 159e2a1..292de1d 100644 --- a/yacl/crypto/sign/rsa_signing_test.cc +++ b/yacl/crypto/sign/rsa_signing_test.cc @@ -18,7 +18,7 @@ #include "gtest/gtest.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" namespace yacl::crypto { diff --git a/yacl/crypto/sign/sm2_signing.cc b/yacl/crypto/sign/sm2_signing.cc index 7e69c28..6bbb226 100644 --- a/yacl/crypto/sign/sm2_signing.cc +++ b/yacl/crypto/sign/sm2_signing.cc @@ -31,13 +31,13 @@ std::vector Sm2Signer::Sign(ByteContainerView message) const { // That is, EVP_PKEY_sign() and EVP_PKEY_verify() does not work on sm2 // // see: https://www.openssl.org/docs/man3.0/man7/EVP_PKEY-SM2.html - auto ctx = openssl::UniquePkeyCtx( + auto ctx = ossl::UniquePkeyCtx( EVP_PKEY_CTX_new(sk_.get(), /* engine = default */ nullptr)); YACL_ENFORCE(ctx != nullptr); EVP_PKEY_CTX_set1_id(ctx.get(), kDefaultSm2Id.data(), kDefaultSm2Id.size()); // create message digest context - auto mctx = openssl::UniqueMdCtx(EVP_MD_CTX_new()); + auto mctx = ossl::UniqueMdCtx(EVP_MD_CTX_new()); YACL_ENFORCE(mctx != nullptr); EVP_MD_CTX_set_pkey_ctx(mctx.get(), ctx.get()); // set it related to pkey ctx @@ -64,13 +64,13 @@ std::vector Sm2Signer::Sign(ByteContainerView message) const { bool Sm2Verifier::Verify(ByteContainerView message, ByteContainerView signature) const { - auto ctx = openssl::UniquePkeyCtx( + auto ctx = ossl::UniquePkeyCtx( EVP_PKEY_CTX_new(pk_.get(), /* engine = default */ nullptr)); YACL_ENFORCE(ctx != nullptr); EVP_PKEY_CTX_set1_id(ctx.get(), kDefaultSm2Id.data(), kDefaultSm2Id.size()); // create message digest context - auto mctx = openssl::UniqueMdCtx(EVP_MD_CTX_new()); + auto mctx = ossl::UniqueMdCtx(EVP_MD_CTX_new()); YACL_ENFORCE(mctx != nullptr); EVP_MD_CTX_set_pkey_ctx(mctx.get(), ctx.get()); diff --git a/yacl/crypto/sign/sm2_signing.h b/yacl/crypto/sign/sm2_signing.h index 9a65f8e..ca7a9a3 100644 --- a/yacl/crypto/sign/sm2_signing.h +++ b/yacl/crypto/sign/sm2_signing.h @@ -19,7 +19,7 @@ #include "yacl/crypto/key_utils.h" #include "yacl/crypto/sign/signing.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* submodules */ #include "yacl/crypto/hash/hash_utils.h" @@ -32,7 +32,7 @@ namespace yacl::crypto { class Sm2Signer final : public AsymmetricSigner { public: // constructors and destrucors - explicit Sm2Signer(openssl::UniquePkey&& sk) : sk_(std::move(sk)) {} + explicit Sm2Signer(ossl::UniquePkey&& sk) : sk_(std::move(sk)) {} explicit Sm2Signer(/* pem key */ ByteContainerView sk_buf) : sk_(LoadKeyFromBuf(sk_buf)) {} @@ -42,7 +42,7 @@ class Sm2Signer final : public AsymmetricSigner { std::vector Sign(ByteContainerView message) const override; private: - const openssl::UniquePkey sk_; + const ossl::UniquePkey sk_; const SignatureScheme scheme_ = SignatureScheme::SM2_SIGNING_SM3_HASH; }; @@ -50,7 +50,7 @@ class Sm2Signer final : public AsymmetricSigner { class Sm2Verifier final : public AsymmetricVerifier { public: // constructors and destrucors - explicit Sm2Verifier(openssl::UniquePkey&& pk) : pk_(std::move(pk)) {} + explicit Sm2Verifier(ossl::UniquePkey&& pk) : pk_(std::move(pk)) {} explicit Sm2Verifier(/* pem key */ ByteContainerView pk_buf) : pk_(LoadKeyFromBuf(pk_buf)) {} @@ -62,7 +62,7 @@ class Sm2Verifier final : public AsymmetricVerifier { ByteContainerView signature) const override; private: - const openssl::UniquePkey pk_; + const ossl::UniquePkey pk_; const SignatureScheme scheme_ = SignatureScheme::SM2_SIGNING_SM3_HASH; }; diff --git a/yacl/crypto/sign/sm2_signing_test.cc b/yacl/crypto/sign/sm2_signing_test.cc index 6582667..44e20dc 100644 --- a/yacl/crypto/sign/sm2_signing_test.cc +++ b/yacl/crypto/sign/sm2_signing_test.cc @@ -18,7 +18,7 @@ #include "gtest/gtest.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" namespace yacl::crypto { diff --git a/yacl/crypto/tools/BUILD.bazel b/yacl/crypto/tools/BUILD.bazel index 233a2e6..2ef47cd 100644 --- a/yacl/crypto/tools/BUILD.bazel +++ b/yacl/crypto/tools/BUILD.bazel @@ -31,7 +31,7 @@ yacl_cc_library( srcs = ["prg.cc"], hdrs = ["prg.h"], deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:dynamic_bitset", "//yacl/crypto/block_cipher:symmetric_crypto", "//yacl/math/mpint", diff --git a/yacl/crypto/tools/prg.h b/yacl/crypto/tools/prg.h index 0416dc0..e614bf3 100644 --- a/yacl/crypto/tools/prg.h +++ b/yacl/crypto/tools/prg.h @@ -26,7 +26,7 @@ #include "yacl/base/dynamic_bitset.h" #include "yacl/base/int128.h" #include "yacl/math/mpint/mp_int.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* submodules */ #include "yacl/crypto/block_cipher/symmetric_crypto.h" diff --git a/yacl/kernel/algorithms/BUILD.bazel b/yacl/kernel/algorithms/BUILD.bazel index 723a8d1..175a995 100644 --- a/yacl/kernel/algorithms/BUILD.bazel +++ b/yacl/kernel/algorithms/BUILD.bazel @@ -28,7 +28,7 @@ yacl_cc_library( hdrs = ["portable_ot_interface.h"], deps = [ ":base_ot_interface", - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:exception", "//yacl/crypto/tools:ro", "//yacl/link", @@ -46,7 +46,7 @@ yacl_cc_library( ], deps = [ ":base_ot_interface", - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:exception", "//yacl/crypto/tools:ro", "//yacl/link", @@ -61,7 +61,7 @@ yacl_cc_library( srcs = ["base_ot.cc"], hdrs = ["base_ot.h"], deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:exception", "//yacl/kernel/type:ot_store_utils", "//yacl/link", @@ -91,7 +91,7 @@ yacl_cc_library( srcs = ["iknp_ote.cc"], hdrs = ["iknp_ote.h"], deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/crypto/tools:crhash", "//yacl/crypto/tools:prg", "//yacl/crypto/tools:rp", @@ -117,7 +117,7 @@ yacl_cc_library( hdrs = ["kkrt_ote.h"], copts = AES_COPT_FLAGS, deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:exception", "//yacl/base:int128", "//yacl/crypto/aes:aes_opt", @@ -148,7 +148,7 @@ yacl_cc_library( hdrs = ["sgrr_ote.h"], copts = AES_COPT_FLAGS, deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/crypto/aes:aes_opt", "//yacl/crypto/rand", "//yacl/crypto/tools:crhash", @@ -178,7 +178,7 @@ yacl_cc_library( hdrs = ["gywz_ote.h"], copts = AES_COPT_FLAGS, deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:aligned_vector", "//yacl/crypto/aes:aes_opt", "//yacl/crypto/rand", @@ -214,7 +214,7 @@ yacl_cc_library( ], copts = AES_COPT_FLAGS, deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:exception", "//yacl/crypto/hash:hash_utils", "//yacl/crypto/rand", @@ -248,7 +248,7 @@ yacl_cc_library( hdrs = ["kos_ote.h"], copts = AES_COPT_FLAGS, deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:dynamic_bitset", "//yacl/base:exception", "//yacl/base:int128", @@ -316,7 +316,7 @@ yacl_cc_library( hdrs = ["mpfss.h"], copts = AES_COPT_FLAGS, deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:aligned_vector", "//yacl/base:dynamic_bitset", "//yacl/base:int128", @@ -348,7 +348,7 @@ yacl_cc_library( hdrs = ["base_vole.h"], copts = AES_COPT_FLAGS, deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:aligned_vector", "//yacl/base:dynamic_bitset", "//yacl/base:int128", @@ -379,7 +379,7 @@ yacl_cc_library( hdrs = ["mp_vole.h"], copts = AES_COPT_FLAGS, deps = [ - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:aligned_vector", "//yacl/base:dynamic_bitset", "//yacl/base:int128", @@ -415,7 +415,7 @@ yacl_cc_library( deps = [ ":base_vole", ":mp_vole", - "//yacl:secparam", + "//yacl/base:secparam", "//yacl/base:aligned_vector", "//yacl/base:dynamic_bitset", "//yacl/base:int128", diff --git a/yacl/kernel/algorithms/base_ot.h b/yacl/kernel/algorithms/base_ot.h index b8e761a..8a4d295 100644 --- a/yacl/kernel/algorithms/base_ot.h +++ b/yacl/kernel/algorithms/base_ot.h @@ -23,7 +23,7 @@ #include "yacl/base/int128.h" #include "yacl/kernel/type/ot_store_utils.h" #include "yacl/link/link.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* submodules */ #if defined(__linux__) && defined(__x86_64) diff --git a/yacl/kernel/algorithms/base_vole.h b/yacl/kernel/algorithms/base_vole.h index 0bf0ba8..e149cb6 100644 --- a/yacl/kernel/algorithms/base_vole.h +++ b/yacl/kernel/algorithms/base_vole.h @@ -22,7 +22,7 @@ /* submodules */ #include "yacl/kernel/algorithms/softspoken_ote.h" #include "yacl/kernel/type/ot_store_utils.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" YACL_MODULE_DECLARE("base_vole", SecParam::C::INF, SecParam::S::INF); namespace yacl::crypto { diff --git a/yacl/kernel/algorithms/ferret_ote.h b/yacl/kernel/algorithms/ferret_ote.h index c724935..8e32bd6 100644 --- a/yacl/kernel/algorithms/ferret_ote.h +++ b/yacl/kernel/algorithms/ferret_ote.h @@ -21,7 +21,7 @@ #include "yacl/kernel/type/ot_store_utils.h" #include "yacl/math/gadget.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" #include "yacl/utils/cuckoo_index.h" /* submodules */ diff --git a/yacl/kernel/algorithms/ferret_ote_rn.h b/yacl/kernel/algorithms/ferret_ote_rn.h index 92f7054..0c834ce 100644 --- a/yacl/kernel/algorithms/ferret_ote_rn.h +++ b/yacl/kernel/algorithms/ferret_ote_rn.h @@ -21,7 +21,7 @@ #include "yacl/crypto/hash/hash_utils.h" #include "yacl/crypto/tools/common.h" #include "yacl/math/galois_field/gf_intrinsic.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* submodules */ #include "yacl/kernel/algorithms/gywz_ote.h" diff --git a/yacl/kernel/algorithms/ferret_ote_un.h b/yacl/kernel/algorithms/ferret_ote_un.h index 90952d5..860ea43 100644 --- a/yacl/kernel/algorithms/ferret_ote_un.h +++ b/yacl/kernel/algorithms/ferret_ote_un.h @@ -20,7 +20,7 @@ #include #include "yacl/math/gadget.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" #include "yacl/utils/cuckoo_index.h" /* submodules */ diff --git a/yacl/kernel/algorithms/gywz_ote.h b/yacl/kernel/algorithms/gywz_ote.h index 9aadea4..2c9e752 100644 --- a/yacl/kernel/algorithms/gywz_ote.h +++ b/yacl/kernel/algorithms/gywz_ote.h @@ -20,7 +20,7 @@ #include "yacl/base/int128.h" #include "yacl/link/link.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* submodules */ #include "yacl/crypto/aes/aes_opt.h" diff --git a/yacl/kernel/algorithms/iknp_ote.h b/yacl/kernel/algorithms/iknp_ote.h index 023cd21..f4288df 100644 --- a/yacl/kernel/algorithms/iknp_ote.h +++ b/yacl/kernel/algorithms/iknp_ote.h @@ -22,7 +22,7 @@ #include "yacl/base/dynamic_bitset.h" #include "yacl/kernel/type/ot_store_utils.h" #include "yacl/link/link.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" #include "yacl/utils/matrix_utils.h" /* submodules */ diff --git a/yacl/kernel/algorithms/kkrt_ote.h b/yacl/kernel/algorithms/kkrt_ote.h index 21d108b..68187e0 100644 --- a/yacl/kernel/algorithms/kkrt_ote.h +++ b/yacl/kernel/algorithms/kkrt_ote.h @@ -21,7 +21,7 @@ #include "yacl/kernel/type/ot_store_utils.h" #include "yacl/link/link.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* submodules */ #include "yacl/crypto/aes/aes_intrinsics.h" diff --git a/yacl/kernel/algorithms/kos_ote.h b/yacl/kernel/algorithms/kos_ote.h index 2de34c6..8ce9ed5 100644 --- a/yacl/kernel/algorithms/kos_ote.h +++ b/yacl/kernel/algorithms/kos_ote.h @@ -21,7 +21,7 @@ #include "yacl/base/dynamic_bitset.h" #include "yacl/kernel/type/ot_store_utils.h" #include "yacl/link/link.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* submodules */ #include "yacl/crypto/rand/rand.h" diff --git a/yacl/kernel/algorithms/mp_vole.h b/yacl/kernel/algorithms/mp_vole.h index 2f53061..8d72eec 100644 --- a/yacl/kernel/algorithms/mp_vole.h +++ b/yacl/kernel/algorithms/mp_vole.h @@ -24,7 +24,7 @@ #include "yacl/kernel/type/ot_store_utils.h" #include "yacl/math/gadget.h" #include "yacl/math/galois_field/gf_intrinsic.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" YACL_MODULE_DECLARE("mp_vole", SecParam::C::INF, SecParam::S::INF); diff --git a/yacl/kernel/algorithms/mpfss.h b/yacl/kernel/algorithms/mpfss.h index bd04ac7..16059ed 100644 --- a/yacl/kernel/algorithms/mpfss.h +++ b/yacl/kernel/algorithms/mpfss.h @@ -20,7 +20,7 @@ /* submodules */ #include "yacl/crypto/rand/rand.h" #include "yacl/kernel/type/ot_store_utils.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* security parameter declaration */ // this module is only a wrapper, no need for security parameter definition diff --git a/yacl/kernel/algorithms/portable_ot_interface.h b/yacl/kernel/algorithms/portable_ot_interface.h index 1653825..72b0f7d 100644 --- a/yacl/kernel/algorithms/portable_ot_interface.h +++ b/yacl/kernel/algorithms/portable_ot_interface.h @@ -23,7 +23,7 @@ #endif #include "yacl/kernel/algorithms/base_ot_interface.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* security parameter declaration */ YACL_MODULE_DECLARE("base_ot_portable", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/kernel/algorithms/sgrr_ote.h b/yacl/kernel/algorithms/sgrr_ote.h index fd46868..ac2393a 100644 --- a/yacl/kernel/algorithms/sgrr_ote.h +++ b/yacl/kernel/algorithms/sgrr_ote.h @@ -20,7 +20,7 @@ #include "yacl/kernel/type/ot_store_utils.h" #include "yacl/link/link.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* submodules */ #include "yacl/crypto/aes/aes_opt.h" diff --git a/yacl/kernel/algorithms/silent_vole.h b/yacl/kernel/algorithms/silent_vole.h index 3f9fcc0..7e57939 100644 --- a/yacl/kernel/algorithms/silent_vole.h +++ b/yacl/kernel/algorithms/silent_vole.h @@ -17,7 +17,7 @@ #include "yacl/base/exception.h" #include "yacl/base/int128.h" #include "yacl/link/context.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* submodules */ #include "yacl/crypto/rand/rand.h" diff --git a/yacl/kernel/algorithms/softspoken_ote.h b/yacl/kernel/algorithms/softspoken_ote.h index b977b84..321b726 100644 --- a/yacl/kernel/algorithms/softspoken_ote.h +++ b/yacl/kernel/algorithms/softspoken_ote.h @@ -24,7 +24,7 @@ #include "yacl/base/int128.h" #include "yacl/link/context.h" #include "yacl/link/link.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* submodules */ #include "yacl/crypto/rand/rand.h" diff --git a/yacl/kernel/algorithms/x86_asm_ot_interface.h b/yacl/kernel/algorithms/x86_asm_ot_interface.h index b1456d1..6680ac3 100644 --- a/yacl/kernel/algorithms/x86_asm_ot_interface.h +++ b/yacl/kernel/algorithms/x86_asm_ot_interface.h @@ -23,7 +23,7 @@ #include #include "yacl/kernel/algorithms/base_ot_interface.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" /* security parameter declaration */ YACL_MODULE_DECLARE("base_ot_x86_asm", SecParam::C::k128, SecParam::S::INF); diff --git a/yacl/kernel/ot_kernel.cc b/yacl/kernel/ot_kernel.cc index 4c8d845..5aff773 100644 --- a/yacl/kernel/ot_kernel.cc +++ b/yacl/kernel/ot_kernel.cc @@ -28,7 +28,7 @@ #include "yacl/kernel/algorithms/softspoken_ote.h" #include "yacl/kernel/type/ot_store_utils.h" #include "yacl/link/context.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" #include "yacl/utils/parallel.h" #include "yacl/utils/thread_pool.h" diff --git a/yacl/kernel/ot_kernel.h b/yacl/kernel/ot_kernel.h index 2199eec..e570750 100644 --- a/yacl/kernel/ot_kernel.h +++ b/yacl/kernel/ot_kernel.h @@ -25,7 +25,7 @@ #include "yacl/kernel/algorithms/base_ot.h" #include "yacl/kernel/algorithms/ferret_ote.h" #include "yacl/kernel/algorithms/softspoken_ote.h" -#include "yacl/secparam.h" +#include "yacl/base/secparam.h" namespace yacl::crypto { diff --git a/yacl/crypto/ossl_provider/BUILD.bazel b/yacl/ossl_provider/BUILD.bazel similarity index 95% rename from yacl/crypto/ossl_provider/BUILD.bazel rename to yacl/ossl_provider/BUILD.bazel index 957e2f6..8cd0852 100644 --- a/yacl/crypto/ossl_provider/BUILD.bazel +++ b/yacl/ossl_provider/BUILD.bazel @@ -47,7 +47,7 @@ yacl_cc_library( ], visibility = ["//visibility:public"], # public deps = [ - "//yacl/crypto:openssl_wrappers", # openssl here + "//yacl/crypto:ossl_wrappers", # openssl here "@com_google_absl//absl/strings", ], ) @@ -64,7 +64,7 @@ yacl_cc_library( ], visibility = ["//visibility:private"], deps = [ - "//yacl/crypto:openssl_wrappers", # openssl here + "//yacl/crypto:ossl_wrappers", # openssl here "//yacl/crypto/rand/entropy_source", # use yacl es ], alwayslink = True, # DO NOT DELETE THIS diff --git a/yacl/crypto/ossl_provider/helper.h b/yacl/ossl_provider/helper.h similarity index 96% rename from yacl/crypto/ossl_provider/helper.h rename to yacl/ossl_provider/helper.h index 55af04b..984212f 100644 --- a/yacl/crypto/ossl_provider/helper.h +++ b/yacl/ossl_provider/helper.h @@ -56,7 +56,7 @@ inline std::string GetProviderPath() { std::string path1; std::string path2; std::string path3 = - fmt::format("/yacl/crypto/ossl_provider/libprov_shared{}", SO_EXT); + fmt::format("/yacl/ossl_provider/libprov_shared{}", SO_EXT); // step 1: determine if target is "cc_test" or "cc_library" if (selfdir_str.find("sandbox") != std::string::npos) { diff --git a/yacl/crypto/ossl_provider/linux_exported_syms.lds b/yacl/ossl_provider/linux_exported_syms.lds similarity index 100% rename from yacl/crypto/ossl_provider/linux_exported_syms.lds rename to yacl/ossl_provider/linux_exported_syms.lds diff --git a/yacl/crypto/ossl_provider/macos_exported_syms.lds b/yacl/ossl_provider/macos_exported_syms.lds similarity index 100% rename from yacl/crypto/ossl_provider/macos_exported_syms.lds rename to yacl/ossl_provider/macos_exported_syms.lds diff --git a/yacl/crypto/ossl_provider/provider.cc b/yacl/ossl_provider/provider.cc similarity index 97% rename from yacl/crypto/ossl_provider/provider.cc rename to yacl/ossl_provider/provider.cc index 99144d8..746e96b 100644 --- a/yacl/crypto/ossl_provider/provider.cc +++ b/yacl/ossl_provider/provider.cc @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "yacl/crypto/ossl_provider/rand_impl.h" -#include "yacl/crypto/ossl_provider/version.h" +#include "yacl/ossl_provider/rand_impl.h" +#include "yacl/ossl_provider/version.h" using FuncPtr = void (*)(); diff --git a/yacl/crypto/ossl_provider/provider_test.cc b/yacl/ossl_provider/provider_test.cc similarity index 96% rename from yacl/crypto/ossl_provider/provider_test.cc rename to yacl/ossl_provider/provider_test.cc index 66f59cd..f8ec902 100644 --- a/yacl/crypto/ossl_provider/provider_test.cc +++ b/yacl/ossl_provider/provider_test.cc @@ -23,17 +23,17 @@ #include "openssl/rand.h" #include "openssl/randerr.h" -#include "yacl/crypto/openssl_wrappers.h" -#include "yacl/crypto/ossl_provider/helper.h" +#include "yacl/crypto/ossl_wrappers.h" +#include "yacl/ossl_provider/helper.h" namespace yacl::crypto { TEST(OpensslTest, ShouldWork) { - auto libctx = openssl::UniqueLib(OSSL_LIB_CTX_new()); + auto libctx = ossl::UniqueLib(OSSL_LIB_CTX_new()); // OSSL_PROVIDER_load() loads and initializes a provider. This may simply // initialize a provider that was previously added with - auto prov = openssl::UniqueProv( + auto prov = ossl::UniqueProv( OSSL_PROVIDER_load(libctx.get(), GetProviderPath().c_str())); YACL_ENFORCE(prov != nullptr, ERR_error_string(ERR_get_error(), nullptr)); diff --git a/yacl/crypto/ossl_provider/rand_impl.h b/yacl/ossl_provider/rand_impl.h similarity index 99% rename from yacl/crypto/ossl_provider/rand_impl.h rename to yacl/ossl_provider/rand_impl.h index f6022d0..618b837 100644 --- a/yacl/crypto/ossl_provider/rand_impl.h +++ b/yacl/ossl_provider/rand_impl.h @@ -23,7 +23,7 @@ #include "openssl/randerr.h" #include "spdlog/spdlog.h" -#include "yacl/crypto/openssl_wrappers.h" +#include "yacl/crypto/ossl_wrappers.h" #include "yacl/crypto/rand/entropy_source/entropy_source.h" namespace yc = yacl::crypto; diff --git a/yacl/crypto/ossl_provider/version.h b/yacl/ossl_provider/version.h similarity index 100% rename from yacl/crypto/ossl_provider/version.h rename to yacl/ossl_provider/version.h