edwards/183/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_EDWARDS_183_ATE_MILLER_LOOP_HPP
27 #define CRYPTO3_ALGEBRA_PAIRING_EDWARDS_183_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 = 183>
43 
44  template<>
47 
50  using gt_type = typename curve_type::gt_type;
51 
52  public:
53  static typename gt_type::value_type process(const policy_type::ate_g1_precomputed_type &prec_P,
54  const policy_type::ate_g2_precomputed_type &prec_Q) {
55 
56  typename gt_type::value_type f = gt_type::value_type::one();
57 
58  bool found_one = false;
59  std::size_t idx = 0;
60 
61  const typename policy_type::integral_type &loop_count = params_type::ate_loop_count;
62 
63  for (long i = params_type::integral_type_max_bits - 1; i >= 0; --i) {
64  const bool bit = nil::crypto3::multiprecision::bit_test(loop_count, i);
65  if (!found_one) {
66  /* this skips the MSB itself */
67  found_one |= bit;
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::Fq3_conic_coefficients cc = prec_Q[idx++];
75 
76  typename gt_type::value_type g_RR_at_P = typename gt_type::value_type(
77  prec_P.P_XY * cc.c_XY + prec_P.P_XZ * cc.c_XZ, prec_P.P_ZZplusYZ * cc.c_ZZ);
78  f = f.squared() * g_RR_at_P;
79  if (bit) {
80  cc = prec_Q[idx++];
81  typename gt_type::value_type g_RQ_at_P = typename gt_type::value_type(
82  prec_P.P_ZZplusYZ * cc.c_ZZ, prec_P.P_XY * cc.c_XY + prec_P.P_XZ * cc.c_XZ);
83  f = f * g_RQ_at_P;
84  }
85  }
86 
87  return f;
88  }
89  };
90  } // namespace pairing
91  } // namespace algebra
92  } // namespace crypto3
93 } // namespace nil
94 #endif // CRYPTO3_ALGEBRA_PAIRING_EDWARDS_183_ATE_MILLER_LOOP_HPP
Definition: pairing/detail/alt_bn128/params.hpp:38
Definition: pairing/detail/edwards/183/types.hpp:38
static gt_type::value_type process(const policy_type::ate_g1_precomputed_type &prec_P, const policy_type::ate_g2_precomputed_type &prec_Q)
Definition: edwards/183/ate_miller_loop.hpp:53
Definition: edwards/183/ate_miller_loop.hpp:42
Definition: pair.hpp:31
A struct representing a Edwards curve, providing 128 bits of security.
Definition: curves/edwards.hpp:51
policy_type::gt_field_type gt_type
Definition: curves/edwards.hpp:69