]> git.proxmox.com Git - mirror_edk2.git/commitdiff
CryptoPkg: Add xxxxHashAll APIs to facilitate the digest computation
authorQin Long <qin.long@intel.com>
Tue, 1 Nov 2016 02:25:30 +0000 (10:25 +0800)
committerQin Long <qin.long@intel.com>
Wed, 2 Nov 2016 15:16:10 +0000 (23:16 +0800)
Add new xxxxHashAll APIs to facilitate the digest computation of blob
data. New APIs include: Md4HashAll(), Md5HashAll(), Sha1HashAll(),
Sha256HashAll(), Sha384HashAll(), and Sha512HashAll().

The corresponding test cases were added in Cryptest utility.

Cc: Ting Ye <ting.ye@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qin Long <qin.long@intel.com>
Reviewed-by: Ting Ye <ting.ye@intel.com>
CryptoPkg/Application/Cryptest/HashVerify.c
CryptoPkg/Include/Library/BaseCryptLib.h
CryptoPkg/Library/BaseCryptLib/Hash/CryptMd4.c
CryptoPkg/Library/BaseCryptLib/Hash/CryptMd4Null.c
CryptoPkg/Library/BaseCryptLib/Hash/CryptMd5.c
CryptoPkg/Library/BaseCryptLib/Hash/CryptSha1.c
CryptoPkg/Library/BaseCryptLib/Hash/CryptSha256.c
CryptoPkg/Library/BaseCryptLib/Hash/CryptSha512.c
CryptoPkg/Library/BaseCryptLib/Hash/CryptSha512Null.c

