algebra/include/nil/crypto3/algebra/pairing/mnt6/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_MNT6_298_FINAL_EXPONENTIATION_HPP
27 #define CRYPTO3_ALGEBRA_PAIRING_MNT6_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 base_field_type = typename curve_type::base_field_type;
49  using gt_type = typename curve_type::gt_type;
50 
51  static typename gt_type::value_type
52  final_exponentiation_last_chunk(const typename gt_type::value_type &elt,
53  const typename gt_type::value_type &elt_inv) {
54 
55  const typename gt_type::value_type elt_q = elt.Frobenius_map(1);
56  typename gt_type::value_type w1_part =
57  elt_q.cyclotomic_exp(params_type::final_exponent_last_chunk_w1);
58  typename gt_type::value_type w0_part;
59  if (params_type::final_exponent_last_chunk_is_w0_neg) {
60  w0_part = elt_inv.cyclotomic_exp(params_type::final_exponent_last_chunk_abs_of_w0);
61  } else {
62  w0_part = elt.cyclotomic_exp(params_type::final_exponent_last_chunk_abs_of_w0);
63  }
64  typename gt_type::value_type result = w1_part * w0_part;
65 
66  return result;
67  }
68 
69  static typename gt_type::value_type
70  final_exponentiation_first_chunk(const typename gt_type::value_type &elt,
71  const typename gt_type::value_type &elt_inv) {
72 
73  /* (q^3-1)*(q+1) */
74 
75  /* elt_q3 = elt^(q^3) */
76  const typename gt_type::value_type elt_q3 = elt.Frobenius_map(3);
77  /* elt_q3_over_elt = elt^(q^3-1) */
78  const typename gt_type::value_type elt_q3_over_elt = elt_q3 * elt_inv;
79  /* alpha = elt^((q^3-1) * q) */
80  const typename gt_type::value_type alpha = elt_q3_over_elt.Frobenius_map(1);
81  /* beta = elt^((q^3-1)*(q+1) */
82  const typename gt_type::value_type beta = alpha * elt_q3_over_elt;
83  return beta;
84  }
85 
86  public:
87  static typename gt_type::value_type process(const typename gt_type::value_type &elt) {
88 
89  const typename gt_type::value_type elt_inv = elt.inversed();
90  const typename gt_type::value_type elt_to_first_chunk =
91  final_exponentiation_first_chunk(elt, elt_inv);
92  const typename gt_type::value_type elt_inv_to_first_chunk =
93  final_exponentiation_first_chunk(elt_inv, elt);
94  return final_exponentiation_last_chunk(elt_to_first_chunk, elt_inv_to_first_chunk);
95  }
96  };
97  } // namespace pairing
98  } // namespace algebra
99  } // namespace crypto3
100 } // namespace nil
101 #endif // CRYPTO3_ALGEBRA_PAIRING_MNT6_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/mnt6/298/final_exponentiation.hpp:87
Definition: algebra/include/nil/crypto3/algebra/pairing/mnt6/298/final_exponentiation.hpp:39
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
IETF IPsec groups.
Definition: mnt6/base_field.hpp:46