14#ifndef OPENVPN_CRYPTO_CRYPTO_AEAD_EPOCH_H
15#define OPENVPN_CRYPTO_CRYPTO_AEAD_EPOCH_H
34template <
typename CRYPTO_API>
71 pkt_header.
write(op32, 4);
72 encrypt_ctx.pid.write_next(pkt_header);
74 std::array<uint8_t, EpochDataChannelCryptoContext::IV_SIZE> calculated_iv{};
75 encrypt_ctx.calculate_iv(pkt_header.data() + 4, calculated_iv);
80 throw aead_epoch_error(
"encrypt work buffer too small");
88 encrypt_ctx.cipher.encrypt(buf.
data(), work_data, buf.
size(), calculated_iv.data(), auth_tag, pkt_header.data(), pkt_header.size());
93 buf.
prepend(pkt_header.c_data() + 4, pkt_header.size() - 4);
117 pkt_header.
write(op32, 4);
118 auto *packet_id = pkt_header.write_alloc(8);
119 buf.
read(packet_id, 8);
124 pid.
read(packet_id_buf);
135 std::array<uint8_t, EpochDataChannelCryptoContext::IV_SIZE> calculated_iv{};
141 throw aead_epoch_error(
"decrypt work buffer too small");
144 if (!decrypt_ctx->cipher.decrypt(buf.
c_data(),
work_decrypt.
data(), buf.
size(), calculated_iv.data(),
nullptr, pkt_header.data(), pkt_header.size()))
153 if (!decrypt_ctx->pid.test_add(pid, now,
stats))
175 throw aead_epoch_error(
"AEAD Epoch requires epoch keys to be in use");
227template <
typename CRYPTO_API>
267 return CRYPTO_API::CipherContextAEAD::AUTH_TAG_LEN + 4;
CryptoDCSettingsData crypto_info() override
CryptoDCInstance::Ptr new_obj(const unsigned int key_id) override
CryptoDCSettingsData dc_settings
size_t encap_overhead() const override
RCPtr< CryptoContext > Ptr
CryptoContext(SSLLib::Ctx libctx_arg, CryptoDCSettingsData dc_settings_data, const Frame::Ptr &frame_arg, const SessionStats::Ptr &stats_arg)
void init_cipher(StaticKey &&encrypt_key, StaticKey &&decrypt_key) override
void init_pid(const char *recv_name, const int recv_unit, const SessionStats::Ptr &recv_stats_arg) override
BufferAllocated work_encrypt
void rekey(const RekeyType type) override
BufferAllocated work_decrypt
Crypto(SSLLib::Ctx libctx_arg, CryptoDCSettingsData dc_settings_data, const Frame::Ptr &frame_arg, const SessionStats::Ptr &stats_arg)
void increase_send_epoch()
Error::Type decrypt(BufferAllocated &buf, const std::time_t now, const unsigned char *op32) override
bool encrypt(BufferAllocated &buf, const unsigned char *op32) override
bool consider_compression(const CompressContext &comp_ctx) override
CryptoDCSettingsData dc_settings
void init_hmac(StaticKey &&encrypt_key, StaticKey &&decrypt_key) override
unsigned int defined() const override
void swap(BufferAllocatedType< T_ > &other)
Swaps the contents of this BufferAllocatedType object with another BufferAllocatedType object.
const T * c_data() const
Returns a const pointer to the start of the buffer.
size_t max_size() const
Return the maximum allowable size value in T objects given the current offset (without considering re...
T * write_alloc(const size_t size)
Allocate space for writing data to the buffer.
void prepend(const T *data, const size_t size)
Prepend data to the buffer.
size_t size() const
Returns the size of the buffer in T objects.
T * data()
Get a mutable pointer to the start of the array.
bool empty() const
Returns true if the buffer is empty.
void write(const T *data, const size_t size)
Write data to the buffer.
void set_size(const size_t size)
After an external method, operating on the array as a mutable unsigned char buffer,...
void reset_size()
Resets the size of the buffer to zero.
void read(NCT *data, const size_t size)
Read data from the buffer into the specified memory location.
CryptoAlgs::KeyDerivation key_derivation
void set_digest(CryptoAlgs::Type digest)
CryptoAlgs::Type cipher() const
bool useEpochKeys() const
bool should_renegotiate()
EpochDataChannelDecryptContext * lookup_decrypt_key(uint16_t epoch)
void replace_update_recv_key(std::uint16_t new_epoch, const SessionStats::Ptr &stats_arg)
void check_send_iterate()
EpochDataChannelEncryptContext & encrypt()
size_t prepare(const unsigned int context, Buffer &buf) const
#define OPENVPN_EXCEPTION(C)
bool defined(const Type type)
void calculate_iv(uint8_t *packet_id, std::array< uint8_t, IV_SIZE > &iv_dest)
void read(ConstBuffer &buf)
constexpr std::size_t size() const