detail/extension_params/bn128/fp2.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_FIELDS_BN128_FP2_EXTENSION_PARAMS_HPP
27 #define CRYPTO3_ALGEBRA_FIELDS_BN128_FP2_EXTENSION_PARAMS_HPP
28 
31 
33 
34 namespace nil {
35  namespace crypto3 {
36  namespace algebra {
37  namespace fields {
38 
39  template<typename BaseField>
40  struct fp2;
41  namespace detail {
42 
43  template<typename BaseField>
44  struct fp2_extension_params;
45 
46  /************************* BN128 ***********************************/
47 
48  template<std::size_t Version>
49  class fp2_extension_params<fields::bn128<Version>> : public params<fields::bn128<Version>> {
50 
53 
54  public:
56 
59 
60  constexpr static const integral_type modulus = policy_type::modulus;
61 
63  typedef typename non_residue_field_type::value_type non_residue_type;
65  typedef typename underlying_field_type::value_type underlying_type;
66 
67  constexpr static const std::size_t s = 0x04;
68  constexpr static const extended_integral_type t =
69  0x925C4B8763CBF9C599A6F7C0348D21CB00B85511637560626EDFA5C34C6B38D04689E957A1242C84A50189C6D96CADCA602072D09EAC1013B5458A2275D69B_cppui504;
70  constexpr static const extended_integral_type t_minus_1_over_2 =
71  0x492E25C3B1E5FCE2CCD37BE01A4690E5805C2A88B1BAB031376FD2E1A6359C682344F4ABD09216425280C4E36CB656E5301039684F560809DAA2C5113AEB4D_cppui503;
72  constexpr static const std::array<integral_type, 2> nqr = {0x02, 0x01};
73  constexpr static const std::array<integral_type, 2> nqr_to_t = {
74  0xB20DCB5704E326A0DD3ECD4F30515275398A41A4E1DC5D347CFBBEDDA71CF82_cppui252,
75  0xB1FFEFD8885BF22252522C29527D19F05CFC50E9715370AB0F3A6CA462390C_cppui248};
76 
77  constexpr static const extended_integral_type group_order =
78  0x492E25C3B1E5FCE2CCD37BE01A4690E5805C2A88B1BAB031376FD2E1A6359C682344F4ABD09216425280C4E36CB656E5301039684F560809DAA2C5113AEB4D8_cppui507;
79 
80  /*constexpr static const std::array<non_residue_type, 2> Frobenius_coeffs_c1 =
81  {non_residue_type(0x00), non_residue_type(0x00)};*/
82 
83  constexpr static const std::array<integral_type, 2> Frobenius_coeffs_c1 = {0x00, 0x00};
84 
85  constexpr static const non_residue_type non_residue = non_residue_type(
86  0x30644E72E131A029B85045B68181585D97816A916871CA8D3C208C16D87CFD46_cppui254);
87  };
88 
89  template<std::size_t Version>
90  constexpr typename fp2_extension_params<bn128_base_field<Version>>::non_residue_type const
92 
93  template<std::size_t Version>
94  constexpr typename std::size_t const fp2_extension_params<bn128_base_field<Version>>::s;
95 
96  template<std::size_t Version>
97  constexpr typename fp2_extension_params<bn128_base_field<Version>>::extended_integral_type const
99 
100  template<std::size_t Version>
101  constexpr typename fp2_extension_params<bn128_base_field<Version>>::extended_integral_type const
103 
104  template<std::size_t Version>
105  constexpr std::array<typename fp2_extension_params<bn128_base_field<Version>>::integral_type,
107 
108  template<std::size_t Version>
109  constexpr std::array<typename fp2_extension_params<bn128_base_field<Version>>::integral_type,
111 
112  template<std::size_t Version>
113  constexpr typename fp2_extension_params<bn128_base_field<Version>>::extended_integral_type const
115 
116  template<std::size_t Version>
117  constexpr std::array<typename fp2_extension_params<bn128_base_field<Version>>::integral_type,
118  2> const fp2_extension_params<bn128_base_field<Version>>::Frobenius_coeffs_c1;
119 
120  } // namespace detail
121  } // namespace fields
122  } // namespace algebra
123  } // namespace crypto3
124 } // namespace nil
125 
126 #endif // CRYPTO3_ALGEBRA_FIELDS_BN128_FP2_EXTENSION_PARAMS_HPP
non_residue_field_type::value_type non_residue_type
Definition: detail/extension_params/bn128/fp2.hpp:63
underlying_field_type::value_type underlying_type
Definition: detail/extension_params/bn128/fp2.hpp:65
base_field_type non_residue_field_type
Definition: detail/extension_params/bn128/fp2.hpp:62
policy_type::integral_type integral_type
Definition: detail/extension_params/bn128/fp2.hpp:57
policy_type::extended_integral_type extended_integral_type
Definition: detail/extension_params/bn128/fp2.hpp:58
base_field_type underlying_field_type
Definition: detail/extension_params/bn128/fp2.hpp:64
Definition: pair.hpp:31
IETF IPsec groups.
Definition: bn128/base_field.hpp:46
Definition: detail/extension_params/alt_bn128/fp2.hpp:44
Definition: fields/params.hpp:35
field_type::integral_type integral_type
Definition: fields/params.hpp:42
field_type::extended_integral_type extended_integral_type
Definition: fields/params.hpp:44