tate_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_TATE_MILLER_LOOP_HPP
27 #define CRYPTO3_ALGEBRA_PAIRING_EDWARDS_183_TATE_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::tate_g1_precomp &prec_P,
54  const policy_type::tate_g2_precomp &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  for (long i = policy_type::scalar_field_bits - 1; i >= 0; --i) {
61  const bool bit =
62  nil::crypto3::multiprecision::bit_test(policy_type::scalar_field_modulus, i);
63  if (!found_one) {
64  /* this skips the MSB itself */
65  found_one |= bit;
66  continue;
67  }
68 
69  /* code below gets executed for all bits (EXCEPT the MSB itself) of
70  policy_type::scalar_field_modulus (skipping leading zeros) in MSB to LSB
71  order */
72  typename policy_type::Fq_conic_coefficients cc = prec_P[idx++];
73  typename gt_type::value_type g_RR_at_Q = typename gt_type::value_type(
74  Fq3(cc.c_XZ, Fq(0l), Fq(0l)) + cc.c_XY * prec_Q.y0, cc.c_ZZ * prec_Q.eta);
75  f = f.squared() * g_RR_at_Q;
76  if (bit) {
77  cc = prec_P[idx++];
78 
79  typename gt_type::value_type g_RP_at_Q = typename gt_type::value_type(
80  Fq3(cc.c_XZ, Fq(0l), Fq(0l)) + cc.c_XY * prec_Q.y0, cc.c_ZZ * prec_Q.eta);
81  f = f * g_RP_at_Q;
82  }
83  }
84 
85  return f;
86  }
87  };
88  } // namespace pairing
89  } // namespace algebra
90  } // namespace crypto3
91 } // namespace nil
92 #endif // CRYPTO3_ALGEBRA_PAIRING_EDWARDS_183_TATE_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::tate_g1_precomp &prec_P, const policy_type::tate_g2_precomp &prec_Q)
Definition: tate_miller_loop.hpp:53
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