9#include <botan/streebog.h>
10#include <botan/loadstor.h>
11#include <botan/exceptn.h>
20 return std::unique_ptr<HashFunction>(
new Streebog(*
this));
24 m_output_bits(output_bits),
31 if(output_bits != 256 && output_bits != 512)
53 const uint64_t fill = (m_output_bits == 512) ? 0 : 0x0101010101010101;
54 std::fill(m_h.begin(), m_h.end(), fill);
62 const size_t block_size = m_buffer.size();
68 if(m_position + length >= block_size)
72 input += (block_size - m_position);
73 length -= (block_size - m_position);
78 const size_t full_blocks = length / block_size;
79 const size_t remaining = length % block_size;
81 for(
size_t i = 0; i != full_blocks; ++i)
87 buffer_insert(m_buffer, m_position, input + full_blocks * block_size, remaining);
88 m_position += remaining;
96 m_buffer[m_position++] = 0x01;
98 if(m_position != m_buffer.size())
99 clear_mem(&m_buffer[m_position], m_buffer.size() - m_position);
102 m_count += (m_position - 1) * 8;
116inline uint64_t force_le(uint64_t x)
118#if defined(BOTAN_TARGET_CPU_IS_LITTLE_ENDIAN)
120#elif defined(BOTAN_TARGET_CPU_IS_BIG_ENDIAN)
123 store_le(x,
reinterpret_cast<uint8_t*
>(&x));
128inline void lps(uint64_t block[8])
132 std::memcpy(r, block, 64);
134 for(
int i = 0; i < 8; ++i)
152 std::memcpy(M, input, 64);
159 uint64_t N = force_le(last_block ? 0ULL : m_count);
170 for(
size_t i = 0; i != 8; ++i)
175 for(
size_t i = 0; i < 12; ++i)
177 for(
size_t j = 0; j != 8; ++j)
182 for(
size_t j = 0; j != 8; ++j)
186 for(
size_t i = 0; i != 8; ++i)
188 m_h[i] ^= hN[i] ^ M[i];
194 for(
int i = 0; i < 8; i++)
196 const uint64_t m = force_le(M[i]);
197 const uint64_t hi = force_le(m_S[i]);
198 const uint64_t t = hi + m +
carry;
200 m_S[i] = force_le(t);
void compress(const uint8_t input[], bool lastblock=false)
void add_data(const uint8_t input[], size_t length) override
size_t output_length() const override
void compress_64(const uint64_t input[], bool lastblock=false)
std::unique_ptr< HashFunction > copy_state() const override
void final_result(uint8_t out[]) override
Streebog(size_t output_bits)
std::string name() const override
std::string to_string(const BER_Object &obj)
void zeroise(std::vector< T, Alloc > &vec)
uint16_t reverse_bytes(uint16_t val)
size_t buffer_insert(std::vector< T, Alloc > &buf, size_t buf_offset, const T input[], size_t input_length)
const uint64_t STREEBOG_C[12][8]
void carry(int64_t &h0, int64_t &h1)
void copy_mem(T *out, const T *in, size_t n)
void store_le(uint16_t in, uint8_t out[2])
const uint64_t STREEBOG_Ax[8][256]
void clear_mem(T *ptr, size_t n)