algorithm/deal_shares.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2020-2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020-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_PUBKEY_DEAL_SHARES_HPP
27 #define CRYPTO3_PUBKEY_DEAL_SHARES_HPP
28 
30 
33 
35 
36 namespace nil {
37  namespace crypto3 {
38  namespace pubkey {
39  template<typename Scheme>
41 
42  template<typename Scheme>
44  typename modes::isomorphic<Scheme>::template bind<shares_dealing_policy<Scheme>>::type;
45  } // namespace pubkey
46 
66  template<typename Scheme, typename InputIterator, typename OutputIterator,
68  OutputIterator deal_shares(InputIterator first, InputIterator last, std::size_t n, OutputIterator out) {
69 
70  typedef typename pubkey::shares_dealing_accumulator_set<ProcessingMode> DealingAccumulator;
71 
74 
75  return SchemeImpl(
76  first, last, std::move(out),
77  DealingAccumulator(n, nil::crypto3::accumulators::threshold_value = std::distance(first, last)));
78  }
79 
98  template<typename Scheme, typename SinglePassRange, typename OutputIterator,
99  typename ProcessingMode = pubkey::shares_dealing_processing_mode_default<Scheme>>
100  OutputIterator deal_shares(const SinglePassRange &range, std::size_t n, OutputIterator out) {
101 
102  typedef typename pubkey::shares_dealing_accumulator_set<ProcessingMode> DealingAccumulator;
103 
106 
107  return SchemeImpl(range, std::move(out),
108  DealingAccumulator(n, nil::crypto3::accumulators::threshold_value = range.size()));
109  }
110 
131  template<typename Scheme, typename InputIterator, typename OutputIterator,
132  typename ProcessingMode = pubkey::shares_dealing_processing_mode_default<Scheme>>
133  OutputIterator deal_shares(InputIterator first, InputIterator last, std::size_t n,
134  const typename Scheme::weights_type &weights, OutputIterator out) {
135 
136  typedef typename pubkey::shares_dealing_accumulator_set<ProcessingMode> DealingAccumulator;
137 
140 
141  return SchemeImpl(
142  first, last, std::move(out),
143  DealingAccumulator(n, nil::crypto3::accumulators::threshold_value = std::distance(first, last),
144  nil::crypto3::accumulators::weights = weights));
145  }
146 
166  template<typename Scheme, typename SinglePassRange, typename OutputIterator,
167  typename ProcessingMode = pubkey::shares_dealing_processing_mode_default<Scheme>>
168  OutputIterator deal_shares(const SinglePassRange &range, std::size_t n,
169  const typename Scheme::weights_type &weights, OutputIterator out) {
170 
171  typedef typename pubkey::shares_dealing_accumulator_set<ProcessingMode> DealingAccumulator;
172 
175 
176  return SchemeImpl(range, std::move(out),
177  DealingAccumulator(n, nil::crypto3::accumulators::threshold_value = range.size(),
178  nil::crypto3::accumulators::weights = weights));
179  }
180 
199  template<typename Scheme, typename InputIterator,
200  typename ProcessingMode = pubkey::shares_dealing_processing_mode_default<Scheme>,
201  typename OutputAccumulator = typename pubkey::shares_dealing_accumulator_set<ProcessingMode>>
202  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<OutputAccumulator>::value,
203  OutputAccumulator>::type &
204  deal_shares(InputIterator first, InputIterator last, OutputAccumulator &acc) {
205 
208 
209  return SchemeImpl(first, last, std::forward<OutputAccumulator>(acc));
210  }
211 
229  template<typename Scheme, typename SinglePassRange,
230  typename ProcessingMode = pubkey::shares_dealing_processing_mode_default<Scheme>,
231  typename OutputAccumulator = typename pubkey::shares_dealing_accumulator_set<ProcessingMode>>
232  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<OutputAccumulator>::value,
233  OutputAccumulator>::type &
234  deal_shares(const SinglePassRange &range, OutputAccumulator &acc) {
235 
238 
239  return SchemeImpl(range, std::forward<OutputAccumulator>(acc));
240  }
241 
263  template<typename Scheme, typename InputIterator,
264  typename ProcessingMode = pubkey::shares_dealing_processing_mode_default<Scheme>,
265  typename DealingAccumulator = typename pubkey::shares_dealing_accumulator_set<ProcessingMode>,
266  typename StreamSchemeImpl = pubkey::detail::value_pubkey_impl<DealingAccumulator>,
267  typename SchemeImpl = pubkey::detail::range_pubkey_impl<StreamSchemeImpl>>
268  SchemeImpl deal_shares(InputIterator first, InputIterator last, std::size_t n) {
269 
270  return SchemeImpl(
271  first, last,
272  DealingAccumulator(n, nil::crypto3::accumulators::threshold_value = std::distance(first, last)));
273  }
274 
295  template<typename Scheme, typename SinglePassRange,
296  typename ProcessingMode = pubkey::shares_dealing_processing_mode_default<Scheme>,
297  typename DealingAccumulator = typename pubkey::shares_dealing_accumulator_set<ProcessingMode>,
298  typename StreamSchemeImpl = pubkey::detail::value_pubkey_impl<DealingAccumulator>,
299  typename SchemeImpl = pubkey::detail::range_pubkey_impl<StreamSchemeImpl>>
300  SchemeImpl deal_shares(const SinglePassRange &range, std::size_t n) {
301 
302  return SchemeImpl(range, DealingAccumulator(n, nil::crypto3::accumulators::threshold_value = range.size()));
303  }
304 
327  template<typename Scheme, typename InputIterator,
328  typename ProcessingMode = pubkey::shares_dealing_processing_mode_default<Scheme>,
329  typename DealingAccumulator = typename pubkey::shares_dealing_accumulator_set<ProcessingMode>,
330  typename StreamSchemeImpl = pubkey::detail::value_pubkey_impl<DealingAccumulator>,
331  typename SchemeImpl = pubkey::detail::range_pubkey_impl<StreamSchemeImpl>>
332  SchemeImpl deal_shares(InputIterator first, InputIterator last, std::size_t n,
333  const typename Scheme::weights_type &weights) {
334 
335  return SchemeImpl(
336  first, last,
337  DealingAccumulator(n, nil::crypto3::accumulators::threshold_value = std::distance(first, last),
338  nil::crypto3::accumulators::weights = weights));
339  }
340 
362  template<typename Scheme, typename SinglePassRange,
363  typename ProcessingMode = pubkey::shares_dealing_processing_mode_default<Scheme>,
364  typename DealingAccumulator = typename pubkey::shares_dealing_accumulator_set<ProcessingMode>,
365  typename StreamSchemeImpl = pubkey::detail::value_pubkey_impl<DealingAccumulator>,
366  typename SchemeImpl = pubkey::detail::range_pubkey_impl<StreamSchemeImpl>>
367  SchemeImpl deal_shares(const SinglePassRange &range, std::size_t n,
368  const typename Scheme::weights_type &weights) {
369 
370  return SchemeImpl(range, DealingAccumulator(n, nil::crypto3::accumulators::threshold_value = range.size(),
371  nil::crypto3::accumulators::weights = weights));
372  }
373  } // namespace crypto3
374 } // namespace nil
375 
376 #endif // include guard
OutputIterator deal_shares(InputIterator first, InputIterator last, std::size_t n, OutputIterator out)
Deal shares using passed polynomial coefficients, threshold number of participants required to recons...
Definition: algorithm/deal_shares.hpp:68
OutputIterator move(const SinglePassRange &rng, OutputIterator result)
Definition: move.hpp:45
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
boost::accumulators::accumulator_set< typename ProcessingMode::result_type, boost::accumulators::features< accumulators::tag::deal_shares< ProcessingMode > >> shares_dealing_accumulator_set
Definition: secret_sharing_state.hpp:46
typename modes::isomorphic< Scheme >::template bind< shares_dealing_policy< Scheme > >::type shares_dealing_processing_mode_default
Definition: algorithm/deal_shares.hpp:44
typename modes::isomorphic< Scheme >::shares_dealing_policy shares_dealing_policy
Definition: algorithm/deal_shares.hpp:40
Definition: pair.hpp:31
Definition: pubkey_value.hpp:167
Definition: pubkey_value.hpp:49
Definition: isomorphic.hpp:219