algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2020-2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020-2021 Ilias Khairullin <ilias@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_CURVES_HASH_TO_CURVE_SUITES_HPP
27 #define CRYPTO3_ALGEBRA_CURVES_HASH_TO_CURVE_SUITES_HPP
28 
30 
33 
34 //#include <nil/crypto3/algebra/curves/detail/h2c/h2c_utils.hpp>
35 //#include <nil/crypto3/algebra/curves/detail/h2c/h2c_iso_map.hpp>
36 
37 #include <cstdint>
38 #include <vector>
39 
40 #include <boost/predef.h>
41 
42 namespace nil {
43  namespace crypto3 {
44  namespace algebra {
45  namespace curves {
46  namespace detail {
47  template<typename GroupType>
48  struct h2c_suite;
49 
50  template<>
51  struct h2c_suite<typename bls12_381::g1_type<>> {
53  typedef typename bls12_381::g1_type<> group_type;
55 
56  typedef typename group_type::value_type group_value_type;
57  typedef typename group_type::field_type::integral_type integral_type;
58  typedef typename group_type::field_type::modular_type modular_type;
59  typedef typename group_type::field_type::modular_backend modular_backend;
60  typedef typename group_type::field_type::value_type field_value_type;
61 
62  // BLS12381G1_XMD:SHA-256_SSWU_RO_
63  constexpr static std::array<std::uint8_t, 31> suite_id = {
64  66, 76, 83, 49, 50, 51, 56, 49, 71, 49, 95, 88, 77, 68, 58, 83,
65  72, 65, 45, 50, 53, 54, 95, 83, 83, 87, 85, 95, 82, 79, 95};
66  constexpr static integral_type p = curve_type::base_field_type::modulus;
67  constexpr static std::size_t m = 1;
68  constexpr static std::size_t k = 128;
69  constexpr static std::size_t L = 64;
70 
71  constexpr static inline const field_value_type Ai = field_value_type(
72  0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d_cppui381);
73  constexpr static inline const field_value_type Bi = field_value_type(
74  0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0_cppui381);
75  constexpr static inline const field_value_type Z = field_value_type(11);
76  constexpr static integral_type h_eff = 0xd201000000010001_cppui381;
77  };
78 
79  template<>
80  struct h2c_suite<typename bls12_381::g2_type<>> {
82  typedef typename bls12_381::g2_type<> group_type;
84 
85  typedef typename group_type::value_type group_value_type;
86  typedef typename group_type::field_type::integral_type integral_type;
87  typedef typename group_type::field_type::modular_type modular_type;
88  typedef typename group_type::field_type::modular_backend modular_backend;
89  typedef typename group_type::field_type::value_type field_value_type;
90 
91  // BLS12381G2_XMD:SHA-256_SSWU_RO_
92  constexpr static std::array<std::uint8_t, 31> suite_id = {
93  0x42, 0x4c, 0x53, 0x31, 0x32, 0x33, 0x38, 0x31, 0x47, 0x32, 0x5f,
94  0x58, 0x4d, 0x44, 0x3a, 0x53, 0x48, 0x41, 0x2d, 0x32, 0x35, 0x36,
95  0x5f, 0x53, 0x53, 0x57, 0x55, 0x5f, 0x52, 0x4f, 0x5f};
96  constexpr static integral_type p = curve_type::base_field_type::modulus;
97  constexpr static std::size_t m = 2;
98  constexpr static std::size_t k = 128;
99  constexpr static std::size_t L = 64;
100 
101  constexpr static inline field_value_type Ai = field_value_type(0, 240);
102  constexpr static inline field_value_type Bi = field_value_type(1012, 1012);
103 #if BOOST_COMP_GNUC
104  constexpr static inline field_value_type Z = []() { return -field_value_type(2, 1); }();
105 #else
106  constexpr static inline field_value_type Z = -field_value_type(2, 1);
107 #endif
108  constexpr static inline auto h_eff =
109  0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551_cppui636;
110  };
111  } // namespace detail
112  } // namespace curves
113  } // namespace algebra
114  } // namespace crypto3
115 } // namespace nil
116 
117 #endif // CRYPTO3_ALGEBRA_CURVES_HASH_TO_CURVE_SUITES_HPP
A struct representing a BLS12-381 and BLS12-377 curve.
Definition: curves/bls12.hpp:49
typename detail::bls12_g2< Version, Form, Coordinates > g2_type
Definition: curves/bls12.hpp:63
typename detail::bls12_g1< Version, Form, Coordinates > g1_type
Definition: curves/bls12.hpp:59
SHA2.
Definition: sha2.hpp:46
Definition: pair.hpp:31
bls12_381::g1_type group_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:53
hashes::sha2< 256 > hash_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:54
group_type::field_type::value_type field_value_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:60
group_type::field_type::modular_backend modular_backend
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:59
bls12_381 curve_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:52
group_type::value_type group_value_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:56
group_type::field_type::modular_type modular_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:58
group_type::field_type::integral_type integral_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:57
group_type::field_type::integral_type integral_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:86
bls12_381::g2_type group_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:82
hashes::sha2< 256 > hash_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:83
group_type::value_type group_value_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:85
group_type::field_type::value_type field_value_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:89
group_type::field_type::modular_type modular_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:87
group_type::field_type::modular_backend modular_backend
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:88
bls12_381 curve_type
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:81
Definition: algebra/include/nil/crypto3/algebra/curves/detail/h2c/h2c_suites.hpp:48