8 #include <botan/mdx_hash.h> 9 #include <botan/exceptn.h> 10 #include <botan/loadstor.h> 11 #include <botan/internal/bit_ops.h> 22 m_pad_char(bit_big_endian == true ? 0x80 : 0x01),
23 m_counter_size(cnt_size),
25 m_count_big_endian(byte_big_endian),
31 throw Invalid_Argument(
"MDx_HashFunction block length must be a power of 2");
32 if(m_block_bits < 3 || m_block_bits > 16)
33 throw Invalid_Argument(
"MDx_HashFunction block size too large or too small");
34 if(m_counter_size < 8 || m_counter_size > block_len)
35 throw Invalid_State(
"MDx_HashFunction invalid counter length");
44 m_count = m_position = 0;
52 const size_t block_len =
static_cast<size_t>(1) << m_block_bits;
60 if(m_position + length >= block_len)
63 input += (block_len - m_position);
64 length -= (block_len - m_position);
70 const size_t full_blocks = length >> m_block_bits;
71 const size_t remaining = length & (block_len - 1);
78 buffer_insert(m_buffer, m_position, input + full_blocks * block_len, remaining);
79 m_position += remaining;
87 const size_t block_len =
static_cast<size_t>(1) << m_block_bits;
89 clear_mem(&m_buffer[m_position], block_len - m_position);
90 m_buffer[m_position] = m_pad_char;
92 if(m_position >= block_len - m_counter_size)
113 const uint64_t bit_count = m_count * 8;
115 if(m_count_big_endian)
116 store_be(bit_count, out + m_counter_size - 8);
118 store_le(bit_count, out + m_counter_size - 8);
void store_be(uint16_t in, uint8_t out[2])
void clear_mem(T *ptr, size_t n)
MDx_HashFunction(size_t block_length, bool big_byte_endian, bool big_bit_endian, uint8_t counter_size=8)
#define BOTAN_ASSERT_NOMSG(expr)
virtual void compress_n(const uint8_t blocks[], size_t block_n)=0
void add_data(const uint8_t input[], size_t length) override final
virtual void copy_out(uint8_t buffer[])=0
constexpr bool is_power_of_2(T arg)
virtual void write_count(uint8_t out[])
size_t buffer_insert(std::vector< T, Alloc > &buf, size_t buf_offset, const T input[], size_t input_length)
virtual size_t output_length() const =0
void final_result(uint8_t output[]) override final
void store_le(uint16_t in, uint8_t out[2])
void zeroise(std::vector< T, Alloc > &vec)