From nobody Thu May 2 15:11:51 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+53619+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+53619+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 1580494925233360.55672071478307; Fri, 31 Jan 2020 10:22:05 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id xr60YY1788612xusmBUGEQg2; Fri, 31 Jan 2020 10:22:03 -0800 X-Received: from mga02.intel.com (mga02.intel.com []) by mx.groups.io with SMTP id smtpd.web09.533.1580494920687533656 for ; Fri, 31 Jan 2020 10:22:02 -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 orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jan 2020 10:22:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,386,1574150400"; d="scan'208";a="310076606" X-Received: from ansukerk-desk.amr.corp.intel.com ([10.34.130.122]) by orsmga001.jf.intel.com with ESMTP; 31 Jan 2020 10:22:01 -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, srinivas.musti@intel.com, subash.lakkimsetti@intel.com, john.mathews@intel.com Subject: [edk2-devel] [PATCH v8 1/2] CryptoPkg: Add CryptoPkg Token Space GUID Date: Fri, 31 Jan 2020 11:21:55 -0700 Message-Id: <20200131182156.13332-2-amol.n.sukerkar@intel.com> In-Reply-To: <20200131182156.13332-1-amol.n.sukerkar@intel.com> References: <20200131182156.13332-1-amol.n.sukerkar@intel.com> 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: 3r1MFnCXEcZvXRciSHbIQVLUx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1580494923; bh=DM4hH9S33kQ6jCv0O49d9SWo1+VYxQJw0vy9Vd6aFDg=; h=Cc:Date:From:Reply-To:Subject:To; b=WibnY/gz2X+icQNU4yRNE+8ijuAXWNMUym/y24FoBCMG/PFwivOWqOFtTRSFySosAey yPZKntbDPKduKkaV1pjGJbXgbXRndm4qsqDNIDspLundNOlh4JBClmmx3Cp89tOua42XE bRySBltJtYHoYacRX7ApmunhlHLlSBdW6gQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Added CryptoPkg Token Space GUID to be able to define PCDs. Cc: Jiewen Yao Cc: Jian J Wang Cc: Michael D Kinney Signed-off-by: Amol N Sukerkar --- Notes: v6 - removed file CryptoPkgTokenSpace.h =20 v7 - fixed typo =20 v8 - Fixed Author and signed-off-by name CryptoPkg/CryptoPkg.dec | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CryptoPkg/CryptoPkg.dec b/CryptoPkg/CryptoPkg.dec index 08bedd57daad..16f08ea60926 100644 --- a/CryptoPkg/CryptoPkg.dec +++ b/CryptoPkg/CryptoPkg.dec @@ -4,7 +4,7 @@ # This Package provides cryptographic-related libraries for UEFI security= modules. # It also provides a test application to test libraries. # -# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -33,5 +33,9 @@ [LibraryClasses] ## TlsLib|Include/Library/TlsLib.h =20 +[Guids] + ## Crypto package token space guid. + gEfiCryptoPkgTokenSpaceGuid =3D { 0xd3fb176, 0x9569, 0x4d51, { 0xa3= , 0xef, 0x7d, 0x61, 0xc6, 0x4f, 0xea, 0xba }} + [UserExtensions.TianoCore."ExtraFiles"] CryptoPkgExtra.uni --=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 (#53619): https://edk2.groups.io/g/devel/message/53619 Mute This Topic: https://groups.io/mt/70879608/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 Thu May 2 15:11:51 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+53620+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+53620+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 1580494927131585.6335433400791; Fri, 31 Jan 2020 10:22:07 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id EGsGYY1788612xsBj4DAmQ0z; Fri, 31 Jan 2020 10:22:06 -0800 X-Received: from mga02.intel.com (mga02.intel.com []) by mx.groups.io with SMTP id smtpd.web09.533.1580494920687533656 for ; Fri, 31 Jan 2020 10:22: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 orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jan 2020 10:22:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,386,1574150400"; d="scan'208";a="310076623" X-Received: from ansukerk-desk.amr.corp.intel.com ([10.34.130.122]) by orsmga001.jf.intel.com with ESMTP; 31 Jan 2020 10:22: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, srinivas.musti@intel.com, subash.lakkimsetti@intel.com, john.mathews@intel.com Subject: [edk2-devel] [PATCH v8 2/2] CryptoPkg/BaseHashApiLib: Implement Unified Hash Calculation API Date: Fri, 31 Jan 2020 11:21:56 -0700 Message-Id: <20200131182156.13332-3-amol.n.sukerkar@intel.com> In-Reply-To: <20200131182156.13332-1-amol.n.sukerkar@intel.com> References: <20200131182156.13332-1-amol.n.sukerkar@intel.com> 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: ojkQvLr9z7EAwTKodz1duWxzx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1580494926; bh=7pd7FLUzSOlmhNT4+NCMzi5ZPisx8xklUsMV43SsnSE=; h=Cc:Date:From:Reply-To:Subject:To; b=gSFfXmjNFMeb/4DzqAYhos3QJXMn4qLKeRRl6gWU1hG1unxRe3qVzh3kDj1xPYCUbXj sTDGJt6bm41wkRYWZw7PKHQul8h0Cd+aaWuLO8huaLDgiPE3+COhADuRfmUA2LccSLfvK DvKNus4FpEZUxD8lIqDU8Gv/+8+sf+koNFY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This commit introduces a Unified Hash API to calculate hash using a hashing algorithm specified by the PCD, PcdHashApiLibPolicy. This library interfaces with the various hashing API, such as, MD4, MD5, SHA1, SHA256, SHA512 and SM3_256 implemented in BaseCryptLib. The user can calculate the desired hash by setting PcdHashApiLibPolicy to appropriate value. This feature is documented in the Bugzilla, https://bugzilla.tianocore.org/show_bug.cgi?id=3D2151. Cc: Jiewen Yao Cc: Jian J Wang Cc: Michael D Kinney Signed-off-by: Amol N Sukerkar --- Notes: v8 - Changed name from BaseHashApiLib.h to HashApiLib.h - Fixed Author and signed-off-by name CryptoPkg/Library/HashApiLib/BaseHashApiLib.c | 333 ++++++++++++++++++++ CryptoPkg/CryptoPkg.dec | 20 ++ CryptoPkg/CryptoPkg.dsc | 4 +- CryptoPkg/CryptoPkg.uni | 18 +- CryptoPkg/Include/Library/HashApiLib.h | 122 +++++++ CryptoPkg/Library/HashApiLib/BaseHashApiLib.inf | 44 +++ CryptoPkg/Library/HashApiLib/BaseHashApiLib.uni | 17 + 7 files changed, 556 insertions(+), 2 deletions(-) diff --git a/CryptoPkg/Library/HashApiLib/BaseHashApiLib.c b/CryptoPkg/Libr= ary/HashApiLib/BaseHashApiLib.c new file mode 100644 index 000000000000..0c9206ca248f --- /dev/null +++ b/CryptoPkg/Library/HashApiLib/BaseHashApiLib.c @@ -0,0 +1,333 @@ +/** @file + Unified Hash API Implementation + + This file implements the Unified Hash API. + + This API, when called, will calculate the Hash using the + hashing algorithm specified by PcdHashApiLibPolicy. + + Copyright (c) 2020, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +/** + Retrieves the size, in bytes, of the context buffer required for hash op= erations. + + @return The size, in bytes, of the context buffer required for hash ope= rations. + +**/ +UINTN +EFIAPI +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: + return Sha1GetContextSize (); + break; + + case HASH_API_ALGO_SHA256: + return Sha256GetContextSize (); + break; + + case HASH_API_ALGO_SHA384: + return Sha384GetContextSize (); + break; + + case HASH_API_ALGO_SHA512: + return Sha512GetContextSize (); + break; + + case HASH_API_ALGO_SM3_256: + return Sm3GetContextSize (); + break; + + default: + ASSERT (FALSE); + return 0; + break; + } +} + +/** + Init hash sequence. + + @param[out] HashContext Hash context. + + @retval TRUE Hash start and HashHandle returned. + @retval FALSE Hash Init unsuccessful. +**/ +BOOLEAN +EFIAPI +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: + return Sha1Init (HashContext); + break; + + case HASH_API_ALGO_SHA256: + return Sha256Init (HashContext); + break; + + case HASH_API_ALGO_SHA384: + return Sha384Init (HashContext); + break; + + case HASH_API_ALGO_SHA512: + return Sha512Init (HashContext); + break; + + case HASH_API_ALGO_SM3_256: + return Sm3Init (HashContext); + break; + + default: + ASSERT (FALSE); + return FALSE; + break; + } +} + +/** + Makes a copy of an existing hash context. + + @param[in] HashContext Hash context. + @param[out] NewHashContext New copy of hash context. + + @retval TRUE Hash context copy succeeded. + @retval FALSE Hash context copy failed. + +**/ +BOOLEAN +EFIAPI +HashApiDuplicate ( + IN HASH_API_CONTEXT *HashContext, + OUT VOID *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: + return Sha1Duplicate (HashContext, NewHashContext); + break; + + case HASH_API_ALGO_SHA256: + return Sha256Duplicate (HashContext, NewHashContext); + break; + + case HASH_API_ALGO_SHA384: + return Sha384Duplicate (HashContext, NewHashContext); + break; + + case HASH_API_ALGO_SHA512: + return Sha512Duplicate (HashContext, NewHashContext); + break; + + case HASH_API_ALGO_SM3_256: + return Sm3Duplicate (HashContext, NewHashContext); + break; + + default: + ASSERT (FALSE); + return FALSE; + break; + } +} + +/** + Update hash data. + + @param[in] HashContext Hash context. + @param[in] DataToHash Data to be hashed. + @param[in] DataToHashLen Data size. + + @retval TRUE Hash updated. + @retval FALSE Hash updated unsuccessful. +**/ +BOOLEAN +EFIAPI +HashApiUpdate ( + IN HASH_API_CONTEXT *HashContext, + IN VOID *DataToHash, + 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: + return Sha1Update (HashContext, DataToHash, DataToHashLen); + break; + + case HASH_API_ALGO_SHA256: + return Sha256Update (HashContext, DataToHash, DataToHashLen); + break; + + case HASH_API_ALGO_SHA384: + return Sha384Update (HashContext, DataToHash, DataToHashLen); + break; + + case HASH_API_ALGO_SHA512: + return Sha512Update (HashContext, DataToHash, DataToHashLen); + break; + + case HASH_API_ALGO_SM3_256: + return Sm3Update (HashContext, DataToHash, DataToHashLen); + break; + + default: + ASSERT (FALSE); + return FALSE; + break; + } +} + +/** + Hash complete. + + @param[in] HashContext Hash context. + @param[out] Digest Hash Digest. + + @retval TRUE Hash complete and Digest is returned. + @retval FALSE Hash complete unsuccessful. +**/ +BOOLEAN +EFIAPI +HashApiFinal ( + IN HASH_API_CONTEXT *HashContext, + 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: + return Sha1Final (HashContext, Digest); + break; + + case HASH_API_ALGO_SHA256: + return Sha256Final (HashContext, Digest); + break; + + case HASH_API_ALGO_SHA384: + return Sha384Final (HashContext, Digest); + break; + + case HASH_API_ALGO_SHA512: + return Sha512Final (HashContext, Digest); + break; + + case HASH_API_ALGO_SM3_256: + return Sm3Final (HashContext, Digest); + break; + + default: + ASSERT (FALSE); + return FALSE; + break; + } +} + +/** + Computes hash message digest of a input data buffer. + + @param[in] DataToHash Data to be hashed. + @param[in] DataToHashLen Data size. + @param[out] Digest Hash Digest. + + @retval TRUE Hash digest computation succeeded. + @retval FALSE Hash digest computation failed. + +**/ +BOOLEAN +EFIAPI +HashApiHashAll ( + IN CONST VOID *DataToHash, + IN UINTN DataToHashLen, + 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: + return Sha1HashAll (DataToHash, DataToHashLen, Digest); + break; + + case HASH_API_ALGO_SHA256: + return Sha256HashAll (DataToHash, DataToHashLen, Digest); + break; + + case HASH_API_ALGO_SHA384: + return Sha384HashAll (DataToHash, DataToHashLen, Digest); + break; + + case HASH_API_ALGO_SHA512: + return Sha512HashAll (DataToHash, DataToHashLen, Digest); + break; + + case HASH_API_ALGO_SM3_256: + return Sm3HashAll (DataToHash, DataToHashLen, Digest); + break; + + default: + ASSERT (FALSE); + return FALSE; + break; + } +} diff --git a/CryptoPkg/CryptoPkg.dec b/CryptoPkg/CryptoPkg.dec index 16f08ea60926..5b7c5bd30115 100644 --- a/CryptoPkg/CryptoPkg.dec +++ b/CryptoPkg/CryptoPkg.dec @@ -33,9 +33,29 @@ [LibraryClasses] ## TlsLib|Include/Library/TlsLib.h =20 + ## @libraryclass Provides Unified API for different hash implementatio= ns. + # + BaseHashApiLib|Include/Library/BaseHashApiLib.h + [Guids] ## Crypto package token space guid. gEfiCryptoPkgTokenSpaceGuid =3D { 0xd3fb176, 0x9569, 0x4d51, { 0xa3= , 0xef, 0x7d, 0x61, 0xc6, 0x4f, 0xea, 0xba }} =20 +[PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] + ## 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.
+ # 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.
+ # @Prompt Set policy for hashing unsigned image for Secure Boot. + # @ValidRange 0x80000001 | 0x00000001 - 0x00000007 + gEfiCryptoPkgTokenSpaceGuid.PcdHashApiLibPolicy|0x04|UINT8|0x00000001 + [UserExtensions.TianoCore."ExtraFiles"] CryptoPkgExtra.uni diff --git a/CryptoPkg/CryptoPkg.dsc b/CryptoPkg/CryptoPkg.dsc index ec43c1f0a47e..aa87dcb50b74 100644 --- a/CryptoPkg/CryptoPkg.dsc +++ b/CryptoPkg/CryptoPkg.dsc @@ -1,7 +1,7 @@ ## @file # Cryptographic Library Package for UEFI Security Implementation. # -# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -44,6 +44,7 @@ [LibraryClasses] =20 IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf + BaseHashApiLib|CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.inf =20 [LibraryClasses.ARM, LibraryClasses.AARCH64] # @@ -120,6 +121,7 @@ [Components] CryptoPkg/Library/TlsLibNull/TlsLibNull.inf CryptoPkg/Library/OpensslLib/OpensslLib.inf CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf + CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.inf =20 [Components.IA32, Components.X64] CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf diff --git a/CryptoPkg/CryptoPkg.uni b/CryptoPkg/CryptoPkg.uni index beb0036ef583..0dae4c40454c 100644 --- a/CryptoPkg/CryptoPkg.uni +++ b/CryptoPkg/CryptoPkg.uni @@ -4,7 +4,7 @@ // This Package provides cryptographic-related libraries for UEFI security= modules. // It also provides a test application to test libraries. // -// Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+// Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.
// // SPDX-License-Identifier: BSD-2-Clause-Patent // @@ -17,3 +17,19 @@ =20 =20 =20 +#string STR_gEfiCryptoPkgTokenSpaceGuid_PcdHashApiLibPolicy_PROMPT #langu= age en-US "HASH algorithm to calculate hash" + +#string STR_gEfiCryptoPkgTokenSpaceGuid_PcdHashApiLibPolicy_HELP #languag= e en-US "This PCD indicates the HASH algorithm to calculate hash of data.
\n" + = "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.
" + + + diff --git a/CryptoPkg/Include/Library/HashApiLib.h b/CryptoPkg/Include/Lib= rary/HashApiLib.h new file mode 100644 index 000000000000..4f01d72a2201 --- /dev/null +++ b/CryptoPkg/Include/Library/HashApiLib.h @@ -0,0 +1,122 @@ +/** @file + Unified Hash API Defines + + This API when called will calculate the Hash using the + hashing algorithm specified by PcdHashApiLibPolicy. + + Copyright (c) 2020, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __BASEHASHAPILIB_H_ +#define __BASEHASHAPILIB_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 of the context buffer required for hash operations. + + @return The size of the context buffer required for hash operations (in= bytes). +**/ +UINTN +EFIAPI +HashApiGetContextSize ( + VOID +); + +/** + Init hash sequence. + + @param[out] HashContext Hash context. + + @retval TRUE Hash start and HashHandle returned. + @retval FALSE Hash Init unsuccessful. +**/ +BOOLEAN +EFIAPI +HashApiInit ( + OUT HASH_API_CONTEXT HashContext +); + +/** + Makes a copy of an existing hash context. + + @param[in] HashContext Hash context. + @param[out] NewHashContext New copy of hash context. + + @retval TRUE Hash context copy succeeded. + @retval FALSE Hash context copy failed. +**/ +BOOLEAN +EFIAPI +HashApiDuplicate ( + IN HASH_API_CONTEXT HashContext, + OUT HASH_API_CONTEXT NewHashContext +); + +/** + Update hash data. + + @param[in] HashContext Hash context. + @param[in] DataToHash Data to be hashed. + @param[in] DataToHashLen Data size. + + @retval TRUE Hash updated. + @retval FALSE Hash updated unsuccessful. +**/ +BOOLEAN +EFIAPI +HashApiUpdate ( + IN HASH_API_CONTEXT HashContext, + IN VOID *DataToHash, + IN UINTN DataToHashLen +); + +/** + Hash complete. + + @param[in] HashContext Hash context. + @param[out] Digest Hash Digest. + + @retval TRUE Hash complete and Digest is returned. + @retval FALSE Hash complete unsuccessful. +**/ +BOOLEAN +EFIAPI +HashApiFinal ( + IN HASH_API_CONTEXT HashContext, + OUT UINT8 *Digest +); + +/** + Computes hash message digest of a input data buffer. + + @param[in] DataToHash Data to be hashed. + @param[in] DataToHashLen Data size. + @param[out] Digest Hash Digest. + + @retval TRUE Hash digest computation succeeded. + @retval FALSE Hash digest computation failed. +**/ +BOOLEAN +EFIAPI +HashApiHashAll ( + IN CONST VOID *DataToHash, + IN UINTN DataToHashLen, + OUT UINT8 *Digest +); + +#endif diff --git a/CryptoPkg/Library/HashApiLib/BaseHashApiLib.inf b/CryptoPkg/Li= brary/HashApiLib/BaseHashApiLib.inf new file mode 100644 index 000000000000..92ff358475c4 --- /dev/null +++ b/CryptoPkg/Library/HashApiLib/BaseHashApiLib.inf @@ -0,0 +1,44 @@ +## @file +# Provides Unified API for Hash Calculation +# +# This library is BaseHashApiLib. It will redirect hash request to +# each individual hash API, such as SHA1, SHA256, SHA384, SM3 based +# on hashing algorithm specified by PcdHashApiLibPolicy. +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D BaseHashApiLib + MODULE_UNI_FILE =3D BaseHashApiLib.uni + FILE_GUID =3D DDCBCFBA-8EEB-488a-96D6-097831A6E50B + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D BaseHashApiLib + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + BaseHashApiLib.c + +[Packages] + MdePkg/MdePkg.dec + CryptoPkg/CryptoPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + BaseCryptLib + PcdLib + +[Pcd] + gEfiCryptoPkgTokenSpaceGuid.PcdHashApiLibPolicy ## CONSUMES diff --git a/CryptoPkg/Library/HashApiLib/BaseHashApiLib.uni b/CryptoPkg/Li= brary/HashApiLib/BaseHashApiLib.uni new file mode 100644 index 000000000000..49ba82e86f59 --- /dev/null +++ b/CryptoPkg/Library/HashApiLib/BaseHashApiLib.uni @@ -0,0 +1,17 @@ +// /** @file +// Provides Unified API for Hash Calculation +// +// This library is BaseHashApiLib. It will redirect hash request to +// each individual hash API, such as SHA1, SHA256, SHA384, SM3 based +// on hashing algorithm specified by PcdHashApiLibPolicy. +// +// Copyright (c) 2020, Intel Corporation. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Provides hash ser= vice by specified hash handler" + +#string STR_MODULE_DESCRIPTION #language en-US "This library is U= nified Hash API. It will redirect hash request to the hash handler specifie= d by PcdHashApiLibPolicy." --=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 (#53620): https://edk2.groups.io/g/devel/message/53620 Mute This Topic: https://groups.io/mt/70879609/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-