From nobody Wed May 8 22:37:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+54484+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+54484+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1581722465973532.5774433430862; Fri, 14 Feb 2020 15:21:05 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id YiNcYY1788612xmQMeCmYlsa; Fri, 14 Feb 2020 15:21:05 -0800 X-Received: from mga04.intel.com (mga04.intel.com []) by mx.groups.io with SMTP id smtpd.web12.1381.1581722464555507361 for ; Fri, 14 Feb 2020 15:21:04 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Feb 2020 15:21:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,442,1574150400"; d="scan'208";a="314210949" X-Received: from ansukerk-desk.amr.corp.intel.com ([10.34.130.122]) by orsmga001.jf.intel.com with ESMTP; 14 Feb 2020 15:21:03 -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: [edk2-devel] [PATCH v3 1/2] CryptoPkg/BaseHashApiLib: Align BaseHashApiLib with TPM 2.0 Implementation Date: Fri, 14 Feb 2020 16:20:59 -0700 Message-Id: <20200214232100.11088-2-amol.n.sukerkar@intel.com> In-Reply-To: <20200214232100.11088-1-amol.n.sukerkar@intel.com> References: <20200214232100.11088-1-amol.n.sukerkar@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,amol.n.sukerkar@intel.com X-Gm-Message-State: gj0YKMf4nJwDzxnplfTEFV4cx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1581722465; bh=0APTbazK1yrHpAbQb0Sfzkx3OyRL6UHvxAMg6fo/fMI=; h=Cc:Date:From:Reply-To:Subject:To; b=wOMqayE54+ASpJFtUyeZp59nNnYi6HKndHg3UaceK/Gj/Ni+2YKy1uDMwLIU+8MEDU9 Wfx1he8Yf7xYYhNKC1BBUv528mTRAUUTOBfn04jdDsIO77yA2Z6tLngXF3mD1RLHoKjQM 4vWErZt83BrdNavMWV5E39duCY4RGcpRZbY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2511 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 =20 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 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..df0b294860dc 100644 --- a/CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.c +++ b/CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.c @@ -12,6 +12,7 @@ **/ =20 #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 (PcdGet16 (PcdHashApiLibPolicy)) { + case HASH_ALG_SHA1: return Sha1GetContextSize (); break; =20 - case HASH_API_ALGO_SHA256: + case HASH_ALG_SHA256: return Sha256GetContextSize (); break; =20 - case HASH_API_ALGO_SHA384: + case HASH_ALG_SHA384: return Sha384GetContextSize (); break; =20 - case HASH_API_ALGO_SHA512: + case HASH_ALG_SHA512: return Sha512GetContextSize (); break; =20 - case HASH_API_ALGO_SM3_256: + case HASH_ALG_SM3_256: return Sm3GetContextSize (); break; =20 @@ -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 (PcdGet16 (PcdHashApiLibPolicy)) { + case HASH_ALG_SHA1: return Sha1Init (HashContext); break; =20 - case HASH_API_ALGO_SHA256: + case HASH_ALG_SHA256: return Sha256Init (HashContext); break; =20 - case HASH_API_ALGO_SHA384: + case HASH_ALG_SHA384: return Sha384Init (HashContext); break; =20 - case HASH_API_ALGO_SHA512: + case HASH_ALG_SHA512: return Sha512Init (HashContext); break; =20 - case HASH_API_ALGO_SM3_256: + case HASH_ALG_SM3_256: return Sm3Init (HashContext); break; =20 @@ -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 (PcdGet16 (PcdHashApiLibPolicy)) { + case HASH_ALG_SHA1: return Sha1Duplicate (HashContext, NewHashContext); break; =20 - case HASH_API_ALGO_SHA256: + case HASH_ALG_SHA256: return Sha256Duplicate (HashContext, NewHashContext); break; =20 - case HASH_API_ALGO_SHA384: + case HASH_ALG_SHA384: return Sha384Duplicate (HashContext, NewHashContext); break; =20 - case HASH_API_ALGO_SHA512: + case HASH_ALG_SHA512: return Sha512Duplicate (HashContext, NewHashContext); break; =20 - case HASH_API_ALGO_SM3_256: + case HASH_ALG_SM3_256: return Sm3Duplicate (HashContext, NewHashContext); break; =20 @@ -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 (PcdGet16 (PcdHashApiLibPolicy)) { + case HASH_ALG_SHA1: return Sha1Update (HashContext, DataToHash, DataToHashLen); break; =20 - case HASH_API_ALGO_SHA256: + case HASH_ALG_SHA256: return Sha256Update (HashContext, DataToHash, DataToHashLen); break; =20 - case HASH_API_ALGO_SHA384: + case HASH_ALG_SHA384: return Sha384Update (HashContext, DataToHash, DataToHashLen); break; =20 - case HASH_API_ALGO_SHA512: + case HASH_ALG_SHA512: return Sha512Update (HashContext, DataToHash, DataToHashLen); break; =20 - case HASH_API_ALGO_SM3_256: + case HASH_ALG_SM3_256: return Sm3Update (HashContext, DataToHash, DataToHashLen); break; =20 @@ -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 (PcdGet16 (PcdHashApiLibPolicy)) { + case HASH_ALG_SHA1: return Sha1Final (HashContext, Digest); break; =20 - case HASH_API_ALGO_SHA256: + case HASH_ALG_SHA256: return Sha256Final (HashContext, Digest); break; =20 - case HASH_API_ALGO_SHA384: + case HASH_ALG_SHA384: return Sha384Final (HashContext, Digest); break; =20 - case HASH_API_ALGO_SHA512: + case HASH_ALG_SHA512: return Sha512Final (HashContext, Digest); break; =20 - case HASH_API_ALGO_SM3_256: + case HASH_ALG_SM3_256: return Sm3Final (HashContext, Digest); break; =20 @@ -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 (PcdGet16 (PcdHashApiLibPolicy)) { + case HASH_ALG_SHA1: return Sha1HashAll (DataToHash, DataToHashLen, Digest); break; =20 - case HASH_API_ALGO_SHA256: + case HASH_ALG_SHA256: return Sha256HashAll (DataToHash, DataToHashLen, Digest); break; =20 - case HASH_API_ALGO_SHA384: + case HASH_ALG_SHA384: return Sha384HashAll (DataToHash, DataToHashLen, Digest); break; =20 - case HASH_API_ALGO_SHA512: + case HASH_ALG_SHA512: return Sha512HashAll (DataToHash, DataToHashLen, Digest); break; =20 - case HASH_API_ALGO_SM3_256: + case HASH_ALG_SM3_256: return Sm3HashAll (DataToHash, DataToHashLen, Digest); break; =20 diff --git a/CryptoPkg/CryptoPkg.dec b/CryptoPkg/CryptoPkg.dec index 8bd63a76dd22..25ffeb499cae 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.
+ # 0x0001 - HASH_ALG_SHA1.
+ # 0x0002 - HASH_ALG_SHA256.
+ # 0x0004 - HASH_ALG_SHA384.
+ # 0x0008 - HASH_ALG_SHA512.
+ # 0x0010 - 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 | 0x0001, 0x0002, 0x0004, 0x0008, 0x0010 + gEfiCryptoPkgTokenSpaceGuid.PcdHashApiLibPolicy|0x0002|UINT16|0x00000001 =20 [UserExtensions.TianoCore."ExtraFiles"] CryptoPkgExtra.uni diff --git a/CryptoPkg/CryptoPkg.uni b/CryptoPkg/CryptoPkg.uni index 2222762f42ee..295027d67692 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 S= HA256.
\n" - = "0x00000001 - MD4.
\n" - = "0x00000002 - MD5.
\n" - = "0x00000003 - SHA1.
\n" - = "0x00000004 - SHA256.
\n" - = "0x00000005 - SHA384.
\n" - = "0x00000006 - SHA512.
\n" - = "0x00000007 - SM3.
" + = "0x0001 - HASH_ALG_SHA1.
\n" + = "0x0002 - HASH_ALG_SHA256.
\n" + = "0x0004 - HASH_ALG_SHA384.
\n" + = "0x0008 - HASH_ALG_SHA512.
\n" + = "0x0010 - HASH_ALG_SM3.
" =20 #string STR_gEfiCryptoPkgTokenSpaceGuid_PcdCryptoServiceFamilyEnable_PROMP= T #language en-US "Enable/Disable EDK II Crypto Protocol/PPI services" =20 diff --git a/CryptoPkg/Include/Library/HashApiLib.h b/CryptoPkg/Include/Lib= rary/HashApiLib.h index 22068e5a1756..17250505fda1 100644 --- a/CryptoPkg/Include/Library/HashApiLib.h +++ b/CryptoPkg/Include/Library/HashApiLib.h @@ -9,23 +9,11 @@ =20 **/ =20 -#ifndef __BASEHASHAPILIB_H_ -#define __BASEHASHAPILIB_H_ +#ifndef __HASH_API_LIB_H_ +#define __HASH_API_LIB_H_ =20 typedef VOID *HASH_API_CONTEXT; =20 -// -// 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 op= erations. =20 --=20 2.16.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#54484): https://edk2.groups.io/g/devel/message/54484 Mute This Topic: https://groups.io/mt/71287683/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 22:37:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+54485+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+54485+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1581722466236460.361019331432; Fri, 14 Feb 2020 15:21:06 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id v12IYY1788612x3WCmAySeqe; Fri, 14 Feb 2020 15:21:05 -0800 X-Received: from mga04.intel.com (mga04.intel.com []) by mx.groups.io with SMTP id smtpd.web12.1381.1581722464555507361 for ; Fri, 14 Feb 2020 15:21:05 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Feb 2020 15:21:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,442,1574150400"; d="scan'208";a="314210954" X-Received: from ansukerk-desk.amr.corp.intel.com ([10.34.130.122]) by orsmga001.jf.intel.com with ESMTP; 14 Feb 2020 15:21:04 -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: [edk2-devel] [PATCH v3 2/2] CryptoPkg/BaseHashApiLib: Change PcdHashApiLibPolicy type to FixedAtBuild Date: Fri, 14 Feb 2020 16:21:00 -0700 Message-Id: <20200214232100.11088-3-amol.n.sukerkar@intel.com> In-Reply-To: <20200214232100.11088-1-amol.n.sukerkar@intel.com> References: <20200214232100.11088-1-amol.n.sukerkar@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,amol.n.sukerkar@intel.com X-Gm-Message-State: PeiEK4OM3mjUFisl3jIbg4Urx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1581722465; bh=poYUXi0YmWQjOlXHDXC/McTTe0kz9PavSoT6eo5HOws=; h=Cc:Date:From:Reply-To:Subject:To; b=XeNlSsFCcdBP994xCflHapMk54MxyQZCcx420/PFbZQx0nqFFYnJ8BQiRr/tyv47DS6 TYDYMAbUpRDlCm1E9RBl244Fp7F+Rnn26X2G3quTnRUl1NcSvv5Lp9VPy921jwgqwDn56 mLbQt4/DMBrlQgGDp6Hb4V8Zt032DOm5Vh0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2511 This commit changes the PCD PcdHashApiLibPolicy to the type PcdsFixedAtBuild so as to be able to optimize away the unused hashing algorithms in HashApiLib instance used by a driver. Cc: Jiewen Yao Cc: Jian J Wang Cc: Michael D Kinney Signed-off-by: Amol N Sukerkar --- Notes: v2 - Fixed closed parantheses in the commit message CryptoPkg/CryptoPkg.dec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CryptoPkg/CryptoPkg.dec b/CryptoPkg/CryptoPkg.dec index 25ffeb499cae..01e9dbf1141f 100644 --- a/CryptoPkg/CryptoPkg.dec +++ b/CryptoPkg/CryptoPkg.dec @@ -69,7 +69,7 @@ [PcdsFixedAtBuild] Pcd/PcdCryptoServiceFamilyEnable.h } =20 -[PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] +[PcdsFixedAtBuild] ## This PCD indicates the HASH algorithm to calculate hash of data # Based on the value set, the required algorithm is chosen to calculate # the hash of data.
--=20 2.16.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#54485): https://edk2.groups.io/g/devel/message/54485 Mute This Topic: https://groups.io/mt/71287684/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-