12#include "InternalCryptLib.h"
13#include <openssl/aes.h>
14#include <openssl/evp.h>
58 CONST EVP_CIPHER *Cipher;
62 if (DataInSize > INT_MAX) {
66 if (ADataSize > INT_MAX) {
76 Cipher = EVP_aes_128_gcm ();
79 Cipher = EVP_aes_192_gcm ();
82 Cipher = EVP_aes_256_gcm ();
88 if ((TagSize != 12) && (TagSize != 13) && (TagSize != 14) && (TagSize != 15) && (TagSize != 16)) {
92 if (DataOutSize !=
NULL) {
93 if ((*DataOutSize > INT_MAX) || (*DataOutSize < DataInSize)) {
98 Ctx = EVP_CIPHER_CTX_new ();
103 RetValue = (BOOLEAN)EVP_EncryptInit_ex (Ctx, Cipher,
NULL,
NULL,
NULL);
108 RetValue = (BOOLEAN)EVP_CIPHER_CTX_ctrl (Ctx, EVP_CTRL_GCM_SET_IVLEN, (INT32)IvSize,
NULL);
113 RetValue = (BOOLEAN)EVP_EncryptInit_ex (Ctx,
NULL,
NULL, Key, Iv);
118 RetValue = (BOOLEAN)EVP_EncryptUpdate (Ctx,
NULL, (INT32 *)&TempOutSize, AData, (INT32)ADataSize);
123 RetValue = (BOOLEAN)EVP_EncryptUpdate (Ctx, DataOut, (INT32 *)&TempOutSize, DataIn, (INT32)DataInSize);
128 RetValue = (BOOLEAN)EVP_EncryptFinal_ex (Ctx, DataOut, (INT32 *)&TempOutSize);
133 RetValue = (BOOLEAN)EVP_CIPHER_CTX_ctrl (Ctx, EVP_CTRL_GCM_GET_TAG, (INT32)TagSize, (VOID *)TagOut);
136 EVP_CIPHER_CTX_free (Ctx);
141 if (DataOutSize !=
NULL) {
142 *DataOutSize = DataInSize;
191 CONST EVP_CIPHER *Cipher;
195 if (DataInSize > INT_MAX) {
199 if (ADataSize > INT_MAX) {
209 Cipher = EVP_aes_128_gcm ();
212 Cipher = EVP_aes_192_gcm ();
215 Cipher = EVP_aes_256_gcm ();
221 if ((TagSize != 12) && (TagSize != 13) && (TagSize != 14) && (TagSize != 15) && (TagSize != 16)) {
225 if (DataOutSize !=
NULL) {
226 if ((*DataOutSize > INT_MAX) || (*DataOutSize < DataInSize)) {
231 Ctx = EVP_CIPHER_CTX_new ();
236 RetValue = (BOOLEAN)EVP_DecryptInit_ex (Ctx, Cipher,
NULL,
NULL,
NULL);
241 RetValue = (BOOLEAN)EVP_CIPHER_CTX_ctrl (Ctx, EVP_CTRL_GCM_SET_IVLEN, (INT32)IvSize,
NULL);
246 RetValue = (BOOLEAN)EVP_DecryptInit_ex (Ctx,
NULL,
NULL, Key, Iv);
251 RetValue = (BOOLEAN)EVP_DecryptUpdate (Ctx,
NULL, (INT32 *)&TempOutSize, AData, (INT32)ADataSize);
256 RetValue = (BOOLEAN)EVP_DecryptUpdate (Ctx, DataOut, (INT32 *)&TempOutSize, DataIn, (INT32)DataInSize);
261 RetValue = (BOOLEAN)EVP_CIPHER_CTX_ctrl (Ctx, EVP_CTRL_GCM_SET_TAG, (INT32)TagSize, (VOID *)Tag);
266 RetValue = (BOOLEAN)EVP_DecryptFinal_ex (Ctx, DataOut, (INT32 *)&TempOutSize);
269 EVP_CIPHER_CTX_free (Ctx);
274 if (DataOutSize !=
NULL) {
275 *DataOutSize = DataInSize;
BOOLEAN EFIAPI AeadAesGcmDecrypt(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Iv, IN UINTN IvSize, IN CONST UINT8 *AData, IN UINTN ADataSize, IN CONST UINT8 *DataIn, IN UINTN DataInSize, IN CONST UINT8 *Tag, IN UINTN TagSize, OUT UINT8 *DataOut, OUT UINTN *DataOutSize)
BOOLEAN EFIAPI AeadAesGcmEncrypt(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Iv, IN UINTN IvSize, IN CONST UINT8 *AData, IN UINTN ADataSize, IN CONST UINT8 *DataIn, IN UINTN DataInSize, OUT UINT8 *TagOut, IN UINTN TagSize, OUT UINT8 *DataOut, OUT UINTN *DataOutSize)