9#include <botan/internal/tls_null.h>
11#include <botan/assert.h>
12#include <botan/tls_alert.h>
13#include <botan/tls_exceptn.h>
14#include <botan/internal/fmt.h>
15#include <botan/internal/loadstor.h>
36 return fmt(
"TLS_NULL({})", m_mac_name);
68void TLS_NULL_HMAC_AEAD_Mode::key_schedule(std::span<const uint8_t> key) {
69 if(key.size() != m_mac_keylen) {
72 m_key.assign(key.begin(), key.end());
76void TLS_NULL_HMAC_AEAD_Mode::start_msg(
const uint8_t nonce[],
size_t nonce_len) {
80 throw Invalid_IV_Length(
name(), nonce_len);
84size_t TLS_NULL_HMAC_AEAD_Mode::process_msg(uint8_t buf[],
size_t sz) {
90 BOTAN_ARG_CHECK(idx == 0,
"TLS 1.2 NULL/HMAC: cannot handle non-zero index in set_associated_data_n");
91 BOTAN_ARG_CHECK(ad.size() == 13,
"TLS 1.2 NULL/HMAC: invalid TLS AEAD associated data length");
105 process(std::span{buffer}.subspan(offset));
106 buffer.resize(buffer.size() +
tag_size());
116 "TLS_NULL_HMAC_AEAD_Decryption needs at least tag_size() bytes in final buffer");
118 const auto data_and_tag = std::span{buffer}.subspan(offset);
119 const auto data = data_and_tag.first(data_and_tag.size() -
tag_size());
120 const auto tag = data_and_tag.subspan(data.size());
123 if(!
mac().verify_mac(tag)) {
124 throw TLS_Exception(Alert::BadRecordMac,
"Message authentication failure");
127 buffer.resize(buffer.size() -
tag_size());
#define BOTAN_STATE_CHECK(expr)
#define BOTAN_ASSERT_NONNULL(ptr)
#define BOTAN_ARG_CHECK(expr, msg)
void update(const uint8_t in[], size_t length)
void final(uint8_t out[])
size_t process(std::span< uint8_t > msg)
virtual size_t output_length(size_t input_length) const =0
virtual bool has_keying_material() const =0
void set_key(const OctetString &key)
void finish_msg(secure_vector< uint8_t > &final_block, size_t offset=0) override
size_t output_length(size_t input_length) const override
size_t output_length(size_t input_length) const override
void set_associated_data_n(size_t idx, std::span< const uint8_t > ad) override
size_t update_granularity() const final
size_t ideal_granularity() const final
void set_associated_data_n(size_t idx, std::span< const uint8_t > ad) override
bool has_keying_material() const final
MessageAuthenticationCode & mac() const
Key_Length_Specification key_spec() const final
size_t mac_keylen() const
std::string name() const final
bool valid_nonce_length(size_t nl) const final
TLS_NULL_HMAC_AEAD_Mode(std::unique_ptr< MessageAuthenticationCode > mac, size_t mac_keylen)
size_t tag_size() const final
std::string fmt(std::string_view format, const T &... args)
std::vector< T, secure_allocator< T > > secure_vector