8#ifndef BOTAN_MDX_BASE_H_
9#define BOTAN_MDX_BASE_H_
11#include <botan/hash.h>
13#include <botan/internal/alignment_buffer.h>
14#include <botan/internal/bit_ops.h>
15#include <botan/internal/loadstor.h>
16#include <botan/internal/stl_util.h>
28 requires(
typename T::digest_type& digest, std::span<const uint8_t> input,
size_t blocks) {
29 { T::init(digest) } -> std::same_as<void>;
30 { T::compress_n(digest, input, blocks) } -> std::same_as<void>;
36 } && T::block_bytes >= 64 &&
is_power_of_2(T::block_bytes) && T::output_bytes >= 16 && T::ctr_bytes >= 8 &&
39template <md_hash_implementation MD>
44 void update(std::span<const uint8_t> input) {
49 MD::compress_n(m_digest, one_block.value(), 1);
55 MD::compress_n(m_digest, aligned_data, full_blocks);
60 m_count += input.size();
63 void final(std::span<uint8_t> output) {
65 append_counter_and_finalize();
77 void append_padding_bit() {
80 const uint8_t final_byte = 0x80;
81 m_buffer.
append({&final_byte, 1});
83 const uint8_t final_byte = 0x01;
84 m_buffer.
append({&final_byte, 1});
88 void append_counter_and_finalize() {
93 MD::compress_n(m_digest, m_buffer.
consume(), 1);
101 const uint64_t bit_count = m_count * 8;
104 store_be(bit_count, last_bytes.data());
106 store_le(bit_count, last_bytes.data());
110 MD::compress_n(m_digest, m_buffer.
consume(), 1);
113 void copy_output(std::span<uint8_t> output) {
117 copy_out_be(output.first(MD::output_bytes), m_digest);
119 copy_out_le(output.first(MD::output_bytes), m_digest);
124 typename MD::digest_type m_digest;
127 AlignmentBuffer<uint8_t, MD::block_bytes> m_buffer;
#define BOTAN_ASSERT_NOMSG(expr)
std::tuple< std::span< const uint8_t >, size_t > aligned_data_to_process(BufferSlicer &slicer) const
bool ready_to_consume() const
void append(std::span< const T > elements)
size_t elements_until_alignment() const
std::optional< std::span< const T > > handle_unaligned_data(BufferSlicer &slicer)
std::span< T > directly_modify_last(size_t elements)
std::span< const T > consume()
void fill_up_with_zeros()
bool in_alignment() const
void update(std::span< const uint8_t > input)
int(* final)(unsigned char *, CTX *)
void copy_out_be(std::span< uint8_t > out, InR &&in)
constexpr bool is_power_of_2(T arg)
constexpr auto store_le(ParamTs &&... params)
void copy_out_le(std::span< uint8_t > out, InR &&in)
constexpr auto store_be(ParamTs &&... params)