pubkey/include/nil/crypto3/pubkey/algorithm/verify.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_VERIFY_HPP
27 #define CRYPTO3_PUBKEY_VERIFY_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<verification_policy<Scheme>>::type;
50 
51  template<typename Scheme>
53  typename modes::isomorphic<Scheme>::template bind<pop_verification_policy<Scheme>>::type;
54  } // namespace pubkey
55 
75  template<typename Scheme, typename ProcessingMode = pubkey::pop_verification_processing_mode_default<Scheme>,
76  typename VerificationAccumulator = pubkey::verification_accumulator_set<ProcessingMode>,
77  typename StreamSchemeImpl = pubkey::detail::value_pubkey_impl<VerificationAccumulator>,
78  typename SchemeImpl = pubkey::detail::range_pubkey_impl<StreamSchemeImpl>>
79  SchemeImpl verify(const typename pubkey::public_key<Scheme>::signature_type &proof,
80  const pubkey::public_key<Scheme> &key) {
81  return SchemeImpl(VerificationAccumulator(key, accumulators::signature = proof));
82  }
83 
106  template<typename Scheme, typename InputIterator,
107  typename ProcessingMode = pubkey::verification_processing_mode_default<Scheme>,
108  typename VerificationAccumulator = pubkey::verification_accumulator_set<ProcessingMode>,
109  typename StreamSchemeImpl = pubkey::detail::value_pubkey_impl<VerificationAccumulator>,
110  typename SchemeImpl = pubkey::detail::range_pubkey_impl<StreamSchemeImpl>>
111  SchemeImpl verify(InputIterator first, InputIterator last,
112  const typename pubkey::public_key<Scheme>::signature_type &signature,
113  const pubkey::public_key<Scheme> &key) {
114  return SchemeImpl(first, last, VerificationAccumulator(key, accumulators::signature = signature));
115  }
116 
138  template<typename Scheme, typename SinglePassRange,
139  typename ProcessingMode = pubkey::verification_processing_mode_default<Scheme>,
140  typename VerificationAccumulator = pubkey::verification_accumulator_set<ProcessingMode>,
141  typename StreamSchemeImpl = pubkey::detail::value_pubkey_impl<VerificationAccumulator>,
142  typename SchemeImpl = pubkey::detail::range_pubkey_impl<StreamSchemeImpl>>
143  SchemeImpl verify(const SinglePassRange &range,
144  const typename pubkey::public_key<Scheme>::signature_type &signature,
145  const pubkey::public_key<Scheme> &key) {
146  return SchemeImpl(range, VerificationAccumulator(key, accumulators::signature = signature));
147  }
148 
167  template<typename Scheme, typename InputIterator,
168  typename ProcessingMode = pubkey::verification_processing_mode_default<Scheme>,
169  typename OutputAccumulator = pubkey::verification_accumulator_set<ProcessingMode>>
170  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<OutputAccumulator>::value,
171  OutputAccumulator>::type &
172  verify(InputIterator first, InputIterator last, OutputAccumulator &acc) {
175 
176  return SchemeImpl(first, last, std::forward<OutputAccumulator>(acc));
177  }
178 
196  template<typename Scheme, typename SinglePassRange,
197  typename ProcessingMode = pubkey::verification_processing_mode_default<Scheme>,
198  typename OutputAccumulator = pubkey::verification_accumulator_set<ProcessingMode>>
199  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<OutputAccumulator>::value,
200  OutputAccumulator>::type &
201  verify(const SinglePassRange &range, OutputAccumulator &acc) {
204 
205  return SchemeImpl(range, std::forward<OutputAccumulator>(acc));
206  }
207 
227  template<typename Scheme, typename InputIterator, typename OutputIterator,
228  typename ProcessingMode = pubkey::verification_processing_mode_default<Scheme>>
229  OutputIterator verify(InputIterator first, InputIterator last,
230  const typename pubkey::public_key<Scheme>::signature_type &signature,
231  const pubkey::public_key<Scheme> &key, OutputIterator out) {
232  typedef pubkey::verification_accumulator_set<ProcessingMode> VerificationAccumulator;
233 
236 
237  return SchemeImpl(first, last, std::move(out),
238  VerificationAccumulator(key, accumulators::signature = signature));
239  }
240 
259  template<typename Scheme, typename SinglePassRange, typename OutputIterator,
260  typename ProcessingMode = pubkey::verification_processing_mode_default<Scheme>>
261  OutputIterator verify(const SinglePassRange &range,
262  const typename pubkey::public_key<Scheme>::signature_type &signature,
263  const pubkey::public_key<Scheme> &key, OutputIterator out) {
264  typedef pubkey::verification_accumulator_set<ProcessingMode> VerificationAccumulator;
265 
268 
269  return SchemeImpl(range, std::move(out), VerificationAccumulator(key, accumulators::signature = signature));
270  }
271  } // namespace crypto3
272 } // namespace nil
273 
274 #endif // include guard
SchemeImpl verify(const typename pubkey::public_key< Scheme >::signature_type &proof, const pubkey::public_key< Scheme > &key)
Verification of the proof of possession of the supplied key.
Definition: pubkey/include/nil/crypto3/pubkey/algorithm/verify.hpp:79
boost::accumulators::accumulator_set< typename ProcessingMode::result_type, boost::accumulators::features< accumulators::tag::verify< ProcessingMode > >> verification_accumulator_set
Accumulator set with pre-defined verification accumulator params.
Definition: pubkey_state.hpp:73
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< verification_policy< Scheme > >::type verification_processing_mode_default
Definition: pubkey/include/nil/crypto3/pubkey/algorithm/verify.hpp:49
typename pubkey::modes::isomorphic< Scheme >::pop_verification_policy pop_verification_policy
Definition: pubkey/include/nil/crypto3/pubkey/algorithm/verify.hpp:45
typename pubkey::modes::isomorphic< Scheme >::verification_policy verification_policy
Definition: pubkey/include/nil/crypto3/pubkey/algorithm/verify.hpp:42
typename modes::isomorphic< Scheme >::template bind< pop_verification_policy< Scheme > >::type pop_verification_processing_mode_default
Definition: pubkey/include/nil/crypto3/pubkey/algorithm/verify.hpp:53
Definition: pair.hpp:31
Definition: pubkey_value.hpp:167
Definition: pubkey_value.hpp:49
Definition: isomorphic.hpp:219
Public key - a key that can be published and used to verify the authenticity of the signed document,...
Definition: public_key.hpp:43