diff --git a/bazel/mcl.BUILD b/bazel/mcl.BUILD index 96df74e..ab7f381 100644 --- a/bazel/mcl.BUILD +++ b/bazel/mcl.BUILD @@ -15,8 +15,6 @@ load("@bazel_skylib//lib:selects.bzl", "selects") load("@rules_foreign_cc//foreign_cc:defs.bzl", "make") load("@yacl//bazel:yacl.bzl", "yacl_cmake_external") -load("@rules_foreign_cc//foreign_cc:defs.bzl", "make") -load("@bazel_skylib//lib:selects.bzl", "selects") package(default_visibility = ["//visibility:public"]) diff --git a/bazel/patches/mcl.patch b/bazel/patches/mcl.patch index bc9d671..466d253 100644 --- a/bazel/patches/mcl.patch +++ b/bazel/patches/mcl.patch @@ -1,21 +1,22 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index 2b54b261..5c1f14c7 100644 +index f2ee05c5..8fcb4f23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -145,6 +145,10 @@ target_compile_options(mcl_st PRIVATE ${MCL_COMPILE_OPTIONS}) - # target_compile_features(mcl PUBLIC cxx_std_11) - # target_compile_features(mcl_st PUBLIC cxx_std_11) +@@ -134,6 +134,11 @@ endif() + target_compile_options(mcl PRIVATE ${MCL_COMPILE_OPTIONS}) + target_compile_options(mcl_st PRIVATE ${MCL_COMPILE_OPTIONS}) +set(TARGET_FLAG "") +if(DEFINED CMAKE_ANDROID_ARCH_LLVM_TRIPLE) + set(TARGET_FLAG "--target=${CMAKE_ANDROID_ARCH_LLVM_TRIPLE}") +endif() - - # use bint-x64 on x64, bint${BIT}.ll on the other CPU - if(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") # Win64 -@@ -163,16 +167,16 @@ elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT APPLE) - target_sources(mcl PRIVATE src/asm/bint-x64-amd64.S) - target_sources(mcl_st PRIVATE src/asm/bint-x64-amd64.S) ++ + # set_target_properties(mcl PROPERTIES + # CXX_STANDARD 11 + # CXX_STANDARD_REQUIRED YES +@@ -168,16 +173,16 @@ elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT APPLE) + target_sources(mcl_st PRIVATE src/asm/bint-x64-amd64.S) + endif() else() - if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") - message(FATAL_ERROR "requiring clang++. cmake -DCMAKE_CXX_COMPILER=clang++ ..") @@ -34,7 +35,7 @@ index 2b54b261..5c1f14c7 100644 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_custom_target(gen_bint.o SOURCES ${BINT_OBJ}) -@@ -199,7 +203,7 @@ elseif(${MCL_USE_LLVM}) +@@ -210,7 +215,7 @@ elseif(${MCL_USE_LLVM}) target_compile_definitions(mcl_st PUBLIC MCL_USE_LLVM=1) add_custom_command(OUTPUT ${BASE_OBJ} @@ -43,6 +44,69 @@ index 2b54b261..5c1f14c7 100644 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_custom_target(gen_base.o SOURCES ${BASE_OBJ}) +@@ -222,7 +227,7 @@ elseif(${MCL_USE_LLVM}) + endif() + + # use src/msm_avx.cpp on x64 +-if(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") # Win64 ++# if(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") # Win64 + # set(MSM_OBJ "${CMAKE_CURRENT_BINARY_DIR}/msm_avx.obj") + + # add_custom_command(OUTPUT ${MSM_OBJ} +@@ -236,20 +241,20 @@ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") # Win64 + # add_dependencies(mcl_st msm_avx.o) + # target_sources(mcl_st PRIVATE ${MSM_OBJ}) + +-elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT APPLE) +- set(MSM_OBJ "${CMAKE_CURRENT_BINARY_DIR}/msm_avx.o") +- +- add_custom_command(OUTPUT ${MSM_OBJ} +- COMMAND ${CMAKE_CXX_COMPILER} -c -o ${MSM_OBJ} ${CMAKE_CURRENT_SOURCE_DIR}/src/msm_avx.cpp ${MCL_COMPILE_OPTIONS} -I ${CMAKE_CURRENT_SOURCE_DIR}/include -mavx512f -mavx512ifma -std=c++11 -fno-exceptions -fno-rtti -DCYBOZU_DONT_USE_STRING -DCYBOZU_DONT_USE_EXCEPTION -DNDEBUG +- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +- add_custom_target(msm_avx.o +- SOURCES ${MSM_OBJ}) +- target_link_libraries(mcl PUBLIC ${MSM_OBJ}) +- add_dependencies(mcl msm_avx.o) +- target_link_libraries(mcl_st PUBLIC ${MSM_OBJ}) +- add_dependencies(mcl_st msm_avx.o) +- target_sources(mcl_st PRIVATE ${MSM_OBJ}) +-endif() ++# elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT APPLE) ++# set(MSM_OBJ "${CMAKE_CURRENT_BINARY_DIR}/msm_avx.o") ++ ++# add_custom_command(OUTPUT ${MSM_OBJ} ++# COMMAND ${CMAKE_CXX_COMPILER} -c -o ${MSM_OBJ} ${CMAKE_CURRENT_SOURCE_DIR}/src/msm_avx.cpp ${MCL_COMPILE_OPTIONS} -I ${CMAKE_CURRENT_SOURCE_DIR}/include -mavx512f -mavx512ifma -std=c++11 -fno-exceptions -fno-rtti -DCYBOZU_DONT_USE_STRING -DCYBOZU_DONT_USE_EXCEPTION -DNDEBUG ++# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) ++# add_custom_target(msm_avx.o ++# SOURCES ${MSM_OBJ}) ++# target_link_libraries(mcl PUBLIC ${MSM_OBJ}) ++# add_dependencies(mcl msm_avx.o) ++# target_link_libraries(mcl_st PUBLIC ${MSM_OBJ}) ++# add_dependencies(mcl_st msm_avx.o) ++# target_sources(mcl_st PRIVATE ${MSM_OBJ}) ++# endif() + + if(MCL_TEST_WITH_GMP) + if(NOT MSVC) +diff --git a/include/mcl/op.hpp b/include/mcl/op.hpp +index 5bf4bc7b..1da38f1d 100644 +--- a/include/mcl/op.hpp ++++ b/include/mcl/op.hpp +@@ -411,13 +411,7 @@ inline void dump(const std::string& s) + + } } // mcl::fp + +-#ifndef MCL_MSM +- #if (/*defined(_WIN64) ||*/ defined(__x86_64__)) && !defined(__APPLE__) && (MCL_SIZEOF_UNIT == 8) +- #define MCL_MSM 1 +- #else +- #define MCL_MSM 0 +- #endif +-#endif ++#define MCL_MSM 0 + + #if MCL_MSM == 1 + namespace mcl { namespace msm { diff --git a/Makefile b/Makefile index a60dbf59..0d27036b 100644 --- a/Makefile diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 5a797d9..06ef882 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -394,15 +394,15 @@ def _com_github_herumi_mcl(): maybe( http_archive, name = "com_github_herumi_mcl", - strip_prefix = "mcl-1.88", - sha256 = "7fcc630c008e973dda88dd1d1cd2bb14face95ee3ed3b2f717fbb25d340d6ba5", + strip_prefix = "mcl-1.99", + sha256 = "5ff9702c1f1b021925d1334ca0a03c87783174075aeaf87801842d3c08b3d39e", type = "tar.gz", build_file = "@yacl//bazel:mcl.BUILD", patch_args = ["-p1"], patches = [ "@yacl//bazel:patches/mcl.patch", ], - urls = ["https://github.com/herumi/mcl/archive/refs/tags/v1.88.tar.gz"], + urls = ["https://github.com/herumi/mcl/archive/refs/tags/v1.99.tar.gz"], ) def _lib25519(): diff --git a/yacl/crypto/ecc/mcl/mcl_ec_factory.cc b/yacl/crypto/ecc/mcl/mcl_ec_factory.cc index 1d94158..4356e53 100644 --- a/yacl/crypto/ecc/mcl/mcl_ec_factory.cc +++ b/yacl/crypto/ecc/mcl/mcl_ec_factory.cc @@ -28,17 +28,17 @@ std::map Name2MclCurveEnum = { {"secp160k1", MCL_SECP160K1}, }; -#define CASE_DEFINE(mcl_curve_macro, class_name) \ - case mcl_curve_macro: { \ - static auto generator = [&] { \ - auto p = std::make_shared(); \ - mcl::initCurve( \ - curve_type, p.get(), mcl::fp::Mode::FP_AUTO, mcl::ec::Jacobi); \ - return p; \ - }(); \ - YACL_ENFORCE(!generator->isZero()); \ - return std::unique_ptr( \ - new class_name(meta, curve_type, AnyPtr(generator))); \ +#define CASE_DEFINE(mcl_curve_macro, class_name) \ + case mcl_curve_macro: { \ + static auto generator = [&] { \ + auto p = std::make_shared(); \ + mcl::initCurve(curve_type, p.get(), \ + mcl::fp::Mode::FP_AUTO, mcl::ec::Jacobi); \ + return p; \ + }(); \ + YACL_ENFORCE(!generator->isZero()); \ + return std::unique_ptr( \ + new class_name(meta, curve_type, AnyPtr(generator))); \ } std::unique_ptr MclEGFactory::Create(const CurveMeta& meta) { diff --git a/yacl/crypto/ecc/mcl/mcl_ec_group.h b/yacl/crypto/ecc/mcl/mcl_ec_group.h index c5dd57b..75ecf67 100644 --- a/yacl/crypto/ecc/mcl/mcl_ec_group.h +++ b/yacl/crypto/ecc/mcl/mcl_ec_group.h @@ -35,7 +35,7 @@ class MclEGFactory { template class MclGroupT : public EcGroupSketch { public: - using Ec = mcl::EcT; + using Ec = mcl::EcT; using Fr = Zn_; using Fp = Fp_; using BaseFp = typename Fp::BaseFp; diff --git a/yacl/math/galois_field/factory/mcl_factory.cc b/yacl/math/galois_field/factory/mcl_factory.cc index 2cca5b9..150627c 100644 --- a/yacl/math/galois_field/factory/mcl_factory.cc +++ b/yacl/math/galois_field/factory/mcl_factory.cc @@ -81,7 +81,9 @@ std::unique_ptr MclFieldFactory::Create( new MclField>, 6>(mod)); case 12: return std::unique_ptr( - new MclField>, 12>(mod)); + new MclField, + mcl::FpT>, + 12>(mod)); default: YACL_THROW("Not supported Field by {}", kMclLib); } diff --git a/yacl/math/galois_field/factory/mcl_factory.h b/yacl/math/galois_field/factory/mcl_factory.h index 9dbbc03..ca9d210 100644 --- a/yacl/math/galois_field/factory/mcl_factory.h +++ b/yacl/math/galois_field/factory/mcl_factory.h @@ -19,6 +19,10 @@ #include "yacl/math/galois_field/factory/gf_scalar.h" +namespace mcl::bn::local { +struct FrTag; +} + namespace yacl::math { class MclFieldFactory { @@ -121,6 +125,7 @@ using DefaultFp = mcl::FpT<>; // size 512 using FpWithSize256 = mcl::FpT; // Max element size 256 bits using DefaultFp2 = mcl::Fp2T>; using DefaultFp6 = mcl::Fp6T>; -using DefaultFp12 = mcl::Fp12T>; // size 512 +using DefaultFp12 = + mcl::Fp12T, mcl::FpT>; // size 512 } // namespace yacl::math