reconstruct.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_SSS_RECONSTRUCT_HPP
27 #define CRYPTO3_ACCUMULATORS_PUBKEY_SSS_RECONSTRUCT_HPP
28 
29 #include <set>
30 #include <utility>
31 #include <algorithm>
32 #include <iterator>
33 
34 #include <boost/concept_check.hpp>
35 
36 #include <boost/accumulators/framework/accumulator_base.hpp>
37 #include <boost/accumulators/framework/parameters/sample.hpp>
38 
41 
44 
46 
47 namespace nil {
48  namespace crypto3 {
49  namespace pubkey {
50  namespace accumulators {
51  namespace impl {
52  template<typename ProcessingMode, typename = void>
54 
55  template<typename ProcessingMode>
56  struct reconstruct_impl<ProcessingMode> : boost::accumulators::accumulator_base {
57  protected:
58  typedef ProcessingMode processing_mode_type;
59  typedef typename processing_mode_type::scheme_type scheme_type;
60  typedef typename processing_mode_type::op_type op_type;
61  typedef typename processing_mode_type::internal_accumulator_type internal_accumulator_type;
62 
63  public:
64  typedef typename processing_mode_type::result_type result_type;
65 
66  template<typename Args>
67  reconstruct_impl(const Args &args) : seen_shares(0) {
68  }
69 
70  inline result_type result(boost::accumulators::dont_care) const {
71  return processing_mode_type::process(acc);
72  }
73 
74  template<typename Args>
75  inline void operator()(const Args &args) {
76  resolve_type(args[boost::accumulators::sample],
77  args[::nil::crypto3::accumulators::iterator_last | nullptr]);
78  }
79 
80  protected:
81  inline void resolve_type(const share_sss<scheme_type> &share, std::nullptr_t = nullptr) {
82  processing_mode_type::update(acc, share);
83  seen_shares++;
84  }
85 
86  inline void resolve_type(const public_share_sss<scheme_type> &public_share, std::nullptr_t = nullptr) {
87  processing_mode_type::update(acc, public_share);
88  seen_shares++;
89  }
90 
91  template<typename InputRange>
92  inline void resolve_type(const InputRange &range, std::nullptr_t) {
93  for (const auto &s : range) {
94  resolve_type(s);
95  }
96  }
97 
98  template<typename InputIterator>
99  inline void resolve_type(InputIterator first, InputIterator last) {
100  for (auto it = first; it != last; it++) {
101  resolve_type(*it);
102  }
103  }
104 
105  std::size_t seen_shares;
107  };
108  } // namespace impl
109 
110  namespace tag {
111  template<typename ProcessingMode>
112  struct reconstruct : boost::accumulators::depends_on<> {
113  typedef ProcessingMode mode_type;
114 
117 
118  typedef boost::mpl::always<accumulators::impl::reconstruct_impl<mode_type>> impl;
119  };
120  } // namespace tag
121 
122  namespace extract {
123  template<typename ProcessingMode, typename AccumulatorSet>
124  typename boost::mpl::apply<AccumulatorSet, tag::reconstruct<ProcessingMode>>::type::result_type
125  reconstruct(const AccumulatorSet &acc) {
126  return boost::accumulators::extract_result<tag::reconstruct<ProcessingMode>>(acc);
127  }
128  } // namespace extract
129  } // namespace accumulators
130  } // namespace pubkey
131  } // namespace crypto3
132 } // namespace nil
133 
134 #endif // CRYPTO3_ACCUMULATORS_PUBKEY_SSS_RECONSTRUCT_HPP
boost::mpl::apply< AccumulatorSet, tag::reconstruct< ProcessingMode > >::type::result_type reconstruct(const AccumulatorSet &acc)
Definition: reconstruct.hpp:125
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
Definition: pair.hpp:31
processing_mode_type::op_type op_type
Definition: reconstruct.hpp:60
reconstruct_impl(const Args &args)
Definition: reconstruct.hpp:67
processing_mode_type::scheme_type scheme_type
Definition: reconstruct.hpp:59
result_type result(boost::accumulators::dont_care) const
Definition: reconstruct.hpp:70
internal_accumulator_type acc
Definition: reconstruct.hpp:106
processing_mode_type::internal_accumulator_type internal_accumulator_type
Definition: reconstruct.hpp:61
void resolve_type(const public_share_sss< scheme_type > &public_share, std::nullptr_t=nullptr)
Definition: reconstruct.hpp:86
void operator()(const Args &args)
Definition: reconstruct.hpp:75
void resolve_type(const share_sss< scheme_type > &share, std::nullptr_t=nullptr)
Definition: reconstruct.hpp:81
void resolve_type(const InputRange &range, std::nullptr_t)
Definition: reconstruct.hpp:92
processing_mode_type::result_type result_type
Definition: reconstruct.hpp:64
void resolve_type(InputIterator first, InputIterator last)
Definition: reconstruct.hpp:99
ProcessingMode mode_type
Definition: reconstruct.hpp:113
boost::mpl::always< accumulators::impl::reconstruct_impl< mode_type > > impl
Definition: reconstruct.hpp:118
Definition: share_sss.hpp:35