From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.5804.1647485020022692473 for ; Wed, 16 Mar 2022 19:43:40 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=BmNmEXzp; spf=pass (domain: intel.com, ip: 134.134.136.100, 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=1647485020; x=1679021020; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=FO6mMFl+ZGkaC+tsez5IJnxJcP7Gr6mKTfR2Wk2ERQs=; b=BmNmEXzphoxw/vyidd+BHST0CvpS6fb5CIIrn4tYsQipRf2MebIo+uR+ afyEPNTKQLjNKc4RQivO9mrQKioSLHiBN9MASbKC4KkYBF9TyPDrhMhju M03cJKkawIX/YUXM5kuOQltiOhJIbUVQlqhdXptD6KL07cTOnQNM4mO2j SbWU4zIMuDsLLy5HpXpLWFwXw0bEti4WQ8bHGMLX2C9myeq5w3OOU/m9x QYjKaMPq5g6QDVdgGPX3l93O7CKidqbXFCOtsxOKMyEq2yZZWcNmZN1UG horVhmLetGEiqLBgydISFNzSZvhVbFQaLRFtb52GXM4XY6jT8u3t9zjAY g==; X-IronPort-AV: E=McAfee;i="6200,9189,10288"; a="319978050" X-IronPort-AV: E=Sophos;i="5.90,188,1643702400"; d="scan'208";a="319978050" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2022 19:43:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,188,1643702400"; d="scan'208";a="635215931" Received: from fmsmsx604.amr.corp.intel.com ([10.18.126.84]) by FMSMGA003.fm.intel.com with ESMTP; 16 Mar 2022 19:43:38 -0700 Received: from fmsmsx608.amr.corp.intel.com (10.18.126.88) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 16 Mar 2022 19:43:38 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx608.amr.corp.intel.com (10.18.126.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 16 Mar 2022 19:43:37 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Frontend Transport; Wed, 16 Mar 2022 19:43:37 -0700 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.174) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.21; Wed, 16 Mar 2022 19:43:36 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E5U5fmCX9nzhafkZ7HeCEQYXdUneNbKk+jt7aWsPwEjarOWcPuIqYCN7E+jj6OFDldbIo5gxFW3DTWoadzLnXHSJ5MPV6bu+Z360uCDDr3lZD4FTx8ngXoFugSiIwt3GtduEwrjJ4bmFGXaaN3V+Ls9EE88LslOMVdjskSHnm1IK/pPe7RFm6zp5r16QE7XHfUhh59GiAgJp0rI+i06RgvriCE4eAbqetmDdp+GiEH2CUbC2686+WUHBDgCrU3055hYnj1WUiK8FnowRJCfMgwX+evPAflYyZ9IL12sS5k5RokznChwDtoLWq4S8ACcerPFgSMgOWlGiABctg4/xTw== 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=xS5jd1FzA33gOlx5+7JGPbra7SCOeO+9JSya05lSBP8=; b=hGZqSsMNtzMtDerFXWzlhhDBvxX90eVXjgKbWlSidbYDCxHICieA6NBfxnWCyOjGPkVnNUtUSad19WQsYdF3wz6ZCsqLUK7TH5aLdqBBv0VHs/T8ewtv7Ak/52GM+MQaj5Pety0WRYiRt7tehE6PYUuhmqsmU9xfdtmPH98ByBdkwdp4KhgbDRYvtVI2riGwfPSZggQxNJO+vMvDFmPhF/7UJyjw+dkfLdUDMqJmice/d/mJGtovEu005r3RjUxfEnetcGA1FsFMrfqLVb1E/astFSu9HJQcWsqhb5E+pFriirPAMAMm9pr2+2lmzltUzZzyy92hSIwwYaIbUodxUQ== 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 BN6PR11MB2034.namprd11.prod.outlook.com (2603:10b6:404:43::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.14; Thu, 17 Mar 2022 02:43:29 +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.014; Thu, 17 Mar 2022 02:43:29 +0000 From: "Li, Zhihao" To: "Yao, Jiewen" , "devel@edk2.groups.io" 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+YhUwgASDgDA= Date: Thu, 17 Mar 2022 02:43:29 +0000 Message-ID: References: <20220309084409.502-1-zhihao.li@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.6.401.20 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: ebef2cc4-d147-4f87-4c44-08da07bfeb9a x-ms-traffictypediagnostic: BN6PR11MB2034: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: jbiKkgmN9qgeCj0mm+oqA7SA4v3kVUXRTQ8C5tzj/zOLRtcmVVGKAGF/9XFsb8IHe1kFVb2P9k8CTpaxLDW9SGeUTlrvztgWIj790P2Nbq/r9IbzgQQU2ylsJ4RrlVb3t+kZ/jELKbOhJ2Ofu6Am9hGxzeTKoencR88fnhPm86DWqLKHWEHwcujhPgRx/5GXOSo7b6BdAhZUNqBaY55kimyRj+2SLxbl3k1u6X8mdJFxwXDe++I8iCdyo1vfHE2Xc8+j5o39QEN1XoaocXhJ5jG61b7tYsBU+RDGNLChpts/5VGdc9J0HMGTmekfxU8awc156Jnge/zGS7aN/uCCYfvhOFLsVU2AtJvQ0M7qaf77CkrVkMKgSa06Atqshe45HNCXmtSGhHr7HsatP1Js/IfB+5ZLKChA7e/3DfcptxsojvRkdfmPyIlKpO4+g+HiYCoGfo1S1HToxMCbhWm284ZPek9HKZnWh0I4HSnfyKXm4/Ca3cK/cKzDFZHIajR+CttRu+vIJBjGXXKASuWzVYrfUUk2mUNkc8AigfMQQqfw7VyJLBDVkfdEWdBAMlbEt1ckQXdpb1t0u+x1iyPXUCMZVEZmuOXVwKS+AOQfa3yOYq8Vdgp5Zy2CGhfDPbZEsmHI/6EDNdg+O9w7LWm8mUQaTAlQSRptL0uS8HCTsaFvputtjE57OyFQ5f1KAOWoRNgOen334jggunyrcTsLwQy25KPRgvy5K+TTzrkNqIykdwoA32nmAkjun1PPGCxaDv96kwjHjIV7mmnC1T9B1IHwXldm2z8Y7qvgjzW4o2qnOL8hCn2I8iVttWBlUwbd 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)(38070700005)(9686003)(83380400001)(26005)(8936002)(186003)(86362001)(30864003)(5660300002)(508600001)(71200400001)(2906002)(82960400001)(53546011)(7696005)(966005)(122000001)(52536014)(6506007)(45080400002)(76116006)(8676002)(66446008)(66476007)(66556008)(66946007)(64756008)(4326008)(33656002)(110136005)(54906003)(55016003)(316002)(19627235002)(107886003)(38100700002)(579004)(559001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?PkVIq66RrgsZ02ir01m5BByrBMRBNR6yOCncKqshHNAH3B6q+HDEYvvsLqox?= =?us-ascii?Q?dR6dYX2I/74wE/hLsZP8j0ln4pwGqLKUk2Mdk8eStOvTDmR1lYJJZUFMCBSb?= =?us-ascii?Q?+N3QN6KwFS69FeopYQ9i77Ho4cOeS6iIpRTgovG1tA4H+dVlblS/pApb9+JB?= =?us-ascii?Q?dT6MscHNEytHdG7bXCfSZZQJ5eEXQ34Udc+FRtHZTRhUME9BUJcXTJ9sgteG?= =?us-ascii?Q?bngLxv8biFn4gmmb3lhDJ1M1VN473pF4g392AEEntaZLq7GIwa17QAbEJrQK?= =?us-ascii?Q?uXiWap+DRF/xQq4xMOUY4sVNMsd7Vh0Yav9P/ggduM3pembhY2exh0SJ4o9h?= =?us-ascii?Q?MYCdUKAXdhAwer7yyxwgSkMDmWlydhPzamZpP6WloVS08rYh8pB4PjOcf81L?= =?us-ascii?Q?CtA9/7LD+z+SdKdLQSDz095R1+5PW9KlJa7CxWqEm46Y606bnnWxO6M2sAHH?= =?us-ascii?Q?4x5UEuFsbgejJ21d9pa1WSCdSMtZzlh6GqKywR3TMM2PElIovIuCtnkAjSG3?= =?us-ascii?Q?Kw0iWZ69/NiCb44ht0oHJ59buIVkUKN3jiG0XHYOJ/7hP0mc8EdlrCQpgVnZ?= =?us-ascii?Q?AUPMAaWE6HD3Sf4Uz5quokZJmuBJB70bEruoaC5v2TlcXGhTy/j49jbF2/Tc?= =?us-ascii?Q?+xBNsaEDFze27/Q6dPRD/f7GzaxWRzyDFYlnAsQ4oN/qZqQii0s2Jh4KR2v6?= =?us-ascii?Q?XnWRW0fzqj6t2mHyWJx9tQmkvYvcgBwCbGWzzliClAFNreHNguA39IYwsEI0?= =?us-ascii?Q?MZmeXq/QEz5hB8JRtXyxr3AKvlijCnc+g0keNUDpkvX2WQaNugl/zy7cKa6L?= =?us-ascii?Q?K2oqeFCLAjVDe82olDIeBM+NPSp81Pqed6VxORjIkjR7Z5E2BYPRPjLzT6sr?= =?us-ascii?Q?qbqTPvXqEyCMeFMkoAzSZZ4pDdudA49lxeqge+M6sIWYOHjNdCvXIcSgGcwg?= =?us-ascii?Q?sj3chNCM7gbgzMger5LxB1Icd1ANj7P+lAc76GFK3r/4ivCOw7TwKxMuCPPV?= =?us-ascii?Q?FlKBxAx0CMetMDi7HWWIcfc8ii3HA3TQe7GL1s7tlPqtJLpG6VRx7Q6t9P2q?= =?us-ascii?Q?EaAySBCJF7D1CTTi/g9bt2qxG1FUK5q6oScUDp1hMmRKVn9bGKBV4AO9rKqD?= =?us-ascii?Q?b90oxuGSY45PdIG6cXN4IwKdVbZfXACkB+OQewj0v7Ff9Eg1g3imft1nyget?= =?us-ascii?Q?rQh3a9fo8HzG4tLHEFiBTnKILh+wqc0gEtdNHZrp5j1qoqofhft3vb+q7Jsq?= =?us-ascii?Q?cRD9lvF40/OANFQCHZlwpi4dRMknPmDbacxAQWnMgZ6z9gqfDdQLVcrhhZjm?= =?us-ascii?Q?syl8CrnG3ZMWBtR8qHdwFSddAalmh0BHVIfeK3bc80DY7gxfcuHJ3naArnHy?= =?us-ascii?Q?qicVVV2CroLl3SNRcOKDTkN07Egk/UvO1LKXJ3ugC6V8c+c+cDLB4R46ZcmD?= =?us-ascii?Q?0UFbaLCOpVWRKgmygG7awgkALq5N+ayB?= 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: ebef2cc4-d147-4f87-4c44-08da07bfeb9a X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Mar 2022 02:43:29.7533 (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: wUdFTRHVhzMl7NtIBEmVDrDY8CXDemX5t50zjk7vtP0PAoJZjtuk7ac6uw4c/c82aP5jq/U8PBrllA/driGAiA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR11MB2034 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 Will send patch_v6 with following update soon. 1. adjust the position of new field in the data structure. 2.update the version of data structure if it existing. 3.With the usability test, the CrytoLibOnProtocol version code can be used = normally as static version. Best Regard Zhihao -----Original Message----- From: Yao, Jiewen =20 Sent: Monday, March 14, 2022 1:50 PM 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. 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