detail/extension_params/bls12/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_BLS12_FP2_EXTENSION_PARAMS_HPP
27 #define CRYPTO3_ALGEBRA_FIELDS_BLS12_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 
42  namespace detail {
43 
44  template<typename BaseField>
45  struct fp2_extension_params;
46 
47  /************************* BLS12-381 ***********************************/
48 
49  template<>
50  class fp2_extension_params<fields::bls12<381>> : public params<fields::bls12<381>> {
51 
54 
55  public:
57 
60 
61  constexpr static const integral_type modulus = policy_type::modulus;
62 
64  typedef typename non_residue_field_type::value_type non_residue_type;
66  typedef typename underlying_field_type::value_type underlying_type;
67 
68  constexpr static const std::size_t s = 0x03;
69  constexpr static const extended_integral_type t =
70  0x5486F497186BF8E97A4F1D5445E4BD3C5B921CA1CE08D68CDCB3C92693D17A0A14C59FA2DBB94DDEA62926612F1DE023AD0C3390C30B8F6525D0B50E1234092CD7F23DA7CE36E862C586706C42279FAF9DAD63AEC705D564D54000038E31C7_cppui759;
71  constexpr static const extended_integral_type t_minus_1_over_2 =
72  0x2A437A4B8C35FC74BD278EAA22F25E9E2DC90E50E7046B466E59E49349E8BD050A62CFD16DDCA6EF53149330978EF011D68619C86185C7B292E85A87091A04966BF91ED3E71B743162C338362113CFD7CED6B1D76382EAB26AA00001C718E3_cppui758;
73  constexpr static const std::array<integral_type, 2> nqr = {0x01, 0x01};
74  constexpr static const std::array<integral_type, 2> nqr_to_t = {
75  0x6AF0E0437FF400B6831E36D6BD17FFE48395DABC2D3435E77F76E17009241C5EE67992F72EC05F4C81084FBEDE3CC09_cppui379,
76  0x135203E60180A68EE2E9C448D77A2CD91C3DEDD930B1CF60EF396489F61EB45E304466CF3E67FA0AF1EE7B04121BDEA2_cppui381};
77 
78  constexpr static const extended_integral_type group_order =
79  0x1521BD25C61AFE3A5E93C75511792F4F16E48728738235A3372CF249A4F45E82853167E8B6EE5377A98A49984BC77808EB430CE430C2E3D949742D43848D024B35FC8F69F38DBA18B1619C1B1089E7EBE76B58EBB1C1755935500000E38C71C_cppui761;
80 
81  /*constexpr static const std::array<non_residue_type, 2> Frobenius_coeffs_c1 =
82  {non_residue_type(0x01),
83  non_residue_type(0x1A0111EA397FE69A4B1BA7B6434BACD764774B84F38512BF6730D2A0F6B0F6241EABFFFEB153FFFFB9FEFFFFFFFFAAAA_cppui381)};*/
84 
85  constexpr static const std::array<integral_type, 2> Frobenius_coeffs_c1 = {
86  0x01,
87  0x1A0111EA397FE69A4B1BA7B6434BACD764774B84F38512BF6730D2A0F6B0F6241EABFFFEB153FFFFB9FEFFFFFFFFAAAA_cppui381};
88 
89  constexpr static const non_residue_type non_residue = non_residue_type(
90  0x1A0111EA397FE69A4B1BA7B6434BACD764774B84F38512BF6730D2A0F6B0F6241EABFFFEB153FFFFB9FEFFFFFFFFAAAA_cppui381);
91  };
92 
93  /************************* BLS12-377 ***********************************/
94 
95  template<>
96  class fp2_extension_params<fields::bls12<377>> : public params<fields::bls12<377>> {
97 
100 
101  public:
103 
106 
107  constexpr static const integral_type modulus = policy_type::modulus;
108 
110  typedef non_residue_field_type::value_type non_residue_type;
112  typedef underlying_field_type::value_type underlying_type;
113 
114  constexpr static const std::size_t s = 0x2F;
115  constexpr static const extended_integral_type t =
116  0x5A60FA1775FF644AD227766C24C78977170FB495DD27E3EBCE2827BB49AB813A0315F720CC19B8029CE24A0549AD88C155555176E15C063064972B0C7193AD797F7A46BE3813495B44D1E5C37B000E671A4A9E00000021423_cppui707;
117  constexpr static const extended_integral_type t_minus_1_over_2 =
118  0x2D307D0BBAFFB2256913BB361263C4BB8B87DA4AEE93F1F5E71413DDA4D5C09D018AFB90660CDC014E712502A4D6C460AAAAA8BB70AE0318324B958638C9D6BCBFBD235F1C09A4ADA268F2E1BD8007338D254F00000010A11_cppui706;
119  constexpr static const std::array<integral_type, 2> nqr = {0x00, 0x01};
120  constexpr static const std::array<integral_type, 2> nqr_to_t = {
121  0x00,
122  0x1ABEF7237D62007BB9B2EDA5AFCB52F9D179F23DBD49B8D1B24CF7C1BF8066791317689172D0F4CB90CF47182B7D7B2_cppui377};
123 
124  constexpr static const extended_integral_type group_order =
125  0x16983E85DD7FD912B489DD9B0931E25DC5C3ED257749F8FAF38A09EED26AE04E80C57DC833066E00A7389281526B62305555545DB857018C1925CAC31C64EB5E5FDE91AF8E04D256D1347970DEC00399C692A780000008508C00000000000_cppui753;
126 
127  /*constexpr static const std::array<non_residue_type, 2> Frobenius_coeffs_c1 =
128  {non_residue_type(0x01),
129  non_residue_type(0x1AE3A4617C510EAC63B05C06CA1493B1A22D9F300F5138F1EF3622FBA094800170B5D44300000008508C00000000000_cppui377)};*/
130 
131  constexpr static const std::array<integral_type, 2> Frobenius_coeffs_c1 = {
132  0x01,
133  0x1AE3A4617C510EAC63B05C06CA1493B1A22D9F300F5138F1EF3622FBA094800170B5D44300000008508C00000000000_cppui377};
134 
135  constexpr static const non_residue_type non_residue = non_residue_type(
136  0x1AE3A4617C510EAC63B05C06CA1493B1A22D9F300F5138F1EF3622FBA094800170B5D44300000008508BFFFFFFFFFFC_cppui377);
137  };
138 
139  constexpr typename fp2_extension_params<bls12_base_field<381>>::non_residue_type const
141  constexpr typename fp2_extension_params<bls12_base_field<377>>::non_residue_type const
143 
144  constexpr typename std::size_t const fp2_extension_params<bls12_base_field<381>>::s;
145  constexpr typename std::size_t const fp2_extension_params<bls12_base_field<377>>::s;
146 
147  constexpr typename fp2_extension_params<bls12_base_field<381>>::extended_integral_type const
149  constexpr typename fp2_extension_params<bls12_base_field<377>>::extended_integral_type const
151 
152  constexpr typename fp2_extension_params<bls12_base_field<381>>::extended_integral_type const
154  constexpr typename fp2_extension_params<bls12_base_field<377>>::extended_integral_type const
156 
157  constexpr std::array<typename fp2_extension_params<bls12_base_field<381>>::integral_type, 2> const
159  constexpr std::array<typename fp2_extension_params<bls12_base_field<377>>::integral_type, 2> const
161 
162  constexpr std::array<typename fp2_extension_params<bls12_base_field<381>>::integral_type, 2> const
164  constexpr std::array<typename fp2_extension_params<bls12_base_field<377>>::integral_type, 2> const
166 
167  constexpr typename fp2_extension_params<bls12_base_field<381>>::extended_integral_type const
169  constexpr typename fp2_extension_params<bls12_base_field<377>>::extended_integral_type const
171 
172  constexpr std::array<typename fp2_extension_params<bls12_base_field<381>>::integral_type, 2> const
173  fp2_extension_params<bls12_base_field<381>>::Frobenius_coeffs_c1;
174  constexpr std::array<typename fp2_extension_params<bls12_base_field<377>>::integral_type, 2> const
175  fp2_extension_params<bls12_base_field<377>>::Frobenius_coeffs_c1;
176 
177  } // namespace detail
178  } // namespace fields
179  } // namespace algebra
180  } // namespace crypto3
181 } // namespace nil
182 
183 #endif // CRYPTO3_ALGEBRA_FIELDS_BLS12_FP2_EXTENSION_PARAMS_HPP
policy_type::extended_integral_type extended_integral_type
Definition: detail/extension_params/bls12/fp2.hpp:105
non_residue_field_type::value_type non_residue_type
Definition: detail/extension_params/bls12/fp2.hpp:110
base_field_type non_residue_field_type
Definition: detail/extension_params/bls12/fp2.hpp:109
policy_type::integral_type integral_type
Definition: detail/extension_params/bls12/fp2.hpp:104
base_field_type underlying_field_type
Definition: detail/extension_params/bls12/fp2.hpp:111
underlying_field_type::value_type underlying_type
Definition: detail/extension_params/bls12/fp2.hpp:112
policy_type::integral_type integral_type
Definition: detail/extension_params/bls12/fp2.hpp:58
underlying_field_type::value_type underlying_type
Definition: detail/extension_params/bls12/fp2.hpp:66
policy_type::extended_integral_type extended_integral_type
Definition: detail/extension_params/bls12/fp2.hpp:59
base_field_type non_residue_field_type
Definition: detail/extension_params/bls12/fp2.hpp:63
non_residue_field_type::value_type non_residue_type
Definition: detail/extension_params/bls12/fp2.hpp:64
base_field_type underlying_field_type
Definition: detail/extension_params/bls12/fp2.hpp:65
Definition: pair.hpp:31
IETF IPsec groups.
Definition: bls12/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