accumulators/aggregate_verify.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_HPP
27 #define CRYPTO3_ACCUMULATORS_PUBKEY_AGGREGATE_VERIFY_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_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>
68  aggregate_verify_impl(const Args &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 | nullptr],
75  args[::nil::crypto3::accumulators::iterator_last | nullptr],
76  args[::nil::crypto3::accumulators::key | nullptr]);
77  }
78 
79  inline result_type result(boost::accumulators::dont_care) const {
80  return processing_mode_type::process(acc, signature);
81  }
82 
83  protected:
84  inline void resolve_type(std::nullptr_t, std::nullptr_t, std::nullptr_t) {
85  }
86 
87  //
88  // set verified signature
89  //
90  inline void resolve_type(const signature_type &new_sig, std::nullptr_t, std::nullptr_t) {
91  signature = new_sig;
92  }
93 
94  //
95  // append verified msg of specified public key for aggregate verification
96  //
97  template<typename InputRange>
98  inline void resolve_type(const InputRange &range, std::nullptr_t, const key_type &pubkey) {
99  processing_mode_type::update(acc, pubkey, range);
100  }
101 
102  //
103  // append verified msg of specified public key for aggregate verification
104  //
105  template<typename InputIterator>
106  inline void resolve_type(InputIterator first, InputIterator last, const key_type &pubkey) {
107  processing_mode_type::update(acc, pubkey, first, last);
108  }
109 
112  };
113  } // namespace impl
114 
115  namespace tag {
116  template<typename ProcessingMode>
117  struct aggregate_verify : boost::accumulators::depends_on<> {
118  typedef ProcessingMode processing_mode_type;
119 
122 
123  typedef boost::mpl::always<accumulators::impl::aggregate_verify_impl<processing_mode_type>>
125  };
126  } // namespace tag
127 
128  namespace extract {
129  template<typename ProcessingMode, typename AccumulatorSet>
130  typename boost::mpl::apply<AccumulatorSet, tag::aggregate_verify<ProcessingMode>>::type::result_type
131  aggregate_verify(const AccumulatorSet &acc) {
132  return boost::accumulators::extract_result<tag::aggregate_verify<ProcessingMode>>(acc);
133  }
134  } // namespace extract
135  } // namespace accumulators
136  } // namespace pubkey
137  } // namespace crypto3
138 } // namespace nil
139 
140 #endif // CRYPTO3_ACCUMULATORS_PUBKEY_AGGREGATE_VERIFY_HPP
boost::mpl::apply< AccumulatorSet, tag::aggregate_verify< ProcessingMode > >::type::result_type aggregate_verify(const AccumulatorSet &acc)
Definition: accumulators/aggregate_verify.hpp:131
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.hpp:55
void resolve_type(std::nullptr_t, std::nullptr_t, std::nullptr_t)
Definition: accumulators/aggregate_verify.hpp:84
op_type::signature_type signature_type
Definition: accumulators/aggregate_verify.hpp:61
ProcessingMode processing_mode_type
Definition: accumulators/aggregate_verify.hpp:57
void resolve_type(const signature_type &new_sig, std::nullptr_t, std::nullptr_t)
Definition: accumulators/aggregate_verify.hpp:90
signature_type signature
Definition: accumulators/aggregate_verify.hpp:110
processing_mode_type::internal_accumulator_type internal_accumulator_type
Definition: accumulators/aggregate_verify.hpp:60
processing_mode_type::op_type op_type
Definition: accumulators/aggregate_verify.hpp:59
public_key< scheme_type > key_type
Definition: accumulators/aggregate_verify.hpp:62
void resolve_type(const InputRange &range, std::nullptr_t, const key_type &pubkey)
Definition: accumulators/aggregate_verify.hpp:98
void operator()(const Args &args)
Definition: accumulators/aggregate_verify.hpp:73
result_type result(boost::accumulators::dont_care) const
Definition: accumulators/aggregate_verify.hpp:79
internal_accumulator_type acc
Definition: accumulators/aggregate_verify.hpp:111
processing_mode_type::result_type result_type
Definition: accumulators/aggregate_verify.hpp:65
aggregate_verify_impl(const Args &args)
Definition: accumulators/aggregate_verify.hpp:68
void resolve_type(InputIterator first, InputIterator last, const key_type &pubkey)
Definition: accumulators/aggregate_verify.hpp:106
processing_mode_type::scheme_type scheme_type
Definition: accumulators/aggregate_verify.hpp:58
Definition: accumulators/aggregate_verify.hpp:117
boost::mpl::always< accumulators::impl::aggregate_verify_impl< processing_mode_type > > impl
Definition: accumulators/aggregate_verify.hpp:124
ProcessingMode processing_mode_type
Definition: accumulators/aggregate_verify.hpp:118
Public key - a key that can be published and used to verify the authenticity of the signed document,...
Definition: public_key.hpp:43