accumulators/verify_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_VERIFY_SHARE_HPP
27 #define CRYPTO3_ACCUMULATORS_PUBKEY_SSS_VERIFY_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 // #include <nil/crypto3/pubkey/secret_sharing/pedersen.hpp>
44 
45 namespace nil {
46  namespace crypto3 {
47  namespace pubkey {
48  namespace accumulators {
49  namespace impl {
50  template<typename ProcessingMode, typename = void>
52 
53  template<typename ProcessingMode>
54  struct verify_share_impl<ProcessingMode> : boost::accumulators::accumulator_base {
55  protected:
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 -- verified public (or private) share
66  //
67  template<typename Args>
68  verify_share_impl(const Args &args) :
69  verified_public_share(args[boost::accumulators::sample]), seen_coeffs(0) {
70  // TODO: replace with rvalue
71  // TODO: init accumulator without default constructor
72  auto i = verified_public_share.get_index();
73  processing_mode_type::init_accumulator(acc, i);
74  }
75 
76  //
77  // boost::accumulators::sample -- public polynomial coefficients
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  inline result_type result(boost::accumulators::dont_care) const {
87  return processing_mode_type::process(acc, verified_public_share);
88  }
89 
90  protected:
91  inline void resolve_type(const typename scheme_type::public_coeff_type &public_coeff,
92  std::nullptr_t = nullptr) {
93  processing_mode_type::update(acc, seen_coeffs, public_coeff);
94  seen_coeffs++;
95  }
96 
97  template<typename InputRange>
98  inline void resolve_type(const InputRange &range, std::nullptr_t) {
99  for (const auto &pc : range) {
100  resolve_type(pc);
101  }
102  }
103 
104  template<typename InputIterator>
105  inline void resolve_type(InputIterator first, InputIterator last) {
106  for (auto it = first; it != last; it++) {
107  resolve_type(*it);
108  }
109  }
110 
111  std::size_t seen_coeffs;
114  };
115  } // namespace impl
116 
117  namespace tag {
118  template<typename ProcessingMode>
119  struct verify_share : boost::accumulators::depends_on<> {
120  typedef ProcessingMode mode_type;
121 
124 
125  typedef boost::mpl::always<accumulators::impl::verify_share_impl<mode_type>> impl;
126  };
127  } // namespace tag
128 
129  namespace extract {
130  template<typename ProcessingMode, typename AccumulatorSet>
131  typename boost::mpl::apply<AccumulatorSet, tag::verify_share<ProcessingMode>>::type::result_type
132  verify_share(const AccumulatorSet &acc) {
133  return boost::accumulators::extract_result<tag::verify_share<ProcessingMode>>(acc);
134  }
135  } // namespace extract
136  } // namespace accumulators
137  } // namespace pubkey
138  } // namespace crypto3
139 } // namespace nil
140 
141 #endif // CRYPTO3_ACCUMULATORS_PUBKEY_SSS_VERIFY_SHARE_HPP
boost::mpl::apply< AccumulatorSet, tag::verify_share< ProcessingMode > >::type::result_type verify_share(const AccumulatorSet &acc)
Definition: accumulators/verify_share.hpp:132
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
Definition: pair.hpp:31
result_type result(boost::accumulators::dont_care) const
Definition: accumulators/verify_share.hpp:86
void resolve_type(InputIterator first, InputIterator last)
Definition: accumulators/verify_share.hpp:105
void resolve_type(const InputRange &range, std::nullptr_t)
Definition: accumulators/verify_share.hpp:98
internal_accumulator_type acc
Definition: accumulators/verify_share.hpp:113
std::size_t seen_coeffs
Definition: accumulators/verify_share.hpp:111
verify_share_impl(const Args &args)
Definition: accumulators/verify_share.hpp:68
processing_mode_type::scheme_type scheme_type
Definition: accumulators/verify_share.hpp:57
processing_mode_type::op_type op_type
Definition: accumulators/verify_share.hpp:58
void resolve_type(const typename scheme_type::public_coeff_type &public_coeff, std::nullptr_t=nullptr)
Definition: accumulators/verify_share.hpp:91
public_share_sss< scheme_type > verified_public_share
Definition: accumulators/verify_share.hpp:112
processing_mode_type::result_type result_type
Definition: accumulators/verify_share.hpp:62
processing_mode_type::internal_accumulator_type internal_accumulator_type
Definition: accumulators/verify_share.hpp:59
void operator()(const Args &args)
Definition: accumulators/verify_share.hpp:81
ProcessingMode processing_mode_type
Definition: accumulators/verify_share.hpp:56
Definition: accumulators/verify_share.hpp:51
Definition: accumulators/verify_share.hpp:119
boost::mpl::always< accumulators::impl::verify_share_impl< mode_type > > impl
Definition: accumulators/verify_share.hpp:125
ProcessingMode mode_type
Definition: accumulators/verify_share.hpp:120