algorithm/sign.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020-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_SIGN_HPP
27 #define CRYPTO3_PUBKEY_SIGN_HPP
28 
30 
33 
35 
37 
38 namespace nil {
39  namespace crypto3 {
40  namespace pubkey {
41  template<typename Scheme>
43 
44  template<typename Scheme>
46 
47  template<typename Scheme>
49  typename modes::isomorphic<Scheme>::template bind<signing_policy<Scheme>>::type;
50 
51  template<typename Scheme>
53  typename modes::isomorphic<Scheme>::template bind<pop_proving_policy<Scheme>>::type;
54  } // namespace pubkey
55 
73  template<typename Scheme, typename ProcessingMode = pubkey::pop_proving_processing_mode_default<Scheme>,
74  typename SigningAccumulator = pubkey::signing_accumulator_set<ProcessingMode>,
75  typename StreamSchemeImpl = pubkey::detail::value_pubkey_impl<SigningAccumulator>,
76  typename SchemeImpl = pubkey::detail::range_pubkey_impl<StreamSchemeImpl>>
77  SchemeImpl sign(const pubkey::private_key<Scheme> &key) {
78  return SchemeImpl(SigningAccumulator(key));
79  }
80 
101  template<typename Scheme, typename InputIterator,
102  typename ProcessingMode = pubkey::signing_processing_mode_default<Scheme>,
103  typename SigningAccumulator = pubkey::signing_accumulator_set<ProcessingMode>,
104  typename StreamSchemeImpl = pubkey::detail::value_pubkey_impl<SigningAccumulator>,
105  typename SchemeImpl = pubkey::detail::range_pubkey_impl<StreamSchemeImpl>>
106  SchemeImpl sign(InputIterator first, InputIterator last, const pubkey::private_key<Scheme> &key) {
107  return SchemeImpl(first, last, SigningAccumulator(key));
108  }
109 
129  template<typename Scheme, typename SinglePassRange,
130  typename ProcessingMode = pubkey::signing_processing_mode_default<Scheme>,
131  typename SigningAccumulator = pubkey::signing_accumulator_set<ProcessingMode>,
132  typename StreamSchemeImpl = pubkey::detail::value_pubkey_impl<SigningAccumulator>,
133  typename SchemeImpl = pubkey::detail::range_pubkey_impl<StreamSchemeImpl>>
134  SchemeImpl sign(const SinglePassRange &range, const pubkey::private_key<Scheme> &key) {
135  return SchemeImpl(range, SigningAccumulator(key));
136  }
137 
156  template<typename Scheme, typename InputIterator,
157  typename ProcessingMode = pubkey::signing_processing_mode_default<Scheme>,
158  typename OutputAccumulator = pubkey::signing_accumulator_set<ProcessingMode>>
159  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<OutputAccumulator>::value,
160  OutputAccumulator>::type &
161  sign(InputIterator first, InputIterator last, OutputAccumulator &acc) {
164 
165  return SchemeImpl(first, last, std::forward<OutputAccumulator>(acc));
166  }
167 
185  template<typename Scheme, typename SinglePassRange,
186  typename ProcessingMode = pubkey::signing_processing_mode_default<Scheme>,
187  typename OutputAccumulator = pubkey::signing_accumulator_set<ProcessingMode>>
188  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<OutputAccumulator>::value,
189  OutputAccumulator>::type &
190  sign(const SinglePassRange &range, OutputAccumulator &acc) {
193 
194  return SchemeImpl(range, std::forward<OutputAccumulator>(acc));
195  }
196 
215  template<typename Scheme, typename InputIterator, typename OutputIterator,
216  typename ProcessingMode = pubkey::signing_processing_mode_default<Scheme>>
217  OutputIterator sign(InputIterator first, InputIterator last, const pubkey::private_key<Scheme> &key,
218  OutputIterator out) {
219  typedef pubkey::signing_accumulator_set<ProcessingMode> SigningAccumulator;
220 
223 
224  return SchemeImpl(first, last, std::move(out), SigningAccumulator(key));
225  }
226 
244  template<typename Scheme, typename SinglePassRange, typename OutputIterator,
245  typename ProcessingMode = pubkey::signing_processing_mode_default<Scheme>>
246  OutputIterator sign(const SinglePassRange &range, const pubkey::private_key<Scheme> &key, OutputIterator out) {
247  typedef pubkey::signing_accumulator_set<ProcessingMode> SigningAccumulator;
248 
251 
252  return SchemeImpl(range, std::move(out), SigningAccumulator(key));
253  }
254  } // namespace crypto3
255 } // namespace nil
256 
257 #endif // CRYPTO3_PUBKEY_SIGN_HPP
SchemeImpl sign(const pubkey::private_key< Scheme > &key)
Proving of possession of the supplied key.
Definition: algorithm/sign.hpp:77
boost::accumulators::accumulator_set< typename ProcessingMode::result_type, boost::accumulators::features< accumulators::tag::sign< ProcessingMode > >> signing_accumulator_set
Accumulator set with pre-defined signing accumulator params.
Definition: pubkey_state.hpp:59
OutputIterator move(const SinglePassRange &rng, OutputIterator result)
Definition: move.hpp:45
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
typename modes::isomorphic< Scheme >::template bind< pop_proving_policy< Scheme > >::type pop_proving_processing_mode_default
Definition: algorithm/sign.hpp:53
typename modes::isomorphic< Scheme >::template bind< signing_policy< Scheme > >::type signing_processing_mode_default
Definition: algorithm/sign.hpp:49
typename pubkey::modes::isomorphic< Scheme >::pop_proving_policy pop_proving_policy
Definition: algorithm/sign.hpp:45
typename pubkey::modes::isomorphic< Scheme >::signing_policy signing_policy
Definition: algorithm/sign.hpp:42
Definition: pair.hpp:31
Definition: pubkey_value.hpp:167
Definition: pubkey_value.hpp:49
Definition: isomorphic.hpp:219
Private key - a key known only to its owner. Only the user keeping his private key secret guarantees ...
Definition: private_key.hpp:47