9#include <botan/internal/eax.h>
11#include <botan/internal/cmac.h>
12#include <botan/internal/ct_utils.h>
13#include <botan/internal/ctr.h>
14#include <botan/internal/fmt.h>
24 uint8_t tag,
size_t block_size, MessageAuthenticationCode& mac,
const uint8_t in[],
size_t length) {
25 for(
size_t i = 0; i != block_size - 1; ++i) {
29 mac.update(in, length);
40 m_cipher(std::move(cipher)),
41 m_ctr(std::make_unique<
CTR_BE>(m_cipher->new_object())),
42 m_cmac(std::make_unique<
CMAC>(m_cipher->new_object())) {
44 throw Invalid_Argument(fmt(
"Tag size {} is not allowed for {}", tag_size, name()));
78 return m_ctr->key_spec();
82 return m_ctr->has_keying_material() &&
m_cmac->has_keying_material();
88void EAX_Mode::key_schedule(std::span<const uint8_t> key) {
101 BOTAN_ARG_CHECK(idx == 0,
"EAX: cannot handle non-zero index in set_associated_data_n");
103 throw Invalid_State(
"Cannot set AD for EAX while processing a message");
108void EAX_Mode::start_msg(
const uint8_t nonce[],
size_t nonce_len) {
117 for(
size_t i = 0; i !=
block_size() - 1; ++i) {
123size_t EAX_Encryption::process_msg(uint8_t buf[],
size_t sz) {
125 m_ctr->cipher(buf, buf, sz);
143 buffer += std::make_pair(data_mac.data(),
tag_size());
148size_t EAX_Decryption::process_msg(uint8_t buf[],
size_t sz) {
151 m_ctr->cipher(buf, buf, sz);
157 const size_t sz = buffer.size() - offset;
158 uint8_t* buf = buffer.data() + offset;
162 const size_t remaining = sz -
tag_size();
165 m_cmac->update(buf, remaining);
166 m_ctr->cipher(buf, buf, remaining);
169 const uint8_t* included_tag = &buf[remaining];
182 buffer.resize(offset + remaining);
187 throw Invalid_Authentication_Tag(
"EAX tag check failed");
#define BOTAN_STATE_CHECK(expr)
#define BOTAN_ARG_CHECK(expr, msg)
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
int(* update)(CTX *, const void *, CC_LONG len)
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
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