3
* (C) 1999-2007 Jack Lloyd
5
* Botan is released under the Simplified BSD License (see license.txt)
8
#ifndef BOTAN_STREAM_CIPHER_H_
9
#define BOTAN_STREAM_CIPHER_H_
11
#include <botan/sym_algo.h>
18
* Base class for all stream ciphers
20
class BOTAN_PUBLIC_API(2,0) StreamCipher : public SymmetricAlgorithm
23
virtual ~StreamCipher() = default;
26
* Create an instance based on a name
27
* If provider is empty then best available is chosen.
28
* @param algo_spec algorithm name
29
* @param provider provider implementation to use
30
* @return a null pointer if the algo/provider combination cannot be found
32
static std::unique_ptr<StreamCipher>
33
create(const std::string& algo_spec,
34
const std::string& provider = "");
37
* Create an instance based on a name
38
* If provider is empty then best available is chosen.
39
* @param algo_spec algorithm name
40
* @param provider provider implementation to use
41
* Throws a Lookup_Error if the algo/provider combination cannot be found
43
static std::unique_ptr<StreamCipher>
44
create_or_throw(const std::string& algo_spec,
45
const std::string& provider = "");
48
* @return list of available providers for this algorithm, empty if not available
50
static std::vector<std::string> providers(const std::string& algo_spec);
53
* Encrypt or decrypt a message
54
* @param in the plaintext
55
* @param out the byte array to hold the output, i.e. the ciphertext
56
* @param len the length of both in and out in bytes
58
virtual void cipher(const uint8_t in[], uint8_t out[], size_t len) = 0;
61
* Encrypt or decrypt a message
62
* The message is encrypted/decrypted in place.
63
* @param buf the plaintext / ciphertext
64
* @param len the length of buf in bytes
66
void cipher1(uint8_t buf[], size_t len)
67
{ cipher(buf, buf, len); }
71
* The message is encrypted/decrypted in place.
72
* @param inout the plaintext / ciphertext
74
template<typename Alloc>
75
void encipher(std::vector<uint8_t, Alloc>& inout)
76
{ cipher(inout.data(), inout.data(), inout.size()); }
80
* The message is encrypted in place.
81
* @param inout the plaintext / ciphertext
83
template<typename Alloc>
84
void encrypt(std::vector<uint8_t, Alloc>& inout)
85
{ cipher(inout.data(), inout.data(), inout.size()); }
88
* Decrypt a message in place
89
* The message is decrypted in place.
90
* @param inout the plaintext / ciphertext
92
template<typename Alloc>
93
void decrypt(std::vector<uint8_t, Alloc>& inout)
94
{ cipher(inout.data(), inout.data(), inout.size()); }
97
* Resync the cipher using the IV
98
* @param iv the initialization vector
99
* @param iv_len the length of the IV in bytes
101
virtual void set_iv(const uint8_t iv[], size_t iv_len) = 0;
104
* @param iv_len the length of the IV in bytes
105
* @return if the length is valid for this algorithm
107
virtual bool valid_iv_length(size_t iv_len) const { return (iv_len == 0); }
110
* @return a new object representing the same algorithm as *this
112
virtual StreamCipher* clone() const = 0;
115
* Set the offset and the state used later to generate the keystream
116
* @param offset the offset where we begin to generate the keystream
118
virtual void seek(uint64_t offset) = 0;
121
* @return provider information about this implementation. Default is "base",
122
* might also return "sse2", "avx2", "openssl", or some other arbitrary string.
124
virtual std::string provider() const { return "base"; }