55 return (cipher->name() +
"/ECB/" + padder->name());
61void ECB_Encryption::write(
const byte input[],
size_t length)
73 SecureVector<byte> padding(cipher->
block_size());
74 padder->
pad(padding, padding.size(), last_block);
83void ECB_Encryption::buffered_block(
const byte input[],
size_t input_length)
85 const size_t blocks_in_temp = temp.size() / cipher->block_size();
86 size_t blocks = input_length / cipher->block_size();
90 size_t to_proc = std::min(blocks, blocks_in_temp);
92 cipher->encrypt_n(input, &temp[0], to_proc);
94 send(temp, to_proc * cipher->block_size());
96 input += to_proc * cipher->block_size();
101void ECB_Encryption::buffered_final(
const byte input[],
size_t input_length)
103 if(input_length % cipher->block_size() == 0)
104 buffered_block(input, input_length);
105 else if(input_length != 0)
135 cipher->set_key(key);
152 return (cipher->name() +
"/ECB/" + padder->name());
158void ECB_Decryption::write(
const byte input[],
size_t length)
174void ECB_Decryption::buffered_block(
const byte input[],
size_t length)
176 const size_t blocks_in_temp = temp.size() / cipher->block_size();
177 size_t blocks = length / cipher->block_size();
181 size_t to_proc = std::min(blocks, blocks_in_temp);
183 cipher->decrypt_n(input, &temp[0], to_proc);
185 send(temp, to_proc * cipher->block_size());
187 input += to_proc * cipher->block_size();
195void ECB_Decryption::buffered_final(
const byte input[],
size_t length)
197 if(length == 0 || length % cipher->block_size() != 0)
200 size_t extra_blocks = (length - 1) / cipher->block_size();
202 buffered_block(input, extra_blocks * cipher->block_size());
204 input += extra_blocks * cipher->block_size();
206 cipher->decrypt(input, temp);
207 send(temp, padder->unpad(temp, cipher->block_size()));
virtual size_t pad_bytes(size_t block_size, size_t position) const
virtual void pad(byte block[], size_t size, size_t current_position) const =0
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
ECB_Decryption(BlockCipher *ciph, BlockCipherModePaddingMethod *pad)
ECB_Encryption(BlockCipher *ciph, BlockCipherModePaddingMethod *pad)
void send(const byte in[], size_t length)
Decoding_Error(const std::string &name)
Encoding_Error(const std::string &name)