diff --git a/include/nil/crypto3/algebra/fields/alt_bn128/base_field.hpp b/include/nil/crypto3/algebra/fields/alt_bn128/base_field.hpp index 2a2c3ec4..336d09b3 100644 --- a/include/nil/crypto3/algebra/fields/alt_bn128/base_field.hpp +++ b/include/nil/crypto3/algebra/fields/alt_bn128/base_field.hpp @@ -57,8 +57,8 @@ namespace nil { constexpr static const integral_type modulus = 0x30644E72E131A029B85045B68181585D97816A916871CA8D3C208C16D87CFD47_cppui254; -// constexpr static const integral_type group_order_minus_one_half = -// (modulus - 1) / 2; + constexpr static const integral_type group_order_minus_one_half = + (modulus - 1) / 2; /* constexpr static const integral_type group_order_minus_one_half = 0x183227397098D014DC2822DB40C0AC2ECBC0B548B438E5469E10460B6C3E7EA3_cppui254; @@ -87,7 +87,7 @@ namespace nil { constexpr typename alt_bn128_base_field<254>::integral_type const alt_bn128_base_field<254>::modulus; -// constexpr typename alt_bn128_base_field<254>::integral_type const alt_bn128_base_field<254>::group_order_minus_one_half; + constexpr typename alt_bn128_base_field<254>::integral_type const alt_bn128_base_field<254>::group_order_minus_one_half; constexpr typename alt_bn128_base_field<254>::modular_params_type const alt_bn128_base_field<254>::modulus_params; diff --git a/include/nil/crypto3/algebra/pairing/forms/short_weierstrass/jacobian_with_a4_0_sbit/ate_miller_loop.hpp b/include/nil/crypto3/algebra/pairing/forms/short_weierstrass/jacobian_with_a4_0_sbit/ate_miller_loop.hpp index 6933af18..e6a031a5 100644 --- a/include/nil/crypto3/algebra/pairing/forms/short_weierstrass/jacobian_with_a4_0_sbit/ate_miller_loop.hpp +++ b/include/nil/crypto3/algebra/pairing/forms/short_weierstrass/jacobian_with_a4_0_sbit/ate_miller_loop.hpp @@ -36,90 +36,6 @@ namespace nil { namespace crypto3 { namespace algebra { - - -namespace debug { -template -void print_field_element(std::ostream &os, const typename fields::detail::element_fp &e) { -// os << std::hex <<"0x"<< std::setw((FieldParams::modulus_bits+7)/4) << std::setfill('0') << e.data << "_cppui" << std::dec << FieldParams::modulus_bits << " "; - os << '"' << e.data << '"' ; -} - -template -void print_field_element(std::ostream &os, const typename fields::detail::element_fp2 &e) { - os << " [ "; - print_field_element(os, e.data[0]); - os << ", "; - print_field_element(os, e.data[1]); - os << "]"; -} - -template -void print_field_element(std::ostream &os, const typename fields::detail::element_fp3 &e) { - os << "["; - print_field_element(os, e.data[0]); - os << ", "; - print_field_element(os, e.data[1]); - os << ", "; - print_field_element(os, e.data[2]); - os << "]"; -} - -template -void print_field_element(std::ostream &os, const typename fields::detail::element_fp4 &e) { - os << "["; - print_field_element(os, e.data[0]); - os << ", "; - print_field_element(os, e.data[1]); - os << "]"; -} - -template -void print_field_element(std::ostream &os, const typename fields::detail::element_fp6_2over3 &e) { - os << "["; - print_field_element(os, e.data[0]); - os << ", "; - print_field_element(os, e.data[1]); - os << "]"; -} - -template -void print_field_element(std::ostream &os, const typename fields::detail::element_fp6_3over2 &e) { - os << " [" << std::endl; - print_field_element(os, e.data[0]); - os << ", " << std::endl; - print_field_element(os, e.data[1]); - os << ", " << std::endl; - print_field_element(os, e.data[2]); - os << std::endl << " ]"; -} - - -template -void print_field_element(std::ostream &os, const fields::detail::element_fp12_2over3over2 &e) { - os << "[" << std::endl; - print_field_element(os, e.data[0]); - os << ", " << std::endl; - print_field_element(os, e.data[1]); - os << std::endl << "]"; -} - -template -void print_ell_coeffs(std::ostream &os, - fields::detail::element_fp2 const& ell_0, - fields::detail::element_fp2 const& ell_VW, - fields::detail::element_fp2 const& ell_VV) -{ - os << "{" << std::endl; - os << "\"ell_0\" : "; print_field_element(os, ell_0 ); os << "," << std::endl; - os << "\"ell_VW\": "; print_field_element(os, ell_VW); os << "," << std::endl; - os << "\"ell_VV\": "; print_field_element(os, ell_VV); os << "" << std::endl; - os << "}" << std::endl; -} - -} - - namespace pairing { template @@ -162,52 +78,31 @@ void print_ell_coeffs(std::ostream &os, ++idx; if (params_type::twist_type == twist_type::TWIST_TYPE_M) { f = f.mul_by_014(c.ell_0, prec_P.PX * c.ell_VW, prec_P.PY * c.ell_VV); - debug::print_ell_coeffs(std::cout, c.ell_0, prec_P.PX * c.ell_VW, prec_P.PY * c.ell_VV); } else { f = f.mul_by_034(prec_P.PY * c.ell_0, prec_P.PX * c.ell_VW, c.ell_VV); - debug::print_ell_coeffs(std::cout, prec_P.PY * c.ell_0, prec_P.PX * c.ell_VW, c.ell_VV); } - std::cout << "by bit " << std::setw(2) << (int)(*bit) <<" :"; - debug::print_field_element(std::cout, f); - std::cout << std::endl; } - - std::cout << "-------" << std::endl; } - std::cout << "~~~~~~~~~~~~~~FINAL~~~~~~~~~~~~~" << std::endl; - debug::print_field_element(std::cout, f); std::cout << std::endl; - if (params_type::final_exponent_is_z_neg) { f = f.inversed(); } - std::cout << "~~~~~~~~~~~~~~INVERSED?~~~~~~~~~~~~~" << std::endl; - debug::print_field_element(std::cout, f); std::cout << std::endl; - - - std::cout << "~=~=~=~= Final two coefficeints ~=~=~=~=" << std::endl; c = prec_Q.coeffs[idx]; ++idx; if (params_type::twist_type == twist_type::TWIST_TYPE_M) { f = f.mul_by_014(c.ell_0, prec_P.PX * c.ell_VW, prec_P.PY * c.ell_VV); - debug::print_ell_coeffs(std::cout, c.ell_0, prec_P.PX * c.ell_VW, prec_P.PY * c.ell_VV); } else { f = f.mul_by_034(prec_P.PY * c.ell_0, prec_P.PX * c.ell_VW, c.ell_VV); - debug::print_ell_coeffs(std::cout, prec_P.PY * c.ell_0, prec_P.PX * c.ell_VW, c.ell_VV); } - debug::print_field_element(std::cout, f); std::cout << std::endl; c = prec_Q.coeffs[idx]; ++idx; if (params_type::twist_type == twist_type::TWIST_TYPE_M) { f = f.mul_by_014(c.ell_0, prec_P.PX * c.ell_VW, prec_P.PY * c.ell_VV); - debug::print_ell_coeffs(std::cout, c.ell_0, prec_P.PX * c.ell_VW, prec_P.PY * c.ell_VV); } else { f = f.mul_by_034(prec_P.PY * c.ell_0, prec_P.PX * c.ell_VW, c.ell_VV); - debug::print_ell_coeffs(std::cout, prec_P.PY * c.ell_0, prec_P.PX * c.ell_VW, c.ell_VV); } - debug::print_field_element(std::cout, f); std::cout << std::endl; return f; } diff --git a/include/nil/crypto3/algebra/pairing/forms/short_weierstrass/jacobian_with_a4_0_sbit/ate_precompute_g2.hpp b/include/nil/crypto3/algebra/pairing/forms/short_weierstrass/jacobian_with_a4_0_sbit/ate_precompute_g2.hpp index a2ce9511..fdeade23 100644 --- a/include/nil/crypto3/algebra/pairing/forms/short_weierstrass/jacobian_with_a4_0_sbit/ate_precompute_g2.hpp +++ b/include/nil/crypto3/algebra/pairing/forms/short_weierstrass/jacobian_with_a4_0_sbit/ate_precompute_g2.hpp @@ -54,27 +54,6 @@ namespace nil { using g2_field_type_value = typename g2_type::field_type::value_type; - static void print_g2(typename g2_type::value_type const& v) - { - std::cout << "{"; - std::cout << "\"x\": [ \"" << v.X.data[0] << "\", \"" << v.X.data[1] << "\"], "; - std::cout << "\"y\": [ \"" << v.Y.data[0] << "\", \"" << v.Y.data[1] << "\"], "; - std::cout << "\"z\": [ \"" << v.Z.data[0] << "\", \"" << v.Z.data[1] << "\"]"; - std::cout << "}"; - } - - static void print_ell(typename policy_type::ate_ell_coeffs const& c) - { - std::cout << "{"; - std::cout << "\"ell_0\" : [ \"" - << c.ell_0.data[0] << "\", \"" << c.ell_0.data[1] << "\"], " << std::endl; - std::cout << "\"ell_VW\": [ \"" - << c.ell_VW.data[0] << "\", \"" << c.ell_VW.data[1] << "\"], " << std::endl; - std::cout << "\"ell_VV\": [ \"" - << c.ell_VV.data[0] << "\", \"" << c.ell_VV.data[1] << "\"]" << std::endl; - std::cout << "}"; - } - /* https://eprint.iacr.org/2013/722.pdf * Equations (11) at p.13 * current *= 2, output ell coefficients in c @@ -84,9 +63,6 @@ namespace nil { typename g2_type::value_type ¤t, typename policy_type::ate_ell_coeffs &c) { - -// std::cout << "doubling: "; print_g2(current); std::cout << std::endl; - const g2_field_type_value X = current.X, Y = current.Y, Z = current.Z; const g2_field_type_value A = two_inv * (X * Y); // A = X1 * Y1 / 2 @@ -115,9 +91,6 @@ namespace nil { c.ell_VW = J.doubled()+J; c.ell_VV = I; } -// std::cout << "doubling: "; print_g2(current); std::cout << std::endl; -// print_ell(c); std::cout << std::endl; - } /* https://eprint.iacr.org/2013/722.pdf @@ -129,9 +102,6 @@ namespace nil { typename g2_type::value_type ¤t, typename policy_type::ate_ell_coeffs &c) { - -// std::cout << "adding: "; print_g2(current); std::cout << std::endl; - const g2_field_type_value X1 = current.X, Y1 = current.Y, Z1 = current.Z; const g2_field_type_value &x2 = base.X, &y2 = base.Y; @@ -159,8 +129,6 @@ namespace nil { c.ell_VW = -theta; c.ell_VV = J; } -// std::cout << "adding: "; print_g2(current); std::cout << std::endl; -// print_ell(c); std::cout << std::endl; } static typename g2_affine_type::value_type mul_by_char( diff --git a/include/nil/crypto3/algebra/pairing/forms/short_weierstrass/jacobian_with_a4_0_sbit/final_exponentiation.hpp b/include/nil/crypto3/algebra/pairing/forms/short_weierstrass/jacobian_with_a4_0_sbit/final_exponentiation.hpp index 366bcaca..c8f9bc98 100644 --- a/include/nil/crypto3/algebra/pairing/forms/short_weierstrass/jacobian_with_a4_0_sbit/final_exponentiation.hpp +++ b/include/nil/crypto3/algebra/pairing/forms/short_weierstrass/jacobian_with_a4_0_sbit/final_exponentiation.hpp @@ -32,90 +32,6 @@ namespace nil { namespace crypto3 { namespace algebra { - /* - namespace debug { - -template -void print_field_element(std::ostream &os, const typename fields::detail::element_fp &e) { -// os << std::hex <<"0x"<< std::setw((FieldParams::modulus_bits+7)/4) << std::setfill('0') << e.data << "_cppui" << std::dec << FieldParams::modulus_bits << " "; - os << '"' << e.data << '"' ; -} - -template -void print_field_element(std::ostream &os, const typename fields::detail::element_fp2 &e) { - os << "["; - print_field_element(os, e.data[0]); - os << ", "; - print_field_element(os, e.data[1]); - os << "]"; -} - -template -void print_field_element(std::ostream &os, const typename fields::detail::element_fp3 &e) { - os << "["; - print_field_element(os, e.data[0]); - os << ", "; - print_field_element(os, e.data[1]); - os << ", "; - print_field_element(os, e.data[2]); - os << "]"; -} - -template -void print_field_element(std::ostream &os, const typename fields::detail::element_fp4 &e) { - os << "["; - print_field_element(os, e.data[0]); - os << ", "; - print_field_element(os, e.data[1]); - os << "]"; -} - -template -void print_field_element(std::ostream &os, const typename fields::detail::element_fp6_2over3 &e) { - os << "["; - print_field_element(os, e.data[0]); - os << ", "; - print_field_element(os, e.data[1]); - os << "]"; -} - -template -void print_field_element(std::ostream &os, const typename fields::detail::element_fp6_3over2 &e) { - os << "["; - print_field_element(os, e.data[0]); - os << ", "; - print_field_element(os, e.data[1]); - os << ", "; - print_field_element(os, e.data[2]); - os << "]"; -} - - -template -void print_field_element(std::ostream &os, const fields::detail::element_fp12_2over3over2 &e) { - os << "["; - print_field_element(os, e.data[0]); - os << ", "; - print_field_element(os, e.data[1]); - os << "]"; -} - -template -void print_ell_coeffs(std::ostream &os, - fields::detail::element_fp2 const& ell_0, - fields::detail::element_fp2 const& ell_VW, - fields::detail::element_fp2 const& ell_VV) -{ - os << "{" << std::endl; - os << "\"ell_0\" : "; print_field_element(os, ell_0 ); os << "," << std::endl; - os << "\"ell_VW\": "; print_field_element(os, ell_VW); os << "," << std::endl; - os << "\"ell_VV\": "; print_field_element(os, ell_VV); os << "" << std::endl; - os << "}" << std::endl; -} -} -*/ - - namespace pairing { template @@ -141,68 +57,37 @@ void print_ell_coeffs(std::ostream &os, * */ static typename gt_type::value_type process(const typename gt_type::value_type &elt) { - std::cout << "~~~~~ FINAL EXPONENTIATION ~~~~~~" << std::endl; - std::cout << "elt: "; debug::print_field_element(std::cout, elt); std::cout << std::endl; - -#define DUMP_FP12(X) { std::cout << #X " :" ; debug::print_field_element(std::cout, X); std::cout << std::endl; } /* TODO: check elt == 0 ? */ auto f1 = elt.unitary_inversed(); - DUMP_FP12(f1); auto f2 = elt.inversed(); - DUMP_FP12(f2); auto r = f1 * f2; f2 = r; r = r.Frobenius_map(2); r *= f2; - DUMP_FP12(r); - auto y0 = exp_by_z(r); - DUMP_FP12(y0); auto y1 = y0.cyclotomic_squared(); - DUMP_FP12(y1); auto y2 = y1.cyclotomic_squared(); - DUMP_FP12(y2); auto y3 = y2 * y1; - DUMP_FP12(y3); auto y4 = exp_by_z(y3); - DUMP_FP12(y4); auto y5 = y4.cyclotomic_squared(); - DUMP_FP12(y5); auto y6 = exp_by_z(y5); - DUMP_FP12(y6); y3 = y3.unitary_inversed(); - DUMP_FP12(y3); y6 = y6.unitary_inversed(); - DUMP_FP12(y6); auto y7 = y6 * y4; - DUMP_FP12(y7); auto y8 = y7 * y3; - DUMP_FP12(y8); auto y9 = y8 * y1; - DUMP_FP12(y9); auto y10 = y8 * y4; - DUMP_FP12(y10); auto y11 = y10 * r; - DUMP_FP12(y11); auto y12 = y9.Frobenius_map(1); - DUMP_FP12(y12); auto y13 = y12 * y11; - DUMP_FP12(y13); y8 = y8.Frobenius_map(2); - DUMP_FP12(y8); auto y14 = y8 * y13; - DUMP_FP12(y14); r = r.unitary_inversed(); - DUMP_FP12(r); auto y15 = r * y9; - DUMP_FP12(y15); y15 = y15.Frobenius_map(3); - DUMP_FP12(y15); auto result = y15 * y14; - DUMP_FP12(result); - return result; } }; diff --git a/test/pairing_debug.cpp b/test/pairing_debug.cpp index c363ab8d..cee9daf1 100644 --- a/test/pairing_debug.cpp +++ b/test/pairing_debug.cpp @@ -893,11 +893,11 @@ void check_curve() { BOOST_AUTO_TEST_SUITE(pairing_debug_tests) BOOST_AUTO_TEST_CASE(pairing_operation_test_atl_bn128_254) { -// using curve_type = typename curves::alt_bn128_254; + using curve_type = typename curves::alt_bn128_254; //using curve_type = typename curves::mnt4<298>; //using curve_type = typename curves::mnt6<298>; //using curve_type = typename curves::bls12<381>; - using curve_type = typename curves::bls12<377>; +// using curve_type = typename curves::bls12<377>; // check_curve();