From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web10.5088.1647568879867958455 for ; Thu, 17 Mar 2022 19:01:20 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=IEgvBWqM; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: zhihao.li@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647568880; x=1679104880; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=aWfktqBCm71GOzV088G5g3K/WGrXOFil2cEn1qbJlYs=; b=IEgvBWqMSXzg9GGH7SGmA3MqsYuk/6IrKKwlJImnSO5bkRcErXsW6qDf 1YV2s2uWDZJ06Z4ss8c+kCSYNegQIojg0/22pM9t9gzaCkDUVslJB+Muh kQaxFAqIZR/uTb9Syz6gVpdwIZ8yRS4w/fZGXutIWXyNnDLmCAbFDSuyR DVqgE/Fmqu7DH9TUvdnj1iR7zFYX0xlRXc74KFIJSOlJfef5BpCpIVyhY G8PXY4y5m6tZEl8P/wFdHL08+85XlJKHVzNGMt21WRdQjAyhsxDCojoB+ /Z0lM4VndH0to8LuwErbuBE420deqPUFtSzfVGQ4ppptwlLXTXCi/0FEZ A==; X-IronPort-AV: E=McAfee;i="6200,9189,10289"; a="244481617" X-IronPort-AV: E=Sophos;i="5.90,190,1643702400"; d="scan'208";a="244481617" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2022 19:01:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,190,1643702400"; d="scan'208";a="517002888" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga006.jf.intel.com with ESMTP; 17 Mar 2022 19:01:16 -0700 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 17 Mar 2022 19:01:13 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Frontend Transport; Thu, 17 Mar 2022 19:01:13 -0700 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.171) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.21; Thu, 17 Mar 2022 19:01:10 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RDY6c/1LUaG8zz7TMT5AgjC8VSqGW4r+PkPokWlwNy+EdGMPpdACGkb/BVQmw5D9LLDhwngodzVatqRNI0Oc7YYnWxl1/jcjA9IIi+BZQ04MWckixV7Bqq97hNTvPGFJdfOkOV6icVTizSX3OESF0GBg3TtzbULeTpZPaBqwnWUgevtI/oN2OL0XFwEkM8xCqLLlnPf8pHNPaPH8+54l/LcjCEy0bYRqQJuBRlUrAIgXsnZ1pmRSagV2EFCowfgRyDy3kUI25wV1bhWO/9gl9Z7sPURtLL8OVordyQT5cKoWAL0TpXnRqcRh29tXPzKjBTnrRecOOR3Yd+OfqafxXA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mVsPDL0BCHP9r4EWdgqhLUyLyg+s82hEIDSRmZs2Juo=; b=BShzjiieOa5h+kXw9tTpfzw2vczRgoM2+3gr+rw5nJIYNZrrhbb43dUeNzlfMfDv+5lkJKTKp1cbBISl/GqyaMPvj8vq3K3ujdw0gOOSnqq3h8df0LlU1EI/YNA0WGT9RpSB6lfNvRAlKdMQYicTPkP33LtAlIwU6agsMZMC5sy5QBkzaK5G05bHVhk5K+7sWU9KNF0z5YZdQQEDcg06LvAnWQUW9tpUfh6ffvnO72bn3EdSv+VhmYnsoINnXjxbOInnWqxHbbB99h553nbEWzaVtbqmJms/O0SXIS/xg/EUt+qjatLgZiYToODk1UkEr9eUcX/ZoYaKgMsFZ3MCOw== 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 Received: from DM6PR11MB4738.namprd11.prod.outlook.com (2603:10b6:5:2a3::18) by BY5PR11MB3895.namprd11.prod.outlook.com (2603:10b6:a03:18e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.14; Fri, 18 Mar 2022 02:01:00 +0000 Received: from DM6PR11MB4738.namprd11.prod.outlook.com ([fe80::74f3:4efa:c586:a951]) by DM6PR11MB4738.namprd11.prod.outlook.com ([fe80::74f3:4efa:c586:a951%7]) with mapi id 15.20.5081.018; Fri, 18 Mar 2022 02:00:59 +0000 From: "Li, Zhihao" To: "Yao, Jiewen" , "devel@edk2.groups.io" CC: "Wang, Jian J" , "Lu, Xiaoyu1" , "Jiang, Guomin" , "Fu, Siyuan" Subject: Re: [PATCH v6 1/1] CryptoPkg: Add new hash algorithm ParallelHash256HashAll in BaseCryptLib. Thread-Topic: [PATCH v6 1/1] CryptoPkg: Add new hash algorithm ParallelHash256HashAll in BaseCryptLib. Thread-Index: AQHYObhWpGZOzIXh0ECh0X9gIAaugqzDE/0wgACqfmCAAJPR0IAACryQgAAGnYCAAACx0A== Date: Fri, 18 Mar 2022 02:00:59 +0000 Message-ID: References: <20220317043430.1002-1-zhihao.li@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6a940d58-a03d-4126-30d5-08da088325db x-ms-traffictypediagnostic: BY5PR11MB3895:EE_ x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: HyJUbFbxP8UA9P93lJBt4xIWNwZXG9dYZ+x+bY9Vqp52CehqqmcIxA/KllGDB6rgpqOqa5eSZouEy186IVKHHhMjhPxY7WG4fCvy2UIDg6haOQ9JWH9SEg8X4Qr09V18nqLxJS9z1W5w1yxSvJD1hjpFkTD4SOTAnB1NFjJHLG8pEnqrsyF1fIxGlhIhr5pT4QzzVR77D6pQHA2mqQzJG3tUvhyyCOaqkLP/4cTLIGCWc5NjlS6MAjG8Tqd5vl3fBwzwbiN+wyifFwdCOASiklyP8ufVGs6NxFu564Cd+sH9y6+mWaiwIVB5BPUFB1dU/QLFri+wlc9Er3XRqcpxNNLy5BAYZLlvPrHczkdJGubucQDT8c9/6x1xgJPHBNl4jCP2V4amdifpypWxBdeh6GBHijcp09ZH+u49Zk/QtX0muauv1TrlK66GONbSZsy3ieIQHH1QZyNA8lvZaELUY1GfHbrU9fhB27/BFRiPLa59UXyUTX4jbWlDTgjzxVFf4+fx9f8YL0fFSz/kZ0E1fDWARHIxIlTcABtLtzo7JwlhD7lUo9OH7x2ZrjgAoFkFTaigonoYgh+z6Sfk4PI3kWto3N0v7eBLpPnuU9KQEafi6Rp4y886FJhTBYlGmX2hDk8xpuM31VPwJnWubvrCutE3wr50ZeUVR9L+tcERIHjWs2YFDMLTMIgldQv5NXVDwiNpXZ4gynDHgb/wRO18NnlGGIlB1Yivl2/uIeC/JedS920EVT6mxCdVD23IxSG2z5RyRYEWt1BAXoghpyAy/umpsN6y/XHYPSL2l2uNxh6ze5fQuApCWjz7uUzQ16j+NgH5ja/xFc5pYpyCdGsvDQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR11MB4738.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(52536014)(110136005)(38070700005)(86362001)(54906003)(82960400001)(122000001)(19627235002)(316002)(107886003)(83380400001)(186003)(26005)(66446008)(55016003)(66476007)(8936002)(66556008)(76116006)(64756008)(66946007)(8676002)(4326008)(508600001)(33656002)(966005)(53546011)(9686003)(6506007)(7696005)(71200400001)(30864003)(5660300002)(38100700002)(2906002)(45080400002)(559001)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?lCqWCj8KH4/j1p3tATnuu0D0hLCYI2oOit5k3j04raN1hq2s98SrW0Id9kaU?= =?us-ascii?Q?B9J/J0g7jkAjWeaKgedHTuB4U0njkaUssGuXhAIkuMjv5q44U2QuCeJpzkmc?= =?us-ascii?Q?x3pZl3N+SeaLCX59AOLGkp9SoPUsE2EPAZUUg5Kk9okAokF6cU5LysWG0ecO?= =?us-ascii?Q?uy3rH17OjgsEPwGRn5kAq+Ekdk0p57kjE1hwxQin0pzd6q0REZ7dAYafKFeN?= =?us-ascii?Q?tHsqVEp7r4CvgcDR0Hc+eyA7mraCKAAOhNMQCUqxD6wj1S/6930JUksuvNd6?= =?us-ascii?Q?u9uxjwcY6pqohmv4u81M75RaEpkDtY6MlqG9lYuyuj/gXYI/h3CZY7XflXJy?= =?us-ascii?Q?75JgDxH7f8jDT7rbarJ0LyVOshjqqFH37cbHRT++w/zCPcNTQoxjL9ZTnvFN?= =?us-ascii?Q?Oja4EG4+O0mY1Szpt9S+2mezhDq/mTTt9wwKAJMDS7ZcoVGMSAU/sFYwVy00?= =?us-ascii?Q?B7l7PEix9XERrE7NwKgCnZf/1MCljUoXweYEf5JixNcBgRvvI9GzNr7iIFzr?= =?us-ascii?Q?GRK7NIm7NdkfK1/XttVHN0I+i+iNMnvw/CKnw1MXYdLarbvBeLkrAzTvhzHb?= =?us-ascii?Q?tAZgT9kkBxJbuHkFSW6QYEirP6p9gZk+SQk8XR7Etesgku0Ozy9wBz8Mf8wg?= =?us-ascii?Q?TAahj9qfaufpqbfeBvU3xVYoiznJAnnSP3aepZzJjNJec+qpDuTAShHsZ/+Y?= =?us-ascii?Q?+3zotO6BPCTTN5aKIy6toiPFKp2XbN0ZB8W+35HOHUYYIUOhNfopLLnn6uD4?= =?us-ascii?Q?tmkujiVBPlF0jUsEJ3H0Wd/x/eBPBbmCjX5/io7gwo0kfuBskAe6dT2jMmeY?= =?us-ascii?Q?cG2tmOKy3MN/HNXKXKtmxvcsoz42VMpD03DCJODeekuO6h8ftqKqcOkRYflb?= =?us-ascii?Q?ebhvA/4EM2QTlSc3Cn79J4KWhZGqH6ei9XzX0ZbBlAkjUU6U8m4FryhbQuom?= =?us-ascii?Q?M0IPvCpqNyxO0aZlrS20xsPvrzN9XRh46/qkvNbDypaf/rRsAFsoU4vsxkuG?= =?us-ascii?Q?WvFYDHT3/H/3W7i17eRtvbMC3X7VG9TL1o1G2r0W3pXyCFviornmKdA1VmtW?= =?us-ascii?Q?ft4ZoOWYlJKzumiLPlyuv+QmbQpN6t1OixsyVnLy950AD8pe4JjUnmntKa7A?= =?us-ascii?Q?dRPdm8BWbMKCIELyxhYUjw2yWpEF5V6UlFl3had5U0P1ErQ/6GTY8i6F6cgI?= =?us-ascii?Q?+FspbAS+9pG4BwC1beHUcm2Hbniv/JnAsYKfChbi6oGr3llBfJgVdwe4Xwb1?= =?us-ascii?Q?QtOatZMxv9AZKEYzJLPocBeSNlUj2CngxGabnFJqbWSsRAkM6FvWO5qLtBCB?= =?us-ascii?Q?pzjkwLKkh+x4wl1h2Yy4Ct6swEen2l4B+DZQN3UYAdqGt5mFNnxug4jlIjsQ?= =?us-ascii?Q?UhlBrJrMdAEsBAzsyGtGgBwinWY+6NppiMuRmrD3MuzVU8MRUhXzSW8KZ2ir?= =?us-ascii?Q?hsuI4a2ldqrWDm+fTls4iXA5tD/CvK5b?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4738.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6a940d58-a03d-4126-30d5-08da088325db X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Mar 2022 02:00:59.3487 (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: o/+RrwwqHFMm4qEPOWvRTxZaKdppbYz8Z7vkOAz/Fxo1sPfWbQwsGdjGnz0YkY8vaxFMBwhxGWNAvI3CRQeCbg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR11MB3895 Return-Path: zhihao.li@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable OK > -----Original Message----- > From: Yao, Jiewen > Sent: Friday, March 18, 2022 9:59 AM > To: Li, Zhihao ; devel@edk2.groups.io > Cc: Wang, Jian J ; Lu, Xiaoyu1 ; > Jiang, Guomin ; Fu, Siyuan ; > Yao, Jiewen > Subject: RE: [PATCH v6 1/1] CryptoPkg: Add new hash algorithm > ParallelHash256HashAll in BaseCryptLib. >=20 > Yes. It seems we missed RsaPssSign and RsaPssVerify in previous patch. Si= gh... >=20 > Would you please help to add them? >=20 >=20 >=20 > > -----Original Message----- > > From: Li, Zhihao > > Sent: Friday, March 18, 2022 9:53 AM > > To: Yao, Jiewen ; devel@edk2.groups.io > > Cc: Wang, Jian J ; Lu, Xiaoyu1 > ; > > Jiang, Guomin ; Fu, Siyuan > > Subject: RE: [PATCH v6 1/1] CryptoPkg: Add new hash algorithm > > ParallelHash256HashAll in BaseCryptLib. > > > > Build CryptoPei and CryptoSmm driver report this error. > > > > INFO - /home/vsts/work/1/s/CryptoPkg/Driver/Crypto.c:4707:3: error: > > initialization of 'BOOLEAN (__attribute__((ms_abi)) *)(void *, const UI= NT8 *, > > UINTN, UINT16, UINT16, UINT8 *, UINTN *)' from incompatible pointer = type > > 'BOOLEAN (__attribute__((ms_abi)) *)(const void *, UINTN, UINTN, void= *, > > UINTN, const void *, UINTN)' [-Werror=3Dincompatible-pointer-types] > > INFO - 4707 | CryptoServiceParallelHash256HashAll > > > > In Crypto.c: > > const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto =3D { > > ... > > CryptoServiceTlsGetHostPrivateKey, > > CryptoServiceTlsGetCertRevocationList, > > /// Parallel hash > > CryptoServiceParallelHash256HashAll > > }; > > In Crypto.h > > struct _EDKII_CRYPTO_PROTOCOL { > > ... > > EDKII_CRYPTO_TLS_GET_CERT_REVOCATION_LIST > > TlsGetCertRevocationList; > > /// RSA PSS > > EDKII_CRYPTO_RSA_PSS_SIGN RsaPssSign; > > EDKII_CRYPTO_RSA_PSS_VERIFY RsaPssVerify; > > /// Parallel hash > > EDKII_CRYPTO_PARALLEL_HASH_ALL ParallelHash256Has= hAll; > > }; > > And > > typedef > > BOOLEAN > > (EFIAPI *EDKII_CRYPTO_RSA_PSS_SIGN)( > > IN VOID *RsaContext, > > IN CONST UINT8 *Message, > > IN UINTN MsgSize, > > IN UINT16 DigestLen, > > IN UINT16 SaltLen, > > OUT UINT8 *Signature, > > IN OUT UINTN *SigSize > > ); > > > > So I think solve this error need to put ParallelHash256HashAll before > RsaPssSign. > > And test result is successful. > > Is there anything wrong with my judgment? > > > > > > > -----Original Message----- > > > From: Yao, Jiewen > > > Sent: Friday, March 18, 2022 8:56 AM > > > To: Li, Zhihao ; devel@edk2.groups.io > > > Cc: Wang, Jian J ; Lu, Xiaoyu1 > > ; > > > Jiang, Guomin ; Fu, Siyuan > > > Subject: RE: [PATCH v6 1/1] CryptoPkg: Add new hash algorithm > > > ParallelHash256HashAll in BaseCryptLib. > > > > > > What is root cause of failure? > > > > > > I don't understand. > > > > > > > -----Original Message----- > > > > From: Li, Zhihao > > > > Sent: Friday, March 18, 2022 12:27 AM > > > > To: Yao, Jiewen ; devel@edk2.groups.io > > > > Cc: Wang, Jian J ; Lu, Xiaoyu1 > > > ; > > > > Jiang, Guomin ; Fu, Siyuan > > > > > Subject: RE: [PATCH v6 1/1] CryptoPkg: Add new hash algorithm > > > > ParallelHash256HashAll in BaseCryptLib. > > > > > > > > Because it will cause patch to fail in CI test while to succeed if = follow the > > > setting. > > > > Failed test: https://github.com/tianocore/edk2/pull/2535 > > > > > > > > I guess it's because data structure > EDKII_CRYPTO_PROTOCOL( mEdkiiCrypto) > > > > doesn't have /// RSA PSS members in Crypto.c > > > > > > > > > -----Original Message----- > > > > > From: Yao, Jiewen > > > > > Sent: Thursday, March 17, 2022 10:13 PM > > > > > To: Li, Zhihao ; devel@edk2.groups.io > > > > > Cc: Wang, Jian J ; Lu, Xiaoyu1 > > > > ; > > > > > Jiang, Guomin ; Fu, Siyuan > > > > > > > Subject: RE: [PATCH v6 1/1] CryptoPkg: Add new hash algorithm > > > > > ParallelHash256HashAll in BaseCryptLib. > > > > > > > > > > Hey > > > > > Are you following the guideline - don't put new field in the midd= le ? > > > > > > > > > > ParallelHash256HashAll API is still in the middle...... > > > > > > > > > > > > > > > > @@ -3641,6 +3670,8 @@ struct _EDKII_CRYPTO_PROTOCOL { > > > > > > EDKII_CRYPTO_TLS_GET_HOST_PUBLIC_CERT > > > TlsGetHostPublicCert; > > > > > > > > > > > > EDKII_CRYPTO_TLS_GET_HOST_PRIVATE_KEY > > > TlsGetHostPrivateKey; > > > > > > > > > > > > EDKII_CRYPTO_TLS_GET_CERT_REVOCATION_LIST > > > > > > TlsGetCertRevocationList; > > > > > > > > > > > > + /// Parallel hash > > > > > > > > > > > > + EDKII_CRYPTO_PARALLEL_HASH_ALL > > ParallelHash256HashAll; > > > > > > > > > > > > /// RSA PSS > > > > > > > > > > > > EDKII_CRYPTO_RSA_PSS_SIGN RsaPssSig= n; > > > > > > > > > > > > EDKII_CRYPTO_RSA_PSS_VERIFY RsaPssVer= ify; > > > > > > > > > > > > > > > > > > > > > > -----Original Message----- > > > > > > From: Li, Zhihao > > > > > > Sent: Thursday, March 17, 2022 12:35 PM > > > > > > To: devel@edk2.groups.io > > > > > > Cc: Yao, Jiewen ; Wang, Jian J > > > > > ; > > > > > > Lu, Xiaoyu1 ; Jiang, Guomin > > > > > ; > > > > > > Fu, Siyuan > > > > > > Subject: [PATCH v6 1/1] CryptoPkg: Add new hash algorithm > > > > > > ParallelHash256HashAll in BaseCryptLib. > > > > > > > > > > > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3596 > > > > > > > > > > > > Parallel hash function ParallelHash256HashAll, as defined in NI= ST's > > > > > > Special Publication 800-185, published December 2016. It utiliz= es > > > > > > multi-process to calculate the digest. > > > > > > > > > > > > Passed CI test. > > > > > > Onprotocol version code passed test. > > > > > > > > > > > > Cc: Jiewen Yao > > > > > > Cc: Jian J Wang > > > > > > Cc: Xiaoyu Lu > > > > > > Cc: Guomin Jiang > > > > > > Cc: Siyuan Fu > > > > > > Cc: Zhihao Li > > > > > > > > > > > > Signed-off-by: Zhihao Li > > > > > > --- > > > > > > CryptoPkg/Driver/Crypto.c = | 38 ++- > > > > > > CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c = | > 282 > > > > > > ++++++++++++++++++++ > > > > > > CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c = | > 278 > > > > > > +++++++++++++++++++ > > > > > > CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHashNull.c = | > > 40 > > > > +++ > > > > > > CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c = | 166 > > > > > > ++++++++++++ > > > > > > CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c = | 107 > > > > > ++++++++ > > > > > > CryptoPkg/Library/BaseCryptLibNull/Hash/CryptParallelHashNull.= c > | > > > 40 > > > > > +++ > > > > > > CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c = | 34 > > > ++- > > > > > > CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests= .c | > > > 145 > > > > > > ++++++++++ > > > > > > CryptoPkg/CryptoPkg.ci.yaml = | 4 +- > > > > > > CryptoPkg/Include/Library/BaseCryptLib.h = | 31 ++- > > > > > > CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h = | 8 > +- > > > > > > CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf = | 3 +- > > > > > > CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h = | > 201 > > > > > > ++++++++++++++ > > > > > > CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf = | 3 +- > > > > > > CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf = | 3 +- > > > > > > CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf = | 8 +- > > > > > > CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf = | 3 > +- > > > > > > CryptoPkg/Library/Include/CrtLibSupport.h = | 3 +- > > > > > > CryptoPkg/Private/Protocol/Crypto.h = | 35 ++- > > > > > > CryptoPkg/Test/CryptoPkgHostUnitTest.dsc = | 4 + > > > > > > > CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf > > | > > > > 4 > > > > > + > > > > > > 22 files changed, 1426 insertions(+), 14 deletions(-) > > > > > > > > > > > > diff --git a/CryptoPkg/Driver/Crypto.c b/CryptoPkg/Driver/Crypt= o.c > > > > > > index d5d6aa8e5820..5a9245c07cc5 100644 > > > > > > --- a/CryptoPkg/Driver/Crypto.c > > > > > > +++ b/CryptoPkg/Driver/Crypto.c > > > > > > @@ -3,7 +3,7 @@ > > > > > > from BaseCryptLib and TlsLib. > > > > > > > > > > > > > > > > > > > > > > > > Copyright (C) Microsoft Corporation. All rights reserved. > > > > > > > > > > > > - Copyright (c) 2019 - 2020, Intel Corporation. All rights res= erved.
> > > > > > > > > > > > + Copyright (c) 2019 - 2022, Intel Corporation. All rights res= erved.
> > > > > > > > > > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > > > > > > > > > > > > > **/ > > > > > > > > > > > > @@ -4470,6 +4470,38 @@ CryptoServiceTlsGetCertRevocationList ( > > > > > > return CALL_BASECRYPTLIB (TlsGet.Services.CertRevocationList= , > > > > > > TlsGetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED); > > > > > > > > > > > > } > > > > > > > > > > > > > > > > > > > > > > > > +/** > > > > > > > > > > > > + Parallel hash function ParallelHash256, as defined in NIST's= Special > > > > > Publication > > > > > > 800-185, > > > > > > > > > > > > + published December 2016. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[in] Input Pointer to the input message (= X). > > > > > > > > > > > > + @param[in] InputByteLen The number(>0) of input bytes = provided > > for > > > > the > > > > > > input data. > > > > > > > > > > > > + @param[in] BlockSize The size of each block (B). > > > > > > > > > > > > + @param[out] Output Pointer to the output buffer. > > > > > > > > > > > > + @param[in] OutputByteLen The desired number of output b= ytes > (L). > > > > > > > > > > > > + @param[in] Customization Pointer to the customization s= tring (S). > > > > > > > > > > > > + @param[in] CustomByteLen The length of the customizatio= n > string > > in > > > > > bytes. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval TRUE ParallelHash256 digest computation succeeded. > > > > > > > > > > > > + @retval FALSE ParallelHash256 digest computation failed. > > > > > > > > > > > > + @retval FALSE This interface is not supported. > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > +BOOLEAN > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +CryptoServiceParallelHash256HashAll ( > > > > > > > > > > > > + IN CONST VOID *Input, > > > > > > > > > > > > + IN UINTN InputByteLen, > > > > > > > > > > > > + IN UINTN BlockSize, > > > > > > > > > > > > + OUT VOID *Output, > > > > > > > > > > > > + IN UINTN OutputByteLen, > > > > > > > > > > > > + IN CONST VOID *Customization, > > > > > > > > > > > > + IN UINTN CustomByteLen > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + return CALL_BASECRYPTLIB (ParallelHash.Services.HashAll, > > > > > > ParallelHash256HashAll, (Input, InputByteLen, BlockSize, Output= , > > > > > OutputByteLen, > > > > > > Customization, CustomByteLen), FALSE); > > > > > > > > > > > > +} > > > > > > > > > > > > + > > > > > > > > > > > > const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto =3D { > > > > > > > > > > > > /// Version > > > > > > > > > > > > CryptoServiceGetCryptoVersion, > > > > > > > > > > > > @@ -4670,5 +4702,7 @@ const EDKII_CRYPTO_PROTOCOL > > mEdkiiCrypto > > > =3D > > > > { > > > > > > CryptoServiceTlsGetCaCertificate, > > > > > > > > > > > > CryptoServiceTlsGetHostPublicCert, > > > > > > > > > > > > CryptoServiceTlsGetHostPrivateKey, > > > > > > > > > > > > - CryptoServiceTlsGetCertRevocationList > > > > > > > > > > > > + CryptoServiceTlsGetCertRevocationList, > > > > > > > > > > > > + /// Parallel hash > > > > > > > > > > > > + CryptoServiceParallelHash256HashAll > > > > > > > > > > > > }; > > > > > > > > > > > > diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256= .c > > > > > > b/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c > > > > > > new file mode 100644 > > > > > > index 000000000000..2a9eaf9eec40 > > > > > > --- /dev/null > > > > > > +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c > > > > > > @@ -0,0 +1,282 @@ > > > > > > +/** @file > > > > > > > > > > > > + cSHAKE-256 Digest Wrapper Implementations. > > > > > > > > > > > > + > > > > > > > > > > > > +Copyright (c) 2022, Intel Corporation. All rights reserved. > > > > > > > > > > > > +SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > + > > > > > > > > > > > > +#include "CryptParallelHash.h" > > > > > > > > > > > > + > > > > > > > > > > > > +#define CSHAKE256_SECURITY_STRENGTH 256 > > > > > > > > > > > > +#define CSHAKE256_RATE_IN_BYTES 136 > > > > > > > > > > > > + > > > > > > > > > > > > +CONST CHAR8 mZeroPadding[CSHAKE256_RATE_IN_BYTES] =3D { 0 }; > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + CShake256 initial function. > > > > > > > > > > > > + > > > > > > > > > > > > + Initializes user-supplied memory pointed by CShake256Context= as > > > cSHAKE- > > > > > 256 > > > > > > hash context for > > > > > > > > > > > > + subsequent use. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[out] CShake256Context Pointer to cSHAKE-256 context > being > > > > > > initialized. > > > > > > > > > > > > + @param[in] OutputLen The desired number of output l= ength in > > > bytes. > > > > > > > > > > > > + @param[in] Name Pointer to the function name s= tring. > > > > > > > > > > > > + @param[in] NameLen The length of the function nam= e in bytes. > > > > > > > > > > > > + @param[in] Customization Pointer to the customization s= tring. > > > > > > > > > > > > + @param[in] CustomizationLen The length of the customizatio= n > string > > in > > > > > > bytes. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval TRUE cSHAKE-256 context initialization succeeded. > > > > > > > > > > > > + @retval FALSE cSHAKE-256 context initialization failed. > > > > > > > > > > > > + @retval FALSE This interface is not supported. > > > > > > > > > > > > +**/ > > > > > > > > > > > > +BOOLEAN > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +CShake256Init ( > > > > > > > > > > > > + OUT VOID *CShake256Context, > > > > > > > > > > > > + IN UINTN OutputLen, > > > > > > > > > > > > + IN CONST VOID *Name, > > > > > > > > > > > > + IN UINTN NameLen, > > > > > > > > > > > > + IN CONST VOID *Customization, > > > > > > > > > > > > + IN UINTN CustomizationLen > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + BOOLEAN Status; > > > > > > > > > > > > + UINT8 EncBuf[sizeof (UINTN) + 1]; > > > > > > > > > > > > + UINTN EncLen; > > > > > > > > > > > > + UINTN AbsorbLen; > > > > > > > > > > > > + UINTN PadLen; > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Check input parameters. > > > > > > > > > > > > + // > > > > > > > > > > > > + if ((CShake256Context =3D=3D NULL) || (OutputLen =3D=3D 0) |= | ((NameLen !=3D > 0) > > > > && > > > > > > (Name =3D=3D NULL)) || ((CustomizationLen !=3D 0) && (Customiza= tion =3D=3D > > NULL))) > > > { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Initialize KECCAK context with pad value and block size. > > > > > > > > > > > > + // > > > > > > > > > > > > + if ((NameLen =3D=3D 0) && (CustomizationLen =3D=3D 0)) { > > > > > > > > > > > > + // > > > > > > > > > > > > + // When N and S are both empty strings, cSHAKE(X, L, N, S)= is > > equivalent > > > > to > > > > > > > > > > > > + // SHAKE as defined in FIPS 202. > > > > > > > > > > > > + // > > > > > > > > > > > > + Status =3D (BOOLEAN)KeccakInit ( > > > > > > > > > > > > + (Keccak1600_Ctx *)CShake256Context, > > > > > > > > > > > > + '\x1f', > > > > > > > > > > > > + (KECCAK1600_WIDTH - > CSHAKE256_SECURITY_STRENGTH > > * > > > 2) > > > > / > > > > > 8, > > > > > > > > > > > > + OutputLen > > > > > > > > > > > > + ); > > > > > > > > > > > > + > > > > > > > > > > > > + return Status; > > > > > > > > > > > > + } else { > > > > > > > > > > > > + Status =3D (BOOLEAN)KeccakInit ( > > > > > > > > > > > > + (Keccak1600_Ctx *)CShake256Context, > > > > > > > > > > > > + '\x04', > > > > > > > > > > > > + (KECCAK1600_WIDTH - > CSHAKE256_SECURITY_STRENGTH > > * > > > 2) > > > > / > > > > > 8, > > > > > > > > > > > > + OutputLen > > > > > > > > > > > > + ); > > > > > > > > > > > > + if (!Status) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + AbsorbLen =3D 0; > > > > > > > > > > > > + // > > > > > > > > > > > > + // Absorb Absorb bytepad(.., rate). > > > > > > > > > > > > + // > > > > > > > > > > > > + EncLen =3D LeftEncode (EncBuf, CSHAKE256_RATE_IN_BYTES); > > > > > > > > > > > > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx > > *)CShake256Context, > > > > > > EncBuf, EncLen); > > > > > > > > > > > > + if (!Status) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + AbsorbLen +=3D EncLen; > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Absorb encode_string(N). > > > > > > > > > > > > + // > > > > > > > > > > > > + EncLen =3D LeftEncode (EncBuf, NameLen * 8); > > > > > > > > > > > > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx > > *)CShake256Context, > > > > > > EncBuf, EncLen); > > > > > > > > > > > > + if (!Status) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + AbsorbLen +=3D EncLen; > > > > > > > > > > > > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx > > > > *)CShake256Context, > > > > > > Name, NameLen); > > > > > > > > > > > > + if (!Status) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + AbsorbLen +=3D NameLen; > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Absorb encode_string(S). > > > > > > > > > > > > + // > > > > > > > > > > > > + EncLen =3D LeftEncode (EncBuf, CustomizationLen * 8); > > > > > > > > > > > > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx > > *)CShake256Context, > > > > > > EncBuf, EncLen); > > > > > > > > > > > > + if (!Status) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + AbsorbLen +=3D EncLen; > > > > > > > > > > > > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx > > > > *)CShake256Context, > > > > > > Customization, CustomizationLen); > > > > > > > > > > > > + if (!Status) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + AbsorbLen +=3D CustomizationLen; > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Absorb zero padding up to rate. > > > > > > > > > > > > + // > > > > > > > > > > > > + PadLen =3D CSHAKE256_RATE_IN_BYTES - AbsorbLen % > > > > > > CSHAKE256_RATE_IN_BYTES; > > > > > > > > > > > > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx > > *)CShake256Context, > > > > > > mZeroPadding, PadLen); > > > > > > > > > > > > + if (!Status) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + return TRUE; > > > > > > > > > > > > + } > > > > > > > > > > > > +} > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Digests the input data and updates cSHAKE-256 context. > > > > > > > > > > > > + > > > > > > > > > > > > + This function performs cSHAKE-256 digest on a data buffer of= the > > > specified > > > > > > size. > > > > > > > > > > > > + It can be called multiple times to compute the digest of lon= g or > > > > > discontinuous > > > > > > data streams. > > > > > > > > > > > > + cSHAKE-256 context should be already correctly initialized b= y > > > > > CShake256Init(), > > > > > > and should not be finalized > > > > > > > > > > > > + by CShake256Final(). Behavior with invalid context is undefi= ned. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[in, out] CShake256Context Pointer to the cSHAKE-25= 6 > > > context. > > > > > > > > > > > > + @param[in] Data Pointer to the buffer co= ntaining the > data > > to > > > > be > > > > > > hashed. > > > > > > > > > > > > + @param[in] DataSize Size of Data buffer in b= ytes. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval TRUE cSHAKE-256 data digest succeeded. > > > > > > > > > > > > + @retval FALSE cSHAKE-256 data digest failed. > > > > > > > > > > > > + @retval FALSE This interface is not supported. > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > +BOOLEAN > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +CShake256Update ( > > > > > > > > > > > > + IN OUT VOID *CShake256Context, > > > > > > > > > > > > + IN CONST VOID *Data, > > > > > > > > > > > > + IN UINTN DataSize > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + // > > > > > > > > > > > > + // Check input parameters. > > > > > > > > > > > > + // > > > > > > > > > > > > + if (CShake256Context =3D=3D NULL) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Check invalid parameters, in case that only DataLength wa= s > checked > > in > > > > > > OpenSSL. > > > > > > > > > > > > + // > > > > > > > > > > > > + if ((Data =3D=3D NULL) && (DataSize !=3D 0)) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + return (BOOLEAN)(Sha3Update ((Keccak1600_Ctx > *)CShake256Context, > > > > > Data, > > > > > > DataSize)); > > > > > > > > > > > > +} > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Completes computation of the cSHAKE-256 digest value. > > > > > > > > > > > > + > > > > > > > > > > > > + This function completes cSHAKE-256 hash computation and retr= ieves > > the > > > > > > digest value into > > > > > > > > > > > > + the specified memory. After this function has been called, t= he > cSHAKE- > > > 256 > > > > > > context cannot > > > > > > > > > > > > + be used again. > > > > > > > > > > > > + cSHAKE-256 context should be already correctly initialized b= y > > > > > CShake256Init(), > > > > > > and should not be > > > > > > > > > > > > + finalized by CShake256Final(). Behavior with invalid cSHAKE-= 256 > > context > > > is > > > > > > undefined. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[in, out] CShake256Context Pointer to the cSHAKE-256 > > context. > > > > > > > > > > > > + @param[out] HashValue Pointer to a buffer that = receives the > > > > > cSHAKE- > > > > > > 256 digest > > > > > > > > > > > > + value. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval TRUE cSHAKE-256 digest computation succeeded. > > > > > > > > > > > > + @retval FALSE cSHAKE-256 digest computation failed. > > > > > > > > > > > > + @retval FALSE This interface is not supported. > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > +BOOLEAN > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +CShake256Final ( > > > > > > > > > > > > + IN OUT VOID *CShake256Context, > > > > > > > > > > > > + OUT UINT8 *HashValue > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + // > > > > > > > > > > > > + // Check input parameters. > > > > > > > > > > > > + // > > > > > > > > > > > > + if ((CShake256Context =3D=3D NULL) || (HashValue =3D=3D NULL= )) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // cSHAKE-256 Hash Finalization. > > > > > > > > > > > > + // > > > > > > > > > > > > + return (BOOLEAN)(Sha3Final ((Keccak1600_Ctx *)CShake256Conte= xt, > > > > > > HashValue)); > > > > > > > > > > > > +} > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Computes the CSHAKE-256 message digest of a input data buffe= r. > > > > > > > > > > > > + > > > > > > > > > > > > + This function performs the CSHAKE-256 message digest of a gi= ven > data > > > > > buffer, > > > > > > and places > > > > > > > > > > > > + the digest value into the specified memory. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[in] Data Pointer to the buffer contai= ning the data > to > > > be > > > > > > hashed. > > > > > > > > > > > > + @param[in] DataSize Size of Data buffer in bytes= . > > > > > > > > > > > > + @param[in] OutputLen Size of output in bytes. > > > > > > > > > > > > + @param[in] Name Pointer to the function name= string. > > > > > > > > > > > > + @param[in] NameLen Size of the function name in= bytes. > > > > > > > > > > > > + @param[in] Customization Pointer to the customization= string. > > > > > > > > > > > > + @param[in] CustomizationLen Size of the customization st= ring in > > bytes. > > > > > > > > > > > > + @param[out] HashValue Pointer to a buffer that rec= eives the > > > > CSHAKE- > > > > > > 256 digest > > > > > > > > > > > > + value. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval TRUE CSHAKE-256 digest computation succeeded. > > > > > > > > > > > > + @retval FALSE CSHAKE-256 digest computation failed. > > > > > > > > > > > > + @retval FALSE This interface is not supported. > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > +BOOLEAN > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +CShake256HashAll ( > > > > > > > > > > > > + IN CONST VOID *Data, > > > > > > > > > > > > + IN UINTN DataSize, > > > > > > > > > > > > + IN UINTN OutputLen, > > > > > > > > > > > > + IN CONST VOID *Name, > > > > > > > > > > > > + IN UINTN NameLen, > > > > > > > > > > > > + IN CONST VOID *Customization, > > > > > > > > > > > > + IN UINTN CustomizationLen, > > > > > > > > > > > > + OUT UINT8 *HashValue > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + BOOLEAN Status; > > > > > > > > > > > > + Keccak1600_Ctx Ctx; > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Check input parameters. > > > > > > > > > > > > + // > > > > > > > > > > > > + if (HashValue =3D=3D NULL) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + if ((Data =3D=3D NULL) && (DataSize !=3D 0)) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + Status =3D CShake256Init (&Ctx, OutputLen, Name, NameLen, > > > Customization, > > > > > > CustomizationLen); > > > > > > > > > > > > + if (!Status) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + Status =3D CShake256Update (&Ctx, Data, DataSize); > > > > > > > > > > > > + if (!Status) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + return CShake256Final (&Ctx, HashValue); > > > > > > > > > > > > +} > > > > > > > > > > > > diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelH= ash.c > > > > > > b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c > > > > > > new file mode 100644 > > > > > > index 000000000000..f7ce9dbf523e > > > > > > --- /dev/null > > > > > > +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c > > > > > > @@ -0,0 +1,278 @@ > > > > > > +/** @file > > > > > > > > > > > > + ParallelHash Implementation. > > > > > > > > > > > > + > > > > > > > > > > > > +Copyright (c) 2022, Intel Corporation. All rights reserved. > > > > > > > > > > > > +SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > + > > > > > > > > > > > > +#include "CryptParallelHash.h" > > > > > > > > > > > > +#include > > > > > > > > > > > > +#include > > > > > > > > > > > > + > > > > > > > > > > > > +#define PARALLELHASH_CUSTOMIZATION "ParallelHash" > > > > > > > > > > > > + > > > > > > > > > > > > +UINTN mBlockNum; > > > > > > > > > > > > +UINTN mBlockSize; > > > > > > > > > > > > +UINTN mLastBlockSize; > > > > > > > > > > > > +UINT8 *mInput; > > > > > > > > > > > > +UINTN mBlockResultSize; > > > > > > > > > > > > +UINT8 *mBlockHashResult; > > > > > > > > > > > > +BOOLEAN *mBlockIsCompleted; > > > > > > > > > > > > +SPIN_LOCK *mSpinLockList; > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Complete computation of digest of each block. > > > > > > > > > > > > + > > > > > > > > > > > > + Each AP perform the function called by BSP. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[in] ProcedureArgument Argument of the procedure. > > > > > > > > > > > > +**/ > > > > > > > > > > > > +VOID > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +ParallelHashApExecute ( > > > > > > > > > > > > + IN VOID *ProcedureArgument > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + UINTN Index; > > > > > > > > > > > > + BOOLEAN Status; > > > > > > > > > > > > + > > > > > > > > > > > > + for (Index =3D 0; Index < mBlockNum; Index++) { > > > > > > > > > > > > + if (AcquireSpinLockOrFail (&mSpinLockList[Index])) { > > > > > > > > > > > > + // > > > > > > > > > > > > + // Completed, try next one. > > > > > > > > > > > > + // > > > > > > > > > > > > + if (mBlockIsCompleted[Index]) { > > > > > > > > > > > > + ReleaseSpinLock (&mSpinLockList[Index]); > > > > > > > > > > > > + continue; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Calculate CShake256 for this block. > > > > > > > > > > > > + // > > > > > > > > > > > > + Status =3D CShake256HashAll ( > > > > > > > > > > > > + mInput + Index * mBlockSize, > > > > > > > > > > > > + (Index =3D=3D (mBlockNum - 1)) ? mLastBlockSi= ze : mBlockSize, > > > > > > > > > > > > + mBlockResultSize, > > > > > > > > > > > > + NULL, > > > > > > > > > > > > + 0, > > > > > > > > > > > > + NULL, > > > > > > > > > > > > + 0, > > > > > > > > > > > > + mBlockHashResult + Index * mBlockResultSize > > > > > > > > > > > > + ); > > > > > > > > > > > > + if (!EFI_ERROR (Status)) { > > > > > > > > > > > > + mBlockIsCompleted[Index] =3D TRUE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + ReleaseSpinLock (&mSpinLockList[Index]); > > > > > > > > > > > > + } > > > > > > > > > > > > + } > > > > > > > > > > > > +} > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Dispatch the block task to each AP in SMM mode. > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > +VOID > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +MmDispatchBlockToAP ( > > > > > > > > > > > > + VOID > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + UINTN Index; > > > > > > > > > > > > + > > > > > > > > > > > > + for (Index =3D 0; Index < gMmst->NumberOfCpus; Index++) { > > > > > > > > > > > > + if (Index !=3D gMmst->CurrentlyExecutingCpu) { > > > > > > > > > > > > + gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NU= LL); > > > > > > > > > > > > + } > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + return; > > > > > > > > > > > > +} > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Parallel hash function ParallelHash256, as defined in NIST's= Special > > > > > Publication > > > > > > 800-185, > > > > > > > > > > > > + published December 2016. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[in] Input Pointer to the input message (= X). > > > > > > > > > > > > + @param[in] InputByteLen The number(>0) of input bytes = provided > > for > > > > the > > > > > > input data. > > > > > > > > > > > > + @param[in] BlockSize The size of each block (B). > > > > > > > > > > > > + @param[out] Output Pointer to the output buffer. > > > > > > > > > > > > + @param[in] OutputByteLen The desired number of output b= ytes > (L). > > > > > > > > > > > > + @param[in] Customization Pointer to the customization s= tring (S). > > > > > > > > > > > > + @param[in] CustomByteLen The length of the customizatio= n > string > > in > > > > > bytes. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval TRUE ParallelHash256 digest computation succeeded. > > > > > > > > > > > > + @retval FALSE ParallelHash256 digest computation failed. > > > > > > > > > > > > + @retval FALSE This interface is not supported. > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > +BOOLEAN > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +ParallelHash256HashAll ( > > > > > > > > > > > > + IN CONST VOID *Input, > > > > > > > > > > > > + IN UINTN InputByteLen, > > > > > > > > > > > > + IN UINTN BlockSize, > > > > > > > > > > > > + OUT VOID *Output, > > > > > > > > > > > > + IN UINTN OutputByteLen, > > > > > > > > > > > > + IN CONST VOID *Customization, > > > > > > > > > > > > + IN UINTN CustomByteLen > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + UINT8 EncBufB[sizeof (UINTN)+1]; > > > > > > > > > > > > + UINTN EncSizeB; > > > > > > > > > > > > + UINT8 EncBufN[sizeof (UINTN)+1]; > > > > > > > > > > > > + UINTN EncSizeN; > > > > > > > > > > > > + UINT8 EncBufL[sizeof (UINTN)+1]; > > > > > > > > > > > > + UINTN EncSizeL; > > > > > > > > > > > > + UINTN Index; > > > > > > > > > > > > + UINT8 *CombinedInput; > > > > > > > > > > > > + UINTN CombinedInputSize; > > > > > > > > > > > > + BOOLEAN AllCompleted; > > > > > > > > > > > > + UINTN Offset; > > > > > > > > > > > > + BOOLEAN ReturnValue; > > > > > > > > > > > > + > > > > > > > > > > > > + if ((InputByteLen =3D=3D 0) || (OutputByteLen =3D=3D 0) || (= BlockSize =3D=3D 0)) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + if ((Input =3D=3D NULL) || (Output =3D=3D NULL)) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + if ((CustomByteLen !=3D 0) && (Customization =3D=3D NULL)) { > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + mBlockSize =3D BlockSize; > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Calculate block number n. > > > > > > > > > > > > + // > > > > > > > > > > > > + mBlockNum =3D InputByteLen % mBlockSize =3D=3D 0 ? InputByte= Len / > > > > mBlockSize : > > > > > > InputByteLen / mBlockSize + 1; > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Set hash result size of each block in bytes. > > > > > > > > > > > > + // > > > > > > > > > > > > + mBlockResultSize =3D OutputByteLen; > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Encode B, n, L to string and record size. > > > > > > > > > > > > + // > > > > > > > > > > > > + EncSizeB =3D LeftEncode (EncBufB, mBlockSize); > > > > > > > > > > > > + EncSizeN =3D RightEncode (EncBufN, mBlockNum); > > > > > > > > > > > > + EncSizeL =3D RightEncode (EncBufL, OutputByteLen * CHAR_BIT)= ; > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Allocate buffer for combined input (newX), Block complete= d flag > and > > > > > > SpinLock. > > > > > > > > > > > > + // > > > > > > > > > > > > + CombinedInputSize =3D EncSizeB + EncSizeN + EncSizeL + mBloc= kNum * > > > > > > mBlockResultSize; > > > > > > > > > > > > + CombinedInput =3D AllocateZeroPool (CombinedInputSize); > > > > > > > > > > > > + mBlockIsCompleted =3D AllocateZeroPool (mBlockNum * sizeof > > > (BOOLEAN)); > > > > > > > > > > > > + mSpinLockList =3D AllocatePool (mBlockNum * sizeof (SPIN= _LOCK)); > > > > > > > > > > > > + if ((CombinedInput =3D=3D NULL) || (mBlockIsCompleted =3D=3D= NULL) || > > > > > > (mSpinLockList =3D=3D NULL)) { > > > > > > > > > > > > + ReturnValue =3D FALSE; > > > > > > > > > > > > + goto Exit; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Fill LeftEncode(B). > > > > > > > > > > > > + // > > > > > > > > > > > > + CopyMem (CombinedInput, EncBufB, EncSizeB); > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Prepare for parallel hash. > > > > > > > > > > > > + // > > > > > > > > > > > > + mBlockHashResult =3D CombinedInput + EncSizeB; > > > > > > > > > > > > + mInput =3D (UINT8 *)Input; > > > > > > > > > > > > + mLastBlockSize =3D InputByteLen % mBlockSize =3D=3D 0 ? mB= lockSize : > > > > > > InputByteLen % mBlockSize; > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Initialize SpinLock for each result block. > > > > > > > > > > > > + // > > > > > > > > > > > > + for (Index =3D 0; Index < mBlockNum; Index++) { > > > > > > > > > > > > + InitializeSpinLock (&mSpinLockList[Index]); > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Dispatch blocklist to each AP. > > > > > > > > > > > > + // > > > > > > > > > > > > + if (gMmst !=3D NULL) { > > > > > > > > > > > > + MmDispatchBlockToAP (); > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Wait until all block hash completed. > > > > > > > > > > > > + // > > > > > > > > > > > > + do { > > > > > > > > > > > > + AllCompleted =3D TRUE; > > > > > > > > > > > > + for (Index =3D 0; Index < mBlockNum; Index++) { > > > > > > > > > > > > + if (AcquireSpinLockOrFail (&mSpinLockList[Index])) { > > > > > > > > > > > > + if (!mBlockIsCompleted[Index]) { > > > > > > > > > > > > + AllCompleted =3D FALSE; > > > > > > > > > > > > + ReturnValue =3D CShake256HashAll ( > > > > > > > > > > > > + mInput + Index * mBlockSize, > > > > > > > > > > > > + (Index =3D=3D (mBlockNum - 1)) ? mL= astBlockSize : > > mBlockSize, > > > > > > > > > > > > + mBlockResultSize, > > > > > > > > > > > > + NULL, > > > > > > > > > > > > + 0, > > > > > > > > > > > > + NULL, > > > > > > > > > > > > + 0, > > > > > > > > > > > > + mBlockHashResult + Index * mBlockRe= sultSize > > > > > > > > > > > > + ); > > > > > > > > > > > > + if (ReturnValue) { > > > > > > > > > > > > + mBlockIsCompleted[Index] =3D TRUE; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + ReleaseSpinLock (&mSpinLockList[Index]); > > > > > > > > > > > > + break; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + ReleaseSpinLock (&mSpinLockList[Index]); > > > > > > > > > > > > + } else { > > > > > > > > > > > > + AllCompleted =3D FALSE; > > > > > > > > > > > > + break; > > > > > > > > > > > > + } > > > > > > > > > > > > + } > > > > > > > > > > > > + } while (!AllCompleted); > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Fill LeftEncode(n). > > > > > > > > > > > > + // > > > > > > > > > > > > + Offset =3D EncSizeB + mBlockNum * mBlockResultSize; > > > > > > > > > > > > + CopyMem (CombinedInput + Offset, EncBufN, EncSizeN); > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Fill LeftEncode(L). > > > > > > > > > > > > + // > > > > > > > > > > > > + Offset +=3D EncSizeN; > > > > > > > > > > > > + CopyMem (CombinedInput + Offset, EncBufL, EncSizeL); > > > > > > > > > > > > + > > > > > > > > > > > > + ReturnValue =3D CShake256HashAll ( > > > > > > > > > > > > + CombinedInput, > > > > > > > > > > > > + CombinedInputSize, > > > > > > > > > > > > + OutputByteLen, > > > > > > > > > > > > + PARALLELHASH_CUSTOMIZATION, > > > > > > > > > > > > + AsciiStrLen (PARALLELHASH_CUSTOMIZATION), > > > > > > > > > > > > + Customization, > > > > > > > > > > > > + CustomByteLen, > > > > > > > > > > > > + Output > > > > > > > > > > > > + ); > > > > > > > > > > > > + > > > > > > > > > > > > +Exit: > > > > > > > > > > > > + ZeroMem (CombinedInput, CombinedInputSize); > > > > > > > > > > > > + > > > > > > > > > > > > + if (CombinedInput !=3D NULL) { > > > > > > > > > > > > + FreePool (CombinedInput); > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + if (mSpinLockList !=3D NULL) { > > > > > > > > > > > > + FreePool ((VOID *)mSpinLockList); > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + if (mBlockIsCompleted !=3D NULL) { > > > > > > > > > > > > + FreePool (mBlockIsCompleted); > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + return ReturnValue; > > > > > > > > > > > > +} > > > > > > > > > > > > diff --git > a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHashNull.c > > > > > > b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHashNull.c > > > > > > new file mode 100644 > > > > > > index 000000000000..2bf89594def5 > > > > > > --- /dev/null > > > > > > +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHashNull= .c > > > > > > @@ -0,0 +1,40 @@ > > > > > > +/** @file > > > > > > > > > > > > + ParallelHash Implementation which does not provide real capa= bilities. > > > > > > > > > > > > + > > > > > > > > > > > > +Copyright (c) 2022, Intel Corporation. All rights reserved. > > > > > > > > > > > > +SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > + > > > > > > > > > > > > +#include "InternalCryptLib.h" > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Parallel hash function ParallelHash256, as defined in NIST's= Special > > > > > Publication > > > > > > 800-185, > > > > > > > > > > > > + published December 2016. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[in] Input Pointer to the input message (= X). > > > > > > > > > > > > + @param[in] InputByteLen The number(>0) of input bytes = provided > > for > > > > the > > > > > > input data. > > > > > > > > > > > > + @param[in] BlockSize The size of each block (B). > > > > > > > > > > > > + @param[out] Output Pointer to the output buffer. > > > > > > > > > > > > + @param[in] OutputByteLen The desired number of output b= ytes > (L). > > > > > > > > > > > > + @param[in] Customization Pointer to the customization s= tring (S). > > > > > > > > > > > > + @param[in] CustomByteLen The length of the customizatio= n > string > > in > > > > > bytes. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval FALSE This interface is not supported. > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > +BOOLEAN > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +ParallelHash256HashAll ( > > > > > > > > > > > > + IN CONST VOID *Input, > > > > > > > > > > > > + IN UINTN InputByteLen, > > > > > > > > > > > > + IN UINTN BlockSize, > > > > > > > > > > > > + OUT VOID *Output, > > > > > > > > > > > > + IN UINTN OutputByteLen, > > > > > > > > > > > > + IN CONST VOID *Customization, > > > > > > > > > > > > + IN UINTN CustomByteLen > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + ASSERT (FALSE); > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > +} > > > > > > > > > > > > diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c > > > > > > b/CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c > > > > > > new file mode 100644 > > > > > > index 000000000000..6abafc3c00e6 > > > > > > --- /dev/null > > > > > > +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c > > > > > > @@ -0,0 +1,166 @@ > > > > > > +/** @file > > > > > > > > > > > > + SHA3 realted functions from OpenSSL. > > > > > > > > > > > > + > > > > > > > > > > > > +Copyright (c) 2022, Intel Corporation. All rights reserved. > > > > > > > > > > > > +SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > + > > > > > > > > > > > > +Copyright 2022 The OpenSSL Project Authors. All Rights Reserve= d. > > > > > > > > > > > > +Licensed under the OpenSSL license (the "License"). You may n= ot use > > > > > > > > > > > > +this file except in compliance with the License. You can obta= in a copy > > > > > > > > > > > > +in the file LICENSE in the source distribution or at > > > > > > > > > > > > +https://www.openssl.org/source/license.html > > > > > > > > > > > > +**/ > > > > > > > > > > > > + > > > > > > > > > > > > +#include "CryptParallelHash.h" > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Keccak initial fuction. > > > > > > > > > > > > + > > > > > > > > > > > > + Set up state with specified capacity. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[out] Context Pointer to the context being i= nitialized. > > > > > > > > > > > > + @param[in] Pad Delimited Suffix. > > > > > > > > > > > > + @param[in] BlockSize Size of context block. > > > > > > > > > > > > + @param[in] MessageDigestLen Size of message digest in byte= s. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval 1 Initialize successfully. > > > > > > > > > > > > + @retval 0 Fail to initialize. > > > > > > > > > > > > +**/ > > > > > > > > > > > > +UINT8 > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +KeccakInit ( > > > > > > > > > > > > + OUT Keccak1600_Ctx *Context, > > > > > > > > > > > > + IN UINT8 Pad, > > > > > > > > > > > > + IN UINTN BlockSize, > > > > > > > > > > > > + IN UINTN MessageDigestLen > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + if (BlockSize <=3D sizeof (Context->buf)) { > > > > > > > > > > > > + memset (Context->A, 0, sizeof (Context->A)); > > > > > > > > > > > > + > > > > > > > > > > > > + Context->num =3D 0; > > > > > > > > > > > > + Context->block_size =3D BlockSize; > > > > > > > > > > > > + Context->md_size =3D MessageDigestLen; > > > > > > > > > > > > + Context->pad =3D Pad; > > > > > > > > > > > > + > > > > > > > > > > > > + return 1; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + return 0; > > > > > > > > > > > > +} > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Sha3 update fuction. > > > > > > > > > > > > + > > > > > > > > > > > > + This function performs Sha3 digest on a data buffer of the s= pecified > > size. > > > > > > > > > > > > + It can be called multiple times to compute the digest of lon= g or > > > > > discontinuous > > > > > > data streams. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[in,out] Context Pointer to the Keccak context. > > > > > > > > > > > > + @param[in] Data Pointer to the buffer containing th= e data to be > > > > > hashed. > > > > > > > > > > > > + @param[in] DataSize Size of Data buffer in bytes. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval 1 Update successfully. > > > > > > > > > > > > +**/ > > > > > > > > > > > > +UINT8 > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +Sha3Update ( > > > > > > > > > > > > + IN OUT Keccak1600_Ctx *Context, > > > > > > > > > > > > + IN const VOID *Data, > > > > > > > > > > > > + IN UINTN DataSize > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + const UINT8 *DataCopy; > > > > > > > > > > > > + UINTN BlockSize; > > > > > > > > > > > > + UINTN Num; > > > > > > > > > > > > + UINTN Rem; > > > > > > > > > > > > + > > > > > > > > > > > > + DataCopy =3D Data; > > > > > > > > > > > > + BlockSize =3D (UINT8)(Context->block_size); > > > > > > > > > > > > + > > > > > > > > > > > > + if (DataSize =3D=3D 0) { > > > > > > > > > > > > + return 1; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + if ((Num =3D Context->num) !=3D 0) { > > > > > > > > > > > > + // > > > > > > > > > > > > + // process intermediate buffer > > > > > > > > > > > > + // > > > > > > > > > > > > + Rem =3D BlockSize - Num; > > > > > > > > > > > > + > > > > > > > > > > > > + if (DataSize < Rem) { > > > > > > > > > > > > + memcpy (Context->buf + Num, DataCopy, DataSize); > > > > > > > > > > > > + Context->num +=3D DataSize; > > > > > > > > > > > > + return 1; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // We have enough data to fill or overflow the intermediat= e > > > > > > > > > > > > + // buffer. So we append |Rem| bytes and process the block, > > > > > > > > > > > > + // leaving the rest for later processing. > > > > > > > > > > > > + // > > > > > > > > > > > > + memcpy (Context->buf + Num, DataCopy, Rem); > > > > > > > > > > > > + DataCopy +=3D Rem; > > > > > > > > > > > > + DataSize -=3D Rem; > > > > > > > > > > > > + (void)SHA3_absorb (Context->A, Context->buf, BlockSize, Bl= ockSize); > > > > > > > > > > > > + Context->num =3D 0; > > > > > > > > > > > > + // Context->buf is processed, Context->num is guaranteed t= o be > zero. > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + if (DataSize >=3D BlockSize) { > > > > > > > > > > > > + Rem =3D SHA3_absorb (Context->A, DataCopy, DataSize, Block= Size); > > > > > > > > > > > > + } else { > > > > > > > > > > > > + Rem =3D DataSize; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + if (Rem > 0) { > > > > > > > > > > > > + memcpy (Context->buf, DataCopy + DataSize - Rem, Rem); > > > > > > > > > > > > + Context->num =3D Rem; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + return 1; > > > > > > > > > > > > +} > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Completes computation of Sha3 message digest. > > > > > > > > > > > > + > > > > > > > > > > > > + This function completes sha3 hash computation and retrieves = the > > digest > > > > > value > > > > > > into > > > > > > > > > > > > + the specified memory. After this function has been called, t= he keccak > > > > > context > > > > > > cannot > > > > > > > > > > > > + be used again. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[in, out] Context Pointer to the keccak contex= t. > > > > > > > > > > > > + @param[out] MessageDigest Pointer to a buffer that rec= eives the > > > > > > message digest. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval 1 Meaasge digest computation succeeded. > > > > > > > > > > > > +**/ > > > > > > > > > > > > +UINT8 > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +Sha3Final ( > > > > > > > > > > > > + IN OUT Keccak1600_Ctx *Context, > > > > > > > > > > > > + OUT UINT8 *MessageDigest > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + UINTN BlockSize; > > > > > > > > > > > > + UINTN Num; > > > > > > > > > > > > + > > > > > > > > > > > > + BlockSize =3D Context->block_size; > > > > > > > > > > > > + Num =3D Context->num; > > > > > > > > > > > > + > > > > > > > > > > > > + if (Context->md_size =3D=3D 0) { > > > > > > > > > > > > + return 1; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Pad the data with 10*1. Note that |Num| can be |BlockSize= - 1| > > > > > > > > > > > > + // in which case both byte operations below are performed on > > > > > > > > > > > > + // same byte. > > > > > > > > > > > > + // > > > > > > > > > > > > + memset (Context->buf + Num, 0, BlockSize - Num); > > > > > > > > > > > > + Context->buf[Num] =3D Context->pad; > > > > > > > > > > > > + Context->buf[BlockSize - 1] |=3D 0x80; > > > > > > > > > > > > + > > > > > > > > > > > > + (void)SHA3_absorb (Context->A, Context->buf, BlockSize, Bloc= kSize); > > > > > > > > > > > > + > > > > > > > > > > > > + SHA3_squeeze (Context->A, MessageDigest, Context->md_size, > > > BlockSize); > > > > > > > > > > > > + > > > > > > > > > > > > + return 1; > > > > > > > > > > > > +} > > > > > > > > > > > > diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c > > > > > > b/CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c > > > > > > new file mode 100644 > > > > > > index 000000000000..12c46cfbcd59 > > > > > > --- /dev/null > > > > > > +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c > > > > > > @@ -0,0 +1,107 @@ > > > > > > +/** @file > > > > > > > > > > > > + Encode realted functions from Xkcp. > > > > > > > > > > > > + > > > > > > > > > > > > +Copyright (c) 2022, Intel Corporation. All rights reserved. > > > > > > > > > > > > +SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > + > > > > > > > > > > > > +Copyright 2022 The eXtended Keccak Code Package (XKCP) > > > > > > > > > > > > +https://github.com/XKCP/XKCP > > > > > > > > > > > > +Keccak, designed by Guido Bertoni, Joan Daemen, Michael Peeter= s > and > > > > Gilles > > > > > > Van Assche. > > > > > > > > > > > > +Implementation by the designers, hereby denoted as "the > implementer". > > > > > > > > > > > > +For more information, feedback or questions, please refer to t= he > Keccak > > > > > Team > > > > > > website: > > > > > > > > > > > > +https://keccak.team/ > > > > > > > > > > > > +To the extent possible under law, the implementer has waived a= ll > > > copyright > > > > > > > > > > > > +and related or neighboring rights to the source code in this f= ile. > > > > > > > > > > > > +http://creativecommons.org/publicdomain/zero/1.0/ > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > + > > > > > > > > > > > > +#include "CryptParallelHash.h" > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Encode function from XKCP. > > > > > > > > > > > > + > > > > > > > > > > > > + Encodes the input as a byte string in a way that can be > unambiguously > > > > > parsed > > > > > > > > > > > > + from the beginning of the string by inserting the length of = the byte > > string > > > > > > > > > > > > + before the byte string representation of input. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[out] EncBuf Result of left encode. > > > > > > > > > > > > + @param[in] Value Input of left encode. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval EncLen Size of encode result in bytes. > > > > > > > > > > > > +**/ > > > > > > > > > > > > +UINTN > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +LeftEncode ( > > > > > > > > > > > > + OUT UINT8 *EncBuf, > > > > > > > > > > > > + IN UINTN Value > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + UINT32 BlockNum; > > > > > > > > > > > > + UINT32 EncLen; > > > > > > > > > > > > + UINT32 Index; > > > > > > > > > > > > + UINTN ValueCopy; > > > > > > > > > > > > + > > > > > > > > > > > > + for ( ValueCopy =3D Value, BlockNum =3D 0; ValueCopy && (Blo= ckNum < > > > sizeof > > > > > > (UINTN)); ++BlockNum, ValueCopy >>=3D 8 ) { > > > > > > > > > > > > + // > > > > > > > > > > > > + // Empty > > > > > > > > > > > > + // > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + if (BlockNum =3D=3D 0) { > > > > > > > > > > > > + BlockNum =3D 1; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + for (Index =3D 1; Index <=3D BlockNum; ++Index) { > > > > > > > > > > > > + EncBuf[Index] =3D (UINT8)(Value >> (8 * (BlockNum - Index)= )); > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + EncBuf[0] =3D (UINT8)BlockNum; > > > > > > > > > > > > + EncLen =3D BlockNum + 1; > > > > > > > > > > > > + > > > > > > > > > > > > + return EncLen; > > > > > > > > > > > > +} > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Encode function from XKCP. > > > > > > > > > > > > + > > > > > > > > > > > > + Encodes the input as a byte string in a way that can be > unambiguously > > > > > parsed > > > > > > > > > > > > + from the end of the string by inserting the length of the by= te string > > after > > > > > > > > > > > > + the byte string representation of input. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[out] EncBuf Result of right encode. > > > > > > > > > > > > + @param[in] Value Input of right encode. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval EncLen Size of encode result in bytes. > > > > > > > > > > > > +**/ > > > > > > > > > > > > +UINTN > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +RightEncode ( > > > > > > > > > > > > + OUT UINT8 *EncBuf, > > > > > > > > > > > > + IN UINTN Value > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + UINT32 BlockNum; > > > > > > > > > > > > + UINT32 EncLen; > > > > > > > > > > > > + UINT32 Index; > > > > > > > > > > > > + UINTN ValueCopy; > > > > > > > > > > > > + > > > > > > > > > > > > + for (ValueCopy =3D Value, BlockNum =3D 0; ValueCopy && (Bloc= kNum < > > > sizeof > > > > > > (UINTN)); ++BlockNum, ValueCopy >>=3D 8) { > > > > > > > > > > > > + // > > > > > > > > > > > > + // Empty > > > > > > > > > > > > + // > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + if (BlockNum =3D=3D 0) { > > > > > > > > > > > > + BlockNum =3D 1; > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + for (Index =3D 1; Index <=3D BlockNum; ++Index) { > > > > > > > > > > > > + EncBuf[Index-1] =3D (UINT8)(Value >> (8 * (BlockNum-Index)= )); > > > > > > > > > > > > + } > > > > > > > > > > > > + > > > > > > > > > > > > + EncBuf[BlockNum] =3D (UINT8)BlockNum; > > > > > > > > > > > > + EncLen =3D BlockNum + 1; > > > > > > > > > > > > + > > > > > > > > > > > > + return EncLen; > > > > > > > > > > > > +} > > > > > > > > > > > > diff --git > > > > a/CryptoPkg/Library/BaseCryptLibNull/Hash/CryptParallelHashNull.c > > > > > > b/CryptoPkg/Library/BaseCryptLibNull/Hash/CryptParallelHashNull= .c > > > > > > new file mode 100644 > > > > > > index 000000000000..2bf89594def5 > > > > > > --- /dev/null > > > > > > +++ > b/CryptoPkg/Library/BaseCryptLibNull/Hash/CryptParallelHashNull.c > > > > > > @@ -0,0 +1,40 @@ > > > > > > +/** @file > > > > > > > > > > > > + ParallelHash Implementation which does not provide real capa= bilities. > > > > > > > > > > > > + > > > > > > > > > > > > +Copyright (c) 2022, Intel Corporation. All rights reserved. > > > > > > > > > > > > +SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > + > > > > > > > > > > > > +#include "InternalCryptLib.h" > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Parallel hash function ParallelHash256, as defined in NIST's= Special > > > > > Publication > > > > > > 800-185, > > > > > > > > > > > > + published December 2016. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[in] Input Pointer to the input message (= X). > > > > > > > > > > > > + @param[in] InputByteLen The number(>0) of input bytes = provided > > for > > > > the > > > > > > input data. > > > > > > > > > > > > + @param[in] BlockSize The size of each block (B). > > > > > > > > > > > > + @param[out] Output Pointer to the output buffer. > > > > > > > > > > > > + @param[in] OutputByteLen The desired number of output b= ytes > (L). > > > > > > > > > > > > + @param[in] Customization Pointer to the customization s= tring (S). > > > > > > > > > > > > + @param[in] CustomByteLen The length of the customizatio= n > string > > in > > > > > bytes. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval FALSE This interface is not supported. > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > +BOOLEAN > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +ParallelHash256HashAll ( > > > > > > > > > > > > + IN CONST VOID *Input, > > > > > > > > > > > > + IN UINTN InputByteLen, > > > > > > > > > > > > + IN UINTN BlockSize, > > > > > > > > > > > > + OUT VOID *Output, > > > > > > > > > > > > + IN UINTN OutputByteLen, > > > > > > > > > > > > + IN CONST VOID *Customization, > > > > > > > > > > > > + IN UINTN CustomByteLen > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + ASSERT (FALSE); > > > > > > > > > > > > + return FALSE; > > > > > > > > > > > > +} > > > > > > > > > > > > diff --git a/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptL= ib.c > > > > > > b/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c > > > > > > index c8df259ea963..8ee1b53cf957 100644 > > > > > > --- a/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c > > > > > > +++ b/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c > > > > > > @@ -3,7 +3,7 @@ > > > > > > Protocol/PPI. > > > > > > > > > > > > > > > > > > > > > > > > Copyright (C) Microsoft Corporation. All rights reserved. > > > > > > > > > > > > - Copyright (c) 2019 - 2020, Intel Corporation. All rights res= erved.
> > > > > > > > > > > > + Copyright (c) 2019 - 2022, Intel Corporation. All rights res= erved.
> > > > > > > > > > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > > > > > > > > > > > > > **/ > > > > > > > > > > > > @@ -870,6 +870,38 @@ Sha512HashAll ( > > > > > > CALL_CRYPTO_SERVICE (Sha512HashAll, (Data, DataSize, HashVal= ue), > > > > FALSE); > > > > > > > > > > > > } > > > > > > > > > > > > > > > > > > > > > > > > +/** > > > > > > > > > > > > + Parallel hash function ParallelHash256, as defined in NIST's= Special > > > > > Publication > > > > > > 800-185, > > > > > > > > > > > > + published December 2016. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[in] Input Pointer to the input message (= X). > > > > > > > > > > > > + @param[in] InputByteLen The number(>0) of input bytes = provided > > for > > > > the > > > > > > input data. > > > > > > > > > > > > + @param[in] BlockSize The size of each block (B). > > > > > > > > > > > > + @param[out] Output Pointer to the output buffer. > > > > > > > > > > > > + @param[in] OutputByteLen The desired number of output b= ytes > (L). > > > > > > > > > > > > + @param[in] Customization Pointer to the customization s= tring (S). > > > > > > > > > > > > + @param[in] CustomByteLen The length of the customizatio= n > string > > in > > > > > bytes. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval TRUE ParallelHash256 digest computation succeeded. > > > > > > > > > > > > + @retval FALSE ParallelHash256 digest computation failed. > > > > > > > > > > > > + @retval FALSE This interface is not supported. > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > +BOOLEAN > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +ParallelHash256HashAll ( > > > > > > > > > > > > + IN CONST VOID *Input, > > > > > > > > > > > > + IN UINTN InputByteLen, > > > > > > > > > > > > + IN UINTN BlockSize, > > > > > > > > > > > > + OUT VOID *Output, > > > > > > > > > > > > + IN UINTN OutputByteLen, > > > > > > > > > > > > + IN CONST VOID *Customization, > > > > > > > > > > > > + IN UINTN CustomByteLen > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + CALL_CRYPTO_SERVICE (ParallelHash256HashAll, (Input, > InputByteLen, > > > > > > BlockSize, Output, OutputByteLen, Customization, CustomByteLen)= , > > FALSE); > > > > > > > > > > > > +} > > > > > > > > > > > > + > > > > > > > > > > > > /** > > > > > > > > > > > > Retrieves the size, in bytes, of the context buffer required= for SM3 > hash > > > > > > operations. > > > > > > > > > > > > > > > > > > > > > > > > diff --git > > > > a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests.c > > > > > > b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTest= s.c > > > > > > new file mode 100644 > > > > > > index 000000000000..fb57e91a9f16 > > > > > > --- /dev/null > > > > > > +++ > b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests.c > > > > > > @@ -0,0 +1,145 @@ > > > > > > +/** @file > > > > > > > > > > > > + Application for Parallelhash Function Validation. > > > > > > > > > > > > + > > > > > > > > > > > > +Copyright (c) 2022, Intel Corporation. All rights reserved. > > > > > > > > > > > > +SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > + > > > > > > > > > > > > +#include "TestBaseCryptLib.h" > > > > > > > > > > > > + > > > > > > > > > > > > +// > > > > > > > > > > > > +// Parallelhash Test Sample common parameters. > > > > > > > > > > > > +// > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINTN OutputByteLen > =3D > > > 64; > > > > > > > > > > > > + > > > > > > > > > > > > +// > > > > > > > > > > > > +// Parallelhash Test Sample #1 from NIST Special Publication 8= 00-185. > > > > > > > > > > > > +// > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 InputSample1[] > =3D > > { > > > > > > > > > > > > + // input data of sample1. > > > > > > > > > > > > + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, = 0x12, > 0x13, > > > > > 0x14, > > > > > > 0x15, 0x16, 0x17, > > > > > > > > > > > > + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27 > > > > > > > > > > > > +}; > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN > > InputSample1ByteLen > > > =3D > > > > > 24; > > > > > > // Length of sample1 input data in bytes. > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID > > > > > *CustomizationSample1 > > > > > > =3D ""; // Customization string (S) of sample1. > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN > > > CustomSample1ByteLen > > > > =3D > > > > > 0; > > > > > > // Customization string length of sample1 in bytes. > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample1 > > =3D > > > 8; > > > > > > // Block size of sample1. > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 > > > > > ExpectOutputSample1[] > > > > > > =3D { > > > > > > > > > > > > + // Expected output data of sample1. > > > > > > > > > > > > + 0xbc, 0x1e, 0xf1, 0x24, 0xda, 0x34, 0x49, 0x5e, 0x94, 0x8e, = 0xad, > 0x20, > > > > > 0x7d, > > > > > > 0xd9, 0x84, 0x22, > > > > > > > > > > > > + 0x35, 0xda, 0x43, 0x2d, 0x2b, 0xbc, 0x54, 0xb4, 0xc1, 0x10, = 0xe6, > 0x4c, > > > > > 0x45, > > > > > > 0x11, 0x05, 0x53, > > > > > > > > > > > > + 0x1b, 0x7f, 0x2a, 0x3e, 0x0c, 0xe0, 0x55, 0xc0, 0x28, 0x05, = 0xe7, > 0xc2, > > > > 0xde, > > > > > > 0x1f, 0xb7, 0x46, > > > > > > > > > > > > + 0xaf, 0x97, 0xa1, 0xd0, 0x01, 0xf4, 0x3b, 0x82, 0x4e, 0x31, = 0xb8, > 0x76, > > > > 0x12, > > > > > > 0x41, 0x04, 0x29 > > > > > > > > > > > > +}; > > > > > > > > > > > > + > > > > > > > > > > > > +// > > > > > > > > > > > > +// Parallelhash Test Sample #2 from NIST Special Publication 8= 00-185. > > > > > > > > > > > > +// > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 *InputSample2 > > > =3D > > > > > > InputSample1; // Input of sample2 is same as samp= le1. > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN > > InputSample2ByteLen > > > =3D > > > > > 24; > > > > > > // Length of sample2 input data in bytes. > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID > > > > > *CustomizationSample2 > > > > > > =3D "Parallel Data"; // Customization string (S) of = sample2. > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN > > > CustomSample2ByteLen > > > > =3D > > > > > > 13; // Customization string length of s= ample2 in bytes. > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample2 > > =3D > > > 8; > > > > > > // Block size of sample2. > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 > > > > > ExpectOutputSample2[] > > > > > > =3D { > > > > > > > > > > > > + // Expected output data of sample2. > > > > > > > > > > > > + 0xcd, 0xf1, 0x52, 0x89, 0xb5, 0x4f, 0x62, 0x12, 0xb4, 0xbc, = 0x27, > 0x05, > > > > 0x28, > > > > > > 0xb4, 0x95, 0x26, > > > > > > > > > > > > + 0x00, 0x6d, 0xd9, 0xb5, 0x4e, 0x2b, 0x6a, 0xdd, 0x1e, 0xf6, = 0x90, > 0x0d, > > > > > 0xda, > > > > > > 0x39, 0x63, 0xbb, > > > > > > > > > > > > + 0x33, 0xa7, 0x24, 0x91, 0xf2, 0x36, 0x96, 0x9c, 0xa8, 0xaf, = 0xae, > 0xa2, > > > > 0x9c, > > > > > > 0x68, 0x2d, 0x47, > > > > > > > > > > > > + 0xa3, 0x93, 0xc0, 0x65, 0xb3, 0x8e, 0x29, 0xfa, 0xe6, 0x51, = 0xa2, > 0x09, > > > > 0x1c, > > > > > > 0x83, 0x31, 0x10 > > > > > > > > > > > > +}; > > > > > > > > > > > > + > > > > > > > > > > > > +// > > > > > > > > > > > > +// Parallelhash Test Sample #3 from NIST Special Publication 8= 00-185. > > > > > > > > > > > > +// > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 InputSample3[] > =3D > > { > > > > > > > > > > > > + // input data of sample3. > > > > > > > > > > > > + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, = 0x0a, > 0x0b, > > > > > 0x10, > > > > > > 0x11, 0x12, 0x13, > > > > > > > > > > > > + 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x20, 0x21, = 0x22, > 0x23, > > > > > 0x24, > > > > > > 0x25, 0x26, 0x27, > > > > > > > > > > > > + 0x28, 0x29, 0x2a, 0x2b, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, = 0x36, > 0x37, > > > > > 0x38, > > > > > > 0x39, 0x3a, 0x3b, > > > > > > > > > > > > + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, = 0x4a, > 0x4b, > > > > > 0x50, > > > > > > 0x51, 0x52, 0x53, > > > > > > > > > > > > + 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b > > > > > > > > > > > > +}; > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN > > InputSample3ByteLen > > > =3D > > > > > 72; > > > > > > // Length of sample3 input data in bytes. > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID > > > > > *CustomizationSample3 > > > > > > =3D "Parallel Data"; // Customization string (S) of = sample3. > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN > > > CustomSample3ByteLen > > > > =3D > > > > > > 13; // Customization string length of s= ample3 in bytes. > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample3 > > =3D > > > > 12; > > > > > > // Block size of sample3. > > > > > > > > > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 > > > > > ExpectOutputSample3[] > > > > > > =3D { > > > > > > > > > > > > + // Expected output data of sample3. > > > > > > > > > > > > + 0x69, 0xd0, 0xfc, 0xb7, 0x64, 0xea, 0x05, 0x5d, 0xd0, 0x93, = 0x34, > 0xbc, > > > > 0x60, > > > > > > 0x21, 0xcb, 0x7e, > > > > > > > > > > > > + 0x4b, 0x61, 0x34, 0x8d, 0xff, 0x37, 0x5d, 0xa2, 0x62, 0x67, = 0x1c, > 0xde, > > > > 0xc3, > > > > > > 0xef, 0xfa, 0x8d, > > > > > > > > > > > > + 0x1b, 0x45, 0x68, 0xa6, 0xcc, 0xe1, 0x6b, 0x1c, 0xad, 0x94, = 0x6d, > 0xdd, > > > > > 0xe2, > > > > > > 0x7f, 0x6c, 0xe2, > > > > > > > > > > > > + 0xb8, 0xde, 0xe4, 0xcd, 0x1b, 0x24, 0x85, 0x1e, 0xbf, 0x00, = 0xeb, > 0x90, > > > > > 0xd4, > > > > > > 0x38, 0x13, 0xe9 > > > > > > > > > > > > +}; > > > > > > > > > > > > + > > > > > > > > > > > > +UNIT_TEST_STATUS > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +TestVerifyParallelHash256HashAll ( > > > > > > > > > > > > + IN UNIT_TEST_CONTEXT Context > > > > > > > > > > > > + ) > > > > > > > > > > > > +{ > > > > > > > > > > > > + BOOLEAN Status; > > > > > > > > > > > > + UINT8 Output[64]; > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Test #1 using sample1. > > > > > > > > > > > > + // > > > > > > > > > > > > + Status =3D ParallelHash256HashAll ( > > > > > > > > > > > > + InputSample1, > > > > > > > > > > > > + InputSample1ByteLen, > > > > > > > > > > > > + BlockSizeSample1, > > > > > > > > > > > > + Output, > > > > > > > > > > > > + OutputByteLen, > > > > > > > > > > > > + CustomizationSample1, > > > > > > > > > > > > + CustomSample1ByteLen > > > > > > > > > > > > + ); > > > > > > > > > > > > + UT_ASSERT_TRUE (Status); > > > > > > > > > > > > + > > > > > > > > > > > > + // Check the output with the expected output. > > > > > > > > > > > > + UT_ASSERT_MEM_EQUAL (Output, ExpectOutputSample1, > > > > OutputByteLen); > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Test #2 using sample2. > > > > > > > > > > > > + // > > > > > > > > > > > > + Status =3D ParallelHash256HashAll ( > > > > > > > > > > > > + InputSample2, > > > > > > > > > > > > + InputSample2ByteLen, > > > > > > > > > > > > + BlockSizeSample2, > > > > > > > > > > > > + Output, > > > > > > > > > > > > + OutputByteLen, > > > > > > > > > > > > + CustomizationSample2, > > > > > > > > > > > > + CustomSample2ByteLen > > > > > > > > > > > > + ); > > > > > > > > > > > > + UT_ASSERT_TRUE (Status); > > > > > > > > > > > > + > > > > > > > > > > > > + // Check the output with the expected output. > > > > > > > > > > > > + UT_ASSERT_MEM_EQUAL (Output, ExpectOutputSample2, > > > > OutputByteLen); > > > > > > > > > > > > + > > > > > > > > > > > > + // > > > > > > > > > > > > + // Test #3 using sample3. > > > > > > > > > > > > + // > > > > > > > > > > > > + Status =3D ParallelHash256HashAll ( > > > > > > > > > > > > + InputSample3, > > > > > > > > > > > > + InputSample3ByteLen, > > > > > > > > > > > > + BlockSizeSample3, > > > > > > > > > > > > + Output, > > > > > > > > > > > > + OutputByteLen, > > > > > > > > > > > > + CustomizationSample3, > > > > > > > > > > > > + CustomSample3ByteLen > > > > > > > > > > > > + ); > > > > > > > > > > > > + UT_ASSERT_TRUE (Status); > > > > > > > > > > > > + > > > > > > > > > > > > + // Check the output with the expected output. > > > > > > > > > > > > + UT_ASSERT_MEM_EQUAL (Output, ExpectOutputSample3, > > > > OutputByteLen); > > > > > > > > > > > > + > > > > > > > > > > > > + return EFI_SUCCESS; > > > > > > > > > > > > +} > > > > > > > > > > > > + > > > > > > > > > > > > +TEST_DESC mParallelhashTest[] =3D { > > > > > > > > > > > > + // > > > > > > > > > > > > + // -----Description------------------------------Class------= ---------------- > > > > Function-- > > > > > -- > > > > > > -------------Pre---Post--Context > > > > > > > > > > > > + // > > > > > > > > > > > > + { "TestVerifyParallelHash256HashAll()", > > > > > > "CryptoPkg.BaseCryptLib.ParallelHash256HashAll", > > > > > > TestVerifyParallelHash256HashAll, NULL, NULL, NULL }, > > > > > > > > > > > > +}; > > > > > > > > > > > > + > > > > > > > > > > > > +UINTN mParallelhashTestNum =3D ARRAY_SIZE (mParallelhashTest)= ; > > > > > > > > > > > > diff --git a/CryptoPkg/CryptoPkg.ci.yaml > b/CryptoPkg/CryptoPkg.ci.yaml > > > > > > index eeb388ae71c5..e21fafac1efe 100644 > > > > > > --- a/CryptoPkg/CryptoPkg.ci.yaml > > > > > > +++ b/CryptoPkg/CryptoPkg.ci.yaml > > > > > > @@ -2,7 +2,7 @@ > > > > > > # CI configuration for CryptoPkg > > > > > > > > > > > > # > > > > > > > > > > > > # Copyright (c) Microsoft Corporation > > > > > > > > > > > > -# Copyright (c) 2020, Intel Corporation. All rights reserved.<= BR> > > > > > > > > > > > > +# Copyright (c) 2020 - 2022, Intel Corporation. All rights res= erved.
> > > > > > > > > > > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > ## > > > > > > > > > > > > { > > > > > > > > > > > > @@ -34,6 +34,8 @@ > > > > > > "Library/OpensslLib/rand_pool.c", > > > > > > > > > > > > # This has OpenSSL interfaces that aren't UEFI spe= c compliant > > > > > > > > > > > > "Library/Include/CrtLibSupport.h", > > > > > > > > > > > > + # This has OpenSSL interfaces that aren't UEFI spe= c compliant > > > > > > > > > > > > + "Library/BaseCryptLib/Hash/CryptParallelHash.h", > > > > > > > > > > > > # These directories contain auto-generated OpenSSL= content > > > > > > > > > > > > "Library/OpensslLib", > > > > > > > > > > > > "Library/IntrinsicLib", > > > > > > > > > > > > diff --git a/CryptoPkg/Include/Library/BaseCryptLib.h > > > > > > b/CryptoPkg/Include/Library/BaseCryptLib.h > > > > > > index f4bc7c0d73d9..7d1499350a49 100644 > > > > > > --- a/CryptoPkg/Include/Library/BaseCryptLib.h > > > > > > +++ b/CryptoPkg/Include/Library/BaseCryptLib.h > > > > > > @@ -4,7 +4,7 @@ > > > > > > primitives (Hash Serials, HMAC, RSA, Diffie-Hellman, etc) fo= r UEFI > > security > > > > > > > > > > > > functionality enabling. > > > > > > > > > > > > > > > > > > > > > > > > -Copyright (c) 2009 - 2020, Intel Corporation. All rights reser= ved.
> > > > > > > > > > > > +Copyright (c) 2009 - 2022, Intel Corporation. All rights reser= ved.
> > > > > > > > > > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > > > > > > > > > > > > > **/ > > > > > > > > > > > > @@ -753,6 +753,35 @@ Sha512HashAll ( > > > > > > OUT UINT8 *HashValue > > > > > > > > > > > > ); > > > > > > > > > > > > > > > > > > > > > > > > +/** > > > > > > > > > > > > + Parallel hash function ParallelHash256, as defined in NIST's= Special > > > > > Publication > > > > > > 800-185, > > > > > > > > > > > > + published December 2016. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[in] Input Pointer to the input message (= X). > > > > > > > > > > > > + @param[in] InputByteLen The number(>0) of input bytes = provided > > for > > > > the > > > > > > input data. > > > > > > > > > > > > + @param[in] BlockSize The size of each block (B). > > > > > > > > > > > > + @param[out] Output Pointer to the output buffer. > > > > > > > > > > > > + @param[in] OutputByteLen The desired number of output b= ytes > (L). > > > > > > > > > > > > + @param[in] Customization Pointer to the customization s= tring (S). > > > > > > > > > > > > + @param[in] CustomByteLen The length of the customizatio= n > string > > in > > > > > bytes. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval TRUE ParallelHash256 digest computation succeeded. > > > > > > > > > > > > + @retval FALSE ParallelHash256 digest computation failed. > > > > > > > > > > > > + @retval FALSE This interface is not supported. > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > +BOOLEAN > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +ParallelHash256HashAll ( > > > > > > > > > > > > + IN CONST VOID *Input, > > > > > > > > > > > > + IN UINTN InputByteLen, > > > > > > > > > > > > + IN UINTN BlockSize, > > > > > > > > > > > > + OUT VOID *Output, > > > > > > > > > > > > + IN UINTN OutputByteLen, > > > > > > > > > > > > + IN CONST VOID *Customization, > > > > > > > > > > > > + IN UINTN CustomByteLen > > > > > > > > > > > > + ); > > > > > > > > > > > > + > > > > > > > > > > > > /** > > > > > > > > > > > > Retrieves the size, in bytes, of the context buffer required= for SM3 > hash > > > > > > operations. > > > > > > > > > > > > > > > > > > > > > > > > diff --git a/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable= .h > > > > > > b/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h > > > > > > index 5186a54759ae..77330961352e 100644 > > > > > > --- a/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h > > > > > > +++ b/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h > > > > > > @@ -2,7 +2,7 @@ > > > > > > Defines the PCD_CRYPTO_SERVICE_FAMILY_ENABLE structure > > > associated > > > > > with > > > > > > > > > > > > gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable. > > > > > > > > > > > > > > > > > > > > > > > > - Copyright (c) 2019 - 2020, Intel Corporation. All rights res= erved.
> > > > > > > > > > > > + Copyright (c) 2019 - 2022, Intel Corporation. All rights res= erved.
> > > > > > > > > > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > > > > > > > > > > > > > **/ > > > > > > > > > > > > @@ -288,6 +288,12 @@ typedef struct { > > > > > > } Services; > > > > > > > > > > > > UINT32 Family; > > > > > > > > > > > > } TlsGet; > > > > > > > > > > > > + union { > > > > > > > > > > > > + struct { > > > > > > > > > > > > + UINT8 HashAll : 1; > > > > > > > > > > > > + } Services; > > > > > > > > > > > > + UINT32 Family; > > > > > > > > > > > > + } ParallelHash; > > > > > > > > > > > > } PCD_CRYPTO_SERVICE_FAMILY_ENABLE; > > > > > > > > > > > > > > > > > > > > > > > > #endif > > > > > > > > > > > > diff --git a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf > > > > > > b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf > > > > > > index 49703fa4c963..15cf3dab105c 100644 > > > > > > --- a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf > > > > > > +++ b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf > > > > > > @@ -6,7 +6,7 @@ > > > > > > # This external input must be validated carefully to avoid se= curity > issues > > > > such > > > > > as > > > > > > > > > > > > # buffer overflow or integer overflow. > > > > > > > > > > > > # > > > > > > > > > > > > -# Copyright (c) 2009 - 2020, Intel Corporation. All rights re= served.
> > > > > > > > > > > > +# Copyright (c) 2009 - 2022, Intel Corporation. All rights re= served.
> > > > > > > > > > > > # Copyright (c) 2020, Hewlett Packard Enterprise Development = LP. All > > > rights > > > > > > reserved.
> > > > > > > > > > > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > # > > > > > > > > > > > > @@ -34,6 +34,7 @@ > > > > > > Hash/CryptSha256.c > > > > > > > > > > > > Hash/CryptSha512.c > > > > > > > > > > > > Hash/CryptSm3.c > > > > > > > > > > > > + Hash/CryptParallelHashNull.c > > > > > > > > > > > > Hmac/CryptHmacSha256.c > > > > > > > > > > > > Kdf/CryptHkdf.c > > > > > > > > > > > > Cipher/CryptAes.c > > > > > > > > > > > > diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelH= ash.h > > > > > > b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h > > > > > > new file mode 100644 > > > > > > index 000000000000..fe08d4928e8d > > > > > > --- /dev/null > > > > > > +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h > > > > > > @@ -0,0 +1,201 @@ > > > > > > +/** @file > > > > > > > > > > > > + ParallelHash related function and type declaration. > > > > > > > > > > > > + > > > > > > > > > > > > +Copyright (c) 2022, Intel Corporation. All rights reserved. > > > > > > > > > > > > +SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > + > > > > > > > > > > > > +Copyright 2022 The OpenSSL Project Authors. All Rights Reserve= d. > > > > > > > > > > > > +Licensed under the OpenSSL license (the "License"). You may n= ot use > > > > > > > > > > > > +this file except in compliance with the License. You can obta= in a copy > > > > > > > > > > > > +in the file LICENSE in the source distribution or at > > > > > > > > > > > > +https://www.openssl.org/source/license.html > > > > > > > > > > > > + > > > > > > > > > > > > +Copyright 2022 The eXtended Keccak Code Package (XKCP) > > > > > > > > > > > > +https://github.com/XKCP/XKCP > > > > > > > > > > > > +Keccak, designed by Guido Bertoni, Joan Daemen, Michael Peeter= s > and > > > > Gilles > > > > > > Van Assche. > > > > > > > > > > > > +Implementation by the designers, hereby denoted as "the > implementer". > > > > > > > > > > > > +For more information, feedback or questions, please refer to t= he > Keccak > > > > > Team > > > > > > website: > > > > > > > > > > > > +https://keccak.team/ > > > > > > > > > > > > +To the extent possible under law, the implementer has waived a= ll > > > copyright > > > > > > > > > > > > +and related or neighboring rights to the source code in this f= ile. > > > > > > > > > > > > +http://creativecommons.org/publicdomain/zero/1.0/ > > > > > > > > > > > > +**/ > > > > > > > > > > > > + > > > > > > > > > > > > +#include "InternalCryptLib.h" > > > > > > > > > > > > + > > > > > > > > > > > > +#define KECCAK1600_WIDTH 1600 > > > > > > > > > > > > + > > > > > > > > > > > > +// > > > > > > > > > > > > +// This struct referring to m_sha3.c from opessl and modified = its type > > > name. > > > > > > > > > > > > +// > > > > > > > > > > > > +typedef struct { > > > > > > > > > > > > + uint64_t A[5][5]; > > > > > > > > > > > > + size_t block_size; /* cached ctx->digest->block_s= ize */ > > > > > > > > > > > > + size_t md_size; /* output length, variable in = XOF */ > > > > > > > > > > > > + size_t num; /* used bytes in below buffer = */ > > > > > > > > > > > > + unsigned char buf[KECCAK1600_WIDTH / 8 - 32]; > > > > > > > > > > > > + unsigned char pad; > > > > > > > > > > > > +} Keccak1600_Ctx; > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + SHA3_absorb can be called multiple times, but at each invoca= tion > > > > > > > > > > > > + largest multiple of |r| out of |len| bytes are processed. Th= en > > > > > > > > > > > > + remaining amount of bytes is returned. This is done to spare= caller > > > > > > > > > > > > + trouble of calculating the largest multiple of |r|. |r| can = be viewed > > > > > > > > > > > > + as blocksize. It is commonly (1600 - 256*n)/8, e.g. 168, 136= , 104, > > > > > > > > > > > > + 72, but can also be (1600 - 448)/8 =3D 144. All this means t= hat message > > > > > > > > > > > > + padding and intermediate sub-block buffering, byte- or bitwi= se, is > > > > > > > > > > > > + caller's responsibility. > > > > > > > > > > > > +**/ > > > > > > > > > > > > +size_t > > > > > > > > > > > > +SHA3_absorb ( > > > > > > > > > > > > + uint64_t A[5][5], > > > > > > > > > > > > + const unsigned char *inp, > > > > > > > > > > > > + size_t len, > > > > > > > > > > > > + size_t r > > > > > > > > > > > > + ); > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + SHA3_squeeze is called once at the end to generate |out| has= h value > > > > > > > > > > > > + of |len| bytes. > > > > > > > > > > > > +**/ > > > > > > > > > > > > +void > > > > > > > > > > > > +SHA3_squeeze ( > > > > > > > > > > > > + uint64_t A[5][5], > > > > > > > > > > > > + unsigned char *out, > > > > > > > > > > > > + size_t len, > > > > > > > > > > > > + size_t r > > > > > > > > > > > > + ); > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Encode function from XKCP. > > > > > > > > > > > > + > > > > > > > > > > > > + Encodes the input as a byte string in a way that can be > unambiguously > > > > > parsed > > > > > > > > > > > > + from the beginning of the string by inserting the length of = the byte > > string > > > > > > > > > > > > + before the byte string representation of input. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[out] EncBuf Result of left encode. > > > > > > > > > > > > + @param[in] Value Input of left encode. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval EncLen Size of encode result in bytes. > > > > > > > > > > > > +**/ > > > > > > > > > > > > +UINTN > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +LeftEncode ( > > > > > > > > > > > > + OUT UINT8 *EncBuf, > > > > > > > > > > > > + IN UINTN Value > > > > > > > > > > > > + ); > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Encode function from XKCP. > > > > > > > > > > > > + > > > > > > > > > > > > + Encodes the input as a byte string in a way that can be > unambiguously > > > > > parsed > > > > > > > > > > > > + from the end of the string by inserting the length of the by= te string > > after > > > > > > > > > > > > + the byte string representation of input. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[out] EncBuf Result of right encode. > > > > > > > > > > > > + @param[in] Value Input of right encode. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval EncLen Size of encode result in bytes. > > > > > > > > > > > > +**/ > > > > > > > > > > > > +UINTN > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +RightEncode ( > > > > > > > > > > > > + OUT UINT8 *EncBuf, > > > > > > > > > > > > + IN UINTN Value > > > > > > > > > > > > + ); > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Keccak initial fuction. > > > > > > > > > > > > + > > > > > > > > > > > > + Set up state with specified capacity. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[out] Context Pointer to the context being i= nitialized. > > > > > > > > > > > > + @param[in] Pad Delimited Suffix. > > > > > > > > > > > > + @param[in] BlockSize Size of context block. > > > > > > > > > > > > + @param[in] MessageDigestLen Size of message digest in byte= s. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval 1 Initialize successfully. > > > > > > > > > > > > + @retval 0 Fail to initialize. > > > > > > > > > > > > +**/ > > > > > > > > > > > > +UINT8 > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +KeccakInit ( > > > > > > > > > > > > + OUT Keccak1600_Ctx *Context, > > > > > > > > > > > > + IN UINT8 Pad, > > > > > > > > > > > > + IN UINTN BlockSize, > > > > > > > > > > > > + IN UINTN MessageDigstLen > > > > > > > > > > > > + ); > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Sha3 update fuction. > > > > > > > > > > > > + > > > > > > > > > > > > + This function performs Sha3 digest on a data buffer of the s= pecified > > size. > > > > > > > > > > > > + It can be called multiple times to compute the digest of lon= g or > > > > > discontinuous > > > > > > data streams. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[in,out] Context Pointer to the Keccak context. > > > > > > > > > > > > + @param[in] Data Pointer to the buffer containing th= e data to be > > > > > hashed. > > > > > > > > > > > > + @param[in] DataSize Size of Data buffer in bytes. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval 1 Update successfully. > > > > > > > > > > > > +**/ > > > > > > > > > > > > +UINT8 > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +Sha3Update ( > > > > > > > > > > > > + IN OUT Keccak1600_Ctx *Context, > > > > > > > > > > > > + IN const VOID *Data, > > > > > > > > > > > > + IN UINTN DataSize > > > > > > > > > > > > + ); > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Completes computation of Sha3 message digest. > > > > > > > > > > > > + > > > > > > > > > > > > + This function completes sha3 hash computation and retrieves = the > > digest > > > > > value > > > > > > into > > > > > > > > > > > > + the specified memory. After this function has been called, t= he keccak > > > > > context > > > > > > cannot > > > > > > > > > > > > + be used again. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[in, out] Context Pointer to the keccak contex= t. > > > > > > > > > > > > + @param[out] MessageDigest Pointer to a buffer that rec= eives the > > > > > > message digest. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval 1 Meaasge digest computation succeeded. > > > > > > > > > > > > +**/ > > > > > > > > > > > > +UINT8 > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +Sha3Final ( > > > > > > > > > > > > + IN OUT Keccak1600_Ctx *Context, > > > > > > > > > > > > + OUT UINT8 *MessageDigest > > > > > > > > > > > > + ); > > > > > > > > > > > > + > > > > > > > > > > > > +/** > > > > > > > > > > > > + Computes the CSHAKE-256 message digest of a input data buffe= r. > > > > > > > > > > > > + > > > > > > > > > > > > + This function performs the CSHAKE-256 message digest of a gi= ven > data > > > > > buffer, > > > > > > and places > > > > > > > > > > > > + the digest value into the specified memory. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[in] Data Pointer to the buffer contai= ning the data > to > > > be > > > > > > hashed. > > > > > > > > > > > > + @param[in] DataSize Size of Data buffer in bytes= . > > > > > > > > > > > > + @param[in] OutputLen Size of output in bytes. > > > > > > > > > > > > + @param[in] Name Pointer to the function name= string. > > > > > > > > > > > > + @param[in] NameLen Size of the function name in= bytes. > > > > > > > > > > > > + @param[in] Customization Pointer to the customization= string. > > > > > > > > > > > > + @param[in] CustomizationLen Size of the customization st= ring in > > bytes. > > > > > > > > > > > > + @param[out] HashValue Pointer to a buffer that rec= eives the > > > > CSHAKE- > > > > > > 256 digest > > > > > > > > > > > > + value. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval TRUE CSHAKE-256 digest computation succeeded. > > > > > > > > > > > > + @retval FALSE CSHAKE-256 digest computation failed. > > > > > > > > > > > > + @retval FALSE This interface is not supported. > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > +BOOLEAN > > > > > > > > > > > > +EFIAPI > > > > > > > > > > > > +CShake256HashAll ( > > > > > > > > > > > > + IN CONST VOID *Data, > > > > > > > > > > > > + IN UINTN DataSize, > > > > > > > > > > > > + IN UINTN OutputLen, > > > > > > > > > > > > + IN CONST VOID *Name, > > > > > > > > > > > > + IN UINTN NameLen, > > > > > > > > > > > > + IN CONST VOID *Customization, > > > > > > > > > > > > + IN UINTN CustomizationLen, > > > > > > > > > > > > + OUT UINT8 *HashValue > > > > > > > > > > > > + ); > > > > > > > > > > > > diff --git a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf > > > > > > b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf > > > > > > index 0cab5f3ce36c..bf1563b06407 100644 > > > > > > --- a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf > > > > > > +++ b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf > > > > > > @@ -13,7 +13,7 @@ > > > > > > # PEM handler functions, and pseudorandom number generator > > functions > > > > are > > > > > > not > > > > > > > > > > > > # supported in this instance. > > > > > > > > > > > > # > > > > > > > > > > > > -# Copyright (c) 2010 - 2020, Intel Corporation. All rights re= served.
> > > > > > > > > > > > +# Copyright (c) 2010 - 2022, Intel Corporation. All rights re= served.
> > > > > > > > > > > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > # > > > > > > > > > > > > ## > > > > > > > > > > > > @@ -40,6 +40,7 @@ > > > > > > Hash/CryptSha256.c > > > > > > > > > > > > Hash/CryptSm3.c > > > > > > > > > > > > Hash/CryptSha512.c > > > > > > > > > > > > + Hash/CryptParallelHashNull.c > > > > > > > > > > > > Hmac/CryptHmacSha256.c > > > > > > > > > > > > Kdf/CryptHkdf.c > > > > > > > > > > > > Cipher/CryptAesNull.c > > > > > > > > > > > > diff --git a/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf > > > > > > b/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf > > > > > > index fdbb6edfd23e..6742da0be4fe 100644 > > > > > > --- a/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf > > > > > > +++ b/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf > > > > > > @@ -11,7 +11,7 @@ > > > > > > # functions, PKCS#7 SignedData sign functions, Diffie-Hellman > functions, > > > > and > > > > > > > > > > > > # authenticode signature verification functions are not suppo= rted in > this > > > > > > instance. > > > > > > > > > > > > # > > > > > > > > > > > > -# Copyright (c) 2009 - 2021, Intel Corporation. All rights re= served.
> > > > > > > > > > > > +# Copyright (c) 2009 - 2022, Intel Corporation. All rights re= served.
> > > > > > > > > > > > # Copyright (c) 2021, Hewlett Packard Enterprise Development = LP. All > > > rights > > > > > > reserved.
> > > > > > > > > > > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > # > > > > > > > > > > > > @@ -40,6 +40,7 @@ > > > > > > Hash/CryptSha256.c > > > > > > > > > > > > Hash/CryptSm3.c > > > > > > > > > > > > Hash/CryptSha512.c > > > > > > > > > > > > + Hash/CryptParallelHashNull.c > > > > > > > > > > > > Hmac/CryptHmacSha256.c > > > > > > > > > > > > Kdf/CryptHkdf.c > > > > > > > > > > > > Cipher/CryptAes.c > > > > > > > > > > > > diff --git a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf > > > > > > b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf > > > > > > index e6470d7a2127..8f39517f78b7 100644 > > > > > > --- a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf > > > > > > +++ b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf > > > > > > @@ -10,7 +10,7 @@ > > > > > > # RSA external functions, PKCS#7 SignedData sign functions, D= iffie- > > > Hellman > > > > > > functions, and > > > > > > > > > > > > # authenticode signature verification functions are not suppo= rted in > this > > > > > > instance. > > > > > > > > > > > > # > > > > > > > > > > > > -# Copyright (c) 2010 - 2021, Intel Corporation. All rights re= served.
> > > > > > > > > > > > +# Copyright (c) 2010 - 2022, Intel Corporation. All rights re= served.
> > > > > > > > > > > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > # > > > > > > > > > > > > ## > > > > > > > > > > > > @@ -38,6 +38,10 @@ > > > > > > Hash/CryptSha256.c > > > > > > > > > > > > Hash/CryptSm3.c > > > > > > > > > > > > Hash/CryptSha512.c > > > > > > > > > > > > + Hash/CryptSha3.c > > > > > > > > > > > > + Hash/CryptXkcp.c > > > > > > > > > > > > + Hash/CryptCShake256.c > > > > > > > > > > > > + Hash/CryptParallelHash.c > > > > > > > > > > > > Hmac/CryptHmacSha256.c > > > > > > > > > > > > Kdf/CryptHkdfNull.c > > > > > > > > > > > > Cipher/CryptAes.c > > > > > > > > > > > > @@ -85,6 +89,8 @@ > > > > > > OpensslLib > > > > > > > > > > > > IntrinsicLib > > > > > > > > > > > > PrintLib > > > > > > > > > > > > + MmServicesTableLib > > > > > > > > > > > > + SynchronizationLib > > > > > > > > > > > > > > > > > > > > > > > > # > > > > > > > > > > > > # Remove these [BuildOptions] after this library is cleaned up > > > > > > > > > > > > diff --git a/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNul= l.inf > > > > > > b/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf > > > > > > index faf959827b90..63d1d82d1914 100644 > > > > > > --- a/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf > > > > > > +++ b/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf > > > > > > @@ -6,7 +6,7 @@ > > > > > > # This external input must be validated carefully to avoid se= curity > issues > > > > such > > > > > as > > > > > > > > > > > > # buffer overflow or integer overflow. > > > > > > > > > > > > # > > > > > > > > > > > > -# Copyright (c) 2009 - 2020, Intel Corporation. All rights re= served.
> > > > > > > > > > > > +# Copyright (c) 2009 - 2022, Intel Corporation. All rights re= served.
> > > > > > > > > > > > # Copyright (c) 2020, Hewlett Packard Enterprise Development = LP. All > > > rights > > > > > > reserved.
> > > > > > > > > > > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > # > > > > > > > > > > > > @@ -34,6 +34,7 @@ > > > > > > Hash/CryptSha256Null.c > > > > > > > > > > > > Hash/CryptSha512Null.c > > > > > > > > > > > > Hash/CryptSm3Null.c > > > > > > > > > > > > + Hash/CryptParallelHashNull.c > > > > > > > > > > > > Hmac/CryptHmacSha256Null.c > > > > > > > > > > > > Kdf/CryptHkdfNull.c > > > > > > > > > > > > Cipher/CryptAesNull.c > > > > > > > > > > > > diff --git a/CryptoPkg/Library/Include/CrtLibSupport.h > > > > > > b/CryptoPkg/Library/Include/CrtLibSupport.h > > > > > > index d257dca8fa9b..b76b140a7acf 100644 > > > > > > --- a/CryptoPkg/Library/Include/CrtLibSupport.h > > > > > > +++ b/CryptoPkg/Library/Include/CrtLibSupport.h > > > > > > @@ -2,7 +2,7 @@ > > > > > > Root include file of C runtime library to support building t= he third- > party > > > > > > > > > > > > cryptographic library. > > > > > > > > > > > > > > > > > > > > > > > > -Copyright (c) 2010 - 2021, Intel Corporation. All rights reser= ved.
> > > > > > > > > > > > +Copyright (c) 2010 - 2022, Intel Corporation. All rights reser= ved.
> > > > > > > > > > > > Copyright (c) 2020, Hewlett Packard Enterprise Development LP.= All > > rights > > > > > > reserved.
> > > > > > > > > > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > > > > > > > > > > > > > @@ -111,6 +111,7 @@ typedef UINT8 u_char; > > > > > > typedef UINT32 uid_t; > > > > > > > > > > > > typedef UINT32 gid_t; > > > > > > > > > > > > typedef CHAR16 wchar_t; > > > > > > > > > > > > +typedef UINT64 uint64_t; > > > > > > > > > > > > > > > > > > > > > > > > // > > > > > > > > > > > > // File operations are not required for EFI building, > > > > > > > > > > > > diff --git a/CryptoPkg/Private/Protocol/Crypto.h > > > > > > b/CryptoPkg/Private/Protocol/Crypto.h > > > > > > index e378a8a8c60e..de45778c7d42 100644 > > > > > > --- a/CryptoPkg/Private/Protocol/Crypto.h > > > > > > +++ b/CryptoPkg/Private/Protocol/Crypto.h > > > > > > @@ -2,7 +2,7 @@ > > > > > > This Protocol provides Crypto services to DXE modules > > > > > > > > > > > > > > > > > > > > > > > > Copyright (C) Microsoft Corporation. All rights reserved. > > > > > > > > > > > > - Copyright (c) 2020 - 2021, Intel Corporation. All rights res= erved.
> > > > > > > > > > > > + Copyright (c) 2020 - 2022, Intel Corporation. All rights res= erved.
> > > > > > > > > > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > > > > > > > > > > > > > **/ > > > > > > > > > > > > @@ -21,7 +21,7 @@ > > > > > > /// the EDK II Crypto Protocol is extended, this version defin= e must be > > > > > > > > > > > > /// increased. > > > > > > > > > > > > /// > > > > > > > > > > > > -#define EDKII_CRYPTO_VERSION 7 > > > > > > > > > > > > +#define EDKII_CRYPTO_VERSION 8 > > > > > > > > > > > > > > > > > > > > > > > > /// > > > > > > > > > > > > /// EDK II Crypto Protocol forward declaration > > > > > > > > > > > > @@ -3383,6 +3383,35 @@ EFI_STATUS > > > > > > IN OUT UINTN *DataSize > > > > > > > > > > > > ); > > > > > > > > > > > > > > > > > > > > > > > > +/** > > > > > > > > > > > > + Parallel hash function ParallelHash256, as defined in NIST's= Special > > > > > Publication > > > > > > 800-185, > > > > > > > > > > > > + published December 2016. > > > > > > > > > > > > + > > > > > > > > > > > > + @param[in] Input Pointer to the input message (= X). > > > > > > > > > > > > + @param[in] InputByteLen The number(>0) of input bytes = provided > > for > > > > the > > > > > > input data. > > > > > > > > > > > > + @param[in] BlockSize The size of each block (B). > > > > > > > > > > > > + @param[out] Output Pointer to the output buffer. > > > > > > > > > > > > + @param[in] OutputByteLen The desired number of output b= ytes > (L). > > > > > > > > > > > > + @param[in] Customization Pointer to the customization s= tring (S). > > > > > > > > > > > > + @param[in] CustomByteLen The length of the customizatio= n > string > > in > > > > > bytes. > > > > > > > > > > > > + > > > > > > > > > > > > + @retval TRUE ParallelHash256 digest computation succeeded. > > > > > > > > > > > > + @retval FALSE ParallelHash256 digest computation failed. > > > > > > > > > > > > + @retval FALSE This interface is not supported. > > > > > > > > > > > > + > > > > > > > > > > > > +**/ > > > > > > > > > > > > +typedef > > > > > > > > > > > > +BOOLEAN > > > > > > > > > > > > +(EFIAPI *EDKII_CRYPTO_PARALLEL_HASH_ALL)( > > > > > > > > > > > > + IN CONST VOID *Input, > > > > > > > > > > > > + IN UINTN InputByteLen, > > > > > > > > > > > > + IN UINTN BlockSize, > > > > > > > > > > > > + OUT VOID *Output, > > > > > > > > > > > > + IN UINTN OutputByteLen, > > > > > > > > > > > > + IN CONST VOID *Customization, > > > > > > > > > > > > + IN UINTN CustomByteLen > > > > > > > > > > > > + ); > > > > > > > > > > > > + > > > > > > > > > > > > /** > > > > > > > > > > > > Carries out the RSA-SSA signature generation with EMSA-PSS > encoding > > > > > scheme. > > > > > > > > > > > > > > > > > > > > > > > > @@ -3641,6 +3670,8 @@ struct _EDKII_CRYPTO_PROTOCOL { > > > > > > EDKII_CRYPTO_TLS_GET_HOST_PUBLIC_CERT > > > TlsGetHostPublicCert; > > > > > > > > > > > > EDKII_CRYPTO_TLS_GET_HOST_PRIVATE_KEY > > > TlsGetHostPrivateKey; > > > > > > > > > > > > EDKII_CRYPTO_TLS_GET_CERT_REVOCATION_LIST > > > > > > TlsGetCertRevocationList; > > > > > > > > > > > > + /// Parallel hash > > > > > > > > > > > > + EDKII_CRYPTO_PARALLEL_HASH_ALL > > ParallelHash256HashAll; > > > > > > > > > > > > /// RSA PSS > > > > > > > > > > > > EDKII_CRYPTO_RSA_PSS_SIGN RsaPssSig= n; > > > > > > > > > > > > EDKII_CRYPTO_RSA_PSS_VERIFY RsaPssVer= ify; > > > > > > > > > > > > diff --git a/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc > > > > > > b/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc > > > > > > index ff0af36bcc80..c50a9cc4dc9f 100644 > > > > > > --- a/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc > > > > > > +++ b/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc > > > > > > @@ -2,6 +2,7 @@ > > > > > > # CryptoPkg DSC file used to build host-based unit tests. > > > > > > > > > > > > # > > > > > > > > > > > > # Copyright (c) Microsoft Corporation.
> > > > > > > > > > > > +# Copyright (c) 2022, Intel Corporation. All rights reserved.<= BR> > > > > > > > > > > > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > # > > > > > > > > > > > > ## > > > > > > > > > > > > @@ -21,6 +22,9 @@ > > > > > > [LibraryClasses] > > > > > > > > > > > > OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf > > > > > > > > > > > > > > > > > BaseCryptLib|CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf > > > > > > > > > > > > + > > > > > > > > > > > > > > > > > > > > > MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTableLib > > > > > > .inf > > > > > > > > > > > > + > > > > > > > > > > > > > > > > > > > > > SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizat= i > > > > > > onLib.inf > > > > > > > > > > > > + > > > > > > > > > > > > > > > > > > > > > TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplat > > > > > > e.inf > > > > > > > > > > > > > > > > > > > > > > > > [LibraryClasses.AARCH64, LibraryClasses.ARM] > > > > > > > > > > > > RngLib|MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf > > > > > > > > > > > > diff --git > > > > > > > > a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf > > > > > > > > b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf > > > > > > index 00c869265080..399db596c2d1 100644 > > > > > > --- > > > > a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost= .inf > > > > > > +++ > > > > > > b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf > > > > > > @@ -2,6 +2,7 @@ > > > > > > # Host-based UnitTest for BaseCryptLib > > > > > > > > > > > > # > > > > > > > > > > > > # Copyright (c) Microsoft Corporation.
> > > > > > > > > > > > +# Copyright (c) 2022, Intel Corporation. All rights reserved.<= BR> > > > > > > > > > > > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > ## > > > > > > > > > > > > > > > > > > > > > > > > @@ -35,6 +36,7 @@ > > > > > > Pkcs7EkuTests.c > > > > > > > > > > > > OaepEncryptTests.c > > > > > > > > > > > > RsaPssTests.c > > > > > > > > > > > > + ParallelhashTests.c > > > > > > > > > > > > > > > > > > > > > > > > [Packages] > > > > > > > > > > > > MdePkg/MdePkg.dec > > > > > > > > > > > > @@ -45,3 +47,5 @@ > > > > > > DebugLib > > > > > > > > > > > > BaseCryptLib > > > > > > > > > > > > UnitTestLib > > > > > > > > > > > > + MmServicesTableLib > > > > > > > > > > > > + SynchronizationLib > > > > > > > > > > > > -- > > > > > > 2.26.2.windows.1