From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web12.23288.1647237025622768180 for ; Sun, 13 Mar 2022 22:50:25 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=PHD8gz8x; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: jiewen.yao@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647237025; x=1678773025; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=0WbvkK/MAUT9tAwVtYDUFt0/IkTAJy8Ca9Yg2RPjMPA=; b=PHD8gz8xqxc9zq2DBvte4v2pXNlpeKFCHjo/xbP5xAgJeQtuPZUJ80bg H31K1GccsGgF5E2dKycC38mIueXikywfKGBgyosDK0P07lI28TCwPN9ro 8owgPTlCwZ65jhmERInrQwDbPYlgoxk+feqNvFKKqReQBGATBllTewdjL ZwGzo1/Mubb58q1i0ITEcrdvulHYnNlAMauZXGnhTObnp4Pv5l0zc5rGC xKzECtT8K6UvLGRDlx+w1NqUjVZyRCja3D7kG2fvCzloP0soIPGhRIu3Y 3KuP71ZKQwx1653LjFI1VVkWXnHKSSDuQ0mvg1KnqnF/wVW+jDH+liHdg Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10285"; a="280698724" X-IronPort-AV: E=Sophos;i="5.90,179,1643702400"; d="scan'208";a="280698724" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2022 22:50:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,179,1643702400"; d="scan'208";a="782552819" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by fmsmga006.fm.intel.com with ESMTP; 13 Mar 2022 22:50:24 -0700 Received: from orsmsx607.amr.corp.intel.com (10.22.229.20) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Sun, 13 Mar 2022 22:50:23 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx607.amr.corp.intel.com (10.22.229.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Frontend Transport; Sun, 13 Mar 2022 22:50:23 -0700 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.48) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.21; Sun, 13 Mar 2022 22:50:22 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SODJOqA0PjCAb/FY6EfrEK7rVZzKAR+/sWRUG/L38doLjGcU5/yuRa+VJn5Cq2bXYF0A09fAidR7xk5HTdnb/+MUEYmpLUms3AVuflkSaDFZ+x+LQGfDjk817bzWkFyuq9TVRJ/RZlxswBWrvHUCGacD2vyrpbgs3DdGkP90Fa7ltU/mQlqZICUV5iB/HtsJ7LplbqT5CaDQEakW0I/mfzB0XU2/MRWyRaFbGw7KW//pMx++tw1qRCD5i6x6eyFw/spZADDnFldcynKJmsOoTB5X9XqvdVxWNAdM5HkjHz7DnP+tPmbUgLNxNVJtPYlvUSn09a1aEjPppyvoaSjY4A== 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=2Sn8JBblv33mv1Pf0lKf9wPl+U4fdbb2ybqExBJSWFQ=; b=AGieWLRHPcaRrbs2JSBeEZtWS/QUXG2H9YBfPYVSAuF5nxlNqAKQAre7yTdniFy1OH6t8NnvNQCZSqwwAwsN31hNjDNZKIyseIuXW4A6gEt1s5KxjHsmtSPg4JIOB9Tq3LgqdsFjBEu6TuokHHtKNDLJ7PNFaY+TS4EEpAkK7vkOthwh/C2dwux3COnBA7iuwz4Hbgf+RzFnvdU3BM+RvY9rs3BrircFbXQFNSMsZHQ3jmPJ0mKaL8NtEMLnsZIw+cQBqloNL04WNm4Cn7A0+eLmt+Q3lQjavCDtbTDIZ11E1nhAjMJhU1oLY31u7+YsNg4Ek+dI3gt38EwghvL3UA== 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 MW4PR11MB5872.namprd11.prod.outlook.com (2603:10b6:303:169::14) by BYAPR11MB3415.namprd11.prod.outlook.com (2603:10b6:a03:81::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.25; Mon, 14 Mar 2022 05:50:19 +0000 Received: from MW4PR11MB5872.namprd11.prod.outlook.com ([fe80::752f:fdc8:905f:3fec]) by MW4PR11MB5872.namprd11.prod.outlook.com ([fe80::752f:fdc8:905f:3fec%5]) with mapi id 15.20.5061.028; Mon, 14 Mar 2022 05:50:19 +0000 From: "Yao, Jiewen" To: "devel@edk2.groups.io" , "Li, Zhihao" CC: "Wang, Jian J" , "Lu, Xiaoyu1" , "Jiang, Guomin" , "Fu, Siyuan" Subject: Re: [edk2-devel] [PATCH v5 1/1] CryptoPkg: Add new hash algorithm ParallelHash256HashAll in BaseCryptLib. Thread-Topic: [edk2-devel] [PATCH v5 1/1] CryptoPkg: Add new hash algorithm ParallelHash256HashAll in BaseCryptLib. Thread-Index: AQHYM5HkgVkA+xMsuEi9WsPx/ccLCqy+YhUw Date: Mon, 14 Mar 2022 05:50:19 +0000 Message-ID: References: <20220309084409.502-1-zhihao.li@intel.com> In-Reply-To: <20220309084409.502-1-zhihao.li@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.6.401.20 dlp-product: dlpe-windows dlp-reaction: no-action 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: 51eba85f-9312-43aa-9df8-08da057e859b x-ms-traffictypediagnostic: BYAPR11MB3415: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: MU25zDvFvVPigQ0S28Z2RAQQE0EYEVOf38PTMB0o7g2y2OcDx/A4uYtDFTBudpzqvFwfg2v4nhylw0MEcHkIhckGlXlx8kjABEFOctMGTtq6eHNs5JV7kqVGnjO9C45+sd+ZvHHewYybUdjgOICZ+/hnP0tNnTV0hs+hs4U8oOOE2MB2wOv5QwHEJS9tvlMb2Shxv3M2gBx7MYtMwaePWQ4u5DQist2n0nthFUO4Ydsarc76Q7h7xBu/knY53cD1pxuYp98VHJmqs1kLtuh3VcUWXfj5PeOjofQYkQ8YCZOXc1jQPvZsxgj6WCrQaM0PCEOJqMNMkT0O4EU/EcN7nrscsCWKqDBfaiIuJunYmOtDuj4YWcUy2iyR0abvdSc1g3QU4MU05SmL7h20LVdt7+ohkJOxFVeU5po5UWsc3qPxvY85R3HJaQ8tYj02RO7ahPqYjPYN/L5nHQt3A8G8LMU+7YfcWsIm056JjlWwuLlTQt+Amy4tIgmhbdkvC7HUZKq+ZyoSIRgA48wJAhm13cFqzlJbALIC0kufmi0nCn3mCO+rUJQwYS91WywC4qE8gdhPDnenk4KdgYzihQNOrVmsmX/1bRIgB+KnWeRMmKt9zaaFEY1BCu0dm9rQc63pvziF45YSGWsT0pmggmpCGFg4vbF1oZoAmprZ8YabeHPsdZbjhr3QfN60WJar2j7lyzyE6KIdhzN6rB3ecspAypLcb73BRgvZZ9/AdnFcmRvTqLPZiTS0ieIDRL3+mswbIHCUo8BpUfd8+pR3yHjKaL8ue2wLGiKuFapeLVZXt3/i0m5j9iS4ybMdMtf1GzSd x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR11MB5872.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(6506007)(7696005)(53546011)(76116006)(33656002)(86362001)(8936002)(8676002)(9686003)(64756008)(66476007)(66556008)(66446008)(66946007)(4326008)(71200400001)(122000001)(316002)(30864003)(107886003)(38100700002)(6636002)(110136005)(54906003)(55016003)(52536014)(83380400001)(5660300002)(2906002)(508600001)(45080400002)(38070700005)(82960400001)(966005)(26005)(19627235002)(186003)(579004)(559001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?ReI8BXd6sopCe9gKKuHH/FLOHMen6y4kX1CTGVnqntH9eTqosByWhxiZaqih?= =?us-ascii?Q?dj4rZSWeYlRD2h15dpIRMprVbCmdQve6BNDqpPDX38YMm95Zo6YFHUqw/Yxw?= =?us-ascii?Q?mwFsiJ8Ra3F0WVyTOGJJq+iDa+IVALVlVeuaWXJdR7ukXN+JkWe3u0c3vPdB?= =?us-ascii?Q?s4YFlpacNyLkyxz3NgmBUSlNwSmQlhUi37uY7hMONEHTc+oWB7+Z/NPAvu3J?= =?us-ascii?Q?CbMbPYZozR7WELH7irMrKhM0UqRnq4CoUG4HwnGG3LEvOKMsP28VwnOaK47k?= =?us-ascii?Q?sTWU0UQT1taPomxlSgWsx9DBVaDuuDpBX7ZUahFMJ3b0t9vHfgp/EuTbnQR6?= =?us-ascii?Q?IdmfVo6gZ+eN/9XVgnAbtfD0oe5FqK7D6qjjQ/J52TvJH+FIioZbSg1e2tls?= =?us-ascii?Q?6bB9ZNHaUctixgLgXOOAjRdx2WfsyHCpc3/yTgl561Wn6QY3ZE6/fFwdGhXC?= =?us-ascii?Q?dJrrZDIZFlJ28GITEAv+W982vPQoxyxnCnJVRhx4QFvMsRjG7Tr7V3fHUBeu?= =?us-ascii?Q?U1W8zMVoOtEBRHfztfG93l5i9uGK+T4ztLp6FWpQScHtcidndcqtIO29lbUP?= =?us-ascii?Q?faKfixRKagJP12A4Pqc22POBQJeJSZ2kTG9F0u/DYkrvhJZyP6GjlqA7RRFl?= =?us-ascii?Q?f9sI8/X9vrgAFJtoijbURiGmJ6tePaLz1o+qF5J+66FVDQTvvMWtK709aQcj?= =?us-ascii?Q?eCu0fQ5kZKYeUfXg8to9e+5HjA6VnICo+Ktwidmb6yBhDtjt5U/rP3uSugUx?= =?us-ascii?Q?MHUFxEktbvCNIIT6WUAirAyx1qTPDIqyTfKjWsk8TqUK0Eo86PIdnX4f54fa?= =?us-ascii?Q?5kDaXtI5rIu37hAMv43sVi3H+ImHLArBVRgHx4M7yYnZVsMy4m+mRnWOcU8Q?= =?us-ascii?Q?LyVMpVWj68YOSsJJ5DBa9QBxKETRA7T7RKb1cLLktKbxQ8cqOZhYNnmBZD3o?= =?us-ascii?Q?Qb23LNBIFnXmSOUHpYGHcvlYS7WKYkOz3vOu30MzALO9YzaW+4uGqPz8w/xv?= =?us-ascii?Q?Shx6c6zh7HlYh+JswByJdE4+6XQkYpMXwSS2KUXKCrc5CDyn1ZNUqUIEcFiK?= =?us-ascii?Q?6D5a1n6dB3bHD9w7dCsjcI/9cG81W1X+luPV5oEsqqAeDSC/lGLipdS/TweI?= =?us-ascii?Q?pEfc2zhUpY60+ZG42pMkjUfZYrx15Qfy3ci4QBezLW8ZfxrO1+wcl26UNRbT?= =?us-ascii?Q?Y1Kmaro3e1F0ZpTPqPdOk6vyiAX89bR2X45X4ojFfZ8/u956plCclVRPwVeR?= =?us-ascii?Q?YwKLjMVhd7MKq865NnmLa4y0AHb8k/IADozU1f7Aud1nyQyxE/SfCs+QL7P3?= =?us-ascii?Q?233e0R3Ni4OZIp5SwZhG6ZZr3OXSzW/63KBRmZld36Q0vBxqS/8MSoJkEMmQ?= =?us-ascii?Q?X8Csa3WOBDHArflLL4fgRBbwi7K3psWaawTVEJrqidPTZPK5rrC8Ccje7jpG?= =?us-ascii?Q?yVW9XVePWLv45mEpbD2zYvHVBhi2UBLm?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW4PR11MB5872.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51eba85f-9312-43aa-9df8-08da057e859b X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Mar 2022 05:50:19.0358 (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: vjpD//w10Dv6WEgJ0T3F8xIlt0VkAy4eygXV6fkjH5dw1W8eqLCaRr9iN8tdg2LD7Qs6Hw5NELVGC4zfULKhmw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3415 Return-Path: jiewen.yao@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thanks. It is close to final version, but there are some compatibility issu= e need to be address. 1) Whenever you add a new field in the data structure, please add it at the= end. Don't add them in the middle. E.g. PCD_CRYPTO_SERVICE_FAMILY_ENABLE, _EDKII_CRYPTO_PROTOCOL 2) Whenever you add a new field for a data structure, please remember to in= crease the version. E.g. EDKII_CRYPTO_VERSION 3) Please clarify if you have tested the CrytoLibOnProtocol version code. Thank you Yao Jiewen > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Li, Zhihao > Sent: Wednesday, March 9, 2022 4:44 PM > To: devel@edk2.groups.io > Cc: Yao, Jiewen ; Wang, Jian J ; > Lu, Xiaoyu1 ; Jiang, Guomin ; > Fu, Siyuan > Subject: [edk2-devel] [PATCH v5 1/1] CryptoPkg: Add new hash algorithm > ParallelHash256HashAll in BaseCryptLib. >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3596 >=20 > Parallel hash function ParallelHash256HashAll, as defined in NIST's > Special Publication 800-185, published December 2016. It utilizes > multi-process to calculate the digest. >=20 > Some modifications to pass CI test. >=20 > Cc: Jiewen Yao > Cc: Jian J Wang > Cc: Xiaoyu Lu > Cc: Guomin Jiang > Cc: Siyuan Fu > Cc: Zhihao Li >=20 > Signed-off-by: Zhihao Li > --- > CryptoPkg/Driver/Crypto.c | = 36 ++- > 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 | = 31 +++ > CryptoPkg/Test/CryptoPkgHostUnitTest.dsc | = 3 + > CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf | = 4 + > 22 files changed, 1422 insertions(+), 11 deletions(-) >=20 > diff --git a/CryptoPkg/Driver/Crypto.c b/CryptoPkg/Driver/Crypto.c > index d5d6aa8e5820..35312e0818a0 100644 > --- a/CryptoPkg/Driver/Crypto.c > +++ b/CryptoPkg/Driver/Crypto.c > @@ -3,7 +3,7 @@ > from BaseCryptLib and TlsLib. >=20 >=20 >=20 > Copyright (C) Microsoft Corporation. All rights reserved. >=20 > - Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.
>=20 > + Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > **/ >=20 > @@ -1314,6 +1314,38 @@ CryptoServiceSha512HashAll ( > return CALL_BASECRYPTLIB (Sha512.Services.HashAll, Sha512HashAll, (Dat= a, > DataSize, HashValue), FALSE); >=20 > } >=20 >=20 >=20 > +/** >=20 > + Parallel hash function ParallelHash256, as defined in NIST's Special P= ublication > 800-185, >=20 > + published December 2016. >=20 > + >=20 > + @param[in] Input Pointer to the input message (X). >=20 > + @param[in] InputByteLen The number(>0) of input bytes provided f= or the > input data. >=20 > + @param[in] BlockSize The size of each block (B). >=20 > + @param[out] Output Pointer to the output buffer. >=20 > + @param[in] OutputByteLen The desired number of output bytes (L). >=20 > + @param[in] Customization Pointer to the customization string (S). >=20 > + @param[in] CustomByteLen The length of the customization string i= n bytes. >=20 > + >=20 > + @retval TRUE ParallelHash256 digest computation succeeded. >=20 > + @retval FALSE ParallelHash256 digest computation failed. >=20 > + @retval FALSE This interface is not supported. >=20 > + >=20 > +**/ >=20 > +BOOLEAN >=20 > +EFIAPI >=20 > +CryptoServiceParallelHash256HashAll ( >=20 > + IN CONST VOID *Input, >=20 > + IN UINTN InputByteLen, >=20 > + IN UINTN BlockSize, >=20 > + OUT VOID *Output, >=20 > + IN UINTN OutputByteLen, >=20 > + IN CONST VOID *Customization, >=20 > + IN UINTN CustomByteLen >=20 > + ) >=20 > +{ >=20 > + return CALL_BASECRYPTLIB (ParallelHash.Services.HashAll, > ParallelHash256HashAll, (Input, InputByteLen, BlockSize, Output, OutputBy= teLen, > Customization, CustomByteLen), FALSE); >=20 > +} >=20 > + >=20 > /** >=20 > Retrieves the size, in bytes, of the context buffer required for SM3 h= ash > operations. >=20 >=20 >=20 > @@ -4590,6 +4622,8 @@ const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto =3D { > CryptoServiceSha512Update, >=20 > CryptoServiceSha512Final, >=20 > CryptoServiceSha512HashAll, >=20 > + /// Parallel hash >=20 > + CryptoServiceParallelHash256HashAll, >=20 > /// X509 >=20 > CryptoServiceX509GetSubjectName, >=20 > CryptoServiceX509GetCommonName, >=20 > diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c > b/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c > new file mode 100644 > index 000000000000..96e3c8eb02e1 > --- /dev/null > +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c > @@ -0,0 +1,282 @@ > +/** @file >=20 > + cSHAKE-256 Digest Wrapper Implementations. >=20 > + >=20 > +Copyright (c) 2022, Intel Corporation. All rights reserved.
>=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +**/ >=20 > + >=20 > +#include "CryptParallelHash.h" >=20 > + >=20 > +#define CSHAKE256_SECURITY_STRENGTH 256 >=20 > +#define CSHAKE256_RATE_IN_BYTES 136 >=20 > + >=20 > +const CHAR8 mZeroPadding[CSHAKE256_RATE_IN_BYTES] =3D { 0 }; >=20 > + >=20 > +/** >=20 > + CShake256 initial function. >=20 > + >=20 > + Initializes user-supplied memory pointed by CShake256Context as cSHAKE= -256 > hash context for >=20 > + subsequent use. >=20 > + >=20 > + @param[out] CShake256Context Pointer to cSHAKE-256 context being > initialized. >=20 > + @param[in] OutputLen The desired number of output length in b= ytes. >=20 > + @param[in] Name Pointer to the function name string. >=20 > + @param[in] NameLen The length of the function name in bytes= . >=20 > + @param[in] Customization Pointer to the customization string. >=20 > + @param[in] CustomizationLen The length of the customization string i= n > bytes. >=20 > + >=20 > + @retval TRUE cSHAKE-256 context initialization succeeded. >=20 > + @retval FALSE cSHAKE-256 context initialization failed. >=20 > + @retval FALSE This interface is not supported. >=20 > +**/ >=20 > +BOOLEAN >=20 > +EFIAPI >=20 > +CShake256Init ( >=20 > + OUT VOID *CShake256Context, >=20 > + IN UINTN OutputLen, >=20 > + IN CONST VOID *Name, >=20 > + IN UINTN NameLen, >=20 > + IN CONST VOID *Customization, >=20 > + IN UINTN CustomizationLen >=20 > + ) >=20 > +{ >=20 > + BOOLEAN Status; >=20 > + UINT8 EncBuf[sizeof (UINTN) + 1]; >=20 > + UINTN EncLen; >=20 > + UINTN AbsorbLen; >=20 > + UINTN PadLen; >=20 > + >=20 > + // >=20 > + // Check input parameters. >=20 > + // >=20 > + if ((CShake256Context =3D=3D NULL) || (OutputLen =3D=3D 0) || ((NameLe= n !=3D 0) && > (Name =3D=3D NULL)) || ((CustomizationLen !=3D 0) && (Customization =3D= =3D NULL))) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + // >=20 > + // Initialize KECCAK context with pad value and block size. >=20 > + // >=20 > + if ((NameLen =3D=3D 0) && (CustomizationLen =3D=3D 0)) { >=20 > + // >=20 > + // When N and S are both empty strings, cSHAKE(X, L, N, S) is equiva= lent to >=20 > + // SHAKE as defined in FIPS 202. >=20 > + // >=20 > + Status =3D (BOOLEAN)KeccakInit ( >=20 > + (Keccak1600_Ctx *)CShake256Context, >=20 > + '\x1f', >=20 > + (KECCAK1600_WIDTH - CSHAKE256_SECURITY_STRENGTH = * 2) / 8, >=20 > + OutputLen >=20 > + ); >=20 > + >=20 > + return Status; >=20 > + } else { >=20 > + Status =3D (BOOLEAN)KeccakInit ( >=20 > + (Keccak1600_Ctx *)CShake256Context, >=20 > + '\x04', >=20 > + (KECCAK1600_WIDTH - CSHAKE256_SECURITY_STRENGTH = * 2) / 8, >=20 > + OutputLen >=20 > + ); >=20 > + if (!Status) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + AbsorbLen =3D 0; >=20 > + // >=20 > + // Absorb Absorb bytepad(.., rate). >=20 > + // >=20 > + EncLen =3D LeftEncode (EncBuf, CSHAKE256_RATE_IN_BYTES); >=20 > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx *)CShake256Context, > EncBuf, EncLen); >=20 > + if (!Status) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + AbsorbLen +=3D EncLen; >=20 > + >=20 > + // >=20 > + // Absorb encode_string(N). >=20 > + // >=20 > + EncLen =3D LeftEncode (EncBuf, NameLen * 8); >=20 > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx *)CShake256Context, > EncBuf, EncLen); >=20 > + if (!Status) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + AbsorbLen +=3D EncLen; >=20 > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx *)CShake256Conte= xt, > Name, NameLen); >=20 > + if (!Status) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + AbsorbLen +=3D NameLen; >=20 > + >=20 > + // >=20 > + // Absorb encode_string(S). >=20 > + // >=20 > + EncLen =3D LeftEncode (EncBuf, CustomizationLen * 8); >=20 > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx *)CShake256Context, > EncBuf, EncLen); >=20 > + if (!Status) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + AbsorbLen +=3D EncLen; >=20 > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx *)CShake256Conte= xt, > Customization, CustomizationLen); >=20 > + if (!Status) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + AbsorbLen +=3D CustomizationLen; >=20 > + >=20 > + // >=20 > + // Absorb zero padding up to rate. >=20 > + // >=20 > + PadLen =3D CSHAKE256_RATE_IN_BYTES - AbsorbLen % > CSHAKE256_RATE_IN_BYTES; >=20 > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx *)CShake256Context, > mZeroPadding, PadLen); >=20 > + if (!Status) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + return TRUE; >=20 > + } >=20 > +} >=20 > + >=20 > +/** >=20 > + Digests the input data and updates cSHAKE-256 context. >=20 > + >=20 > + This function performs cSHAKE-256 digest on a data buffer of the speci= fied > size. >=20 > + It can be called multiple times to compute the digest of long or disco= ntinuous > data streams. >=20 > + cSHAKE-256 context should be already correctly initialized by CShake25= 6Init(), > and should not be finalized >=20 > + by CShake256Final(). Behavior with invalid context is undefined. >=20 > + >=20 > + @param[in, out] CShake256Context Pointer to the cSHAKE-256 context. >=20 > + @param[in] Data Pointer to the buffer containing t= he data to be > hashed. >=20 > + @param[in] DataSize Size of Data buffer in bytes. >=20 > + >=20 > + @retval TRUE cSHAKE-256 data digest succeeded. >=20 > + @retval FALSE cSHAKE-256 data digest failed. >=20 > + @retval FALSE This interface is not supported. >=20 > + >=20 > +**/ >=20 > +BOOLEAN >=20 > +EFIAPI >=20 > +CShake256Update ( >=20 > + IN OUT VOID *CShake256Context, >=20 > + IN CONST VOID *Data, >=20 > + IN UINTN DataSize >=20 > + ) >=20 > +{ >=20 > + // >=20 > + // Check input parameters. >=20 > + // >=20 > + if (CShake256Context =3D=3D NULL) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + // >=20 > + // Check invalid parameters, in case that only DataLength was checked = in > OpenSSL. >=20 > + // >=20 > + if ((Data =3D=3D NULL) && (DataSize !=3D 0)) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + return (BOOLEAN)(Sha3Update ((Keccak1600_Ctx *)CShake256Context, Data, > DataSize)); >=20 > +} >=20 > + >=20 > +/** >=20 > + Completes computation of the cSHAKE-256 digest value. >=20 > + >=20 > + This function completes cSHAKE-256 hash computation and retrieves the > digest value into >=20 > + the specified memory. After this function has been called, the cSHAKE-= 256 > context cannot >=20 > + be used again. >=20 > + cSHAKE-256 context should be already correctly initialized by CShake25= 6Init(), > and should not be >=20 > + finalized by CShake256Final(). Behavior with invalid cSHAKE-256 contex= t is > undefined. >=20 > + >=20 > + @param[in, out] CShake256Context Pointer to the cSHAKE-256 context. >=20 > + @param[out] HashValue Pointer to a buffer that receives t= he cSHAKE- > 256 digest >=20 > + value. >=20 > + >=20 > + @retval TRUE cSHAKE-256 digest computation succeeded. >=20 > + @retval FALSE cSHAKE-256 digest computation failed. >=20 > + @retval FALSE This interface is not supported. >=20 > + >=20 > +**/ >=20 > +BOOLEAN >=20 > +EFIAPI >=20 > +CShake256Final ( >=20 > + IN OUT VOID *CShake256Context, >=20 > + OUT UINT8 *HashValue >=20 > + ) >=20 > +{ >=20 > + // >=20 > + // Check input parameters. >=20 > + // >=20 > + if ((CShake256Context =3D=3D NULL) || (HashValue =3D=3D NULL)) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + // >=20 > + // cSHAKE-256 Hash Finalization. >=20 > + // >=20 > + return (BOOLEAN)(Sha3Final ((Keccak1600_Ctx *)CShake256Context, > HashValue)); >=20 > +} >=20 > + >=20 > +/** >=20 > + Computes the CSHAKE-256 message digest of a input data buffer. >=20 > + >=20 > + This function performs the CSHAKE-256 message digest of a given data b= uffer, > and places >=20 > + the digest value into the specified memory. >=20 > + >=20 > + @param[in] Data Pointer to the buffer containing the d= ata to be > hashed. >=20 > + @param[in] DataSize Size of Data buffer in bytes. >=20 > + @param[in] OutputLen Size of output in bytes. >=20 > + @param[in] Name Pointer to the function name string. >=20 > + @param[in] NameLen Size of the function name in bytes. >=20 > + @param[in] Customization Pointer to the customization string. >=20 > + @param[in] CustomizationLen Size of the customization string in by= tes. >=20 > + @param[out] HashValue Pointer to a buffer that receives the = CSHAKE- > 256 digest >=20 > + value. >=20 > + >=20 > + @retval TRUE CSHAKE-256 digest computation succeeded. >=20 > + @retval FALSE CSHAKE-256 digest computation failed. >=20 > + @retval FALSE This interface is not supported. >=20 > + >=20 > +**/ >=20 > +BOOLEAN >=20 > +EFIAPI >=20 > +CShake256HashAll ( >=20 > + IN CONST VOID *Data, >=20 > + IN UINTN DataSize, >=20 > + IN UINTN OutputLen, >=20 > + IN CONST VOID *Name, >=20 > + IN UINTN NameLen, >=20 > + IN CONST VOID *Customization, >=20 > + IN UINTN CustomizationLen, >=20 > + OUT UINT8 *HashValue >=20 > + ) >=20 > +{ >=20 > + BOOLEAN Status; >=20 > + Keccak1600_Ctx Ctx; >=20 > + >=20 > + // >=20 > + // Check input parameters. >=20 > + // >=20 > + if (HashValue =3D=3D NULL) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + if ((Data =3D=3D NULL) && (DataSize !=3D 0)) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + Status =3D CShake256Init (&Ctx, OutputLen, Name, NameLen, Customizatio= n, > CustomizationLen); >=20 > + if (!Status) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + Status =3D CShake256Update (&Ctx, Data, DataSize); >=20 > + if (!Status) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + return CShake256Final (&Ctx, HashValue); >=20 > +} >=20 > diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.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 >=20 > + ParallelHash Implementation. >=20 > + >=20 > +Copyright (c) 2022, Intel Corporation. All rights reserved.
>=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +**/ >=20 > + >=20 > +#include "CryptParallelHash.h" >=20 > +#include >=20 > +#include >=20 > + >=20 > +#define PARALLELHASH_CUSTOMIZATION "ParallelHash" >=20 > + >=20 > +UINTN mBlockNum; >=20 > +UINTN mBlockSize; >=20 > +UINTN mLastBlockSize; >=20 > +UINT8 *mInput; >=20 > +UINTN mBlockResultSize; >=20 > +UINT8 *mBlockHashResult; >=20 > +BOOLEAN *mBlockIsCompleted; >=20 > +SPIN_LOCK *mSpinLockList; >=20 > + >=20 > +/** >=20 > + Complete computation of digest of each block. >=20 > + >=20 > + Each AP perform the function called by BSP. >=20 > + >=20 > + @param[in] ProcedureArgument Argument of the procedure. >=20 > +**/ >=20 > +VOID >=20 > +EFIAPI >=20 > +ParallelHashApExecute ( >=20 > + IN VOID *ProcedureArgument >=20 > + ) >=20 > +{ >=20 > + UINTN Index; >=20 > + BOOLEAN Status; >=20 > + >=20 > + for (Index =3D 0; Index < mBlockNum; Index++) { >=20 > + if (AcquireSpinLockOrFail (&mSpinLockList[Index])) { >=20 > + // >=20 > + // Completed, try next one. >=20 > + // >=20 > + if (mBlockIsCompleted[Index]) { >=20 > + ReleaseSpinLock (&mSpinLockList[Index]); >=20 > + continue; >=20 > + } >=20 > + >=20 > + // >=20 > + // Calculate CShake256 for this block. >=20 > + // >=20 > + Status =3D CShake256HashAll ( >=20 > + mInput + Index * mBlockSize, >=20 > + (Index =3D=3D (mBlockNum - 1)) ? mLastBlockSize : mBloc= kSize, >=20 > + mBlockResultSize, >=20 > + NULL, >=20 > + 0, >=20 > + NULL, >=20 > + 0, >=20 > + mBlockHashResult + Index * mBlockResultSize >=20 > + ); >=20 > + if (!EFI_ERROR (Status)) { >=20 > + mBlockIsCompleted[Index] =3D TRUE; >=20 > + } >=20 > + >=20 > + ReleaseSpinLock (&mSpinLockList[Index]); >=20 > + } >=20 > + } >=20 > +} >=20 > + >=20 > +/** >=20 > + Dispatch the block task to each AP in SMM mode. >=20 > + >=20 > +**/ >=20 > +VOID >=20 > +EFIAPI >=20 > +MmDispatchBlockToAP ( >=20 > + VOID >=20 > + ) >=20 > +{ >=20 > + UINTN Index; >=20 > + >=20 > + for (Index =3D 0; Index < gMmst->NumberOfCpus; Index++) { >=20 > + if (Index !=3D gMmst->CurrentlyExecutingCpu) { >=20 > + gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NULL); >=20 > + } >=20 > + } >=20 > + >=20 > + return; >=20 > +} >=20 > + >=20 > +/** >=20 > + Parallel hash function ParallelHash256, as defined in NIST's Special P= ublication > 800-185, >=20 > + published December 2016. >=20 > + >=20 > + @param[in] Input Pointer to the input message (X). >=20 > + @param[in] InputByteLen The number(>0) of input bytes provided f= or the > input data. >=20 > + @param[in] BlockSize The size of each block (B). >=20 > + @param[out] Output Pointer to the output buffer. >=20 > + @param[in] OutputByteLen The desired number of output bytes (L). >=20 > + @param[in] Customization Pointer to the customization string (S). >=20 > + @param[in] CustomByteLen The length of the customization string i= n bytes. >=20 > + >=20 > + @retval TRUE ParallelHash256 digest computation succeeded. >=20 > + @retval FALSE ParallelHash256 digest computation failed. >=20 > + @retval FALSE This interface is not supported. >=20 > + >=20 > +**/ >=20 > +BOOLEAN >=20 > +EFIAPI >=20 > +ParallelHash256HashAll ( >=20 > + IN CONST VOID *Input, >=20 > + IN UINTN InputByteLen, >=20 > + IN UINTN BlockSize, >=20 > + OUT VOID *Output, >=20 > + IN UINTN OutputByteLen, >=20 > + IN CONST VOID *Customization, >=20 > + IN UINTN CustomByteLen >=20 > + ) >=20 > +{ >=20 > + UINT8 EncBufB[sizeof (UINTN)+1]; >=20 > + UINTN EncSizeB; >=20 > + UINT8 EncBufN[sizeof (UINTN)+1]; >=20 > + UINTN EncSizeN; >=20 > + UINT8 EncBufL[sizeof (UINTN)+1]; >=20 > + UINTN EncSizeL; >=20 > + UINTN Index; >=20 > + UINT8 *CombinedInput; >=20 > + UINTN CombinedInputSize; >=20 > + BOOLEAN AllCompleted; >=20 > + UINTN Offset; >=20 > + BOOLEAN ReturnValue; >=20 > + >=20 > + if ((InputByteLen =3D=3D 0) || (OutputByteLen =3D=3D 0) || (BlockSize = =3D=3D 0)) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + if ((Input =3D=3D NULL) || (Output =3D=3D NULL)) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + if ((CustomByteLen !=3D 0) && (Customization =3D=3D NULL)) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + mBlockSize =3D BlockSize; >=20 > + >=20 > + // >=20 > + // Calculate block number n. >=20 > + // >=20 > + mBlockNum =3D InputByteLen % mBlockSize =3D=3D 0 ? InputByteLen / mBlo= ckSize : > InputByteLen / mBlockSize + 1; >=20 > + >=20 > + // >=20 > + // Set hash result size of each block in bytes. >=20 > + // >=20 > + mBlockResultSize =3D OutputByteLen; >=20 > + >=20 > + // >=20 > + // Encode B, n, L to string and record size. >=20 > + // >=20 > + EncSizeB =3D LeftEncode (EncBufB, mBlockSize); >=20 > + EncSizeN =3D RightEncode (EncBufN, mBlockNum); >=20 > + EncSizeL =3D RightEncode (EncBufL, OutputByteLen * CHAR_BIT); >=20 > + >=20 > + // >=20 > + // Allocate buffer for combined input (newX), Block completed flag and > SpinLock. >=20 > + // >=20 > + CombinedInputSize =3D EncSizeB + EncSizeN + EncSizeL + mBlockNum * > mBlockResultSize; >=20 > + CombinedInput =3D AllocateZeroPool (CombinedInputSize); >=20 > + mBlockIsCompleted =3D AllocateZeroPool (mBlockNum * sizeof (BOOLEAN)); >=20 > + mSpinLockList =3D AllocatePool (mBlockNum * sizeof (SPIN_LOCK)); >=20 > + if ((CombinedInput =3D=3D NULL) || (mBlockIsCompleted =3D=3D NULL) || > (mSpinLockList =3D=3D NULL)) { >=20 > + ReturnValue =3D FALSE; >=20 > + goto Exit; >=20 > + } >=20 > + >=20 > + // >=20 > + // Fill LeftEncode(B). >=20 > + // >=20 > + CopyMem (CombinedInput, EncBufB, EncSizeB); >=20 > + >=20 > + // >=20 > + // Prepare for parallel hash. >=20 > + // >=20 > + mBlockHashResult =3D CombinedInput + EncSizeB; >=20 > + mInput =3D (UINT8 *)Input; >=20 > + mLastBlockSize =3D InputByteLen % mBlockSize =3D=3D 0 ? mBlockSize : > InputByteLen % mBlockSize; >=20 > + >=20 > + // >=20 > + // Initialize SpinLock for each result block. >=20 > + // >=20 > + for (Index =3D 0; Index < mBlockNum; Index++) { >=20 > + InitializeSpinLock (&mSpinLockList[Index]); >=20 > + } >=20 > + >=20 > + // >=20 > + // Dispatch blocklist to each AP. >=20 > + // >=20 > + if (gMmst !=3D NULL) { >=20 > + MmDispatchBlockToAP (); >=20 > + } >=20 > + >=20 > + // >=20 > + // Wait until all block hash completed. >=20 > + // >=20 > + do { >=20 > + AllCompleted =3D TRUE; >=20 > + for (Index =3D 0; Index < mBlockNum; Index++) { >=20 > + if (AcquireSpinLockOrFail (&mSpinLockList[Index])) { >=20 > + if (!mBlockIsCompleted[Index]) { >=20 > + AllCompleted =3D FALSE; >=20 > + ReturnValue =3D CShake256HashAll ( >=20 > + mInput + Index * mBlockSize, >=20 > + (Index =3D=3D (mBlockNum - 1)) ? mLastBlockSi= ze : mBlockSize, >=20 > + mBlockResultSize, >=20 > + NULL, >=20 > + 0, >=20 > + NULL, >=20 > + 0, >=20 > + mBlockHashResult + Index * mBlockResultSize >=20 > + ); >=20 > + if (ReturnValue) { >=20 > + mBlockIsCompleted[Index] =3D TRUE; >=20 > + } >=20 > + >=20 > + ReleaseSpinLock (&mSpinLockList[Index]); >=20 > + break; >=20 > + } >=20 > + >=20 > + ReleaseSpinLock (&mSpinLockList[Index]); >=20 > + } else { >=20 > + AllCompleted =3D FALSE; >=20 > + break; >=20 > + } >=20 > + } >=20 > + } while (!AllCompleted); >=20 > + >=20 > + // >=20 > + // Fill LeftEncode(n). >=20 > + // >=20 > + Offset =3D EncSizeB + mBlockNum * mBlockResultSize; >=20 > + CopyMem (CombinedInput + Offset, EncBufN, EncSizeN); >=20 > + >=20 > + // >=20 > + // Fill LeftEncode(L). >=20 > + // >=20 > + Offset +=3D EncSizeN; >=20 > + CopyMem (CombinedInput + Offset, EncBufL, EncSizeL); >=20 > + >=20 > + ReturnValue =3D CShake256HashAll ( >=20 > + CombinedInput, >=20 > + CombinedInputSize, >=20 > + OutputByteLen, >=20 > + PARALLELHASH_CUSTOMIZATION, >=20 > + AsciiStrLen (PARALLELHASH_CUSTOMIZATION), >=20 > + Customization, >=20 > + CustomByteLen, >=20 > + Output >=20 > + ); >=20 > + >=20 > +Exit: >=20 > + ZeroMem (CombinedInput, CombinedInputSize); >=20 > + >=20 > + if (CombinedInput !=3D NULL) { >=20 > + FreePool (CombinedInput); >=20 > + } >=20 > + >=20 > + if (mSpinLockList !=3D NULL) { >=20 > + FreePool ((VOID *)mSpinLockList); >=20 > + } >=20 > + >=20 > + if (mBlockIsCompleted !=3D NULL) { >=20 > + FreePool (mBlockIsCompleted); >=20 > + } >=20 > + >=20 > + return ReturnValue; >=20 > +} >=20 > 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 >=20 > + ParallelHash Implementation which does not provide real capabilities. >=20 > + >=20 > +Copyright (c) 2022, Intel Corporation. All rights reserved.
>=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +**/ >=20 > + >=20 > +#include "InternalCryptLib.h" >=20 > + >=20 > +/** >=20 > + Parallel hash function ParallelHash256, as defined in NIST's Special P= ublication > 800-185, >=20 > + published December 2016. >=20 > + >=20 > + @param[in] Input Pointer to the input message (X). >=20 > + @param[in] InputByteLen The number(>0) of input bytes provided f= or the > input data. >=20 > + @param[in] BlockSize The size of each block (B). >=20 > + @param[out] Output Pointer to the output buffer. >=20 > + @param[in] OutputByteLen The desired number of output bytes (L). >=20 > + @param[in] Customization Pointer to the customization string (S). >=20 > + @param[in] CustomByteLen The length of the customization string i= n bytes. >=20 > + >=20 > + @retval FALSE This interface is not supported. >=20 > + >=20 > +**/ >=20 > +BOOLEAN >=20 > +EFIAPI >=20 > +ParallelHash256HashAll ( >=20 > + IN CONST VOID *Input, >=20 > + IN UINTN InputByteLen, >=20 > + IN UINTN BlockSize, >=20 > + OUT VOID *Output, >=20 > + IN UINTN OutputByteLen, >=20 > + IN CONST VOID *Customization, >=20 > + IN UINTN CustomByteLen >=20 > + ) >=20 > +{ >=20 > + ASSERT (FALSE); >=20 > + return FALSE; >=20 > +} >=20 > 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 >=20 > + SHA3 realted functions from OpenSSL. >=20 > + >=20 > +Copyright (c) 2022, Intel Corporation. All rights reserved.
>=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +Copyright 2022 The OpenSSL Project Authors. All Rights Reserved. >=20 > +Licensed under the OpenSSL license (the "License"). You may not use >=20 > +this file except in compliance with the License. You can obtain a copy >=20 > +in the file LICENSE in the source distribution or at >=20 > +https://www.openssl.org/source/license.html >=20 > +**/ >=20 > + >=20 > +#include "CryptParallelHash.h" >=20 > + >=20 > +/** >=20 > + Keccak initial fuction. >=20 > + >=20 > + Set up state with specified capacity. >=20 > + >=20 > + @param[out] Context Pointer to the context being initialized= . >=20 > + @param[in] Pad Delimited Suffix. >=20 > + @param[in] BlockSize Size of context block. >=20 > + @param[in] MessageDigestLen Size of message digest in bytes. >=20 > + >=20 > + @retval 1 Initialize successfully. >=20 > + @retval 0 Fail to initialize. >=20 > +**/ >=20 > +UINT8 >=20 > +EFIAPI >=20 > +KeccakInit ( >=20 > + OUT Keccak1600_Ctx *Context, >=20 > + IN UINT8 Pad, >=20 > + IN UINTN BlockSize, >=20 > + IN UINTN MessageDigestLen >=20 > + ) >=20 > +{ >=20 > + if (BlockSize <=3D sizeof (Context->buf)) { >=20 > + memset (Context->A, 0, sizeof (Context->A)); >=20 > + >=20 > + Context->num =3D 0; >=20 > + Context->block_size =3D BlockSize; >=20 > + Context->md_size =3D MessageDigestLen; >=20 > + Context->pad =3D Pad; >=20 > + >=20 > + return 1; >=20 > + } >=20 > + >=20 > + return 0; >=20 > +} >=20 > + >=20 > +/** >=20 > + Sha3 update fuction. >=20 > + >=20 > + This function performs Sha3 digest on a data buffer of the specified s= ize. >=20 > + It can be called multiple times to compute the digest of long or disco= ntinuous > data streams. >=20 > + >=20 > + @param[in,out] Context Pointer to the Keccak context. >=20 > + @param[in] Data Pointer to the buffer containing the data to = be hashed. >=20 > + @param[in] DataSize Size of Data buffer in bytes. >=20 > + >=20 > + @retval 1 Update successfully. >=20 > +**/ >=20 > +UINT8 >=20 > +EFIAPI >=20 > +Sha3Update ( >=20 > + IN OUT Keccak1600_Ctx *Context, >=20 > + IN const VOID *Data, >=20 > + IN UINTN DataSize >=20 > + ) >=20 > +{ >=20 > + const UINT8 *DataCopy; >=20 > + UINTN BlockSize; >=20 > + UINTN Num; >=20 > + UINTN Rem; >=20 > + >=20 > + DataCopy =3D Data; >=20 > + BlockSize =3D (UINT8)(Context->block_size); >=20 > + >=20 > + if (DataSize =3D=3D 0) { >=20 > + return 1; >=20 > + } >=20 > + >=20 > + if ((Num =3D Context->num) !=3D 0) { >=20 > + // >=20 > + // process intermediate buffer >=20 > + // >=20 > + Rem =3D BlockSize - Num; >=20 > + >=20 > + if (DataSize < Rem) { >=20 > + memcpy (Context->buf + Num, DataCopy, DataSize); >=20 > + Context->num +=3D DataSize; >=20 > + return 1; >=20 > + } >=20 > + >=20 > + // >=20 > + // We have enough data to fill or overflow the intermediate >=20 > + // buffer. So we append |Rem| bytes and process the block, >=20 > + // leaving the rest for later processing. >=20 > + // >=20 > + memcpy (Context->buf + Num, DataCopy, Rem); >=20 > + DataCopy +=3D Rem; >=20 > + DataSize -=3D Rem; >=20 > + (void)SHA3_absorb (Context->A, Context->buf, BlockSize, BlockSize); >=20 > + Context->num =3D 0; >=20 > + // Context->buf is processed, Context->num is guaranteed to be zero. >=20 > + } >=20 > + >=20 > + if (DataSize >=3D BlockSize) { >=20 > + Rem =3D SHA3_absorb (Context->A, DataCopy, DataSize, BlockSize); >=20 > + } else { >=20 > + Rem =3D DataSize; >=20 > + } >=20 > + >=20 > + if (Rem > 0) { >=20 > + memcpy (Context->buf, DataCopy + DataSize - Rem, Rem); >=20 > + Context->num =3D Rem; >=20 > + } >=20 > + >=20 > + return 1; >=20 > +} >=20 > + >=20 > +/** >=20 > + Completes computation of Sha3 message digest. >=20 > + >=20 > + This function completes sha3 hash computation and retrieves the digest= value > into >=20 > + the specified memory. After this function has been called, the keccak = context > cannot >=20 > + be used again. >=20 > + >=20 > + @param[in, out] Context Pointer to the keccak context. >=20 > + @param[out] MessageDigest Pointer to a buffer that receives the > message digest. >=20 > + >=20 > + @retval 1 Meaasge digest computation succeeded. >=20 > +**/ >=20 > +UINT8 >=20 > +EFIAPI >=20 > +Sha3Final ( >=20 > + IN OUT Keccak1600_Ctx *Context, >=20 > + OUT UINT8 *MessageDigest >=20 > + ) >=20 > +{ >=20 > + UINTN BlockSize; >=20 > + UINTN Num; >=20 > + >=20 > + BlockSize =3D Context->block_size; >=20 > + Num =3D Context->num; >=20 > + >=20 > + if (Context->md_size =3D=3D 0) { >=20 > + return 1; >=20 > + } >=20 > + >=20 > + // >=20 > + // Pad the data with 10*1. Note that |Num| can be |BlockSize - 1| >=20 > + // in which case both byte operations below are performed on >=20 > + // same byte. >=20 > + // >=20 > + memset (Context->buf + Num, 0, BlockSize - Num); >=20 > + Context->buf[Num] =3D Context->pad; >=20 > + Context->buf[BlockSize - 1] |=3D 0x80; >=20 > + >=20 > + (void)SHA3_absorb (Context->A, Context->buf, BlockSize, BlockSize); >=20 > + >=20 > + SHA3_squeeze (Context->A, MessageDigest, Context->md_size, BlockSize); >=20 > + >=20 > + return 1; >=20 > +} >=20 > 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 >=20 > + Encode realted functions from Xkcp. >=20 > + >=20 > +Copyright (c) 2022, Intel Corporation. All rights reserved.
>=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +Copyright 2022 The eXtended Keccak Code Package (XKCP) >=20 > +https://github.com/XKCP/XKCP >=20 > +Keccak, designed by Guido Bertoni, Joan Daemen, Michael Peeters and Gill= es > Van Assche. >=20 > +Implementation by the designers, hereby denoted as "the implementer". >=20 > +For more information, feedback or questions, please refer to the Keccak = Team > website: >=20 > +https://keccak.team/ >=20 > +To the extent possible under law, the implementer has waived all copyrig= ht >=20 > +and related or neighboring rights to the source code in this file. >=20 > +http://creativecommons.org/publicdomain/zero/1.0/ >=20 > + >=20 > +**/ >=20 > + >=20 > +#include "CryptParallelHash.h" >=20 > + >=20 > +/** >=20 > + Encode function from XKCP. >=20 > + >=20 > + Encodes the input as a byte string in a way that can be unambiguously = parsed >=20 > + from the beginning of the string by inserting the length of the byte s= tring >=20 > + before the byte string representation of input. >=20 > + >=20 > + @param[out] EncBuf Result of left encode. >=20 > + @param[in] Value Input of left encode. >=20 > + >=20 > + @retval EncLen Size of encode result in bytes. >=20 > +**/ >=20 > +UINTN >=20 > +EFIAPI >=20 > +LeftEncode ( >=20 > + OUT UINT8 *EncBuf, >=20 > + IN UINTN Value >=20 > + ) >=20 > +{ >=20 > + UINT32 BlockNum; >=20 > + UINT32 EncLen; >=20 > + UINT32 Index; >=20 > + UINTN ValueCopy; >=20 > + >=20 > + for ( ValueCopy =3D Value, BlockNum =3D 0; ValueCopy && (BlockNum < si= zeof > (UINTN)); ++BlockNum, ValueCopy >>=3D 8 ) { >=20 > + // >=20 > + // Empty >=20 > + // >=20 > + } >=20 > + >=20 > + if (BlockNum =3D=3D 0) { >=20 > + BlockNum =3D 1; >=20 > + } >=20 > + >=20 > + for (Index =3D 1; Index <=3D BlockNum; ++Index) { >=20 > + EncBuf[Index] =3D (UINT8)(Value >> (8 * (BlockNum - Index))); >=20 > + } >=20 > + >=20 > + EncBuf[0] =3D (UINT8)BlockNum; >=20 > + EncLen =3D BlockNum + 1; >=20 > + >=20 > + return EncLen; >=20 > +} >=20 > + >=20 > +/** >=20 > + Encode function from XKCP. >=20 > + >=20 > + Encodes the input as a byte string in a way that can be unambiguously = parsed >=20 > + from the end of the string by inserting the length of the byte string = after >=20 > + the byte string representation of input. >=20 > + >=20 > + @param[out] EncBuf Result of right encode. >=20 > + @param[in] Value Input of right encode. >=20 > + >=20 > + @retval EncLen Size of encode result in bytes. >=20 > +**/ >=20 > +UINTN >=20 > +EFIAPI >=20 > +RightEncode ( >=20 > + OUT UINT8 *EncBuf, >=20 > + IN UINTN Value >=20 > + ) >=20 > +{ >=20 > + UINT32 BlockNum; >=20 > + UINT32 EncLen; >=20 > + UINT32 Index; >=20 > + UINTN ValueCopy; >=20 > + >=20 > + for (ValueCopy =3D Value, BlockNum =3D 0; ValueCopy && (BlockNum < siz= eof > (UINTN)); ++BlockNum, ValueCopy >>=3D 8) { >=20 > + // >=20 > + // Empty >=20 > + // >=20 > + } >=20 > + >=20 > + if (BlockNum =3D=3D 0) { >=20 > + BlockNum =3D 1; >=20 > + } >=20 > + >=20 > + for (Index =3D 1; Index <=3D BlockNum; ++Index) { >=20 > + EncBuf[Index-1] =3D (UINT8)(Value >> (8 * (BlockNum-Index))); >=20 > + } >=20 > + >=20 > + EncBuf[BlockNum] =3D (UINT8)BlockNum; >=20 > + EncLen =3D BlockNum + 1; >=20 > + >=20 > + return EncLen; >=20 > +} >=20 > diff --git a/CryptoPkg/Library/BaseCryptLibNull/Hash/CryptParallelHashNul= l.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 >=20 > + ParallelHash Implementation which does not provide real capabilities. >=20 > + >=20 > +Copyright (c) 2022, Intel Corporation. All rights reserved.
>=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +**/ >=20 > + >=20 > +#include "InternalCryptLib.h" >=20 > + >=20 > +/** >=20 > + Parallel hash function ParallelHash256, as defined in NIST's Special P= ublication > 800-185, >=20 > + published December 2016. >=20 > + >=20 > + @param[in] Input Pointer to the input message (X). >=20 > + @param[in] InputByteLen The number(>0) of input bytes provided f= or the > input data. >=20 > + @param[in] BlockSize The size of each block (B). >=20 > + @param[out] Output Pointer to the output buffer. >=20 > + @param[in] OutputByteLen The desired number of output bytes (L). >=20 > + @param[in] Customization Pointer to the customization string (S). >=20 > + @param[in] CustomByteLen The length of the customization string i= n bytes. >=20 > + >=20 > + @retval FALSE This interface is not supported. >=20 > + >=20 > +**/ >=20 > +BOOLEAN >=20 > +EFIAPI >=20 > +ParallelHash256HashAll ( >=20 > + IN CONST VOID *Input, >=20 > + IN UINTN InputByteLen, >=20 > + IN UINTN BlockSize, >=20 > + OUT VOID *Output, >=20 > + IN UINTN OutputByteLen, >=20 > + IN CONST VOID *Customization, >=20 > + IN UINTN CustomByteLen >=20 > + ) >=20 > +{ >=20 > + ASSERT (FALSE); >=20 > + return FALSE; >=20 > +} >=20 > diff --git a/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.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. >=20 >=20 >=20 > Copyright (C) Microsoft Corporation. All rights reserved. >=20 > - Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.
>=20 > + Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > **/ >=20 > @@ -870,6 +870,38 @@ Sha512HashAll ( > CALL_CRYPTO_SERVICE (Sha512HashAll, (Data, DataSize, HashValue), FALSE= ); >=20 > } >=20 >=20 >=20 > +/** >=20 > + Parallel hash function ParallelHash256, as defined in NIST's Special P= ublication > 800-185, >=20 > + published December 2016. >=20 > + >=20 > + @param[in] Input Pointer to the input message (X). >=20 > + @param[in] InputByteLen The number(>0) of input bytes provided f= or the > input data. >=20 > + @param[in] BlockSize The size of each block (B). >=20 > + @param[out] Output Pointer to the output buffer. >=20 > + @param[in] OutputByteLen The desired number of output bytes (L). >=20 > + @param[in] Customization Pointer to the customization string (S). >=20 > + @param[in] CustomByteLen The length of the customization string i= n bytes. >=20 > + >=20 > + @retval TRUE ParallelHash256 digest computation succeeded. >=20 > + @retval FALSE ParallelHash256 digest computation failed. >=20 > + @retval FALSE This interface is not supported. >=20 > + >=20 > +**/ >=20 > +BOOLEAN >=20 > +EFIAPI >=20 > +ParallelHash256HashAll ( >=20 > + IN CONST VOID *Input, >=20 > + IN UINTN InputByteLen, >=20 > + IN UINTN BlockSize, >=20 > + OUT VOID *Output, >=20 > + IN UINTN OutputByteLen, >=20 > + IN CONST VOID *Customization, >=20 > + IN UINTN CustomByteLen >=20 > + ) >=20 > +{ >=20 > + CALL_CRYPTO_SERVICE (ParallelHash256HashAll, (Input, InputByteLen, > BlockSize, Output, OutputByteLen, Customization, CustomByteLen), FALSE); >=20 > +} >=20 > + >=20 > /** >=20 > Retrieves the size, in bytes, of the context buffer required for SM3 h= ash > operations. >=20 >=20 >=20 > diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTes= ts.c > b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests.c > new file mode 100644 > index 000000000000..fb57e91a9f16 > --- /dev/null > +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests.c > @@ -0,0 +1,145 @@ > +/** @file >=20 > + Application for Parallelhash Function Validation. >=20 > + >=20 > +Copyright (c) 2022, Intel Corporation. All rights reserved.
>=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +**/ >=20 > + >=20 > +#include "TestBaseCryptLib.h" >=20 > + >=20 > +// >=20 > +// Parallelhash Test Sample common parameters. >=20 > +// >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINTN OutputByteLen =3D 64; >=20 > + >=20 > +// >=20 > +// Parallelhash Test Sample #1 from NIST Special Publication 800-185. >=20 > +// >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 InputSample1[] =3D { >=20 > + // input data of sample1. >=20 > + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x13= , 0x14, > 0x15, 0x16, 0x17, >=20 > + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27 >=20 > +}; >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN InputSample1ByteLen =3D 24; > // Length of sample1 input data in bytes. >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID *CustomizationSample1 > =3D ""; // Customization string (S) of sample1. >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN CustomSample1ByteLen =3D 0; > // Customization string length of sample1 in bytes. >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample1 =3D 8; > // Block size of sample1. >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 ExpectOutputSample1[] > =3D { >=20 > + // Expected output data of sample1. >=20 > + 0xbc, 0x1e, 0xf1, 0x24, 0xda, 0x34, 0x49, 0x5e, 0x94, 0x8e, 0xad, 0x20= , 0x7d, > 0xd9, 0x84, 0x22, >=20 > + 0x35, 0xda, 0x43, 0x2d, 0x2b, 0xbc, 0x54, 0xb4, 0xc1, 0x10, 0xe6, 0x4c= , 0x45, > 0x11, 0x05, 0x53, >=20 > + 0x1b, 0x7f, 0x2a, 0x3e, 0x0c, 0xe0, 0x55, 0xc0, 0x28, 0x05, 0xe7, 0xc2= , 0xde, > 0x1f, 0xb7, 0x46, >=20 > + 0xaf, 0x97, 0xa1, 0xd0, 0x01, 0xf4, 0x3b, 0x82, 0x4e, 0x31, 0xb8, 0x76= , 0x12, > 0x41, 0x04, 0x29 >=20 > +}; >=20 > + >=20 > +// >=20 > +// Parallelhash Test Sample #2 from NIST Special Publication 800-185. >=20 > +// >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 *InputSample2 =3D > InputSample1; // Input of sample2 is same as sample1. >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN InputSample2ByteLen =3D 24; > // Length of sample2 input data in bytes. >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID *CustomizationSample2 > =3D "Parallel Data"; // Customization string (S) of sample2. >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN CustomSample2ByteLen =3D > 13; // Customization string length of sample2 in = bytes. >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample2 =3D 8; > // Block size of sample2. >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 ExpectOutputSample2[] > =3D { >=20 > + // Expected output data of sample2. >=20 > + 0xcd, 0xf1, 0x52, 0x89, 0xb5, 0x4f, 0x62, 0x12, 0xb4, 0xbc, 0x27, 0x05= , 0x28, > 0xb4, 0x95, 0x26, >=20 > + 0x00, 0x6d, 0xd9, 0xb5, 0x4e, 0x2b, 0x6a, 0xdd, 0x1e, 0xf6, 0x90, 0x0d= , 0xda, > 0x39, 0x63, 0xbb, >=20 > + 0x33, 0xa7, 0x24, 0x91, 0xf2, 0x36, 0x96, 0x9c, 0xa8, 0xaf, 0xae, 0xa2= , 0x9c, > 0x68, 0x2d, 0x47, >=20 > + 0xa3, 0x93, 0xc0, 0x65, 0xb3, 0x8e, 0x29, 0xfa, 0xe6, 0x51, 0xa2, 0x09= , 0x1c, > 0x83, 0x31, 0x10 >=20 > +}; >=20 > + >=20 > +// >=20 > +// Parallelhash Test Sample #3 from NIST Special Publication 800-185. >=20 > +// >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 InputSample3[] =3D { >=20 > + // input data of sample3. >=20 > + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b= , 0x10, > 0x11, 0x12, 0x13, >=20 > + 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x20, 0x21, 0x22, 0x23= , 0x24, > 0x25, 0x26, 0x27, >=20 > + 0x28, 0x29, 0x2a, 0x2b, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37= , 0x38, > 0x39, 0x3a, 0x3b, >=20 > + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b= , 0x50, > 0x51, 0x52, 0x53, >=20 > + 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b >=20 > +}; >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN InputSample3ByteLen =3D 72; > // Length of sample3 input data in bytes. >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID *CustomizationSample3 > =3D "Parallel Data"; // Customization string (S) of sample3. >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN CustomSample3ByteLen =3D > 13; // Customization string length of sample3 in = bytes. >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample3 =3D 12; > // Block size of sample3. >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 ExpectOutputSample3[] > =3D { >=20 > + // Expected output data of sample3. >=20 > + 0x69, 0xd0, 0xfc, 0xb7, 0x64, 0xea, 0x05, 0x5d, 0xd0, 0x93, 0x34, 0xbc= , 0x60, > 0x21, 0xcb, 0x7e, >=20 > + 0x4b, 0x61, 0x34, 0x8d, 0xff, 0x37, 0x5d, 0xa2, 0x62, 0x67, 0x1c, 0xde= , 0xc3, > 0xef, 0xfa, 0x8d, >=20 > + 0x1b, 0x45, 0x68, 0xa6, 0xcc, 0xe1, 0x6b, 0x1c, 0xad, 0x94, 0x6d, 0xdd= , 0xe2, > 0x7f, 0x6c, 0xe2, >=20 > + 0xb8, 0xde, 0xe4, 0xcd, 0x1b, 0x24, 0x85, 0x1e, 0xbf, 0x00, 0xeb, 0x90= , 0xd4, > 0x38, 0x13, 0xe9 >=20 > +}; >=20 > + >=20 > +UNIT_TEST_STATUS >=20 > +EFIAPI >=20 > +TestVerifyParallelHash256HashAll ( >=20 > + IN UNIT_TEST_CONTEXT Context >=20 > + ) >=20 > +{ >=20 > + BOOLEAN Status; >=20 > + UINT8 Output[64]; >=20 > + >=20 > + // >=20 > + // Test #1 using sample1. >=20 > + // >=20 > + Status =3D ParallelHash256HashAll ( >=20 > + InputSample1, >=20 > + InputSample1ByteLen, >=20 > + BlockSizeSample1, >=20 > + Output, >=20 > + OutputByteLen, >=20 > + CustomizationSample1, >=20 > + CustomSample1ByteLen >=20 > + ); >=20 > + UT_ASSERT_TRUE (Status); >=20 > + >=20 > + // Check the output with the expected output. >=20 > + UT_ASSERT_MEM_EQUAL (Output, ExpectOutputSample1, OutputByteLen); >=20 > + >=20 > + // >=20 > + // Test #2 using sample2. >=20 > + // >=20 > + Status =3D ParallelHash256HashAll ( >=20 > + InputSample2, >=20 > + InputSample2ByteLen, >=20 > + BlockSizeSample2, >=20 > + Output, >=20 > + OutputByteLen, >=20 > + CustomizationSample2, >=20 > + CustomSample2ByteLen >=20 > + ); >=20 > + UT_ASSERT_TRUE (Status); >=20 > + >=20 > + // Check the output with the expected output. >=20 > + UT_ASSERT_MEM_EQUAL (Output, ExpectOutputSample2, OutputByteLen); >=20 > + >=20 > + // >=20 > + // Test #3 using sample3. >=20 > + // >=20 > + Status =3D ParallelHash256HashAll ( >=20 > + InputSample3, >=20 > + InputSample3ByteLen, >=20 > + BlockSizeSample3, >=20 > + Output, >=20 > + OutputByteLen, >=20 > + CustomizationSample3, >=20 > + CustomSample3ByteLen >=20 > + ); >=20 > + UT_ASSERT_TRUE (Status); >=20 > + >=20 > + // Check the output with the expected output. >=20 > + UT_ASSERT_MEM_EQUAL (Output, ExpectOutputSample3, OutputByteLen); >=20 > + >=20 > + return EFI_SUCCESS; >=20 > +} >=20 > + >=20 > +TEST_DESC mParallelhashTest[] =3D { >=20 > + // >=20 > + // -----Description------------------------------Class----------------= ------Function---- > -------------Pre---Post--Context >=20 > + // >=20 > + { "TestVerifyParallelHash256HashAll()", > "CryptoPkg.BaseCryptLib.ParallelHash256HashAll", > TestVerifyParallelHash256HashAll, NULL, NULL, NULL }, >=20 > +}; >=20 > + >=20 > +UINTN mParallelhashTestNum =3D ARRAY_SIZE (mParallelhashTest); >=20 > 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 >=20 > # >=20 > # Copyright (c) Microsoft Corporation >=20 > -# Copyright (c) 2020, Intel Corporation. All rights reserved.
>=20 > +# Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.
>=20 > # SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > ## >=20 > { >=20 > @@ -34,6 +34,8 @@ > "Library/OpensslLib/rand_pool.c", >=20 > # This has OpenSSL interfaces that aren't UEFI spec complian= t >=20 > "Library/Include/CrtLibSupport.h", >=20 > + # This has OpenSSL interfaces that aren't UEFI spec complian= t >=20 > + "Library/BaseCryptLib/Hash/CryptParallelHash.h", >=20 > # These directories contain auto-generated OpenSSL content >=20 > "Library/OpensslLib", >=20 > "Library/IntrinsicLib", >=20 > 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) for UEFI sec= urity >=20 > functionality enabling. >=20 >=20 >=20 > -Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.
>=20 > +Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > **/ >=20 > @@ -753,6 +753,35 @@ Sha512HashAll ( > OUT UINT8 *HashValue >=20 > ); >=20 >=20 >=20 > +/** >=20 > + Parallel hash function ParallelHash256, as defined in NIST's Special P= ublication > 800-185, >=20 > + published December 2016. >=20 > + >=20 > + @param[in] Input Pointer to the input message (X). >=20 > + @param[in] InputByteLen The number(>0) of input bytes provided f= or the > input data. >=20 > + @param[in] BlockSize The size of each block (B). >=20 > + @param[out] Output Pointer to the output buffer. >=20 > + @param[in] OutputByteLen The desired number of output bytes (L). >=20 > + @param[in] Customization Pointer to the customization string (S). >=20 > + @param[in] CustomByteLen The length of the customization string i= n bytes. >=20 > + >=20 > + @retval TRUE ParallelHash256 digest computation succeeded. >=20 > + @retval FALSE ParallelHash256 digest computation failed. >=20 > + @retval FALSE This interface is not supported. >=20 > + >=20 > +**/ >=20 > +BOOLEAN >=20 > +EFIAPI >=20 > +ParallelHash256HashAll ( >=20 > + IN CONST VOID *Input, >=20 > + IN UINTN InputByteLen, >=20 > + IN UINTN BlockSize, >=20 > + OUT VOID *Output, >=20 > + IN UINTN OutputByteLen, >=20 > + IN CONST VOID *Customization, >=20 > + IN UINTN CustomByteLen >=20 > + ); >=20 > + >=20 > /** >=20 > Retrieves the size, in bytes, of the context buffer required for SM3 h= ash > operations. >=20 >=20 >=20 > diff --git a/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h > b/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h > index 5186a54759ae..0b30a821bc16 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 >=20 > gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable. >=20 >=20 >=20 > - Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.
>=20 > + Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > **/ >=20 > @@ -172,6 +172,12 @@ typedef struct { > } Services; >=20 > UINT32 Family; >=20 > } Sha512; >=20 > + union { >=20 > + struct { >=20 > + UINT8 HashAll : 1; >=20 > + } Services; >=20 > + UINT32 Family; >=20 > + } ParallelHash; >=20 > union { >=20 > struct { >=20 > UINT8 GetSubjectName : 1; >=20 > 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 security iss= ues such as >=20 > # buffer overflow or integer overflow. >=20 > # >=20 > -# Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved. >=20 > +# Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved. >=20 > # Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All ri= ghts > reserved.
>=20 > # SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > # >=20 > @@ -34,6 +34,7 @@ > Hash/CryptSha256.c >=20 > Hash/CryptSha512.c >=20 > Hash/CryptSm3.c >=20 > + Hash/CryptParallelHashNull.c >=20 > Hmac/CryptHmacSha256.c >=20 > Kdf/CryptHkdf.c >=20 > Cipher/CryptAes.c >=20 > diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.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 >=20 > + ParallelHash related function and type declaration. >=20 > + >=20 > +Copyright (c) 2022, Intel Corporation. All rights reserved.
>=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +Copyright 2022 The OpenSSL Project Authors. All Rights Reserved. >=20 > +Licensed under the OpenSSL license (the "License"). You may not use >=20 > +this file except in compliance with the License. You can obtain a copy >=20 > +in the file LICENSE in the source distribution or at >=20 > +https://www.openssl.org/source/license.html >=20 > + >=20 > +Copyright 2022 The eXtended Keccak Code Package (XKCP) >=20 > +https://github.com/XKCP/XKCP >=20 > +Keccak, designed by Guido Bertoni, Joan Daemen, Michael Peeters and Gill= es > Van Assche. >=20 > +Implementation by the designers, hereby denoted as "the implementer". >=20 > +For more information, feedback or questions, please refer to the Keccak = Team > website: >=20 > +https://keccak.team/ >=20 > +To the extent possible under law, the implementer has waived all copyrig= ht >=20 > +and related or neighboring rights to the source code in this file. >=20 > +http://creativecommons.org/publicdomain/zero/1.0/ >=20 > +**/ >=20 > + >=20 > +#include "InternalCryptLib.h" >=20 > + >=20 > +#define KECCAK1600_WIDTH 1600 >=20 > + >=20 > +// >=20 > +// This struct referring to m_sha3.c from opessl and modified its type n= ame. >=20 > +// >=20 > +typedef struct { >=20 > + uint64_t A[5][5]; >=20 > + size_t block_size; /* cached ctx->digest->block_size */ >=20 > + size_t md_size; /* output length, variable in XOF */ >=20 > + size_t num; /* used bytes in below buffer */ >=20 > + unsigned char buf[KECCAK1600_WIDTH / 8 - 32]; >=20 > + unsigned char pad; >=20 > +} Keccak1600_Ctx; >=20 > + >=20 > +/** >=20 > + SHA3_absorb can be called multiple times, but at each invocation >=20 > + largest multiple of |r| out of |len| bytes are processed. Then >=20 > + remaining amount of bytes is returned. This is done to spare caller >=20 > + trouble of calculating the largest multiple of |r|. |r| can be viewed >=20 > + as blocksize. It is commonly (1600 - 256*n)/8, e.g. 168, 136, 104, >=20 > + 72, but can also be (1600 - 448)/8 =3D 144. All this means that messag= e >=20 > + padding and intermediate sub-block buffering, byte- or bitwise, is >=20 > + caller's responsibility. >=20 > +**/ >=20 > +size_t >=20 > +SHA3_absorb ( >=20 > + uint64_t A[5][5], >=20 > + const unsigned char *inp, >=20 > + size_t len, >=20 > + size_t r >=20 > + ); >=20 > + >=20 > +/** >=20 > + SHA3_squeeze is called once at the end to generate |out| hash value >=20 > + of |len| bytes. >=20 > +**/ >=20 > +void >=20 > +SHA3_squeeze ( >=20 > + uint64_t A[5][5], >=20 > + unsigned char *out, >=20 > + size_t len, >=20 > + size_t r >=20 > + ); >=20 > + >=20 > +/** >=20 > + Encode function from XKCP. >=20 > + >=20 > + Encodes the input as a byte string in a way that can be unambiguously = parsed >=20 > + from the beginning of the string by inserting the length of the byte s= tring >=20 > + before the byte string representation of input. >=20 > + >=20 > + @param[out] EncBuf Result of left encode. >=20 > + @param[in] Value Input of left encode. >=20 > + >=20 > + @retval EncLen Size of encode result in bytes. >=20 > +**/ >=20 > +UINTN >=20 > +EFIAPI >=20 > +LeftEncode ( >=20 > + OUT UINT8 *EncBuf, >=20 > + IN UINTN Value >=20 > + ); >=20 > + >=20 > +/** >=20 > + Encode function from XKCP. >=20 > + >=20 > + Encodes the input as a byte string in a way that can be unambiguously = parsed >=20 > + from the end of the string by inserting the length of the byte string = after >=20 > + the byte string representation of input. >=20 > + >=20 > + @param[out] EncBuf Result of right encode. >=20 > + @param[in] Value Input of right encode. >=20 > + >=20 > + @retval EncLen Size of encode result in bytes. >=20 > +**/ >=20 > +UINTN >=20 > +EFIAPI >=20 > +RightEncode ( >=20 > + OUT UINT8 *EncBuf, >=20 > + IN UINTN Value >=20 > + ); >=20 > + >=20 > +/** >=20 > + Keccak initial fuction. >=20 > + >=20 > + Set up state with specified capacity. >=20 > + >=20 > + @param[out] Context Pointer to the context being initialized= . >=20 > + @param[in] Pad Delimited Suffix. >=20 > + @param[in] BlockSize Size of context block. >=20 > + @param[in] MessageDigestLen Size of message digest in bytes. >=20 > + >=20 > + @retval 1 Initialize successfully. >=20 > + @retval 0 Fail to initialize. >=20 > +**/ >=20 > +UINT8 >=20 > +EFIAPI >=20 > +KeccakInit ( >=20 > + OUT Keccak1600_Ctx *Context, >=20 > + IN UINT8 Pad, >=20 > + IN UINTN BlockSize, >=20 > + IN UINTN MessageDigstLen >=20 > + ); >=20 > + >=20 > +/** >=20 > + Sha3 update fuction. >=20 > + >=20 > + This function performs Sha3 digest on a data buffer of the specified s= ize. >=20 > + It can be called multiple times to compute the digest of long or disco= ntinuous > data streams. >=20 > + >=20 > + @param[in,out] Context Pointer to the Keccak context. >=20 > + @param[in] Data Pointer to the buffer containing the data to = be hashed. >=20 > + @param[in] DataSize Size of Data buffer in bytes. >=20 > + >=20 > + @retval 1 Update successfully. >=20 > +**/ >=20 > +UINT8 >=20 > +EFIAPI >=20 > +Sha3Update ( >=20 > + IN OUT Keccak1600_Ctx *Context, >=20 > + IN const VOID *Data, >=20 > + IN UINTN DataSize >=20 > + ); >=20 > + >=20 > +/** >=20 > + Completes computation of Sha3 message digest. >=20 > + >=20 > + This function completes sha3 hash computation and retrieves the digest= value > into >=20 > + the specified memory. After this function has been called, the keccak = context > cannot >=20 > + be used again. >=20 > + >=20 > + @param[in, out] Context Pointer to the keccak context. >=20 > + @param[out] MessageDigest Pointer to a buffer that receives the > message digest. >=20 > + >=20 > + @retval 1 Meaasge digest computation succeeded. >=20 > +**/ >=20 > +UINT8 >=20 > +EFIAPI >=20 > +Sha3Final ( >=20 > + IN OUT Keccak1600_Ctx *Context, >=20 > + OUT UINT8 *MessageDigest >=20 > + ); >=20 > + >=20 > +/** >=20 > + Computes the CSHAKE-256 message digest of a input data buffer. >=20 > + >=20 > + This function performs the CSHAKE-256 message digest of a given data b= uffer, > and places >=20 > + the digest value into the specified memory. >=20 > + >=20 > + @param[in] Data Pointer to the buffer containing the d= ata to be > hashed. >=20 > + @param[in] DataSize Size of Data buffer in bytes. >=20 > + @param[in] OutputLen Size of output in bytes. >=20 > + @param[in] Name Pointer to the function name string. >=20 > + @param[in] NameLen Size of the function name in bytes. >=20 > + @param[in] Customization Pointer to the customization string. >=20 > + @param[in] CustomizationLen Size of the customization string in by= tes. >=20 > + @param[out] HashValue Pointer to a buffer that receives the = CSHAKE- > 256 digest >=20 > + value. >=20 > + >=20 > + @retval TRUE CSHAKE-256 digest computation succeeded. >=20 > + @retval FALSE CSHAKE-256 digest computation failed. >=20 > + @retval FALSE This interface is not supported. >=20 > + >=20 > +**/ >=20 > +BOOLEAN >=20 > +EFIAPI >=20 > +CShake256HashAll ( >=20 > + IN CONST VOID *Data, >=20 > + IN UINTN DataSize, >=20 > + IN UINTN OutputLen, >=20 > + IN CONST VOID *Name, >=20 > + IN UINTN NameLen, >=20 > + IN CONST VOID *Customization, >=20 > + IN UINTN CustomizationLen, >=20 > + OUT UINT8 *HashValue >=20 > + ); >=20 > 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 ar= e > not >=20 > # supported in this instance. >=20 > # >=20 > -# Copyright (c) 2010 - 2020, Intel Corporation. All rights reserved. >=20 > +# Copyright (c) 2010 - 2022, Intel Corporation. All rights reserved. >=20 > # SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > # >=20 > ## >=20 > @@ -40,6 +40,7 @@ > Hash/CryptSha256.c >=20 > Hash/CryptSm3.c >=20 > Hash/CryptSha512.c >=20 > + Hash/CryptParallelHashNull.c >=20 > Hmac/CryptHmacSha256.c >=20 > Kdf/CryptHkdf.c >=20 > Cipher/CryptAesNull.c >=20 > 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 >=20 > # authenticode signature verification functions are not supported in th= is > instance. >=20 > # >=20 > -# Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved. >=20 > +# Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved. >=20 > # Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All ri= ghts > reserved.
>=20 > # SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > # >=20 > @@ -40,6 +40,7 @@ > Hash/CryptSha256.c >=20 > Hash/CryptSm3.c >=20 > Hash/CryptSha512.c >=20 > + Hash/CryptParallelHashNull.c >=20 > Hmac/CryptHmacSha256.c >=20 > Kdf/CryptHkdf.c >=20 > Cipher/CryptAes.c >=20 > 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, Diffie-Hell= man > functions, and >=20 > # authenticode signature verification functions are not supported in th= is > instance. >=20 > # >=20 > -# Copyright (c) 2010 - 2021, Intel Corporation. All rights reserved. >=20 > +# Copyright (c) 2010 - 2022, Intel Corporation. All rights reserved. >=20 > # SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > # >=20 > ## >=20 > @@ -38,6 +38,10 @@ > Hash/CryptSha256.c >=20 > Hash/CryptSm3.c >=20 > Hash/CryptSha512.c >=20 > + Hash/CryptSha3.c >=20 > + Hash/CryptXkcp.c >=20 > + Hash/CryptCShake256.c >=20 > + Hash/CryptParallelHash.c >=20 > Hmac/CryptHmacSha256.c >=20 > Kdf/CryptHkdfNull.c >=20 > Cipher/CryptAes.c >=20 > @@ -85,6 +89,8 @@ > OpensslLib >=20 > IntrinsicLib >=20 > PrintLib >=20 > + MmServicesTableLib >=20 > + SynchronizationLib >=20 >=20 >=20 > # >=20 > # Remove these [BuildOptions] after this library is cleaned up >=20 > diff --git a/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.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 security iss= ues such as >=20 > # buffer overflow or integer overflow. >=20 > # >=20 > -# Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved. >=20 > +# Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved. >=20 > # Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All ri= ghts > reserved.
>=20 > # SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > # >=20 > @@ -34,6 +34,7 @@ > Hash/CryptSha256Null.c >=20 > Hash/CryptSha512Null.c >=20 > Hash/CryptSm3Null.c >=20 > + Hash/CryptParallelHashNull.c >=20 > Hmac/CryptHmacSha256Null.c >=20 > Kdf/CryptHkdfNull.c >=20 > Cipher/CryptAesNull.c >=20 > 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 the third-p= arty >=20 > cryptographic library. >=20 >=20 >=20 > -Copyright (c) 2010 - 2021, Intel Corporation. All rights reserved.
>=20 > +Copyright (c) 2010 - 2022, Intel Corporation. All rights reserved.
>=20 > Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All right= s > reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > @@ -111,6 +111,7 @@ typedef UINT8 u_char; > typedef UINT32 uid_t; >=20 > typedef UINT32 gid_t; >=20 > typedef CHAR16 wchar_t; >=20 > +typedef UINT64 uint64_t; >=20 >=20 >=20 > // >=20 > // File operations are not required for EFI building, >=20 > diff --git a/CryptoPkg/Private/Protocol/Crypto.h > b/CryptoPkg/Private/Protocol/Crypto.h > index e378a8a8c60e..d51fc4a0e2cc 100644 > --- a/CryptoPkg/Private/Protocol/Crypto.h > +++ b/CryptoPkg/Private/Protocol/Crypto.h > @@ -1905,6 +1905,35 @@ BOOLEAN > OUT UINT8 *HashValue >=20 > ); >=20 >=20 >=20 > +/** >=20 > + Parallel hash function ParallelHash256, as defined in NIST's Special P= ublication > 800-185, >=20 > + published December 2016. >=20 > + >=20 > + @param[in] Input Pointer to the input message (X). >=20 > + @param[in] InputByteLen The number(>0) of input bytes provided f= or the > input data. >=20 > + @param[in] BlockSize The size of each block (B). >=20 > + @param[out] Output Pointer to the output buffer. >=20 > + @param[in] OutputByteLen The desired number of output bytes (L). >=20 > + @param[in] Customization Pointer to the customization string (S). >=20 > + @param[in] CustomByteLen The length of the customization string i= n bytes. >=20 > + >=20 > + @retval TRUE ParallelHash256 digest computation succeeded. >=20 > + @retval FALSE ParallelHash256 digest computation failed. >=20 > + @retval FALSE This interface is not supported. >=20 > + >=20 > +**/ >=20 > +typedef >=20 > +BOOLEAN >=20 > +(EFIAPI *EDKII_CRYPTO_PARALLEL_HASH_ALL)( >=20 > + IN CONST VOID *Input, >=20 > + IN UINTN InputByteLen, >=20 > + IN UINTN BlockSize, >=20 > + OUT VOID *Output, >=20 > + IN UINTN OutputByteLen, >=20 > + IN CONST VOID *Customization, >=20 > + IN UINTN CustomByteLen >=20 > + ); >=20 > + >=20 > // ---------------------------------------------------------------------= ------- >=20 > // X509 >=20 > // ---------------------------------------------------------------------= ------- >=20 > @@ -3560,6 +3589,8 @@ struct _EDKII_CRYPTO_PROTOCOL { > EDKII_CRYPTO_SHA512_UPDATE Sha512Update; >=20 > EDKII_CRYPTO_SHA512_FINAL Sha512Final; >=20 > EDKII_CRYPTO_SHA512_HASH_ALL Sha512HashAll; >=20 > + /// Parallel hash >=20 > + EDKII_CRYPTO_PARALLEL_HASH_ALL ParallelHash256Hash= All; >=20 > /// X509 >=20 > EDKII_CRYPTO_X509_GET_SUBJECT_NAME X509GetSubjectName; >=20 > EDKII_CRYPTO_X509_GET_COMMON_NAME X509GetCommonName; >=20 > diff --git a/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc > b/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc > index ff0af36bcc80..ba6e1edb6015 100644 > --- a/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc > +++ b/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc > @@ -21,6 +21,9 @@ > [LibraryClasses] >=20 > OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf >=20 > BaseCryptLib|CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.i= nf >=20 > + > MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTableLib > .inf >=20 > + > SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizat= i > onLib.inf >=20 > + > TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplat > e.inf >=20 >=20 >=20 > [LibraryClasses.AARCH64, LibraryClasses.ARM] >=20 > RngLib|MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf >=20 > 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.i= nf > +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.i= nf > @@ -2,6 +2,7 @@ > # Host-based UnitTest for BaseCryptLib >=20 > # >=20 > # Copyright (c) Microsoft Corporation.
>=20 > +# Copyright (c) 2022, Intel Corporation. All rights reserved.
>=20 > # SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > ## >=20 >=20 >=20 > @@ -35,6 +36,7 @@ > Pkcs7EkuTests.c >=20 > OaepEncryptTests.c >=20 > RsaPssTests.c >=20 > + ParallelhashTests.c >=20 >=20 >=20 > [Packages] >=20 > MdePkg/MdePkg.dec >=20 > @@ -45,3 +47,5 @@ > DebugLib >=20 > BaseCryptLib >=20 > UnitTestLib >=20 > + MmServicesTableLib >=20 > + SynchronizationLib >=20 > -- > 2.26.2.windows.1 >=20 >=20 >=20 > -=3D-=3D-=3D-=3D-=3D-=3D > Groups.io Links: You receive all messages sent to this group. > View/Reply Online (#87382): https://edk2.groups.io/g/devel/message/87382 > Mute This Topic: https://groups.io/mt/89658124/1772286 > Group Owner: devel+owner@edk2.groups.io > Unsubscribe: https://edk2.groups.io/g/devel/unsub [jiewen.yao@intel.com] > -=3D-=3D-=3D-=3D-=3D-=3D >=20