9#include <botan/internal/gmac.h>
11#include <botan/block_cipher.h>
12#include <botan/exceptn.h>
13#include <botan/internal/fmt.h>
14#include <botan/internal/ghash.h>
15#include <botan/internal/stl_util.h>
20 m_cipher(std::move(cipher)), m_ghash(std::make_unique<
GHASH>()), m_H(GCM_BS), m_initialized(false) {}
27 m_initialized =
false;
33 return m_cipher->key_spec();
37 return fmt(
"GMAC({})", m_cipher->name());
44void GMAC::add_data(std::span<const uint8_t> input) {
49 m_ghash->update_associated_data(one_block.value());
55 m_ghash->update_associated_data(aligned_data);
62 return m_cipher->has_keying_material();
65void GMAC::key_schedule(std::span<const uint8_t> key) {
67 m_cipher->set_key(key);
69 m_cipher->encrypt(m_H);
70 m_ghash->set_key(m_H);
73void GMAC::start_msg(std::span<const uint8_t> nonce) {
76 if(nonce.size() == 12) {
77 copy_mem(y0.data(), nonce.data(), nonce.size());
80 m_ghash->ghash_update(y0, nonce);
81 m_ghash->add_final_block(y0, 0, nonce.size());
85 m_cipher->encrypt(y0.data(), m_enc_y0.data());
86 m_ghash->start(m_enc_y0);
90void GMAC::final_result(std::span<uint8_t> mac) {
94 if(m_initialized ==
false) {
95 throw Invalid_State(
"GMAC was not used with a fresh nonce");
104 m_ghash->set_key(m_H);
109 return std::make_unique<GMAC>(m_cipher->new_object());
std::tuple< std::span< const uint8_t >, size_t > aligned_data_to_process(BufferSlicer &slicer) const
std::optional< std::span< const T > > handle_unaligned_data(BufferSlicer &slicer)
std::span< const T > consume_partial()
bool in_alignment() const
std::string name() const override
GMAC(std::unique_ptr< BlockCipher > cipher)
std::unique_ptr< MessageAuthenticationCode > new_object() const override
Key_Length_Specification key_spec() const override
bool has_keying_material() const override
size_t output_length() const override
void zeroise(std::vector< T, Alloc > &vec)
std::string fmt(std::string_view format, const T &... args)
std::vector< T, secure_allocator< T > > secure_vector
constexpr void copy_mem(T *out, const T *in, size_t n)