9#include <botan/internal/gmac.h>
11#include <botan/block_cipher.h>
12#include <botan/exceptn.h>
13#include <botan/mem_ops.h>
14#include <botan/internal/fmt.h>
15#include <botan/internal/ghash.h>
20 m_cipher(std::move(cipher)), m_ghash(std::make_unique<
GHASH>()), m_H(GCM_BS), m_initialized(false) {}
26 m_initialized =
false;
32 return m_cipher->key_spec();
36 return fmt(
"GMAC({})", m_cipher->name());
40 return m_ghash->provider();
47void GMAC::add_data(std::span<const uint8_t> input) {
48 m_ghash->update_associated_data(input);
52 return m_cipher->has_keying_material();
55void GMAC::key_schedule(std::span<const uint8_t> key) {
57 m_cipher->set_key(key);
59 m_cipher->encrypt(m_H);
60 m_ghash->set_key(m_H);
63void GMAC::start_msg(std::span<const uint8_t> nonce) {
64 std::array<uint8_t, GCM_BS> y0 = {0};
66 if(nonce.size() == 12) {
67 copy_mem(y0.data(), nonce.data(), nonce.size());
70 m_ghash->nonce_hash(y0, nonce);
73 m_cipher->encrypt(y0.data());
78void GMAC::final_result(std::span<uint8_t> mac) {
83 throw Invalid_State(
"GMAC was not used with a fresh nonce");
87 m_ghash->reset_associated_data();
91 return std::make_unique<GMAC>(m_cipher->new_object());
std::string name() const override
GMAC(std::unique_ptr< BlockCipher > cipher)
std::string provider() const override
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)
constexpr void copy_mem(T *out, const T *in, size_t n)
std::string fmt(std::string_view format, const T &... args)