9#include <botan/internal/xor_buf.h>
20 cipher(ciph), padder(pad)
22 if(!padder->valid_blocksize(cipher->block_size()))
25 state.resize(cipher->block_size());
36 cipher(ciph), padder(pad)
38 if(!padder->valid_blocksize(cipher->block_size()))
41 state.resize(cipher->block_size());
62void CBC_Encryption::buffered_block(
const byte input[],
size_t length)
64 size_t blocks = length / state.
size();
66 for(
size_t i = 0; i != blocks; ++i)
77void CBC_Encryption::buffered_final(
const byte input[],
size_t length)
79 if(length % cipher->block_size() == 0)
80 buffered_block(input, length);
85void CBC_Encryption::write(
const byte input[],
size_t input_length)
94 SecureVector<byte> padding(cipher->block_size());
95 padder->pad(padding, padding.size(), last_block);
97 size_t pad_bytes = padder->pad_bytes(cipher->block_size(), last_block);
109 return (cipher->name() +
"/CBC/" + padder->name());
118 cipher(ciph), padder(pad)
120 if(!padder->valid_blocksize(cipher->block_size()))
123 state.resize(cipher->block_size());
135 cipher(ciph), padder(pad)
137 if(!padder->valid_blocksize(cipher->block_size()))
140 state.resize(cipher->block_size());
162void CBC_Decryption::buffered_block(
const byte input[],
size_t length)
165 size_t blocks = length / cipher->
block_size();
169 size_t to_proc = std::min<size_t>(blocks, blocks_in_temp);
171 cipher->
decrypt_n(input, &temp[0], to_proc);
175 for(
size_t i = 1; i < to_proc; ++i)
194void CBC_Decryption::buffered_final(
const byte input[],
size_t length)
196 if(length == 0 || length % cipher->block_size() != 0)
199 size_t extra_blocks = (length - 1) / cipher->block_size();
201 buffered_block(input, extra_blocks * cipher->block_size());
203 input += extra_blocks * cipher->block_size();
205 cipher->decrypt(input, temp);
206 xor_buf(temp, state, cipher->block_size());
207 send(temp, padder->unpad(temp, cipher->block_size()));
209 copy_mem(&state[0], input, state.size());
215void CBC_Decryption::write(
const byte input[],
size_t length)
233 return (cipher->name() +
"/CBC/" + padder->name());
virtual void decrypt_n(const byte in[], byte out[], size_t blocks) const =0
void encrypt(const byte in[], byte out[]) const
virtual size_t block_size() const =0
size_t current_position() const
Buffered_Filter(size_t block_size, size_t final_minimum)
void write(const byte in[], size_t length)
size_t buffered_block_size() const
void set_iv(const InitializationVector &iv)
void set_key(const SymmetricKey &key)
bool valid_iv_length(size_t iv_len) const
CBC_Decryption(BlockCipher *cipher, BlockCipherModePaddingMethod *padding)
void set_iv(const InitializationVector &iv)
CBC_Encryption(BlockCipher *cipher, BlockCipherModePaddingMethod *padding)
bool valid_iv_length(size_t iv_len) const
void set_key(const SymmetricKey &key)
void send(const byte in[], size_t length)
SecureVector< byte > bits_of() const
void xor_buf(byte out[], const byte in[], size_t length)
void copy_mem(T *out, const T *in, size_t n)
OctetString InitializationVector
Decoding_Error(const std::string &name)
Encoding_Error(const std::string &name)
Invalid_IV_Length(const std::string &mode, size_t bad_len)