14#ifndef OPENVPN_CRYPTO_ENCRYPT_CHM_H
15#define OPENVPN_CRYPTO_ENCRYPT_CHM_H
31template <
typename CRYPTO_API>
46 unsigned char iv_buf[CRYPTO_API::CipherContext::MAX_IV_LENGTH];
47 const size_t iv_length =
cipher.iv_length();
50 const int cipher_mode =
cipher.cipher_mode();
51 if (cipher_mode == CRYPTO_API::CipherContext::CIPH_CBC_MODE)
61 throw chm_unsupported_cipher_mode();
97 rng = std::move(rng_arg);
112 const unsigned char *content = buf.
data();
113 const size_t content_size = buf.
size();
114 const size_t hmac_size =
hmac.output_size();
116 hmac.hmac(hmac_buf, hmac_size, content, content_size);
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.
T * prepend_alloc(const size_t size)
Allocate space for prepending data to the buffer.
size_t max_size() const
Return the maximum allowable size value in T objects given the current offset (without considering re...
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.
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.
OPENVPN_SIMPLE_EXCEPTION(chm_unsupported_cipher_mode)
void prepend_hmac(BufferAllocated &buf)
CipherContext< CRYPTO_API > cipher
void set_rng(StrongRandomAPI::Ptr rng_arg)
OvpnHMAC< CRYPTO_API > hmac
void encrypt(BufferAllocated &buf)
PacketIDDataSend pid_send
size_t prepare(const unsigned int context, Buffer &buf) const
void prepend_next(Buffer &buf)
virtual void rand_bytes(unsigned char *buf, size_t size)=0
Fill a buffer with random bytes.
Implementation of the base classes for random number generators.