9 #include <botan/package.h>
10 #include <botan/filters.h>
11 #include <botan/ctr.h>
12 #include <botan/get_byte.h>
13 #include <botan/internal/xor_buf.h>
19 const byte input[],
size_t input_len,
22 const size_t BLOCK_SIZE = cipher->
block_size();
28 const std::string all_zeros(BLOCK_SIZE*2,
'0');
43 (input_len + BLOCK_SIZE - 1) / BLOCK_SIZE;
45 byte* final_block = output + input_len;
49 for(
size_t i = 0; i != blocks; ++i)
51 const size_t left = std::min<size_t>(BLOCK_SIZE,
52 input_len - BLOCK_SIZE * i);
55 copy_mem(&buf[0], output + (BLOCK_SIZE * i), left);
57 for(
size_t j = 0; j !=
sizeof(i); ++j)
58 buf[BLOCK_SIZE - 1 - j] ^=
get_byte(
sizeof(i)-1-j, i);
62 xor_buf(final_block, buf, BLOCK_SIZE);
70 const byte input[],
size_t input_len,
73 const size_t BLOCK_SIZE = cipher->
block_size();
78 if(input_len < BLOCK_SIZE)
82 const std::string all_zeros(BLOCK_SIZE*2,
'0');
91 input + (input_len - BLOCK_SIZE),
94 const size_t blocks = ((input_len - 1) / BLOCK_SIZE);
97 for(
size_t i = 0; i != blocks; ++i)
99 const size_t left = std::min<size_t>(BLOCK_SIZE,
100 input_len - BLOCK_SIZE * (i+1));
103 copy_mem(&buf[0], input + (BLOCK_SIZE * i), left);
105 for(
size_t j = 0; j !=
sizeof(i); ++j)
106 buf[BLOCK_SIZE - 1 - j] ^=
get_byte(
sizeof(i)-1-j, i);
110 xor_buf(&package_key[0], buf, BLOCK_SIZE);
size_t read(byte output[], size_t length)
void clear_mem(T *ptr, size_t n)
std::invalid_argument Invalid_Argument
byte get_byte(size_t byte_num, T input)
size_t remaining(message_id msg=DEFAULT_MESSAGE) const
bool valid_keylength(size_t length) const
RandomNumberGenerator * rng
void set_key(const SymmetricKey &key)
const byte * begin() const
void copy_mem(T *out, const T *in, size_t n)
void aont_package(RandomNumberGenerator &rng, BlockCipher *cipher, const byte input[], size_t input_len, byte output[])
void aont_unpackage(BlockCipher *cipher, const byte input[], size_t input_len, byte output[])
void encrypt(const byte in[], byte out[]) const
void xor_buf(byte out[], const byte in[], size_t length)
void zeroise(MemoryRegion< T > &vec)
virtual size_t block_size() const =0
void process_msg(const byte in[], size_t length)