isomorphic.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020 Nikita Kaskov <nbering@nil.foundation>
4 // Copyright (c) 2020-2021 Ilias Khairullin <ilias@nil.foundation>
5 //
6 // MIT License
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 //---------------------------------------------------------------------------//
26 
27 #ifndef CRYPTO3_PUBKEY_SCHEME_MODES_HPP
28 #define CRYPTO3_PUBKEY_SCHEME_MODES_HPP
29 
30 #include <type_traits>
31 
41 
42 namespace nil {
43  namespace crypto3 {
44  namespace pubkey {
45  namespace detail {
46  template<typename Scheme>
48  typedef std::size_t size_type;
49 
50  typedef Scheme scheme_type;
51  };
52 
53  template<typename Scheme>
54  struct isomorphic_signing_policy : public isomorphic_policy<Scheme> {
56 
58  typedef void op_type;
59  typedef typename key_type::internal_accumulator_type internal_accumulator_type;
60  typedef typename key_type::signature_type result_type;
61 
62  template<typename... Args>
63  static inline void init_accumulator(const key_type &key, Args &...args) {
64  key.init_accumulator(args...);
65  }
66 
67  template<typename... Args>
68  inline static void update(const key_type &key, Args &...args) {
69  key.update(args...);
70  }
71 
72  template<typename... Args>
73  static inline result_type process(const key_type &key, Args &...args) {
74  return key.sign(args...);
75  }
76  };
77 
78  template<typename Scheme>
81 
83  typedef void op_type;
84  typedef typename key_type::internal_accumulator_type internal_accumulator_type;
85  typedef bool result_type;
86 
87  template<typename... Args>
88  static inline void init_accumulator(const key_type &key, Args &...args) {
89  key.init_accumulator(args...);
90  }
91 
92  template<typename... Args>
93  inline static void update(const key_type &key, Args &...args) {
94  key.update(args...);
95  }
96 
97  template<typename... Args>
98  static inline result_type process(const key_type &key, Args &...args) {
99  return key.verify(args...);
100  }
101  };
102 
103  template<typename Op>
104  struct isomorphic_operation_policy : public isomorphic_policy<typename Op::scheme_type> {
106 
107  typedef void key_type;
108  typedef Op op_type;
109  typedef typename op_type::internal_accumulator_type internal_accumulator_type;
110  typedef typename op_type::result_type result_type;
111 
112  template<typename... Args>
113  static inline void init_accumulator(Args &...args) {
114  op_type::init_accumulator(args...);
115  }
116 
117  template<typename... Args>
118  inline static void update(Args &...args) {
119  op_type::update(args...);
120  }
121 
122  template<typename... Args>
123  static inline result_type process(Args &...args) {
124  return op_type::process(args...);
125  }
126  };
127 
128  template<typename Scheme>
131 
133  typedef void op_type;
134  // TODO: refactor internal_accumulator_type
136  typedef typename key_type::signature_type result_type;
137 
138  template<typename... Args>
139  static inline void init_accumulator(const key_type &key, Args &...args) {
140  }
141 
142  template<typename... Args>
143  inline static void update(const key_type &key, Args &...args) {
144  }
145 
146  template<typename... Args>
147  static inline result_type process(const key_type &key, Args &...args) {
148  return key.pop_prove();
149  }
150  };
151 
152  template<typename Scheme>
155 
157  typedef void op_type;
158  // TODO: refactor internal_accumulator_type
160  typedef bool result_type;
161 
162  template<typename... Args>
163  static inline void init_accumulator(const key_type &key, Args &...args) {
164  }
165 
166  template<typename... Args>
167  inline static void update(const key_type &key, Args &...args) {
168  }
169 
170  template<typename... Args>
171  static inline result_type process(const key_type &key, Args &...args) {
172  return key.pop_verify(args...);
173  }
174  };
175 
176  template<typename Policy>
177  class isomorphic {
178  typedef Policy policy_type;
179 
180  public:
181  typedef typename policy_type::scheme_type scheme_type;
182  typedef typename policy_type::key_type key_type;
183  typedef typename policy_type::op_type op_type;
184  typedef typename policy_type::internal_accumulator_type internal_accumulator_type;
185  typedef typename policy_type::result_type result_type;
186 
187  template<typename... Args>
188  static inline void init_accumulator(Args &...args) {
189  policy_type::init_accumulator(args...);
190  }
191 
192  template<typename... Args>
193  inline static void update(Args &...args) {
194  policy_type::update(args...);
195  }
196 
197  template<typename... Args>
198  inline static result_type process(Args &...args) {
199  return policy_type::process(args...);
200  }
201  };
202  } // namespace detail
203 
204  namespace modes {
218  template<typename Scheme>
219  struct isomorphic {
220  typedef Scheme scheme_type;
221 
238 
239  template<typename Policy>
240  struct bind {
242  };
243  };
244  } // namespace modes
245  } // namespace pubkey
246  } // namespace crypto3
247 } // namespace nil
248 
249 #endif // CRYPTO3_PUBKEY_SCHEME_MODES_HPP
Definition: isomorphic.hpp:177
policy_type::key_type key_type
Definition: isomorphic.hpp:182
policy_type::internal_accumulator_type internal_accumulator_type
Definition: isomorphic.hpp:184
static result_type process(Args &...args)
Definition: isomorphic.hpp:198
static void update(Args &...args)
Definition: isomorphic.hpp:193
policy_type::result_type result_type
Definition: isomorphic.hpp:185
policy_type::op_type op_type
Definition: isomorphic.hpp:183
policy_type::scheme_type scheme_type
Definition: isomorphic.hpp:181
static void init_accumulator(Args &...args)
Definition: isomorphic.hpp:188
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
Definition: pair.hpp:31
isomorphic_policy< typename Op::scheme_type >::scheme_type scheme_type
Definition: isomorphic.hpp:105
static void update(Args &...args)
Definition: isomorphic.hpp:118
op_type::result_type result_type
Definition: isomorphic.hpp:110
op_type::internal_accumulator_type internal_accumulator_type
Definition: isomorphic.hpp:109
static void init_accumulator(Args &...args)
Definition: isomorphic.hpp:113
static result_type process(Args &...args)
Definition: isomorphic.hpp:123
std::size_t size_type
Definition: isomorphic.hpp:48
Scheme scheme_type
Definition: isomorphic.hpp:50
static result_type process(const key_type &key, Args &...args)
Definition: isomorphic.hpp:147
key_type::signature_type result_type
Definition: isomorphic.hpp:136
static void update(const key_type &key, Args &...args)
Definition: isomorphic.hpp:143
private_key< scheme_type > key_type
Definition: isomorphic.hpp:132
bool internal_accumulator_type
Definition: isomorphic.hpp:135
static void init_accumulator(const key_type &key, Args &...args)
Definition: isomorphic.hpp:139
isomorphic_policy< Scheme >::scheme_type scheme_type
Definition: isomorphic.hpp:130
static void init_accumulator(const key_type &key, Args &...args)
Definition: isomorphic.hpp:163
isomorphic_policy< Scheme >::scheme_type scheme_type
Definition: isomorphic.hpp:154
static result_type process(const key_type &key, Args &...args)
Definition: isomorphic.hpp:171
public_key< scheme_type > key_type
Definition: isomorphic.hpp:156
static void update(const key_type &key, Args &...args)
Definition: isomorphic.hpp:167
static void init_accumulator(const key_type &key, Args &...args)
Definition: isomorphic.hpp:63
isomorphic_policy< Scheme >::scheme_type scheme_type
Definition: isomorphic.hpp:55
private_key< scheme_type > key_type
Definition: isomorphic.hpp:57
static result_type process(const key_type &key, Args &...args)
Definition: isomorphic.hpp:73
key_type::signature_type result_type
Definition: isomorphic.hpp:60
key_type::internal_accumulator_type internal_accumulator_type
Definition: isomorphic.hpp:59
static void update(const key_type &key, Args &...args)
Definition: isomorphic.hpp:68
static result_type process(const key_type &key, Args &...args)
Definition: isomorphic.hpp:98
static void update(const key_type &key, Args &...args)
Definition: isomorphic.hpp:93
static void init_accumulator(const key_type &key, Args &...args)
Definition: isomorphic.hpp:88
public_key< scheme_type > key_type
Definition: isomorphic.hpp:82
key_type::internal_accumulator_type internal_accumulator_type
Definition: isomorphic.hpp:84
isomorphic_policy< Scheme >::scheme_type scheme_type
Definition: isomorphic.hpp:80
Definition: isomorphic.hpp:240
detail::isomorphic< Policy > type
Definition: isomorphic.hpp:241
Definition: isomorphic.hpp:219
detail::isomorphic_pop_proving_policy< scheme_type > pop_proving_policy
Definition: isomorphic.hpp:229
detail::isomorphic_operation_policy< deal_shares_op< scheme_type > > shares_dealing_policy
Definition: isomorphic.hpp:231
detail::isomorphic_verification_policy< scheme_type > verification_policy
Definition: isomorphic.hpp:223
detail::isomorphic_operation_policy< reconstruct_secret_op< scheme_type > > secret_reconstructing_policy
Definition: isomorphic.hpp:234
detail::isomorphic_operation_policy< deal_share_op< scheme_type > > share_dealing_policy
Definition: isomorphic.hpp:237
detail::isomorphic_operation_policy< aggregate_op< scheme_type > > aggregation_policy
Definition: isomorphic.hpp:224
detail::isomorphic_operation_policy< aggregate_verify_op< scheme_type > > aggregate_verification_policy
Definition: isomorphic.hpp:226
detail::isomorphic_pop_verification_policy< scheme_type > pop_verification_policy
Definition: isomorphic.hpp:230
detail::isomorphic_operation_policy< verify_share_op< scheme_type > > share_verification_policy
Definition: isomorphic.hpp:232
Scheme scheme_type
Definition: isomorphic.hpp:220
detail::isomorphic_signing_policy< scheme_type > signing_policy
Definition: isomorphic.hpp:222
detail::isomorphic_operation_policy< aggregate_verify_single_msg_op< scheme_type > > single_msg_aggregate_verification_policy
Definition: isomorphic.hpp:228
detail::isomorphic_operation_policy< reconstruct_public_secret_op< scheme_type > > public_secret_reconstructing_policy
Definition: isomorphic.hpp:236
Private key - a key known only to its owner. Only the user keeping his private key secret guarantees ...
Definition: private_key.hpp:47
Public key - a key that can be published and used to verify the authenticity of the signed document,...
Definition: public_key.hpp:43