accumulators/deal_share.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_DEAL_SHARE_HPP
27 #define CRYPTO3_ACCUMULATORS_PUBKEY_SSS_DEAL_SHARE_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 
43 
45 
46 namespace nil {
47  namespace crypto3 {
48  namespace pubkey {
49  namespace accumulators {
50  namespace impl {
51  template<typename ProcessingMode, typename = void>
53 
54  template<typename ProcessingMode>
55  struct deal_share_impl<ProcessingMode> : boost::accumulators::accumulator_base {
56  typedef ProcessingMode processing_mode_type;
57  typedef typename processing_mode_type::scheme_type scheme_type;
58  typedef typename processing_mode_type::op_type op_type;
59  typedef typename processing_mode_type::internal_accumulator_type internal_accumulator_type;
60 
61  public:
62  typedef typename processing_mode_type::result_type result_type;
63 
64  //
65  // boost::accumulators::sample -- participant index
66  //
67  template<typename Args>
68  deal_share_impl(const Args &args) {
69  processing_mode_type::init_accumulator(acc, args[boost::accumulators::sample]);
70  }
71 
72  inline result_type result(boost::accumulators::dont_care) const {
73  return processing_mode_type::process(acc);
74  }
75 
76  //
77  // boost::accumulators::sample -- partial shares generated by other participants
78  // input coefficients should be supplied in increasing term degrees order
79  //
80  template<typename Args>
81  inline void operator()(const Args &args) {
82  resolve_type(args[boost::accumulators::sample],
83  args[::nil::crypto3::accumulators::iterator_last | nullptr]);
84  }
85 
86  protected:
87  inline void resolve_type(const share_sss<scheme_type> &share, std::nullptr_t = nullptr) {
88  processing_mode_type::update(acc, share);
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 
106  };
107  } // namespace impl
108 
109  namespace tag {
110  template<typename ProcessingMode>
111  struct deal_share : boost::accumulators::depends_on<> {
112  typedef ProcessingMode mode_type;
113 
116 
117  typedef boost::mpl::always<accumulators::impl::deal_share_impl<mode_type>> impl;
118  };
119  } // namespace tag
120 
121  namespace extract {
122  template<typename ProcessingMode, typename AccumulatorSet>
123  typename boost::mpl::apply<AccumulatorSet, tag::deal_share<ProcessingMode>>::type::result_type
124  deal_share(const AccumulatorSet &acc) {
125  return boost::accumulators::extract_result<tag::deal_share<ProcessingMode>>(acc);
126  }
127  } // namespace extract
128  } // namespace accumulators
129  } // namespace pubkey
130  } // namespace crypto3
131 } // namespace nil
132 
133 #endif // CRYPTO3_ACCUMULATORS_PUBKEY_SSS_DEAL_SHARE_HPP
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
boost::mpl::apply< AccumulatorSet, tag::deal_share< ProcessingMode > >::type::result_type deal_share(const AccumulatorSet &acc)
Definition: accumulators/deal_share.hpp:124
Definition: pair.hpp:31
internal_accumulator_type acc
Definition: accumulators/deal_share.hpp:105
void operator()(const Args &args)
Definition: accumulators/deal_share.hpp:81
processing_mode_type::internal_accumulator_type internal_accumulator_type
Definition: accumulators/deal_share.hpp:59
void resolve_type(const share_sss< scheme_type > &share, std::nullptr_t=nullptr)
Definition: accumulators/deal_share.hpp:87
void resolve_type(InputIterator first, InputIterator last)
Definition: accumulators/deal_share.hpp:99
result_type result(boost::accumulators::dont_care) const
Definition: accumulators/deal_share.hpp:72
void resolve_type(const InputRange &range, std::nullptr_t)
Definition: accumulators/deal_share.hpp:92
deal_share_impl(const Args &args)
Definition: accumulators/deal_share.hpp:68
processing_mode_type::op_type op_type
Definition: accumulators/deal_share.hpp:58
ProcessingMode processing_mode_type
Definition: accumulators/deal_share.hpp:56
processing_mode_type::result_type result_type
Definition: accumulators/deal_share.hpp:62
processing_mode_type::scheme_type scheme_type
Definition: accumulators/deal_share.hpp:57
Definition: accumulators/deal_share.hpp:52
Definition: accumulators/deal_share.hpp:111
boost::mpl::always< accumulators::impl::deal_share_impl< mode_type > > impl
Definition: accumulators/deal_share.hpp:117
ProcessingMode mode_type
Definition: accumulators/deal_share.hpp:112
Definition: share_sss.hpp:35