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:
Qin Long
2016-11-01 10:25:30 +08:00
parent 90a4021967
commit b7d1ba0a8a
9 changed files with 589 additions and 10 deletions

View File

@@ -1,7 +1,7 @@
/** @file
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
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;