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