9 #include <botan/internal/xor_buf.h>
20 cipher(ciph), padder(pad)
36 cipher(ciph), padder(pad)
62 void 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)
77 void CBC_Encryption::buffered_final(
const byte input[],
size_t length)
80 buffered_block(input, length);
82 throw Encoding_Error(
name() +
": Did not pad to full blocksize");
85 void CBC_Encryption::write(
const byte input[],
size_t input_length)
90 void CBC_Encryption::end_msg()
94 SecureVector<byte> padding(cipher->
block_size());
95 padder->
pad(padding, padding.size(), last_block);
109 return (cipher->
name() +
"/CBC/" + padder->
name());
118 cipher(ciph), padder(pad)
135 cipher(ciph), padder(pad)
162 void 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)
194 void CBC_Decryption::buffered_final(
const byte input[],
size_t length)
196 if(length == 0 || length % cipher->
block_size() != 0)
197 throw Decoding_Error(
name() +
": Ciphertext not multiple of block size");
199 size_t extra_blocks = (length - 1) / cipher->
block_size();
201 buffered_block(input, extra_blocks * cipher->
block_size());
215 void CBC_Decryption::write(
const byte input[],
size_t length)
223 void CBC_Decryption::end_msg()
233 return (cipher->
name() +
"/CBC/" + padder->
name());
void decrypt(const byte in[], byte out[]) const
virtual bool valid_blocksize(size_t block_size) const =0
void set_iv(const InitializationVector &iv)
CBC_Encryption(BlockCipher *cipher, BlockCipherModePaddingMethod *padding)
void write(const byte in[], size_t length)
SecureVector< byte > bits_of() const
void send(const byte in[], size_t length)
bool valid_iv_length(size_t iv_len) const
void copy_mem(T *out, const T *in, size_t n)
virtual std::string name() const =0
CBC_Decryption(BlockCipher *cipher, BlockCipherModePaddingMethod *padding)
void set_key(const SymmetricKey &key)
void set_key(const SymmetricKey &key)
void encrypt(const byte in[], byte out[]) const
size_t current_position() const
virtual size_t pad_bytes(size_t block_size, size_t position) const
void xor_buf(byte out[], const byte in[], size_t length)
bool valid_iv_length(size_t iv_len) const
virtual void decrypt_n(const byte in[], byte out[], size_t blocks) const =0
virtual std::string name() const =0
virtual size_t block_size() const =0
virtual size_t unpad(const byte block[], size_t size) const =0
virtual void pad(byte block[], size_t size, size_t current_position) const =0
size_t buffered_block_size() const
void set_iv(const InitializationVector &iv)