h2c.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_HPP
27 #define CRYPTO3_HASH_H2C_HPP
28 
29 #include <string>
30 #include <vector>
31 
34 
35 namespace nil {
36  namespace crypto3 {
37  namespace hashes {
38  template<typename Group, UniformityCount _uniformity_count = UniformityCount::uniform_count,
39  ExpandMsgVariant _expand_msg_variant = ExpandMsgVariant::rfc_xmd>
41  constexpr static UniformityCount uniformity_count = _uniformity_count;
42  constexpr static ExpandMsgVariant expand_msg_variant = _expand_msg_variant;
43 
45  typedef std::vector<std::uint8_t> dst_type;
46  static inline dst_type dst = []() {
47  std::string default_tag_str = "QUUX-V01-CS02-with-";
48  dst_type dst(default_tag_str.begin(), default_tag_str.end());
49  dst.insert(dst.end(), suite_type::suite_id.begin(), suite_type::suite_id.end());
50  return dst;
51  }();
52  };
53 
61  template<typename Group, typename Params = h2c_default_params<Group>>
62  struct h2c {
63  typedef Group group_type;
64  typedef Params params_type;
65 
66  protected:
67  typedef detail::ep_map<Group, params_type, params_type::uniformity_count,
68  params_type::expand_msg_variant>
70 
71  public:
73  typedef typename group_type::value_type group_value_type;
74  typedef typename policy_type::internal_accumulator_type internal_accumulator_type;
76 
77  static inline void init_accumulator(internal_accumulator_type &acc) {
78  policy_type::init_accumulator(acc);
79  }
80 
81  template<typename InputRange>
82  static inline void update(internal_accumulator_type &acc, const InputRange &range) {
83  policy_type::update(acc, range);
84  }
85 
86  template<typename InputIterator>
87  static inline void update(internal_accumulator_type &acc, InputIterator first, InputIterator last) {
88  policy_type::update(acc, first, last);
89  }
90 
92  return policy_type::process(acc);
93  }
94  };
95  } // namespace hashes
96  } // namespace crypto3
97 } // namespace nil
98 
99 #endif // CRYPTO3_HASH_H2C_HPP
UniformityCount
Definition: h2c_policy.hpp:32
ExpandMsgVariant
Definition: h2c_policy.hpp:34
Definition: pair.hpp:31
Definition: h2c_functions.hpp:439
h2c_suite< Group > suite_type
Definition: h2c.hpp:44
constexpr static ExpandMsgVariant expand_msg_variant
Definition: h2c.hpp:42
std::vector< std::uint8_t > dst_type
Definition: h2c.hpp:45
constexpr static UniformityCount uniformity_count
Definition: h2c.hpp:41
static dst_type dst
Definition: h2c.hpp:46
Definition: hash/include/nil/crypto3/hash/h2c_suites.hpp:44
Hashing to Elliptic Curves https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-11.
Definition: h2c.hpp:62
Group group_type
Definition: h2c.hpp:63
static void update(internal_accumulator_type &acc, InputIterator first, InputIterator last)
Definition: h2c.hpp:87
h2c_suite< Group >::hash_type hash_type
Definition: h2c.hpp:72
policy_type::internal_accumulator_type internal_accumulator_type
Definition: h2c.hpp:74
group_type::value_type group_value_type
Definition: h2c.hpp:73
static void update(internal_accumulator_type &acc, const InputRange &range)
Definition: h2c.hpp:82
Params params_type
Definition: h2c.hpp:64
group_value_type result_type
Definition: h2c.hpp:75
static void init_accumulator(internal_accumulator_type &acc)
Definition: h2c.hpp:77
detail::ep_map< Group, params_type, params_type::uniformity_count, params_type::expand_msg_variant > policy_type
Definition: h2c.hpp:69
static result_type process(internal_accumulator_type &acc)
Definition: h2c.hpp:91