Re: [edk2] [PATCH v2] CryptoPkg: Add xxxxHashAll APIs to facilitate the digest computation

2016-11-02 Thread Ye, Ting
Reviewed-by: Ye Ting  

-Original Message-
From: Long, Qin 
Sent: Tuesday, November 01, 2016 10:34 AM
To: edk2-devel@lists.01.org
Cc: Ye, Ting 
Subject: [PATCH v2] CryptoPkg: Add HashAll APIs to facilitate the digest 
computation

Add new HashAll 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 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qin Long 
---
 CryptoPkg/Application/Cryptest/HashVerify.c|  76 +-
 CryptoPkg/Include/Library/BaseCryptLib.h   | 158 -
 CryptoPkg/Library/BaseCryptLib/Hash/CryptMd4.c |  48 ++-
 CryptoPkg/Library/BaseCryptLib/Hash/CryptMd4Null.c |  27 +++-
 CryptoPkg/Library/BaseCryptLib/Hash/CryptMd5.c |  48 ++-
 CryptoPkg/Library/BaseCryptLib/Hash/CryptSha1.c|  48 ++-
 CryptoPkg/Library/BaseCryptLib/Hash/CryptSha256.c  |  48 ++-  
CryptoPkg/Library/BaseCryptLib/Hash/CryptSha512.c  |  94 +++-
 .../Library/BaseCryptLib/Hash/CryptSha512Null.c|  52 ++-
 9 files changed, 589 insertions(+), 10 deletions(-)

diff --git a/CryptoPkg/Application/Cryptest/HashVerify.c 
b/CryptoPkg/Application/Cryptest/HashVerify.c
index ca64361..a35cad5 100644
--- a/CryptoPkg/Application/Cryptest/HashVerify.c
+++ b/CryptoPkg/Application/Cryptest/HashVerify.c
@@ -1,7 +1,7 @@
 /** @file
   Application for Hash Primitives Validation.
 
-Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
 This program and the accompanying materials  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 @@ -127,7 +127,19 
@@ ValidateCryptDigest (
   FreePool (HashCtx);
 
   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]");
 return EFI_ABORTED;
   }
@@ -172,6 +184,18 @@ ValidateCryptDigest (
 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"- SHA1:   ");
@@ -212,6 +236,18 @@ ValidateCryptDigest (
 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"- SHA256: ");
@@ -252,6 +288,18 @@ ValidateCryptDigest (
 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"- SHA384: ");
@@ -292,6 +340,18 @@ ValidateCryptDigest (
 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"- SHA512: ");
@@ -332,6 +392,18 @@ ValidateCryptDigest (
 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");
 
   return EFI_SUCCESS;
diff --git a/CryptoPkg/Include/Library/BaseCryptLib.h 
b/CryptoPkg/Include/Library/BaseCryptLib.h
index 0371d73..3463626 100644
--- a/CryptoPkg/Include/Library/BaseCryptLib.h
+++ 

[edk2] [PATCH v2] CryptoPkg: Add xxxxHashAll APIs to facilitate the digest computation

2016-10-31 Thread Qin Long
Add new HashAll 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 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qin Long 
---
 CryptoPkg/Application/Cryptest/HashVerify.c|  76 +-
 CryptoPkg/Include/Library/BaseCryptLib.h   | 158 -
 CryptoPkg/Library/BaseCryptLib/Hash/CryptMd4.c |  48 ++-
 CryptoPkg/Library/BaseCryptLib/Hash/CryptMd4Null.c |  27 +++-
 CryptoPkg/Library/BaseCryptLib/Hash/CryptMd5.c |  48 ++-
 CryptoPkg/Library/BaseCryptLib/Hash/CryptSha1.c|  48 ++-
 CryptoPkg/Library/BaseCryptLib/Hash/CryptSha256.c  |  48 ++-
 CryptoPkg/Library/BaseCryptLib/Hash/CryptSha512.c  |  94 +++-
 .../Library/BaseCryptLib/Hash/CryptSha512Null.c|  52 ++-
 9 files changed, 589 insertions(+), 10 deletions(-)

diff --git a/CryptoPkg/Application/Cryptest/HashVerify.c 
b/CryptoPkg/Application/Cryptest/HashVerify.c
index ca64361..a35cad5 100644
--- a/CryptoPkg/Application/Cryptest/HashVerify.c
+++ b/CryptoPkg/Application/Cryptest/HashVerify.c
@@ -1,7 +1,7 @@
 /** @file
   Application for Hash Primitives Validation.
 
-Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
 This program and the accompanying materials
 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
@@ -127,7 +127,19 @@ ValidateCryptDigest (
   FreePool (HashCtx);
 
   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]");
 return EFI_ABORTED;
   }
@@ -172,6 +184,18 @@ ValidateCryptDigest (
 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"- SHA1:   ");
@@ -212,6 +236,18 @@ ValidateCryptDigest (
 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"- SHA256: ");
@@ -252,6 +288,18 @@ ValidateCryptDigest (
 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"- SHA384: ");
@@ -292,6 +340,18 @@ ValidateCryptDigest (
 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"- SHA512: ");
@@ -332,6 +392,18 @@ ValidateCryptDigest (
 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");
 
   return EFI_SUCCESS;
diff --git a/CryptoPkg/Include/Library/BaseCryptLib.h 
b/CryptoPkg/Include/Library/BaseCryptLib.h
index 0371d73..3463626 100644
--- a/CryptoPkg/Include/Library/BaseCryptLib.h
+++ b/CryptoPkg/Include/Library/BaseCryptLib.h
@@ -4,7 +4,7 @@
   primitives (Hash Serials, HMAC, RSA, Diffie-Hellman, etc) for UEFI security
   functionality enabling.
 
-Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2016, Intel Corporation. All