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
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}