From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.3446.1579232854511611353 for ; Thu, 16 Jan 2020 19:47:34 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=jL8KqZ41; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: amol.n.sukerkar@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2020 19:47:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,328,1574150400"; d="scan'208";a="373538197" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga004.jf.intel.com with ESMTP; 16 Jan 2020 19:47:33 -0800 Received: from FMSEDG002.ED.cps.intel.com (10.1.192.134) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 16 Jan 2020 19:47:33 -0800 Received: from NAM04-CO1-obe.outbound.protection.outlook.com (104.47.45.56) by edgegateway.intel.com (192.55.55.69) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 16 Jan 2020 19:47:33 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l9cvrNWLX+7+EZphuQWIhkEKV2W7nAIXa48ci0/S2RRdlJikzmGsN4mM1wR9ciuvmXONwf81uwlHZO3Zlxp4tEr/4PRINjwFJpnzQSnCMz6yB6YQws/eu3o/lQJg43h0LeHO1+kftVLPzb8Dr7665F5l52VSd0vczjfk+9K6rGb5eQTD3u7uvf8yViC4MMQHNhLfOD0Je3HANURZ76HC7Hpbm7p20BgJexz3v+YHv/Ke3J//GTnHeW8FZhUVXplkXgnivdCq5y2Xmyph4sVRCOz5pc8HQCHY1Ve+5UN+pPJPe30CNl2eaJdDi7nZraXSVwTiBMCQg7P+ITAG0Jg0WA== 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=fhaMA3aqlTQFSTyQODUnFc6KbKxLot2QV4NV0laHAfU=; b=gDZL4fTD78jzgSwjsz5DSSOKfiMPlqGqDssMiDkFpanJ/5EN5RavpsSsgxFwWsBTVuP7YHwR3zk0c3jL34kfW4+CBJnJo8LGCfd7mmXv78oIpSZ3kh5+PgAHkUdJA22J0zAz3st5fix7tO7DnZyqLiH8cimWbK70+Zfn08T6Q+WIpPcN++FDM36eRnciRibeNIyf17uKsyTKPxjRqzTlWpck3dAt7ddUdCem4q+XSP3zmkj1agYMHiMi/yLQHeb4IXQoJH7kknVoK/61bQBP8tqAkQV2sXQIF/VfHCoi+tGmMCcl37uWjjJO58RRQ/6LT7FBagzsJNIGNwTtg25crQ== 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=fhaMA3aqlTQFSTyQODUnFc6KbKxLot2QV4NV0laHAfU=; b=jL8KqZ41zrdqBVKVv+4Gexi2InJY0bCR/WggXqVkfBFLrQSheR8ihAKla2EsCaEPc9m88xVIbM1CccjF0p/4OvaVd487XxxEGb1pgCqIdLalXzMdOinhHYJ0+Y7WQEIbbmyPdKGH4NQW8UM40JNLMvrJya754pWuttp2kO7Rsq8= Received: from MWHPR11MB0064.namprd11.prod.outlook.com (10.164.192.146) by MWHPR11MB1263.namprd11.prod.outlook.com (10.169.237.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2623.14; Fri, 17 Jan 2020 03:47:30 +0000 Received: from MWHPR11MB0064.namprd11.prod.outlook.com ([fe80::6921:1be9:8a98:4549]) by MWHPR11MB0064.namprd11.prod.outlook.com ([fe80::6921:1be9:8a98:4549%5]) with mapi id 15.20.2623.018; Fri, 17 Jan 2020 03:47:30 +0000 From: "Sukerkar, Amol N" To: "Gao, Liming" , "devel@edk2.groups.io" , "Wang, Jian J" CC: "Kinney, Michael D" , "Yao, Jiewen" , "Agrawal, Sachin" , "Musti, Srinivas" , "Sukerkar, Amol N" Subject: Re: [edk2-devel] [PATCH v2 1/1] SecurityPkg/BaseHashLib: Implement Unified Hash Calculation API Thread-Topic: [edk2-devel] [PATCH v2 1/1] SecurityPkg/BaseHashLib: Implement Unified Hash Calculation API Thread-Index: AQHVyvETJsClZTDraE6d24/5UbWyCKfrCD2ggAAO3ACAAUHXQIAATh2AgAANR5CAAAKkgIAAzzaAgAB+uACAADbYgA== Date: Fri, 17 Jan 2020 03:47:30 +0000 Message-ID: References: <20200114154107.655-1-amol.n.sukerkar@intel.com> <20200114154107.655-2-amol.n.sukerkar@intel.com> <233b34aaf0f241aa8f997c2eac4aa306@intel.com> <204e104f9b3c4cef81cdf6503074d911@intel.com> <9d9fbe3f0fd6436b95b8adb2a3fc80d9@intel.com> In-Reply-To: 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: [134.134.136.215] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4fe0fa76-e752-408f-538c-08d79afffa5e x-ms-traffictypediagnostic: MWHPR11MB1263: 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:10000; x-forefront-prvs: 0285201563 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(366004)(376002)(346002)(136003)(39860400002)(199004)(189003)(66446008)(66476007)(5660300002)(52536014)(7696005)(33656002)(6506007)(64756008)(76116006)(66556008)(66946007)(316002)(53546011)(107886003)(15188155005)(55016002)(478600001)(966005)(16799955002)(2906002)(45080400002)(9686003)(30864003)(15650500001)(26005)(86362001)(6636002)(19627235002)(71200400001)(54906003)(4326008)(66574012)(81156014)(8676002)(8936002)(81166006)(186003)(110136005)(569006);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR11MB1263;H:MWHPR11MB0064.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: DetuhvA7MoJYRiDhnTW5ir8SCUJhjk3og2BkPnJrSwRG40ic5JGzGWsxByNAt8JbdrkwljEdDarN8aTo+X4+R1FOZWDKpsO9WiNPG1NPzxtQaBCCrweSUlQYEW98Wxl/idKce2K/16p5SgrgH1XRkzuoU9xBFnIvHCneIMt1Zb1O6HY0TWKN9hfiIbmlNQJrJXEwHnL8MfO1wr1I0vyDSlhYhtGyyMbLP8vstwqnO8T1tjZ3xfrsoKWoapXvyAHi5uxH0R1YkLcOyoIszeWXDNRRpY70XSD606hD1sqY7D9SpiVeWcm8dFis0+buH36CaLCrC3UkcOAp3vWWwEvLFQgwOilpZTMOEA1kcgqVqWlhYgQ4PkKVbt6/Apsc7U/6CrvTqyagNkr641ZY4APd3GJpJxKogqWs7xkX/0BOgfXD0/4gHSxkBkERNSMXsi3N0QQRkpCytOJsm1+qoJHfh4pPe0dXa24x4KmzueE6Bs954pF1XLeEuUftIg3QcIayozXrB+saQhI23npoAMW3KA== MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 4fe0fa76-e752-408f-538c-08d79afffa5e X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jan 2020 03:47:30.1040 (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: iJGvKXGL+q2YUgEDL3OEa1jvxNn6GUCYUTvyjMAPKXrkrqTMhE8o2h9ZGdYoE5TLVvlB75U6+McAsznjw4P/rqO5M8dOBXqj3fixAvRmapk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR11MB1263 Return-Path: amol.n.sukerkar@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: quoted-printable Thanks, Liming! ~ Amol -----Original Message----- From: Gao, Liming =20 Sent: Thursday, January 16, 2020 5:31 PM To: Sukerkar, Amol N ; devel@edk2.groups.io; Wa= ng, Jian J Cc: Kinney, Michael D ; Yao, Jiewen ; Agrawal, Sachin ; Musti, Srinivas <= srinivas.musti@intel.com> Subject: RE: [edk2-devel] [PATCH v2 1/1] SecurityPkg/BaseHashLib: Implemen= t Unified Hash Calculation API Amol: I just add it into edk2 2020 Q1 stable tag feature planning.=20 Thanks Liming -----Original Message----- From: Sukerkar, Amol N Sent: 2020=1B$BG/=1B(B1=1B$B7n=1B(B17=1B$BF|=1B(B 0:58 To: Gao, Liming ; devel@edk2.groups.io; Wang, Jian J= Cc: Kinney, Michael D ; Yao, Jiewen ; Agrawal, Sachin ; Musti, Srinivas <= srinivas.musti@intel.com>; Sukerkar, Amol N Subject: RE: [edk2-devel] [PATCH v2 1/1] SecurityPkg/BaseHashLib: Implemen= t Unified Hash Calculation API Sure, Liming! Please add edk2 2020 Q1 stable tag to this feature. I will f= ollow the schedule. Thanks, Amol -----Original Message----- From: Gao, Liming Sent: Wednesday, January 15, 2020 9:36 PM To: Sukerkar, Amol N ; devel@edk2.groups.io; Wa= ng, Jian J Cc: Kinney, Michael D ; Yao, Jiewen ; Agrawal, Sachin ; Musti, Srinivas <= srinivas.musti@intel.com> Subject: RE: [edk2-devel] [PATCH v2 1/1] SecurityPkg/BaseHashLib: Implemen= t Unified Hash Calculation API If this change plans to catch edk2 2020 Q1 stable tag, I will add it into = https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Release-Planni= ng Then, you need to follow Q1 stable tag schedule to finish this change. > -----Original Message----- > From: Sukerkar, Amol N > Sent: Thursday, January 16, 2020 12:27 PM > To: devel@edk2.groups.io; Gao, Liming ; Wang,=20 > Jian J > Cc: Kinney, Michael D ; Yao, Jiewen=20 > ; Agrawal, Sachin ;=20 > Musti, Srinivas ; Sukerkar, Amol N=20 > > Subject: RE: [edk2-devel] [PATCH v2 1/1] SecurityPkg/BaseHashLib:=20 > Implement Unified Hash Calculation API >=20 > Thanks, Liming! How do I find out if it catches EDK 2020 Q1 stable tag? >=20 > ~ Amol >=20 > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Liming=20 > Gao > Sent: Wednesday, January 15, 2020 8:39 PM > To: Sukerkar, Amol N ;=20 > devel@edk2.groups.io; Wang, Jian J > Cc: Kinney, Michael D ; Yao, Jiewen=20 > ; Agrawal, Sachin ;=20 > Musti, Srinivas > Subject: Re: [edk2-devel] [PATCH v2 1/1] SecurityPkg/BaseHashLib:=20 > Implement Unified Hash Calculation API >=20 > Yes. Does it catch EDK2 2020 Q1 stable tag? >=20 > > -----Original Message----- > > From: Sukerkar, Amol N > > Sent: Thursday, January 16, 2020 7:02 AM > > To: Gao, Liming ; devel@edk2.groups.io; Wang,=20 > > Jian J > > Cc: Kinney, Michael D ; Yao, Jiewen=20 > > ; Agrawal, Sachin ;=20 > > Musti, Srinivas ; Sukerkar, Amol N=20 > > > > Subject: RE: [edk2-devel] [PATCH v2 1/1] SecurityPkg/BaseHashLib: > > Implement Unified Hash Calculation API > > > > Hi Liming, > > > > We already have a ticket filed in Bugzilla, https://bugzilla.tianocore= .org/show_bug.cgi?id=3D2151. Would this be sufficient? > > > > Thanks, > > Amol > > > > -----Original Message----- > > From: Gao, Liming > > Sent: Tuesday, January 14, 2020 8:47 PM > > To: devel@edk2.groups.io; Wang, Jian J ;=20 > > Sukerkar, Amol N > > Cc: Kinney, Michael D ; Yao, Jiewen=20 > > ; Agrawal, Sachin ;=20 > > Musti, Srinivas > > Subject: RE: [edk2-devel] [PATCH v2 1/1] SecurityPkg/BaseHashLib: > > Implement Unified Hash Calculation API > > > > Amol: > > This is new feature. Please submit BZ > > (https://bugzilla.tianocore.org/) to track it. If this feature catches= edk2 2020 Q1 stable tag, I will add it into edk2 feature planning. > > > > Thanks > > Liming > > -----Original Message----- > > From: devel@edk2.groups.io On Behalf Of Wang,= =20 > > Jian J > > Sent: 2020=1B$BG/=1B(B1=1B$B7n=1B(B15=1B$BF|=1B(B 11:14 > > To: Sukerkar, Amol N ;=20 > > devel@edk2.groups.io > > Cc: Kinney, Michael D ; Yao, Jiewen=20 > > ; Agrawal, Sachin ;=20 > > Musti, Srinivas > > Subject: Re: [edk2-devel] [PATCH v2 1/1] SecurityPkg/BaseHashLib: > > Implement Unified Hash Calculation API > > > > Amol, > > > > 1. Your patch doesn't support hashing more than one algorithm at the s= ame time. > > Is this on purpose? Sorry I don't remember the conclusion in last d= iscussion. > > 2. There're trailing spaces in BaseHashLibCommon.c and BashHashLibComm= on.h. > > You can use BaseTools\Scripts\PatchCheck.py to check it before send= ing patch. > > > > See my other comments below. > > > > > -----Original Message----- > > > From: Sukerkar, Amol N > > > Sent: Tuesday, January 14, 2020 11:41 PM > > > To: devel@edk2.groups.io > > > Cc: Kinney, Michael D ; Yao, Jiewen=20 > > > ; Wang, Jian J ;=20 > > > Agrawal, Sachin ; Musti, Srinivas=20 > > > > > > Subject: [PATCH v2 1/1] SecurityPkg/BaseHashLib: Implement Unified= =20 > > > Hash Calculation API > > > > > > This commit introduces a Unified Hash API to calculate hash using=20 > > > a hashing algorithm specified by the PCD, PcdSystemHashPolicy. > > > This library interfaces with the various hashing API, such as,=20 > > > MD4, MD5, SHA1, SHA256, > > > SHA512 and SM3_256 implemented in CryptoPkg. The user can=20 > > > calculate the desired hash by setting PcdSystemHashPolicy to appropr= iate value. > > > > > > Cc: Jiewen Yao > > > Cc: Jian J Wang > > > Cc: Michael D Kinney > > > Signed-off-by: Sukerkar, Amol N > > > --- > > > > > > Notes: > > > v2: > > > - Fixed the commit message format > > > > > > SecurityPkg/Library/BaseHashLib/BaseHashLibCommon.c | 252 > > > ++++++++++++++++++++ > > > SecurityPkg/Library/BaseHashLib/BaseHashLibDxe.c | 122 +++++++++= + > > > SecurityPkg/Library/BaseHashLib/BaseHashLibPei.c | 125 +++++++++= + > > > SecurityPkg/Include/Library/BaseHashLib.h | 84 +++++++ > > > SecurityPkg/Library/BaseHashLib/BaseHashLibCommon.h | 71 ++++++=20 > > > SecurityPkg/Library/BaseHashLib/BaseHashLibDxe.inf | 47 ++++=20 > > > SecurityPkg/Library/BaseHashLib/BaseHashLibDxe.uni | 18 ++=20 > > > SecurityPkg/Library/BaseHashLib/BaseHashLibPei.inf | 52 ++++=20 > > > SecurityPkg/Library/BaseHashLib/BaseHashLibPei.uni | 17 ++ > > > SecurityPkg/SecurityPkg.dec | 23 +- > > > SecurityPkg/SecurityPkg.dsc | 10 +- > > > SecurityPkg/SecurityPkg.uni | 15 +- > > > 12 files changed, 833 insertions(+), 3 deletions(-) > > > > > > diff --git a/SecurityPkg/Library/BaseHashLib/BaseHashLibCommon.c > > > b/SecurityPkg/Library/BaseHashLib/BaseHashLibCommon.c > > > new file mode 100644 > > > index 000000000000..f8742e55b5f7 > > > --- /dev/null > > > +++ b/SecurityPkg/Library/BaseHashLib/BaseHashLibCommon.c > > > @@ -0,0 +1,252 @@ > > > +/** @file > > > > > > + Implement image verification services for secure boot service > > > > > > + > > > > > > + Caution: This file requires additional review when modified. > > > > > > + This library will have external input - PE/COFF image. > > > > > > + This external input must be validated carefully to avoid=20 > > > + security issue like > > > > > > + buffer overflow, integer overflow. > > > > > > + > > > > > > + DxeImageVerificationLibImageRead() function will make sure the=20 > > > + PE/COFF > > > image content > > > > > > + read is within the image buffer. > > > > > > + > > > > > > + DxeImageVerificationHandler(), HashPeImageByType(), > > > + HashPeImage() > > > function will accept > > > > > > + untrusted PE/COFF image and validate its data structure within=20 > > > + this image > > > buffer before use. > > > > > > + > > > > > > +Copyright (c) 2009 - 2020, Intel Corporation. All rights=20 > > > +reserved.
> > > > > > +(C) Copyright 2016 Hewlett Packard Enterprise Development LP
> > > > > > +This program and the accompanying materials > > > > > > +are licensed and made available under the terms and conditions of= =20 > > > +the BSD > > > License > > > > > > +which accompanies this distribution. The full text of the=20 > > > +license may be found > > > at > > > > > > +http://opensource.org/licenses/bsd-license.php > > > > > > + > > > > > > +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > > +BASIS, > > > > > > +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > > > OR IMPLIED. > > > > > > + > > > > > > +**/ > > > > > > + > > > > > > +#include > > > > > > +#include > > > > > > +#include > > > > > > +#include > > > > > > +#include > > > > > > +#include > > > > > > +#include > > > > > > + > > > > > > +/** > > > > > > + Init hash sequence with Hash Algorithm specified by HashPolicy. > > > > > > + > > > > > > + @param HashPolicy Hash Algorithm Policy. > > > > > > + @param HashHandle Hash handle. > > > > > > + > > > > > > + @retval TRUE Hash start and HashHandle returned. > > > > > > + @retval FALSE Hash Init unsuccessful. > > > > > > +**/ > > > > > > +BOOLEAN > > > > > > +EFIAPI > > > > > > +HashInitInternal ( > > > > > > + IN UINT8 HashPolicy, > > > > > > + OUT HASH_HANDLE *HashHandle > > > > > > + ) > > > > > > +{ > > > > > > + BOOLEAN Status; > > > > > > + VOID *HashCtx; > > > > > > + UINTN CtxSize; > > > > > > + > > > > > > + switch (HashPolicy) { > > > > > > + case HASH_MD4: > > > > > > + CtxSize =3D Md4GetContextSize (); > > > > > > + HashCtx =3D AllocatePool (CtxSize); > > > > > > + ASSERT (HashCtx !=3D NULL); > > > > > > + > > > > > > + Status =3D Md4Init (HashCtx); > > > > > > + break; > > > > > > + > > > > > > + case HASH_MD5: > > > > > > + CtxSize =3D Md5GetContextSize (); > > > > > > + HashCtx =3D AllocatePool (CtxSize); > > > > > > + ASSERT (HashCtx !=3D NULL); > > > > > > + > > > > > > + Status =3D Md5Init (HashCtx); > > > > > > + break; > > > > > > + > > > > > > + case HASH_SHA1: > > > > > > + CtxSize =3D Sha1GetContextSize (); > > > > > > + HashCtx =3D AllocatePool (CtxSize); > > > > > > + ASSERT (HashCtx !=3D NULL); > > > > > > + > > > > > > + Status =3D Sha1Init (HashCtx); > > > > > > + break; > > > > > > + > > > > > > + case HASH_SHA256: > > > > > > + CtxSize =3D Sha256GetContextSize (); > > > > > > + HashCtx =3D AllocatePool (CtxSize); > > > > > > + ASSERT (HashCtx !=3D NULL); > > > > > > + > > > > > > + Status =3D Sha256Init (HashCtx); > > > > > > + break; > > > > > > + > > > > > > + case HASH_SHA384: > > > > > > + CtxSize =3D Sha384GetContextSize (); > > > > > > + HashCtx =3D AllocatePool (CtxSize); > > > > > > + ASSERT (HashCtx !=3D NULL); > > > > > > + > > > > > > + Status =3D Sha384Init (HashCtx); > > > > > > + break; > > > > > > + > > > > > > + case HASH_SHA512: > > > > > > + CtxSize =3D Sha512GetContextSize (); > > > > > > + HashCtx =3D AllocatePool (CtxSize); > > > > > > + ASSERT (HashCtx !=3D NULL); > > > > > > + > > > > > > + Status =3D Sha512Init (HashCtx); > > > > > > + break; > > > > > > + > > > > > > + case HASH_SM3_256: > > > > > > + CtxSize =3D Sm3GetContextSize (); > > > > > > + HashCtx =3D AllocatePool (CtxSize); > > > > > > + ASSERT (HashCtx !=3D NULL); > > > > > > + > > > > > > + Status =3D Sm3Init (HashCtx); > > > > > > + break; > > > > > > + > > > > > > + default: > > > > > > + ASSERT (FALSE); > > > > > > + break; > > > > > > + } > > > > > > + > > > > 3. Instead of switch..case, using a global array to defines all=20 > > supported interfaces would be more efficient, since you can value of P= cdSystemHashPolicy to index them directly. > > > > > > > > + *HashHandle =3D (HASH_HANDLE)HashCtx; > > > > > > + > > > > > > + return Status; > > > > > > +} > > > > > > + > > > > > > +/** > > > > > > + Update hash data with Hash Algorithm specified by HashPolicy. > > > > > > + > > > > > > + @param HashPolicy Hash Algorithm Policy. > > > > > > + @param HashHandle Hash handle. > > > > > > + @param DataToHash Data to be hashed. > > > > > > + @param DataToHashLen Data size. > > > > > > + > > > > > > + @retval TRUE Hash updated. > > > > > > + @retval FALSE Hash updated unsuccessful. > > > > > > +**/ > > > > > > +BOOLEAN > > > > > > +EFIAPI > > > > > > +HashUpdateInternal ( > > > > > > + IN UINT8 HashPolicy, > > > > > > + IN HASH_HANDLE HashHandle, > > > > > > + IN VOID *DataToHash, > > > > > > + IN UINTN DataToHashLen > > > > > > + ) > > > > > > +{ > > > > > > + BOOLEAN Status; > > > > > > + VOID *HashCtx; > > > > > > + > > > > > > + HashCtx =3D (VOID *)HashHandle; > > > > > > + > > > > > > + switch (HashPolicy) { > > > > > > + case HASH_MD4: > > > > > > + Status =3D Md4Update (HashCtx, DataToHash, DataToHashLen); > > > > > > + break; > > > > > > + > > > > > > + case HASH_MD5: > > > > > > + Status =3D Md5Update (HashCtx, DataToHash, DataToHashLen); > > > > > > + break; > > > > > > + > > > > > > + case HASH_SHA1: > > > > > > + Status =3D Sha1Update (HashCtx, DataToHash, DataToHashLen); > > > > > > + break; > > > > > > + > > > > > > + case HASH_SHA256: > > > > > > + Status =3D Sha256Update (HashCtx, DataToHash, DataToHashLen); > > > > > > + break; > > > > > > + > > > > > > + case HASH_SHA384: > > > > > > + Status =3D Sha384Update (HashCtx, DataToHash, DataToHashLen); > > > > > > + break; > > > > > > + > > > > > > + case HASH_SHA512: > > > > > > + Status =3D Sha512Update (HashCtx, DataToHash, DataToHashLen); > > > > > > + break; > > > > > > + > > > > > > + case HASH_SM3_256: > > > > > > + Status =3D Sm3Update (HashCtx, DataToHash, DataToHashLen); > > > > > > + break; > > > > > > + > > > > > > + default: > > > > > > + ASSERT (FALSE); > > > > > > + break; > > > > > > + } > > > > > > > 4. The same as 3 > > > > > + > > > > > > + return Status; > > > > > > +} > > > > > > + > > > > > > +/** > > > > > > + Hash complete with Hash Algorithm specified by HashPolicy. > > > > > > + > > > > > > + @param HashPolicy Hash Algorithm Policy. > > > > > > + @param HashHandle Hash handle. > > > > > > + @param Digest Hash Digest. > > > > > > + > > > > > > + @retval TRUE Hash complete and Digest is returned. > > > > > > + @retval FALSE Hash complete unsuccessful. > > > > > > +**/ > > > > > > +BOOLEAN > > > > > > +EFIAPI > > > > > > +HashFinalInternal ( > > > > > > + IN UINT8 HashPolicy, > > > > > > + IN HASH_HANDLE HashHandle, > > > > > > + OUT UINT8 **Digest > > > > > > + ) > > > > > > +{ > > > > > > + BOOLEAN Status; > > > > > > + VOID *HashCtx; > > > > > > + UINT8 DigestData[SHA512_DIGEST_SIZE]; > > > > > > + > > > > > > + HashCtx =3D (VOID *)HashHandle; > > > > > > + > > > > > > + switch (HashPolicy) { > > > > > > + case HASH_MD4: > > > > > > + Status =3D Md4Final (HashCtx, DigestData); > > > > > > + CopyMem (*Digest, DigestData, MD4_DIGEST_SIZE); > > > > > > + break; > > > > > > + > > > > > > + case HASH_MD5: > > > > > > + Status =3D Md5Final (HashCtx, DigestData); > > > > > > + CopyMem (*Digest, DigestData, MD5_DIGEST_SIZE); > > > > > > + break; > > > > > > + > > > > > > + case HASH_SHA1: > > > > > > + Status =3D Sha1Final (HashCtx, DigestData); > > > > > > + CopyMem (*Digest, DigestData, SHA1_DIGEST_SIZE); > > > > > > + break; > > > > > > + > > > > > > + case HASH_SHA256: > > > > > > + Status =3D Sha256Final (HashCtx, DigestData); > > > > > > + CopyMem (*Digest, DigestData, SHA256_DIGEST_SIZE); > > > > > > + break; > > > > > > + > > > > > > + case HASH_SHA384: > > > > > > + Status =3D Sha384Final (HashCtx, DigestData); > > > > > > + CopyMem (*Digest, DigestData, SHA384_DIGEST_SIZE); > > > > > > + break; > > > > > > + > > > > > > + case HASH_SHA512: > > > > > > + Status =3D Sha512Final (HashCtx, DigestData); > > > > > > + CopyMem (*Digest, DigestData, SHA512_DIGEST_SIZE); > > > > > > + break; > > > > > > + > > > > > > + case HASH_SM3_256: > > > > > > + Status =3D Sm3Final (HashCtx, DigestData); > > > > > > + CopyMem (*Digest, DigestData, SM3_256_DIGEST_SIZE); > > > > > > + break; > > > > > > + > > > > > > + default: > > > > > > + ASSERT (FALSE); > > > > > > + break; > > > > > > > 5. The same as 3 > > > > > + } > > > > > > + > > > > > > + FreePool (HashCtx); > > > > > > + > > > > > > + return Status; > > > > > > +} > > > \ No newline at end of file > > > diff --git a/SecurityPkg/Library/BaseHashLib/BaseHashLibDxe.c > > > b/SecurityPkg/Library/BaseHashLib/BaseHashLibDxe.c > > > new file mode 100644 > > > index 000000000000..ea22cfe16e2f > > > --- /dev/null > > > +++ b/SecurityPkg/Library/BaseHashLib/BaseHashLibDxe.c > > > @@ -0,0 +1,122 @@ > > > +/** @file > > > > > > + This library is Unified Hash API. It will redirect hash request= =20 > > > + to > > > > > > + the hash handler specified by PcdSystemHashPolicy such as SHA1,= =20 > > > + SHA256, > > > > > > + SHA384 and SM3... > > > > > > + > > > > > > +Copyright (c) 2013 - 2020, Intel Corporation. All rights reserved. > > > +
> > > > > > +SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > + > > > > > > +**/ > > > > > > + > > > > > > + > > > > > > +#include > > > > > > +#include > > > > > > +#include > > > > > > +#include > > > > > > +#include > > > > > > +#include > > > > > > + > > > > > > +#include "BaseHashLibCommon.h" > > > > > > + > > > > > > +/** > > > > > > + Init hash sequence. > > > > > > + > > > > > > + @param HashHandle Hash handle. > > > > > > + > > > > > > + @retval TRUE Hash start and HashHandle returned. > > > > > > + @retval FALSE Hash Init unsuccessful. > > > > > > +**/ > > > > > > +BOOLEAN > > > > > > +EFIAPI > > > > > > +HashApiInit ( > > > > > > + OUT HASH_HANDLE *HashHandle > > > > > > +) > > > > > > +{ > > > > > > + BOOLEAN Status; > > > > > > + UINT8 HashPolicy; > > > > > > + HASH_HANDLE Handle; > > > > > > + > > > > > > + HashPolicy =3D PcdGet8 (PcdSystemHashPolicy); > > > > > > + > > > > > > + Status =3D HashInitInternal (HashPolicy, &Handle); > > > > > > + > > > > > > + *HashHandle =3D Handle; > > > > > > + > > > > > > + return Status; > > > > > > +} > > > > > > + > > > > > > +/** > > > > > > + Update hash data. > > > > > > + > > > > > > + @param HashHandle Hash handle. > > > > > > + @param DataToHash Data to be hashed. > > > > > > + @param DataToHashLen Data size. > > > > > > + > > > > > > + @retval TRUE Hash updated. > > > > > > + @retval FALSE Hash updated unsuccessful. > > > > > > +**/ > > > > > > +BOOLEAN > > > > > > +EFIAPI > > > > > > +HashApiUpdate ( > > > > > > + IN HASH_HANDLE HashHandle, > > > > > > + IN VOID *DataToHash, > > > > > > + IN UINTN DataToHashLen > > > > > > +) > > > > > > +{ > > > > > > + BOOLEAN Status; > > > > > > + UINT8 HashPolicy; > > > > > > + > > > > > > + HashPolicy =3D PcdGet8 (PcdSystemHashPolicy); > > > > > > + > > > > > > + Status =3D HashUpdateInternal (HashPolicy, HashHandle,=20 > > > + DataToHash, > > > DataToHashLen); > > > > > > + > > > > > > + return Status; > > > > > > +} > > > > > > + > > > > > > +/** > > > > > > + Hash complete. > > > > > > + > > > > > > + @param HashHandle Hash handle. > > > > > > + @param Digest Hash Digest. > > > > > > + > > > > > > + @retval TRUE Hash complete and Digest is returned. > > > > > > + @retval FALSE Hash complete unsuccessful. > > > > > > +**/ > > > > > > +BOOLEAN > > > > > > +EFIAPI > > > > > > +HashApiFinal ( > > > > > > + IN HASH_HANDLE HashHandle, > > > > > > + OUT UINT8 *Digest > > > > > > +) > > > > > > +{ > > > > > > + BOOLEAN Status; > > > > > > + UINT8 HashPolicy; > > > > > > + > > > > > > + HashPolicy =3D PcdGet8 (PcdSystemHashPolicy); > > > > > > + > > > > > > + Status =3D HashFinalInternal (HashPolicy, &HashHandle, &Digest); > > > > > > + > > > > > > + return Status; > > > > > > +} > > > > > > + > > > > > > +/** > > > > > > + The constructor function of BaseHashLib Dxe. > > > > > > + > > > > > > + @param FileHandle The handle of FFS header the loaded driver. > > > > > > + @param PeiServices The pointer to the PEI services. > > > > > > + > > > > > > + @retval EFI_SUCCESS The constructor executes successful= ly. > > > > > > + @retval EFI_OUT_OF_RESOURCES There is no enough resource for=20 > > > + the > > > constructor. > > > > > > + > > > > > > +**/ > > > > > > +EFI_STATUS > > > > > > +EFIAPI > > > > > > +BaseHashLibApiDxeConstructor ( > > > > > > + IN EFI_HANDLE ImageHandle, > > > > > > + IN EFI_SYSTEM_TABLE *SystemTable > > > > > > + ) > > > > > > +{ > > > > > > + DEBUG ((DEBUG_INFO,"Calling BaseHashLibApiDxeConstructor..=20 > > > + \n")); > > > > > > + > > > > > > + return EFI_SUCCESS; > > > > > > +} > > > > 6. Constructor is not necessary if you don't have anything to do with = it. > > You can remove it from inf file and here. > > > > > \ No newline at end of file > > > diff --git a/SecurityPkg/Library/BaseHashLib/BaseHashLibPei.c > > > b/SecurityPkg/Library/BaseHashLib/BaseHashLibPei.c > > > new file mode 100644 > > > index 000000000000..580ac21fc1d9 > > > --- /dev/null > > > +++ b/SecurityPkg/Library/BaseHashLib/BaseHashLibPei.c > > > @@ -0,0 +1,125 @@ > > > +/** @file > > > > > > + This library is Unified Hash API. It will redirect hash request= =20 > > > + to > > > > > > + the hash handler specified by PcdSystemHashPolicy such as SHA1,= =20 > > > + SHA256, > > > > > > + SHA384 and SM3... > > > > > > + > > > > > > +Copyright (c) 2013 - 2020, Intel Corporation. All rights reserved. > > > +
> > > > > > +SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > + > > > > > > +**/ > > > > > > + > > > > > > + > > > > > > +#include > > > > > > +#include > > > > > > +#include > > > > > > +#include > > > > > > +#include > > > > > > +#include > > > > > > +#include > > > > > > +#include > > > > > > + > > > > > > +#include > > > > > > +#include "BaseHashLibCommon.h" > > > > > > + > > > > > > +/** > > > > > > + Init hash sequence. > > > > > > + > > > > > > + @param HashHandle Hash handle. > > > > > > + > > > > > > + @retval TRUE Hash start and HashHandle returned. > > > > > > + @retval FALSE Hash Init unsuccessful. > > > > > > +**/ > > > > > > +BOOLEAN > > > > > > +EFIAPI > > > > > > +HashApiInit ( > > > > > > + OUT HASH_HANDLE *HashHandle > > > > > > +) > > > > > > +{ > > > > > > + BOOLEAN Status; > > > > > > + UINT8 HashPolicy; > > > > > > + HASH_HANDLE Handle; > > > > > > + > > > > > > + HashPolicy =3D PcdGet8 (PcdSystemHashPolicy); > > > > > > + > > > > > > + Status =3D HashInitInternal (HashPolicy, &Handle); > > > > > > + > > > > > > + *HashHandle =3D Handle; > > > > > > + > > > > > > + return Status; > > > > > > +} > > > > > > + > > > > > > +/** > > > > > > + Update hash data. > > > > > > + > > > > > > + @param HashHandle Hash handle. > > > > > > + @param DataToHash Data to be hashed. > > > > > > + @param DataToHashLen Data size. > > > > > > + > > > > > > + @retval TRUE Hash updated. > > > > > > + @retval FALSE Hash updated unsuccessful. > > > > > > +**/ > > > > > > +BOOLEAN > > > > > > +EFIAPI > > > > > > +HashApiUpdate ( > > > > > > + IN HASH_HANDLE HashHandle, > > > > > > + IN VOID *DataToHash, > > > > > > + IN UINTN DataToHashLen > > > > > > +) > > > > > > +{ > > > > > > + BOOLEAN Status; > > > > > > + UINT8 HashPolicy; > > > > > > + > > > > > > + HashPolicy =3D PcdGet8 (PcdSystemHashPolicy); > > > > > > + > > > > > > + Status =3D HashUpdateInternal (HashPolicy, HashHandle,=20 > > > + DataToHash, > > > DataToHashLen); > > > > > > + > > > > > > + return Status; > > > > > > +} > > > > > > + > > > > > > +/** > > > > > > + Hash complete. > > > > > > + > > > > > > + @param HashHandle Hash handle. > > > > > > + @param Digest Hash Digest. > > > > > > + > > > > > > + @retval TRUE Hash complete and Digest is returned. > > > > > > + @retval FALSE Hash complete unsuccessful. > > > > > > +**/ > > > > > > +BOOLEAN > > > > > > +EFIAPI > > > > > > +HashApiFinal ( > > > > > > + IN HASH_HANDLE HashHandle, > > > > > > + OUT UINT8 *Digest > > > > > > +) > > > > > > +{ > > > > > > + BOOLEAN Status; > > > > > > + UINT8 HashPolicy; > > > > > > + > > > > > > + HashPolicy =3D PcdGet8 (PcdSystemHashPolicy); > > > > > > + > > > > > > + Status =3D HashFinalInternal (HashPolicy, HashHandle, &Digest); > > > > > > + > > > > > > + return Status; > > > > > > +} > > > > > > + > > > > > > +/** > > > > > > + The constructor function of BaseHashLib Pei. > > > > > > + > > > > > > + @param FileHandle The handle of FFS header the loaded driver. > > > > > > + @param PeiServices The pointer to the PEI services. > > > > > > + > > > > > > + @retval EFI_SUCCESS The constructor executes successful= ly. > > > > > > + @retval EFI_OUT_OF_RESOURCES There is no enough resource for=20 > > > + the > > > constructor. > > > > > > + > > > > > > +**/ > > > > > > +EFI_STATUS > > > > > > +EFIAPI > > > > > > +BaseHashLibApiPeiConstructor ( > > > > > > + IN EFI_PEI_FILE_HANDLE FileHandle, > > > > > > + IN CONST EFI_PEI_SERVICES **PeiServices > > > > > > + ) > > > > > > +{ > > > > > > + DEBUG ((DEBUG_INFO,"Calling BaseHashLibApiPeiConstructor..=20 > > > + \n")); > > > > > > + > > > > > > + return EFI_SUCCESS; > > > > > > +} > > > > 7. The same as 6 > > > > > \ No newline at end of file > > > diff --git a/SecurityPkg/Include/Library/BaseHashLib.h > > > b/SecurityPkg/Include/Library/BaseHashLib.h > > > new file mode 100644 > > > index 000000000000..e1883fe7ce41 > > > --- /dev/null > > > +++ b/SecurityPkg/Include/Library/BaseHashLib.h > > > @@ -0,0 +1,84 @@ > > > +/** @file > > > + The internal header file includes the common header files,=20 > > > +defines > > > + internal structure and functions used by ImageVerificationLib. > > > + > > > +Copyright (c) 2009 - 2020, Intel Corporation. All rights=20 > > > +reserved.
This program and the accompanying materials are=20 > > > +licensed and made available under the terms and conditions of the= =20 > > > +BSD > > > License > > > +which accompanies this distribution. The full text of the=20 > > > +license may be found > > > at > > > +http://opensource.org/licenses/bsd-license.php > > > + > > > +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > > +BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER=20 > > > +EXPRESS > > > OR IMPLIED. > > > + > > > +**/ > > > + > > > +#ifndef __BASEHASHLIB_H_ > > > +#define __BASEHASHLIB_H_ > > > + > > > +#include > > > +#include > > > +#include > > > + > > > +// > > > +// Hash Algorithms > > > +// > > > +#define HASH_DEFAULT 0x00000000 > > > +#define HASH_MD4 0x00000001 > > > +#define HASH_MD5 0x00000002 > > > +#define HASH_SHA1 0x00000003 > > > +#define HASH_SHA256 0x00000004 > > > +#define HASH_SHA384 0x00000005 > > > +#define HASH_SHA512 0x00000006 > > > +#define HASH_SM3_256 0x00000007 > > > + > > > + > > > +/** > > > + Init hash sequence. > > > + > > > + @param HashHandle Hash handle. > > > + > > > + @retval TRUE Hash start and HashHandle returned. > > > + @retval FALSE Hash Init unsuccessful. > > > +**/ > > > +BOOLEAN > > > +EFIAPI > > > +HashApiInit ( > > > + OUT HASH_HANDLE *HashHandle > > > +); > > > + > > > +/** > > > + Update hash data. > > > + > > > + @param HashHandle Hash handle. > > > + @param DataToHash Data to be hashed. > > > + @param DataToHashLen Data size. > > > + > > > + @retval TRUE Hash updated. > > > + @retval FALSE Hash updated unsuccessful. > > > +**/ > > > +BOOLEAN > > > +EFIAPI > > > +HashApiUpdate ( > > > + IN HASH_HANDLE HashHandle, > > > + IN VOID *DataToHash, > > > + IN UINTN DataToHashLen > > > +); > > > + > > > +/** > > > + Hash complete. > > > + > > > + @param HashHandle Hash handle. > > > + @param Digest Hash Digest. > > > + > > > + @retval TRUE Hash complete and Digest is returned. > > > + @retval FALSE Hash complete unsuccessful. > > > +**/ > > > +BOOLEAN > > > +EFIAPI > > > +HashApiFinal ( > > > + IN HASH_HANDLE HashHandle, > > > + OUT UINT8 *Digest > > > +); > > > + > > > +#endif > > > \ No newline at end of file > > > diff --git a/SecurityPkg/Library/BaseHashLib/BaseHashLibCommon.h > > > b/SecurityPkg/Library/BaseHashLib/BaseHashLibCommon.h > > > new file mode 100644 > > > index 000000000000..776b74ad753b > > > --- /dev/null > > > +++ b/SecurityPkg/Library/BaseHashLib/BaseHashLibCommon.h > > > @@ -0,0 +1,71 @@ > > > +/** @file > > > + The internal header file includes the common header files,=20 > > > +defines > > > + internal structure and functions used by ImageVerificationLib. > > > + > > > +Copyright (c) 2009 - 2020, Intel Corporation. All rights=20 > > > +reserved.
This program and the accompanying materials are=20 > > > +licensed and made available under the terms and conditions of the= =20 > > > +BSD > > > License > > > +which accompanies this distribution. The full text of the=20 > > > +license may be found > > > at > > > +http://opensource.org/licenses/bsd-license.php > > > + > > > +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > > +BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER=20 > > > +EXPRESS > > > OR IMPLIED. > > > + > > > +**/ > > > + > > > +#ifndef __BASEHASHLIB_COMMON_H_ > > > +#define __BASEHASHLIB_COMMON_H_ > > > + > > > +/** > > > + Init hash sequence with Hash Algorithm specified by HashPolicy. > > > + > > > + @param HashHandle Hash handle. > > > + > > > + @retval EFI_SUCCESS Hash start and HashHandle returned. > > > + @retval EFI_UNSUPPORTED System has no HASH library registere= d. > > > +**/ > > > +BOOLEAN > > > +EFIAPI > > > +HashInitInternal ( > > > + IN UINT8 HashPolicy, > > > + OUT HASH_HANDLE *HashHandle > > > + ); > > > + > > > +/** > > > + Hash complete with Hash Algorithm specified by HashPolicy. > > > + > > > + @param HashPolicy Hash Algorithm Policy. > > > + @param HashHandle Hash handle. > > > + @param Digest Hash Digest. > > > + > > > + @retval TRUE Hash complete and Digest is returned. > > > + @retval FALSE Hash complete unsuccessful. > > > +**/ > > > +BOOLEAN > > > +EFIAPI > > > +HashUpdateInternal ( > > > + IN UINT8 HashPolicy, > > > + IN HASH_HANDLE HashHandle, > > > + IN VOID *DataToHash, > > > + IN UINTN DataToHashLen > > > + ); > > > + > > > +/** > > > + Update hash data with Hash Algorithm specified by HashPolicy. > > > + > > > + @param HashPolicy Hash Algorithm Policy. > > > + @param HashHandle Hash handle. > > > + @param DataToHash Data to be hashed. > > > + @param DataToHashLen Data size. > > > + > > > + @retval TRUE Hash updated. > > > + @retval FALSE Hash updated unsuccessful. > > > +**/ > > > +BOOLEAN > > > +EFIAPI > > > +HashFinalInternal ( > > > + IN UINT8 HashPolicy, > > > + IN HASH_HANDLE HashHandle, > > > + OUT UINT8 **Digest > > > + ); > > > +#endif > > > \ No newline at end of file > > > diff --git a/SecurityPkg/Library/BaseHashLib/BaseHashLibDxe.inf > > > b/SecurityPkg/Library/BaseHashLib/BaseHashLibDxe.inf > > > new file mode 100644 > > > index 000000000000..f97bda06108f > > > --- /dev/null > > > +++ b/SecurityPkg/Library/BaseHashLib/BaseHashLibDxe.inf > > > @@ -0,0 +1,47 @@ > > > +## @file > > > > > > +# Provides hash service by registered hash handler > > > > > > +# > > > > > > +# This library is Base Hash Lib. It will redirect hash request=20 > > > +to each individual > > > > > > +# hash handler registered, such as SHA1, SHA256, SHA384, SM3. > > > > > > +# > > > > > > +# Copyright (c) 2018 - 2020, Intel Corporation. All rights=20 > > > +reserved.
> > > > > > +# SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > +# > > > > > > +## > > > > > > + > > > > > > +[Defines] > > > > > > + INF_VERSION =3D 0x00010005 > > > > > > + BASE_NAME =3D BaseHashLibDxe > > > > > > + MODULE_UNI_FILE =3D BaseHashLibDxe.uni > > > > > > + FILE_GUID =3D 158DC712-F15A-44dc-93BB-167504= 5BE066 > > > > > > + MODULE_TYPE =3D DXE_DRIVER > > > > > > + VERSION_STRING =3D 1.0 > > > > > > + LIBRARY_CLASS =3D BaseHashLib|DXE_DRIVER DXE_RUN= TIME_DRIVER > > > DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER > > > > > > + CONSTRUCTOR =3D BaseHashLibApiDxeConstructor > > > > 8. Since the above function is actually empty, you can remove above li= ne and > > function in c file. > > > > > > > > + > > > > > > +# > > > > > > +# The following information is for reference only and not=20 > > > +required by the build > > > tools. > > > > > > +# > > > > > > +# VALID_ARCHITECTURES =3D IA32 X64 > > > > > > +# > > > > > > + > > > > > > +[Sources] > > > > > > + BaseHashLibCommon.h > > > > > > + BaseHashLibCommon.c > > > > > > + BaseHashLibDxe.c > > > > > > + > > > > > > +[Packages] > > > > > > + MdePkg/MdePkg.dec > > > > > > + CryptoPkg/CryptoPkg.dec > > > > > > + SecurityPkg/SecurityPkg.dec > > > > > > + > > > > > > +[LibraryClasses] > > > > > > + BaseLib > > > > > > + BaseMemoryLib > > > > > > + DebugLib > > > > > > + MemoryAllocationLib > > > > > > + BaseCryptLib > > > > > > + PcdLib > > > > > > + > > > > > > +[Pcd] > > > > > > + gEfiSecurityPkgTokenSpaceGuid.PcdSystemHashPolicy ## CONSUMES > > > > > > diff --git a/SecurityPkg/Library/BaseHashLib/BaseHashLibDxe.uni > > > b/SecurityPkg/Library/BaseHashLib/BaseHashLibDxe.uni > > > new file mode 100644 > > > index 000000000000..1865773b4a25 > > > --- /dev/null > > > +++ b/SecurityPkg/Library/BaseHashLib/BaseHashLibDxe.uni > > > @@ -0,0 +1,18 @@ > > > +// /** @file > > > > > > +// Provides hash service by registered hash handler > > > > > > +// > > > > > > +// This library is Unified Hash API. It will redirect hash=20 > > > +request to each individual > > > > > > +// hash handler registered, such as SHA1, SHA256. Platform can=20 > > > +use > > > PcdTpm2HashMask to > > > > > > +// mask some hash engines. > > > > > > +// > > > > > > +// Copyright (c) 2018 - 2020, Intel Corporation. All rights=20 > > > +reserved.
> > > > > > +// > > > > > > +// SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > +// > > > > > > +// **/ > > > > > > + > > > > > > + > > > > > > +#string STR_MODULE_ABSTRACT #language en-US "Provides h= ash > > > service by specified hash handler" > > > > > > + > > > > > > +#string STR_MODULE_DESCRIPTION #language en-US "This libra= ry is > > > Unified Hash API. It will redirect hash request to the hash=20 > > > handler specified by PcdSystemHashPolicy." > > > > > > + > > > > > > diff --git a/SecurityPkg/Library/BaseHashLib/BaseHashLibPei.inf > > > b/SecurityPkg/Library/BaseHashLib/BaseHashLibPei.inf > > > new file mode 100644 > > > index 000000000000..4d36030744bd > > > --- /dev/null > > > +++ b/SecurityPkg/Library/BaseHashLib/BaseHashLibPei.inf > > > @@ -0,0 +1,52 @@ > > > +## @file > > > > > > +# Provides hash service by registered hash handler > > > > > > +# > > > > > > +# This library is BaseCrypto router. It will redirect hash=20 > > > +request to each > > > individual > > > > > > +# hash handler registered, such as SHA1, SHA256. > > > > > > +# > > > > > > +# Copyright (c) 2018 - 2020, Intel Corporation. All rights=20 > > > +reserved.
> > > > > > +# SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > +# > > > > > > +## > > > > > > + > > > > > > +[Defines] > > > > > > + INF_VERSION =3D 0x00010005 > > > > > > + BASE_NAME =3D BaseHashLibPei > > > > > > + MODULE_UNI_FILE =3D BaseHashLibPei.uni > > > > > > + FILE_GUID =3D DDCBCFBA-8EEB-488a-96D6-097831= A6E50B > > > > > > + MODULE_TYPE =3D PEIM > > > > > > + VERSION_STRING =3D 1.0 > > > > > > + LIBRARY_CLASS =3D BaseHashLib|PEIM > > > > > > + CONSTRUCTOR =3D BaseHashLibApiPeiConstructor > > > > > > > 9. The same as 8 > > > > > + > > > > > > +# > > > > > > +# The following information is for reference only and not=20 > > > +required by the build > > > tools. > > > > > > +# > > > > > > +# VALID_ARCHITECTURES =3D IA32 X64 > > > > > > +# > > > > > > + > > > > > > +[Sources] > > > > > > + BaseHashLibCommon.h > > > > > > + BaseHashLibCommon.c > > > > > > + BaseHashLibPei.c > > > > > > + > > > > > > +[Packages] > > > > > > + MdePkg/MdePkg.dec > > > > > > + SecurityPkg/SecurityPkg.dec > > > > > > + CryptoPkg/CryptoPkg.dec > > > > > > + MdeModulePkg/MdeModulePkg.dec > > > > > > + > > > > > > +[LibraryClasses] > > > > > > + BaseLib > > > > > > + BaseMemoryLib > > > > > > + DebugLib > > > > > > + MemoryAllocationLib > > > > > > + BaseCryptLib > > > > > > + PcdLib > > > > > > + > > > > > > +[Guids] > > > > > > + ## SOMETIMES_CONSUMES ## GUID > > > > > > + gZeroGuid > > > > > > + > > > > > > +[Pcd] > > > > > > + gEfiSecurityPkgTokenSpaceGuid.PcdSystemHashPolicy ## CONSUMES > > > > > > diff --git a/SecurityPkg/Library/BaseHashLib/BaseHashLibPei.uni > > > b/SecurityPkg/Library/BaseHashLib/BaseHashLibPei.uni > > > new file mode 100644 > > > index 000000000000..2131b61bd235 > > > --- /dev/null > > > +++ b/SecurityPkg/Library/BaseHashLib/BaseHashLibPei.uni > > > @@ -0,0 +1,17 @@ > > > +// /** @file > > > > > > +// Provides hash service by registered hash handler > > > > > > +// > > > > > > +// This library is Unified Hash API. It will redirect hash=20 > > > +request to each individual > > > > > > +// hash handler registered, such as SHA1, SHA256. > > > > > > +// > > > > > > +// Copyright (c) 2018 - 2020, Intel Corporation. All rights=20 > > > +reserved.
> > > > > > +// > > > > > > +// SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > +// > > > > > > +// **/ > > > > > > + > > > > > > + > > > > > > +#string STR_MODULE_ABSTRACT #language en-US "Provides h= ash > > > service by specified hash handler" > > > > > > + > > > > > > +#string STR_MODULE_DESCRIPTION #language en-US "This libra= ry is > > > Unified Hash API. It will redirect hash request to the hash=20 > > > handler specified by PcdSystemHashPolicy." > > > > > > + > > > > > > diff --git a/SecurityPkg/SecurityPkg.dec=20 > > > b/SecurityPkg/SecurityPkg.dec index cac36caf0a0d..e0e144124ddd > > > 100644 > > > --- a/SecurityPkg/SecurityPkg.dec > > > +++ b/SecurityPkg/SecurityPkg.dec > > > @@ -5,7 +5,7 @@ > > > # It also provides the definitions(including=20 > > > PPIs/PROTOCOLs/GUIDs and library > > > classes) > > > > > > # and libraries instances, which are used for those features. > > > > > > # > > > > > > -# Copyright (c) 2009 - 2019, Intel Corporation. All rights=20 > > > reserved.
> > > > > > +# Copyright (c) 2009 - 2020, Intel Corporation. All rights=20 > > > +reserved.
> > > > > > # (C) Copyright 2015 Hewlett Packard Enterprise Development LP=20 > > >
> > > > > > # Copyright (c) 2017, Microsoft Corporation. All rights reserved. > > >
> > > > > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > @@ -27,6 +27,10 @@ [LibraryClasses] > > > # > > > > > > HashLib|Include/Library/HashLib.h > > > > > > > > > > > > + ## @libraryclass Provides hash interfaces from different implem= entations. > > > > > > + # > > > > > > + BaseHashLib|Include/Library/HashLib.h > > > > > > + > > > > > > ## @libraryclass Provides a platform specific interface to=20 > > > detect physically present user. > > > > > > # > > > > > > PlatformSecureLib|Include/Library/PlatformSecureLib.h > > > > > > @@ -496,5 +500,22 @@ [PcdsDynamic, PcdsDynamicEx] > > > # @Prompt Tpm2AcpiTableLasa LASA field in TPM2 ACPI table. > > > > > > > > > gEfiSecurityPkgTokenSpaceGuid.PcdTpm2AcpiTableLasa|0|UINT64|0x0001 > > > 00 > > > 23 > > > > > > > > > > > > +[PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic,=20 > > > +PcdsDynamicEx] > > > > > > + ## This PCD indicates the HASH algorithm to verify unsigned=20 > > > + PE/COFF image > > > > > > + # Based on the value set, the required algorithm is chosen to=20 > > > + verify > > > > > > + # the unsigned image during Secure Boot.
> > > > > > + # The hashing algorithm selected must match the hashing=20 > > > + algorithm used to > > > > > > + # hash the image to be added to DB using tools such as=20 > > > + KeyEnroll.
> > > > > > + # 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 > > > > > > + > > > gEfiSecurityPkgTokenSpaceGuid.PcdSystemHashPolicy|0x04|UINT8|0x000 > > > 10 > > > 02 > > > 4 > > > > > > + > > > > > > [UserExtensions.TianoCore."ExtraFiles"] > > > > > > SecurityPkgExtra.uni > > > > > > diff --git a/SecurityPkg/SecurityPkg.dsc=20 > > > b/SecurityPkg/SecurityPkg.dsc index a2eeadda7a7e..86a5847e2509 > > > 100644 > > > --- a/SecurityPkg/SecurityPkg.dsc > > > +++ b/SecurityPkg/SecurityPkg.dsc > > > @@ -1,7 +1,7 @@ > > > ## @file > > > > > > # Security Module Package for All Architectures. > > > > > > # > > > > > > -# Copyright (c) 2009 - 2019, Intel Corporation. All rights=20 > > > reserved.
> > > > > > +# Copyright (c) 2009 - 2020, Intel Corporation. All rights=20 > > > +reserved.
> > > > > > # (C) Copyright 2015 Hewlett Packard Enterprise Development=20 > > > LP
> > > > > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > # > > > > > > @@ -95,6 +95,7 @@ [LibraryClasses.common.PEIM] > > > > > > Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTp= m. > > > inf > > > > > > > > > Tcg2PhysicalPresenceLib|SecurityPkg/Library/PeiTcg2PhysicalPresenc > > > Tcg2PhysicalPresenceLib|eL > > > Tcg2PhysicalPresenceLib|ib > > > Tcg2PhysicalPresenceLib|/PeiTc > > > g2PhysicalPresenceLib.inf > > > > > > RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf > > > > > > + BaseHashLib|SecurityPkg/Library/BaseHashLib/BaseHashLibPei.inf > > > > > > > > > > > > [LibraryClasses.common.DXE_DRIVER] > > > > > > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > > > > > > @@ -110,6 +111,7 @@ [LibraryClasses.common.DXE_DRIVER] > > > > > > Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibTcg/Tpm12DeviceLi > > > Tpm12DeviceLib|bT > > > Tpm12DeviceLib|cg > > > Tpm12DeviceLib|.i > > > nf > > > > > > > > > Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg= 2. > > > Tpm2DeviceLib|in > > > f > > > > > > > > > FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerL > > > FileExplorerLib|ib > > > FileExplorerLib|.i > > > nf > > > > > > + BaseHashLib|SecurityPkg/Library/BaseHashLib/BaseHashLibDxe.inf > > > > > > > > > > > > [LibraryClasses.common.UEFI_DRIVER, > > > LibraryClasses.common.DXE_RUNTIME_DRIVER, > > > LibraryClasses.common.DXE_SAL_DRIVER,] > > > > > > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > > > > > > @@ -211,6 +213,12 @@ [Components] > > > > > > > > > SecurityPkg/Library/HashLibTpm2/HashLibTpm2.inf > > > > > > > > > > > > + # > > > > > > + # Unified Hash API > > > > > > + # > > > > > > + SecurityPkg/Library/BaseHashLib/BaseHashLibDxe.inf > > > > > > + SecurityPkg/Library/BaseHashLib/BaseHashLibPei.inf > > > > > > + > > > > > > # > > > > > > # TCG Storage. > > > > > > # > > > > > > diff --git a/SecurityPkg/SecurityPkg.uni=20 > > > b/SecurityPkg/SecurityPkg.uni index 68587304d779..32ef97f81461 > > > 100644 > > > --- a/SecurityPkg/SecurityPkg.uni > > > +++ b/SecurityPkg/SecurityPkg.uni > > > @@ -5,7 +5,7 @@ > > > // It also provides the definitions(including=20 > > > PPIs/PROTOCOLs/GUIDs and library > > > classes) > > > > > > // and libraries instances, which are used for those features. > > > > > > // > > > > > > -// Copyright (c) 2009 - 2018, Intel Corporation. All rights=20 > > > reserved.
> > > > > > +// Copyright (c) 2009 - 2020, Intel Corporation. All rights=20 > > > +reserved.
> > > > > > // > > > > > > // SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > // > > > > > > @@ -295,3 +295,16 @@ > > > > > > > > > #string > > > STR_gEfiSecurityPkgTokenSpaceGuid_PcdTpm2AcpiTableLasa_HELP > > > #language en-US "This PCD defines LASA of TPM2 ACPI table\n\n" > > > > > > > > > "0 means this field is unsupported\n" > > > > > > + > > > > > > > > > + > > > #string > > > STR_gEfiSecurityPkgTokenSpaceGuid_PcdSystemHashPolicy_PROMPT > > > #language en-US "HASH algorithm to verify unsigned PE/COFF image" > > > > > > + > > > > > > +#string > > > +STR_gEfiSecurityPkgTokenSpaceGuid_PcdSystemHashPolicy_HELP > > > #language en-US "This PCD indicates the HASH algorithm used by=20 > > > Unified Hash API.

\n" > > > > > > + > > > + "Based on the value set, the > > > required algorithm is chosen to calculate\n" > > > > > > + = "the hash desired.
\n" > > > > > > + = "0x00000001 - MD4.
\n" > > > > > > + = "0x00000002 - MD5.
\n" > > > > > > + = "0x00000003 - SHA1.
\n" > > > > > > + > > > + "0x00000004 - > > > SHA256.
\n" > > > > > > + > > > + "0x00000005 - > > > SHA384.
\n" > > > > > > + > > > + "0x00000006 - > > > SHA512.
\n" > > > > > > + = "0x00000007 - SM3.
" > > > > > > -- > > > 2.16.2.windows.1 > > > > > > > > > > >=20 >=20 >=20 >=20