mac/include/nil/crypto3/mac/algorithm/compute.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2019 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_MAC_COMPUTE_HPP
27 #define CRYPTO3_MAC_COMPUTE_HPP
28 
33 
35 
36 namespace nil {
37  namespace crypto3 {
38  namespace mac {
39  template<typename Mac, template<typename> class Padding = nop_padding>
41  }
42 
55  template<typename Mac, typename InputIterator, typename OutputIterator>
56  OutputIterator compute(InputIterator first, InputIterator last, const mac::mac_key<Mac> &key,
57  OutputIterator out) {
59 
60  typedef mac::detail::value_mac_impl<MacAccumulator> StreamSchemeImpl;
62 
63  return SchemeImpl(first, last, std::move(out), MacAccumulator(key));
64  }
65 
77  template<typename Mac, typename SinglePassRange, typename OutputIterator>
78  OutputIterator compute(const SinglePassRange &rng, const mac::mac_key<Mac> &key, OutputIterator out) {
80 
81  typedef mac::detail::value_mac_impl<MacAccumulator> StreamSchemeImpl;
83 
84  return SchemeImpl(rng, std::move(out), MacAccumulator(key));
85  }
86 
98  template<typename Mac, typename InputIterator,
99  typename MacAccumulator = mac::computation_accumulator_set<mac::computation_policy<Mac>>,
100  typename StreamMacImpl = mac::detail::value_mac_impl<MacAccumulator>,
101  typename MacImpl = mac::detail::range_mac_impl<StreamMacImpl>>
102  MacImpl compute(InputIterator first, InputIterator last, const mac::mac_key<Mac> &key) {
103  return MacImpl(first, last, MacAccumulator(key));
104  }
105 
114  template<typename Mac, typename SinglePassRange,
115  typename MacAccumulator = mac::computation_accumulator_set<mac::computation_policy<Mac>>,
116  typename StreamMacImpl = mac::detail::value_mac_impl<MacAccumulator>,
117  typename MacImpl = mac::detail::range_mac_impl<StreamMacImpl>>
118  MacImpl compute(const SinglePassRange &rng, const mac::mac_key<Mac> &key) {
119  return MacImpl(rng, MacAccumulator(key));
120  }
121 
138  template<typename Mac, typename InputIterator,
139  typename OutputAccumulator = mac::computation_accumulator_set<mac::computation_policy<Mac>>>
140  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<OutputAccumulator>::value,
141  OutputAccumulator>::type &
142  compute(InputIterator first, InputIterator last, OutputAccumulator &acc) {
143  typedef mac::detail::ref_mac_impl<OutputAccumulator> StreamMacImpl;
145 
146  return MacImpl(first, last, std::forward<OutputAccumulator>(acc));
147  }
148 
164  template<typename Mac, typename SinglePassRange,
165  typename OutputAccumulator = mac::computation_accumulator_set<mac::computation_policy<Mac>>>
166  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<OutputAccumulator>::value,
167  OutputAccumulator>::type &
168  compute(const SinglePassRange &r, OutputAccumulator &acc) {
169  typedef mac::detail::ref_mac_impl<OutputAccumulator> StreamMacImpl;
171 
172  return MacImpl(r, std::forward<OutputAccumulator>(acc));
173  }
174  } // namespace crypto3
175 } // namespace nil
176 
177 #endif // CRYPTO3_MAC_COMPUTE_HPP
boost::mpl::apply< AccumulatorSet, tag::mac< ProcessingPolicy > >::type::result_type mac(const AccumulatorSet &acc)
Definition: accumulators/mac.hpp:99
OutputIterator move(const SinglePassRange &rng, OutputIterator result)
Definition: move.hpp:45
boost::accumulators::accumulator_set< typename ProcessingPolicy::result_type, boost::accumulators::features< accumulators::tag::mac< ProcessingPolicy > >> computation_accumulator_set
Definition: mac_state.hpp:40
typename processing_policies< Mac, Padding >::computation_policy computation_policy
Definition: mac/include/nil/crypto3/mac/algorithm/compute.hpp:40
OutputIterator compute(InputIterator first, InputIterator last, const mac::mac_key< Mac > &key, OutputIterator out)
Definition: mac/include/nil/crypto3/mac/algorithm/compute.hpp:56
Definition: pair.hpp:31
Definition: mac_processing_policies.hpp:45
Definition: mac_value.hpp:122
Definition: mac_value.hpp:72
Definition: mac_value.hpp:47
Definition: mac_value.hpp:59
Mac key - a key that can be used to create and verify MAC.
Definition: mac_key.hpp:41