emsa_raw.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2020 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_PK_PAD_EMSA_RAW_HPP
27 #define CRYPTO3_PK_PAD_EMSA_RAW_HPP
28 
29 #include <type_traits>
30 #include <vector>
31 #include <algorithm>
32 
33 #include <nil/marshalling/algorithms/pack.hpp>
34 #include <nil/marshalling/types/integral.hpp>
35 #include <nil/marshalling/types/optional.hpp>
36 
37 namespace nil {
38  namespace crypto3 {
39  namespace pubkey {
40  namespace padding {
41  namespace detail {
42  template<typename ValueType, typename = void>
44 
45  template<typename ValueType, typename = void>
47 
48  template<typename ValueType>
50  typename std::enable_if<std::is_integral<ValueType>::value>::type> {
51  typedef std::vector<ValueType> internal_accumulator_type;
53 
54  static inline void init_accumulator(internal_accumulator_type &acc) {
55  }
56 
57  // TODO: pack data from input::value_type to accumulator::value_type
58  template<typename InputRange>
59  static inline typename std::enable_if<std::is_same<
60  ValueType,
61  typename std::iterator_traits<typename InputRange::iterator>::value_type>::value>::type
62  update(internal_accumulator_type &acc, const InputRange &range) {
63  std::copy(std::cbegin(range), std::cend(range), std::back_inserter(acc));
64  }
65 
66  // TODO: pack data from input::value_type to accumulator::value_type
67  template<typename InputIterator>
68  static inline typename std::enable_if<std::is_same<
69  ValueType, typename std::iterator_traits<InputIterator>::value_type>::value>::type
70  update(internal_accumulator_type &acc, InputIterator first, InputIterator last) {
71  std::copy(first, last, std::back_inserter(acc));
72  }
73 
75  return acc;
76  }
77  };
78 
79  template<typename ValueType>
81  ValueType, typename std::enable_if<std::is_integral<ValueType>::value>::type> {
82  protected:
84 
85  public:
86  typedef typename encoding_policy::internal_accumulator_type internal_accumulator_type;
87  typedef bool result_type;
88 
89  static inline void init_accumulator(internal_accumulator_type &acc) {
90  encoding_policy::init_accumulator(acc);
91  }
92 
93  template<typename InputRange>
94  static inline void update(internal_accumulator_type &acc, const InputRange &range) {
95  encoding_policy::update(range, acc);
96  }
97 
98  template<typename InputIterator>
99  static inline void update(internal_accumulator_type &acc, InputIterator first,
100  InputIterator last) {
101  encoding_policy::update(first, last, acc);
102  }
103 
104  // TODO: pack data from input::value_type to accumulator::value_type
105  template<typename InputRange>
106  static inline typename std::enable_if<
107  std::is_same<ValueType, typename std::iterator_traits<
108  typename InputRange::iterator>::value_type>::value,
109  result_type>::type
110  process(internal_accumulator_type &acc, const InputRange &msg_repr) {
111  return std::equal(std::cbegin(acc), std::cend(acc), std::cbegin(msg_repr),
112  std::cend(msg_repr));
113  }
114  };
115  } // namespace detail
116 
124  template<typename ValueType>
125  struct emsa_raw {
127 
130  };
131  } // namespace padding
132  } // namespace pubkey
133  } // namespace crypto3
134 } // namespace nil
135 
136 #endif
typename std::iterator_traits< Iterator >::value_type ValueType
Definition: algebra/include/nil/crypto3/detail/make_array.hpp:50
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
Definition: pair.hpp:31
static std::enable_if< std::is_same< ValueType, typename std::iterator_traits< typename InputRange::iterator >::value_type >::value >::type update(internal_accumulator_type &acc, const InputRange &range)
Definition: emsa_raw.hpp:62
static std::enable_if< std::is_same< ValueType, typename std::iterator_traits< InputIterator >::value_type >::value >::type update(internal_accumulator_type &acc, InputIterator first, InputIterator last)
Definition: emsa_raw.hpp:70
static std::enable_if< std::is_same< ValueType, typename std::iterator_traits< typename InputRange::iterator >::value_type >::value, result_type >::type process(internal_accumulator_type &acc, const InputRange &msg_repr)
Definition: emsa_raw.hpp:110
static void update(internal_accumulator_type &acc, InputIterator first, InputIterator last)
Definition: emsa_raw.hpp:99
EMSA raw. Essentially, accumulate input data in the container with elements of ValueType and return i...
Definition: emsa_raw.hpp:125
detail::emsa_raw_encoding_policy< ValueType > encoding_policy
Definition: emsa_raw.hpp:128
ValueType value_type
Definition: emsa_raw.hpp:126
detail::emsa_raw_verification_policy< ValueType > verification_policy
Definition: emsa_raw.hpp:129