forms/short_weierstrass/jacobian_with_a4_0/ate_double_miller_loop.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2020-2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020-2021 Nikita Kaskov <nbering@nil.foundation>
4 //
5 // MIT License
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 //---------------------------------------------------------------------------//
25 
26 #ifndef CRYPTO3_ALGEBRA_PAIRING_SHORT_WEIERSTRASS_JACOBIAN_WITH_A4_0_ATE_DOUBLE_MILLER_LOOP_HPP
27 #define CRYPTO3_ALGEBRA_PAIRING_SHORT_WEIERSTRASS_JACOBIAN_WITH_A4_0_ATE_DOUBLE_MILLER_LOOP_HPP
28 
29 #include <nil/crypto3/multiprecision/number.hpp>
30 #include <nil/crypto3/multiprecision/cpp_int.hpp>
31 
33 
34 namespace nil {
35  namespace crypto3 {
36  namespace algebra {
37  namespace pairing {
38 
39  template<typename CurveType>
41  using curve_type = CurveType;
42 
45 
46  using gt_type = typename curve_type::gt_type;
47 
48  public:
49  static typename gt_type::value_type
51  const typename policy_type::ate_g2_precomputed_type &prec_Q1,
52  const typename policy_type::ate_g1_precomputed_type &prec_P2,
53  const typename policy_type::ate_g2_precomputed_type &prec_Q2) {
54 
55  typename gt_type::value_type f = gt_type::value_type::one();
56 
57  bool found_one = false;
58  std::size_t idx = 0;
59 
60  const typename policy_type::integral_type &loop_count = params_type::ate_loop_count;
61 
62  for (long i = params_type::integral_type_max_bits; i >= 0; --i) {
63  const bool bit = nil::crypto3::multiprecision::bit_test(loop_count, i);
64  if (!found_one) {
65  /* this skips the MSB itself */
66  found_one |= bit;
67  continue;
68  }
69 
70  /* code below gets executed for all bits (EXCEPT the MSB itself) of
71  param_p (skipping leading zeros) in MSB to LSB
72  order */
73 
74  typename policy_type::ate_ell_coeffs c1 = prec_Q1.coeffs[idx];
75  typename policy_type::ate_ell_coeffs c2 = prec_Q2.coeffs[idx];
76  ++idx;
77 
78  f = f.squared();
79 
80  f = f.mul_by_045(c1.ell_0, prec_P1.PY * c1.ell_VW, prec_P1.PX * c1.ell_VV);
81  f = f.mul_by_045(c2.ell_0, prec_P2.PY * c2.ell_VW, prec_P2.PX * c2.ell_VV);
82 
83  if (bit) {
84  typename policy_type::ate_ell_coeffs c1 = prec_Q1.coeffs[idx];
85  typename policy_type::ate_ell_coeffs c2 = prec_Q2.coeffs[idx];
86  ++idx;
87 
88  f = f.mul_by_045(c1.ell_0, prec_P1.PY * c1.ell_VW, prec_P1.PX * c1.ell_VV);
89  f = f.mul_by_045(c2.ell_0, prec_P2.PY * c2.ell_VW, prec_P2.PX * c2.ell_VV);
90  }
91  }
92 
93  if (params_type::ate_is_loop_count_neg) {
94  f = f.inversed();
95  }
96 
97  return f;
98  }
99  };
100  } // namespace pairing
101  } // namespace algebra
102  } // namespace crypto3
103 } // namespace nil
104 #endif // CRYPTO3_ALGEBRA_PAIRING_SHORT_WEIERSTRASS_JACOBIAN_WITH_A4_0_ATE_DOUBLE_MILLER_LOOP_HPP
Definition: pairing/detail/alt_bn128/params.hpp:38
Definition: pairing/detail/forms/short_weierstrass/jacobian_with_a4_0/types.hpp:36
typename curve_type::base_field_type::integral_type integral_type
Definition: pairing/detail/forms/short_weierstrass/jacobian_with_a4_0/types.hpp:40
Definition: forms/short_weierstrass/jacobian_with_a4_0/ate_double_miller_loop.hpp:40
static gt_type::value_type process(const typename policy_type::ate_g1_precomputed_type &prec_P1, const typename policy_type::ate_g2_precomputed_type &prec_Q1, const typename policy_type::ate_g1_precomputed_type &prec_P2, const typename policy_type::ate_g2_precomputed_type &prec_Q2)
Definition: forms/short_weierstrass/jacobian_with_a4_0/ate_double_miller_loop.hpp:50
Definition: pair.hpp:31
Definition: pairing/detail/forms/short_weierstrass/jacobian_with_a4_0/types.hpp:68
std::vector< coeffs_type > coeffs
Definition: pairing/detail/forms/short_weierstrass/jacobian_with_a4_0/types.hpp:73
Definition: pairing/detail/forms/short_weierstrass/jacobian_with_a4_0/types.hpp:46
g1_field_value_type PX
Definition: pairing/detail/forms/short_weierstrass/jacobian_with_a4_0/types.hpp:48
g1_field_value_type PY
Definition: pairing/detail/forms/short_weierstrass/jacobian_with_a4_0/types.hpp:49
Definition: pairing/detail/forms/short_weierstrass/jacobian_with_a4_0/types.hpp:56
g2_field_value_type ell_VV
Definition: pairing/detail/forms/short_weierstrass/jacobian_with_a4_0/types.hpp:60
g2_field_value_type ell_VW
Definition: pairing/detail/forms/short_weierstrass/jacobian_with_a4_0/types.hpp:59
g2_field_value_type ell_0
Definition: pairing/detail/forms/short_weierstrass/jacobian_with_a4_0/types.hpp:58