9#include <botan/internal/streebog.h>
11#include <botan/exceptn.h>
12#include <botan/internal/bswap.h>
13#include <botan/internal/fmt.h>
14#include <botan/internal/loadstor.h>
15#include <botan/internal/stl_util.h>
24 return std::make_unique<Streebog>(*
this);
28 if(output_bits != 256 && output_bits != 512) {
36 return fmt(
"Streebog-{}", m_output_bits);
47 const uint64_t fill = (m_output_bits == 512) ? 0 : 0x0101010101010101;
48 std::fill(m_h.begin(), m_h.end(), fill);
58 if(
const auto one_block = m_buffer.handle_unaligned_data(in)) {
63 if(m_buffer.in_alignment()) {
64 while(
const auto aligned_block = m_buffer.next_aligned_block_to_process(in)) {
76 const auto pos = m_buffer.elements_in_buffer();
78 const uint8_t padding = 0x01;
79 m_buffer.append({&padding, 1});
80 m_buffer.fill_up_with_zeros();
85 m_buffer.fill_up_with_zeros();
86 store_le(m_count, m_buffer.directly_modify_first(
sizeof(m_count)).data());
87 compress(m_buffer.consume().data(),
true);
97inline uint64_t force_le(uint64_t x) {
98 if constexpr(std::endian::native == std::endian::little) {
100 }
else if constexpr(std::endian::native == std::endian::big) {
103 store_le(x,
reinterpret_cast<uint8_t*
>(&x));
108inline void lps(uint64_t block[8]) {
111 std::memcpy(r, block, 64);
113 for(
int i = 0; i < 8; ++i) {
125 std::memcpy(M, input, 64);
131 const uint64_t N = last_block ? 0 : force_le(m_count);
142 for(
size_t i = 0; i != 8; ++i) {
146 for(
size_t i = 0; i < 12; ++i) {
147 for(
size_t j = 0; j != 8; ++j) {
153 for(
size_t j = 0; j != 8; ++j) {
158 for(
size_t i = 0; i != 8; ++i) {
159 m_h[i] ^= hN[i] ^ M[i];
164 for(
int i = 0; i < 8; i++) {
165 const uint64_t m = force_le(M[i]);
166 const uint64_t hi = force_le(m_S[i]);
167 const uint64_t t = hi + m +
carry;
169 m_S[i] = force_le(t);
void compress(const uint8_t input[], bool lastblock=false)
void add_data(std::span< const uint8_t > input) 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(std::span< uint8_t > out) override
Streebog(size_t output_bits)
std::string name() const override
void zeroise(std::vector< T, Alloc > &vec)
std::string fmt(std::string_view format, const T &... args)
const uint64_t STREEBOG_C[12][8]
constexpr T reverse_bytes(T x)
constexpr auto store_le(ParamTs &&... params)
void carry(int64_t &h0, int64_t &h1)
const uint64_t STREEBOG_Ax[8][256]
constexpr void copy_mem(T *out, const T *in, size_t n)