OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::OpenSSLCrypto::CipherContextAEAD Class Reference

#include <cipheraead.hpp>

Collaboration diagram for openvpn::OpenSSLCrypto::CipherContextAEAD:
[legend]

Public Types

enum  { MODE_UNDEF = -1 , ENCRYPT = 1 , DECRYPT = 0 }
 
enum  : size_t { IV_LEN = 12 , AUTH_TAG_LEN = 16 }
 

Public Member Functions

 CipherContextAEAD (const CipherContextAEAD &)=delete
 
CipherContextAEADoperator= (const CipherContextAEAD &)=delete
 
 CipherContextAEAD (CipherContextAEAD &&other) noexcept
 
CipherContextAEADoperator= (CipherContextAEAD &&other)
 
 OPENVPN_EXCEPTION (openssl_gcm_error)
 
bool constexpr requires_authtag_at_end ()
 
 CipherContextAEAD ()=default
 
 ~CipherContextAEAD ()
 
void init (SSLLib::Ctx libctx, const CryptoAlgs::Type alg, const unsigned char *key, const unsigned int keysize, const int mode)
 
void encrypt (const unsigned char *input, unsigned char *output, size_t length, const unsigned char *iv, unsigned char *tag, const unsigned char *ad, size_t ad_len)
 
const Crypto::AEADUsageLimitget_usage_limit ()
 
bool decrypt (const unsigned char *input, unsigned char *output, size_t length, const unsigned char *iv, const unsigned char *tag, const unsigned char *ad, size_t ad_len)
 
bool is_initialized () const
 

Static Public Member Functions

static bool is_supported (SSLLib::Ctx libctx, const CryptoAlgs::Type alg)
 

Private Types

using evp_cipher_type = const EVP_CIPHER
 
using CIPHER_unique_ptr = std::unique_ptr< evp_cipher_type, decltype(&::EVP_CIPHER_free)>
 

Private Member Functions

void free_cipher_context ()
 
void check_initialized () const
 

Static Private Member Functions

static evp_cipher_typecipher_type (SSLLib::Ctx libctx, const CryptoAlgs::Type alg, unsigned int &keysize)
 

Private Attributes

EVP_CIPHER_CTX * ctx = nullptr
 
Crypto::AEADUsageLimit aead_usage_limit_ = {}
 

Detailed Description

Definition at line 30 of file cipheraead.hpp.

Member Typedef Documentation

◆ CIPHER_unique_ptr

Definition at line 40 of file cipheraead.hpp.

◆ evp_cipher_type

Definition at line 36 of file cipheraead.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
MODE_UNDEF 
ENCRYPT 
DECRYPT 

Definition at line 62 of file cipheraead.hpp.

◆ anonymous enum

anonymous enum : size_t
Enumerator
IV_LEN 
AUTH_TAG_LEN 

Definition at line 70 of file cipheraead.hpp.

Constructor & Destructor Documentation

◆ CipherContextAEAD() [1/3]

openvpn::OpenSSLCrypto::CipherContextAEAD::CipherContextAEAD ( const CipherContextAEAD )
delete

◆ CipherContextAEAD() [2/3]

openvpn::OpenSSLCrypto::CipherContextAEAD::CipherContextAEAD ( CipherContextAEAD &&  other)
inlinenoexcept

Definition at line 46 of file cipheraead.hpp.

◆ CipherContextAEAD() [3/3]

openvpn::OpenSSLCrypto::CipherContextAEAD::CipherContextAEAD ( )
default

◆ ~CipherContextAEAD()

openvpn::OpenSSLCrypto::CipherContextAEAD::~CipherContextAEAD ( )
inline

Definition at line 83 of file cipheraead.hpp.

Member Function Documentation

◆ check_initialized()

void openvpn::OpenSSLCrypto::CipherContextAEAD::check_initialized ( ) const
inlineprivate

Definition at line 306 of file cipheraead.hpp.

Here is the caller graph for this function:

◆ cipher_type()

static evp_cipher_type * openvpn::OpenSSLCrypto::CipherContextAEAD::cipher_type ( SSLLib::Ctx  libctx,
const CryptoAlgs::Type  alg,
unsigned int &  keysize 
)
inlinestaticprivate

