From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web10.5474.1646389487371092457 for ; Fri, 04 Mar 2022 02:24:47 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=AbgDuHuO; spf=pass (domain: intel.com, ip: 192.55.52.43, 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=1646389487; x=1677925487; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=n9kFXZj3VoyrUPhUMMjXcCXqv5s+MvwtRhMpPGvTEog=; b=AbgDuHuOn3ZJGCXvVRvUZnf0pxBNzrSPnMxB+I2efqhjXmkmZqj2Yl2W uVEz98nMwAt84nlHV7SwWtKmlypDEzXh499kRkZmWyw1wjsV1bbb41LWK HqlkW4kKYTU0mME+jBMKQtmXeqjMhDqn+LI2RZrN9eD6Tml8sDB5uEirQ yeAB0sllhXPT9Gry4WLVWTLJXRNdT4Hz5zTlS4/ku5MmdNiDHyRxhlCwb munwq2+18mL/OTpU6a9bV0IXChLRg1dHcQ0mqDnwJJ2nYuEJa7J8AKqjd HFuQwmkRDZS1adKTUA6t1ljh+ejtQ5QNcxZusmWhpXRyEtrxqSrHMPXUs w==; X-IronPort-AV: E=McAfee;i="6200,9189,10275"; a="340378392" X-IronPort-AV: E=Sophos;i="5.90,154,1643702400"; d="scan'208";a="340378392" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2022 02:24:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,154,1643702400"; d="scan'208";a="508944670" Received: from orsmsx605.amr.corp.intel.com ([10.22.229.18]) by orsmga002.jf.intel.com with ESMTP; 04 Mar 2022 02:24:46 -0800 Received: from orsmsx607.amr.corp.intel.com (10.22.229.20) by ORSMSX605.amr.corp.intel.com (10.22.229.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 02:24:46 -0800 Received: from orsmsx607.amr.corp.intel.com (10.22.229.20) 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; Fri, 4 Mar 2022 02:24:45 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) 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; Fri, 4 Mar 2022 02:24:45 -0800 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.173) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.21; Fri, 4 Mar 2022 02:24:45 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q9wNnCA4fCUkRmb7aan+bjM/BBQIadPH/S3pU43NKVBKpng2aMXCZtcBv6ep3qjlci9VjYAKT2U4g87OuI9ktiuc/vr88XTYsyxM06WimjlZ0irJoiisCqHSK1Bo7deNmlq5F2VZQRPfXaL8mRsf+lRG64QeetsEnZQ3hAsM0uoB9wnaPCeqGNWcyr/+E8aTikzginFR/4JUWgg7OnylPA07OMskvDusv8VAXtQpsitHcf6W0kdaQTFS/Z7da0NGDZ+pf2G1cI9jkgqK1qrMj5ZMc7jBVYH6Tzx69LQhE/B855YN6pu3sbP/EthCry0y8XRK8yPIzQRb2Grx43T/cw== 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=Ozy/PcgTCZ3t2KWFhDxF2CRTE089Qj62mtaSDCzIeVk=; b=F18cjEbpopEl+aV4uAao8XUksLpRsKy+fIG4UCnyQ9OE7gmkk3S2lo/jXNxvkYxrEKYA5oIZ+Gp+9E37pMPK0HTDp4h2v1azjkm7cUCCcuD+ghMG+yBIC+V7tJTPPdPINN8HckFFirUZR/P4E4xblrUjK9Y+r5lHZkhX5uokjaLkRgBkZUaNZOr4QHjQPAkJDRXieNT0EuDCqsri8JFoAUJRZ6azqEFL2pZhi/x25BXNAH4fCAT+8W3RHUkC5/9PUuf7LcDDh2iqjC1fnDhIsydYB4Uya28MjVEDDKARqBrQTCB24/VJmiNHJHBbzoF0/S6UO98VM6pTXYrPjjMrLw== 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 SN6PR11MB3263.namprd11.prod.outlook.com (2603:10b6:805:c5::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Fri, 4 Mar 2022 10:24:42 +0000 Received: from DM6PR11MB4738.namprd11.prod.outlook.com ([fe80::1527:223f:8a2d:4f5e]) by DM6PR11MB4738.namprd11.prod.outlook.com ([fe80::1527:223f:8a2d:4f5e%8]) with mapi id 15.20.5038.017; Fri, 4 Mar 2022 10:24:42 +0000 From: "Li, Zhihao" To: "Yao, Jiewen" , "devel@edk2.groups.io" CC: "Wang, Jian J" , "Lu, Xiaoyu1" , "Jiang, Guomin" , "Fu, Siyuan" Subject: Re: [PATCH v4 1/1] CryptoPkg: Add new hash algorithm ParallelHash256HashAll in BaseCryptLib. Thread-Topic: [PATCH v4 1/1] CryptoPkg: Add new hash algorithm ParallelHash256HashAll in BaseCryptLib. Thread-Index: AQHYLhRKC68P/rH3bUmCFCzzvIQNwayuvhywgABHCuA= Date: Fri, 4 Mar 2022 10:24:42 +0000 Message-ID: References: <20220302090232.2157-1-zhihao.li@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d0784a73-bec3-4d1b-eb4e-08d9fdc93246 x-ms-traffictypediagnostic: SN6PR11MB3263: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: /b/+hRkhsqfZqjsu/ArIFgVJX0ZNu3vykhFdzj8yaAP1Haf7x3WWaiCCCpSeuTSKn9211gGtETf+iTQLabba/iEtfKK/5w3qYjirYJGhlLc0O9C/lKzjjN2XrSOExwcp9jvcowdwwP7KfRUgsYw2/KF3MO2nBn2RDF7V6BqJinbIHxzmgqi30SjCO/q+OGiSGUs+UZY6flJYe41aiH8VXvl2dMmN1KSMXIP2tc5wH+ttQdCYbBNa8KZ3q8OFGbkervyuxXaFpVlDo3T37khwD2ZD+BcWSNAzJEWulFVcQImWoGh3VzMG91MZz/c9ZqJSe1BENw9RLFF4o7sYvXmzNt/S0H3UcVZsTKYo8m1l2TVQ4o4DR/r413e+/Xm7weR+gsP/0U1vEwut36Q18DTuakKjLXWP8TlH6cF33cbsFv1fykTuBYLlKSFp/Xjdmsi3zZtlCGwWG1eMrbQ71uZuUwyLigxMaDEd2SBhO+QbKA9n7TA/vyAFrgOwq747JW2avjBevuNk/gKaOEQpT+1T8iRCVWjfKoEj1iCqF5PopRB1J1Uq21XmVP5EFBgOlYFhnqP6e8wCemMZ3LjrCyqPI3OeqWKE4mdPnOixG/FkldeduELjpbKKytfRIS3jUZ0j1RyF3QI6TRKiV/uP0kYtlUaf9Fp5E8I+QXbEFoEmVXR5/uqFd6D7dXZWiX11vr1EtvQ3cDAzgVBJmPr3Fd5Hv/qiqF0J2FhbTN5+Y0P8WnIKB9lp/xVyTskgLihJ7RpPwYZZq21h3q0MV4rR9Jy61uTJWy0EWIZcdCGroB/Av6xQIZjpQmG1He94OL0CqXAq 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)(82960400001)(38070700005)(45080400002)(19627235002)(2906002)(110136005)(53546011)(54906003)(38100700002)(7696005)(122000001)(6506007)(30864003)(76116006)(8936002)(66556008)(64756008)(8676002)(66476007)(66946007)(107886003)(66446008)(86362001)(4326008)(186003)(316002)(9686003)(52536014)(33656002)(5660300002)(26005)(966005)(508600001)(71200400001)(55016003)(83380400001)(579004)(559001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?O+FgLbKamStrZNNIjcZKdjTumF6kzTK7OaLNl3tuRFZ1D+7bYsOpNJRmgbfl?= =?us-ascii?Q?Bbmuuhhpm3Np7srW9oBCUPuDFRHUHReSMcJoJ4XlFKXvERY0B65SGSuWeQPb?= =?us-ascii?Q?R2YLXCWBDuxJW/MW+ntJ0usjyF+opGnysn1nGgg7TdNQerhs8vUXMb1lx7dX?= =?us-ascii?Q?f2Z3v5GssYXyrSkBdEm1tWUo1ANu+e8B1PZKH9Clx5ldQfj5Y4iKEbDmhC3k?= =?us-ascii?Q?Lu47NW0kvrli98MBf7VMnZo+ZjVdT35ZvKGLX1/KefDKgqh4qbeIZ4ASp6Dn?= =?us-ascii?Q?s76wDR5O9vEW/+JAijl6rVb03akmHPQOpNseqWjaoEeyB4ol1Q/qFdjel49i?= =?us-ascii?Q?b6tm490k8+1UEM503ysPrPV6rKSB5KGJWPONHOSJGkMikzMstNaQa7bdeDqB?= =?us-ascii?Q?QT3R/MmCwfhqFeSD7wNwmqZOJffDHG6e3Ih0Gku4xtIBFePFKgTfEjOhXAQP?= =?us-ascii?Q?1fp2+i+dVHEMrJcl+F8A5EBcPFhLuOy9RDwYbi8YF4UodjdDXBai3N2eJG4P?= =?us-ascii?Q?qgynKcKCsQYztLULM2ZN28ay/o6eXYF4XXtRl657BgE5BIjRiSe3yFOY0QFw?= =?us-ascii?Q?uT7vqV9VlKMaD/HO6arVn7eiJ8gSanSFrPyhWQovokXjqG5HNzdK4xt9P+LN?= =?us-ascii?Q?GaDZGXzbv7Q8P6qsM9k1qDVnZuMgT3T825EY0KAcA+2r2zLoXuzblPgr+I0e?= =?us-ascii?Q?VpEWElDHuf9eR1Xhft3WZ6dm4v/lOT4f1zMDPY2ZJ6XAQ/fwwjAnkFSfDy2d?= =?us-ascii?Q?Q40aQsOZseqSI4hFTvBEHURZ37V5SECJxsyonWIl0EFTwCmJ3/4hcwZuwuvq?= =?us-ascii?Q?QAJH07hg6elTE67V3G4wbdAHrStwXnGihkBUSTjZlAydpgprU8I4aDemV/6L?= =?us-ascii?Q?A/7AasQ8jO1AJ3N12e4icz+i8YymxAuZG8r6ZaBSlJ+U6NvwXsCk86z4gIht?= =?us-ascii?Q?IlAwBrU4nTw+6vG9j0hLkdm1B63bWXlX9QRlPvdtiwpsecFKn3nWMuBwzV/G?= =?us-ascii?Q?RGEcnOHKdpnVbIdYCXpJ+DLJ3BOupla6kK/a2CGOchT5GSut/NRS6oa8sG0c?= =?us-ascii?Q?+ildZBlPv5gIBZHerzc3s2CogAyQf1OIhrg8wqY8vKmZ2rsivPZk8kSz7+Wy?= =?us-ascii?Q?hgi7DgezzFVHbDTiG2AU++1vJaZM/oavMB6si2q4R3bPcEu61SZdizB3+KaF?= =?us-ascii?Q?GNmzRPmYES0drZe93/ucHfYF3q8HGKfshxfe9dLlLDdR/dUerimSk/xYyb7D?= =?us-ascii?Q?+o31t/98YHM6F2Vvpip5SHcfic0oDuvQzQMNbh2YkLkv+dz62S+VEUKq6HWG?= =?us-ascii?Q?+cLclpgMcply+cboKJuHRhj/YzucGXV5k2/4HbpTn14IlZARfl65MXXJWaX6?= =?us-ascii?Q?NSCrShk/na4z+JUr7IhfTIRX1jGDoE7ZxRNImtH8ho9f/0u1yXuW3/28Gud3?= =?us-ascii?Q?E7Ehjd6gNsU9WVN3/csV8kxGAhRShCjNZUHx7v/VkyATY6ULNvAu8pTrVLgz?= =?us-ascii?Q?LKUHpIuLvQ7T28agSmUu3ibY1K4sYHehxXJSRvUNsXenNkpMFN5CF1iNT6Zl?= =?us-ascii?Q?U/5WoAzGUBoeyMD2WqmIDM3hFZU+L4EiE1yAcDDQaxhCnp8mcbP+miv+MwGr?= =?us-ascii?Q?Zg=3D=3D?= 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: d0784a73-bec3-4d1b-eb4e-08d9fdc93246 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Mar 2022 10:24:42.1680 (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: Gt8pK8CJ8OmSKUT266F/klu9A9c2+2oXtIv2q3/LbQ43DaTuy6hwLp3NHSigOxrT2podUtLR2Unr2/mZOg1F4g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB3263 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 Hi, Jiewen Thanks for your comments. I have some confusion. 1.Can I create new .h file in CryptoPkg\Library\BaseCryptLib\Hash\ to place= Keccak1600_Ctx and other declarations. Otherwise I put Keccak1600_Ctx define into CryptSha3.c and CryptCShake256.c Repetitively. 2. SHA3_absorb and SHA3_squeeze function from Openssl keccak1600.c(no heade= r file), and they can't pass EFI coding style check. If I re-implement them in CryptSha3.c, I have to re-implement the whole kec= cak1600.c in BaseCryptlib. There are many=20 Complex define in keccak1600.c need to be concern. So if I can create new .= h file and let EFICodeStyleCheck ignore my new .h file. > -----Original Message----- > From: Yao, Jiewen > Sent: Friday, March 4, 2022 2:06 PM > To: Li, Zhihao ; devel@edk2.groups.io > Cc: Wang, Jian J ; Lu, Xiaoyu1 > ; Jiang, Guomin ; Fu, > Siyuan > Subject: RE: [PATCH v4 1/1] CryptoPkg: Add new hash algorithm > ParallelHash256HashAll in BaseCryptLib. >=20 > Thanks for the update. >=20 > Comments below: >=20 > 1) I don't think we should putting Keccak1600_Ctx in CrtLibSupport.h. It = has > nothing to do with CRT lib. >=20 > 2) Same feedback to SHA3_absorb and SHA3_squeeze. They have nothing to > do with CRT lib. >=20 > 3) when you add new lib interfaces, you need add them to all instances. I > found you only changed SmmCryptLib.inf, but miss others. > Please also update PEI, DXE, RuntimeDxe. NULL version implementation is > acceptable. >=20 > 4) I don't see you update CryptoPkg\Private\Protocol and Ppi. > They should be 1:1 mapping with CryptoLib API. >=20 > Thank you > Yao Jiewen >=20 >=20 > > -----Original Message----- > > From: Li, Zhihao > > Sent: Wednesday, March 2, 2022 5:03 PM > > To: devel@edk2.groups.io > > Cc: Yao, Jiewen ; Wang, Jian J > ; > > Lu, Xiaoyu1 ; Jiang, Guomin > ; > > Fu, Siyuan > > Subject: [PATCH v4 1/1] CryptoPkg: Add new hash algorithm > > ParallelHash256HashAll in BaseCryptLib. > > > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3596 > > > > Parallel hash function ParallelHash256HashAll, as defined in NIST's > > Special Publication 800-185, published December 2016. It utilizes > > multi-process to calculate the digest. > > > > Some modifications to pass CI test. > > > > Cc: Jiewen Yao > > Cc: Jian J Wang > > Cc: Xiaoyu Lu > > Cc: Guomin Jiang > > Cc: Siyuan Fu > > Cc: Zhihao Li > > > > Signed-off-by: Zhihao Li > > --- > > CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c = | 381 > > ++++++++++++++++++++ > > CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c = | 350 > > ++++++++++++++++++ > > CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c = | 166 > > +++++++++ > > CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c = | 107 > ++++++ > > CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests.c = | 145 > > ++++++++ > > CryptoPkg/Include/Library/BaseCryptLib.h = | 31 +- > > CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf = | 8 +- > > CryptoPkg/Library/Include/CrtLibSupport.h = | 38 +- > > CryptoPkg/Test/CryptoPkgHostUnitTest.dsc = | 3 + > > CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf = | > 4 + > > 10 files changed, 1230 insertions(+), 3 deletions(-) > > > > diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c > > b/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c > > new file mode 100644 > > index 000000000000..6b26d74d5413 > > --- /dev/null > > +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c > > @@ -0,0 +1,381 @@ > > +/** @file > > > > + cSHAKE-256 Digest Wrapper Implementations. > > > > + > > > > + Copyright (c) 2022, Intel Corporation. All rights reserved.
> > > > + SPDX-License-Identifier: BSD-2-Clause-Patent > > > > + > > > > +**/ > > > > + > > > > +#include "InternalCryptLib.h" > > > > + > > > > +#define CSHAKE256_SECURITY_STRENGTH 256 > > > > +#define CSHAKE256_RATE_IN_BYTES 136 > > > > + > > > > +const CHAR8 mZeroPadding[CSHAKE256_RATE_IN_BYTES] =3D { 0 }; > > > > + > > > > +/** > > > > + Encode function from XKCP. > > > > + > > > > + Encodes the input as a byte string in a way that can be unambiguousl= y > parsed > > > > + from the beginning of the string by inserting the length of the byte= string > > > > + before the byte string representation of input. > > > > + > > > > + @param[out] EncBuf Result of left encode. > > > > + @param[in] Value Input of left encode. > > > > + > > > > + @retval EncLen Size of encode result in bytes. > > > > +**/ > > > > +UINTN > > > > +EFIAPI > > > > +LeftEncode ( > > > > + OUT UINT8 *EncBuf, > > > > + IN UINTN Value > > > > + ); > > > > + > > > > +/** > > > > + Encode function from XKCP. > > > > + > > > > + Encodes the input as a byte string in a way that can be unambiguousl= y > parsed > > > > + from the end of the string by inserting the length of the byte strin= g after > > > > + the byte string representation of input. > > > > + > > > > + @param[out] EncBuf Result of right encode. > > > > + @param[in] Value Input of right encode. > > > > + > > > > + @retval EncLen Size of encode result in bytes. > > > > +**/ > > > > +UINTN > > > > +EFIAPI > > > > +RightEncode ( > > > > + OUT UINT8 *EncBuf, > > > > + IN UINTN Value > > > > + ); > > > > + > > > > +/** > > > > + Keccak initial fuction. > > > > + > > > > + Set up state with specified capacity. > > > > + > > > > + @param[out] Context Pointer to the context being initializ= ed. > > > > + @param[in] Pad Delimited Suffix. > > > > + @param[in] BlockSize Size of context block. > > > > + @param[in] MessageDigestLen Size of message digest in bytes. > > > > + > > > > + @retval 1 Initialize successfully. > > > > + @retval 0 Fail to initialize. > > > > +**/ > > > > +UINT8 > > > > +EFIAPI > > > > +KeccakInit ( > > > > + OUT Keccak1600_Ctx *Context, > > > > + IN UINT8 Pad, > > > > + IN UINTN BlockSize, > > > > + IN UINTN MessageDigstLen > > > > + ); > > > > + > > > > +/** > > > > + Sha3 update fuction. > > > > + > > > > + This function performs Sha3 digest on a data buffer of the specified= size. > > > > + It can be called multiple times to compute the digest of long or > discontinuous > > data streams. > > > > + > > > > + @param[in,out] Context Pointer to the Keccak context. > > > > + @param[in] Data Pointer to the buffer containing the data t= o be > hashed. > > > > + @param[in] DataSize Size of Data buffer in bytes. > > > > + > > > > + @retval 1 Update successfully. > > > > +**/ > > > > +UINT8 > > > > +EFIAPI > > > > +Sha3Update ( > > > > + IN OUT Keccak1600_Ctx *Context, > > > > + IN const VOID *Data, > > > > + IN UINTN DataSize > > > > + ); > > > > + > > > > +/** > > > > + Completes computation of Sha3 message digest. > > > > + > > > > + This function completes sha3 hash computation and retrieves the dige= st > value > > into > > > > + the specified memory. After this function has been called, the kecca= k > context > > cannot > > > > + be used again. > > > > + > > > > + @param[in, out] Context Pointer to the keccak context. > > > > + @param[out] MessageDigest Pointer to a buffer that receives th= e > > message digest. > > > > + > > > > + @retval 1 Meaasge digest computation succeeded. > > > > +**/ > > > > +UINT8 > > > > +EFIAPI > > > > +Sha3Final ( > > > > + IN OUT Keccak1600_Ctx *Context, > > > > + OUT UINT8 *MessageDigest > > > > + ); > > > > + > > > > +/** > > > > + CShake256 initial function. > > > > + > > > > + Initializes user-supplied memory pointed by CShake256Context as > cSHAKE-256 > > hash context for > > > > + subsequent use. > > > > + > > > > + @param[out] CShake256Context Pointer to cSHAKE-256 context being > > initialized. > > > > + @param[in] OutputLen The desired number of output length in > bytes. > > > > + @param[in] Name Pointer to the function name string. > > > > + @param[in] NameLen The length of the function name in byt= es. > > > > + @param[in] Customization Pointer to the customization string. > > > > + @param[in] CustomizationLen The length of the customization string= in > > bytes. > > > > + > > > > + @retval TRUE cSHAKE-256 context initialization succeeded. > > > > + @retval FALSE cSHAKE-256 context initialization failed. > > > > + @retval FALSE This interface is not supported. > > > > +**/ > > > > +BOOLEAN > > > > +EFIAPI > > > > +CShake256Init ( > > > > + OUT VOID *CShake256Context, > > > > + IN UINTN OutputLen, > > > > + IN CONST VOID *Name, > > > > + IN UINTN NameLen, > > > > + IN CONST VOID *Customization, > > > > + IN UINTN CustomizationLen > > > > + ) > > > > +{ > > > > + BOOLEAN Status; > > > > + UINT8 EncBuf[sizeof (UINTN) + 1]; > > > > + UINTN EncLen; > > > > + UINTN AbsorbLen; > > > > + UINTN PadLen; > > > > + > > > > + // > > > > + // Check input parameters. > > > > + // > > > > + if ((CShake256Context =3D=3D NULL) || (OutputLen =3D=3D 0) || ((Name= Len !=3D 0) > && > > (Name =3D=3D NULL)) || ((CustomizationLen !=3D 0) && (Customization =3D= =3D NULL))) > { > > > > + return FALSE; > > > > + } > > > > + > > > > + // > > > > + // Initialize KECCAK context with pad value and block size. > > > > + // > > > > + if ((NameLen =3D=3D 0) && (CustomizationLen =3D=3D 0)) { > > > > + // > > > > + // When N and S are both empty strings, cSHAKE(X, L, N, S) is equi= valent > to > > > > + // SHAKE as defined in FIPS 202. > > > > + // > > > > + Status =3D (BOOLEAN)KeccakInit ( > > > > + (Keccak1600_Ctx *)CShake256Context, > > > > + '\x1f', > > > > + (KECCAK1600_WIDTH - CSHAKE256_SECURITY_STRENGT= H * 2) > / 8, > > > > + OutputLen > > > > + ); > > > > + > > > > + return Status; > > > > + } else { > > > > + Status =3D (BOOLEAN)KeccakInit ( > > > > + (Keccak1600_Ctx *)CShake256Context, > > > > + '\x04', > > > > + (KECCAK1600_WIDTH - CSHAKE256_SECURITY_STRENGT= H * 2) > / 8, > > > > + OutputLen > > > > + ); > > > > + if (!Status) { > > > > + return FALSE; > > > > + } > > > > + > > > > + AbsorbLen =3D 0; > > > > + // > > > > + // Absorb Absorb bytepad(.., rate). > > > > + // > > > > + EncLen =3D LeftEncode (EncBuf, CSHAKE256_RATE_IN_BYTES); > > > > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx *)CShake256Context= , > > EncBuf, EncLen); > > > > + if (!Status) { > > > > + return FALSE; > > > > + } > > > > + > > > > + AbsorbLen +=3D EncLen; > > > > + > > > > + // > > > > + // Absorb encode_string(N). > > > > + // > > > > + EncLen =3D LeftEncode (EncBuf, NameLen * 8); > > > > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx *)CShake256Context= , > > EncBuf, EncLen); > > > > + if (!Status) { > > > > + return FALSE; > > > > + } > > > > + > > > > + AbsorbLen +=3D EncLen; > > > > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx > *)CShake256Context, > > Name, NameLen); > > > > + if (!Status) { > > > > + return FALSE; > > > > + } > > > > + > > > > + AbsorbLen +=3D NameLen; > > > > + > > > > + // > > > > + // Absorb encode_string(S). > > > > + // > > > > + EncLen =3D LeftEncode (EncBuf, CustomizationLen * 8); > > > > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx *)CShake256Context= , > > EncBuf, EncLen); > > > > + if (!Status) { > > > > + return FALSE; > > > > + } > > > > + > > > > + AbsorbLen +=3D EncLen; > > > > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx > *)CShake256Context, > > Customization, CustomizationLen); > > > > + if (!Status) { > > > > + return FALSE; > > > > + } > > > > + > > > > + AbsorbLen +=3D CustomizationLen; > > > > + > > > > + // > > > > + // Absorb zero padding up to rate. > > > > + // > > > > + PadLen =3D CSHAKE256_RATE_IN_BYTES - AbsorbLen % > > CSHAKE256_RATE_IN_BYTES; > > > > + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx *)CShake256Context= , > > mZeroPadding, PadLen); > > > > + if (!Status) { > > > > + return FALSE; > > > > + } > > > > + > > > > + return TRUE; > > > > + } > > > > +} > > > > + > > > > +/** > > > > + Digests the input data and updates cSHAKE-256 context. > > > > + > > > > + This function performs cSHAKE-256 digest on a data buffer of the > specified > > size. > > > > + It can be called multiple times to compute the digest of long or > discontinuous > > data streams. > > > > + cSHAKE-256 context should be already correctly initialized by > CShake256Init(), > > and should not be finalized > > > > + by CShake256Final(). Behavior with invalid context is undefined. > > > > + > > > > + @param[in, out] CShake256Context Pointer to the cSHAKE-256 contex= t. > > > > + @param[in] Data Pointer to the buffer containing= the data to > be > > hashed. > > > > + @param[in] DataSize Size of Data buffer in bytes. > > > > + > > > > + @retval TRUE cSHAKE-256 data digest succeeded. > > > > + @retval FALSE cSHAKE-256 data digest failed. > > > > + @retval FALSE This interface is not supported. > > > > + > > > > +**/ > > > > +BOOLEAN > > > > +EFIAPI > > > > +CShake256Update ( > > > > + IN OUT VOID *CShake256Context, > > > > + IN CONST VOID *Data, > > > > + IN UINTN DataSize > > > > + ) > > > > +{ > > > > + // > > > > + // Check input parameters. > > > > + // > > > > + if (CShake256Context =3D=3D NULL) { > > > > + return FALSE; > > > > + } > > > > + > > > > + // > > > > + // Check invalid parameters, in case that only DataLength was checke= d in > > OpenSSL. > > > > + // > > > > + if ((Data =3D=3D NULL) && (DataSize !=3D 0)) { > > > > + return FALSE; > > > > + } > > > > + > > > > + return (BOOLEAN)(Sha3Update ((Keccak1600_Ctx *)CShake256Context, > Data, > > DataSize)); > > > > +} > > > > + > > > > +/** > > > > + Completes computation of the cSHAKE-256 digest value. > > > > + > > > > + This function completes cSHAKE-256 hash computation and retrieves th= e > > digest value into > > > > + the specified memory. After this function has been called, the cSHAK= E- > 256 > > context cannot > > > > + be used again. > > > > + cSHAKE-256 context should be already correctly initialized by > CShake256Init(), > > and should not be > > > > + finalized by CShake256Final(). Behavior with invalid cSHAKE-256 cont= ext > is > > undefined. > > > > + > > > > + @param[in, out] CShake256Context Pointer to the cSHAKE-256 context= . > > > > + @param[out] HashValue Pointer to a buffer that receives= the > cSHAKE- > > 256 digest > > > > + value. > > > > + > > > > + @retval TRUE cSHAKE-256 digest computation succeeded. > > > > + @retval FALSE cSHAKE-256 digest computation failed. > > > > + @retval FALSE This interface is not supported. > > > > + > > > > +**/ > > > > +BOOLEAN > > > > +EFIAPI > > > > +CShake256Final ( > > > > + IN OUT VOID *CShake256Context, > > > > + OUT UINT8 *HashValue > > > > + ) > > > > +{ > > > > + // > > > > + // Check input parameters. > > > > + // > > > > + if ((CShake256Context =3D=3D NULL) || (HashValue =3D=3D NULL)) { > > > > + return FALSE; > > > > + } > > > > + > > > > + // > > > > + // cSHAKE-256 Hash Finalization. > > > > + // > > > > + return (BOOLEAN)(Sha3Final ((Keccak1600_Ctx *)CShake256Context, > > HashValue)); > > > > +} > > > > + > > > > +/** > > > > + Computes the CSHAKE-256 message digest of a input data buffer. > > > > + > > > > + This function performs the CSHAKE-256 message digest of a given data > buffer, > > and places > > > > + the digest value into the specified memory. > > > > + > > > > + @param[in] Data Pointer to the buffer containing the= data to be > > hashed. > > > > + @param[in] DataSize Size of Data buffer in bytes. > > > > + @param[in] OutputLen Size of output in bytes. > > > > + @param[in] Name Pointer to the function name string. > > > > + @param[in] NameLen Size of the function name in bytes. > > > > + @param[in] Customization Pointer to the customization string. > > > > + @param[in] CustomizationLen Size of the customization string in = bytes. > > > > + @param[out] HashValue Pointer to a buffer that receives th= e > CSHAKE- > > 256 digest > > > > + value. > > > > + > > > > + @retval TRUE CSHAKE-256 digest computation succeeded. > > > > + @retval FALSE CSHAKE-256 digest computation failed. > > > > + @retval FALSE This interface is not supported. > > > > + > > > > +**/ > > > > +BOOLEAN > > > > +EFIAPI > > > > +CShake256HashAll ( > > > > + IN CONST VOID *Data, > > > > + IN UINTN DataSize, > > > > + IN UINTN OutputLen, > > > > + IN CONST VOID *Name, > > > > + IN UINTN NameLen, > > > > + IN CONST VOID *Customization, > > > > + IN UINTN CustomizationLen, > > > > + OUT UINT8 *HashValue > > > > + ) > > > > +{ > > > > + BOOLEAN Status; > > > > + Keccak1600_Ctx Ctx; > > > > + > > > > + // > > > > + // Check input parameters. > > > > + // > > > > + if (HashValue =3D=3D NULL) { > > > > + return FALSE; > > > > + } > > > > + > > > > + if ((Data =3D=3D NULL) && (DataSize !=3D 0)) { > > > > + return FALSE; > > > > + } > > > > + > > > > + Status =3D CShake256Init (&Ctx, OutputLen, Name, NameLen, > Customization, > > CustomizationLen); > > > > + if (!Status) { > > > > + return FALSE; > > > > + } > > > > + > > > > + Status =3D CShake256Update (&Ctx, Data, DataSize); > > > > + if (!Status) { > > > > + return FALSE; > > > > + } > > > > + > > > > + return CShake256Final (&Ctx, HashValue); > > > > +} > > > > diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c > > b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c > > new file mode 100644 > > index 000000000000..825cc8ea6b20 > > --- /dev/null > > +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c > > @@ -0,0 +1,350 @@ > > +/** @file > > > > + ParallelHash Implementation. > > > > + > > > > +Copyright (c) 2022, Intel Corporation. All rights reserved.
> > > > +SPDX-License-Identifier: BSD-2-Clause-Patent > > > > + > > > > +**/ > > > > + > > > > +#include "InternalCryptLib.h" > > > > +#include > > > > +#include > > > > + > > > > +#define PARALLELHASH_CUSTOMIZATION "ParallelHash" > > > > + > > > > +UINTN mBlockNum; > > > > +UINTN mBlockSize; > > > > +UINTN mLastBlockSize; > > > > +UINT8 *mInput; > > > > +UINTN mBlockResultSize; > > > > +UINT8 *mBlockHashResult; > > > > +BOOLEAN *mBlockIsCompleted; > > > > +SPIN_LOCK *mSpinLockList; > > > > + > > > > +/** > > > > + Encode function from XKCP. > > > > + > > > > + Encodes the input as a byte string in a way that can be unambiguousl= y > parsed > > > > + from the beginning of the string by inserting the length of the byte= string > > > > + before the byte string representation of input. > > > > + > > > > + @param[out] EncBuf Result of left encode. > > > > + @param[in] Value Input of left encode. > > > > + > > > > + @retval EncLen Size of encode result in bytes. > > > > +**/ > > > > +UINTN > > > > +EFIAPI > > > > +LeftEncode ( > > > > + OUT UINT8 *EncBuf, > > > > + IN UINTN Value > > > > + ); > > > > + > > > > +/** > > > > + Encode function from XKCP. > > > > + > > > > + Encodes the input as a byte string in a way that can be unambiguousl= y > parsed > > > > + from the end of the string by inserting the length of the byte strin= g after > > > > + the byte string representation of input. > > > > + > > > > + @param[out] EncBuf Result of right encode. > > > > + @param[in] Value Input of right encode. > > > > + > > > > + @retval EncLen Size of encode result in bytes. > > > > +**/ > > > > +UINTN > > > > +EFIAPI > > > > +RightEncode ( > > > > + OUT UINT8 *EncBuf, > > > > + IN UINTN Value > > > > + ); > > > > + > > > > +/** > > > > + Computes the CSHAKE-256 message digest of a input data buffer. > > > > + > > > > + This function performs the CSHAKE-256 message digest of a given data > buffer, > > and places > > > > + the digest value into the specified memory. > > > > + > > > > + @param[in] Data Pointer to the buffer containing the= data to be > > hashed. > > > > + @param[in] DataSize Size of Data buffer in bytes. > > > > + @param[in] OutputLen Size of output in bytes. > > > > + @param[in] Name Pointer to the function name string. > > > > + @param[in] NameLen Size of the function name in bytes. > > > > + @param[in] Customization Pointer to the customization string. > > > > + @param[in] CustomizationLen Size of the customization string in = bytes. > > > > + @param[out] HashValue Pointer to a buffer that receives th= e > CSHAKE- > > 256 digest > > > > + value. > > > > + > > > > + @retval TRUE CSHAKE-256 digest computation succeeded. > > > > + @retval FALSE CSHAKE-256 digest computation failed. > > > > + @retval FALSE This interface is not supported. > > > > + > > > > +**/ > > > > +BOOLEAN > > > > +EFIAPI > > > > +CShake256HashAll ( > > > > + IN CONST VOID *Data, > > > > + IN UINTN DataSize, > > > > + IN UINTN OutputLen, > > > > + IN CONST VOID *Name, > > > > + IN UINTN NameLen, > > > > + IN CONST VOID *Customization, > > > > + IN UINTN CustomizationLen, > > > > + OUT UINT8 *HashValue > > > > + ); > > > > + > > > > +/** > > > > + Complete computation of digest of each block. > > > > + > > > > + Each AP perform the function called by BSP. > > > > + > > > > + @param[in] ProcedureArgument Argument of the procedure. > > > > +**/ > > > > +VOID > > > > +EFIAPI > > > > +ParallelHashApExecute ( > > > > + IN VOID *ProcedureArgument > > > > + ) > > > > +{ > > > > + UINTN Index; > > > > + BOOLEAN Status; > > > > + > > > > + for (Index =3D 0; Index < mBlockNum; Index++) { > > > > + if (AcquireSpinLockOrFail (&mSpinLockList[Index])) { > > > > + // > > > > + // Completed, try next one. > > > > + // > > > > + if (mBlockIsCompleted[Index]) { > > > > + ReleaseSpinLock (&mSpinLockList[Index]); > > > > + continue; > > > > + } > > > > + > > > > + // > > > > + // Calculate CShake256 for this block. > > > > + // > > > > + Status =3D CShake256HashAll ( > > > > + mInput + Index * mBlockSize, > > > > + (Index =3D=3D (mBlockNum - 1)) ? mLastBlockSize : mBl= ockSize, > > > > + mBlockResultSize, > > > > + NULL, > > > > + 0, > > > > + NULL, > > > > + 0, > > > > + mBlockHashResult + Index * mBlockResultSize > > > > + ); > > > > + if (!EFI_ERROR (Status)) { > > > > + mBlockIsCompleted[Index] =3D TRUE; > > > > + } > > > > + > > > > + ReleaseSpinLock (&mSpinLockList[Index]); > > > > + } > > > > + } > > > > +} > > > > + > > > > +/** > > > > + Dispatch the block task to each AP in SMM mode. > > > > + > > > > +**/ > > > > +VOID > > > > +EFIAPI > > > > +MmDispatchBlockToAP ( > > > > + VOID > > > > + ) > > > > +{ > > > > + UINTN Index; > > > > + > > > > + for (Index =3D 0; Index < gMmst->NumberOfCpus; Index++) { > > > > + if (Index !=3D gMmst->CurrentlyExecutingCpu) { > > > > + gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NULL); > > > > + } > > > > + } > > > > + > > > > + return; > > > > +} > > > > + > > > > +/** > > > > + Parallel hash function ParallelHash256, as defined in NIST's Special > Publication > > 800-185, > > > > + published December 2016. > > > > + > > > > + @param[in] Input Pointer to the input message (X). > > > > + @param[in] InputByteLen The number(>0) of input bytes provided > for the > > input data. > > > > + @param[in] BlockSize The size of each block (B). > > > > + @param[out] Output Pointer to the output buffer. > > > > + @param[in] OutputByteLen The desired number of output bytes (L)= . > > > > + @param[in] Customization Pointer to the customization string (S= ). > > > > + @param[in] CustomByteLen The length of the customization string= in > bytes. > > > > + > > > > + @retval TRUE ParallelHash256 digest computation succeeded. > > > > + @retval FALSE ParallelHash256 digest computation failed. > > > > + @retval FALSE This interface is not supported. > > > > + > > > > +**/ > > > > +BOOLEAN > > > > +EFIAPI > > > > +ParallelHash256HashAll ( > > > > + IN CONST VOID *Input, > > > > + IN UINTN InputByteLen, > > > > + IN UINTN BlockSize, > > > > + OUT VOID *Output, > > > > + IN UINTN OutputByteLen, > > > > + IN CONST VOID *Customization, > > > > + IN UINTN CustomByteLen > > > > + ) > > > > +{ > > > > + UINT8 EncBufB[sizeof (UINTN)+1]; > > > > + UINTN EncSizeB; > > > > + UINT8 EncBufN[sizeof (UINTN)+1]; > > > > + UINTN EncSizeN; > > > > + UINT8 EncBufL[sizeof (UINTN)+1]; > > > > + UINTN EncSizeL; > > > > + UINTN Index; > > > > + UINT8 *CombinedInput; > > > > + UINTN CombinedInputSize; > > > > + BOOLEAN AllCompleted; > > > > + UINTN Offset; > > > > + BOOLEAN ReturnValue; > > > > + > > > > + if ((InputByteLen =3D=3D 0) || (OutputByteLen =3D=3D 0) || (BlockSiz= e =3D=3D 0)) { > > > > + return FALSE; > > > > + } > > > > + > > > > + if ((Input =3D=3D NULL) || (Output =3D=3D NULL)) { > > > > + return FALSE; > > > > + } > > > > + > > > > + if ((CustomByteLen !=3D 0) && (Customization =3D=3D NULL)) { > > > > + return FALSE; > > > > + } > > > > + > > > > + mBlockSize =3D BlockSize; > > > > + > > > > + // > > > > + // Calculate block number n. > > > > + // > > > > + mBlockNum =3D InputByteLen % mBlockSize =3D=3D 0 ? InputByteLen / > mBlockSize : > > InputByteLen / mBlockSize + 1; > > > > + > > > > + // > > > > + // Set hash result size of each block in bytes. > > > > + // > > > > + mBlockResultSize =3D OutputByteLen; > > > > + > > > > + // > > > > + // Encode B, n, L to string and record size. > > > > + // > > > > + EncSizeB =3D LeftEncode (EncBufB, mBlockSize); > > > > + EncSizeN =3D RightEncode (EncBufN, mBlockNum); > > > > + EncSizeL =3D RightEncode (EncBufL, OutputByteLen * CHAR_BIT); > > > > + > > > > + // > > > > + // Allocate buffer for combined input (newX), Block completed flag a= nd > > SpinLock. > > > > + // > > > > + CombinedInputSize =3D EncSizeB + EncSizeN + EncSizeL + mBlockNum * > > mBlockResultSize; > > > > + CombinedInput =3D AllocateZeroPool (CombinedInputSize); > > > > + mBlockIsCompleted =3D AllocateZeroPool (mBlockNum * sizeof > (BOOLEAN)); > > > > + mSpinLockList =3D AllocatePool (mBlockNum * sizeof (SPIN_LOCK)); > > > > + if ((CombinedInput =3D=3D NULL) || (mBlockIsCompleted =3D=3D NULL) |= | > > (mSpinLockList =3D=3D NULL)) { > > > > + ReturnValue =3D FALSE; > > > > + goto Exit; > > > > + } > > > > + > > > > + // > > > > + // Fill LeftEncode(B). > > > > + // > > > > + CopyMem (CombinedInput, EncBufB, EncSizeB); > > > > + > > > > + // > > > > + // Prepare for parallel hash. > > > > + // > > > > + mBlockHashResult =3D CombinedInput + EncSizeB; > > > > + mInput =3D (UINT8 *)Input; > > > > + mLastBlockSize =3D InputByteLen % mBlockSize =3D=3D 0 ? mBlockSize= : > > InputByteLen % mBlockSize; > > > > + > > > > + // > > > > + // Initialize SpinLock for each result block. > > > > + // > > > > + for (Index =3D 0; Index < mBlockNum; Index++) { > > > > + InitializeSpinLock (&mSpinLockList[Index]); > > > > + } > > > > + > > > > + // > > > > + // Dispatch blocklist to each AP. > > > > + // > > > > + if (gMmst !=3D NULL) { > > > > + MmDispatchBlockToAP (); > > > > + } > > > > + > > > > + // > > > > + // Wait until all block hash completed. > > > > + // > > > > + do { > > > > + AllCompleted =3D TRUE; > > > > + for (Index =3D 0; Index < mBlockNum; Index++) { > > > > + if (AcquireSpinLockOrFail (&mSpinLockList[Index])) { > > > > + if (!mBlockIsCompleted[Index]) { > > > > + AllCompleted =3D FALSE; > > > > + ReturnValue =3D CShake256HashAll ( > > > > + mInput + Index * mBlockSize, > > > > + (Index =3D=3D (mBlockNum - 1)) ? mLastBlock= Size : mBlockSize, > > > > + mBlockResultSize, > > > > + NULL, > > > > + 0, > > > > + NULL, > > > > + 0, > > > > + mBlockHashResult + Index * mBlockResultSize > > > > + ); > > > > + if (ReturnValue) { > > > > + mBlockIsCompleted[Index] =3D TRUE; > > > > + } > > > > + > > > > + ReleaseSpinLock (&mSpinLockList[Index]); > > > > + break; > > > > + } > > > > + > > > > + ReleaseSpinLock (&mSpinLockList[Index]); > > > > + } else { > > > > + AllCompleted =3D FALSE; > > > > + break; > > > > + } > > > > + } > > > > + } while (!AllCompleted); > > > > + > > > > + // > > > > + // Fill LeftEncode(n). > > > > + // > > > > + Offset =3D EncSizeB + mBlockNum * mBlockResultSize; > > > > + CopyMem (CombinedInput + Offset, EncBufN, EncSizeN); > > > > + > > > > + // > > > > + // Fill LeftEncode(L). > > > > + // > > > > + Offset +=3D EncSizeN; > > > > + CopyMem (CombinedInput + Offset, EncBufL, EncSizeL); > > > > + > > > > + ReturnValue =3D CShake256HashAll ( > > > > + CombinedInput, > > > > + CombinedInputSize, > > > > + OutputByteLen, > > > > + PARALLELHASH_CUSTOMIZATION, > > > > + AsciiStrLen (PARALLELHASH_CUSTOMIZATION), > > > > + Customization, > > > > + CustomByteLen, > > > > + Output > > > > + ); > > > > + > > > > +Exit: > > > > + ZeroMem (CombinedInput, CombinedInputSize); > > > > + > > > > + if (CombinedInput !=3D NULL) { > > > > + FreePool (CombinedInput); > > > > + } > > > > + > > > > + if (mSpinLockList !=3D NULL) { > > > > + FreePool ((VOID *)mSpinLockList); > > > > + } > > > > + > > > > + if (mBlockIsCompleted !=3D NULL) { > > > > + FreePool (mBlockIsCompleted); > > > > + } > > > > + > > > > + return ReturnValue; > > > > +} > > > > diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c > > b/CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c > > new file mode 100644 > > index 000000000000..1b9b61a7b629 > > --- /dev/null > > +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c > > @@ -0,0 +1,166 @@ > > +/** @file > > > > + SHA3 realted functions from OpenSSL. > > > > + > > > > + Copyright (c) 2022, Intel Corporation. All rights reserved.
> > > > + SPDX-License-Identifier: BSD-2-Clause-Patent > > > > + > > > > + Copyright 2022 The OpenSSL Project Authors. All Rights Reserved. > > > > + Licensed under the OpenSSL license (the "License"). You may not use > > > > + this file except in compliance with the License. You can obtain a c= opy > > > > + in the file LICENSE in the source distribution or at > > > > + https://www.openssl.org/source/license.html > > > > +**/ > > > > + > > > > +#include "InternalCryptLib.h" > > > > + > > > > +/** > > > > + Keccak initial fuction. > > > > + > > > > + Set up state with specified capacity. > > > > + > > > > + @param[out] Context Pointer to the context being initializ= ed. > > > > + @param[in] Pad Delimited Suffix. > > > > + @param[in] BlockSize Size of context block. > > > > + @param[in] MessageDigestLen Size of message digest in bytes. > > > > + > > > > + @retval 1 Initialize successfully. > > > > + @retval 0 Fail to initialize. > > > > +**/ > > > > +UINT8 > > > > +EFIAPI > > > > +KeccakInit ( > > > > + OUT Keccak1600_Ctx *Context, > > > > + IN UINT8 Pad, > > > > + IN UINTN BlockSize, > > > > + IN UINTN MessageDigestLen > > > > + ) > > > > +{ > > > > + if (BlockSize <=3D sizeof (Context->buf)) { > > > > + memset (Context->A, 0, sizeof (Context->A)); > > > > + > > > > + Context->num =3D 0; > > > > + Context->block_size =3D BlockSize; > > > > + Context->md_size =3D MessageDigestLen; > > > > + Context->pad =3D Pad; > > > > + > > > > + return 1; > > > > + } > > > > + > > > > + return 0; > > > > +} > > > > + > > > > +/** > > > > + Sha3 update fuction. > > > > + > > > > + This function performs Sha3 digest on a data buffer of the specified= size. > > > > + It can be called multiple times to compute the digest of long or > discontinuous > > data streams. > > > > + > > > > + @param[in,out] Context Pointer to the Keccak context. > > > > + @param[in] Data Pointer to the buffer containing the data t= o be > hashed. > > > > + @param[in] DataSize Size of Data buffer in bytes. > > > > + > > > > + @retval 1 Update successfully. > > > > +**/ > > > > +UINT8 > > > > +EFIAPI > > > > +Sha3Update ( > > > > + IN OUT Keccak1600_Ctx *Context, > > > > + IN const VOID *Data, > > > > + IN UINTN DataSize > > > > + ) > > > > +{ > > > > + const UINT8 *DataCopy; > > > > + UINTN BlockSize; > > > > + UINTN Num; > > > > + UINTN Rem; > > > > + > > > > + DataCopy =3D Data; > > > > + BlockSize =3D (UINT8)(Context->block_size); > > > > + > > > > + if (DataSize =3D=3D 0) { > > > > + return 1; > > > > + } > > > > + > > > > + if ((Num =3D Context->num) !=3D 0) { > > > > + // > > > > + // process intermediate buffer > > > > + // > > > > + Rem =3D BlockSize - Num; > > > > + > > > > + if (DataSize < Rem) { > > > > + memcpy (Context->buf + Num, DataCopy, DataSize); > > > > + Context->num +=3D DataSize; > > > > + return 1; > > > > + } > > > > + > > > > + // > > > > + // We have enough data to fill or overflow the intermediate > > > > + // buffer. So we append |Rem| bytes and process the block, > > > > + // leaving the rest for later processing. > > > > + // > > > > + memcpy (Context->buf + Num, DataCopy, Rem); > > > > + DataCopy +=3D Rem; > > > > + DataSize -=3D Rem; > > > > + (void)SHA3_absorb (Context->A, Context->buf, BlockSize, BlockSize)= ; > > > > + Context->num =3D 0; > > > > + // Context->buf is processed, Context->num is guaranteed to be zer= o. > > > > + } > > > > + > > > > + if (DataSize >=3D BlockSize) { > > > > + Rem =3D SHA3_absorb (Context->A, DataCopy, DataSize, BlockSize); > > > > + } else { > > > > + Rem =3D DataSize; > > > > + } > > > > + > > > > + if (Rem > 0) { > > > > + memcpy (Context->buf, DataCopy + DataSize - Rem, Rem); > > > > + Context->num =3D Rem; > > > > + } > > > > + > > > > + return 1; > > > > +} > > > > + > > > > +/** > > > > + Completes computation of Sha3 message digest. > > > > + > > > > + This function completes sha3 hash computation and retrieves the dige= st > value > > into > > > > + the specified memory. After this function has been called, the kecca= k > context > > cannot > > > > + be used again. > > > > + > > > > + @param[in, out] Context Pointer to the keccak context. > > > > + @param[out] MessageDigest Pointer to a buffer that receives th= e > > message digest. > > > > + > > > > + @retval 1 Meaasge digest computation succeeded. > > > > +**/ > > > > +UINT8 > > > > +EFIAPI > > > > +Sha3Final ( > > > > + IN OUT Keccak1600_Ctx *Context, > > > > + OUT UINT8 *MessageDigest > > > > + ) > > > > +{ > > > > + UINTN BlockSize; > > > > + UINTN Num; > > > > + > > > > + BlockSize =3D Context->block_size; > > > > + Num =3D Context->num; > > > > + > > > > + if (Context->md_size =3D=3D 0) { > > > > + return 1; > > > > + } > > > > + > > > > + // > > > > + // Pad the data with 10*1. Note that |Num| can be |BlockSize - 1| > > > > + // in which case both byte operations below are performed on > > > > + // same byte. > > > > + // > > > > + memset (Context->buf + Num, 0, BlockSize - Num); > > > > + Context->buf[Num] =3D Context->pad; > > > > + Context->buf[BlockSize - 1] |=3D 0x80; > > > > + > > > > + (void)SHA3_absorb (Context->A, Context->buf, BlockSize, BlockSize); > > > > + > > > > + SHA3_squeeze (Context->A, MessageDigest, Context->md_size, > BlockSize); > > > > + > > > > + return 1; > > > > +} > > > > diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c > > b/CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c > > new file mode 100644 > > index 000000000000..3058289adc40 > > --- /dev/null > > +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c > > @@ -0,0 +1,107 @@ > > +/** @file > > > > + Encode realted functions from Xkcp. > > > > + > > > > + Copyright (c) 2022, Intel Corporation. All rights reserved.
> > > > + SPDX-License-Identifier: BSD-2-Clause-Patent > > > > + > > > > + Copyright 2022 The eXtended Keccak Code Package (XKCP) > > > > + https://github.com/XKCP/XKCP > > > > + Keccak, designed by Guido Bertoni, Joan Daemen, Michael Peeters and > Gilles > > Van Assche. > > > > + Implementation by the designers, hereby denoted as "the implementer"= . > > > > + For more information, feedback or questions, please refer to the Kec= cak > > Team website: > > > > + https://keccak.team/ > > > > + To the extent possible under law, the implementer has waived all > copyright > > > > + and related or neighboring rights to the source code in this file. > > > > + http://creativecommons.org/publicdomain/zero/1.0/ > > > > + > > > > +**/ > > > > + > > > > +#include "InternalCryptLib.h" > > > > + > > > > +/** > > > > + Encode function from XKCP. > > > > + > > > > + Encodes the input as a byte string in a way that can be unambiguousl= y > parsed > > > > + from the beginning of the string by inserting the length of the byte= string > > > > + before the byte string representation of input. > > > > + > > > > + @param[out] EncBuf Result of left encode. > > > > + @param[in] Value Input of left encode. > > > > + > > > > + @retval EncLen Size of encode result in bytes. > > > > +**/ > > > > +UINTN > > > > +EFIAPI > > > > +LeftEncode ( > > > > + OUT UINT8 *EncBuf, > > > > + IN UINTN Value > > > > + ) > > > > +{ > > > > + UINT32 BlockNum; > > > > + UINT32 EncLen; > > > > + UINT32 Index; > > > > + UINTN ValueCopy; > > > > + > > > > + for ( ValueCopy =3D Value, BlockNum =3D 0; ValueCopy && (BlockNum < > sizeof > > (UINTN)); ++BlockNum, ValueCopy >>=3D 8 ) { > > > > + // > > > > + // Empty > > > > + // > > > > + } > > > > + > > > > + if (BlockNum =3D=3D 0) { > > > > + BlockNum =3D 1; > > > > + } > > > > + > > > > + for (Index =3D 1; Index <=3D BlockNum; ++Index) { > > > > + EncBuf[Index] =3D (UINT8)(Value >> (8 * (BlockNum - Index))); > > > > + } > > > > + > > > > + EncBuf[0] =3D (UINT8)BlockNum; > > > > + EncLen =3D BlockNum + 1; > > > > + > > > > + return EncLen; > > > > +} > > > > + > > > > +/** > > > > + Encode function from XKCP. > > > > + > > > > + Encodes the input as a byte string in a way that can be unambiguousl= y > parsed > > > > + from the end of the string by inserting the length of the byte strin= g after > > > > + the byte string representation of input. > > > > + > > > > + @param[out] EncBuf Result of right encode. > > > > + @param[in] Value Input of right encode. > > > > + > > > > + @retval EncLen Size of encode result in bytes. > > > > +**/ > > > > +UINTN > > > > +EFIAPI > > > > +RightEncode ( > > > > + OUT UINT8 *EncBuf, > > > > + IN UINTN Value > > > > + ) > > > > +{ > > > > + UINT32 BlockNum; > > > > + UINT32 EncLen; > > > > + UINT32 Index; > > > > + UINTN ValueCopy; > > > > + > > > > + for (ValueCopy =3D Value, BlockNum =3D 0; ValueCopy && (BlockNum < > sizeof > > (UINTN)); ++BlockNum, ValueCopy >>=3D 8) { > > > > + // > > > > + // Empty > > > > + // > > > > + } > > > > + > > > > + if (BlockNum =3D=3D 0) { > > > > + BlockNum =3D 1; > > > > + } > > > > + > > > > + for (Index =3D 1; Index <=3D BlockNum; ++Index) { > > > > + EncBuf[Index-1] =3D (UINT8)(Value >> (8 * (BlockNum-Index))); > > > > + } > > > > + > > > > + EncBuf[BlockNum] =3D (UINT8)BlockNum; > > > > + EncLen =3D BlockNum + 1; > > > > + > > > > + return EncLen; > > > > +} > > > > diff --git > a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests.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 > > > > + Application for Parallelhash Function Validation. > > > > + > > > > +Copyright (c) 2022, Intel Corporation. All rights reserved.
> > > > +SPDX-License-Identifier: BSD-2-Clause-Patent > > > > + > > > > +**/ > > > > + > > > > +#include "TestBaseCryptLib.h" > > > > + > > > > +// > > > > +// Parallelhash Test Sample common parameters. > > > > +// > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINTN OutputByteLen =3D > 64; > > > > + > > > > +// > > > > +// Parallelhash Test Sample #1 from NIST Special Publication 800-185. > > > > +// > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 InputSample1[] =3D { > > > > + // input data of sample1. > > > > + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x= 13, > 0x14, > > 0x15, 0x16, 0x17, > > > > + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27 > > > > +}; > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN InputSample1ByteLen > =3D 24; > > // Length of sample1 input data in bytes. > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID > *CustomizationSample1 > > =3D ""; // Customization string (S) of sample1. > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN > CustomSample1ByteLen =3D 0; > > // Customization string length of sample1 in bytes. > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample1 =3D 8= ; > > // Block size of sample1. > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 > ExpectOutputSample1[] > > =3D { > > > > + // Expected output data of sample1. > > > > + 0xbc, 0x1e, 0xf1, 0x24, 0xda, 0x34, 0x49, 0x5e, 0x94, 0x8e, 0xad, 0x= 20, > 0x7d, > > 0xd9, 0x84, 0x22, > > > > + 0x35, 0xda, 0x43, 0x2d, 0x2b, 0xbc, 0x54, 0xb4, 0xc1, 0x10, 0xe6, 0x= 4c, > 0x45, > > 0x11, 0x05, 0x53, > > > > + 0x1b, 0x7f, 0x2a, 0x3e, 0x0c, 0xe0, 0x55, 0xc0, 0x28, 0x05, 0xe7, 0x= c2, > 0xde, > > 0x1f, 0xb7, 0x46, > > > > + 0xaf, 0x97, 0xa1, 0xd0, 0x01, 0xf4, 0x3b, 0x82, 0x4e, 0x31, 0xb8, 0x= 76, > 0x12, > > 0x41, 0x04, 0x29 > > > > +}; > > > > + > > > > +// > > > > +// Parallelhash Test Sample #2 from NIST Special Publication 800-185. > > > > +// > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 *InputSample2 > =3D > > InputSample1; // Input of sample2 is same as sample1. > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN InputSample2ByteLen > =3D 24; > > // Length of sample2 input data in bytes. > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID > *CustomizationSample2 > > =3D "Parallel Data"; // Customization string (S) of sample2. > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN > CustomSample2ByteLen =3D > > 13; // Customization string length of sample2 i= n bytes. > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample2 =3D 8= ; > > // Block size of sample2. > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 > ExpectOutputSample2[] > > =3D { > > > > + // Expected output data of sample2. > > > > + 0xcd, 0xf1, 0x52, 0x89, 0xb5, 0x4f, 0x62, 0x12, 0xb4, 0xbc, 0x27, 0x= 05, > 0x28, > > 0xb4, 0x95, 0x26, > > > > + 0x00, 0x6d, 0xd9, 0xb5, 0x4e, 0x2b, 0x6a, 0xdd, 0x1e, 0xf6, 0x90, 0x= 0d, > 0xda, > > 0x39, 0x63, 0xbb, > > > > + 0x33, 0xa7, 0x24, 0x91, 0xf2, 0x36, 0x96, 0x9c, 0xa8, 0xaf, 0xae, 0x= a2, 0x9c, > > 0x68, 0x2d, 0x47, > > > > + 0xa3, 0x93, 0xc0, 0x65, 0xb3, 0x8e, 0x29, 0xfa, 0xe6, 0x51, 0xa2, 0x= 09, > 0x1c, > > 0x83, 0x31, 0x10 > > > > +}; > > > > + > > > > +// > > > > +// Parallelhash Test Sample #3 from NIST Special Publication 800-185. > > > > +// > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 InputSample3[] =3D { > > > > + // input data of sample3. > > > > + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x= 0b, > 0x10, > > 0x11, 0x12, 0x13, > > > > + 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x20, 0x21, 0x22, 0x= 23, > 0x24, > > 0x25, 0x26, 0x27, > > > > + 0x28, 0x29, 0x2a, 0x2b, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x= 37, > 0x38, > > 0x39, 0x3a, 0x3b, > > > > + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x= 4b, > 0x50, > > 0x51, 0x52, 0x53, > > > > + 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b > > > > +}; > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN InputSample3ByteLen > =3D 72; > > // Length of sample3 input data in bytes. > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID > *CustomizationSample3 > > =3D "Parallel Data"; // Customization string (S) of sample3. > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN > CustomSample3ByteLen =3D > > 13; // Customization string length of sample3 i= n bytes. > > > > +GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample3 =3D > 12; > > // Block size of sample3. > > > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 > ExpectOutputSample3[] > > =3D { > > > > + // Expected output data of sample3. > > > > + 0x69, 0xd0, 0xfc, 0xb7, 0x64, 0xea, 0x05, 0x5d, 0xd0, 0x93, 0x34, 0x= bc, > 0x60, > > 0x21, 0xcb, 0x7e, > > > > + 0x4b, 0x61, 0x34, 0x8d, 0xff, 0x37, 0x5d, 0xa2, 0x62, 0x67, 0x1c, 0x= de, > 0xc3, > > 0xef, 0xfa, 0x8d, > > > > + 0x1b, 0x45, 0x68, 0xa6, 0xcc, 0xe1, 0x6b, 0x1c, 0xad, 0x94, 0x6d, 0x= dd, > 0xe2, > > 0x7f, 0x6c, 0xe2, > > > > + 0xb8, 0xde, 0xe4, 0xcd, 0x1b, 0x24, 0x85, 0x1e, 0xbf, 0x00, 0xeb, 0x= 90, > 0xd4, > > 0x38, 0x13, 0xe9 > > > > +}; > > > > + > > > > +UNIT_TEST_STATUS > > > > +EFIAPI > > > > +TestVerifyParallelHash256HashAll ( > > > > + IN UNIT_TEST_CONTEXT Context > > > > + ) > > > > +{ > > > > + BOOLEAN Status; > > > > + UINT8 Output[64]; > > > > + > > > > + // > > > > + // Test #1 using sample1. > > > > + // > > > > + Status =3D ParallelHash256HashAll ( > > > > + InputSample1, > > > > + InputSample1ByteLen, > > > > + BlockSizeSample1, > > > > + Output, > > > > + OutputByteLen, > > > > + CustomizationSample1, > > > > + CustomSample1ByteLen > > > > + ); > > > > + UT_ASSERT_TRUE (Status); > > > > + > > > > + // Check the output with the expected output. > > > > + UT_ASSERT_MEM_EQUAL (Output, ExpectOutputSample1, > OutputByteLen); > > > > + > > > > + // > > > > + // Test #2 using sample2. > > > > + // > > > > + Status =3D ParallelHash256HashAll ( > > > > + InputSample2, > > > > + InputSample2ByteLen, > > > > + BlockSizeSample2, > > > > + Output, > > > > + OutputByteLen, > > > > + CustomizationSample2, > > > > + CustomSample2ByteLen > > > > + ); > > > > + UT_ASSERT_TRUE (Status); > > > > + > > > > + // Check the output with the expected output. > > > > + UT_ASSERT_MEM_EQUAL (Output, ExpectOutputSample2, > OutputByteLen); > > > > + > > > > + // > > > > + // Test #3 using sample3. > > > > + // > > > > + Status =3D ParallelHash256HashAll ( > > > > + InputSample3, > > > > + InputSample3ByteLen, > > > > + BlockSizeSample3, > > > > + Output, > > > > + OutputByteLen, > > > > + CustomizationSample3, > > > > + CustomSample3ByteLen > > > > + ); > > > > + UT_ASSERT_TRUE (Status); > > > > + > > > > + // Check the output with the expected output. > > > > + UT_ASSERT_MEM_EQUAL (Output, ExpectOutputSample3, > OutputByteLen); > > > > + > > > > + return EFI_SUCCESS; > > > > +} > > > > + > > > > +TEST_DESC mParallelhashTest[] =3D { > > > > + // > > > > + // -----Description------------------------------Class--------------= -------- > Function---- > > -------------Pre---Post--Context > > > > + // > > > > + { "TestVerifyParallelHash256HashAll()", > > "CryptoPkg.BaseCryptLib.ParallelHash256HashAll", > > TestVerifyParallelHash256HashAll, NULL, NULL, NULL }, > > > > +}; > > > > + > > > > +UINTN mParallelhashTestNum =3D ARRAY_SIZE (mParallelhashTest); > > > > diff --git a/CryptoPkg/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 s= ecurity > > > > functionality enabling. > > > > > > > > -Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.
> > > > +Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.
> > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > **/ > > > > @@ -753,6 +753,35 @@ Sha512HashAll ( > > OUT UINT8 *HashValue > > > > ); > > > > > > > > +/** > > > > + Parallel hash function ParallelHash256, as defined in NIST's Special > Publication > > 800-185, > > > > + published December 2016. > > > > + > > > > + @param[in] Input Pointer to the input message (X). > > > > + @param[in] InputByteLen The number(>0) of input bytes provided > for the > > input data. > > > > + @param[in] BlockSize The size of each block (B). > > > > + @param[out] Output Pointer to the output buffer. > > > > + @param[in] OutputByteLen The desired number of output bytes (L)= . > > > > + @param[in] Customization Pointer to the customization string (S= ). > > > > + @param[in] CustomByteLen The length of the customization string= in > bytes. > > > > + > > > > + @retval TRUE ParallelHash256 digest computation succeeded. > > > > + @retval FALSE ParallelHash256 digest computation failed. > > > > + @retval FALSE This interface is not supported. > > > > + > > > > +**/ > > > > +BOOLEAN > > > > +EFIAPI > > > > +ParallelHash256HashAll ( > > > > + IN CONST VOID *Input, > > > > + IN UINTN InputByteLen, > > > > + IN UINTN BlockSize, > > > > + OUT VOID *Output, > > > > + IN UINTN OutputByteLen, > > > > + IN CONST VOID *Customization, > > > > + IN UINTN CustomByteLen > > > > + ); > > > > + > > > > /** > > > > Retrieves the size, in bytes, of the context buffer required for SM3= hash > > operations. > > > > > > > > diff --git a/CryptoPkg/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- > Hellman > > functions, and > > > > # authenticode signature verification functions are not supported in = this > > instance. > > > > # > > > > -# Copyright (c) 2010 - 2021, Intel Corporation. All rights reserved.<= BR> > > > > +# Copyright (c) 2010 - 2022, Intel Corporation. All rights reserved.<= BR> > > > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > > > # > > > > ## > > > > @@ -38,6 +38,10 @@ > > Hash/CryptSha256.c > > > > Hash/CryptSm3.c > > > > Hash/CryptSha512.c > > > > + Hash/CryptSha3.c > > > > + Hash/CryptXkcp.c > > > > + Hash/CryptCShake256.c > > > > + Hash/CryptParallelHash.c > > > > Hmac/CryptHmacSha256.c > > > > Kdf/CryptHkdfNull.c > > > > Cipher/CryptAes.c > > > > @@ -85,6 +89,8 @@ > > OpensslLib > > > > IntrinsicLib > > > > PrintLib > > > > + MmServicesTableLib > > > > + SynchronizationLib > > > > > > > > # > > > > # Remove these [BuildOptions] after this library is cleaned up > > > > diff --git a/CryptoPkg/Library/Include/CrtLibSupport.h > > b/CryptoPkg/Library/Include/CrtLibSupport.h > > index d257dca8fa9b..3471f7429206 100644 > > --- a/CryptoPkg/Library/Include/CrtLibSupport.h > > +++ b/CryptoPkg/Library/Include/CrtLibSupport.h > > @@ -2,9 +2,14 @@ > > Root include file of C runtime library to support building the third= -party > > > > cryptographic library. > > > > > > > > -Copyright (c) 2010 - 2021, Intel Corporation. All rights reserved.
> > > > +Copyright (c) 2010 - 2022, Intel Corporation. All rights reserved.
> > > > Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rig= hts > > reserved.
> > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > +Copyright 2017-2022 The OpenSSL Project Authors. All Rights Reserved. > > > > +Licensed under the OpenSSL license (the "License"). You may not use > > > > +this file except in compliance with the License. You can obtain a cop= y > > > > +in the file LICENSE in the source distribution or at > > > > +https://www.openssl.org/source/license.html > > > > > > > > **/ > > > > > > > > @@ -21,6 +26,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > #define MAX_STRING_SIZE 0x1000 > > > > > > > > +#define KECCAK1600_WIDTH 1600 > > > > + > > > > // > > > > // We already have "no-ui" in out Configure invocation. > > > > // but the code still fails to compile. > > > > @@ -111,6 +118,7 @@ typedef UINT8 u_char; > > typedef UINT32 uid_t; > > > > typedef UINT32 gid_t; > > > > typedef CHAR16 wchar_t; > > > > +typedef UINT64 uint64_t; > > > > > > > > // > > > > // File operations are not required for EFI building, > > > > @@ -118,6 +126,18 @@ typedef CHAR16 wchar_t; > > // > > > > typedef VOID *FILE; > > > > > > > > +// > > > > +// This struct referring to m_sha3.c from opessl and modified its type > name. > > > > +// > > > > +typedef struct { > > > > + uint64_t A[5][5]; > > > > + size_t block_size; /* cached ctx->digest->block_size */ > > > > + size_t md_size; /* output length, variable in XOF */ > > > > + size_t num; /* used bytes in below buffer */ > > > > + unsigned char buf[KECCAK1600_WIDTH / 8 - 32]; > > > > + unsigned char pad; > > > > +} Keccak1600_Ctx; > > > > + > > > > // > > > > // Structures Definitions > > > > // > > > > @@ -371,6 +391,22 @@ secure_getenv ( > > const char * > > > > ); > > > > > > > > +size_t > > > > +SHA3_absorb ( > > > > + uint64_t A[5][5], > > > > + const unsigned char *inp, > > > > + size_t len, > > > > + size_t r > > > > + ); > > > > + > > > > +void > > > > +SHA3_squeeze ( > > > > + uint64_t A[5][5], > > > > + unsigned char *out, > > > > + size_t len, > > > > + size_t r > > > > + ); > > > > + > > > > #if defined (__GNUC__) && (__GNUC__ >=3D 2) > > > > void > > > > abort ( > > > > 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] > > > > OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf > > > > > BaseCryptLib|CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf > > > > + > > > MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTabl > eLib > > .inf > > > > + > > > SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchroniz > ati > > onLib.inf > > > > + > > > TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTem > plat > > e.inf > > > > > > > > [LibraryClasses.AARCH64, LibraryClasses.ARM] > > > > RngLib|MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf > > > > diff --git > > a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf > > b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf > > index 00c869265080..399db596c2d1 100644 > > --- > a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf > > +++ > b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf > > @@ -2,6 +2,7 @@ > > # Host-based UnitTest for BaseCryptLib > > > > # > > > > # Copyright (c) Microsoft Corporation.
> > > > +# Copyright (c) 2022, Intel Corporation. All rights reserved.
> > > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > > > ## > > > > > > > > @@ -35,6 +36,7 @@ > > Pkcs7EkuTests.c > > > > OaepEncryptTests.c > > > > RsaPssTests.c > > > > + ParallelhashTests.c > > > > > > > > [Packages] > > > > MdePkg/MdePkg.dec > > > > @@ -45,3 +47,5 @@ > > DebugLib > > > > BaseCryptLib > > > > UnitTestLib > > > > + MmServicesTableLib > > > > + SynchronizationLib > > > > -- > > 2.26.2.windows.1