9 #include <botan/streebog.h> 10 #include <botan/exceptn.h> 19 return std::unique_ptr<HashFunction>(
new Streebog(*
this));
23 m_output_bits(output_bits),
30 if(output_bits != 256 && output_bits != 512)
52 const uint64_t fill = (m_output_bits == 512) ? 0 : 0x0101010101010101;
53 std::fill(m_h.begin(), m_h.end(), fill);
61 const size_t block_size = m_buffer.size();
67 if(m_position + length >= block_size)
71 input += (block_size - m_position);
72 length -= (block_size - m_position);
77 const size_t full_blocks = length / block_size;
78 const size_t remaining = length % block_size;
80 for(
size_t i = 0; i != full_blocks; ++i)
86 buffer_insert(m_buffer, m_position, input + full_blocks * block_size, remaining);
87 m_position += remaining;
95 m_buffer[m_position++] = 0x01;
97 if(m_position != m_buffer.size())
98 clear_mem(&m_buffer[m_position], m_buffer.size() - m_position);
101 m_count += (m_position - 1) * 8;
115 inline uint64_t force_le(uint64_t x)
117 #if defined(BOTAN_TARGET_CPU_IS_LITTLE_ENDIAN) 119 #elif defined(BOTAN_TARGET_CPU_IS_BIG_ENDIAN) 122 store_le(x, reinterpret_cast<uint8_t*>(&x));
127 inline void lps(uint64_t block[8])
131 std::memcpy(r, block, 64);
133 for(
int i = 0; i < 8; ++i)
151 std::memcpy(M, input, 64);
158 uint64_t N = force_le(last_block ? 0ULL : m_count);
169 for(
size_t i = 0; i != 8; ++i)
174 for(
size_t i = 0; i < 12; ++i)
176 for(
size_t j = 0; j != 8; ++j)
181 for(
size_t j = 0; j != 8; ++j)
185 for(
size_t i = 0; i != 8; ++i)
187 m_h[i] ^= hN[i] ^ M[i];
193 for(
int i = 0; i < 8; i++)
195 const uint64_t m = force_le(M[i]);
196 const uint64_t hi = force_le(m_S[i]);
197 const uint64_t t = hi + m;
199 m_S[i] = force_le(t +
carry);
200 carry = (t < hi ? 1 : 0) | (t < m ? 1 : 0);
std::string name() const override
void carry(int64_t &h0, int64_t &h1)
void clear_mem(T *ptr, size_t n)
size_t output_length() const override
const uint64_t STREEBOG_C[12][8]
std::string to_string(const BER_Object &obj)
std::unique_ptr< HashFunction > copy_state() const override
void add_data(const uint8_t input[], size_t length) override
void compress_64(const uint64_t input[], bool lastblock=false)
void compress(const uint8_t input[], bool lastblock=false)
void copy_mem(T *out, const T *in, size_t n)
uint16_t reverse_bytes(uint16_t val)
void final_result(uint8_t out[]) override
size_t buffer_insert(std::vector< T, Alloc > &buf, size_t buf_offset, const T input[], size_t input_length)
const uint64_t STREEBOG_Ax[8][256]
Streebog(size_t output_bits)
void store_le(uint16_t in, uint8_t out[2])
void zeroise(std::vector< T, Alloc > &vec)