mac_processing_policies.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_MAC_PROCESSING_POLICIES_HPP
27 #define CRYPTO3_MAC_PROCESSING_POLICIES_HPP
28 
29 #include <type_traits>
30 
32 
33 namespace nil {
34  namespace crypto3 {
35  namespace mac {
36  namespace detail {
37  template<typename Mac>
38  struct basic_policy {
39  typedef std::size_t size_type;
40 
41  typedef Mac mac_type;
42  };
43 
44  template<typename Mac>
45  struct computation_policy : public basic_policy<Mac> {
47 
49  typedef typename key_type::internal_accumulator_type internal_accumulator_type;
50  typedef typename key_type::digest_type result_type;
51 
52  template<typename... Args>
53  static inline result_type process(const key_type &key, Args &...args) {
54  return key.compute(args...);
55  }
56 
57  template<typename... Args>
58  inline static void update(const key_type &key, Args &...args) {
59  key.update(args...);
60  }
61 
62  template<typename... Args>
63  inline static void init_accumulator(const key_type &key, Args &...args) {
64  key.init_accumulator(args...);
65  }
66  };
67 
68  template<typename Mac>
69  struct verification_policy : public basic_policy<Mac> {
71 
73  typedef typename key_type::internal_accumulator_type internal_accumulator_type;
74  typedef bool result_type;
75 
76  template<typename... Args>
77  static inline result_type process(const key_type &key, Args &...args) {
78  return key.verify(args...);
79  }
80 
81  template<typename... Args>
82  inline static void update(const key_type &key, Args &...args) {
83  key.update(args...);
84  }
85 
86  template<typename... Args>
87  inline static void init_accumulator(const key_type &key, Args &...args) {
88  key.init_accumulator(args...);
89  }
90  };
91  } // namespace detail
92 
102  template<typename Mac, template<typename> class Padding>
104  typedef Mac mac_type;
105  // TODO: refactor padding concept
106  typedef Padding<Mac> padding_type;
107 
110  };
111  } // namespace mac
112  } // namespace crypto3
113 } // namespace nil
114 
115 #endif // CRYPTO3_MAC_PROCESSING_POLICIES_HPP
boost::mpl::apply< AccumulatorSet, tag::mac< ProcessingPolicy > >::type::result_type mac(const AccumulatorSet &acc)
Definition: accumulators/mac.hpp:99
Definition: pair.hpp:31
Definition: mac_processing_policies.hpp:38
std::size_t size_type
Definition: mac_processing_policies.hpp:39
Mac mac_type
Definition: mac_processing_policies.hpp:41
Definition: mac_processing_policies.hpp:45
static result_type process(const key_type &key, Args &...args)
Definition: mac_processing_policies.hpp:53
basic_policy< Mac >::mac_type mac_type
Definition: mac_processing_policies.hpp:46
mac_key< mac_type > key_type
Definition: mac_processing_policies.hpp:48
static void init_accumulator(const key_type &key, Args &...args)
Definition: mac_processing_policies.hpp:63
key_type::internal_accumulator_type internal_accumulator_type
Definition: mac_processing_policies.hpp:49
static void update(const key_type &key, Args &...args)
Definition: mac_processing_policies.hpp:58
key_type::digest_type result_type
Definition: mac_processing_policies.hpp:50
Definition: mac_processing_policies.hpp:69
static void init_accumulator(const key_type &key, Args &...args)
Definition: mac_processing_policies.hpp:87
basic_policy< Mac >::mac_type mac_type
Definition: mac_processing_policies.hpp:70
static result_type process(const key_type &key, Args &...args)
Definition: mac_processing_policies.hpp:77
mac_key< mac_type > key_type
Definition: mac_processing_policies.hpp:72
bool result_type
Definition: mac_processing_policies.hpp:74
key_type::internal_accumulator_type internal_accumulator_type
Definition: mac_processing_policies.hpp:73
static void update(const key_type &key, Args &...args)
Definition: mac_processing_policies.hpp:82
Mac key - a key that can be used to create and verify MAC.
Definition: mac_key.hpp:41
Definition: mac_processing_policies.hpp:103
detail::verification_policy< mac_type > verification_policy
Definition: mac_processing_policies.hpp:109
Mac mac_type
Definition: mac_processing_policies.hpp:104
detail::computation_policy< mac_type > computation_policy
Definition: mac_processing_policies.hpp:108
Padding< Mac > padding_type
Definition: mac_processing_policies.hpp:106