feldman.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_FELDMAN_SSS_HPP
27 #define CRYPTO3_PUBKEY_FELDMAN_SSS_HPP
28 
30 
32 
33 namespace nil {
34  namespace crypto3 {
35  namespace pubkey {
36  template<typename Group>
37  struct feldman_sss : public shamir_sss<Group> {
39  };
40 
41  template<typename Group>
42  struct public_share_sss<feldman_sss<Group>> : public public_share_sss<shamir_sss<Group>> {
46 
47  public_share_sss() = default;
48 
49  public_share_sss(std::size_t i) : base_type(i) {
50  }
51 
52  public_share_sss(const public_share_type &in_public_share) : base_type(in_public_share) {
53  }
54 
55  public_share_sss(std::size_t i, const typename public_share_type::second_type &ps) : base_type(i, ps) {
56  }
57 
58  //
59  // 0 <= k < t
60  //
61  inline void update(const typename scheme_type::public_coeff_type &public_coeff, std::size_t exp) {
62  assert(scheme_type::check_exp(exp));
63 
64  this->public_share.second =
65  this->public_share.second +
66  typename scheme_type::private_element_type(this->public_share.first).pow(exp) * public_coeff;
67  }
68  };
69 
70  template<typename Group>
71  struct share_sss<feldman_sss<Group>> : public share_sss<shamir_sss<Group>> {
75 
76  share_sss() = default;
77 
78  share_sss(std::size_t i) : base_type(i) {
79  }
80 
81  share_sss(const share_type &in_share) : base_type(in_share) {
82  }
83 
84  share_sss(std::size_t i, const typename share_type::second_type &s) : base_type(i, s) {
85  }
86  };
87 
88  template<typename Group>
89  struct public_secret_sss<feldman_sss<Group>> : public public_secret_sss<shamir_sss<Group>> {
94 
95  template<typename PublicShares>
96  public_secret_sss(const PublicShares &public_shares) : base_type(public_shares) {
97  }
98 
99  template<typename PublicShareIt>
100  public_secret_sss(PublicShareIt first, PublicShareIt last) : base_type(first, last) {
101  }
102 
103  template<typename PublicShares>
104  public_secret_sss(const PublicShares &public_shares, const indexes_type &indexes) :
105  base_type(public_shares, indexes) {
106  }
107 
108  template<typename PublicShareIt>
109  public_secret_sss(PublicShareIt first, PublicShareIt last, const indexes_type &indexes) :
110  base_type(first, last, indexes) {
111  }
112  };
113 
114  template<typename Group>
115  struct secret_sss<feldman_sss<Group>> : public secret_sss<shamir_sss<Group>> {
120 
121  template<typename Shares>
122  secret_sss(const Shares &shares) : base_type(shares) {
123  }
124 
125  template<typename ShareIt>
126  secret_sss(ShareIt first, ShareIt last) : base_type(first, last) {
127  }
128 
129  template<typename Shares>
130  secret_sss(const Shares &shares, const indexes_type &indexes) : base_type(shares, indexes) {
131  }
132 
133  template<typename ShareIt>
134  secret_sss(ShareIt first, ShareIt last, const indexes_type &indexes) : base_type(first, last, indexes) {
135  }
136  };
137 
138  template<typename Group>
139  struct deal_shares_op<feldman_sss<Group>> : public deal_shares_op<shamir_sss<Group>> {
143  typedef std::vector<share_type> shares_type;
146 
147  static inline void init_accumulator(internal_accumulator_type &acc, std::size_t n, std::size_t t) {
148  base_type::template _init_accumulator<share_type>(acc, n, t);
149  }
150 
151  static inline void update(internal_accumulator_type &acc, std::size_t exp,
152  const typename scheme_type::coeff_type &coeff) {
153  base_type::template _update<scheme_type>(acc, exp, coeff);
154  }
155 
157  return base_type::template _process<result_type>(acc);
158  }
159  };
160 
161  template<typename Group>
162  struct verify_share_op<feldman_sss<Group>> {
166  typedef bool result_type;
167 
168  protected:
169  template<typename InternalAccumulator>
170  static inline void _init_accumulator(InternalAccumulator &acc, std::size_t i) {
171  acc = InternalAccumulator(i);
172  }
173 
174  template<typename Scheme, typename InternalAccumulator>
175  static inline void _update(InternalAccumulator &acc, std::size_t exp,
176  const typename Scheme::public_coeff_type &public_coeff) {
177  acc.update(public_coeff, exp);
178  }
179 
180  template<typename InternalAccumulator, typename PublicShare>
181  static inline bool _process(const InternalAccumulator &acc, const PublicShare &verified_public_share) {
182  return acc == verified_public_share;
183  }
184 
185  public:
186  static inline void init_accumulator(internal_accumulator_type &acc, std::size_t i) {
187  _init_accumulator(acc, i);
188  }
189 
190  static inline void update(internal_accumulator_type &acc, std::size_t exp,
191  const typename scheme_type::public_coeff_type &public_coeff) {
192  _update<scheme_type>(acc, exp, public_coeff);
193  }
194 
196  const public_share_type &verified_public_share) {
197  return _process(acc, verified_public_share);
198  }
199  };
200 
201  template<typename Group>
203  : public reconstruct_public_secret_op<shamir_sss<Group>> {
208  typedef std::pair<typename scheme_type::indexes_type, std::set<public_share_type>>
211 
212  public:
213  static inline void init_accumulator() {
214  }
215 
216  static inline void update(internal_accumulator_type &acc, const public_share_type &public_share) {
217  base_type::_update(acc, public_share);
218  }
219 
221  return base_type::template _process<result_type>(acc);
222  }
223  };
224 
225  template<typename Group>
226  struct reconstruct_secret_op<feldman_sss<Group>> : public reconstruct_secret_op<shamir_sss<Group>> {
231  typedef std::pair<typename scheme_type::indexes_type, std::set<share_type>> internal_accumulator_type;
233 
234  public:
235  static inline void init_accumulator() {
236  }
237 
238  static inline void update(internal_accumulator_type &acc, const share_type &share) {
239  base_type::_update(acc, share);
240  }
241 
243  return base_type::template _process<result_type>(acc);
244  }
245  };
246  } // namespace pubkey
247  } // namespace crypto3
248 } // namespace nil
249 
250 #endif // CRYPTO3_PUBKEY_FELDMAN_SSS_HPP
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
Definition: pair.hpp:31
static result_type process(internal_accumulator_type &acc)
Definition: feldman.hpp:156
static void init_accumulator(internal_accumulator_type &acc, std::size_t n, std::size_t t)
Definition: feldman.hpp:147
share_sss< scheme_type > share_type
Definition: feldman.hpp:142
deal_shares_op< shamir_sss< Group > > base_type
Definition: feldman.hpp:140
shares_type result_type
Definition: feldman.hpp:145
std::vector< share_type > shares_type
Definition: feldman.hpp:143
static void update(internal_accumulator_type &acc, std::size_t exp, const typename scheme_type::coeff_type &coeff)
Definition: feldman.hpp:151
feldman_sss< Group > scheme_type
Definition: feldman.hpp:141
shares_type internal_accumulator_type
Definition: feldman.hpp:144
Definition: deal_shares_op.hpp:33
Definition: feldman.hpp:37
shamir_sss< Group > base_type
Definition: feldman.hpp:38
public_secret_sss< shamir_sss< Group > > base_type
Definition: feldman.hpp:90
feldman_sss< Group > scheme_type
Definition: feldman.hpp:91
scheme_type::indexes_type indexes_type
Definition: feldman.hpp:93
public_secret_sss(const PublicShares &public_shares, const indexes_type &indexes)
Definition: feldman.hpp:104
public_secret_sss(PublicShareIt first, PublicShareIt last)
Definition: feldman.hpp:100
public_secret_sss(PublicShareIt first, PublicShareIt last, const indexes_type &indexes)
Definition: feldman.hpp:109
public_secret_sss(const PublicShares &public_shares)
Definition: feldman.hpp:96
scheme_type::public_element_type public_secret_type
Definition: feldman.hpp:92
Definition: public_secret_sss.hpp:33
scheme_type::indexed_public_element_type public_share_type
Definition: feldman.hpp:45
public_share_sss(std::size_t i)
Definition: feldman.hpp:49
public_share_sss< shamir_sss< Group > > base_type
Definition: feldman.hpp:43
public_share_sss(std::size_t i, const typename public_share_type::second_type &ps)
Definition: feldman.hpp:55
feldman_sss< Group > scheme_type
Definition: feldman.hpp:44
public_share_sss(const public_share_type &in_public_share)
Definition: feldman.hpp:52
void update(const typename scheme_type::public_coeff_type &public_coeff, std::size_t exp)
Definition: feldman.hpp:61
Definition: public_share_sss.hpp:33
reconstruct_public_secret_op< shamir_sss< Group > > base_type
Definition: feldman.hpp:204
static void update(internal_accumulator_type &acc, const public_share_type &public_share)
Definition: feldman.hpp:216
static public_secret_type process(internal_accumulator_type &acc)
Definition: feldman.hpp:220
public_share_sss< scheme_type > public_share_type
Definition: feldman.hpp:206
public_secret_sss< scheme_type > public_secret_type
Definition: feldman.hpp:207
feldman_sss< Group > scheme_type
Definition: feldman.hpp:205
std::pair< typename scheme_type::indexes_type, std::set< public_share_type > > internal_accumulator_type
Definition: feldman.hpp:209
Definition: reconstruct_public_secret_op.hpp:33
std::pair< typename scheme_type::indexes_type, std::set< share_type > > internal_accumulator_type
Definition: feldman.hpp:231
secret_sss< scheme_type > secret_type
Definition: feldman.hpp:230
static result_type process(internal_accumulator_type &acc)
Definition: feldman.hpp:242
reconstruct_secret_op< shamir_sss< Group > > base_type
Definition: feldman.hpp:227
share_sss< scheme_type > share_type
Definition: feldman.hpp:229
feldman_sss< Group > scheme_type
Definition: feldman.hpp:228
static void init_accumulator()
Definition: feldman.hpp:235
static void update(internal_accumulator_type &acc, const share_type &share)
Definition: feldman.hpp:238
Definition: reconstruct_secret_op.hpp:33
feldman_sss< Group > scheme_type
Definition: feldman.hpp:117
secret_sss(ShareIt first, ShareIt last)
Definition: feldman.hpp:126
secret_sss(const Shares &shares, const indexes_type &indexes)
Definition: feldman.hpp:130
secret_sss< shamir_sss< Group > > base_type
Definition: feldman.hpp:116
scheme_type::private_element_type secret_type
Definition: feldman.hpp:118
scheme_type::indexes_type indexes_type
Definition: feldman.hpp:119
secret_sss(ShareIt first, ShareIt last, const indexes_type &indexes)
Definition: feldman.hpp:134
secret_sss(const Shares &shares)
Definition: feldman.hpp:122
Definition: secret_sss.hpp:33
Definition: shamir.hpp:58
share_sss(std::size_t i, const typename share_type::second_type &s)
Definition: feldman.hpp:84
scheme_type::indexed_private_element_type share_type
Definition: feldman.hpp:74
share_sss(const share_type &in_share)
Definition: feldman.hpp:81
share_sss(std::size_t i)
Definition: feldman.hpp:78
feldman_sss< Group > scheme_type
Definition: feldman.hpp:73
share_sss< shamir_sss< Group > > base_type
Definition: feldman.hpp:72
Definition: share_sss.hpp:35
std::pair< std::size_t, private_element_type > indexed_private_element_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:49
typename Group::curve_type::scalar_field_type::value_type private_element_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:47
std::pair< std::size_t, public_element_type > indexed_public_element_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:50
private_element_type coeff_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:55
public_element_type public_coeff_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:56
typename Group::value_type public_element_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:48
std::set< std::size_t > indexes_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:57
public_share_sss< scheme_type > public_share_type
Definition: feldman.hpp:164
feldman_sss< Group > scheme_type
Definition: feldman.hpp:163
static void _init_accumulator(InternalAccumulator &acc, std::size_t i)
Definition: feldman.hpp:170
static bool _process(const InternalAccumulator &acc, const PublicShare &verified_public_share)
Definition: feldman.hpp:181
static result_type process(const internal_accumulator_type &acc, const public_share_type &verified_public_share)
Definition: feldman.hpp:195
static void _update(InternalAccumulator &acc, std::size_t exp, const typename Scheme::public_coeff_type &public_coeff)
Definition: feldman.hpp:175
public_share_type internal_accumulator_type
Definition: feldman.hpp:165
static void update(internal_accumulator_type &acc, std::size_t exp, const typename scheme_type::public_coeff_type &public_coeff)
Definition: feldman.hpp:190
static void init_accumulator(internal_accumulator_type &acc, std::size_t i)
Definition: feldman.hpp:186
Definition: verify_share_op.hpp:33