modp_ietf.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_MODP_IETF_HPP
27 #define CRYPTO3_ALGEBRA_FIELDS_MODP_IETF_HPP
28 
30 
33 
35 
36 namespace nil {
37  namespace crypto3 {
38  namespace algebra {
39  namespace fields {
40 
45  template<std::size_t Version>
46  struct modp_ietf : public field<Version> { };
47 
48  template<>
49  struct modp_ietf<1024> : public field<1024> {
51 
52  constexpr static const std::size_t modulus_bits = policy_type::modulus_bits;
54 
56 
57  constexpr static const std::size_t number_bits = policy_type::number_bits;
58  constexpr static const integral_type modulus =
59  0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF_cppui1024;
60 
62  constexpr static const modular_params_type modulus_params = modulus;
63  typedef nil::crypto3::multiprecision::number<
64  nil::crypto3::multiprecision::backends::modular_adaptor<modular_backend, nil::crypto3::multiprecision::backends::modular_params_ct<modular_backend, modulus_params>>>
66 
67  constexpr static const integral_type mul_generator = 0x02;
68 
70 
71  constexpr static const std::size_t value_bits = modulus_bits;
72  constexpr static const std::size_t arity = 1;
73  };
74 
75  template<>
76  struct modp_ietf<1536> : public field<1536> {
78 
79  constexpr static const std::size_t modulus_bits = policy_type::modulus_bits;
81 
82  constexpr static const integral_type modulus =
83  0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF_cppui1536;
84 
85  constexpr static const integral_type mul_generator = 0x02;
86 
88 
89  constexpr static const std::size_t value_bits = modulus_bits;
90  constexpr static const std::size_t arity = 1;
91  };
92 
93  template<>
94  struct modp_ietf<2048> : public field<2048> {
96 
97  constexpr static const std::size_t modulus_bits = policy_type::modulus_bits;
99 
100  constexpr static const integral_type modulus =
101  0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF_cppui2048;
102 
103  constexpr static const integral_type mul_generator = 0x02;
104 
106 
107  constexpr static const std::size_t value_bits = modulus_bits;
108  constexpr static const std::size_t arity = 1;
109  };
110 
111  template<>
112  struct modp_ietf<3072> : public field<3072> {
114 
115  constexpr static const std::size_t modulus_bits = policy_type::modulus_bits;
117 
118  constexpr static const integral_type modulus =
119  0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF_cppui3072;
120 
121  constexpr static const integral_type mul_generator = 0x02;
122 
124 
125  constexpr static const std::size_t value_bits = modulus_bits;
126  constexpr static const std::size_t arity = 1;
127  };
128 
129  template<>
130  struct modp_ietf<4096> : public field<4096> {
132 
133  constexpr static const std::size_t modulus_bits = policy_type::modulus_bits;
135 
136  constexpr static const integral_type modulus =
137  0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199FFFFFFFFFFFFFFFF_cppui4096;
138 
139  constexpr static const integral_type mul_generator = 0x02;
140 
142 
143  constexpr static const std::size_t value_bits = modulus_bits;
144  constexpr static const std::size_t arity = 1;
145  };
146 
147  template<>
148  struct modp_ietf<6144> : public field<6144> {
150 
151  constexpr static const std::size_t modulus_bits = policy_type::modulus_bits;
153 
154  constexpr static const integral_type modulus =
155  0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C93402849236C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BDF8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1BDB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AACC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE12BF2D5B0B7474D6E694F91E6DCC4024FFFFFFFFFFFFFFFF_cppui6144;
156 
157  constexpr static const integral_type mul_generator = 0x02;
158 
160 
161  constexpr static const std::size_t value_bits = modulus_bits;
162  constexpr static const std::size_t arity = 1;
163  };
164 
165  template<>
166  struct modp_ietf<8192> : public field<8192> {
168 
169  constexpr static const std::size_t modulus_bits = policy_type::modulus_bits;
171 
172  constexpr static const integral_type modulus =
173  0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C93402849236C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BDF8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1BDB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AACC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE12BF2D5B0B7474D6E694F91E6DBE115974A3926F12FEE5E438777CB6A932DF8CD8BEC4D073B931BA3BC832B68D9DD300741FA7BF8AFC47ED2576F6936BA424663AAB639C5AE4F5683423B4742BF1C978238F16CBE39D652DE3FDB8BEFC848AD922222E04A4037C0713EB57A81A23F0C73473FC646CEA306B4BCBC8862F8385DDFA9D4B7FA2C087E879683303ED5BDD3A062B3CF5B3A278A66D2A13F83F44F82DDF310EE074AB6A364597E899A0255DC164F31CC50846851DF9AB48195DED7EA1B1D510BD7EE74D73FAF36BC31ECFA268359046F4EB879F924009438B481C6CD7889A002ED5EE382BC9190DA6FC026E479558E4475677E9AA9E3050E2765694DFC81F56E880B96E7160C980DD98EDD3DFFFFFFFFFFFFFFFFF_cppui8192;
174 
175  constexpr static const integral_type mul_generator = 0x02;
176 
178 
179  constexpr static const std::size_t value_bits = modulus_bits;
180  constexpr static const std::size_t arity = 1;
181  };
182 
183  template<std::size_t Version>
185 
186  template<std::size_t Version>
188 
196 
204  } // namespace fields
205  } // namespace algebra
206  } // namespace crypto3
207 } // namespace nil
208 
209 #endif // CRYPTO3_ALGEBRA_FIELDS_MODP_IETF_HPP
Definition: pair.hpp:31
Definition: field.hpp:47
nil::crypto3::multiprecision::number< nil::crypto3::multiprecision::backends::cpp_int_backend< modulus_bits, modulus_bits, nil::crypto3::multiprecision::unsigned_magnitude, nil::crypto3::multiprecision::unchecked, void > > integral_type
Definition: field.hpp:54
nil::crypto3::multiprecision::modular_params< modular_backend > modular_params_type
Definition: field.hpp:72
constexpr static const std::size_t modulus_bits
Definition: field.hpp:49
nil::crypto3::multiprecision::backends::cpp_int_backend< modulus_bits, modulus_bits, nil::crypto3::multiprecision::signed_magnitude, nil::crypto3::multiprecision::unchecked, void > modular_backend
Definition: field.hpp:66
nil::crypto3::multiprecision::number< nil::crypto3::multiprecision::backends::cpp_int_backend< 16 *modulus_bits, 16 *modulus_bits, nil::crypto3::multiprecision::unsigned_magnitude, nil::crypto3::multiprecision::unchecked, void > > extended_integral_type
Definition: field.hpp:60
constexpr static const std::size_t number_bits
Definition: field.hpp:62
detail::element_fp< params< modp_ietf< modulus_bits > > > value_type
Definition: modp_ietf.hpp:69
policy_type::modular_backend modular_backend
Definition: modp_ietf.hpp:61
policy_type::extended_integral_type extended_integral_type
Definition: modp_ietf.hpp:55
field< 1024 > policy_type
Definition: modp_ietf.hpp:50
nil::crypto3::multiprecision::number< nil::crypto3::multiprecision::backends::modular_adaptor< modular_backend, nil::crypto3::multiprecision::backends::modular_params_ct< modular_backend, modulus_params > > > modular_type
Definition: modp_ietf.hpp:65
policy_type::integral_type integral_type
Definition: modp_ietf.hpp:53
detail::element_fp< params< modp_ietf< modulus_bits > > > value_type
Definition: modp_ietf.hpp:87
policy_type::integral_type integral_type
Definition: modp_ietf.hpp:80
field< 1536 > policy_type
Definition: modp_ietf.hpp:77
detail::element_fp< params< modp_ietf< modulus_bits > > > value_type
Definition: modp_ietf.hpp:105
field< 2048 > policy_type
Definition: modp_ietf.hpp:95
policy_type::integral_type integral_type
Definition: modp_ietf.hpp:98
policy_type::integral_type integral_type
Definition: modp_ietf.hpp:116
field< 3072 > policy_type
Definition: modp_ietf.hpp:113
detail::element_fp< params< modp_ietf< modulus_bits > > > value_type
Definition: modp_ietf.hpp:123
field< 4096 > policy_type
Definition: modp_ietf.hpp:131
policy_type::integral_type integral_type
Definition: modp_ietf.hpp:134
detail::element_fp< params< modp_ietf< modulus_bits > > > value_type
Definition: modp_ietf.hpp:141
field< 6144 > policy_type
Definition: modp_ietf.hpp:149
policy_type::integral_type integral_type
Definition: modp_ietf.hpp:152
detail::element_fp< params< modp_ietf< modulus_bits > > > value_type
Definition: modp_ietf.hpp:159
field< 8192 > policy_type
Definition: modp_ietf.hpp:167
policy_type::integral_type integral_type
Definition: modp_ietf.hpp:170
detail::element_fp< params< modp_ietf< modulus_bits > > > value_type
Definition: modp_ietf.hpp:177
IETF IPsec groups.
Definition: modp_ietf.hpp:46