24 EVP_CIPHER_CTX_init(
_ctx);
25 int status = EVP_CipherInit_ex(
_ctx, EVP_aes_128_gcm(),
nullptr,
nullptr,
nullptr,
_encrypting ? 1 : 0);
31 EVP_CIPHER_CTX_free(_ctx);
36 int status = EVP_CipherInit_ex(_ctx,
nullptr,
nullptr, key.data(),
nullptr, -1);
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))
48 if (!EVP_CipherUpdate(_ctx, data, &outLen, data, len))
53 if (!_encrypting && !EVP_CIPHER_CTX_ctrl(_ctx, EVP_CTRL_GCM_SET_TAG,
sizeof(tag), tag))
56 if (!EVP_CipherFinal_ex(_ctx, data + outLen, &outLen))
61 if (_encrypting && !EVP_CIPHER_CTX_ctrl(_ctx, EVP_CTRL_GCM_GET_TAG,
sizeof(tag), tag))
69 ASSERT(!_encrypting,
"Partial encryption is not allowed");
70 ASSERT(partialLength <=
static_cast<size_t>(std::numeric_limits<int>::max()));
71 int len =
static_cast<int>(partialLength);
72 if (!EVP_CipherInit_ex(_ctx,
nullptr,
nullptr,
nullptr, iv.data(), -1))
76 if (!EVP_CipherUpdate(_ctx, data, &outLen, data, len))
81 if (!EVP_CipherFinal_ex(_ctx, data + outLen, &outLen))
uint8[TAG_SIZE_BYTES] Tag
std::array< uint8, IV_SIZE_BYTES > IV
bool ProcessNoIntegrityCheck(IV const &iv, uint8 *data, size_t partialLength)
std::array< uint8, KEY_SIZE_BYTES > Key
bool Process(IV const &iv, uint8 *data, size_t length, Tag &tag)
void Init(Key const &key)