accumulators/aggregate_verify_single_msg.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_ACCUMULATORS_PUBKEY_AGGREGATE_VERIFY_SINGLE_MSG_HPP
27 #define CRYPTO3_ACCUMULATORS_PUBKEY_AGGREGATE_VERIFY_SINGLE_MSG_HPP
28 
29 #include <type_traits>
30 #include <iterator>
31 
32 #include <boost/assert.hpp>
33 #include <boost/concept_check.hpp>
34 
35 #include <boost/range/concepts.hpp>
36 
37 #include <boost/parameter/value_type.hpp>
38 
39 #include <boost/accumulators/framework/accumulator_base.hpp>
40 #include <boost/accumulators/framework/extractor.hpp>
41 #include <boost/accumulators/framework/depends_on.hpp>
42 #include <boost/accumulators/framework/parameters/sample.hpp>
43 
46 
48 
49 namespace nil {
50  namespace crypto3 {
51  namespace pubkey {
52  namespace accumulators {
53  namespace impl {
54  template<typename ProcessingMode>
55  struct aggregate_verify_single_msg_impl : boost::accumulators::accumulator_base {
56  protected:
57  typedef ProcessingMode processing_mode_type;
58  typedef typename processing_mode_type::scheme_type scheme_type;
59  typedef typename processing_mode_type::op_type op_type;
60  typedef typename processing_mode_type::internal_accumulator_type internal_accumulator_type;
61  typedef typename op_type::signature_type signature_type;
63 
64  public:
65  typedef typename processing_mode_type::result_type result_type;
66 
67  template<typename Args>
69  signature(args[boost::accumulators::sample | signature_type::zero()]) {
70  }
71 
72  template<typename Args>
73  inline void operator()(const Args &args) {
74  resolve_type(args[boost::accumulators::sample],
75  args[::nil::crypto3::accumulators::iterator_last | nullptr]);
76  }
77 
78  inline result_type result(boost::accumulators::dont_care) const {
79  return processing_mode_type::process(acc, signature);
80  }
81 
82  protected:
83  //
84  // set verified signature
85  //
86  inline void resolve_type(const signature_type &new_sig, std::nullptr_t) {
87  signature = new_sig;
88  }
89 
90  //
91  // append verified msg or add public key for aggregate verification of single msg
92  //
93  template<typename InputRange>
94  inline void resolve_type(const InputRange &range, std::nullptr_t) {
95  processing_mode_type::update(acc, range);
96  }
97 
98  //
99  // append verified msg or add public key for aggregate verification of single msg
100  //
101  template<typename InputIterator>
102  inline void resolve_type(InputIterator first, InputIterator last) {
103  processing_mode_type::update(acc, first, last);
104  }
105 
108  };
109  } // namespace impl
110 
111  namespace tag {
112  template<typename ProcessingMode>
113  struct aggregate_verify_single_msg : boost::accumulators::depends_on<> {
114  typedef ProcessingMode processing_mode_type;
115 
118 
119  typedef boost::mpl::always<accumulators::impl::aggregate_verify_single_msg_impl<processing_mode_type>>
121  };
122  } // namespace tag
123 
124  namespace extract {
125  template<typename ProcessingMode, typename AccumulatorSet>
126  typename boost::mpl::apply<AccumulatorSet, tag::aggregate_verify_single_msg<ProcessingMode>>::type::result_type
127  aggregate_verify_single_msg(const AccumulatorSet &acc) {
128  return boost::accumulators::extract_result<tag::aggregate_verify_single_msg<ProcessingMode>>(acc);
129  }
130  } // namespace extract
131  } // namespace accumulators
132  } // namespace pubkey
133  } // namespace crypto3
134 } // namespace nil
135 
136 #endif // CRYPTO3_ACCUMULATORS_PUBKEY_AGGREGATE_VERIFY_SINGLE_MSG_HPP
boost::mpl::apply< AccumulatorSet, tag::aggregate_verify_single_msg< ProcessingMode > >::type::result_type aggregate_verify_single_msg(const AccumulatorSet &acc)
Definition: accumulators/aggregate_verify_single_msg.hpp:127
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
Definition: pair.hpp:31
Definition: accumulators/aggregate_verify_single_msg.hpp:55
processing_mode_type::result_type result_type
Definition: accumulators/aggregate_verify_single_msg.hpp:65
processing_mode_type::op_type op_type
Definition: accumulators/aggregate_verify_single_msg.hpp:59
void operator()(const Args &args)
Definition: accumulators/aggregate_verify_single_msg.hpp:73
void resolve_type(InputIterator first, InputIterator last)
Definition: accumulators/aggregate_verify_single_msg.hpp:102
ProcessingMode processing_mode_type
Definition: accumulators/aggregate_verify_single_msg.hpp:57
signature_type signature
Definition: accumulators/aggregate_verify_single_msg.hpp:106
processing_mode_type::internal_accumulator_type internal_accumulator_type
Definition: accumulators/aggregate_verify_single_msg.hpp:60
result_type result(boost::accumulators::dont_care) const
Definition: accumulators/aggregate_verify_single_msg.hpp:78
processing_mode_type::scheme_type scheme_type
Definition: accumulators/aggregate_verify_single_msg.hpp:58
public_key< scheme_type > key_type
Definition: accumulators/aggregate_verify_single_msg.hpp:62
void resolve_type(const signature_type &new_sig, std::nullptr_t)
Definition: accumulators/aggregate_verify_single_msg.hpp:86
void resolve_type(const InputRange &range, std::nullptr_t)
Definition: accumulators/aggregate_verify_single_msg.hpp:94
aggregate_verify_single_msg_impl(const Args &args)
Definition: accumulators/aggregate_verify_single_msg.hpp:68
internal_accumulator_type acc
Definition: accumulators/aggregate_verify_single_msg.hpp:107
op_type::signature_type signature_type
Definition: accumulators/aggregate_verify_single_msg.hpp:61
Definition: accumulators/aggregate_verify_single_msg.hpp:113
boost::mpl::always< accumulators::impl::aggregate_verify_single_msg_impl< processing_mode_type > > impl
Definition: accumulators/aggregate_verify_single_msg.hpp:120
ProcessingMode processing_mode_type
Definition: accumulators/aggregate_verify_single_msg.hpp:114
Public key - a key that can be published and used to verify the authenticity of the signed document,...
Definition: public_key.hpp:43