10#include <botan/internal/kmac.h>
12#include <botan/internal/cshake_xof.h>
13#include <botan/internal/fmt.h>
14#include <botan/internal/keccak_helpers.h>
18KMAC::KMAC(std::unique_ptr<cSHAKE_XOF> cshake,
size_t output_bit_length) :
19 m_output_bit_length(output_bit_length), m_message_started(false), m_cshake(std::move(cshake)) {
20 BOTAN_ARG_CHECK(m_output_bit_length % 8 == 0,
"KMAC output length must be full bytes");
21 BOTAN_ARG_CHECK(m_output_bit_length > 0,
"KMAC output length must be at least one byte");
29 m_message_started =
false;
34 return m_output_bit_length / 8;
49 return !m_encoded_key.empty();
53 return m_cshake->provider();
56void KMAC::start_msg(std::span<const uint8_t> nonce) {
58 m_cshake->start(nonce);
59 m_cshake->update(m_encoded_key);
60 m_message_started =
true;
63void KMAC::add_data(std::span<const uint8_t> data) {
65 if(!m_message_started) {
68 m_cshake->update(data);
71void KMAC::final_result(std::span<uint8_t> output) {
77 m_message_started =
false;
80void KMAC::key_schedule(std::span<const uint8_t> key) {
#define BOTAN_ASSERT_NONNULL(ptr)
#define BOTAN_ARG_CHECK(expr, msg)
std::string name() const override
std::unique_ptr< MessageAuthenticationCode > new_object() const override
KMAC128(size_t output_bit_length)
std::string name() const override
KMAC256(size_t output_bit_length)
std::unique_ptr< MessageAuthenticationCode > new_object() const override
KMAC(std::unique_ptr< cSHAKE_XOF > cshake, size_t output_bit_length)
bool has_keying_material() const final
size_t output_length() const final
Key_Length_Specification key_spec() const final
std::string provider() const final
void assert_key_material_set() const
void zap(std::vector< T, Alloc > &vec)
std::string fmt(std::string_view format, const T &... args)
size_t keccak_absorb_padded_strings_encoding(T &sink, size_t padding_mod, Ts... byte_strings)
std::span< const uint8_t > keccak_int_right_encode(std::span< uint8_t > out, size_t x)
constexpr size_t keccak_max_int_encoding_size()