]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Driver/Crypto.c
CryptoPkg: add AeadAesGcm to Crypto Service.
[mirror_edk2.git] / CryptoPkg / Driver / Crypto.c
index b54e59fd07bc106354808a972c0c2d1952df5bbe..9562dfeec58c3cbb5ae99c1e9d76c8550fd7cf96 100644 (file)
@@ -4938,6 +4938,95 @@ CryptoServiceParallelHash256HashAll (
   return CALL_BASECRYPTLIB (ParallelHash.Services.HashAll, ParallelHash256HashAll, (Input, InputByteLen, BlockSize, Output, OutputByteLen, Customization, CustomByteLen), FALSE);\r
 }\r
 \r
+/**\r
+  Performs AEAD AES-GCM authenticated encryption on a data buffer and additional authenticated data (AAD).\r
+\r
+  IvSize must be 12, otherwise FALSE is returned.\r
+  KeySize must be 16, 24 or 32, otherwise FALSE is returned.\r
+  TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.\r
+\r
+  @param[in]   Key         Pointer to the encryption key.\r
+  @param[in]   KeySize     Size of the encryption key in bytes.\r
+  @param[in]   Iv          Pointer to the IV value.\r
+  @param[in]   IvSize      Size of the IV value in bytes.\r
+  @param[in]   AData       Pointer to the additional authenticated data (AAD).\r
+  @param[in]   ADataSize   Size of the additional authenticated data (AAD) in bytes.\r
+  @param[in]   DataIn      Pointer to the input data buffer to be encrypted.\r
+  @param[in]   DataInSize  Size of the input data buffer in bytes.\r
+  @param[out]  TagOut      Pointer to a buffer that receives the authentication tag output.\r
+  @param[in]   TagSize     Size of the authentication tag in bytes.\r
+  @param[out]  DataOut     Pointer to a buffer that receives the encryption output.\r
+  @param[out]  DataOutSize Size of the output data buffer in bytes.\r
+\r
+  @retval TRUE   AEAD AES-GCM authenticated encryption succeeded.\r
+  @retval FALSE  AEAD AES-GCM authenticated encryption failed.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+CryptoServiceAeadAesGcmEncrypt (\r
+  IN   CONST UINT8  *Key,\r
+  IN   UINTN        KeySize,\r
+  IN   CONST UINT8  *Iv,\r
+  IN   UINTN        IvSize,\r
+  IN   CONST UINT8  *AData,\r
+  IN   UINTN        ADataSize,\r
+  IN   CONST UINT8  *DataIn,\r
+  IN   UINTN        DataInSize,\r
+  OUT  UINT8        *TagOut,\r
+  IN   UINTN        TagSize,\r
+  OUT  UINT8        *DataOut,\r
+  OUT  UINTN        *DataOutSize\r
+  )\r
+{\r
+  return CALL_BASECRYPTLIB (AeadAesGcm.Services.Encrypt, AeadAesGcmEncrypt, (Key, KeySize, Iv, IvSize, AData, ADataSize, DataIn, DataInSize, TagOut, TagSize, DataOut, DataOutSize), FALSE);\r
+}\r
+\r
+/**\r
+  Performs AEAD AES-GCM authenticated decryption on a data buffer and additional authenticated data (AAD).\r
+\r
+  IvSize must be 12, otherwise FALSE is returned.\r
+  KeySize must be 16, 24 or 32, otherwise FALSE is returned.\r
+  TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.\r
+  If additional authenticated data verification fails, FALSE is returned.\r
+\r
+  @param[in]   Key         Pointer to the encryption key.\r
+  @param[in]   KeySize     Size of the encryption key in bytes.\r
+  @param[in]   Iv          Pointer to the IV value.\r
+  @param[in]   IvSize      Size of the IV value in bytes.\r
+  @param[in]   AData       Pointer to the additional authenticated data (AAD).\r
+  @param[in]   ADataSize   Size of the additional authenticated data (AAD) in bytes.\r
+  @param[in]   DataIn      Pointer to the input data buffer to be decrypted.\r
+  @param[in]   DataInSize  Size of the input data buffer in bytes.\r
+  @param[in]   Tag         Pointer to a buffer that contains the authentication tag.\r
+  @param[in]   TagSize     Size of the authentication tag in bytes.\r
+  @param[out]  DataOut     Pointer to a buffer that receives the decryption output.\r
+  @param[out]  DataOutSize Size of the output data buffer in bytes.\r
+\r
+  @retval TRUE   AEAD AES-GCM authenticated decryption succeeded.\r
+  @retval FALSE  AEAD AES-GCM authenticated decryption failed.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+CryptoServiceAeadAesGcmDecrypt (\r
+  IN   CONST UINT8  *Key,\r
+  IN   UINTN        KeySize,\r
+  IN   CONST UINT8  *Iv,\r
+  IN   UINTN        IvSize,\r
+  IN   CONST UINT8  *AData,\r
+  IN   UINTN        ADataSize,\r
+  IN   CONST UINT8  *DataIn,\r
+  IN   UINTN        DataInSize,\r
+  IN   CONST UINT8  *Tag,\r
+  IN   UINTN        TagSize,\r
+  OUT  UINT8        *DataOut,\r
+  OUT  UINTN        *DataOutSize\r
+  )\r
+{\r
+  return CALL_BASECRYPTLIB (AeadAesGcm.Services.Decrypt, AeadAesGcmDecrypt, (Key, KeySize, Iv, IvSize, AData, ADataSize, DataIn, DataInSize, Tag, TagSize, DataOut, DataOutSize), FALSE);\r
+}\r
+\r
 const EDKII_CRYPTO_PROTOCOL  mEdkiiCrypto = {\r
   /// Version\r
   CryptoServiceGetCryptoVersion,\r
@@ -5159,5 +5248,8 @@ const EDKII_CRYPTO_PROTOCOL  mEdkiiCrypto = {
   CryptoServiceHkdfSha256Expand,\r
   CryptoServiceHkdfSha384ExtractAndExpand,\r
   CryptoServiceHkdfSha384Extract,\r
-  CryptoServiceHkdfSha384Expand\r
+  CryptoServiceHkdfSha384Expand,\r
+  /// Aead Aes GCM\r
+  CryptoServiceAeadAesGcmEncrypt,\r
+  CryptoServiceAeadAesGcmDecrypt\r
 };\r