From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web12.1840.1580858126768160971 for ; Tue, 04 Feb 2020 15:15:27 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=GeaajmX0; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: amol.n.sukerkar@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Feb 2020 15:15:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,403,1574150400"; d="scan'208";a="224752898" Received: from orsmsx104.amr.corp.intel.com ([10.22.225.131]) by fmsmga007.fm.intel.com with ESMTP; 04 Feb 2020 15:15:25 -0800 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by ORSMSX104.amr.corp.intel.com (10.22.225.131) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 4 Feb 2020 15:15:22 -0800 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 4 Feb 2020 15:15:22 -0800 Received: from ORSEDG001.ED.cps.intel.com (10.7.248.4) by orsmsx603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Tue, 4 Feb 2020 15:15:22 -0800 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (104.47.37.56) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 4 Feb 2020 15:15:21 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mC0ozNkKGRuBNVMkTYBplyQCboRiVB6soeZKfXNbtDsuSH+aw0vIodnBy/hX43UV909CMOUG9emqDHKumuSgWB0t8JM0Ua5syiKLHjsm/q8EVAWXOsWUd7KrWEgFx6hyqpOTNY/5I134paaWR7IBytCwLOaP3XHZllOkkeHADriyB0BpyO1bJ3xmI1IFw4O/Fjod7OeiGt+Oyp5qM4IeyeWko7Wva1Gc8toRIzoP5aDYpjVnOSJ4gDAu5ANIZl6IAeF5EFB0Nxhmh7vwzdJ3aYv9W8v9l8gPzIsh8QwvdwB6NAvLtovDjqsgBKpr68JWgrBUs/KsmnDrDAxLz3JDKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FmTJwIdfRdsgouvltxNiQxi/Uci7iLcNbJpJXh2oBMI=; b=NO56THFJv9K3Z/ITlt5o5vOdQR7Rqa/vVYj0WEVPbYHCk4KA3MdK9t2HGByW5b4YyW8Zv5glQpfqYuqk/jUcwYT772+5jk6W5FhFBcALEQoW5oe8PFbMvRjwseNR4bttUkxhb56MjrrMyOdaSvkPDnTYGrrpFe1LDflOkp8JXH/Jq3AJb7mGZ+C+yPZd5OfFZ0ZxhSIBMsot5GOWzHLv8UPlMId7vDBfzN4GaF0qfAHai/xaURH1XRkt2LvZShqPzwkTF7igZeLk2s3lLcNVmsttM8ogsAbJ7bJo/kgMNFIi/ypigb72j4RQfo1rIQrso0Ekg4LUoT35G/NNt+0mpw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FmTJwIdfRdsgouvltxNiQxi/Uci7iLcNbJpJXh2oBMI=; b=GeaajmX0TIE/TThZcrOb1ji+FhhaqS5jzjM7vve7634pKdn506Tjp6GgiH120kj9TJt10hdhNAC418p3rr47gCLnAcbtcbIJxWaAl5Cs5980MNTuV6418cm9OopJP4D5hbeVkBT7jsP30w2bk9pZlswvUXGIC0d6LfqvEr8Pcf4= Received: from SN6PR11MB2893.namprd11.prod.outlook.com (20.176.241.151) by SN6PR11MB3069.namprd11.prod.outlook.com (52.135.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.26; Tue, 4 Feb 2020 23:15:13 +0000 Received: from SN6PR11MB2893.namprd11.prod.outlook.com ([fe80::e59c:2d4b:b97c:9676]) by SN6PR11MB2893.namprd11.prod.outlook.com ([fe80::e59c:2d4b:b97c:9676%7]) with mapi id 15.20.2686.034; Tue, 4 Feb 2020 23:15:13 +0000 From: "Sukerkar, Amol N" To: "Yao, Jiewen" , "Kinney, Michael D" , "devel@edk2.groups.io" CC: "Wang, Jian J" , "Sukerkar, Amol N" Subject: Re: [Patch v10 2/2] CryptoPkg/BaseHashApiLib: Implement Unified Hash Calculation API Thread-Topic: [Patch v10 2/2] CryptoPkg/BaseHashApiLib: Implement Unified Hash Calculation API Thread-Index: AQHV2uq9LarSu+1k8ECkh7/d2NhT/6gKVtqAgADi/oCAAAoEcIAAZcWAgAABlGA= Date: Tue, 4 Feb 2020 23:15:12 +0000 Message-ID: References: <20200203233548.7616-1-michael.d.kinney@intel.com> <20200203233548.7616-3-michael.d.kinney@intel.com> <74D8A39837DF1E4DA445A8C0B3885C503F910942@shsmsx102.ccr.corp.intel.com> <74D8A39837DF1E4DA445A8C0B3885C503F912B46@shsmsx102.ccr.corp.intel.com> In-Reply-To: <74D8A39837DF1E4DA445A8C0B3885C503F912B46@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-reaction: no-action dlp-version: 11.2.0.6 dlp-product: dlpe-windows authentication-results: spf=none (sender IP is ) smtp.mailfrom=amol.n.sukerkar@intel.com; x-originating-ip: [192.55.52.202] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: a383f187-a91a-440b-35ad-08d7a9c81675 x-ms-traffictypediagnostic: SN6PR11MB3069: x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6430; x-forefront-prvs: 03030B9493 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(376002)(136003)(396003)(366004)(39860400002)(199004)(189003)(8936002)(2906002)(6506007)(53546011)(54906003)(19627235002)(86362001)(81156014)(110136005)(81166006)(7696005)(26005)(9686003)(316002)(33656002)(66946007)(478600001)(76116006)(4326008)(71200400001)(66476007)(66556008)(64756008)(66446008)(55016002)(186003)(8676002)(30864003)(52536014)(5660300002)(107886003)(966005)(559001)(579004);DIR:OUT;SFP:1102;SCL:1;SRVR:SN6PR11MB3069;H:SN6PR11MB2893.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: f0TtbAd2sQo/MvDp08fFc1rVuepI1iHtvwKSU4c2YEcEKTmCndPC9TE7ZQYIYJTVw+S0r4xGFN2jnKMvgOjokJmJzRymo+gueGZcfxGv6cdDrafZA6ZTl2cmpYETvTu81PEYFvUbItYctCmY+EEtf7sYp2XZ9BmTNizHciNROdw1D//EHzsTyqkU7qKNlP9AahdY82fi940wDOgMeb5T6/HLut8Bny0J699jiRtDSul68KPXc7AdLTvWRPOdxSpBEPButD5XW8nCvWPpvXQxr33uoG4zouNFNcwld1nnxXkEFWIigGI74sjRIxQNjmPucaCmXZVUs4vbLKEewesAViVQ3f5Oodkw+qo/UzRLYiJZWcNawTBrFQhQjx7hI65PIby7NL+KOGWaOOXRJwnTzy8v+6+Dwo/7SQvh8XH5hjbY02XgL47fOlN53t/uzTOo9pUeke/eG/5Q0wRBfs4Yq/Q6quSNHITx03V1nz2fp3RI5Zh8O15mXPuZB879+QmBO1UhaZ93rIt8jOUcBH2PVQ== x-ms-exchange-antispam-messagedata: A4lt5kGTj6C3zu8J4IqQKeasy6f+fuOQJqyvhWCb5qRfBTn96/nE+SPHXSTgwSTv3mRaZqdOUB7GY0DO9ZR6AjiEMXA/p1mOAFymPg49uzvg/SVROGLV/aQEflYzjNrdxTYHXQILI7WviFjMGps/Vg== MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: a383f187-a91a-440b-35ad-08d7a9c81675 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Feb 2020 23:15:12.9639 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Co6vI9V8e8iGAPjGJlZjWRKtLYDkGYM2c96/XD2khLe9LqhYrlVXJ7LnmMC1nP6kEkfFbfSMU6V8YmJUL5Gi75480sca4AcpYt4Q1BWk50g= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB3069 Return-Path: amol.n.sukerkar@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thanks for the feedback, Jiewen! In that case, I agree we should deprecate MD4, MD5 and SHA1 in BaseHashApiL= ib. If the above statement is accurate, I can start next set of patches to remo= ve the deprecated algorithms by creating a Bugzilla ticket. Please confirm. Thanks, Amol -----Original Message----- From: Yao, Jiewen =20 Sent: Tuesday, February 04, 2020 4:06 PM To: Sukerkar, Amol N ; Kinney, Michael D ; devel@edk2.groups.io Cc: Wang, Jian J Subject: RE: [Patch v10 2/2] CryptoPkg/BaseHashApiLib: Implement Unified Ha= sh Calculation API Amol We are in the process to deprecating SHA1. Currently SHA256 is default one. Some products are moving from SHA256 to SHA384. We did crypto usage analysis before. In the current EDKII code base, there is no code using MD4. The only code that using MD5 is the iSCSI. TPM1.2 has to use SHA1 - that is updated by the TPM2. Some old certificate was using SHA1. It will be deprecated and move to SHA2= 56. Even UEFI spec defines MD5, but it does not mean a product has to use MD5. = UEFI spec does not mandate that you must support MD5. Do you see any MD5 usage in BIOS except iSCSI? If no, I prefer to drop MD4/MD5 in this patch. Thank you Yao Jiewen > -----Original Message----- > From: Sukerkar, Amol N > Sent: Wednesday, February 5, 2020 1:10 AM > To: Kinney, Michael D ; Yao, Jiewen=20 > ; devel@edk2.groups.io > Cc: Wang, Jian J ; Sukerkar, Amol N=20 > > Subject: RE: [Patch v10 2/2] CryptoPkg/BaseHashApiLib: Implement=20 > Unified Hash Calculation API >=20 > Hi Jiewen and Mike, >=20 > I agree with general statement that MD4 and MD5 are deprecated.=20 > However, Although not MD4, UEFI spec 2.8 still mentions MD5 (and does=20 > not mention that it is deprecated). That is the reason MD4 and MD5 were i= ncluded. >=20 > If there is going to be an update to UEFI spec deprecating MD5 as=20 > well, we can definitely go ahead and remove MD5 (and MD4). I believe=20 > the decision is should we wait until the change to UEFI spec or make=20 > the change right now. Let me know which approach we should be following. >=20 > Thanks, > Amol >=20 > -----Original Message----- > From: Kinney, Michael D > Sent: Tuesday, February 04, 2020 9:26 AM > To: Yao, Jiewen ; devel@edk2.groups.io; Kinney,=20 > Michael D ; Sukerkar, Amol N=20 > > Cc: Wang, Jian J > Subject: RE: [Patch v10 2/2] CryptoPkg/BaseHashApiLib: Implement=20 > Unified Hash Calculation API >=20 > Jiewen, >=20 > I think UINT8 is fine. We can change default to 0x04 in DEC file. >=20 > I will let Amol comment on why MD4 and MD5 are included. If they are=20 > not required, then I agree they should be removed. >=20 > I do not see a reason to align with TCG spec. The HashApiLib is a=20 > layer on top of BaseCryptLib and the use of hash algorithms is not=20 > limited to TCG related content. The BaseCryptLib could potentially=20 > adopt hash algorithms that are not defined in the TCG specification. =20 > We also do not want CryptoPkg to depend on the SecurityPkg. >=20 > Thanks, >=20 > Mike >=20 > > -----Original Message----- > > From: Yao, Jiewen > > Sent: Monday, February 3, 2020 6:54 PM > > To: Kinney, Michael D ;=20 > > devel@edk2.groups.io > > Cc: Sukerkar, Amol N ; Wang, Jian J=20 > > > > Subject: RE: [Patch v10 2/2] CryptoPkg/BaseHashApiLib: > > Implement Unified Hash Calculation API > > > > Thanks Mike, to cover us during Chinese New Year holiday. > > > > I am just back from vocation. A minor comment: > > > > The PcdHashApiLibPolicy is UINT8, but the value is shown as 32bit=20 > > 0x00000004. > > > > There are couple of ways to enhance: > > 1) Define UINT8, and use 8bit style 0x04. > > 2) Define UINT32, and use 32bit style 0x00000004. > > 3) Define UINT16 (match TCG definition), and use TCG defined value. > > (Tpm20.h) > > #define TPM_ALG_SHA1 (TPM_ALG_ID)(0x0004) > > #define TPM_ALG_SHA256 (TPM_ALG_ID)(0x000B) > > #define TPM_ALG_SHA384 (TPM_ALG_ID)(0x000C) > > #define TPM_ALG_SHA512 (TPM_ALG_ID)(0x000D) > > #define TPM_ALG_SM3_256 (TPM_ALG_ID)(0x0012) > > > > MD4 and MD5 are known as insecure and deprecated. I doubt if we want=20 > > to add such support. (I strong recommend NO). > > > > If we can remove MD4 and MD5, I think we can use #3. > > > > Thank you > > Yao Jiewen > > > > > -----Original Message----- > > > From: Kinney, Michael D > > > Sent: Tuesday, February 4, 2020 7:36 AM > > > To: devel@edk2.groups.io > > > Cc: Sukerkar, Amol N ; > > Yao, Jiewen > > > ; Wang, Jian J > > > > > Subject: [Patch v10 2/2] CryptoPkg/BaseHashApiLib: > > Implement Unified Hash > > > Calculation API > > > > > > From: Amol N Sukerkar > > > > > > https://bugzilla.tianocore.org/show_bug.cgi?id=3D2151 > > > > > > 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,=20 > > > 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 > > > > > Reviewed-by: Michael D Kinney > > > > > --- > > > CryptoPkg/CryptoPkg.dec | 20 > > ++ > > > CryptoPkg/CryptoPkg.dsc | 4 > > +- > > > CryptoPkg/CryptoPkg.uni | 18 > > +- > > > CryptoPkg/Include/Library/HashApiLib.h | 122 > > +++++++ > > > .../Library/BaseHashApiLib/BaseHashApiLib.c | 330 > > ++++++++++++++++++ > > > .../Library/BaseHashApiLib/BaseHashApiLib.inf | 44 > > +++ > > > .../Library/BaseHashApiLib/BaseHashApiLib.uni | 17 > > + > > > 7 files changed, 553 insertions(+), 2 deletions(-) create mode > > > 100644 > > CryptoPkg/Include/Library/HashApiLib.h > > > create mode 100644 > > CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.c > > > create mode 100644 > > CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.inf > > > create mode 100644 > > CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.uni > > > > > > diff --git a/CryptoPkg/CryptoPkg.dec > > b/CryptoPkg/CryptoPkg.dec > > > index 41af6e879e..8ad0fb5d61 100644 > > > --- a/CryptoPkg/CryptoPkg.dec > > > +++ b/CryptoPkg/CryptoPkg.dec > > > @@ -33,9 +33,29 @@ [LibraryClasses] > > > ## > > > TlsLib|Include/Library/TlsLib.h > > > > > > + ## @libraryclass Provides Unified API for > > different hash implementations. > > > + # > > > + HashApiLib|Include/Library/HashApiLib.h > > > + > > > [Guids] > > > ## Crypto package token space guid. > > > gEfiCryptoPkgTokenSpaceGuid =3D { 0x6bd7de60, > > 0x9ef7, 0x4899, { 0x97, > > > 0xd0, 0xab, 0xff, 0xfd, 0xe9, 0x70, 0xf2 } } > > > > > > +[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|UI > > NT8|0x00000001 > > > + > > > [UserExtensions.TianoCore."ExtraFiles"] > > > CryptoPkgExtra.uni > > > diff --git a/CryptoPkg/CryptoPkg.dsc > > b/CryptoPkg/CryptoPkg.dsc > > > index ec43c1f0a4..9656a73b3c 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] > > > > > > > > IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLi > > b.inf > > > > > OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf > > > + > > HashApiLib|CryptoPkg/Library/BaseHashApiLib/BaseHashApi > > Lib.inf > > > > > > [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 > > > > > > [Components.IA32, Components.X64] > > > CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf > > > diff --git a/CryptoPkg/CryptoPkg.uni > > b/CryptoPkg/CryptoPkg.uni > > > index beb0036ef5..0dae4c4045 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=20 > > > +17,19 @@ > > > > > > > > > > > > +#string > > STR_gEfiCryptoPkgTokenSpaceGuid_PcdHashApiLibPolicy_PRO > > MPT > > > #language en-US "HASH algorithm to calculate hash" > > > + > > > +#string > > STR_gEfiCryptoPkgTokenSpaceGuid_PcdHashApiLibPolicy_HEL > > P > > > #language 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 SHA256.
\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/Library/HashApiLib.h > > > new file mode 100644 > > > index 0000000000..22068e5a17 > > > --- /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, in bytes, of the context > > buffer required for hash operations. > > > + > > > + @return The size, in bytes, of the context buffer > > required for hash operations. > > > +**/ > > > +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/BaseHashApiLib/BaseHashApiLib.c > > > b/CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.c > > > new file mode 100644 > > > index 0000000000..277ef9f0b4 > > > --- /dev/null > > > +++ > > b/CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.c > > > @@ -0,0 +1,330 @@ > > > +/** @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=20 > > > + #include =20 > > > +#include #include =20 > > > +#include > > > + > > > +/** > > > + Retrieves the size, in bytes, of the context > > buffer required for hash operations. > > > + > > > + @return The size, in bytes, of the context buffer > > required for hash operations. > > > +**/ > > > +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 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: > > > + 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/Library/BaseHashApiLib/BaseHashApiLib.inf > > > b/CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.inf > > > new file mode 100644 > > > index 0000000000..b4d8675ddd > > > --- /dev/null > > > +++ > > b/CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.inf > > > @@ -0,0 +1,44 @@ > > > +## @file > > > +# Provides Unified API for Hash Calculation # # This library is=20 > > > +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 B1E566DD-DE7C- > > 4F04-BDA0-B1295D3BE927 > > > + 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/BaseHashApiLib/BaseHashApiLib.uni > > > b/CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.uni > > > new file mode 100644 > > > index 0000000000..49ba82e86f > > > --- /dev/null > > > +++ > > b/CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.uni > > > @@ -0,0 +1,17 @@ > > > +// /** @file > > > +// Provides Unified API for Hash Calculation // // This library=20 > > > +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 > > > service by specified hash handler" > > > + > > > +#string STR_MODULE_DESCRIPTION #language > > en-US "This library is > > > Unified Hash API. It will redirect hash request to > > the hash handler specified by > > > PcdHashApiLibPolicy." > > > -- > > > 2.21.0.windows.1 >=20 >=20