From fea16a1591dd14e264339ba0fbfbd37db4fcc64a Mon Sep 17 00:00:00 2001 From: Iluvmagick Date: Thu, 3 Oct 2024 22:04:33 +0400 Subject: [PATCH] Updated algebra examples to run. --- crypto3/libs/algebra/example/CMakeLists.txt | 8 +- crypto3/libs/algebra/example/curves.cpp | 89 +++++-------------- crypto3/libs/algebra/example/fields.cpp | 38 -------- .../libs/algebra/example/hash_to_curve.cpp | 0 crypto3/libs/algebra/example/multiexp.cpp | 28 +++--- crypto3/libs/algebra/example/pairing.cpp | 4 - .../libs/algebra/example/random_element.cpp | 26 ++---- .../nil/crypto3/algebra/curves/babyjubjub.hpp | 3 - .../nil/crypto3/algebra/curves/bls12.hpp | 6 -- .../nil/crypto3/algebra/curves/jubjub.hpp | 3 - .../algebra/fields/bn128/base_field.hpp | 1 + .../algebra/fields/bn128/scalar_field.hpp | 1 + .../nil/crypto3/algebra/fields/dsa_botan.hpp | 2 + .../nil/crypto3/algebra/fields/dsa_jce.hpp | 2 + .../nil/crypto3/algebra/fields/field.hpp | 5 +- .../nil/crypto3/algebra/multiexp/multiexp.hpp | 21 ++--- 16 files changed, 65 insertions(+), 172 deletions(-) delete mode 100644 crypto3/libs/algebra/example/hash_to_curve.cpp diff --git a/crypto3/libs/algebra/example/CMakeLists.txt b/crypto3/libs/algebra/example/CMakeLists.txt index 90969025d4..e80e023306 100644 --- a/crypto3/libs/algebra/example/CMakeLists.txt +++ b/crypto3/libs/algebra/example/CMakeLists.txt @@ -11,10 +11,11 @@ macro(define_algebra_example name) target_link_libraries(algebra_${name}_example PRIVATE ${CMAKE_WORKSPACE_NAME}_algebra - $ + crypto3::multiprecision + Boost::random ) - set_target_properties(algebra_${name}_example PROPERTIES CXX_STANDARD 14) + set_target_properties(algebra_${name}_example PROPERTIES CXX_STANDARD 17) endmacro() set(EXAMPLES_NAMES @@ -23,8 +24,7 @@ set(EXAMPLES_NAMES "curves" "fields" "pairing" - "random_element" - "hash_to_curve") + "random_element") foreach(EXAMPLE_NAME ${EXAMPLES_NAMES}) define_algebra_example(${EXAMPLE_NAME}) diff --git a/crypto3/libs/algebra/example/curves.cpp b/crypto3/libs/algebra/example/curves.cpp index b93144264a..cd9eefe08d 100644 --- a/crypto3/libs/algebra/example/curves.cpp +++ b/crypto3/libs/algebra/example/curves.cpp @@ -32,21 +32,17 @@ #include #include -#include #include #include #include #include -//#include #include #include #include using namespace nil::crypto3::algebra; -// print dunctions can be made using arity in fields - template void fp_curve_group_basic_math_examples() { typedef typename FpCurveGroup::value_type group_value_type; @@ -64,46 +60,17 @@ void fp_curve_group_basic_math_examples() { std::cout << "c1 - c2 value: " << (c1 - c2) << std::endl; - std::cout << "Doubled c1 value: " << (c1.doubled()) << std::endl; - - group_value_type cd = c1.doubled(); - - // group_value_type cn = c1.normalize(); - // std::cout << "c1 normalized value: " << (cn) << std::endl; + std::cout << "doubled c1 value: " << (c1 + c1) << std::endl; } -template -void fp2_curve_group_basic_math_examples() { - using group_value_type = typename Fp2CurveGroup::value_type; - using field_value_type = typename Fp2CurveGroup::field_type::value_type; - - group_value_type c1 = group_value_type::one(), c2 = group_value_type::one().doubled(); - - std::cout << "Curve element values: " << std::endl; - std::cout << "c1 value: " << (c1) << std::endl; - - std::cout << "c2 value: " << (c2) << std::endl; - - std::cout << "c1 + c2 value: " << (c1 + c2) << std::endl; - - std::cout << "c1 - c2 value: " << (c1 - c2) << std::endl; - - std::cout << "Doubled c1 value: " << (c1.doubled()) << std::endl; - - group_value_type cd = c1.doubled(); - - // group_value_type cn = c1.normalize(); - // std::cout << "c1 normalized value: " << (cn) << std::endl; -} - -template -void fp3_curve_group_basic_math_examples() { - using group_value_type = typename Fp3CurveGroup::value_type; - using field_value_type = typename Fp3CurveGroup::field_type::value_type; +template +void fp2_and_3_curve_group_basic_math_examples() { + using group_value_type = typename FpCurveGroup::value_type; + using field_value_type = typename FpCurveGroup::field_type::value_type; - group_value_type c1 = group_value_type::one(), c2 = group_value_type::one().doubled(); + group_value_type c1 = group_value_type::one(), c2 = group_value_type::one() + group_value_type::one(); std::cout << "Curve element values: " << std::endl; std::cout << "c1 value: " << (c1) << std::endl; @@ -114,12 +81,8 @@ void fp3_curve_group_basic_math_examples() { std::cout << "c1 - c2 value: " << (c1 - c2) << std::endl; - std::cout << "Doubled c1 value: " << (c1.doubled()) << std::endl; - - group_value_type cd = c1.doubled(); + std::cout << "doubled c1 value: " << (c1 + c1) << std::endl; - // group_value_type cn = c1.normalize(); - // std::cout << "c1 normalized value: " << (cn) << std::endl; } int main() { @@ -129,17 +92,17 @@ int main() { std::cout << "----------------------------" << std::endl; std::cout << "ALT_BN128-254 curve g2 group basic math:" << std::endl; - fp2_curve_group_basic_math_examples::g2_type<>>(); + fp2_and_3_curve_group_basic_math_examples::g2_type<>>(); std::cout << "----------------------------" << std::endl; std::cout << "BLS12-381 curve g1 group basic math:" << std::endl; - fp_curve_group_basic_math_examples::g1_type<>>(); + fp2_and_3_curve_group_basic_math_examples::g1_type<>>(); std::cout << "----------------------------" << std::endl; std::cout << "BLS12-381 curve g2 group basic math:" << std::endl; - fp2_curve_group_basic_math_examples::g2_type<>>(); + fp2_and_3_curve_group_basic_math_examples::g2_type<>>(); std::cout << "----------------------------" << std::endl; @@ -149,17 +112,7 @@ int main() { std::cout << "----------------------------" << std::endl; std::cout << "BLS12-377 curve g2 group basic math:" << std::endl; - fp2_curve_group_basic_math_examples::g2_type<>>(); - - std::cout << "----------------------------" << std::endl; - - std::cout << "Edwards curve g1 group basic math:" << std::endl; - fp_curve_group_basic_math_examples::g1_type<>>(); - - std::cout << "----------------------------" << std::endl; - - std::cout << "Edwards curve g2 group basic math:" << std::endl; - fp3_curve_group_basic_math_examples::g2_type<>>(); + fp2_and_3_curve_group_basic_math_examples::g2_type<>>(); std::cout << "----------------------------" << std::endl; @@ -168,13 +121,13 @@ int main() { using babyjubjub_g1_type = typename curves::babyjubjub::g1_type<>; using bjj_g1_f_v = typename babyjubjub_g1_type::field_type::value_type; - typename babyjubjub_g1_type::value_type - P1(bjj_g1_f_v(0x274DBCE8D15179969BC0D49FA725BDDF9DE555E0BA6A693C6ADB52FC9EE7A82C_cppui_modular254), - bjj_g1_f_v(0x5CE98C61B05F47FE2EAE9A542BD99F6B2E78246231640B54595FEBFD51EB853_cppui_modular251)), - P2(bjj_g1_f_v(0x2491ABA8D3A191A76E35BC47BD9AFE6CC88FEE14D607CBE779F2349047D5C157_cppui_modular254), - bjj_g1_f_v(0x2E07297F8D3C3D7818DBDDFD24C35583F9A9D4ED0CB0C1D1348DD8F7F99152D7_cppui_modular254)), - P3(bjj_g1_f_v(0x11805510440A3488B3B811EAACD0EC7C72DDED51978190E19067A2AFAEBAF361_cppui_modular253), - bjj_g1_f_v(0x1F07AA1B3C598E2FF9FF77744A39298A0A89A9027777AF9FA100DD448E072C13_cppui_modular253)); + typename babyjubjub_g1_type::value_type + P1(bjj_g1_f_v(0x274DBCE8D15179969BC0D49FA725BDDF9DE555E0BA6A693C6ADB52FC9EE7A82C_cppui_modular254), + bjj_g1_f_v(0x5CE98C61B05F47FE2EAE9A542BD99F6B2E78246231640B54595FEBFD51EB853_cppui_modular251)), + P2(bjj_g1_f_v(0x2491ABA8D3A191A76E35BC47BD9AFE6CC88FEE14D607CBE779F2349047D5C157_cppui_modular254), + bjj_g1_f_v(0x2E07297F8D3C3D7818DBDDFD24C35583F9A9D4ED0CB0C1D1348DD8F7F99152D7_cppui_modular254)), + P3(bjj_g1_f_v(0x11805510440A3488B3B811EAACD0EC7C72DDED51978190E19067A2AFAEBAF361_cppui_modular253), + bjj_g1_f_v(0x1F07AA1B3C598E2FF9FF77744A39298A0A89A9027777AF9FA100DD448E072C13_cppui_modular253)); std::cout << "BabyJubJub addition test: " << std::endl; typename babyjubjub_g1_type::value_type P1pP2 = P1 + P2; @@ -188,7 +141,7 @@ int main() { std::cout << "----------------------------" << std::endl; std::cout << "Mnt4 curve g2 group basic math:" << std::endl; - fp2_curve_group_basic_math_examples::g2_type<>>(); + fp2_and_3_curve_group_basic_math_examples::g2_type<>>(); std::cout << "----------------------------" << std::endl; @@ -198,13 +151,13 @@ int main() { std::cout << "----------------------------" << std::endl; std::cout << "Mnt6 curve g2 group basic math:" << std::endl; - fp3_curve_group_basic_math_examples::g2_type<>>(); + fp2_and_3_curve_group_basic_math_examples::g2_type<>>(); std::cout << "----------------------------" << std::endl; std::cout << "Pallas curve g1 group basic math:" << std::endl; fp_curve_group_basic_math_examples>(); - + std::cout << "----------------------------" << std::endl; return 0; diff --git a/crypto3/libs/algebra/example/fields.cpp b/crypto3/libs/algebra/example/fields.cpp index d524fa8ed2..1c27529261 100644 --- a/crypto3/libs/algebra/example/fields.cpp +++ b/crypto3/libs/algebra/example/fields.cpp @@ -38,18 +38,12 @@ #include #include #include -#include -#include #include #include #include #include #include #include -//#include -//#include -//#include -//#include #include #include @@ -247,8 +241,6 @@ void fields_fp3_basic_math_examples() { e1 += e2; std::cout << "e1 += e2 value: " << e1 << std::endl; - - // std::cout << "e1 inversed value: " << e1.inversed() << std::endl; } int main() { @@ -312,21 +304,6 @@ int main() { std::cout << "----------------------------" << std::endl; - std::cout << "Edwards Fq basic math:" << std::endl; - fields_fp_basic_math_examples>(); - - std::cout << "----------------------------" << std::endl; - - std::cout << "Edwards Fq3 basic math:" << std::endl; - fields_fp3_basic_math_examples>>(); - - std::cout << "----------------------------" << std::endl; - - std::cout << "Edwards Fr basic math:" << std::endl; - fields_fp_basic_math_examples>(); - - std::cout << "----------------------------" << std::endl; - std::cout << "MNT4 Fq basic math:" << std::endl; fields_fp_basic_math_examples>(); @@ -365,20 +342,5 @@ int main() { std::cout << "DSA JCE 1024 basic math:" << std::endl; fields_fp_basic_math_examples>(); - /* std::cout << "----------------------------" << std::endl; - - std::cout << "FFDHE IETF 2048 basic math:" << std::endl; - fields_fp_basic_math_examples>(); - - std::cout << "----------------------------" << std::endl; - - std::cout << "MODP IETF 1024 basic math:" << std::endl; - fields_fp_basic_math_examples>(); - - std::cout << "----------------------------" << std::endl; - - std::cout << "MODP SRP 1024 basic math:" << std::endl; - fields_fp_basic_math_examples>();*/ - return 0; } diff --git a/crypto3/libs/algebra/example/hash_to_curve.cpp b/crypto3/libs/algebra/example/hash_to_curve.cpp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/crypto3/libs/algebra/example/multiexp.cpp b/crypto3/libs/algebra/example/multiexp.cpp index f3349deddb..443e5d5a26 100644 --- a/crypto3/libs/algebra/example/multiexp.cpp +++ b/crypto3/libs/algebra/example/multiexp.cpp @@ -65,12 +65,9 @@ test_instances_t generate_group_elements(std::size_t count, std::size test_instances_t result(count); for (size_t i = 0; i < count; i++) { - - typename GroupType::value_type x = random_element().to_projective(); // djb requires input to be in special form - + auto x = random_element(); for (size_t j = 0; j < size; j++) { result[i].push_back(x); - // result[i].push_back(random_element()); } } @@ -103,8 +100,10 @@ run_result_t profile_multiexp(test_instances_t group_eleme std::vector answers; for (size_t i = 0; i < group_elements.size(); i++) { - answers.push_back(multiexp(group_elements[i].cbegin(), group_elements[i].cend(), - scalars[i].cbegin(), scalars[i].cend(), 1)); + answers.push_back( + multiexp( + group_elements[i].cbegin(), group_elements[i].cend(), + scalars[i].cbegin(), scalars[i].cend(), 1)); } long long time_delta = get_nsec_time() - start_time; @@ -113,7 +112,9 @@ run_result_t profile_multiexp(test_instances_t group_eleme } template -void print_performance_csv(size_t expn_start, std::size_t expn_end_fast, std::size_t expn_end_naive, bool compare_answers) { +void print_performance_csv( + size_t expn_start, std::size_t expn_end_fast, std::size_t expn_end_naive, bool compare_answers +) { for (size_t expn = expn_start; expn <= expn_end_fast; expn++) { printf("%ld", expn); fflush(stdout); @@ -122,12 +123,12 @@ void print_performance_csv(size_t expn_start, std::size_t expn_end_fast, std::si test_instances_t scalars = generate_scalars(10, 1 << expn); run_result_t result_bos_coster = - profile_multiexp>(group_elements, scalars); + profile_multiexp(group_elements, scalars); printf("\t%lld", result_bos_coster.first); fflush(stdout); run_result_t result_djb = - profile_multiexp>(group_elements, scalars); + profile_multiexp(group_elements, scalars); printf("\t%lld", result_djb.first); fflush(stdout); @@ -137,7 +138,7 @@ void print_performance_csv(size_t expn_start, std::size_t expn_end_fast, std::si if (expn <= expn_end_naive) { run_result_t result_naive = - profile_multiexp>(group_elements, scalars); + profile_multiexp(group_elements, scalars); printf("\t%lld", result_naive.first); fflush(stdout); @@ -151,12 +152,15 @@ void print_performance_csv(size_t expn_start, std::size_t expn_end_fast, std::si } int main() { + using g1 = curves::bls12<381>::g1_type<>; + using g2 = curves::bls12<381>::g2_type<>; + using scalar_field_type = curves::bls12<381>::scalar_field_type; std::cout << "Testing BLS12-381 G1" << std::endl; - print_performance_csv::g1_type, curves::bls12<381>::scalar_field_type>(2, 20, 14, true); + print_performance_csv(2, 20, 14, true); std::cout << "Testing BLS12-381 G2" << std::endl; - print_performance_csv::g2_type, curves::bls12<381>::scalar_field_type>(2, 20, 14, true); + print_performance_csv(2, 20, 14, true); return 0; } diff --git a/crypto3/libs/algebra/example/pairing.cpp b/crypto3/libs/algebra/example/pairing.cpp index 9c1ca7d27f..716067bd67 100644 --- a/crypto3/libs/algebra/example/pairing.cpp +++ b/crypto3/libs/algebra/example/pairing.cpp @@ -37,11 +37,9 @@ #include #include #include -#include #include #include #include -#include #include #include @@ -106,6 +104,4 @@ int main() { pairing_example>(); pairing_example>(); - - pairing_example>(); } diff --git a/crypto3/libs/algebra/example/random_element.cpp b/crypto3/libs/algebra/example/random_element.cpp index 2c6a680c4e..5a45298584 100644 --- a/crypto3/libs/algebra/example/random_element.cpp +++ b/crypto3/libs/algebra/example/random_element.cpp @@ -38,20 +38,13 @@ #include #include #include -#include -#include #include #include #include #include -//#include -//#include -//#include -//#include #include #include -#include #include #include @@ -68,29 +61,22 @@ using namespace nil::crypto3::algebra; -template -void random_field_element_example(){ - typename FieldType::value_type v = random_element(); - - std::cout << "Got random value:" << v << std::endl; -} - -template -void random_group_element_example(){ - typename CurveGroupType::value_type v = random_element(); +template +void random_element_example() { + typename Type::value_type v = random_element(); std::cout << "Got random value:" << v << std::endl; } int main() { std::cout << "ALT_BN128-254 Fq random element choice:" << std::endl; - random_field_element_example>(); + random_element_example>(); std::cout << "BLS12-381 Gt random element choice:" << std::endl; - random_field_element_example::gt_type>(); + random_element_example::gt_type>(); std::cout << "BLS12-381 G1 random element choice:" << std::endl; - random_group_element_example::g1_type>(); + random_element_example::g1_type<>>(); return 0; } diff --git a/crypto3/libs/algebra/include/nil/crypto3/algebra/curves/babyjubjub.hpp b/crypto3/libs/algebra/include/nil/crypto3/algebra/curves/babyjubjub.hpp index 97dbd69f80..cc2ef75147 100644 --- a/crypto3/libs/algebra/include/nil/crypto3/algebra/curves/babyjubjub.hpp +++ b/crypto3/libs/algebra/include/nil/crypto3/algebra/curves/babyjubjub.hpp @@ -30,9 +30,6 @@ #include #include -// #include -// #include - namespace nil { namespace crypto3 { namespace algebra { diff --git a/crypto3/libs/algebra/include/nil/crypto3/algebra/curves/bls12.hpp b/crypto3/libs/algebra/include/nil/crypto3/algebra/curves/bls12.hpp index 11a10e3106..821c3a3761 100644 --- a/crypto3/libs/algebra/include/nil/crypto3/algebra/curves/bls12.hpp +++ b/crypto3/libs/algebra/include/nil/crypto3/algebra/curves/bls12.hpp @@ -62,13 +62,7 @@ namespace nil { typename Form = forms::short_weierstrass> using g2_type = typename detail::bls12_g2; #ifndef __ZKLLVM__ - constexpr static const bool has_affine_pairing = false; - - // typedef typename pairing::pairing_policy, - // pairing::detail::bls12_pairing_functions> - // pairing; - #endif typedef typename policy_type::gt_field_type gt_type; }; diff --git a/crypto3/libs/algebra/include/nil/crypto3/algebra/curves/jubjub.hpp b/crypto3/libs/algebra/include/nil/crypto3/algebra/curves/jubjub.hpp index 612659aac0..7643a8ce17 100644 --- a/crypto3/libs/algebra/include/nil/crypto3/algebra/curves/jubjub.hpp +++ b/crypto3/libs/algebra/include/nil/crypto3/algebra/curves/jubjub.hpp @@ -30,9 +30,6 @@ #include #include -// #include -// #include - namespace nil { namespace crypto3 { namespace algebra { diff --git a/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/bn128/base_field.hpp b/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/bn128/base_field.hpp index 5216e0b2f6..81c144a818 100644 --- a/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/bn128/base_field.hpp +++ b/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/bn128/base_field.hpp @@ -58,6 +58,7 @@ namespace nil { constexpr static const integral_type modulus = 0x30644E72E131A029B85045B68181585D97816A916871CA8D3C208C16D87CFD47_cppui_modular254; + constexpr static const integral_type group_order_minus_one_half = (modulus - 1) / 2; typedef typename policy_type::modular_backend modular_backend; constexpr static const modular_params_type modulus_params = modulus.backend(); diff --git a/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/bn128/scalar_field.hpp b/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/bn128/scalar_field.hpp index 015ac64789..64f60ab5a4 100644 --- a/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/bn128/scalar_field.hpp +++ b/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/bn128/scalar_field.hpp @@ -58,6 +58,7 @@ namespace nil { constexpr static const integral_type modulus = 0x30644E72E131A029B85045B68181585D2833E84879B9709143E1F593F0000001_cppui_modular254; + constexpr static const integral_type group_order_minus_one_half = (modulus - 1) / 2; typedef typename policy_type::modular_backend modular_backend; constexpr static const modular_params_type modulus_params = modulus.backend(); diff --git a/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/dsa_botan.hpp b/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/dsa_botan.hpp index 2a35aff7b9..e8c55353f8 100644 --- a/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/dsa_botan.hpp +++ b/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/dsa_botan.hpp @@ -59,6 +59,8 @@ namespace nil { constexpr static const integral_type modulus = 0x91C48A4FDFBCF7C02AE95E7DA126122B5DD2864F559B87E8E74A286D52F59BD1DE68DFD645D0E00C60C080031891980374EEB594A532BFD67B9A09EAC4B8663A07910E68F39465FB7040D25DF13932EBAC4347A530ECBA61C854F9B880D3C0C3660080587C45566DADE26BD5A394BE093B4C0F24B5AFFEF8EC6C5B3E57FB89025A9BC16769932131E16D3C94EFCAB18D0DF061203CC53E6103BC72D5594BFD40CA65380F44A9A851DCB075495FC033A8A58071A1BD78FE052F66555648EB4B719D2AFE8B4880F8DAD6F15818BA178F89274C870BE9B96EB08C46C40040CC2EFE1DFB1B1868DD319DE3C34A32A63AB6EB1224209A419680CC7902D1728D4DF9E1_cppui_modular2048; + constexpr static const integral_type group_order_minus_one_half = (modulus - 1) / 2; + typedef typename policy_type::modular_backend modular_backend; constexpr static const modular_params_type modulus_params = modulus.backend(); typedef boost::multiprecision::number< diff --git a/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/dsa_jce.hpp b/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/dsa_jce.hpp index 49ad55af78..5b3435b01e 100644 --- a/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/dsa_jce.hpp +++ b/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/dsa_jce.hpp @@ -59,6 +59,8 @@ namespace nil { constexpr static const integral_type modulus = 0xFD7F53811D75122952DF4A9C2EECE4E7F611B7523CEF4400C31E3F80B6512669455D402251FB593D8D58FABFC5F5BA30F6CB9B556CD7813B801D346FF26660B76B9950A5A49F9FE8047B1022C24FBBA9D7FEB7C61BF83B57E7C6A8A6150F04FB83F6D3C51EC3023554135A169132F675F3AE2B61D72AEFF22203199DD14801C7_cppui_modular1024; + constexpr static const integral_type group_order_minus_one_half = (modulus - 1) / 2; + typedef typename policy_type::modular_backend modular_backend; constexpr static const modular_params_type modulus_params = modulus.backend(); typedef boost::multiprecision::number< diff --git a/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/field.hpp b/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/field.hpp index 4bcb4a831a..51410e68cc 100755 --- a/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/field.hpp +++ b/crypto3/libs/algebra/include/nil/crypto3/algebra/fields/field.hpp @@ -23,8 +23,7 @@ // SOFTWARE. //---------------------------------------------------------------------------// -#ifndef CRYPTO3_ALGEBRA_FIELDS_FIELD_HPP -#define CRYPTO3_ALGEBRA_FIELDS_FIELD_HPP +#pragma once #include #include @@ -71,5 +70,3 @@ namespace nil { } // namespace algebra } // namespace crypto3 } // namespace nil - -#endif // CRYPTO3_ALGEBRA_FIELDS_FIELD_HPP diff --git a/crypto3/libs/algebra/include/nil/crypto3/algebra/multiexp/multiexp.hpp b/crypto3/libs/algebra/include/nil/crypto3/algebra/multiexp/multiexp.hpp index b7406deaaf..d4e2e508a2 100644 --- a/crypto3/libs/algebra/include/nil/crypto3/algebra/multiexp/multiexp.hpp +++ b/crypto3/libs/algebra/include/nil/crypto3/algebra/multiexp/multiexp.hpp @@ -39,11 +39,12 @@ namespace nil { namespace crypto3 { namespace algebra { template - typename std::iterator_traits::value_type - multiexp(InputBaseIterator vec_start, InputBaseIterator vec_end, InputFieldIterator scalar_start, - InputFieldIterator scalar_end, const std::size_t chunks_count) { + typename InputBaseIterator::value_type + multiexp(const InputBaseIterator vec_start, const InputBaseIterator vec_end, + const InputFieldIterator scalar_start, const InputFieldIterator scalar_end, + const std::size_t chunks_count) { - typedef typename std::iterator_traits::value_type base_value_type; + typedef typename InputBaseIterator::value_type base_value_type; const std::size_t total_size = std::distance(vec_start, vec_end); @@ -57,12 +58,12 @@ namespace nil { base_value_type result = base_value_type::zero(); for (std::size_t i = 0; i < chunks_count; ++i) { - result = - result + MultiexpMethod::process( - vec_start + i * one_chunk_size, - (i == chunks_count - 1 ? vec_end : vec_start + (i + 1) * one_chunk_size), - scalar_start + i * one_chunk_size, - (i == chunks_count - 1 ? scalar_end : scalar_start + (i + 1) * one_chunk_size)); + result += + MultiexpMethod::process( + vec_start + i * one_chunk_size, + (i == chunks_count - 1 ? vec_end : vec_start + (i + 1) * one_chunk_size), + scalar_start + i * one_chunk_size, + (i == chunks_count - 1 ? scalar_end : scalar_start + (i + 1) * one_chunk_size)); } return result;