seek.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_SEEK_HPP
26 #define CRYPTO3_STREAM_SEEK_HPP
27 
29 
32 
33 namespace nil {
34  namespace crypto3 {
51  template<typename StreamCipher, typename InputIterator, typename KeyIterator, typename OutputIterator>
52  OutputIterator seek(InputIterator first, InputIterator last, KeyIterator key_first, KeyIterator key_last,
53  OutputIterator out) {
54 
55  typedef typename StreamCipher::stream_encrypter_type EncryptionMode;
56  typedef typename stream::stream_accumulator<EncryptionMode> CipherAccumulator;
57 
58  typedef stream::detail::value_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
60 
61  return EncrypterImpl(first, last, std::move(out), CiperState(StreamCipher(key_first, key_last)));
62  }
63 
79  template<typename StreamCipher, typename InputIterator,
80  typename OutputAccumulator =
81  typename stream::stream_accumulator<typename StreamCipher::stream_encrypter_type>>
82  OutputAccumulator &seek(InputIterator first, InputIterator last, OutputAccumulator &acc) {
83 
84  typedef typename StreamCipher::stream_encrypter_type EncryptionMode;
85  typedef typename stream::stream_accumulator<EncryptionMode> CipherAccumulator;
86 
87  typedef stream::detail::ref_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
89 
90  return EncrypterImpl(first, last, acc);
91  }
92 
107  template<typename StreamCipher, typename SinglePassRange,
108  typename OutputAccumulator =
109  typename stream::stream_accumulator<typename StreamCipher::stream_encrypter_type>>
110  OutputAccumulator &seek(const SinglePassRange &r, OutputAccumulator &acc) {
111 
112  typedef typename StreamCipher::stream_encrypter_type EncryptionMode;
113  typedef typename stream::stream_accumulator<EncryptionMode> CipherAccumulator;
114 
115  typedef stream::detail::ref_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
117 
118  return EncrypterImpl(r, acc);
119  }
120 
137  template<typename StreamCipher, typename InputIterator, typename KeyIterator,
138  typename CipherAccumulator =
139  typename stream::stream_accumulator<typename StreamCipher::stream_encrypter_type>>
140  stream::detail::range_cipher_impl<stream::detail::value_cipher_impl<CipherAccumulator>>
141  seek(InputIterator first, InputIterator last, KeyIterator key_first, KeyIterator key_last) {
142  typedef stream::detail::value_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
144 
145  return EncrypterImpl(first, last, CipherAccumulator(StreamCipher(key_first, key_last)));
146  }
147 
164  template<typename StreamCipher, typename SinglePassRange, typename KeyRange, typename OutputIterator>
165  OutputIterator seek(const SinglePassRange &rng, const KeyRange &key, OutputIterator out) {
166 
167  typedef typename StreamCipher::stream_encrypter_type EncryptionMode;
168  typedef typename stream::stream_accumulator<EncryptionMode> CipherAccumulator;
169 
170  typedef stream::detail::value_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
172 
173  return EncrypterImpl(rng, std::move(out), CipherState(StreamCipher(key)));
174  }
175 
191  template<typename StreamCipher, typename SinglePassRange, typename KeyRange,
192  typename CipherAccumulator =
193  typename stream::stream_accumulator<typename StreamCipher::stream_encrypter_type>>
194  stream::detail::range_cipher_impl<stream::detail::value_cipher_impl<CipherAccumulator>>
195  seek(const SinglePassRange &r, const KeyRange &key) {
196 
197  typedef stream::detail::value_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
199 
200  return EncrypterImpl(r, CipherState(StreamCipher(key)));
201  }
202  } // namespace crypto3
203 } // namespace nil
204 
205 #endif // include guard
OutputIterator seek(InputIterator first, InputIterator last, KeyIterator key_first, KeyIterator key_last, OutputIterator out)
Definition: seek.hpp:52
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