AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Acore::Crypto::AES Class Reference

#include "AES.h"

Public Types

using IV = std::array< uint8, IV_SIZE_BYTES >
 
using Key = std::array< uint8, KEY_SIZE_BYTES >
 
using Tag = uint8[TAG_SIZE_BYTES]
 

Public Member Functions

 AES (bool encrypting)
 
 ~AES ()
 
void Init (Key const &key)
 
bool Process (IV const &iv, uint8 *data, std::size_t length, Tag &tag)
 

Static Public Attributes

static constexpr std::size_t IV_SIZE_BYTES = 12
 
static constexpr std::size_t KEY_SIZE_BYTES = 16
 
static constexpr std::size_t TAG_SIZE_BYTES = 12
 

Private Attributes

EVP_CIPHER_CTX * _ctx
 
bool _encrypting
 

Detailed Description

Member Typedef Documentation

◆ IV

◆ Key

◆ Tag

Constructor & Destructor Documentation

◆ AES()

Acore::Crypto::AES::AES ( bool  encrypting)
explicit
22 : _ctx(EVP_CIPHER_CTX_new()), _encrypting(encrypting)
23{
24 EVP_CIPHER_CTX_init(_ctx);
25 int status = EVP_CipherInit_ex(_ctx, EVP_aes_128_gcm(), nullptr, nullptr, nullptr, _encrypting ? 1 : 0);
26 ASSERT(status);
27}
#define ASSERT
Definition: Errors.h:68
bool _encrypting
Definition: AES.h:47
EVP_CIPHER_CTX * _ctx
Definition: AES.h:46

References _ctx, _encrypting, and ASSERT.

◆ ~AES()

Acore::Crypto::AES::~AES ( )
30{
31 EVP_CIPHER_CTX_free(_ctx);
32}

Member Function Documentation

◆ Init()

void Acore::Crypto::AES::Init ( Key const &  key)
35{
36 int status = EVP_CipherInit_ex(_ctx, nullptr, nullptr, key.data(), nullptr, -1);
37 ASSERT(status);
38}

References ASSERT.

◆ Process()

bool Acore::Crypto::AES::Process ( IV const &  iv,
uint8 data,
std::size_t  length,
Tag tag 
)
41{
42 ASSERT(length <= static_cast<size_t>(std::numeric_limits<int>::max()));
43 int len = static_cast<int>(length);
44 if (!EVP_CipherInit_ex(_ctx, nullptr, nullptr, nullptr, iv.data(), -1))
45 return false;
46
47 int outLen;
48 if (!EVP_CipherUpdate(_ctx, data, &outLen, data, len))
49 return false;
50
51 len -= outLen;
52
53 if (!_encrypting && !EVP_CIPHER_CTX_ctrl(_ctx, EVP_CTRL_GCM_SET_TAG, sizeof(tag), tag))
54 return false;
55
56 if (!EVP_CipherFinal_ex(_ctx, data + outLen, &outLen))
57 return false;
58
59 ASSERT(len == outLen);
60
61 if (_encrypting && !EVP_CIPHER_CTX_ctrl(_ctx, EVP_CTRL_GCM_GET_TAG, sizeof(tag), tag))
62 return false;
63
64 return true;
65}

References ASSERT.

Member Data Documentation

◆ _ctx

EVP_CIPHER_CTX* Acore::Crypto::AES::_ctx
private

Referenced by AES().

◆ _encrypting

bool Acore::Crypto::AES::_encrypting
private

Referenced by AES().

◆ IV_SIZE_BYTES

constexpr std::size_t Acore::Crypto::AES::IV_SIZE_BYTES = 12
staticconstexpr

◆ KEY_SIZE_BYTES

constexpr std::size_t Acore::Crypto::AES::KEY_SIZE_BYTES = 16
staticconstexpr

◆ TAG_SIZE_BYTES

constexpr std::size_t Acore::Crypto::AES::TAG_SIZE_BYTES = 12
staticconstexpr