algebra/include/nil/crypto3/algebra/pairing/mnt4/298/final_exponentiation.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_FINAL_EXPONENTIATION_HPP
27 #define CRYPTO3_ALGEBRA_PAIRING_MNT4_298_FINAL_EXPONENTIATION_HPP
28 
32 
33 namespace nil {
34  namespace crypto3 {
35  namespace algebra {
36  namespace pairing {
37 
38  template<std::size_t Version = 298>
40 
41  template<>
44 
47 
48  using gt_type = typename curve_type::gt_type;
49 
50  static typename gt_type::value_type
51  final_exponentiation_last_chunk(const typename gt_type::value_type &elt,
52  const typename gt_type::value_type &elt_inv) {
53 
54  const typename gt_type::value_type elt_q = elt.Frobenius_map(1);
55  typename gt_type::value_type w1_part =
56  elt_q.cyclotomic_exp(params_type::final_exponent_last_chunk_w1);
57  typename gt_type::value_type w0_part;
58  if (params_type::final_exponent_last_chunk_is_w0_neg) {
59  w0_part = elt_inv.cyclotomic_exp(params_type::final_exponent_last_chunk_abs_of_w0);
60  } else {
61  w0_part = elt.cyclotomic_exp(params_type::final_exponent_last_chunk_abs_of_w0);
62  }
63  typename gt_type::value_type result = w1_part * w0_part;
64 
65  return result;
66  }
67 
68  static typename gt_type::value_type
69  final_exponentiation_first_chunk(const typename gt_type::value_type &elt,
70  const typename gt_type::value_type &elt_inv) {
71 
72  /* (q^2-1) */
73 
74  /* elt_q2 = elt^(q^2) */
75  const typename gt_type::value_type elt_q2 = elt.Frobenius_map(2);
76  /* elt_q3_over_elt = elt^(q^2-1) */
77  const typename gt_type::value_type elt_q2_over_elt = elt_q2 * elt_inv;
78 
79  return elt_q2_over_elt;
80  }
81 
82  public:
83  static typename gt_type::value_type process(const typename gt_type::value_type &elt) {
84 
85  const typename gt_type::value_type elt_inv = elt.inversed();
86  const typename gt_type::value_type elt_to_first_chunk =
87  final_exponentiation_first_chunk(elt, elt_inv);
88  const typename gt_type::value_type elt_inv_to_first_chunk =
89  final_exponentiation_first_chunk(elt_inv, elt);
90  return final_exponentiation_last_chunk(elt_to_first_chunk, elt_inv_to_first_chunk);
91  }
92  };
93  } // namespace pairing
94  } // namespace algebra
95  } // namespace crypto3
96 } // namespace nil
97 #endif // CRYPTO3_ALGEBRA_PAIRING_MNT4_298_FINAL_EXPONENTIATION_HPP
Definition: pairing/detail/alt_bn128/params.hpp:38
Definition: pairing/detail/forms/short_weierstrass/projective/types.hpp:36
static gt_type::value_type process(const typename gt_type::value_type &elt)
Definition: algebra/include/nil/crypto3/algebra/pairing/mnt4/298/final_exponentiation.hpp:83
Definition: algebra/include/nil/crypto3/algebra/pairing/mnt4/298/final_exponentiation.hpp:39
Definition: pair.hpp:31
A struct representing a mnt4 curve.
Definition: algebra/include/nil/crypto3/algebra/curves/mnt4.hpp:46
policy_type::gt_field_type gt_type
Definition: algebra/include/nil/crypto3/algebra/curves/mnt4.hpp:66