pubkey/include/nil/crypto3/pubkey/secret_sharing/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_BASIC_TYPES_HPP
27 #define CRYPTO3_PUBKEY_SSS_BASIC_TYPES_HPP
28 
29 #include <utility>
30 #include <set>
31 #include <type_traits>
32 #include <iterator>
33 
34 #include <boost/assert.hpp>
35 #include <boost/concept_check.hpp>
36 
37 #include <boost/range/concepts.hpp>
38 
39 namespace nil {
40  namespace crypto3 {
41  namespace pubkey {
42  template<typename Group>
44  //===========================================================================
45  // internal secret sharing scheme types
46 
47  using private_element_type = typename Group::curve_type::scalar_field_type::value_type;
48  using public_element_type = typename Group::value_type;
49  using indexed_private_element_type = std::pair<std::size_t, private_element_type>;
50  using indexed_public_element_type = std::pair<std::size_t, public_element_type>;
51 
52  //===========================================================================
53  // public secret sharing scheme types
54 
57  using indexes_type = std::set<std::size_t>;
58 
59  //===========================================================================
60  // general purposes functions
61 
62  static inline bool check_minimal_size(std::size_t size) {
63  return size >= 2;
64  }
65 
66  static inline std::size_t get_min_threshold_value(std::size_t n) {
67  assert(check_minimal_size(n));
68 
69  return (n + 1) / 2;
70  }
71 
72  static inline bool check_participant_index(std::size_t i) {
73  return i > 0;
74  }
75 
76  static inline bool check_participant_index(std::size_t i, std::size_t n) {
77  return check_participant_index(i) && i <= n;
78  }
79 
80  static inline bool check_threshold_value(std::size_t t, std::size_t n) {
81  return check_minimal_size(t) && n >= t && t >= get_min_threshold_value(n);
82  }
83 
84  static inline bool check_exp(std::size_t exp) {
85  return exp >= 0;
86  }
87 
88  //===========================================================================
89  // TODO: refactor
91  return e * public_element_type::one();
92  }
93 
94  template<typename IndexedElementIt>
95  static inline indexes_type get_indexes(IndexedElementIt first, IndexedElementIt last) {
96  BOOST_CONCEPT_ASSERT((boost::InputIteratorConcept<IndexedElementIt>));
97 
98  indexes_type indexes;
99  for (auto it = first; it != last; ++it) {
100  bool emplace_status = indexes.emplace(it->get_index()).second;
101  assert(check_participant_index(it->get_index()) && emplace_status);
102  }
103 
104  return indexes;
105  }
106  };
107  } // namespace pubkey
108  } // namespace crypto3
109 } // namespace nil
110 
111 #endif // CRYPTO3_PUBKEY_SSS_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
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
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
static bool check_exp(std::size_t exp)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:84
std::pair< std::size_t, public_element_type > indexed_public_element_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:50
static bool check_threshold_value(std::size_t t, std::size_t n)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:80
static std::size_t get_min_threshold_value(std::size_t n)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:66
static bool check_minimal_size(std::size_t size)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:62
private_element_type coeff_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:55
static bool check_participant_index(std::size_t i, std::size_t n)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:76
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
static public_element_type get_public_element(const private_element_type &e)
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:90
std::set< std::size_t > indexes_type
Definition: pubkey/include/nil/crypto3/pubkey/secret_sharing/basic_policy.hpp:57