9#include <botan/internal/xor_buf.h>
20 buffer.resize(2 * cipher->block_size());
21 state.resize(cipher->block_size());
33 buffer.resize(2 * cipher->block_size());
34 state.resize(cipher->block_size());
57void CTS_Encryption::encrypt(
const byte block[])
67void CTS_Encryption::write(
const byte input[],
size_t length)
69 size_t copied = std::min<size_t>(buffer.
size() - position, length);
70 buffer.
copy(position, input, copied);
75 if(length == 0)
return;
91 copy_mem(&buffer[0], &buffer[cipher->block_size()], cipher->block_size());
92 position = cipher->block_size();
94 buffer.copy(position, input, length);
103 if(position < cipher->block_size() + 1)
106 xor_buf(state, buffer, cipher->block_size());
107 cipher->encrypt(state);
108 SecureVector<byte> cn = state;
109 clear_mem(&buffer[position], buffer.size() - position);
110 encrypt(&buffer[cipher->block_size()]);
111 send(cn, position - cipher->block_size());
120 buffer.resize(2 * cipher->block_size());
121 state.resize(cipher->block_size());
122 temp.resize(cipher->block_size());
134 buffer.resize(2 * cipher->block_size());
135 state.resize(cipher->block_size());
136 temp.resize(cipher->block_size());
159void CTS_Decryption::decrypt(
const byte block[])
161 cipher->
decrypt(block, &temp[0]);
170void CTS_Decryption::write(
const byte input[],
size_t length)
172 size_t copied = std::min<size_t>(buffer.
size() - position, length);
173 buffer.
copy(position, input, copied);
178 if(length == 0)
return;
194 copy_mem(&buffer[0], &buffer[cipher->block_size()], cipher->block_size());
195 position = cipher->block_size();
197 buffer.copy(position, input, length);
206 cipher->decrypt(buffer, temp);
207 xor_buf(temp, &buffer[cipher->block_size()], position - cipher->block_size());
209 SecureVector<byte> xn = temp;
212 &xn[position - cipher->block_size()],
213 buffer.size() - position);
215 cipher->decrypt(&buffer[cipher->block_size()], temp);
216 xor_buf(temp, state, cipher->block_size());
217 send(temp, cipher->block_size());
218 send(xn, position - cipher->block_size());
void encrypt(const byte in[], byte out[]) const
void decrypt(const byte in[], byte out[]) const
virtual size_t block_size() const =0
void set_key(const SymmetricKey &key)
CTS_Decryption(BlockCipher *cipher)
void set_iv(const InitializationVector &)
bool valid_iv_length(size_t iv_len) const
bool valid_iv_length(size_t iv_len) const
void set_iv(const InitializationVector &)
void set_key(const SymmetricKey &key)
CTS_Encryption(BlockCipher *cipher)
void send(const byte in[], size_t length)
void copy(const T in[], size_t n)
SecureVector< byte > bits_of() const
void zeroise(MemoryRegion< T > &vec)
void xor_buf(byte out[], const byte in[], size_t length)
void copy_mem(T *out, const T *in, size_t n)
OctetString InitializationVector
void clear_mem(T *ptr, size_t n)
Encoding_Error(const std::string &name)
Invalid_IV_Length(const std::string &mode, size_t bad_len)