pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2020 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020 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_PEDERSEN_DKG_HPP
27 #define CRYPTO3_PUBKEY_PEDERSEN_DKG_HPP
28 
31 
32 namespace nil {
33  namespace crypto3 {
34  namespace pubkey {
35  //
36  // "A threshold cryptosystem without a trusted party" by Torben Pryds Pedersen.
37  // https://dl.acm.org/citation.cfm?id=1754929
38  //
39  template<typename Group>
40  struct pedersen_dkg : public feldman_sss<Group> {
42  };
43 
44  template<typename Group>
45  struct public_share_sss<pedersen_dkg<Group>> : public public_share_sss<feldman_sss<Group>> {
49 
50  public_share_sss() = default;
51 
52  public_share_sss(std::size_t i) : base_type(i) {
53  }
54 
55  public_share_sss(const public_share_type &in_public_share) : base_type(in_public_share) {
56  }
57 
58  public_share_sss(std::size_t i, const typename public_share_type::second_type &ps) : base_type(i, ps) {
59  }
60  };
61 
62  template<typename Group>
63  struct share_sss<pedersen_dkg<Group>> : public share_sss<feldman_sss<Group>> {
67 
68  share_sss() = default;
69 
70  share_sss(std::size_t i) : base_type(i) {
71  }
72 
73  share_sss(const share_type &in_share) : base_type(in_share) {
74  }
75 
76  share_sss(std::size_t i, const typename share_type::second_type &s) : base_type(i, s) {
77  }
78 
79  using base_type::update;
80 
81  inline void update(const share_sss &renewing_share) {
82  assert(renewing_share.get_index() == this->share.first);
83 
84  this->share.second = this->share.second + renewing_share.get_value();
85  }
86  };
87 
88  template<typename Group>
89  struct public_secret_sss<pedersen_dkg<Group>> : public public_secret_sss<feldman_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<pedersen_dkg<Group>> : public secret_sss<feldman_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<pedersen_dkg<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 deal_share_op<pedersen_dkg<Group>> {
167 
168  static inline void init_accumulator(internal_accumulator_type &acc, std::size_t i) {
169  acc = internal_accumulator_type(i);
170  }
171 
172  static inline void update(internal_accumulator_type &acc, const share_type &renewing_share) {
173  acc.update(renewing_share);
174  }
175 
176  static inline result_type process(const internal_accumulator_type &acc) {
177  return acc;
178  }
179  };
180 
181  template<typename Group>
182  struct verify_share_op<pedersen_dkg<Group>> : public verify_share_op<feldman_sss<Group>> {
187  typedef bool result_type;
188 
189  static inline void init_accumulator(internal_accumulator_type &acc, std::size_t i) {
190  base_type::_init_accumulator(acc, i);
191  }
192 
193  static inline void update(internal_accumulator_type &acc, std::size_t exp,
194  const typename scheme_type::public_coeff_type &public_coeff) {
195  base_type::template _update<scheme_type>(acc, exp, public_coeff);
196  }
197 
199  const public_share_type &verified_public_share) {
200  return base_type::_process(acc, verified_public_share);
201  }
202  };
203 
204  template<typename Group>
206  : public reconstruct_public_secret_op<shamir_sss<Group>> {
211  typedef std::pair<typename scheme_type::indexes_type, std::set<public_share_type>>
214 
215  public:
216  static inline void init_accumulator() {
217  }
218 
219  static inline void update(internal_accumulator_type &acc, const public_share_type &public_share) {
220  base_type::_update(acc, public_share);
221  }
222 
224  return base_type::template _process<result_type>(acc);
225  }
226  };
227 
228  template<typename Group>
229  struct reconstruct_secret_op<pedersen_dkg<Group>> : public reconstruct_secret_op<shamir_sss<Group>> {
234  typedef std::pair<typename scheme_type::indexes_type, std::set<share_type>> internal_accumulator_type;
236 
237  public:
238  static inline void init_accumulator() {
239  }
240 
241  static inline void update(internal_accumulator_type &acc, const share_type &share) {
242  base_type::_update(acc, share);
243  }
244 
246  return base_type::template _process<result_type>(acc);
247  }
248  };
249  } // namespace pubkey
250  } // namespace crypto3
251 } // namespace nil
252 
253 #endif // CRYPTO3_PUBKEY_PEDERSEN_DKG_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 void update(internal_accumulator_type &acc, const share_type &renewing_share)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:172
share_sss< scheme_type > share_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:164
static result_type process(const internal_accumulator_type &acc)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:176
share_type internal_accumulator_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:165
share_type result_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:166
pedersen_dkg< Group > scheme_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:163
static void init_accumulator(internal_accumulator_type &acc, std::size_t i)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:168
Definition: deal_share_op.hpp:33
shares_type internal_accumulator_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:144
shares_type result_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:145
std::vector< share_type > shares_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:143
static result_type process(internal_accumulator_type &acc)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:156
static void init_accumulator(internal_accumulator_type &acc, std::size_t n, std::size_t t)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:147
share_sss< scheme_type > share_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:142
static void update(internal_accumulator_type &acc, std::size_t exp, const typename scheme_type::coeff_type &coeff)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:151
deal_shares_op< shamir_sss< Group > > base_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:140
pedersen_dkg< Group > scheme_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:141
Definition: deal_shares_op.hpp:33
Definition: feldman.hpp:37
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:40
feldman_sss< Group > base_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:41
scheme_type::indexes_type indexes_type
Definition: feldman.hpp:93
public_secret_sss< feldman_sss< Group > > base_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:90
scheme_type::indexes_type indexes_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:93
public_secret_sss(const PublicShares &public_shares, const indexes_type &indexes)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:104
public_secret_sss(PublicShareIt first, PublicShareIt last)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:100
public_secret_sss(PublicShareIt first, PublicShareIt last, const indexes_type &indexes)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:109
public_secret_sss(const PublicShares &public_shares)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:96
pedersen_dkg< Group > scheme_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:91
scheme_type::public_element_type public_secret_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:92
Definition: public_secret_sss.hpp:33
scheme_type::indexed_public_element_type public_share_type
Definition: feldman.hpp:45
pedersen_dkg< Group > scheme_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:47
public_share_sss< feldman_sss< Group > > base_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:46
public_share_sss(std::size_t i, const typename public_share_type::second_type &ps)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:58
scheme_type::indexed_public_element_type public_share_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:48
public_share_sss(const public_share_type &in_public_share)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:55
public_share_sss(std::size_t i)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:52
Definition: public_share_sss.hpp:33
static void init_accumulator()
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:216
public_secret_type result_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:213
public_secret_sss< scheme_type > public_secret_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:210
static result_type process(internal_accumulator_type &acc)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:223
static void update(internal_accumulator_type &acc, const public_share_type &public_share)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:219
reconstruct_public_secret_op< shamir_sss< Group > > base_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:207
pedersen_dkg< Group > scheme_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:208
std::pair< typename scheme_type::indexes_type, std::set< public_share_type > > internal_accumulator_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:212
public_share_sss< scheme_type > public_share_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:209
Definition: reconstruct_public_secret_op.hpp:33
pedersen_dkg< Group > scheme_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:231
share_sss< scheme_type > share_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:232
secret_sss< scheme_type > secret_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:233
reconstruct_secret_op< shamir_sss< Group > > base_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:230
secret_type result_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:235
static result_type process(internal_accumulator_type &acc)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:245
std::pair< typename scheme_type::indexes_type, std::set< share_type > > internal_accumulator_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:234
static void update(internal_accumulator_type &acc, const share_type &share)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:241
static void init_accumulator()
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:238
Definition: reconstruct_secret_op.hpp:33
scheme_type::indexes_type indexes_type
Definition: feldman.hpp:119
secret_sss(const Shares &shares, const indexes_type &indexes)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:130
secret_sss(ShareIt first, ShareIt last)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:126
scheme_type::indexes_type indexes_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:119
secret_sss< feldman_sss< Group > > base_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:116
pedersen_dkg< Group > scheme_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:117
secret_sss(ShareIt first, ShareIt last, const indexes_type &indexes)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:134
secret_sss(const Shares &shares)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:122
scheme_type::private_element_type secret_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:118
Definition: secret_sss.hpp:33
scheme_type::indexed_private_element_type share_type
Definition: feldman.hpp:74
share_sss(const share_type &in_share)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:73
scheme_type::indexed_private_element_type share_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:66
share_sss(std::size_t i, const typename share_type::second_type &s)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:76
void update(const share_sss &renewing_share)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:81
pedersen_dkg< Group > scheme_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:65
share_sss< feldman_sss< Group > > base_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:64
share_sss(std::size_t i)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:70
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
static void update(internal_accumulator_type &acc, std::size_t exp, const typename scheme_type::public_coeff_type &public_coeff)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:193
public_share_sss< scheme_type > public_share_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:185
verify_share_op< feldman_sss< Group > > base_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:183
bool result_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:187
pedersen_dkg< Group > scheme_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:184
static result_type process(const internal_accumulator_type &acc, const public_share_type &verified_public_share)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:198
public_share_type internal_accumulator_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:186
static void init_accumulator(internal_accumulator_type &acc, std::size_t i)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:189
Definition: verify_share_op.hpp:33