algebra/include/nil/crypto3/algebra/pairing/edwards/183/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_EDWARDS_183_FINAL_EXPONENTIATION_HPP
27 #define CRYPTO3_ALGEBRA_PAIRING_EDWARDS_183_FINAL_EXPONENTIATION_HPP
28 
32 
33 namespace nil {
34  namespace crypto3 {
35  namespace algebra {
36  namespace pairing {
37 
38  template<std::size_t Version = 183>
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 
57  typename gt_type::value_type w1_part =
58  elt_q.cyclotomic_exp(params_type::final_exponent_last_chunk_w1);
59  typename gt_type::value_type w0_part = gt_type::value_type::zero();
60 
61  if (params_type::final_exponent_last_chunk_is_w0_neg) {
62  w0_part = elt_inv.cyclotomic_exp(params_type::final_exponent_last_chunk_abs_of_w0);
63  } else {
64  w0_part = elt.cyclotomic_exp(params_type::final_exponent_last_chunk_abs_of_w0);
65  }
66 
67  return w1_part * w0_part;
68  }
69 
70  static typename gt_type::value_type
71  final_exponentiation_first_chunk(const typename gt_type::value_type &elt,
72  const typename gt_type::value_type &elt_inv) {
73 
74  /* (q^3-1)*(q+1) */
75 
76  /* elt_q3 = elt^(q^3) */
77  const typename gt_type::value_type elt_q3 = elt.Frobenius_map(3);
78  /* elt_q3_over_elt = elt^(q^3-1) */
79  const typename gt_type::value_type elt_q3_over_elt = elt_q3 * elt_inv;
80  /* alpha = elt^((q^3-1) * q) */
81  const typename gt_type::value_type alpha = elt_q3_over_elt.Frobenius_map(1);
82  /* beta = elt^((q^3-1)*(q+1) */
83  const typename gt_type::value_type beta = alpha * elt_q3_over_elt;
84 
85  return beta;
86  }
87 
88  public:
89  static typename gt_type::value_type process(const typename gt_type::value_type &elt) {
90 
91  const typename gt_type::value_type elt_inv = elt.inversed();
92  const typename gt_type::value_type elt_to_first_chunk =
93  final_exponentiation_first_chunk(elt, elt_inv);
94  const typename gt_type::value_type elt_inv_to_first_chunk =
95  final_exponentiation_first_chunk(elt_inv, elt);
96  return final_exponentiation_last_chunk(elt_to_first_chunk, elt_inv_to_first_chunk);
97  }
98  };
99  } // namespace pairing
100  } // namespace algebra
101  } // namespace crypto3
102 } // namespace nil
103 #endif // CRYPTO3_ALGEBRA_PAIRING_EDWARDS_183_FINAL_EXPONENTIATION_HPP
Definition: pairing/detail/alt_bn128/params.hpp:38
Definition: pairing/detail/edwards/183/types.hpp:38
static gt_type::value_type process(const typename gt_type::value_type &elt)
Definition: algebra/include/nil/crypto3/algebra/pairing/edwards/183/final_exponentiation.hpp:89
Definition: algebra/include/nil/crypto3/algebra/pairing/edwards/183/final_exponentiation.hpp:39
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
IETF IPsec groups.
Definition: edwards/base_field.hpp:46