mnt6/298/affine_ate_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_MNT4_298_AFFINE_ATE_MILLER_LOOP_HPP
27 #define CRYPTO3_ALGEBRA_PAIRING_MNT4_298_AFFINE_ATE_MILLER_LOOP_HPP
28 
29 #include <nil/crypto3/multiprecision/number.hpp>
30 #include <nil/crypto3/multiprecision/cpp_int.hpp>
31 
35 
36 namespace nil {
37  namespace crypto3 {
38  namespace algebra {
39  namespace pairing {
40 
41  template<std::size_t Version = 298>
43 
44  // The only difference between this and mnt4<298> is that they use mul_by_2345 and mul_by_023
45  template<>
48 
50  using gt_type = typename curve_type::gt_type;
51 
52  public:
53  static typename gt_type::value_type
55  const typename policy_type::affine_ate_g2_precomputation &prec_Q) {
56 
57  typename gt_type::value_type f = gt_type::value_type::one();
58 
59  bool found_nonzero = false;
60  std::size_t idx = 0;
61 
62  std::vector<long> NAF = multiprecision::find_wnaf(1, policy_type::ate_loop_count);
63 
64  for (long i = NAF.size() - 1; i >= 0; --i) {
65  if (!found_nonzero) {
66  /* this skips the MSB itself */
67  found_nonzero |= (NAF[i] != 0);
68  continue;
69  }
70 
71  /* code below gets executed for all bits (EXCEPT the MSB itself) of
72  param_p (skipping leading zeros) in MSB to LSB
73  order */
74  typename policy_type::affine_ate_coeffs c = prec_Q.coeffs[idx++];
75 
76  typename gt_type::value_type g_RR_at_P = typename gt_type::value_type(
77  prec_P.PY_twist_squared, -prec_P.PX * c.gamma_twist + c.gamma_X - c.old_RY);
78  f = f.squared().mul_by_2345(g_RR_at_P);
79 
80  if (NAF[i] != 0) {
81  typename policy_type::affine_ate_coeffs c = prec_Q.coeffs[idx++];
82  typename gt_type::value_type g_RQ_at_P;
83  if (NAF[i] > 0) {
84  g_RQ_at_P = typename gt_type::value_type(
85  prec_P.PY_twist_squared, -prec_P.PX * c.gamma_twist + c.gamma_X - prec_Q.QY);
86  } else {
87  g_RQ_at_P = typename gt_type::value_type(
88  prec_P.PY_twist_squared, -prec_P.PX * c.gamma_twist + c.gamma_X + prec_Q.QY);
89  }
90  f = f.mul_by_2345(g_RQ_at_P);
91  }
92  }
93 
94  return f;
95  }
96  };
97  } // namespace pairing
98  } // namespace algebra
99  } // namespace crypto3
100 } // namespace nil
101 #endif // CRYPTO3_ALGEBRA_PAIRING_MNT6_298_AFFINE_ATE_MILLER_LOOP_HPP
Definition: pairing/detail/forms/short_weierstrass/projective/types.hpp:36
static gt_type::value_type process(const typename policy_type::affine_ate_g1_precomputation &prec_P, const typename policy_type::affine_ate_g2_precomputation &prec_Q)
Definition: mnt6/298/affine_ate_miller_loop.hpp:54
Definition: mnt6/298/affine_ate_miller_loop.hpp:42
Definition: pair.hpp:31
A struct representing a mnt6 curve.
Definition: algebra/include/nil/crypto3/algebra/curves/mnt6.hpp:46
policy_type::gt_field_type gt_type
Definition: algebra/include/nil/crypto3/algebra/curves/mnt6.hpp:66
Definition: pairing/detail/forms/short_weierstrass/projective/types.hpp:46
g1_field_value_type PX
Definition: pairing/detail/forms/short_weierstrass/projective/types.hpp:47
g2_field_value_type PY_twist_squared
Definition: pairing/detail/forms/short_weierstrass/projective/types.hpp:49
Definition: pairing/detail/forms/short_weierstrass/projective/types.hpp:61
g2_field_value_type QY
Definition: pairing/detail/forms/short_weierstrass/projective/types.hpp:63
std::vector< affine_ate_coeffs > coeffs
Definition: pairing/detail/forms/short_weierstrass/projective/types.hpp:64
Definition: pairing/detail/forms/short_weierstrass/projective/types.hpp:52
g2_field_value_type gamma_X
Definition: pairing/detail/forms/short_weierstrass/projective/types.hpp:58
g2_field_value_type old_RY
Definition: pairing/detail/forms/short_weierstrass/projective/types.hpp:55
g2_field_value_type gamma_twist
Definition: pairing/detail/forms/short_weierstrass/projective/types.hpp:57