stream/include/nil/crypto3/stream/algorithm/decrypt.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation>
3 //
4 // MIT License
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //---------------------------------------------------------------------------//
24 
25 #ifndef CRYPTO3_STREAM_DECRYPT_HPP
26 #define CRYPTO3_STREAM_DECRYPT_HPP
27 
29 
32 
33 namespace nil {
34  namespace crypto3 {
53  template<typename StreamCipher, typename InputIterator, typename KeyIterator, typename OutputIterator>
54  OutputIterator decrypt(InputIterator first, InputIterator last, KeyIterator key_first, KeyIterator key_last,
55  OutputIterator out) {
56 
57  typedef typename StreamCipher::stream_decrypter_type EncryptionMode;
58  typedef typename stream::stream_accumulator<EncryptionMode> CipherAccumulator;
59 
60  typedef stream::detail::value_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
62 
63  return EncrypterImpl(first, last, std::move(out), CiperState(StreamCipher(key_first, key_last)));
64  }
65 
81  template<typename StreamCipher, typename InputIterator,
82  typename OutputAccumulator =
83  typename stream::stream_accumulator<typename StreamCipher::stream_decrypter_type>>
84  OutputAccumulator &decrypt(InputIterator first, InputIterator last, OutputAccumulator &acc) {
85 
86  typedef typename StreamCipher::stream_decrypter_type EncryptionMode;
87  typedef typename stream::stream_accumulator<EncryptionMode> CipherAccumulator;
88 
89  typedef stream::detail::ref_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
91 
92  return EncrypterImpl(first, last, acc);
93  }
94 
109  template<typename StreamCipher, typename SinglePassRange,
110  typename OutputAccumulator =
111  typename stream::stream_accumulator<typename StreamCipher::stream_decrypter_type>>
112  OutputAccumulator &decrypt(const SinglePassRange &r, OutputAccumulator &acc) {
113 
114  typedef typename StreamCipher::stream_decrypter_type EncryptionMode;
115  typedef typename stream::stream_accumulator<EncryptionMode> CipherAccumulator;
116 
117  typedef stream::detail::ref_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
119 
120  return EncrypterImpl(r, acc);
121  }
122 
140  template<typename StreamCipher, typename InputIterator, typename KeyIterator,
141  typename CipherAccumulator =
142  typename stream::stream_accumulator<typename StreamCipher::stream_decrypter_type>>
143  stream::detail::range_cipher_impl<stream::detail::value_cipher_impl<CipherAccumulator>>
144  decrypt(InputIterator first, InputIterator last, KeyIterator key_first, KeyIterator key_last) {
145 
146  typedef stream::detail::value_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
148 
149  return EncrypterImpl(first, last, CipherAccumulator(StreamCipher(key_first, key_last)));
150  }
151 
168  template<typename StreamCipher, typename SinglePassRange, typename KeyRange, typename OutputIterator>
169  OutputIterator decrypt(const SinglePassRange &rng, const KeyRange &key, OutputIterator out) {
170 
171  typedef typename StreamCipher::stream_decrypter_type EncryptionMode;
172  typedef typename stream::stream_accumulator<EncryptionMode> CipherAccumulator;
173 
174  typedef stream::detail::value_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
176 
177  return EncrypterImpl(rng, std::move(out), CipherState(StreamCipher(key)));
178  }
179 
195  template<typename StreamCipher, typename SinglePassRange, typename KeyRange,
196  typename CipherAccumulator =
197  typename stream::stream_accumulator<typename StreamCipher::stream_decrypter_type>>
198  stream::detail::range_cipher_impl<stream::detail::value_cipher_impl<CipherAccumulator>>
199  decrypt(const SinglePassRange &r, const KeyRange &key) {
200 
201  typedef stream::detail::value_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
203 
204  return EncrypterImpl(r, CipherState(StreamCipher(key)));
205  }
206  } // namespace crypto3
207 } // namespace nil
208 
209 #endif // include guard
OutputIterator decrypt(InputIterator first, InputIterator last, KeyInputIterator key_first, KeyInputIterator key_last, OutputIterator out)
Definition: block/include/nil/crypto3/block/algorithm/decrypt.hpp:66
OutputIterator move(const SinglePassRange &rng, OutputIterator result)
Definition: move.hpp:45
boost::accumulators::accumulator_set< digest< ProcessingMode::input_stream_bits >, boost::accumulators::features< accumulators::tag::stream< ProcessingMode > >> stream_accumulator
Cipher state managing container.
Definition: stream/include/nil/crypto3/stream/cipher_state.hpp:49
Definition: pair.hpp:31
Definition: stream/include/nil/crypto3/stream/cipher_value.hpp:161
Definition: stream/include/nil/crypto3/stream/cipher_value.hpp:73
Definition: stream/include/nil/crypto3/stream/cipher_value.hpp:43
Definition: stream/include/nil/crypto3/stream/cipher_value.hpp:58