]> git.proxmox.com Git - mirror_edk2.git/commitdiff
CryptoPkg: Add new hmac SHA api to Crypto Service.
authorQi Zhang <qi1.zhang@intel.com>
Fri, 23 Sep 2022 01:14:51 +0000 (09:14 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 23 Sep 2022 06:55:58 +0000 (06:55 +0000)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4025

Signed-off-by: Qi Zhang <qi1.zhang@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Xiaoyu Lu <xiaoyu1.lu@intel.com>
Cc: Guomin Jiang <guomin.jiang@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
CryptoPkg/CryptoPkg.dsc
CryptoPkg/Driver/Crypto.c
CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c

index 50e7721f25b851072df29b8dd6926a07ec392e89..417804f64f069f81dd9c055d709502b219ad5567 100644 (file)
 \r
 !if $(CRYPTO_SERVICES) IN "PACKAGE ALL"\r
   gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.HmacSha256.Family                        | PCD_CRYPTO_SERVICE_ENABLE_FAMILY\r
+  gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.HmacSha384.Family                        | PCD_CRYPTO_SERVICE_ENABLE_FAMILY\r
   gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.Md5.Family                               | PCD_CRYPTO_SERVICE_ENABLE_FAMILY\r
   gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.Pkcs.Family                              | PCD_CRYPTO_SERVICE_ENABLE_FAMILY\r
   gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.Dh.Family                                | PCD_CRYPTO_SERVICE_ENABLE_FAMILY\r
 \r
 !if $(CRYPTO_SERVICES) == MIN_PEI\r
   gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.HmacSha256.Family               | PCD_CRYPTO_SERVICE_ENABLE_FAMILY\r
+  gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.HmacSha384.Family               | PCD_CRYPTO_SERVICE_ENABLE_FAMILY\r
   gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.Sha1.Family                     | PCD_CRYPTO_SERVICE_ENABLE_FAMILY\r
   gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.Sha256.Family                   | PCD_CRYPTO_SERVICE_ENABLE_FAMILY\r
   gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.Sha384.Family                   | PCD_CRYPTO_SERVICE_ENABLE_FAMILY\r
 \r
 !if $(CRYPTO_SERVICES) == MIN_DXE_MIN_SMM\r
   gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.HmacSha256.Family                        | PCD_CRYPTO_SERVICE_ENABLE_FAMILY\r
+  gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.HmacSha384.Family                        | PCD_CRYPTO_SERVICE_ENABLE_FAMILY\r
   gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.Pkcs.Services.Pkcs1v2Encrypt             | TRUE\r
   gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.Pkcs.Services.Pkcs5HashPassword          | TRUE\r
   gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.Pkcs.Services.Pkcs7Verify                | TRUE\r
index 76cb9f4da0a4b5b92ca6b477d9e332459734c59e..d99be08022b304e19a046a0e9ae4728f3976acbe 100644 (file)
@@ -1847,6 +1847,218 @@ CryptoServiceHmacSha256Final (
   return CALL_BASECRYPTLIB (HmacSha256.Services.Final, HmacSha256Final, (HmacSha256Context, HmacValue), FALSE);\r
 }\r
 \r
+/**\r
+  Computes the HMAC-SHA256 digest of a input data buffer.\r
+\r
+  This function performs the HMAC-SHA256 digest of a given data buffer, and places\r
+  the digest value into the specified memory.\r
+\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[in]   Data        Pointer to the buffer containing the data to be digested.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[in]   Key         Pointer to the user-supplied key.\r
+  @param[in]   KeySize     Key size in bytes.\r
+  @param[out]  HmacValue   Pointer to a buffer that receives the HMAC-SHA256 digest\r
+                           value (32 bytes).\r
+\r
+  @retval TRUE   HMAC-SHA256 digest computation succeeded.\r
+  @retval FALSE  HMAC-SHA256 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+CryptoServiceHmacSha256All (\r
+  IN   CONST VOID   *Data,\r
+  IN   UINTN        DataSize,\r
+  IN   CONST UINT8  *Key,\r
+  IN   UINTN        KeySize,\r
+  OUT  UINT8        *HmacValue\r
+  )\r
+{\r
+  return CALL_BASECRYPTLIB (HmacSha256.Services.All, HmacSha256All, (Data, DataSize, Key, KeySize, HmacValue), FALSE);\r
+}\r
+\r
+/**\r
+  Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA384 use.\r
+\r
+  @return  Pointer to the HMAC_CTX context that has been initialized.\r
+           If the allocations fails, HmacSha384New() returns NULL.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+CryptoServiceHmacSha384New (\r
+  VOID\r
+  )\r
+{\r
+  return CALL_BASECRYPTLIB (HmacSha384.Services.New, HmacSha384New, (), NULL);\r
+}\r
+\r
+/**\r
+  Release the specified HMAC_CTX context.\r
+\r
+  @param[in]  HmacSha384Ctx  Pointer to the HMAC_CTX context to be released.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+CryptoServiceHmacSha384Free (\r
+  IN  VOID  *HmacSha384Ctx\r
+  )\r
+{\r
+  CALL_VOID_BASECRYPTLIB (HmacSha384.Services.Free, HmacSha384Free, (HmacSha384Ctx));\r
+}\r
+\r
+/**\r
+  Set user-supplied key for subsequent use. It must be done before any\r
+  calling to HmacSha384Update().\r
+\r
+  If HmacSha384Context is NULL, then return FALSE.\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[out]  HmacSha384Context  Pointer to HMAC-SHA384 context.\r
+  @param[in]   Key                Pointer to the user-supplied key.\r
+  @param[in]   KeySize            Key size in bytes.\r
+\r
+  @retval TRUE   The Key is set successfully.\r
+  @retval FALSE  The Key is set unsuccessfully.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+CryptoServiceHmacSha384SetKey (\r
+  OUT  VOID         *HmacSha384Context,\r
+  IN   CONST UINT8  *Key,\r
+  IN   UINTN        KeySize\r
+  )\r
+{\r
+  return CALL_BASECRYPTLIB (HmacSha384.Services.SetKey, HmacSha384SetKey, (HmacSha384Context, Key, KeySize), FALSE);\r
+}\r
+\r
+/**\r
+  Makes a copy of an existing HMAC-SHA384 context.\r
+\r
+  If HmacSha384Context is NULL, then return FALSE.\r
+  If NewHmacSha384Context is NULL, then return FALSE.\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[in]  HmacSha384Context     Pointer to HMAC-SHA384 context being copied.\r
+  @param[out] NewHmacSha384Context  Pointer to new HMAC-SHA384 context.\r
+\r
+  @retval TRUE   HMAC-SHA384 context copy succeeded.\r
+  @retval FALSE  HMAC-SHA384 context copy failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+CryptoServiceHmacSha384Duplicate (\r
+  IN   CONST VOID  *HmacSha384Context,\r
+  OUT  VOID        *NewHmacSha384Context\r
+  )\r
+{\r
+  return CALL_BASECRYPTLIB (HmacSha384.Services.Duplicate, HmacSha256Duplicate, (HmacSha384Context, NewHmacSha384Context), FALSE);\r
+}\r
+\r
+/**\r
+  Digests the input data and updates HMAC-SHA384 context.\r
+\r
+  This function performs HMAC-SHA384 digest on a data buffer of the specified size.\r
+  It can be called multiple times to compute the digest of long or discontinuous data streams.\r
+  HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized\r
+  by HmacSha384Final(). Behavior with invalid context is undefined.\r
+\r
+  If HmacSha384Context is NULL, then return FALSE.\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[in, out]  HmacSha384Context Pointer to the HMAC-SHA384 context.\r
+  @param[in]       Data              Pointer to the buffer containing the data to be digested.\r
+  @param[in]       DataSize          Size of Data buffer in bytes.\r
+\r
+  @retval TRUE   HMAC-SHA384 data digest succeeded.\r
+  @retval FALSE  HMAC-SHA384 data digest failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+CryptoServiceHmacSha384Update (\r
+  IN OUT  VOID        *HmacSha384Context,\r
+  IN      CONST VOID  *Data,\r
+  IN      UINTN       DataSize\r
+  )\r
+{\r
+  return CALL_BASECRYPTLIB (HmacSha384.Services.Update, HmacSha384Update, (HmacSha384Context, Data, DataSize), FALSE);\r
+}\r
+\r
+/**\r
+  Completes computation of the HMAC-SHA384 digest value.\r
+\r
+  This function completes HMAC-SHA384 hash computation and retrieves the digest value into\r
+  the specified memory. After this function has been called, the HMAC-SHA384 context cannot\r
+  be used again.\r
+  HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized\r
+  by HmacSha384Final(). Behavior with invalid HMAC-SHA384 context is undefined.\r
+\r
+  If HmacSha384Context is NULL, then return FALSE.\r
+  If HmacValue is NULL, then return FALSE.\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[in, out]  HmacSha384Context  Pointer to the HMAC-SHA384 context.\r
+  @param[out]      HmacValue          Pointer to a buffer that receives the HMAC-SHA384 digest\r
+                                      value (48 bytes).\r
+\r
+  @retval TRUE   HMAC-SHA384 digest computation succeeded.\r
+  @retval FALSE  HMAC-SHA384 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+CryptoServiceHmacSha384Final (\r
+  IN OUT  VOID   *HmacSha384Context,\r
+  OUT     UINT8  *HmacValue\r
+  )\r
+{\r
+  return CALL_BASECRYPTLIB (HmacSha384.Services.Final, HmacSha384Final, (HmacSha384Context, HmacValue), FALSE);\r
+}\r
+\r
+/**\r
+  Computes the HMAC-SHA384 digest of a input data buffer.\r
+\r
+  This function performs the HMAC-SHA384 digest of a given data buffer, and places\r
+  the digest value into the specified memory.\r
+\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[in]   Data        Pointer to the buffer containing the data to be digested.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[in]   Key         Pointer to the user-supplied key.\r
+  @param[in]   KeySize     Key size in bytes.\r
+  @param[out]  HmacValue   Pointer to a buffer that receives the HMAC-SHA384 digest\r
+                           value (48 bytes).\r
+\r
+  @retval TRUE   HMAC-SHA384 digest computation succeeded.\r
+  @retval FALSE  HMAC-SHA384 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+CryptoServiceHmacSha384All (\r
+  IN   CONST VOID   *Data,\r
+  IN   UINTN        DataSize,\r
+  IN   CONST UINT8  *Key,\r
+  IN   UINTN        KeySize,\r
+  OUT  UINT8        *HmacValue\r
+  )\r
+{\r
+  return CALL_BASECRYPTLIB (HmacSha384.Services.All, HmacSha384All, (Data, DataSize, Key, KeySize, HmacValue), FALSE);\r
+}\r
+\r
 // =====================================================================================\r
 //    Symmetric Cryptography Primitive\r
 // =====================================================================================\r
@@ -4787,5 +4999,15 @@ const EDKII_CRYPTO_PROTOCOL  mEdkiiCrypto = {
   CryptoServiceRsaPssSign,\r
   CryptoServiceRsaPssVerify,\r
   /// Parallel hash\r
-  CryptoServiceParallelHash256HashAll\r
+  CryptoServiceParallelHash256HashAll,\r
+  /// HMAC SHA256 (continued)\r
+  CryptoServiceHmacSha256All,\r
+  /// HMAC SHA384\r
+  CryptoServiceHmacSha384New,\r
+  CryptoServiceHmacSha384Free,\r
+  CryptoServiceHmacSha384SetKey,\r
+  CryptoServiceHmacSha384Duplicate,\r
+  CryptoServiceHmacSha384Update,\r
+  CryptoServiceHmacSha384Final,\r
+  CryptoServiceHmacSha384All\r
 };\r
index 8ee1b53cf957a5ee7109cc8fd249b9eb69aec239..0218e9b59419a4fd3851e3ec5957f9802eb9e710 100644 (file)
@@ -1201,6 +1201,218 @@ HmacSha256Final (
   CALL_CRYPTO_SERVICE (HmacSha256Final, (HmacSha256Context, HmacValue), FALSE);\r
 }\r
 \r
+/**\r
+  Computes the HMAC-SHA256 digest of a input data buffer.\r
+\r
+  This function performs the HMAC-SHA256 digest of a given data buffer, and places\r
+  the digest value into the specified memory.\r
+\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[in]   Data        Pointer to the buffer containing the data to be digested.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[in]   Key         Pointer to the user-supplied key.\r
+  @param[in]   KeySize     Key size in bytes.\r
+  @param[out]  HmacValue   Pointer to a buffer that receives the HMAC-SHA256 digest\r
+                           value (32 bytes).\r
+\r
+  @retval TRUE   HMAC-SHA256 digest computation succeeded.\r
+  @retval FALSE  HMAC-SHA256 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+HmacSha256All (\r
+  IN   CONST VOID   *Data,\r
+  IN   UINTN        DataSize,\r
+  IN   CONST UINT8  *Key,\r
+  IN   UINTN        KeySize,\r
+  OUT  UINT8        *HmacValue\r
+  )\r
+{\r
+  CALL_CRYPTO_SERVICE (HmacSha256All, (Data, DataSize, Key, KeySize, HmacValue), FALSE);\r
+}\r
+\r
+/**\r
+  Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA384 use.\r
+\r
+  @return  Pointer to the HMAC_CTX context that has been initialized.\r
+           If the allocations fails, HmacSha384New() returns NULL.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+HmacSha384New (\r
+  VOID\r
+  )\r
+{\r
+  CALL_CRYPTO_SERVICE (HmacSha384New, (), NULL);\r
+}\r
+\r
+/**\r
+  Release the specified HMAC_CTX context.\r
+\r
+  @param[in]  HmacSha384Ctx  Pointer to the HMAC_CTX context to be released.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+HmacSha384Free (\r
+  IN  VOID  *HmacSha384Ctx\r
+  )\r
+{\r
+  CALL_VOID_CRYPTO_SERVICE (HmacSha384Free, (HmacSha384Ctx));\r
+}\r
+\r
+/**\r
+  Set user-supplied key for subsequent use. It must be done before any\r
+  calling to HmacSha384Update().\r
+\r
+  If HmacSha384Context is NULL, then return FALSE.\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[out]  HmacSha384Context  Pointer to HMAC-SHA384 context.\r
+  @param[in]   Key                Pointer to the user-supplied key.\r
+  @param[in]   KeySize            Key size in bytes.\r
+\r
+  @retval TRUE   The Key is set successfully.\r
+  @retval FALSE  The Key is set unsuccessfully.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+HmacSha384SetKey (\r
+  OUT  VOID         *HmacSha384Context,\r
+  IN   CONST UINT8  *Key,\r
+  IN   UINTN        KeySize\r
+  )\r
+{\r
+  CALL_CRYPTO_SERVICE (HmacSha384SetKey, (HmacSha384Context, Key, KeySize), FALSE);\r
+}\r
+\r
+/**\r
+  Makes a copy of an existing HMAC-SHA384 context.\r
+\r
+  If HmacSha384Context is NULL, then return FALSE.\r
+  If NewHmacSha384Context is NULL, then return FALSE.\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[in]  HmacSha384Context     Pointer to HMAC-SHA384 context being copied.\r
+  @param[out] NewHmacSha384Context  Pointer to new HMAC-SHA384 context.\r
+\r
+  @retval TRUE   HMAC-SHA384 context copy succeeded.\r
+  @retval FALSE  HMAC-SHA384 context copy failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+HmacSha384Duplicate (\r
+  IN   CONST VOID  *HmacSha384Context,\r
+  OUT  VOID        *NewHmacSha384Context\r
+  )\r
+{\r
+  CALL_CRYPTO_SERVICE (HmacSha384Duplicate, (HmacSha384Context, NewHmacSha384Context), FALSE);\r
+}\r
+\r
+/**\r
+  Digests the input data and updates HMAC-SHA384 context.\r
+\r
+  This function performs HMAC-SHA384 digest on a data buffer of the specified size.\r
+  It can be called multiple times to compute the digest of long or discontinuous data streams.\r
+  HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized\r
+  by HmacSha384Final(). Behavior with invalid context is undefined.\r
+\r
+  If HmacSha384Context is NULL, then return FALSE.\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[in, out]  HmacSha384Context Pointer to the HMAC-SHA384 context.\r
+  @param[in]       Data              Pointer to the buffer containing the data to be digested.\r
+  @param[in]       DataSize          Size of Data buffer in bytes.\r
+\r
+  @retval TRUE   HMAC-SHA384 data digest succeeded.\r
+  @retval FALSE  HMAC-SHA384 data digest failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+HmacSha384Update (\r
+  IN OUT  VOID        *HmacSha384Context,\r
+  IN      CONST VOID  *Data,\r
+  IN      UINTN       DataSize\r
+  )\r
+{\r
+  CALL_CRYPTO_SERVICE (HmacSha384Update, (HmacSha384Context, Data, DataSize), FALSE);\r
+}\r
+\r
+/**\r
+  Completes computation of the HMAC-SHA384 digest value.\r
+\r
+  This function completes HMAC-SHA384 hash computation and retrieves the digest value into\r
+  the specified memory. After this function has been called, the HMAC-SHA384 context cannot\r
+  be used again.\r
+  HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized\r
+  by HmacSha384Final(). Behavior with invalid HMAC-SHA384 context is undefined.\r
+\r
+  If HmacSha384Context is NULL, then return FALSE.\r
+  If HmacValue is NULL, then return FALSE.\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[in, out]  HmacSha384Context  Pointer to the HMAC-SHA384 context.\r
+  @param[out]      HmacValue          Pointer to a buffer that receives the HMAC-SHA384 digest\r
+                                      value (48 bytes).\r
+\r
+  @retval TRUE   HMAC-SHA384 digest computation succeeded.\r
+  @retval FALSE  HMAC-SHA384 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+HmacSha384Final (\r
+  IN OUT  VOID   *HmacSha384Context,\r
+  OUT     UINT8  *HmacValue\r
+  )\r
+{\r
+  CALL_CRYPTO_SERVICE (HmacSha384Final, (HmacSha384Context, HmacValue), FALSE);\r
+}\r
+\r
+/**\r
+  Computes the HMAC-SHA384 digest of a input data buffer.\r
+\r
+  This function performs the HMAC-SHA384 digest of a given data buffer, and places\r
+  the digest value into the specified memory.\r
+\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[in]   Data        Pointer to the buffer containing the data to be digested.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[in]   Key         Pointer to the user-supplied key.\r
+  @param[in]   KeySize     Key size in bytes.\r
+  @param[out]  HmacValue   Pointer to a buffer that receives the HMAC-SHA384 digest\r
+                           value (48 bytes).\r
+\r
+  @retval TRUE   HMAC-SHA384 digest computation succeeded.\r
+  @retval FALSE  HMAC-SHA384 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+HmacSha384All (\r
+  IN   CONST VOID   *Data,\r
+  IN   UINTN        DataSize,\r
+  IN   CONST UINT8  *Key,\r
+  IN   UINTN        KeySize,\r
+  OUT  UINT8        *HmacValue\r
+  )\r
+{\r
+  CALL_CRYPTO_SERVICE (HmacSha384All, (Data, DataSize, Key, KeySize, HmacValue), FALSE);\r
+}\r
+\r
 // =====================================================================================\r
 //    Symmetric Cryptography Primitive\r
 // =====================================================================================\r