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