55 return (cipher->
name() +
"/ECB/" + padder->
name());
61 void ECB_Encryption::write(
const byte input[],
size_t length)
69 void ECB_Encryption::end_msg()
73 SecureVector<byte> padding(cipher->
block_size());
74 padder->
pad(padding, padding.size(), last_block);
83 void ECB_Encryption::buffered_block(
const byte input[],
size_t input_length)
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);
101 void ECB_Encryption::buffered_final(
const byte input[],
size_t input_length)
104 buffered_block(input, input_length);
105 else if(input_length != 0)
106 throw Encoding_Error(
name() +
": Did not pad to full blocksize");
152 return (cipher->
name() +
"/ECB/" + padder->
name());
158 void ECB_Decryption::write(
const byte input[],
size_t length)
166 void ECB_Decryption::end_msg()
174 void ECB_Decryption::buffered_block(
const byte input[],
size_t length)
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);
195 void ECB_Decryption::buffered_final(
const byte input[],
size_t length)
197 if(length == 0 || length % cipher->
block_size() != 0)
198 throw Decoding_Error(
name() +
": Ciphertext not multiple of block size");
200 size_t extra_blocks = (length - 1) / cipher->
block_size();
202 buffered_block(input, extra_blocks * cipher->
block_size());
void decrypt(const byte in[], byte out[]) const
void write(const byte in[], size_t length)
void send(const byte in[], size_t length)
void set_key(const SymmetricKey &key)
virtual std::string name() const =0
ECB_Encryption(BlockCipher *ciph, BlockCipherModePaddingMethod *pad)
ECB_Decryption(BlockCipher *ciph, BlockCipherModePaddingMethod *pad)
virtual void encrypt_n(const byte in[], byte out[], size_t blocks) const =0
size_t current_position() const
virtual size_t pad_bytes(size_t block_size, size_t position) 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