wong_resharing.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_WONG_RESHARING_DKG_HPP
27 #define CRYPTO3_PUBKEY_WONG_RESHARING_DKG_HPP
28 
29 #include <nil/crypto3/pubkey/detail/dkg/pedersen.hpp>
30 
31 namespace nil {
32  namespace crypto3 {
33  namespace pubkey {
34  namespace detail {
35  //
36  // "Verifiable Secret Redistribution for Threshold Signing Schemes", by T. Wong et al.
37  // https://www.cs.cmu.edu/~wing/publications/Wong-Wing02b.pdf
38  //
39  template<typename Group>
40  struct wong_resharing : pedersen_dkg<Group> {
42 
45  typedef typename base_type::private_elements_type private_elements_type;
46  typedef typename base_type::indexed_private_elements_type indexed_private_elements_type;
47 
48  //===========================================================================
49  // implicitly ordered in/out
50 
51  template<typename OldPublicSharesRange,
52  typename = typename std::enable_if<
53  std::is_same<public_element_type, typename OldPublicSharesRange::value_type>::value,
54  bool>::type>
55  static inline bool verify_old_secret(const private_element_type &old_secret,
56  const OldPublicSharesRange &old_public_shares) {
57  BOOST_RANGE_CONCEPT_ASSERT((boost::SinglePassRangeConcept<const OldPublicSharesRange>));
58 
59  return verify_old_secret(base_type::get_public_element(old_secret), old_public_shares);
60  }
61 
62  template<typename OldPublicSharesRange,
63  typename = typename std::enable_if<
64  std::is_same<public_element_type, typename OldPublicSharesRange::value_type>::value,
65  bool>::type>
66  static inline bool verify_old_secret(const public_element_type &old_public_secret,
67  const OldPublicSharesRange &old_public_shares) {
68  BOOST_RANGE_CONCEPT_ASSERT((boost::SinglePassRangeConcept<const OldPublicSharesRange>));
69 
70  std::size_t shares_len = std::distance(old_public_shares.begin(), old_public_shares.end());
71  public_element_type temp = public_element_type::zero();
72  std::size_t i = 1;
73 
74  for (const auto &gs_i : old_public_shares) {
75  temp = temp + gs_i * base_type::eval_basis_poly(shares_len, i++);
76  }
77  return old_public_secret == temp;
78  }
79 
80  //===========================================================================
81  // explicitly ordered in/out
82 
83  template<typename OldPublicSharesContainer,
84  typename = typename std::enable_if<
85  std::is_integral<typename OldPublicSharesContainer::key_type>::value &&
86  std::is_same<public_element_type,
87  typename OldPublicSharesContainer::mapped_type>::value,
88  bool>::type>
89  static inline bool verify_old_secret(const private_element_type &old_secret,
90  const OldPublicSharesContainer &old_public_shares) {
91  BOOST_RANGE_CONCEPT_ASSERT((boost::UniqueAssociativeContainer<const OldPublicSharesContainer>));
92  BOOST_RANGE_CONCEPT_ASSERT((boost::PairAssociativeContainer<const OldPublicSharesContainer>));
93 
94  return verify_old_secret(base_type::get_public_element(old_secret), old_public_shares);
95  }
96 
97  template<typename OldPublicSharesContainer,
98  typename = typename std::enable_if<
99  std::is_integral<typename OldPublicSharesContainer::key_type>::value &&
100  std::is_same<public_element_type,
101  typename OldPublicSharesContainer::mapped_type>::value,
102  bool>::type>
103  static inline bool verify_old_secret(const public_element_type &old_public_secret,
104  const OldPublicSharesContainer &old_public_shares) {
105  BOOST_RANGE_CONCEPT_ASSERT((boost::UniqueAssociativeContainer<const OldPublicSharesContainer>));
106  BOOST_RANGE_CONCEPT_ASSERT((boost::PairAssociativeContainer<const OldPublicSharesContainer>));
107 
108  std::size_t shares_len = std::distance(old_public_shares.begin(), old_public_shares.end());
109  public_element_type temp = public_element_type::zero();
110 
111  for (const auto &[i, gs_i] : old_public_shares) {
112  temp = temp + gs_i * base_type::eval_basis_poly(shares_len, i);
113  }
114  return old_public_secret == temp;
115  }
116 
117  //===========================================================================
118  // general functions
119 
120  static inline private_elements_type get_new_poly(private_element_type old_share, std::size_t new_t,
121  std::size_t new_n) {
122  assert(check_t(new_t, new_n));
123 
124  return get_poly(new_t);
125  }
126 
127  // TODO: add custom random generation
129  std::size_t new_t) {
130  assert(new_t > 0);
131 
132  private_elements_type coeffs;
133 
134  coeffs.emplace_back(old_share);
135  for (std::size_t i = 1; i < new_t; i++) {
136  coeffs.emplace_back(algebra::random_element<scalar_field_type>());
137  }
138  return coeffs;
139  }
140  };
141  } // namespace detail
142  } // namespace pubkey
143  } // namespace crypto3
144 } // namespace nil
145 
146 #endif
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
Definition: pair.hpp:31
Definition: wong_resharing.hpp:40
pedersen_dkg< Group > base_type
Definition: wong_resharing.hpp:41
base_type::private_elements_type private_elements_type
Definition: wong_resharing.hpp:45
static bool verify_old_secret(const private_element_type &old_secret, const OldPublicSharesRange &old_public_shares)
Definition: wong_resharing.hpp:55
static bool verify_old_secret(const public_element_type &old_public_secret, const OldPublicSharesRange &old_public_shares)
Definition: wong_resharing.hpp:66
base_type::public_element_type public_element_type
Definition: wong_resharing.hpp:44
static bool verify_old_secret(const private_element_type &old_secret, const OldPublicSharesContainer &old_public_shares)
Definition: wong_resharing.hpp:89
base_type::private_element_type private_element_type
Definition: wong_resharing.hpp:43
static private_elements_type get_new_poly(const private_element_type &old_share, std::size_t new_t)
Definition: wong_resharing.hpp:128
base_type::indexed_private_elements_type indexed_private_elements_type
Definition: wong_resharing.hpp:46
static bool verify_old_secret(const public_element_type &old_public_secret, const OldPublicSharesContainer &old_public_shares)
Definition: wong_resharing.hpp:103
static private_elements_type get_new_poly(private_element_type old_share, std::size_t new_t, std::size_t new_n)
Definition: wong_resharing.hpp:120
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/pedersen.hpp:40
static basic_policy::private_element_type eval_basis_poly(const typename basic_policy::indexes_type &indexes, std::size_t i)
Definition: shamir.hpp:69
static coeffs_type get_poly(std::size_t t, std::size_t n)
Definition: shamir.hpp:88
typename Group::curve_type::scalar_field_type::value_type private_element_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:47
typename Group::value_type public_element_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:48
static public_element_type get_public_element(const private_element_type &e)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:90