algorithm/to_curve.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_TO_CURVE_HPP
27 #define CRYPTO3_HASH_TO_CURVE_HPP
28 
31 
32 #include <nil/crypto3/detail/type_traits.hpp>
33 
34 namespace nil {
35  namespace crypto3 {
57  template<typename Hash, typename InputIterator, typename OutputIterator>
58  typename std::enable_if<!boost::accumulators::detail::is_accumulator_set<OutputIterator>::value,
59  OutputIterator>::type
60  to_curve(InputIterator first, InputIterator last, OutputIterator out) {
61  typedef hashing_to_curve_accumulator_set<Hash> HashingAccumulator;
62 
65 
66  return HashImpl(first, last, std::move(out), HashingAccumulator());
67  }
68 
84  template<typename Hash, typename InputIterator,
85  typename HashingAccumulator = hashing_to_curve_accumulator_set<Hash>>
86  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<HashingAccumulator>::value,
87  HashingAccumulator>::type &
88  to_curve(InputIterator first, InputIterator last, HashingAccumulator &sh) {
91 
92  return HashImpl(first, last, std::forward<HashingAccumulator>(sh));
93  }
94 
109  template<typename Hash, typename InputIterator,
110  typename HashingAccumulator = hashing_to_curve_accumulator_set<Hash>>
111  hashes::detail::range_to_curve_impl<hashes::detail::value_to_curve_impl<typename std::enable_if<
112  boost::accumulators::detail::is_accumulator_set<HashingAccumulator>::value, HashingAccumulator>::type>>
113  to_curve(InputIterator first, InputIterator last) {
116 
117  return HashImpl(first, last, HashingAccumulator());
118  }
119 
134  template<typename Hash, typename SinglePassRange, typename OutputIterator>
135  typename std::enable_if<::nil::crypto3::detail::is_iterator<OutputIterator>::value, OutputIterator>::type
136  to_curve(const SinglePassRange &rng, OutputIterator out) {
137  typedef hashing_to_curve_accumulator_set<Hash> HashingAccumulator;
138 
141 
142  return HashImpl(rng, std::move(out), HashingAccumulator());
143  }
144 
159  template<typename Hash, typename SinglePassRange,
160  typename HashingAccumulator = hashing_to_curve_accumulator_set<Hash>>
161  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<HashingAccumulator>::value,
162  HashingAccumulator>::type &
163  to_curve(const SinglePassRange &rng, HashingAccumulator &sh) {
166 
167  return HashImpl(rng, std::forward<HashingAccumulator>(sh));
168  }
169 
183  template<typename Hash, typename SinglePassRange,
184  typename HashingAccumulator = hashing_to_curve_accumulator_set<Hash>>
185  hashes::detail::range_to_curve_impl<hashes::detail::value_to_curve_impl<HashingAccumulator>>
186  to_curve(const SinglePassRange &r) {
187 
190 
191  return HashImpl(r, HashingAccumulator());
192  }
193 
208  template<typename Hash, typename T, typename OutputIterator>
209  typename std::enable_if<::nil::crypto3::detail::is_iterator<OutputIterator>::value, OutputIterator>::type
210  to_curve(std::initializer_list<T> list, OutputIterator out) {
211  typedef hashing_to_curve_accumulator_set<Hash> HashingAccumulator;
212 
215 
216  return HashImpl(list, std::move(out), HashingAccumulator());
217  }
218 
233  template<typename Hash, typename T, typename HashingAccumulator = hashing_to_curve_accumulator_set<Hash>>
234  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<HashingAccumulator>::value,
235  HashingAccumulator>::type &
236  to_curve(std::initializer_list<T> rng, HashingAccumulator &sh) {
239 
240  return HashImpl(rng, std::forward<HashingAccumulator>(sh));
241  }
242 
256  template<typename Hash, typename T, typename HashingAccumulator = hashing_to_curve_accumulator_set<Hash>>
257  hashes::detail::range_to_curve_impl<hashes::detail::value_to_curve_impl<HashingAccumulator>>
258  to_curve(std::initializer_list<T> r) {
259 
262 
263  return HashImpl(r, HashingAccumulator());
264  }
265  } // namespace crypto3
266 } // namespace nil
267 
268 #endif // CRYPTO3_HASH_TO_CURVE_HPP
std::enable_if<!boost::accumulators::detail::is_accumulator_set< OutputIterator >::value, OutputIterator >::type to_curve(InputIterator first, InputIterator last, OutputIterator out)
Definition: algorithm/to_curve.hpp:60
boost::accumulators::accumulator_set< typename Hash::result_type, boost::accumulators::features< hashes::accumulators::tag::to_curve< Hash > >> hashing_to_curve_accumulator_set
Accumulator set with pre-defined hashing to curve accumulator params.
Definition: to_curve_state.hpp:46
OutputIterator move(const SinglePassRange &rng, OutputIterator result)
Definition: move.hpp:45
Definition: pair.hpp:31
Definition: to_curve_value.hpp:122
Definition: to_curve_value.hpp:72
Definition: to_curve_value.hpp:47
Definition: to_curve_value.hpp:59