index ca64361c3890a3eeafed0672af78e70a10c11942..a35cad5b52775a1f973a38c3cc5f4b6514133ecd 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Application for Hash Primitives Validation.\r
 \r
 /** @file\r
   Application for Hash Primitives Validation.\r
 \r
-Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -127,7 +127,19 @@ ValidateCryptDigest (
   FreePool (HashCtx);\r
 \r
   Print (L"Check Value... ");\r
   FreePool (HashCtx);\r
 \r
   Print (L"Check Value... ");\r
-  if (CompareMem (Digest, Md4Digest, MD5_DIGEST_SIZE) != 0) {\r
+  if (CompareMem (Digest, Md4Digest, MD4_DIGEST_SIZE) != 0) {\r
+    Print (L"[Fail]");\r
+    return EFI_ABORTED;\r
+  }\r
+\r
+  Print (L"HashAll... ");\r
+  ZeroMem (Digest, MD5_DIGEST_SIZE);\r
+  Status  = Md4HashAll (HashData, DataSize, Digest);\r
+  if (!Status) {\r
+    Print (L"[Fail]");\r
+    return EFI_ABORTED;\r
+  }\r
+  if (CompareMem (Digest, Md4Digest, MD4_DIGEST_SIZE) != 0) {\r
     Print (L"[Fail]");\r
     return EFI_ABORTED;\r
   }\r
     Print (L"[Fail]");\r
     return EFI_ABORTED;\r
   }\r
@@ -172,6 +184,18 @@ ValidateCryptDigest (
     return EFI_ABORTED;\r
   }\r
 \r
     return EFI_ABORTED;\r
   }\r
 \r
+  Print (L"HashAll... ");\r
+  ZeroMem (Digest, MD5_DIGEST_SIZE);\r
+  Status  = Md5HashAll (HashData, DataSize, Digest);\r
+  if (!Status) {\r
+    Print (L"[Fail]");\r
+    return EFI_ABORTED;\r
+  }\r
+  if (CompareMem (Digest, Md5Digest, MD5_DIGEST_SIZE) != 0) {\r
+    Print (L"[Fail]");\r
+    return EFI_ABORTED;\r
+  }\r
+\r
   Print (L"[Pass]\n");\r
 \r
   Print (L"- SHA1:   ");\r
   Print (L"[Pass]\n");\r
 \r
   Print (L"- SHA1:   ");\r
@@ -212,6 +236,18 @@ ValidateCryptDigest (
     return EFI_ABORTED;\r
   }\r
 \r
     return EFI_ABORTED;\r
   }\r
 \r
+  Print (L"HashAll... ");\r
+  ZeroMem (Digest, SHA1_DIGEST_SIZE);\r
+  Status  = Sha1HashAll (HashData, DataSize, Digest);\r
+  if (!Status) {\r
+    Print (L"[Fail]");\r
+    return EFI_ABORTED;\r
+  }\r
+  if (CompareMem (Digest, Sha1Digest, SHA1_DIGEST_SIZE) != 0) {\r
+    Print (L"[Fail]");\r
+    return EFI_ABORTED;\r
+  }\r
+\r
   Print (L"[Pass]\n");\r
 \r
   Print (L"- SHA256: ");\r
   Print (L"[Pass]\n");\r
 \r
   Print (L"- SHA256: ");\r
@@ -252,6 +288,18 @@ ValidateCryptDigest (
     return EFI_ABORTED;\r
   }\r
 \r
     return EFI_ABORTED;\r
   }\r
 \r
+  Print (L"HashAll... ");\r
+  ZeroMem (Digest, SHA256_DIGEST_SIZE);\r
+  Status  = Sha256HashAll (HashData, DataSize, Digest);\r
+  if (!Status) {\r
+    Print (L"[Fail]");\r
+    return EFI_ABORTED;\r
+  }\r
+  if (CompareMem (Digest, Sha256Digest, SHA256_DIGEST_SIZE) != 0) {\r
+    Print (L"[Fail]");\r
+    return EFI_ABORTED;\r
+  }\r
+\r
   Print (L"[Pass]\n");\r
 \r
   Print (L"- SHA384: ");\r
   Print (L"[Pass]\n");\r
 \r
   Print (L"- SHA384: ");\r
@@ -292,6 +340,18 @@ ValidateCryptDigest (
     return EFI_ABORTED;\r
   }\r
 \r
     return EFI_ABORTED;\r
   }\r
 \r
+  Print (L"HashAll... ");\r
+  ZeroMem (Digest, SHA384_DIGEST_SIZE);\r
+  Status  = Sha384HashAll (HashData, DataSize, Digest);\r
+  if (!Status) {\r
+    Print (L"[Fail]");\r
+    return EFI_ABORTED;\r
+  }\r
+  if (CompareMem (Digest, Sha384Digest, SHA384_DIGEST_SIZE) != 0) {\r
+    Print (L"[Fail]");\r
+    return EFI_ABORTED;\r
+  }\r
+\r
   Print (L"[Pass]\n");\r
 \r
   Print (L"- SHA512: ");\r
   Print (L"[Pass]\n");\r
 \r
   Print (L"- SHA512: ");\r
@@ -332,6 +392,18 @@ ValidateCryptDigest (
     return EFI_ABORTED;\r
   }\r
 \r
     return EFI_ABORTED;\r
   }\r
 \r
+  Print (L"HashAll... ");\r
+  ZeroMem (Digest, SHA512_DIGEST_SIZE);\r
+  Status  = Sha512HashAll (HashData, DataSize, Digest);\r
+  if (!Status) {\r
+    Print (L"[Fail]");\r
+    return EFI_ABORTED;\r
+  }\r
+  if (CompareMem (Digest, Sha512Digest, SHA512_DIGEST_SIZE) != 0) {\r
+    Print (L"[Fail]");\r
+    return EFI_ABORTED;\r
+  }\r
+\r
   Print (L"[Pass]\n");\r
 \r
   return EFI_SUCCESS;\r
   Print (L"[Pass]\n");\r
 \r
   return EFI_SUCCESS;\r
index 0371d73b86b17630c6d89ecd95c44006068197d7..346362678533f74e6b854249f244099f237f0f44 100644 (file)
@@ -4,7 +4,7 @@
   primitives (Hash Serials, HMAC, RSA, Diffie-Hellman, etc) for UEFI security\r
   functionality enabling.\r
 \r
   primitives (Hash Serials, HMAC, RSA, Diffie-Hellman, etc) for UEFI security\r
   functionality enabling.\r
 \r
-Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -192,6 +192,32 @@ Md4Final (
   OUT     UINT8  *HashValue\r
   );\r
 \r
   OUT     UINT8  *HashValue\r
   );\r
 \r
+/**\r
+  Computes the MD4 message digest of a input data buffer.\r
+\r
+  This function performs the MD4 message 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 hashed.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[out]  HashValue   Pointer to a buffer that receives the MD4 digest\r
+                           value (16 bytes).\r
+\r
+  @retval TRUE   MD4 digest computation succeeded.\r
+  @retval FALSE  MD4 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Md4HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  );\r
+\r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r
 \r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r
 \r
@@ -306,6 +332,32 @@ Md5Final (
   OUT     UINT8  *HashValue\r
   );\r
 \r
   OUT     UINT8  *HashValue\r
   );\r
 \r
+/**\r
+  Computes the MD5 message digest of a input data buffer.\r
+\r
+  This function performs the MD5 message 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 hashed.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[out]  HashValue   Pointer to a buffer that receives the MD5 digest\r
+                           value (16 bytes).\r
+\r
+  @retval TRUE   MD5 digest computation succeeded.\r
+  @retval FALSE  MD5 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Md5HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  );\r
+\r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.\r
 \r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.\r
 \r
@@ -420,6 +472,32 @@ Sha1Final (
   OUT     UINT8  *HashValue\r
   );\r
 \r
   OUT     UINT8  *HashValue\r
   );\r
 \r
+/**\r
+  Computes the SHA-1 message digest of a input data buffer.\r
+\r
+  This function performs the SHA-1 message 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 hashed.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[out]  HashValue   Pointer to a buffer that receives the SHA-1 digest\r
+                           value (20 bytes).\r
+\r
+  @retval TRUE   SHA-1 digest computation succeeded.\r
+  @retval FALSE  SHA-1 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Sha1HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  );\r
+\r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.\r
 \r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.\r
 \r
@@ -525,6 +603,32 @@ Sha256Final (
   OUT     UINT8  *HashValue\r
   );\r
 \r
   OUT     UINT8  *HashValue\r
   );\r
 \r
+/**\r
+  Computes the SHA-256 message digest of a input data buffer.\r
+\r
+  This function performs the SHA-256 message 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 hashed.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[out]  HashValue   Pointer to a buffer that receives the SHA-256 digest\r
+                           value (32 bytes).\r
+\r
+  @retval TRUE   SHA-256 digest computation succeeded.\r
+  @retval FALSE  SHA-256 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Sha256HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  );\r
+\r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.\r
 \r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.\r
 \r
@@ -630,6 +734,32 @@ Sha384Final (
   OUT     UINT8  *HashValue\r
   );\r
 \r
   OUT     UINT8  *HashValue\r
   );\r
 \r
+/**\r
+  Computes the SHA-384 message digest of a input data buffer.\r
+\r
+  This function performs the SHA-384 message 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 hashed.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[out]  HashValue   Pointer to a buffer that receives the SHA-384 digest\r
+                           value (48 bytes).\r
+\r
+  @retval TRUE   SHA-384 digest computation succeeded.\r
+  @retval FALSE  SHA-384 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Sha384HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  );\r
+\r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.\r
 \r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.\r
 \r
@@ -735,6 +865,32 @@ Sha512Final (
   OUT     UINT8  *HashValue\r
   );\r
 \r
   OUT     UINT8  *HashValue\r
   );\r
 \r
+/**\r
+  Computes the SHA-512 message digest of a input data buffer.\r
+\r
+  This function performs the SHA-512 message 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 hashed.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[out]  HashValue   Pointer to a buffer that receives the SHA-512 digest\r
+                           value (64 bytes).\r
+\r
+  @retval TRUE   SHA-512 digest computation succeeded.\r
+  @retval FALSE  SHA-512 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Sha512HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  );\r
+\r
 //=====================================================================================\r
 //    MAC (Message Authentication Code) Primitive\r
 //=====================================================================================\r
 //=====================================================================================\r
 //    MAC (Message Authentication Code) Primitive\r
 //=====================================================================================\r
index 633d34379032b5c9ad9537e6d709bf2e4813bb66..d9cc4455a883567fd9008d81291fb5c1fd30d8f8 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   MD4 Digest Wrapper Implementation over OpenSSL.\r
 \r
 /** @file\r
   MD4 Digest Wrapper Implementation over OpenSSL.\r
 \r
-Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -181,3 +181,49 @@ Md4Final (
   //\r
   return (BOOLEAN) (MD4_Final (HashValue, (MD4_CTX *) Md4Context));\r
 }\r
   //\r
   return (BOOLEAN) (MD4_Final (HashValue, (MD4_CTX *) Md4Context));\r
 }\r
+\r
+/**\r
+  Computes the MD4 message digest of a input data buffer.\r
+\r
+  This function performs the MD4 message 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 hashed.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[out]  HashValue   Pointer to a buffer that receives the MD4 digest\r
+                           value (16 bytes).\r
+\r
+  @retval TRUE   MD4 digest computation succeeded.\r
+  @retval FALSE  MD4 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Md4HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  )\r
+{\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (HashValue == NULL) {\r
+    return FALSE;\r
+  }\r
+  if (Data == NULL && DataSize != 0) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // OpenSSL MD4 Hash Computation.\r
+  //\r
+  if (MD4 (Data, DataSize, HashValue) == NULL) {\r
+    return FALSE;\r
+  } else {\r
+    return TRUE;\r
+  }\r
+}\r
index fc634fd163878f9aba1bc931f47fe8c26e91ad09..01b3f23da7726d25c335608d60eff0ebb006e057 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   MD4 Digest Wrapper Implementation which does not provide real capabilities.\r
 \r
 /** @file\r
   MD4 Digest Wrapper Implementation which does not provide real capabilities.\r
 \r
-Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -122,3 +122,28 @@ Md4Final (
   ASSERT (FALSE);\r
   return FALSE;\r
 }\r
   ASSERT (FALSE);\r
   return FALSE;\r
 }\r
+\r
+/**\r
+  Computes the MD4 message digest of a input data buffer.\r
+\r
+  Return FALSE to indicate this interface is not supported.\r
+\r
+  @param[in]   Data        Pointer to the buffer containing the data to be hashed.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[out]  HashValue   Pointer to a buffer that receives the MD4 digest\r
+                           value (16 bytes).\r
+\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Md4HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return FALSE;\r
+}\r
index e1c10e342c78ee675412cb1664251725b37d1b07..34eabe95a597fb1a22b8c37bceaa91c7c33fdb94 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   MD5 Digest Wrapper Implementation over OpenSSL.\r
 \r
 /** @file\r
   MD5 Digest Wrapper Implementation over OpenSSL.\r
 \r
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -183,3 +183,49 @@ Md5Final (
   //\r
   return (BOOLEAN) (MD5_Final (HashValue, (MD5_CTX *) Md5Context));\r
 }\r
   //\r
   return (BOOLEAN) (MD5_Final (HashValue, (MD5_CTX *) Md5Context));\r
 }\r
+\r
+/**\r
+  Computes the MD5 message digest of a input data buffer.\r
+\r
+  This function performs the MD5 message 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 hashed.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[out]  HashValue   Pointer to a buffer that receives the MD5 digest\r
+                           value (16 bytes).\r
+\r
+  @retval TRUE   MD5 digest computation succeeded.\r
+  @retval FALSE  MD5 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Md5HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  )\r
+{\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (HashValue == NULL) {\r
+    return FALSE;\r
+  }\r
+  if (Data == NULL && (DataSize != 0)) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // OpenSSL MD5 Hash Computation.\r
+  //\r
+  if (MD5 (Data, DataSize, HashValue) == NULL) {\r
+    return FALSE;\r
+  } else {\r
+    return TRUE;\r
+  }\r
+}\r
index 78c29c1b18558b6a856ebc597de400e4bdcfe327..b8a6d0cda0472adc034f5aab728243f62ddf5096 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SHA-1 Digest Wrapper Implementation over OpenSSL.\r
 \r
 /** @file\r
   SHA-1 Digest Wrapper Implementation over OpenSSL.\r
 \r
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -182,3 +182,49 @@ Sha1Final (
   //\r
   return (BOOLEAN) (SHA1_Final (HashValue, (SHA_CTX *) Sha1Context));\r
 }\r
   //\r
   return (BOOLEAN) (SHA1_Final (HashValue, (SHA_CTX *) Sha1Context));\r
 }\r
+\r
+/**\r
+  Computes the SHA-1 message digest of a input data buffer.\r
+\r
+  This function performs the SHA-1 message 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 hashed.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[out]  HashValue   Pointer to a buffer that receives the SHA-1 digest\r
+                           value (20 bytes).\r
+\r
+  @retval TRUE   SHA-1 digest computation succeeded.\r
+  @retval FALSE  SHA-1 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Sha1HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  )\r
+{\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (HashValue == NULL) {\r
+    return FALSE;\r
+  }\r
+  if (Data == NULL && DataSize != 0) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // OpenSSL SHA-1 Hash Computation.\r
+  //\r
+  if (SHA1 (Data, DataSize, HashValue) == NULL) {\r
+    return FALSE;\r
+  } else {\r
+    return TRUE;\r
+  }\r
+}\r
index 56894aca30d678131290425640366a57ee539aa7..aaf689b361a52c3b57de2f220b49f13dfe9c985b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SHA-256 Digest Wrapper Implementation over OpenSSL.\r
 \r
 /** @file\r
   SHA-256 Digest Wrapper Implementation over OpenSSL.\r
 \r
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -181,3 +181,49 @@ Sha256Final (
   //\r
   return (BOOLEAN) (SHA256_Final (HashValue, (SHA256_CTX *) Sha256Context));\r
 }\r
   //\r
   return (BOOLEAN) (SHA256_Final (HashValue, (SHA256_CTX *) Sha256Context));\r
 }\r
+\r
+/**\r
+  Computes the SHA-256 message digest of a input data buffer.\r
+\r
+  This function performs the SHA-256 message 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 hashed.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[out]  HashValue   Pointer to a buffer that receives the SHA-256 digest\r
+                           value (32 bytes).\r
+\r
+  @retval TRUE   SHA-256 digest computation succeeded.\r
+  @retval FALSE  SHA-256 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Sha256HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  )\r
+{\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (HashValue == NULL) {\r
+    return FALSE;\r
+  }\r
+  if (Data == NULL && DataSize != 0) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // OpenSSL SHA-256 Hash Computation.\r
+  //\r
+  if (SHA256 (Data, DataSize, HashValue) == NULL) {\r
+    return FALSE;\r
+  } else {\r
+    return TRUE;\r
+  }\r
+}\r
index 491f45dce62384c063c296340335ca159230e831..457151ed15cd1afae3d949d9435dbd3a4e611137 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SHA-384 and SHA-512 Digest Wrapper Implementations over OpenSSL.\r
 \r
 /** @file\r
   SHA-384 and SHA-512 Digest Wrapper Implementations over OpenSSL.\r
 \r
-Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -184,6 +184,52 @@ Sha384Final (
   return (BOOLEAN) (SHA384_Final (HashValue, (SHA512_CTX *) Sha384Context));\r
 }\r
 \r
   return (BOOLEAN) (SHA384_Final (HashValue, (SHA512_CTX *) Sha384Context));\r
 }\r
 \r
+/**\r
+  Computes the SHA-384 message digest of a input data buffer.\r
+\r
+  This function performs the SHA-384 message 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 hashed.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[out]  HashValue   Pointer to a buffer that receives the SHA-384 digest\r
+                           value (48 bytes).\r
+\r
+  @retval TRUE   SHA-384 digest computation succeeded.\r
+  @retval FALSE  SHA-384 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Sha384HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  )\r
+{\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (HashValue == NULL) {\r
+    return FALSE;\r
+  }\r
+  if (Data == NULL && DataSize != 0) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // OpenSSL SHA-384 Hash Computation.\r
+  //\r
+  if (SHA384 (Data, DataSize, HashValue) == NULL) {\r
+    return FALSE;\r
+  } else {\r
+    return TRUE;\r
+  }\r
+}\r
+\r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.\r
 \r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.\r
 \r
@@ -352,3 +398,49 @@ Sha512Final (
   //\r
   return (BOOLEAN) (SHA384_Final (HashValue, (SHA512_CTX *) Sha512Context));\r
 }\r
   //\r
   return (BOOLEAN) (SHA384_Final (HashValue, (SHA512_CTX *) Sha512Context));\r
 }\r
+\r
+/**\r
+  Computes the SHA-512 message digest of a input data buffer.\r
+\r
+  This function performs the SHA-512 message 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 hashed.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[out]  HashValue   Pointer to a buffer that receives the SHA-512 digest\r
+                           value (64 bytes).\r
+\r
+  @retval TRUE   SHA-512 digest computation succeeded.\r
+  @retval FALSE  SHA-512 digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Sha512HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  )\r
+{\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (HashValue == NULL) {\r
+    return FALSE;\r
+  }\r
+  if (Data == NULL && DataSize != 0) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // OpenSSL SHA-512 Hash Computation.\r
+  //\r
+  if (SHA512 (Data, DataSize, HashValue) == NULL) {\r
+    return FALSE;\r
+  } else {\r
+    return TRUE;\r
+  }\r
+}\r
index 89aeacc74e776767c3e0ee3e1cfa934fa0eb2a48..8cd754f35851f4e69a005ffb62cb0bef33305c4f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SHA-384 and SHA-512 Digest Wrapper Implementations which does not provide real capabilities.\r
 \r
 /** @file\r
   SHA-384 and SHA-512 Digest Wrapper Implementations which does not provide real capabilities.\r
 \r
-Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -122,6 +122,31 @@ Sha384Final (
   return FALSE;\r
 }\r
 \r
   return FALSE;\r
 }\r
 \r
+/**\r
+  Computes the SHA-384 message digest of a input data buffer.\r
+\r
+  Return FALSE to indicate this interface is not supported.\r
+\r
+  @param[in]   Data        Pointer to the buffer containing the data to be hashed.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[out]  HashValue   Pointer to a buffer that receives the SHA-384 digest\r
+                           value (48 bytes).\r
+\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Sha384HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return FALSE;\r
+}\r
+\r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.\r
 \r
 /**\r
   Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.\r
 \r
@@ -229,3 +254,28 @@ Sha512Final (
   ASSERT (FALSE);\r
   return FALSE;\r
 }\r
   ASSERT (FALSE);\r
   return FALSE;\r
 }\r
+\r
+/**\r
+  Computes the SHA-512 message digest of a input data buffer.\r
+\r
+  Return FALSE to indicate this interface is not supported.\r
+\r
+  @param[in]   Data        Pointer to the buffer containing the data to be hashed.\r
+  @param[in]   DataSize    Size of Data buffer in bytes.\r
+  @param[out]  HashValue   Pointer to a buffer that receives the SHA-512 digest\r
+                           value (64 bytes).\r
+\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+Sha512HashAll (\r
+  IN   CONST VOID  *Data,\r
+  IN   UINTN       DataSize,\r
+  OUT  UINT8       *HashValue\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return FALSE;\r
+}\r