26 #ifndef CRYPTO3_PUBKEY_WEIGHTED_SHAMIR_SSS_HPP
27 #define CRYPTO3_PUBKEY_WEIGHTED_SHAMIR_SSS_HPP
34 template<
typename Group>
40 template<
typename Group>
46 typedef typename public_share_type::first_type
index_type;
47 typedef typename public_share_type::second_type
value_type;
52 public_share_sss(std::size_t i, std::size_t w, std::size_t threshold_number) : t(threshold_number) {
53 public_share.first = i;
54 assert(scheme_type::check_participant_index(get_index()));
55 assert(scheme_type::check_weight(i, w));
56 for (std::size_t j = 1; j <= w; ++j) {
57 public_share.second.emplace_back(i * t + j);
58 assert(indexes.emplace(public_share.second.back().get_index()).second);
62 template<
typename PartPublicShares>
63 public_share_sss(std::size_t i, std::size_t threshold_number,
const PartPublicShares &i_public_shares) :
64 public_share_sss(i, threshold_number, std::cbegin(i_public_shares), std::cend(i_public_shares)) {
67 template<
typename PartPublicShareIt>
68 public_share_sss(
const std::size_t i, std::size_t threshold_number, PartPublicShareIt first,
69 PartPublicShareIt last) :
71 public_share.first = i;
72 assert(scheme_type::check_participant_index(get_index()));
73 for (
auto iter = first; iter != last; ++iter) {
74 public_share.second.emplace_back(*iter);
75 assert(indexes.emplace(public_share.second.back().get_index()).second);
80 return public_share.first;
84 return public_share.second;
88 return public_share.second;
100 return std::size(indexes);
104 return this->public_share == other.public_share;
108 return this->get_index() < other.get_index();
111 inline part_public_share_type
113 auto confirmed_indexes = scheme_type::get_indexes(confirmed_weights, t);
116 for (
const auto &public_share_j : public_share.second) {
117 part_share = part_share +
118 public_share_j.get_value() *
119 scheme_type::eval_basis_poly(confirmed_indexes, public_share_j.get_index());
127 indexes_type indexes;
128 public_share_type public_share;
131 template<
typename Group>
135 typedef std::pair<std::size_t, std::vector<part_share_type>>
share_type;
143 share_sss(std::size_t i, std::size_t w, std::size_t threshold_number) : t(threshold_number) {
145 assert(scheme_type::check_participant_index(get_index()));
146 assert(scheme_type::check_weight(i, w));
147 for (std::size_t j = 1; j <= w; ++j) {
148 share.second.emplace_back(i * t + j);
149 assert(indexes.emplace(share.second.back().get_index()).second);
174 return std::size(indexes);
180 return To(share.first, t, share.second);
184 return this->share == other.share;
188 return this->get_index() < other.get_index();
195 for (
auto &share_j : share.second) {
196 share_j.update(coeff, exp);
201 auto confirmed_indexes = scheme_type::get_indexes(confirmed_weights, t);
204 for (
const auto &share_j : share.second) {
205 part_share = part_share + share_j.get_value() * scheme_type::eval_basis_poly(
206 confirmed_indexes, share_j.get_index());
214 indexes_type indexes;
218 template<
typename Group>
225 template<
typename Shares>
229 template<
typename ShareIt>
233 template<
typename Shares>
235 secret_sss(std::cbegin(shares), std::cend(shares), indexes) {
238 template<
typename ShareIt>
248 return this->secret == other.secret;
252 template<
typename ShareIt,
253 typename std::enable_if<
254 std::is_same<
typename std::remove_cv<
typename std::remove_reference<
255 typename std::iterator_traits<ShareIt>::value_type>::type>::type,
259 BOOST_CONCEPT_ASSERT((boost::InputIteratorConcept<ShareIt>));
262 for (
auto iter = first; iter != last; iter++) {
263 std::copy(std::cbegin(iter->get_value()), std::cend(iter->get_value()),
264 std::back_inserter(_shares));
268 scheme_type::get_indexes(std::cbegin(_shares), std::cend(_shares)));
271 template<
typename ShareIt,
272 typename std::enable_if<
273 std::is_same<
typename std::remove_cv<
typename std::remove_reference<
274 typename std::iterator_traits<ShareIt>::value_type>::type>::type,
275 typename share_sss<scheme_type>::part_share_type>::value,
277 static inline secret_type
reconstruct_secret(ShareIt first, ShareIt last,
const indexes_type &indexes) {
278 BOOST_CONCEPT_ASSERT((boost::InputIteratorConcept<ShareIt>));
280 secret_type secret = secret_type::zero();
281 for (
auto it = first; it != last; it++) {
282 secret = secret + it->get_value() * scheme_type::eval_basis_poly(indexes, it->get_index());
291 template<
typename Group>
301 assert(n == std::distance(std::cbegin(weights), std::cend(weights)));
302 assert(scheme_type::check_threshold_value(t, n));
304 for (
const auto &w_i : weights) {
305 acc.emplace_back(w_i.first, w_i.second, t);
311 for (
auto shares_iter = std::begin(acc); shares_iter != std::end(acc); ++shares_iter) {
312 shares_iter->update(coeff, exp);
321 template<
typename Group>
334 acc.emplace_back(share);
std::enable_if<!boost::accumulators::detail::is_accumulator_set< OutputIterator >::value, OutputIterator >::type reconstruct_secret(InputIterator first, InputIterator last, OutputIterator out)
Reconstruct secret using passed shares.
Definition: reconstruct_secret.hpp:69
shares_type internal_accumulator_type
Definition: weighted_shamir.hpp:296
share_sss< scheme_type > share_type
Definition: weighted_shamir.hpp:294
static void update(internal_accumulator_type &acc, std::size_t exp, const typename scheme_type::coeff_type &coeff)
Definition: weighted_shamir.hpp:309
weighted_shamir_sss< Group > scheme_type
Definition: weighted_shamir.hpp:293
std::vector< share_type > shares_type
Definition: weighted_shamir.hpp:295
static void init_accumulator(internal_accumulator_type &acc, std::size_t n, std::size_t t, const typename scheme_type::weights_type &weights)
Definition: weighted_shamir.hpp:299
shares_type result_type
Definition: weighted_shamir.hpp:297
static result_type process(internal_accumulator_type &acc)
Definition: weighted_shamir.hpp:316
Definition: deal_shares_op.hpp:33
Definition: shamir.hpp:133
std::size_t get_threshold_number() const
Definition: weighted_shamir.hpp:95
const value_type & get_value() const
Definition: weighted_shamir.hpp:83
weighted_shamir_sss< Group > scheme_type
Definition: weighted_shamir.hpp:42
public_share_sss< shamir_sss< Group > > part_public_share_type
Definition: weighted_shamir.hpp:43
part_public_share_type to_shamir(const typename scheme_type::weights_type &confirmed_weights) const
Definition: weighted_shamir.hpp:112
std::size_t get_weight() const
Definition: weighted_shamir.hpp:99
const data_type & get_data() const
Definition: weighted_shamir.hpp:87
std::pair< std::size_t, std::vector< part_public_share_type > > public_share_type
Definition: weighted_shamir.hpp:44
public_share_sss(const std::size_t i, std::size_t threshold_number, PartPublicShareIt first, PartPublicShareIt last)
Definition: weighted_shamir.hpp:68
public_share_type::first_type index_type
Definition: weighted_shamir.hpp:46
bool operator<(const public_share_sss &other) const
Definition: weighted_shamir.hpp:107
public_share_type data_type
Definition: weighted_shamir.hpp:48
public_share_sss(std::size_t i, std::size_t threshold_number, const PartPublicShares &i_public_shares)
Definition: weighted_shamir.hpp:63
bool operator==(const public_share_sss &other) const
Definition: weighted_shamir.hpp:103
public_share_sss(std::size_t i, std::size_t w, std::size_t threshold_number)
Definition: weighted_shamir.hpp:52
public_share_sss()=default
public_share_type::second_type value_type
Definition: weighted_shamir.hpp:47
const indexes_type & get_indexes() const
Definition: weighted_shamir.hpp:91
scheme_type::indexes_type indexes_type
Definition: weighted_shamir.hpp:45
index_type get_index() const
Definition: weighted_shamir.hpp:79
Definition: public_share_sss.hpp:33
share_sss< scheme_type > share_type
Definition: weighted_shamir.hpp:324
static void update(internal_accumulator_type &acc, const share_type &share)
Definition: weighted_shamir.hpp:333
secret_sss< scheme_type > secret_type
Definition: weighted_shamir.hpp:325
static void init_accumulator()
Definition: weighted_shamir.hpp:330
std::vector< share_type > internal_accumulator_type
Definition: weighted_shamir.hpp:326
secret_type result_type
Definition: weighted_shamir.hpp:327
weighted_shamir_sss< Group > scheme_type
Definition: weighted_shamir.hpp:323
static result_type process(internal_accumulator_type &acc)
Definition: weighted_shamir.hpp:337
Definition: reconstruct_secret_op.hpp:33
secret_type value_type
Definition: weighted_shamir.hpp:223
const value_type & get_value() const
Definition: weighted_shamir.hpp:243
secret_sss(const Shares &shares)
Definition: weighted_shamir.hpp:226
secret_sss(const Shares &shares, const indexes_type &indexes)
Definition: weighted_shamir.hpp:234
scheme_type::indexes_type indexes_type
Definition: weighted_shamir.hpp:222
scheme_type::private_element_type secret_type
Definition: weighted_shamir.hpp:221
bool operator==(const secret_sss &other) const
Definition: weighted_shamir.hpp:247
weighted_shamir_sss< Group > scheme_type
Definition: weighted_shamir.hpp:220
secret_sss(ShareIt first, ShareIt last, const indexes_type &indexes)
Definition: weighted_shamir.hpp:239
secret_sss(ShareIt first, ShareIt last)
Definition: weighted_shamir.hpp:230
Definition: secret_sss.hpp:33
Definition: shamir.hpp:58
Definition: shamir.hpp:180
void update(const typename scheme_type::coeff_type &coeff, std::size_t exp)
Definition: weighted_shamir.hpp:194
share_type::second_type value_type
Definition: weighted_shamir.hpp:138
share_sss< shamir_sss< Group > > part_share_type
Definition: weighted_shamir.hpp:134
weighted_shamir_sss< Group > scheme_type
Definition: weighted_shamir.hpp:133
share_sss(std::size_t i, std::size_t w, std::size_t threshold_number)
Definition: weighted_shamir.hpp:143
share_type::first_type index_type
Definition: weighted_shamir.hpp:137
scheme_type::indexes_type indexes_type
Definition: weighted_shamir.hpp:136
bool operator<(const share_sss &other) const
Definition: weighted_shamir.hpp:187
const data_type & get_data() const
Definition: weighted_shamir.hpp:161
part_share_type to_shamir(const typename scheme_type::weights_type &confirmed_weights) const
Definition: weighted_shamir.hpp:200
bool operator==(const share_sss &other) const
Definition: weighted_shamir.hpp:183
index_type get_index() const
Definition: weighted_shamir.hpp:153
const indexes_type & get_indexes() const
Definition: weighted_shamir.hpp:165
std::pair< std::size_t, std::vector< part_share_type > > share_type
Definition: weighted_shamir.hpp:135
share_type data_type
Definition: weighted_shamir.hpp:139
std::size_t get_threshold_number() const
Definition: weighted_shamir.hpp:169
std::size_t get_weight() const
Definition: weighted_shamir.hpp:173
const value_type & get_value() const
Definition: weighted_shamir.hpp:157
Definition: share_sss.hpp:35
typename Group::curve_type::scalar_field_type::value_type private_element_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:47
private_element_type coeff_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:55
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
Definition: weighted_basic_policy.hpp:37
std::map< std::size_t, std::size_t > weights_type
Definition: weighted_basic_policy.hpp:45
Definition: weighted_shamir.hpp:35
sss_weighted_basic_policy< Group > basic_policy
Definition: weighted_shamir.hpp:36
shamir_sss< Group > base_type
Definition: weighted_shamir.hpp:37