9#include <botan/internal/eax.h>
11#include <botan/exceptn.h>
12#include <botan/mem_ops.h>
13#include <botan/internal/cmac.h>
14#include <botan/internal/ct_utils.h>
15#include <botan/internal/ctr.h>
16#include <botan/internal/fmt.h>
17#include <botan/internal/int_utils.h>
28 for(
size_t i = 0; i != block_size - 1; ++i) {
32 mac.update(in, length);
47 throw Invalid_Argument(fmt(
"Tag size {} is not allowed for {}", tag_size, name()));
81 return m_ctr->key_spec();
85 return m_ctr->has_keying_material() &&
m_cmac->has_keying_material();
91void EAX_Mode::key_schedule(std::span<const uint8_t> key) {
111 BOTAN_ARG_CHECK(idx == 0,
"EAX: cannot handle non-zero index in set_associated_data_n");
113 throw Invalid_State(
"Cannot set AD for EAX while processing a message");
118void EAX_Mode::start_msg(
const uint8_t nonce[],
size_t nonce_len) {
129 for(
size_t i = 0; i !=
block_size() - 1; ++i) {
139size_t EAX_Encryption::process_msg(uint8_t buf[],
size_t sz) {
141 m_ctr->cipher(buf, buf, sz);
160 buffer += std::make_pair(data_mac.data(),
tag_size());
170size_t EAX_Decryption::process_msg(uint8_t buf[],
size_t sz) {
173 m_ctr->cipher(buf, buf, sz);
180 const size_t sz = buffer.size() - offset;
181 uint8_t* buf = buffer.data() + offset;
185 const size_t remaining = sz -
tag_size();
188 m_cmac->update(buf, remaining);
189 m_ctr->cipher(buf, buf, remaining);
192 const uint8_t* included_tag = &buf[remaining];
205 buffer.resize(offset + remaining);
210 clear_mem(std::span{buffer}.subspan(offset, remaining));
211 throw Invalid_Authentication_Tag(
"EAX tag check failed");
#define BOTAN_STATE_CHECK(expr)
#define BOTAN_ARG_CHECK(expr, msg)
void update(T &buffer, size_t offset=0)
size_t output_length(size_t input_length) const override
size_t output_length(size_t input_length) const override
size_t tag_size() const final
size_t update_granularity() const final
void set_associated_data_n(size_t idx, std::span< const uint8_t > ad) final
size_t block_size() const
size_t ideal_granularity() const final
bool valid_nonce_length(size_t) const final
std::unique_ptr< BlockCipher > m_cipher
bool has_keying_material() const final
EAX_Mode(std::unique_ptr< BlockCipher > cipher, size_t tag_size)
std::unique_ptr< StreamCipher > m_ctr
std::unique_ptr< MessageAuthenticationCode > m_cmac
Key_Length_Specification key_spec() const final
secure_vector< uint8_t > m_nonce_mac
std::string name() const final
secure_vector< uint8_t > m_ad_mac
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
constexpr T add_or_throw(T a, T b, std::string_view msg)
constexpr void xor_buf(ranges::contiguous_output_range< uint8_t > auto &&out, ranges::contiguous_range< uint8_t > auto &&in)
std::vector< T, secure_allocator< T > > secure_vector
constexpr void clear_mem(T *ptr, size_t n)