weighted_basic_policy.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_PUBKEY_SSS_WEIGHTED_BASIC_TYPES_HPP
27 #define CRYPTO3_PUBKEY_SSS_WEIGHTED_BASIC_TYPES_HPP
28 
29 #include <unordered_map>
30 
32 
33 namespace nil {
34  namespace crypto3 {
35  namespace pubkey {
36  template<typename Group>
38  protected:
40 
41  public:
42  //===========================================================================
43  // public weighted secret sharing scheme types
44 
45  using weights_type = std::map<std::size_t, std::size_t>;
46 
47  template<typename Weight>
48  static inline typename std::enable_if<std::is_unsigned<typename Weight::first_type>::value &&
49  std::is_unsigned<typename Weight::second_type>::value,
50  bool>::type
51  check_weight(const Weight &w) {
52  return check_weight(w.first, w.second);
53  }
54 
55  static inline bool check_weight(std::size_t i, std::size_t w) {
56  return base_type::check_participant_index(i) && 0 < w;
57  }
58 
60 
61  static inline typename base_type::indexes_type get_indexes(const weights_type &weights, std::size_t t) {
62  assert(std::size(weights));
63 
64  typename base_type::indexes_type result;
65  for (const auto &weight : weights) {
66  check_weight(weight);
67  for (std::size_t j = 1; j <= weight.second; ++j) {
68  bool emplace_status = result.emplace(weight.first * t + j).second;
69  assert(emplace_status);
70  }
71  }
72 
73  return result;
74  }
75  };
76  } // namespace pubkey
77  } // namespace crypto3
78 } // namespace nil
79 
80 #endif // CRYPTO3_PUBKEY_SSS_WEIGHTED_BASIC_TYPES_HPP
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
Definition: pair.hpp:31
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:43
static indexes_type get_indexes(IndexedElementIt first, IndexedElementIt last)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:95
static bool check_participant_index(std::size_t i)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:72
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
static base_type::indexes_type get_indexes(const weights_type &weights, std::size_t t)
Definition: weighted_basic_policy.hpp:61
static std::enable_if< std::is_unsigned< typename Weight::first_type >::value &&std::is_unsigned< typename Weight::second_type >::value, bool >::type check_weight(const Weight &w)
Definition: weighted_basic_policy.hpp:51
std::map< std::size_t, std::size_t > weights_type
Definition: weighted_basic_policy.hpp:45
sss_basic_policy< Group > base_type
Definition: weighted_basic_policy.hpp:39
static bool check_weight(std::size_t i, std::size_t w)
Definition: weighted_basic_policy.hpp:55