pair.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_ALGORITHM_HPP
27 #define CRYPTO3_ALGEBRA_PAIRING_ALGORITHM_HPP
28 
30 
31 namespace nil {
32  namespace crypto3 {
33  namespace algebra {
34 
35  // template<typename PairingCurveType>
36  // typename PairingCurveType::pairing::affine_ate_g1_precomp
37  // affine_ate_precompute_g1(const typename PairingCurveType::pairing::g1_type::value_type &P) {
38 
39  // return PairingCurveType::pairing::affine_ate_precompute_g1(P);
40  // }
41 
42  // template<typename PairingCurveType>
43  // typename PairingCurveType::pairing::affine_ate_g2_precomp
44  // affine_ate_precompute_g2(const typename PairingCurveType::pairing::g2_type::value_type &P) {
45 
46  // return PairingCurveType::pairing::affine_ate_precompute_g2(P);
47  // }
48 
49  // template<typename PairingCurveType>
50  // typename PairingCurveType::pairing::gt_type::value_type
51  // affine_ate_miller_loop(const typename PairingCurveType::pairing::affine_ate_g1_precomp &prec_P,
52  // const typename PairingCurveType::pairing::affine_ate_g2_precomp &prec_Q) {
53 
54  // return PairingCurveType::pairing::affine_ate_miller_loop(prec_P, prec_Q);
55  // }
56 
57  template<typename PairingCurveType, typename PairingPolicy = pairing::pairing_policy<PairingCurveType>>
58  typename PairingPolicy::g1_precomputed_type
59  precompute_g1(const typename PairingCurveType::template g1_type<>::value_type &P) {
60 
61  return PairingPolicy::precompute_g1::process(P);
62  }
63 
64  template<typename PairingCurveType, typename PairingPolicy = pairing::pairing_policy<PairingCurveType>>
65  typename PairingPolicy::g2_precomputed_type
66  precompute_g2(const typename PairingCurveType::template g2_type<>::value_type &P) {
67 
68  return PairingPolicy::precompute_g2::process(P);
69  }
70 
71  template<typename PairingCurveType, typename PairingPolicy = pairing::pairing_policy<PairingCurveType>>
72  typename PairingCurveType::gt_type::value_type
73  pair(const typename PairingCurveType::template g1_type<>::value_type &v1,
74  const typename PairingCurveType::template g2_type<>::value_type &v2) {
75 
76  typename PairingPolicy::g1_precomputed_type prec_P = PairingPolicy::precompute_g1::process(v1);
77  typename PairingPolicy::g2_precomputed_type prec_Q = PairingPolicy::precompute_g2::process(v2);
78 
79  return PairingPolicy::miller_loop::process(prec_P, prec_Q);
80  }
81 
82  template<typename PairingCurveType, typename PairingPolicy = pairing::pairing_policy<PairingCurveType>>
83  typename PairingCurveType::gt_type::value_type
84  pair_reduced(const typename PairingCurveType::template g1_type<>::value_type &v1,
85  const typename PairingCurveType::template g2_type<>::value_type &v2) {
86 
87  typename PairingPolicy::g1_precomputed_type prec_P = PairingPolicy::precompute_g1::process(v1);
88  typename PairingPolicy::g2_precomputed_type prec_Q = PairingPolicy::precompute_g2::process(v2);
89 
90  typename PairingCurveType::gt_type::value_type f = PairingPolicy::miller_loop::process(prec_P, prec_Q);
91  return PairingPolicy::final_exponentiation::process(f);
92  }
93 
94  template<typename PairingCurveType, typename PairingPolicy = pairing::pairing_policy<PairingCurveType>>
95  typename PairingCurveType::gt_type::value_type
96  double_miller_loop(const typename PairingPolicy::g1_precomputed_type &prec_P1,
97  const typename PairingPolicy::g2_precomputed_type &prec_Q1,
98  const typename PairingPolicy::g1_precomputed_type &prec_P2,
99  const typename PairingPolicy::g2_precomputed_type &prec_Q2) {
100 
101  return PairingPolicy::double_miller_loop::process(prec_P1, prec_Q1, prec_P2, prec_Q2);
102  }
103 
104  template<typename PairingCurveType, typename PairingPolicy = pairing::pairing_policy<PairingCurveType>>
105  typename PairingCurveType::gt_type::value_type
106  final_exponentiation(const typename PairingCurveType::gt_type::value_type &elt) {
107 
108  return PairingPolicy::final_exponentiation::process(elt);
109  }
110 
111  template<typename PairingCurveType, typename PairingPolicy = pairing::pairing_policy<PairingCurveType>>
112  typename PairingCurveType::gt_type::value_type
113  miller_loop(const typename PairingPolicy::g1_precomputed_type &prec_P,
114  const typename PairingPolicy::g2_precomputed_type &prec_Q) {
115 
116  return PairingPolicy::miller_loop::process(prec_P, prec_Q);
117  }
118  } // namespace algebra
119  } // namespace crypto3
120 } // namespace nil
121 
122 #endif // CRYPTO3_ALGEBRA_PAIRING_ALGORITHM_HPP
PairingCurveType::gt_type::value_type double_miller_loop(const typename PairingPolicy::g1_precomputed_type &prec_P1, const typename PairingPolicy::g2_precomputed_type &prec_Q1, const typename PairingPolicy::g1_precomputed_type &prec_P2, const typename PairingPolicy::g2_precomputed_type &prec_Q2)
Definition: pair.hpp:96
PairingCurveType::gt_type::value_type pair_reduced(const typename PairingCurveType::template g1_type<>::value_type &v1, const typename PairingCurveType::template g2_type<>::value_type &v2)
Definition: pair.hpp:84
PairingCurveType::gt_type::value_type miller_loop(const typename PairingPolicy::g1_precomputed_type &prec_P, const typename PairingPolicy::g2_precomputed_type &prec_Q)
Definition: pair.hpp:113
PairingPolicy::g2_precomputed_type precompute_g2(const typename PairingCurveType::template g2_type<>::value_type &P)
Definition: pair.hpp:66
PairingCurveType::gt_type::value_type final_exponentiation(const typename PairingCurveType::gt_type::value_type &elt)
Definition: pair.hpp:106
PairingCurveType::gt_type::value_type pair(const typename PairingCurveType::template g1_type<>::value_type &v1, const typename PairingCurveType::template g2_type<>::value_type &v2)
Definition: pair.hpp:73
PairingPolicy::g1_precomputed_type precompute_g1(const typename PairingCurveType::template g1_type<>::value_type &P)
Definition: pair.hpp:59
Definition: pair.hpp:31