From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com []) by mx.groups.io with SMTP id smtpd.web09.3353.1581796267219933432 for ; Sat, 15 Feb 2020 11:51:09 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: amol.n.sukerkar@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Feb 2020 11:51:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,445,1574150400"; d="scan'208";a="227977281" Received: from ansukerk-desk.amr.corp.intel.com ([10.34.130.122]) by orsmga008.jf.intel.com with ESMTP; 15 Feb 2020 11:51:08 -0800 From: "Sukerkar, Amol N" To: devel@edk2.groups.io Cc: michael.d.kinney@intel.com, jiewen.yao@intel.com, jian.j.wang@intel.com, sachin.agrawal@intel.com, liming.gao@intel.com Subject: [PATCH v6 1/2] CryptoPkg/BaseHashApiLib: Align BaseHashApiLib with TPM 2.0 Implementation Date: Sat, 15 Feb 2020 12:51:02 -0700 Message-Id: <20200215195103.9848-2-amol.n.sukerkar@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20200215195103.9848-1-amol.n.sukerkar@intel.com> References: <20200215195103.9848-1-amol.n.sukerkar@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2511 This commit aligns the baseHashApiLib with TPM 2.0 Implementation as follows: - Remove reference to MD4 and MD5 algorithms as they are deprecated - Align the enumerations for hashing algoerithms with the one used in TPM 2.0 implementation defined in IndustryStandard/Tpm20.h. Cc: Jiewen Yao Cc: Jian J Wang Cc: Michael D Kinney Signed-off-by: Amol N Sukerkar --- Notes: v2 - Fixed closed parentheses in commit message v3 - Fixed #ifdef for HashApiLib.h - Changed location of IndustryStandard/Tpm20.h from HashApiLib.h to BaseHashApiLib.c - Changed @ValidRange to @ValidList in CryptoPkg.dec - Aligned hash algorithm definitions to match Tpm20.h in CryptoPkg.dec and CryptoPkg.uni v4 - Changed PcdHashApiLibPolicy to UINT32 v5 - Changed PcdGet16 to PcdGet32 in BaseHashApiLib.c CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.c | 121 ++++++-------------- CryptoPkg/CryptoPkg.dec | 16 ++- CryptoPkg/CryptoPkg.uni | 12 +- CryptoPkg/Include/Library/HashApiLib.h | 16 +-- 4 files changed, 51 insertions(+), 114 deletions(-) diff --git a/CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.c b/CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.c index 277ef9f0b421..f9796b215865 100644 --- a/CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.c +++ b/CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.c @@ -12,6 +12,7 @@ **/ #include +#include #include #include #include @@ -31,32 +32,24 @@ HashApiGetContextSize ( VOID ) { - switch (PcdGet8 (PcdHashApiLibPolicy)) { - case HASH_API_ALGO_MD4: - return Md4GetContextSize (); - break; - - case HASH_API_ALGO_MD5: - return Md5GetContextSize (); - break; - - case HASH_API_ALGO_SHA1: + switch (PcdGet32 (PcdHashApiLibPolicy)) { + case HASH_ALG_SHA1: return Sha1GetContextSize (); break; - case HASH_API_ALGO_SHA256: + case HASH_ALG_SHA256: return Sha256GetContextSize (); break; - case HASH_API_ALGO_SHA384: + case HASH_ALG_SHA384: return Sha384GetContextSize (); break; - case HASH_API_ALGO_SHA512: + case HASH_ALG_SHA512: return Sha512GetContextSize (); break; - case HASH_API_ALGO_SM3_256: + case HASH_ALG_SM3_256: return Sm3GetContextSize (); break; @@ -81,32 +74,24 @@ HashApiInit ( OUT HASH_API_CONTEXT HashContext ) { - switch (PcdGet8 (PcdHashApiLibPolicy)) { - case HASH_API_ALGO_MD4: - return Md4Init (HashContext); - break; - - case HASH_API_ALGO_MD5: - return Md5Init (HashContext); - break; - - case HASH_API_ALGO_SHA1: + switch (PcdGet32 (PcdHashApiLibPolicy)) { + case HASH_ALG_SHA1: return Sha1Init (HashContext); break; - case HASH_API_ALGO_SHA256: + case HASH_ALG_SHA256: return Sha256Init (HashContext); break; - case HASH_API_ALGO_SHA384: + case HASH_ALG_SHA384: return Sha384Init (HashContext); break; - case HASH_API_ALGO_SHA512: + case HASH_ALG_SHA512: return Sha512Init (HashContext); break; - case HASH_API_ALGO_SM3_256: + case HASH_ALG_SM3_256: return Sm3Init (HashContext); break; @@ -133,32 +118,24 @@ HashApiDuplicate ( OUT HASH_API_CONTEXT NewHashContext ) { - switch (PcdGet8 (PcdHashApiLibPolicy)) { - case HASH_API_ALGO_MD4: - return Md4Duplicate (HashContext, NewHashContext); - break; - - case HASH_API_ALGO_MD5: - return Md5Duplicate (HashContext, NewHashContext); - break; - - case HASH_API_ALGO_SHA1: + switch (PcdGet32 (PcdHashApiLibPolicy)) { + case HASH_ALG_SHA1: return Sha1Duplicate (HashContext, NewHashContext); break; - case HASH_API_ALGO_SHA256: + case HASH_ALG_SHA256: return Sha256Duplicate (HashContext, NewHashContext); break; - case HASH_API_ALGO_SHA384: + case HASH_ALG_SHA384: return Sha384Duplicate (HashContext, NewHashContext); break; - case HASH_API_ALGO_SHA512: + case HASH_ALG_SHA512: return Sha512Duplicate (HashContext, NewHashContext); break; - case HASH_API_ALGO_SM3_256: + case HASH_ALG_SM3_256: return Sm3Duplicate (HashContext, NewHashContext); break; @@ -187,32 +164,24 @@ HashApiUpdate ( IN UINTN DataToHashLen ) { - switch (PcdGet8 (PcdHashApiLibPolicy)) { - case HASH_API_ALGO_MD4: - return Md4Update (HashContext, DataToHash, DataToHashLen); - break; - - case HASH_API_ALGO_MD5: - return Md5Update (HashContext, DataToHash, DataToHashLen); - break; - - case HASH_API_ALGO_SHA1: + switch (PcdGet32 (PcdHashApiLibPolicy)) { + case HASH_ALG_SHA1: return Sha1Update (HashContext, DataToHash, DataToHashLen); break; - case HASH_API_ALGO_SHA256: + case HASH_ALG_SHA256: return Sha256Update (HashContext, DataToHash, DataToHashLen); break; - case HASH_API_ALGO_SHA384: + case HASH_ALG_SHA384: return Sha384Update (HashContext, DataToHash, DataToHashLen); break; - case HASH_API_ALGO_SHA512: + case HASH_ALG_SHA512: return Sha512Update (HashContext, DataToHash, DataToHashLen); break; - case HASH_API_ALGO_SM3_256: + case HASH_ALG_SM3_256: return Sm3Update (HashContext, DataToHash, DataToHashLen); break; @@ -239,32 +208,24 @@ HashApiFinal ( OUT UINT8 *Digest ) { - switch (PcdGet8 (PcdHashApiLibPolicy)) { - case HASH_API_ALGO_MD4: - return Md4Final (HashContext, Digest); - break; - - case HASH_API_ALGO_MD5: - return Md5Final (HashContext, Digest); - break; - - case HASH_API_ALGO_SHA1: + switch (PcdGet32 (PcdHashApiLibPolicy)) { + case HASH_ALG_SHA1: return Sha1Final (HashContext, Digest); break; - case HASH_API_ALGO_SHA256: + case HASH_ALG_SHA256: return Sha256Final (HashContext, Digest); break; - case HASH_API_ALGO_SHA384: + case HASH_ALG_SHA384: return Sha384Final (HashContext, Digest); break; - case HASH_API_ALGO_SHA512: + case HASH_ALG_SHA512: return Sha512Final (HashContext, Digest); break; - case HASH_API_ALGO_SM3_256: + case HASH_ALG_SM3_256: return Sm3Final (HashContext, Digest); break; @@ -293,32 +254,24 @@ HashApiHashAll ( OUT UINT8 *Digest ) { - switch (PcdGet8 (PcdHashApiLibPolicy)) { - case HASH_API_ALGO_MD4: - return Md4HashAll (DataToHash, DataToHashLen, Digest); - break; - - case HASH_API_ALGO_MD5: - return Md5HashAll (DataToHash, DataToHashLen, Digest); - break; - - case HASH_API_ALGO_SHA1: + switch (PcdGet32 (PcdHashApiLibPolicy)) { + case HASH_ALG_SHA1: return Sha1HashAll (DataToHash, DataToHashLen, Digest); break; - case HASH_API_ALGO_SHA256: + case HASH_ALG_SHA256: return Sha256HashAll (DataToHash, DataToHashLen, Digest); break; - case HASH_API_ALGO_SHA384: + case HASH_ALG_SHA384: return Sha384HashAll (DataToHash, DataToHashLen, Digest); break; - case HASH_API_ALGO_SHA512: + case HASH_ALG_SHA512: return Sha512HashAll (DataToHash, DataToHashLen, Digest); break; - case HASH_API_ALGO_SM3_256: + case HASH_ALG_SM3_256: return Sm3HashAll (DataToHash, DataToHashLen, Digest); break; diff --git a/CryptoPkg/CryptoPkg.dec b/CryptoPkg/CryptoPkg.dec index 8bd63a76dd22..82437fef6d89 100644 --- a/CryptoPkg/CryptoPkg.dec +++ b/CryptoPkg/CryptoPkg.dec @@ -74,16 +74,14 @@ [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] # Based on the value set, the required algorithm is chosen to calculate # the hash of data.
# The default hashing algorithm for BaseHashApiLib is set to SHA256.
- # 0x00000001 - MD4.
- # 0x00000002 - MD5.
- # 0x00000003 - SHA1.
- # 0x00000004 - SHA256.
- # 0x00000005 - SHA384.
- # 0x00000006 - SHA512.
- # 0x00000007 - SM3_256.
+ # 0x00000001 - HASH_ALG_SHA1.
+ # 0x00000002 - HASH_ALG_SHA256.
+ # 0x00000004 - HASH_ALG_SHA384.
+ # 0x00000008 - HASH_ALG_SHA512.
+ # 0x00000010 - HASH_ALG_SM3_256.
# @Prompt Set policy for hashing unsigned image for Secure Boot. - # @ValidRange 0x80000001 | 0x00000001 - 0x00000007 - gEfiCryptoPkgTokenSpaceGuid.PcdHashApiLibPolicy|0x04|UINT8|0x00000001 + # @ValidList 0x80000001 | 0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010 + gEfiCryptoPkgTokenSpaceGuid.PcdHashApiLibPolicy|0x00000002|UINT32|0x00000001 [UserExtensions.TianoCore."ExtraFiles"] CryptoPkgExtra.uni diff --git a/CryptoPkg/CryptoPkg.uni b/CryptoPkg/CryptoPkg.uni index 2222762f42ee..28459fcafe5d 100644 --- a/CryptoPkg/CryptoPkg.uni +++ b/CryptoPkg/CryptoPkg.uni @@ -21,13 +21,11 @@ "Based on the value set, the required algorithm is chosen to calculate\n" "the hash of data.
\n" "The default hashing algorithm for BaseHashApiLib is set to SHA256.
\n" - "0x00000001 - MD4.
\n" - "0x00000002 - MD5.
\n" - "0x00000003 - SHA1.
\n" - "0x00000004 - SHA256.
\n" - "0x00000005 - SHA384.
\n" - "0x00000006 - SHA512.
\n" - "0x00000007 - SM3.
" + "0x00000001 - HASH_ALG_SHA1.
\n" + "0x00000002 - HASH_ALG_SHA256.
\n" + "0x00000004 - HASH_ALG_SHA384.
\n" + "0x00000008 - HASH_ALG_SHA512.
\n" + "0x00000010 - HASH_ALG_SM3.
" #string STR_gEfiCryptoPkgTokenSpaceGuid_PcdCryptoServiceFamilyEnable_PROMPT #language en-US "Enable/Disable EDK II Crypto Protocol/PPI services" diff --git a/CryptoPkg/Include/Library/HashApiLib.h b/CryptoPkg/Include/Library/HashApiLib.h index 22068e5a1756..17250505fda1 100644 --- a/CryptoPkg/Include/Library/HashApiLib.h +++ b/CryptoPkg/Include/Library/HashApiLib.h @@ -9,23 +9,11 @@ **/ -#ifndef __BASEHASHAPILIB_H_ -#define __BASEHASHAPILIB_H_ +#ifndef __HASH_API_LIB_H_ +#define __HASH_API_LIB_H_ typedef VOID *HASH_API_CONTEXT; -// -// Hash Algorithms -// -#define HASH_API_ALGO_INVALID 0x00000000 -#define HASH_API_ALGO_MD4 0x00000001 -#define HASH_API_ALGO_MD5 0x00000002 -#define HASH_API_ALGO_SHA1 0x00000003 -#define HASH_API_ALGO_SHA256 0x00000004 -#define HASH_API_ALGO_SHA384 0x00000005 -#define HASH_API_ALGO_SHA512 0x00000006 -#define HASH_API_ALGO_SM3_256 0x00000007 - /** Retrieves the size, in bytes, of the context buffer required for hash operations. -- 2.16.2.windows.1