mgf1.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2020 Mikhail Komarov <nemo@nil.foundation>
3 //
4 // MIT License
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //---------------------------------------------------------------------------//
24 
25 #ifndef CRYPTO3_MGF1_HPP
26 #define CRYPTO3_MGF1_HPP
27 
28 namespace nil {
29  namespace crypto3 {
30  namespace pubkey {
31  namespace padding {
32 
43  template<
44  typename Hash, typename InputIterator, typename OutputIterator,
45  typename StreamHash = typename Hash::template stream_hash<
46  std::numeric_limits<typename std::iterator_traits<InputIterator>::value_type>::digits +
47  std::numeric_limits<typename std::iterator_traits<InputIterator>::value_type>::is_signed>::type>
48  OutputIterator mgf1_mask(InputIterator first, InputIterator last, OutputIterator out,
49  StreamHash sh = StreamHash()) {
50  typename Hash::digest_type result;
51 
52  while (out) {
53  sh.update(first, last);
54  result = sh.end_message();
55 
56  out =
57  std::transform(result.begin(), result.end(), out,
58  [&](const typename Hash::digest_type::value_type &v) { *out++ = v ^ *out; });
59  }
60 
61  return out;
62  }
63  } // namespace padding
64  } // namespace pubkey
65  } // namespace crypto3
66 } // namespace nil
67 
68 #endif
decoded_range< UnaryFunction, SinglePassRange > transform(SinglePassRange &rng, UnaryFunction fn)
Definition: decrypted.hpp:100
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
OutputIterator mgf1_mask(InputIterator first, InputIterator last, OutputIterator out, StreamHash sh=StreamHash())
MGF1 from PKCS #1 v2.0.
Definition: mgf1.hpp:48
Definition: pair.hpp:31