Definition at line 276 of file cipheraead.hpp.

Here is the caller graph for this function:

◆ decrypt()

bool openvpn::OpenSSLCrypto::CipherContextAEAD::decrypt ( const unsigned char *  input,
unsigned char *  output,
size_t  length,
const unsigned char *  iv,
const unsigned char *  tag,
const unsigned char *  ad,
size_t  ad_len 
)
inline

Decrypts AEAD encrypted data. Note that if tag is the nullptr the tag is assumed to be part of input and at the end of the input. The length parameter of input includes the tag in this case

Parameters
inputInput data to decrypt
outputWhere decrypted data will be written to
ivIV of the encrypted data.
lengthlength the of the data, this includes the tag at the end if tag is not a nullptr.
adstart of the additional data
ad_lenlength of the additional data
taglocation of the tag to use or nullptr if at the end of the input

This API of OpenSSL does not modify the tag it is given but the function signature always expects a modifiable tag, so we have to const cast it to get around this restriction

Definition at line 202 of file cipheraead.hpp.

◆ encrypt()

void openvpn::OpenSSLCrypto::CipherContextAEAD::encrypt ( const unsigned char *  input,
unsigned char *  output,
size_t  length,
const unsigned char *  iv,
unsigned char *  tag,
const unsigned char *  ad,
size_t  ad_len 
)
inline

Definition at line 135 of file cipheraead.hpp.

◆ free_cipher_context()

void openvpn::OpenSSLCrypto::CipherContextAEAD::free_cipher_context ( )
inlineprivate

Definition at line 300 of file cipheraead.hpp.

Here is the caller graph for this function:

◆ get_usage_limit()

const Crypto::AEADUsageLimit & openvpn::OpenSSLCrypto::CipherContextAEAD::get_usage_limit ( )
inline

Returns the AEAD usage limit associated with this AEAD cipher instance to check the limits

Definition at line 183 of file cipheraead.hpp.

◆ init()

void openvpn::OpenSSLCrypto::CipherContextAEAD::init ( SSLLib::Ctx  libctx,
const CryptoAlgs::Type  alg,
const unsigned char *  key,
const unsigned int  keysize,
const int  mode 
)
inline

Definition at line 88 of file cipheraead.hpp.

◆ is_initialized()

bool openvpn::OpenSSLCrypto::CipherContextAEAD::is_initialized ( ) const
inline

Definition at line 262 of file cipheraead.hpp.

◆ is_supported()

static bool openvpn::OpenSSLCrypto::CipherContextAEAD::is_supported ( SSLLib::Ctx  libctx,
const CryptoAlgs::Type  alg 
)
inlinestatic

Definition at line 267 of file cipheraead.hpp.

◆ OPENVPN_EXCEPTION()

openvpn::OpenSSLCrypto::CipherContextAEAD::OPENVPN_EXCEPTION ( openssl_gcm_error  )

◆ operator=() [1/2]

CipherContextAEAD & openvpn::OpenSSLCrypto::CipherContextAEAD::operator= ( CipherContextAEAD &&  other)
inline

Definition at line 51 of file cipheraead.hpp.

◆ operator=() [2/2]

CipherContextAEAD & openvpn::OpenSSLCrypto::CipherContextAEAD::operator= ( const CipherContextAEAD )
delete

◆ requires_authtag_at_end()

bool constexpr openvpn::OpenSSLCrypto::CipherContextAEAD::requires_authtag_at_end ( )
inlineconstexpr

Definition at line 76 of file cipheraead.hpp.

Member Data Documentation

◆ aead_usage_limit_

Crypto::AEADUsageLimit openvpn::OpenSSLCrypto::CipherContextAEAD::aead_usage_limit_ = {}
private

Definition at line 315 of file cipheraead.hpp.

◆ ctx

EVP_CIPHER_CTX* openvpn::OpenSSLCrypto::CipherContextAEAD::ctx = nullptr
private

Definition at line 314 of file cipheraead.hpp.


The documentation for this class was generated from the following file: