|
| 1 | +//---------------------------------------------------------------------------// |
| 2 | +// Copyright (c) 2021 Mikhail Komarov <[email protected]> |
| 3 | +// Copyright (c) 2021 Ilias Khairullin <[email protected]> |
| 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_DECRYPT_HPP |
| 27 | +#define CRYPTO3_PUBKEY_DECRYPT_HPP |
| 28 | + |
| 29 | +#include <nil/crypto3/pubkey/algorithm/pubkey.hpp> |
| 30 | + |
| 31 | +#include <nil/crypto3/pubkey/pubkey_value.hpp> |
| 32 | +#include <nil/crypto3/pubkey/pubkey_state.hpp> |
| 33 | + |
| 34 | +#include <nil/crypto3/pubkey/modes/isomorphic.hpp> |
| 35 | + |
| 36 | +#include <nil/crypto3/pubkey/operations/decrypt_op.hpp> |
| 37 | + |
| 38 | +namespace nil { |
| 39 | + namespace crypto3 { |
| 40 | + namespace pubkey { |
| 41 | + template<typename Scheme> |
| 42 | + using decryption_init_params_type = typename decrypt_op<Scheme>::init_params_type; |
| 43 | + } |
| 44 | + template<typename Scheme, typename Mode = pubkey::modes::isomorphic<Scheme>, |
| 45 | + typename ProcessingMode = typename Mode::decryption_policy, typename InputIterator, |
| 46 | + typename PubkeyAccumulator = pubkey::pubkey_accumulator_set<ProcessingMode>, |
| 47 | + typename StreamSchemeImpl = pubkey::detail::value_pubkey_impl<PubkeyAccumulator>, |
| 48 | + typename SchemeImpl = pubkey::detail::range_pubkey_impl<StreamSchemeImpl>> |
| 49 | + SchemeImpl decrypt(InputIterator first, InputIterator last, |
| 50 | + const pubkey::decryption_init_params_type<Scheme> &init_params) { |
| 51 | + return SchemeImpl(first, last, PubkeyAccumulator(init_params)); |
| 52 | + } |
| 53 | + |
| 54 | + template<typename Scheme, typename Mode = pubkey::modes::isomorphic<Scheme>, |
| 55 | + typename ProcessingMode = typename Mode::decryption_policy, typename SinglePassRange, |
| 56 | + typename PubkeyAccumulator = pubkey::pubkey_accumulator_set<ProcessingMode>, |
| 57 | + typename StreamSchemeImpl = pubkey::detail::value_pubkey_impl<PubkeyAccumulator>, |
| 58 | + typename SchemeImpl = pubkey::detail::range_pubkey_impl<StreamSchemeImpl>> |
| 59 | + SchemeImpl decrypt(const SinglePassRange &range, |
| 60 | + const pubkey::decryption_init_params_type<Scheme> &init_params) { |
| 61 | + return SchemeImpl(range, PubkeyAccumulator(init_params)); |
| 62 | + } |
| 63 | + |
| 64 | + template<typename Scheme, typename Mode = pubkey::modes::isomorphic<Scheme>, |
| 65 | + typename ProcessingMode = typename Mode::decryption_policy, typename InputIterator, |
| 66 | + typename OutputAccumulator = pubkey::pubkey_accumulator_set<ProcessingMode>> |
| 67 | + typename std::enable_if<boost::accumulators::detail::is_accumulator_set<OutputAccumulator>::value, |
| 68 | + OutputAccumulator>::type & |
| 69 | + decrypt(InputIterator first, InputIterator last, OutputAccumulator &acc) { |
| 70 | + typedef pubkey::detail::ref_pubkey_impl<OutputAccumulator> StreamSchemeImpl; |
| 71 | + typedef pubkey::detail::range_pubkey_impl<StreamSchemeImpl> SchemeImpl; |
| 72 | + |
| 73 | + return SchemeImpl(first, last, std::forward<OutputAccumulator>(acc)); |
| 74 | + } |
| 75 | + |
| 76 | + template<typename Scheme, typename Mode = pubkey::modes::isomorphic<Scheme>, |
| 77 | + typename ProcessingMode = typename Mode::decryption_policy, typename SinglePassRange, |
| 78 | + typename OutputAccumulator = pubkey::pubkey_accumulator_set<ProcessingMode>> |
| 79 | + typename std::enable_if<boost::accumulators::detail::is_accumulator_set<OutputAccumulator>::value, |
| 80 | + OutputAccumulator>::type & |
| 81 | + decrypt(const SinglePassRange &range, OutputAccumulator &acc) { |
| 82 | + typedef pubkey::detail::ref_pubkey_impl<OutputAccumulator> StreamSchemeImpl; |
| 83 | + typedef pubkey::detail::range_pubkey_impl<StreamSchemeImpl> SchemeImpl; |
| 84 | + |
| 85 | + return SchemeImpl(range, std::forward<OutputAccumulator>(acc)); |
| 86 | + } |
| 87 | + |
| 88 | + template<typename Scheme, typename Mode = pubkey::modes::isomorphic<Scheme>, |
| 89 | + typename ProcessingMode = typename Mode::decryption_policy, typename InputIterator, |
| 90 | + typename OutputIterator> |
| 91 | + OutputIterator decrypt(InputIterator first, InputIterator last, |
| 92 | + const pubkey::decryption_init_params_type<Scheme> &init_params, OutputIterator out) { |
| 93 | + typedef pubkey::pubkey_accumulator_set<ProcessingMode> PubkeyAccumulator; |
| 94 | + |
| 95 | + typedef pubkey::detail::value_pubkey_impl<PubkeyAccumulator> StreamSchemeImpl; |
| 96 | + typedef pubkey::detail::itr_pubkey_impl<StreamSchemeImpl, OutputIterator> SchemeImpl; |
| 97 | + |
| 98 | + return SchemeImpl(first, last, std::move(out), PubkeyAccumulator(init_params)); |
| 99 | + } |
| 100 | + |
| 101 | + template<typename Scheme, typename Mode = pubkey::modes::isomorphic<Scheme>, |
| 102 | + typename ProcessingMode = typename Mode::decryption_policy, typename SinglePassRange, |
| 103 | + typename OutputIterator> |
| 104 | + OutputIterator decrypt(const SinglePassRange &range, |
| 105 | + const pubkey::decryption_init_params_type<Scheme> &init_params, OutputIterator out) { |
| 106 | + typedef pubkey::pubkey_accumulator_set<ProcessingMode> PubkeyAccumulator; |
| 107 | + |
| 108 | + typedef pubkey::detail::value_pubkey_impl<PubkeyAccumulator> StreamSchemeImpl; |
| 109 | + typedef pubkey::detail::itr_pubkey_impl<StreamSchemeImpl, OutputIterator> SchemeImpl; |
| 110 | + |
| 111 | + return SchemeImpl(range, std::move(out), PubkeyAccumulator(init_params)); |
| 112 | + } |
| 113 | + } // namespace crypto3 |
| 114 | +} // namespace nil |
| 115 | + |
| 116 | +#endif // CRYPTO3_PUBKEY_DECRYPT_HPP |
0 commit comments