8 #include <botan/mdx_hash.h>
9 #include <botan/exceptn.h>
10 #include <botan/loadstor.h>
22 BIG_BYTE_ENDIAN(byte_end),
23 BIG_BIT_ENDIAN(bit_end),
26 m_count = m_position = 0;
35 m_count = m_position = 0;
49 if(m_position + length >= m_buffer.size())
52 input += (m_buffer.size() - m_position);
53 length -= (m_buffer.size() - m_position);
58 const size_t full_blocks = length / m_buffer.size();
59 const size_t remaining = length % m_buffer.size();
64 buffer_insert(m_buffer, m_position, input + full_blocks * m_buffer.size(), remaining);
65 m_position += remaining;
73 m_buffer[m_position] = (BIG_BIT_ENDIAN ? 0x80 : 0x01);
74 for(
size_t i = m_position+1; i != m_buffer.size(); ++i)
77 if(m_position >= m_buffer.size() - COUNT_SIZE)
83 write_count(&m_buffer[m_buffer.size() - COUNT_SIZE]);
96 throw Invalid_State(
"MDx_HashFunction::write_count: COUNT_SIZE < 8");
100 const uint64_t bit_count = m_count * 8;
103 store_be(bit_count, out + COUNT_SIZE - 8);
105 store_le(bit_count, out + COUNT_SIZE - 8);
void store_be(uint16_t in, uint8_t out[2])
size_t hash_block_size() const override
virtual void compress_n(const uint8_t blocks[], size_t block_n)=0
virtual void copy_out(uint8_t buffer[])=0
void add_data(const uint8_t input[], size_t length) override
virtual void write_count(uint8_t out[])
void final_result(uint8_t output[]) override
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
MDx_HashFunction(size_t block_length, bool big_byte_endian, bool big_bit_endian, size_t counter_size=8)
void store_le(uint16_t in, uint8_t out[2])
void zeroise(std::vector< T, Alloc > &vec)