From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web09.6707.1647491674430942961 for ; Wed, 16 Mar 2022 21:34:35 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=eas1xcAH; spf=pass (domain: intel.com, ip: 134.134.136.126, 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=1647491674; x=1679027674; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=3K9iMpNyxMfTgqShNg1hXcUhXMJkr9hcgp2PR8tNoo0=; b=eas1xcAHEEpy+BU2nj7vdv2yuj/7nqDPaZKEz95rWWITCJG75rU0Bqvn PD1ntHcAYUztcf1Gw1UEj02IOQRuTyj7vQYoQCLrxDP+rzQ4G2DRuaPpN m1N7i/mq9NWCFjYx//nJ0bIlre10EN37rmwhU6HKWfnr3QPMLYPeoogOb fB2qzjpuCzCUpwsNxfEBWPAouvPTX95EpWakd02hzNpBalvzJlyvDBpJB WoTDXxIzA7LSoQDPkhhxlsGZBvQR6WnaMvnseBKl/TDyV9OlMYYUdpuTb Ol0BtQpfg6Jn3eFRQSXVRqx6wKc3u/6C+qe8VxBmCjmHdg0R06zmh/1Bm A==; X-IronPort-AV: E=McAfee;i="6200,9189,10288"; a="238942391" X-IronPort-AV: E=Sophos;i="5.90,188,1643702400"; d="scan'208";a="238942391" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2022 21:34:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,188,1643702400"; d="scan'208";a="541217401" Received: from win_li.ccr.corp.intel.com ([10.239.157.34]) by orsmga007.jf.intel.com with ESMTP; 16 Mar 2022 21:34:31 -0700 From: "Li, Zhihao" To: devel@edk2.groups.io Cc: Jiewen Yao , Jian J Wang , Xiaoyu Lu , Guomin Jiang , Siyuan Fu Subject: [PATCH v6 1/1] CryptoPkg: Add new hash algorithm ParallelHash256HashAll in BaseCryptLib. Date: Thu, 17 Mar 2022 12:34:30 +0800 Message-Id: <20220317043430.1002-1-zhihao.li@intel.com> X-Mailer: git-send-email 2.26.2.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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. Passed CI test. Onprotocol version code passed test. Cc: Jiewen Yao Cc: Jian J Wang Cc: Xiaoyu Lu Cc: Guomin Jiang Cc: Siyuan Fu Cc: Zhihao Li Signed-off-by: Zhihao Li --- CryptoPkg/Driver/Crypto.c | 3= 8 ++- CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c | 28= 2 ++++++++++++++++++++ CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c | 27= 8 +++++++++++++++++++ CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHashNull.c | 4= 0 +++ CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c | 16= 6 ++++++++++++ CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c | 10= 7 ++++++++ CryptoPkg/Library/BaseCryptLibNull/Hash/CryptParallelHashNull.c | 4= 0 +++ CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c | 3= 4 ++- CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests.c | 14= 5 ++++++++++ CryptoPkg/CryptoPkg.ci.yaml | = 4 +- CryptoPkg/Include/Library/BaseCryptLib.h | 3= 1 ++- CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h | = 8 +- CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf | = 3 +- CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h | 20= 1 ++++++++++++++ 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 | 3= 5 ++- CryptoPkg/Test/CryptoPkgHostUnitTest.dsc | = 4 + CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf | = 4 + 22 files changed, 1426 insertions(+), 14 deletions(-) diff --git a/CryptoPkg/Driver/Crypto.c b/CryptoPkg/Driver/Crypto.c index d5d6aa8e5820..5a9245c07cc5 100644 --- a/CryptoPkg/Driver/Crypto.c +++ b/CryptoPkg/Driver/Crypto.c @@ -3,7 +3,7 @@ from BaseCryptLib and TlsLib.=0D =0D Copyright (C) Microsoft Corporation. All rights reserved.=0D - Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.
=0D + Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D @@ -4470,6 +4470,38 @@ CryptoServiceTlsGetCertRevocationList ( return CALL_BASECRYPTLIB (TlsGet.Services.CertRevocationList, TlsGetCert= RevocationList, (Data, DataSize), EFI_UNSUPPORTED);=0D }=0D =0D +/**=0D + Parallel hash function ParallelHash256, as defined in NIST's Special Pub= lication 800-185,=0D + published December 2016.=0D +=0D + @param[in] Input Pointer to the input message (X).=0D + @param[in] InputByteLen The number(>0) of input bytes provided for= the input data.=0D + @param[in] BlockSize The size of each block (B).=0D + @param[out] Output Pointer to the output buffer.=0D + @param[in] OutputByteLen The desired number of output bytes (L).=0D + @param[in] Customization Pointer to the customization string (S).=0D + @param[in] CustomByteLen The length of the customization string in = bytes.=0D +=0D + @retval TRUE ParallelHash256 digest computation succeeded.=0D + @retval FALSE ParallelHash256 digest computation failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +CryptoServiceParallelHash256HashAll (=0D + IN CONST VOID *Input,=0D + IN UINTN InputByteLen,=0D + IN UINTN BlockSize,=0D + OUT VOID *Output,=0D + IN UINTN OutputByteLen,=0D + IN CONST VOID *Customization,=0D + IN UINTN CustomByteLen=0D + )=0D +{=0D + return CALL_BASECRYPTLIB (ParallelHash.Services.HashAll, ParallelHash256= HashAll, (Input, InputByteLen, BlockSize, Output, OutputByteLen, Customizat= ion, CustomByteLen), FALSE);=0D +}=0D +=0D const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto =3D {=0D /// Version=0D CryptoServiceGetCryptoVersion,=0D @@ -4670,5 +4702,7 @@ const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto =3D { CryptoServiceTlsGetCaCertificate,=0D CryptoServiceTlsGetHostPublicCert,=0D CryptoServiceTlsGetHostPrivateKey,=0D - CryptoServiceTlsGetCertRevocationList=0D + CryptoServiceTlsGetCertRevocationList,=0D + /// Parallel hash=0D + CryptoServiceParallelHash256HashAll=0D };=0D diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c b/CryptoP= kg/Library/BaseCryptLib/Hash/CryptCShake256.c new file mode 100644 index 000000000000..2a9eaf9eec40 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c @@ -0,0 +1,282 @@ +/** @file=0D + cSHAKE-256 Digest Wrapper Implementations.=0D +=0D +Copyright (c) 2022, Intel Corporation. All rights reserved.
=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include "CryptParallelHash.h"=0D +=0D +#define CSHAKE256_SECURITY_STRENGTH 256=0D +#define CSHAKE256_RATE_IN_BYTES 136=0D +=0D +CONST CHAR8 mZeroPadding[CSHAKE256_RATE_IN_BYTES] =3D { 0 };=0D +=0D +/**=0D + CShake256 initial function.=0D +=0D + Initializes user-supplied memory pointed by CShake256Context as cSHAKE-2= 56 hash context for=0D + subsequent use.=0D +=0D + @param[out] CShake256Context Pointer to cSHAKE-256 context being initia= lized.=0D + @param[in] OutputLen The desired number of output length in byt= es.=0D + @param[in] Name Pointer to the function name string.=0D + @param[in] NameLen The length of the function name in bytes.= =0D + @param[in] Customization Pointer to the customization string.=0D + @param[in] CustomizationLen The length of the customization string in = bytes.=0D +=0D + @retval TRUE cSHAKE-256 context initialization succeeded.=0D + @retval FALSE cSHAKE-256 context initialization failed.=0D + @retval FALSE This interface is not supported.=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +CShake256Init (=0D + OUT VOID *CShake256Context,=0D + IN UINTN OutputLen,=0D + IN CONST VOID *Name,=0D + IN UINTN NameLen,=0D + IN CONST VOID *Customization,=0D + IN UINTN CustomizationLen=0D + )=0D +{=0D + BOOLEAN Status;=0D + UINT8 EncBuf[sizeof (UINTN) + 1];=0D + UINTN EncLen;=0D + UINTN AbsorbLen;=0D + UINTN PadLen;=0D +=0D + //=0D + // Check input parameters.=0D + //=0D + if ((CShake256Context =3D=3D NULL) || (OutputLen =3D=3D 0) || ((NameLen = !=3D 0) && (Name =3D=3D NULL)) || ((CustomizationLen !=3D 0) && (Customizat= ion =3D=3D NULL))) {=0D + return FALSE;=0D + }=0D +=0D + //=0D + // Initialize KECCAK context with pad value and block size.=0D + //=0D + if ((NameLen =3D=3D 0) && (CustomizationLen =3D=3D 0)) {=0D + //=0D + // When N and S are both empty strings, cSHAKE(X, L, N, S) is equivale= nt to=0D + // SHAKE as defined in FIPS 202.=0D + //=0D + Status =3D (BOOLEAN)KeccakInit (=0D + (Keccak1600_Ctx *)CShake256Context,=0D + '\x1f',=0D + (KECCAK1600_WIDTH - CSHAKE256_SECURITY_STRENGTH * = 2) / 8,=0D + OutputLen=0D + );=0D +=0D + return Status;=0D + } else {=0D + Status =3D (BOOLEAN)KeccakInit (=0D + (Keccak1600_Ctx *)CShake256Context,=0D + '\x04',=0D + (KECCAK1600_WIDTH - CSHAKE256_SECURITY_STRENGTH * = 2) / 8,=0D + OutputLen=0D + );=0D + if (!Status) {=0D + return FALSE;=0D + }=0D +=0D + AbsorbLen =3D 0;=0D + //=0D + // Absorb Absorb bytepad(.., rate).=0D + //=0D + EncLen =3D LeftEncode (EncBuf, CSHAKE256_RATE_IN_BYTES);=0D + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx *)CShake256Context, En= cBuf, EncLen);=0D + if (!Status) {=0D + return FALSE;=0D + }=0D +=0D + AbsorbLen +=3D EncLen;=0D +=0D + //=0D + // Absorb encode_string(N).=0D + //=0D + EncLen =3D LeftEncode (EncBuf, NameLen * 8);=0D + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx *)CShake256Context, En= cBuf, EncLen);=0D + if (!Status) {=0D + return FALSE;=0D + }=0D +=0D + AbsorbLen +=3D EncLen;=0D + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx *)CShake256Context= , Name, NameLen);=0D + if (!Status) {=0D + return FALSE;=0D + }=0D +=0D + AbsorbLen +=3D NameLen;=0D +=0D + //=0D + // Absorb encode_string(S).=0D + //=0D + EncLen =3D LeftEncode (EncBuf, CustomizationLen * 8);=0D + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx *)CShake256Context, En= cBuf, EncLen);=0D + if (!Status) {=0D + return FALSE;=0D + }=0D +=0D + AbsorbLen +=3D EncLen;=0D + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx *)CShake256Context= , Customization, CustomizationLen);=0D + if (!Status) {=0D + return FALSE;=0D + }=0D +=0D + AbsorbLen +=3D CustomizationLen;=0D +=0D + //=0D + // Absorb zero padding up to rate.=0D + //=0D + PadLen =3D CSHAKE256_RATE_IN_BYTES - AbsorbLen % CSHAKE256_RATE_IN_BYT= ES;=0D + Status =3D (BOOLEAN)Sha3Update ((Keccak1600_Ctx *)CShake256Context, mZ= eroPadding, PadLen);=0D + if (!Status) {=0D + return FALSE;=0D + }=0D +=0D + return TRUE;=0D + }=0D +}=0D +=0D +/**=0D + Digests the input data and updates cSHAKE-256 context.=0D +=0D + This function performs cSHAKE-256 digest on a data buffer of the specifi= ed size.=0D + It can be called multiple times to compute the digest of long or discont= inuous data streams.=0D + cSHAKE-256 context should be already correctly initialized by CShake256I= nit(), and should not be finalized=0D + by CShake256Final(). Behavior with invalid context is undefined.=0D +=0D + @param[in, out] CShake256Context Pointer to the cSHAKE-256 context.=0D + @param[in] Data Pointer to the buffer containing the= data to be hashed.=0D + @param[in] DataSize Size of Data buffer in bytes.=0D +=0D + @retval TRUE cSHAKE-256 data digest succeeded.=0D + @retval FALSE cSHAKE-256 data digest failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +CShake256Update (=0D + IN OUT VOID *CShake256Context,=0D + IN CONST VOID *Data,=0D + IN UINTN DataSize=0D + )=0D +{=0D + //=0D + // Check input parameters.=0D + //=0D + if (CShake256Context =3D=3D NULL) {=0D + return FALSE;=0D + }=0D +=0D + //=0D + // Check invalid parameters, in case that only DataLength was checked in= OpenSSL.=0D + //=0D + if ((Data =3D=3D NULL) && (DataSize !=3D 0)) {=0D + return FALSE;=0D + }=0D +=0D + return (BOOLEAN)(Sha3Update ((Keccak1600_Ctx *)CShake256Context, Data, D= ataSize));=0D +}=0D +=0D +/**=0D + Completes computation of the cSHAKE-256 digest value.=0D +=0D + This function completes cSHAKE-256 hash computation and retrieves the di= gest value into=0D + the specified memory. After this function has been called, the cSHAKE-25= 6 context cannot=0D + be used again.=0D + cSHAKE-256 context should be already correctly initialized by CShake256I= nit(), and should not be=0D + finalized by CShake256Final(). Behavior with invalid cSHAKE-256 context = is undefined.=0D +=0D + @param[in, out] CShake256Context Pointer to the cSHAKE-256 context.=0D + @param[out] HashValue Pointer to a buffer that receives the= cSHAKE-256 digest=0D + value.=0D +=0D + @retval TRUE cSHAKE-256 digest computation succeeded.=0D + @retval FALSE cSHAKE-256 digest computation failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +CShake256Final (=0D + IN OUT VOID *CShake256Context,=0D + OUT UINT8 *HashValue=0D + )=0D +{=0D + //=0D + // Check input parameters.=0D + //=0D + if ((CShake256Context =3D=3D NULL) || (HashValue =3D=3D NULL)) {=0D + return FALSE;=0D + }=0D +=0D + //=0D + // cSHAKE-256 Hash Finalization.=0D + //=0D + return (BOOLEAN)(Sha3Final ((Keccak1600_Ctx *)CShake256Context, HashValu= e));=0D +}=0D +=0D +/**=0D + Computes the CSHAKE-256 message digest of a input data buffer.=0D +=0D + This function performs the CSHAKE-256 message digest of a given data buf= fer, and places=0D + the digest value into the specified memory.=0D +=0D + @param[in] Data Pointer to the buffer containing the dat= a to be hashed.=0D + @param[in] DataSize Size of Data buffer in bytes.=0D + @param[in] OutputLen Size of output in bytes.=0D + @param[in] Name Pointer to the function name string.=0D + @param[in] NameLen Size of the function name in bytes.=0D + @param[in] Customization Pointer to the customization string.=0D + @param[in] CustomizationLen Size of the customization string in byte= s.=0D + @param[out] HashValue Pointer to a buffer that receives the CS= HAKE-256 digest=0D + value.=0D +=0D + @retval TRUE CSHAKE-256 digest computation succeeded.=0D + @retval FALSE CSHAKE-256 digest computation failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +CShake256HashAll (=0D + IN CONST VOID *Data,=0D + IN UINTN DataSize,=0D + IN UINTN OutputLen,=0D + IN CONST VOID *Name,=0D + IN UINTN NameLen,=0D + IN CONST VOID *Customization,=0D + IN UINTN CustomizationLen,=0D + OUT UINT8 *HashValue=0D + )=0D +{=0D + BOOLEAN Status;=0D + Keccak1600_Ctx Ctx;=0D +=0D + //=0D + // Check input parameters.=0D + //=0D + if (HashValue =3D=3D NULL) {=0D + return FALSE;=0D + }=0D +=0D + if ((Data =3D=3D NULL) && (DataSize !=3D 0)) {=0D + return FALSE;=0D + }=0D +=0D + Status =3D CShake256Init (&Ctx, OutputLen, Name, NameLen, Customization,= CustomizationLen);=0D + if (!Status) {=0D + return FALSE;=0D + }=0D +=0D + Status =3D CShake256Update (&Ctx, Data, DataSize);=0D + if (!Status) {=0D + return FALSE;=0D + }=0D +=0D + return CShake256Final (&Ctx, HashValue);=0D +}=0D diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c b/Cryp= toPkg/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=0D + ParallelHash Implementation.=0D +=0D +Copyright (c) 2022, Intel Corporation. All rights reserved.
=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include "CryptParallelHash.h"=0D +#include =0D +#include =0D +=0D +#define PARALLELHASH_CUSTOMIZATION "ParallelHash"=0D +=0D +UINTN mBlockNum;=0D +UINTN mBlockSize;=0D +UINTN mLastBlockSize;=0D +UINT8 *mInput;=0D +UINTN mBlockResultSize;=0D +UINT8 *mBlockHashResult;=0D +BOOLEAN *mBlockIsCompleted;=0D +SPIN_LOCK *mSpinLockList;=0D +=0D +/**=0D + Complete computation of digest of each block.=0D +=0D + Each AP perform the function called by BSP.=0D +=0D + @param[in] ProcedureArgument Argument of the procedure.=0D +**/=0D +VOID=0D +EFIAPI=0D +ParallelHashApExecute (=0D + IN VOID *ProcedureArgument=0D + )=0D +{=0D + UINTN Index;=0D + BOOLEAN Status;=0D +=0D + for (Index =3D 0; Index < mBlockNum; Index++) {=0D + if (AcquireSpinLockOrFail (&mSpinLockList[Index])) {=0D + //=0D + // Completed, try next one.=0D + //=0D + if (mBlockIsCompleted[Index]) {=0D + ReleaseSpinLock (&mSpinLockList[Index]);=0D + continue;=0D + }=0D +=0D + //=0D + // Calculate CShake256 for this block.=0D + //=0D + Status =3D CShake256HashAll (=0D + mInput + Index * mBlockSize,=0D + (Index =3D=3D (mBlockNum - 1)) ? mLastBlockSize : mBlockS= ize,=0D + mBlockResultSize,=0D + NULL,=0D + 0,=0D + NULL,=0D + 0,=0D + mBlockHashResult + Index * mBlockResultSize=0D + );=0D + if (!EFI_ERROR (Status)) {=0D + mBlockIsCompleted[Index] =3D TRUE;=0D + }=0D +=0D + ReleaseSpinLock (&mSpinLockList[Index]);=0D + }=0D + }=0D +}=0D +=0D +/**=0D + Dispatch the block task to each AP in SMM mode.=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +MmDispatchBlockToAP (=0D + VOID=0D + )=0D +{=0D + UINTN Index;=0D +=0D + for (Index =3D 0; Index < gMmst->NumberOfCpus; Index++) {=0D + if (Index !=3D gMmst->CurrentlyExecutingCpu) {=0D + gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NULL);=0D + }=0D + }=0D +=0D + return;=0D +}=0D +=0D +/**=0D + Parallel hash function ParallelHash256, as defined in NIST's Special Pub= lication 800-185,=0D + published December 2016.=0D +=0D + @param[in] Input Pointer to the input message (X).=0D + @param[in] InputByteLen The number(>0) of input bytes provided for= the input data.=0D + @param[in] BlockSize The size of each block (B).=0D + @param[out] Output Pointer to the output buffer.=0D + @param[in] OutputByteLen The desired number of output bytes (L).=0D + @param[in] Customization Pointer to the customization string (S).=0D + @param[in] CustomByteLen The length of the customization string in = bytes.=0D +=0D + @retval TRUE ParallelHash256 digest computation succeeded.=0D + @retval FALSE ParallelHash256 digest computation failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +ParallelHash256HashAll (=0D + IN CONST VOID *Input,=0D + IN UINTN InputByteLen,=0D + IN UINTN BlockSize,=0D + OUT VOID *Output,=0D + IN UINTN OutputByteLen,=0D + IN CONST VOID *Customization,=0D + IN UINTN CustomByteLen=0D + )=0D +{=0D + UINT8 EncBufB[sizeof (UINTN)+1];=0D + UINTN EncSizeB;=0D + UINT8 EncBufN[sizeof (UINTN)+1];=0D + UINTN EncSizeN;=0D + UINT8 EncBufL[sizeof (UINTN)+1];=0D + UINTN EncSizeL;=0D + UINTN Index;=0D + UINT8 *CombinedInput;=0D + UINTN CombinedInputSize;=0D + BOOLEAN AllCompleted;=0D + UINTN Offset;=0D + BOOLEAN ReturnValue;=0D +=0D + if ((InputByteLen =3D=3D 0) || (OutputByteLen =3D=3D 0) || (BlockSize = =3D=3D 0)) {=0D + return FALSE;=0D + }=0D +=0D + if ((Input =3D=3D NULL) || (Output =3D=3D NULL)) {=0D + return FALSE;=0D + }=0D +=0D + if ((CustomByteLen !=3D 0) && (Customization =3D=3D NULL)) {=0D + return FALSE;=0D + }=0D +=0D + mBlockSize =3D BlockSize;=0D +=0D + //=0D + // Calculate block number n.=0D + //=0D + mBlockNum =3D InputByteLen % mBlockSize =3D=3D 0 ? InputByteLen / mBlock= Size : InputByteLen / mBlockSize + 1;=0D +=0D + //=0D + // Set hash result size of each block in bytes.=0D + //=0D + mBlockResultSize =3D OutputByteLen;=0D +=0D + //=0D + // Encode B, n, L to string and record size.=0D + //=0D + EncSizeB =3D LeftEncode (EncBufB, mBlockSize);=0D + EncSizeN =3D RightEncode (EncBufN, mBlockNum);=0D + EncSizeL =3D RightEncode (EncBufL, OutputByteLen * CHAR_BIT);=0D +=0D + //=0D + // Allocate buffer for combined input (newX), Block completed flag and S= pinLock.=0D + //=0D + CombinedInputSize =3D EncSizeB + EncSizeN + EncSizeL + mBlockNum * mBloc= kResultSize;=0D + CombinedInput =3D AllocateZeroPool (CombinedInputSize);=0D + mBlockIsCompleted =3D AllocateZeroPool (mBlockNum * sizeof (BOOLEAN));=0D + mSpinLockList =3D AllocatePool (mBlockNum * sizeof (SPIN_LOCK));=0D + if ((CombinedInput =3D=3D NULL) || (mBlockIsCompleted =3D=3D NULL) || (m= SpinLockList =3D=3D NULL)) {=0D + ReturnValue =3D FALSE;=0D + goto Exit;=0D + }=0D +=0D + //=0D + // Fill LeftEncode(B).=0D + //=0D + CopyMem (CombinedInput, EncBufB, EncSizeB);=0D +=0D + //=0D + // Prepare for parallel hash.=0D + //=0D + mBlockHashResult =3D CombinedInput + EncSizeB;=0D + mInput =3D (UINT8 *)Input;=0D + mLastBlockSize =3D InputByteLen % mBlockSize =3D=3D 0 ? mBlockSize : I= nputByteLen % mBlockSize;=0D +=0D + //=0D + // Initialize SpinLock for each result block.=0D + //=0D + for (Index =3D 0; Index < mBlockNum; Index++) {=0D + InitializeSpinLock (&mSpinLockList[Index]);=0D + }=0D +=0D + //=0D + // Dispatch blocklist to each AP.=0D + //=0D + if (gMmst !=3D NULL) {=0D + MmDispatchBlockToAP ();=0D + }=0D +=0D + //=0D + // Wait until all block hash completed.=0D + //=0D + do {=0D + AllCompleted =3D TRUE;=0D + for (Index =3D 0; Index < mBlockNum; Index++) {=0D + if (AcquireSpinLockOrFail (&mSpinLockList[Index])) {=0D + if (!mBlockIsCompleted[Index]) {=0D + AllCompleted =3D FALSE;=0D + ReturnValue =3D CShake256HashAll (=0D + mInput + Index * mBlockSize,=0D + (Index =3D=3D (mBlockNum - 1)) ? mLastBlockSize= : mBlockSize,=0D + mBlockResultSize,=0D + NULL,=0D + 0,=0D + NULL,=0D + 0,=0D + mBlockHashResult + Index * mBlockResultSize=0D + );=0D + if (ReturnValue) {=0D + mBlockIsCompleted[Index] =3D TRUE;=0D + }=0D +=0D + ReleaseSpinLock (&mSpinLockList[Index]);=0D + break;=0D + }=0D +=0D + ReleaseSpinLock (&mSpinLockList[Index]);=0D + } else {=0D + AllCompleted =3D FALSE;=0D + break;=0D + }=0D + }=0D + } while (!AllCompleted);=0D +=0D + //=0D + // Fill LeftEncode(n).=0D + //=0D + Offset =3D EncSizeB + mBlockNum * mBlockResultSize;=0D + CopyMem (CombinedInput + Offset, EncBufN, EncSizeN);=0D +=0D + //=0D + // Fill LeftEncode(L).=0D + //=0D + Offset +=3D EncSizeN;=0D + CopyMem (CombinedInput + Offset, EncBufL, EncSizeL);=0D +=0D + ReturnValue =3D CShake256HashAll (=0D + CombinedInput,=0D + CombinedInputSize,=0D + OutputByteLen,=0D + PARALLELHASH_CUSTOMIZATION,=0D + AsciiStrLen (PARALLELHASH_CUSTOMIZATION),=0D + Customization,=0D + CustomByteLen,=0D + Output=0D + );=0D +=0D +Exit:=0D + ZeroMem (CombinedInput, CombinedInputSize);=0D +=0D + if (CombinedInput !=3D NULL) {=0D + FreePool (CombinedInput);=0D + }=0D +=0D + if (mSpinLockList !=3D NULL) {=0D + FreePool ((VOID *)mSpinLockList);=0D + }=0D +=0D + if (mBlockIsCompleted !=3D NULL) {=0D + FreePool (mBlockIsCompleted);=0D + }=0D +=0D + return ReturnValue;=0D +}=0D 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=0D + ParallelHash Implementation which does not provide real capabilities.=0D +=0D +Copyright (c) 2022, Intel Corporation. All rights reserved.
=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include "InternalCryptLib.h"=0D +=0D +/**=0D + Parallel hash function ParallelHash256, as defined in NIST's Special Pub= lication 800-185,=0D + published December 2016.=0D +=0D + @param[in] Input Pointer to the input message (X).=0D + @param[in] InputByteLen The number(>0) of input bytes provided for= the input data.=0D + @param[in] BlockSize The size of each block (B).=0D + @param[out] Output Pointer to the output buffer.=0D + @param[in] OutputByteLen The desired number of output bytes (L).=0D + @param[in] Customization Pointer to the customization string (S).=0D + @param[in] CustomByteLen The length of the customization string in = bytes.=0D +=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +ParallelHash256HashAll (=0D + IN CONST VOID *Input,=0D + IN UINTN InputByteLen,=0D + IN UINTN BlockSize,=0D + OUT VOID *Output,=0D + IN UINTN OutputByteLen,=0D + IN CONST VOID *Customization,=0D + IN UINTN CustomByteLen=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return FALSE;=0D +}=0D diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c b/CryptoPkg/Li= brary/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=0D + SHA3 realted functions from OpenSSL.=0D +=0D +Copyright (c) 2022, Intel Corporation. All rights reserved.
=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.=0D +Licensed under the OpenSSL license (the "License"). You may not use=0D +this file except in compliance with the License. You can obtain a copy=0D +in the file LICENSE in the source distribution or at=0D +https://www.openssl.org/source/license.html=0D +**/=0D +=0D +#include "CryptParallelHash.h"=0D +=0D +/**=0D + Keccak initial fuction.=0D +=0D + Set up state with specified capacity.=0D +=0D + @param[out] Context Pointer to the context being initialized.= =0D + @param[in] Pad Delimited Suffix.=0D + @param[in] BlockSize Size of context block.=0D + @param[in] MessageDigestLen Size of message digest in bytes.=0D +=0D + @retval 1 Initialize successfully.=0D + @retval 0 Fail to initialize.=0D +**/=0D +UINT8=0D +EFIAPI=0D +KeccakInit (=0D + OUT Keccak1600_Ctx *Context,=0D + IN UINT8 Pad,=0D + IN UINTN BlockSize,=0D + IN UINTN MessageDigestLen=0D + )=0D +{=0D + if (BlockSize <=3D sizeof (Context->buf)) {=0D + memset (Context->A, 0, sizeof (Context->A));=0D +=0D + Context->num =3D 0;=0D + Context->block_size =3D BlockSize;=0D + Context->md_size =3D MessageDigestLen;=0D + Context->pad =3D Pad;=0D +=0D + return 1;=0D + }=0D +=0D + return 0;=0D +}=0D +=0D +/**=0D + Sha3 update fuction.=0D +=0D + This function performs Sha3 digest on a data buffer of the specified siz= e.=0D + It can be called multiple times to compute the digest of long or discont= inuous data streams.=0D +=0D + @param[in,out] Context Pointer to the Keccak context.=0D + @param[in] Data Pointer to the buffer containing the data to be= hashed.=0D + @param[in] DataSize Size of Data buffer in bytes.=0D +=0D + @retval 1 Update successfully.=0D +**/=0D +UINT8=0D +EFIAPI=0D +Sha3Update (=0D + IN OUT Keccak1600_Ctx *Context,=0D + IN const VOID *Data,=0D + IN UINTN DataSize=0D + )=0D +{=0D + const UINT8 *DataCopy;=0D + UINTN BlockSize;=0D + UINTN Num;=0D + UINTN Rem;=0D +=0D + DataCopy =3D Data;=0D + BlockSize =3D (UINT8)(Context->block_size);=0D +=0D + if (DataSize =3D=3D 0) {=0D + return 1;=0D + }=0D +=0D + if ((Num =3D Context->num) !=3D 0) {=0D + //=0D + // process intermediate buffer=0D + //=0D + Rem =3D BlockSize - Num;=0D +=0D + if (DataSize < Rem) {=0D + memcpy (Context->buf + Num, DataCopy, DataSize);=0D + Context->num +=3D DataSize;=0D + return 1;=0D + }=0D +=0D + //=0D + // We have enough data to fill or overflow the intermediate=0D + // buffer. So we append |Rem| bytes and process the block,=0D + // leaving the rest for later processing.=0D + //=0D + memcpy (Context->buf + Num, DataCopy, Rem);=0D + DataCopy +=3D Rem;=0D + DataSize -=3D Rem;=0D + (void)SHA3_absorb (Context->A, Context->buf, BlockSize, BlockSize);=0D + Context->num =3D 0;=0D + // Context->buf is processed, Context->num is guaranteed to be zero.=0D + }=0D +=0D + if (DataSize >=3D BlockSize) {=0D + Rem =3D SHA3_absorb (Context->A, DataCopy, DataSize, BlockSize);=0D + } else {=0D + Rem =3D DataSize;=0D + }=0D +=0D + if (Rem > 0) {=0D + memcpy (Context->buf, DataCopy + DataSize - Rem, Rem);=0D + Context->num =3D Rem;=0D + }=0D +=0D + return 1;=0D +}=0D +=0D +/**=0D + Completes computation of Sha3 message digest.=0D +=0D + This function completes sha3 hash computation and retrieves the digest v= alue into=0D + the specified memory. After this function has been called, the keccak co= ntext cannot=0D + be used again.=0D +=0D + @param[in, out] Context Pointer to the keccak context.=0D + @param[out] MessageDigest Pointer to a buffer that receives the me= ssage digest.=0D +=0D + @retval 1 Meaasge digest computation succeeded.=0D +**/=0D +UINT8=0D +EFIAPI=0D +Sha3Final (=0D + IN OUT Keccak1600_Ctx *Context,=0D + OUT UINT8 *MessageDigest=0D + )=0D +{=0D + UINTN BlockSize;=0D + UINTN Num;=0D +=0D + BlockSize =3D Context->block_size;=0D + Num =3D Context->num;=0D +=0D + if (Context->md_size =3D=3D 0) {=0D + return 1;=0D + }=0D +=0D + //=0D + // Pad the data with 10*1. Note that |Num| can be |BlockSize - 1|=0D + // in which case both byte operations below are performed on=0D + // same byte.=0D + //=0D + memset (Context->buf + Num, 0, BlockSize - Num);=0D + Context->buf[Num] =3D Context->pad;=0D + Context->buf[BlockSize - 1] |=3D 0x80;=0D +=0D + (void)SHA3_absorb (Context->A, Context->buf, BlockSize, BlockSize);=0D +=0D + SHA3_squeeze (Context->A, MessageDigest, Context->md_size, BlockSize);=0D +=0D + return 1;=0D +}=0D diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c b/CryptoPkg/Li= brary/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=0D + Encode realted functions from Xkcp.=0D +=0D +Copyright (c) 2022, Intel Corporation. All rights reserved.
=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +Copyright 2022 The eXtended Keccak Code Package (XKCP)=0D +https://github.com/XKCP/XKCP=0D +Keccak, designed by Guido Bertoni, Joan Daemen, Michael Peeters and Gilles= Van Assche.=0D +Implementation by the designers, hereby denoted as "the implementer".=0D +For more information, feedback or questions, please refer to the Keccak Te= am website:=0D +https://keccak.team/=0D +To the extent possible under law, the implementer has waived all copyright= =0D +and related or neighboring rights to the source code in this file.=0D +http://creativecommons.org/publicdomain/zero/1.0/=0D +=0D +**/=0D +=0D +#include "CryptParallelHash.h"=0D +=0D +/**=0D + Encode function from XKCP.=0D +=0D + Encodes the input as a byte string in a way that can be unambiguously pa= rsed=0D + from the beginning of the string by inserting the length of the byte str= ing=0D + before the byte string representation of input.=0D +=0D + @param[out] EncBuf Result of left encode.=0D + @param[in] Value Input of left encode.=0D +=0D + @retval EncLen Size of encode result in bytes.=0D +**/=0D +UINTN=0D +EFIAPI=0D +LeftEncode (=0D + OUT UINT8 *EncBuf,=0D + IN UINTN Value=0D + )=0D +{=0D + UINT32 BlockNum;=0D + UINT32 EncLen;=0D + UINT32 Index;=0D + UINTN ValueCopy;=0D +=0D + for ( ValueCopy =3D Value, BlockNum =3D 0; ValueCopy && (BlockNum < size= of (UINTN)); ++BlockNum, ValueCopy >>=3D 8 ) {=0D + //=0D + // Empty=0D + //=0D + }=0D +=0D + if (BlockNum =3D=3D 0) {=0D + BlockNum =3D 1;=0D + }=0D +=0D + for (Index =3D 1; Index <=3D BlockNum; ++Index) {=0D + EncBuf[Index] =3D (UINT8)(Value >> (8 * (BlockNum - Index)));=0D + }=0D +=0D + EncBuf[0] =3D (UINT8)BlockNum;=0D + EncLen =3D BlockNum + 1;=0D +=0D + return EncLen;=0D +}=0D +=0D +/**=0D + Encode function from XKCP.=0D +=0D + Encodes the input as a byte string in a way that can be unambiguously pa= rsed=0D + from the end of the string by inserting the length of the byte string af= ter=0D + the byte string representation of input.=0D +=0D + @param[out] EncBuf Result of right encode.=0D + @param[in] Value Input of right encode.=0D +=0D + @retval EncLen Size of encode result in bytes.=0D +**/=0D +UINTN=0D +EFIAPI=0D +RightEncode (=0D + OUT UINT8 *EncBuf,=0D + IN UINTN Value=0D + )=0D +{=0D + UINT32 BlockNum;=0D + UINT32 EncLen;=0D + UINT32 Index;=0D + UINTN ValueCopy;=0D +=0D + for (ValueCopy =3D Value, BlockNum =3D 0; ValueCopy && (BlockNum < sizeo= f (UINTN)); ++BlockNum, ValueCopy >>=3D 8) {=0D + //=0D + // Empty=0D + //=0D + }=0D +=0D + if (BlockNum =3D=3D 0) {=0D + BlockNum =3D 1;=0D + }=0D +=0D + for (Index =3D 1; Index <=3D BlockNum; ++Index) {=0D + EncBuf[Index-1] =3D (UINT8)(Value >> (8 * (BlockNum-Index)));=0D + }=0D +=0D + EncBuf[BlockNum] =3D (UINT8)BlockNum;=0D + EncLen =3D BlockNum + 1;=0D +=0D + return EncLen;=0D +}=0D diff --git a/CryptoPkg/Library/BaseCryptLibNull/Hash/CryptParallelHashNull.= c b/CryptoPkg/Library/BaseCryptLibNull/Hash/CryptParallelHashNull.c new file mode 100644 index 000000000000..2bf89594def5 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibNull/Hash/CryptParallelHashNull.c @@ -0,0 +1,40 @@ +/** @file=0D + ParallelHash Implementation which does not provide real capabilities.=0D +=0D +Copyright (c) 2022, Intel Corporation. All rights reserved.
=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include "InternalCryptLib.h"=0D +=0D +/**=0D + Parallel hash function ParallelHash256, as defined in NIST's Special Pub= lication 800-185,=0D + published December 2016.=0D +=0D + @param[in] Input Pointer to the input message (X).=0D + @param[in] InputByteLen The number(>0) of input bytes provided for= the input data.=0D + @param[in] BlockSize The size of each block (B).=0D + @param[out] Output Pointer to the output buffer.=0D + @param[in] OutputByteLen The desired number of output bytes (L).=0D + @param[in] Customization Pointer to the customization string (S).=0D + @param[in] CustomByteLen The length of the customization string in = bytes.=0D +=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +ParallelHash256HashAll (=0D + IN CONST VOID *Input,=0D + IN UINTN InputByteLen,=0D + IN UINTN BlockSize,=0D + OUT VOID *Output,=0D + IN UINTN OutputByteLen,=0D + IN CONST VOID *Customization,=0D + IN UINTN CustomByteLen=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return FALSE;=0D +}=0D diff --git a/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c b/Crypt= oPkg/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.=0D =0D Copyright (C) Microsoft Corporation. All rights reserved.=0D - Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.
=0D + Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D @@ -870,6 +870,38 @@ Sha512HashAll ( CALL_CRYPTO_SERVICE (Sha512HashAll, (Data, DataSize, HashValue), FALSE);= =0D }=0D =0D +/**=0D + Parallel hash function ParallelHash256, as defined in NIST's Special Pub= lication 800-185,=0D + published December 2016.=0D +=0D + @param[in] Input Pointer to the input message (X).=0D + @param[in] InputByteLen The number(>0) of input bytes provided for= the input data.=0D + @param[in] BlockSize The size of each block (B).=0D + @param[out] Output Pointer to the output buffer.=0D + @param[in] OutputByteLen The desired number of output bytes (L).=0D + @param[in] Customization Pointer to the customization string (S).=0D + @param[in] CustomByteLen The length of the customization string in = bytes.=0D +=0D + @retval TRUE ParallelHash256 digest computation succeeded.=0D + @retval FALSE ParallelHash256 digest computation failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +ParallelHash256HashAll (=0D + IN CONST VOID *Input,=0D + IN UINTN InputByteLen,=0D + IN UINTN BlockSize,=0D + OUT VOID *Output,=0D + IN UINTN OutputByteLen,=0D + IN CONST VOID *Customization,=0D + IN UINTN CustomByteLen=0D + )=0D +{=0D + CALL_CRYPTO_SERVICE (ParallelHash256HashAll, (Input, InputByteLen, Block= Size, Output, OutputByteLen, Customization, CustomByteLen), FALSE);=0D +}=0D +=0D /**=0D Retrieves the size, in bytes, of the context buffer required for SM3 has= h operations.=0D =0D 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=0D + Application for Parallelhash Function Validation.=0D +=0D +Copyright (c) 2022, Intel Corporation. All rights reserved.
=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include "TestBaseCryptLib.h"=0D +=0D +//=0D +// Parallelhash Test Sample common parameters.=0D +//=0D +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINTN OutputByteLen =3D 64;=0D +=0D +//=0D +// Parallelhash Test Sample #1 from NIST Special Publication 800-185.=0D +//=0D +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 InputSample1[] =3D {=0D + // input data of sample1.=0D + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x13, = 0x14, 0x15, 0x16, 0x17,=0D + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27=0D +};=0D +GLOBAL_REMOVE_IF_UNREFERENCED UINTN InputSample1ByteLen =3D 24; = // Length of sample1 input data in bytes.=0D +GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID *CustomizationSample1 =3D ""; = // Customization string (S) of sample1.=0D +GLOBAL_REMOVE_IF_UNREFERENCED UINTN CustomSample1ByteLen =3D 0; = // Customization string length of sample1 in bytes.=0D +GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample1 =3D 8; = // Block size of sample1.=0D +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 ExpectOutputSample1[] =3D {=0D + // Expected output data of sample1.=0D + 0xbc, 0x1e, 0xf1, 0x24, 0xda, 0x34, 0x49, 0x5e, 0x94, 0x8e, 0xad, 0x20, = 0x7d, 0xd9, 0x84, 0x22,=0D + 0x35, 0xda, 0x43, 0x2d, 0x2b, 0xbc, 0x54, 0xb4, 0xc1, 0x10, 0xe6, 0x4c, = 0x45, 0x11, 0x05, 0x53,=0D + 0x1b, 0x7f, 0x2a, 0x3e, 0x0c, 0xe0, 0x55, 0xc0, 0x28, 0x05, 0xe7, 0xc2, = 0xde, 0x1f, 0xb7, 0x46,=0D + 0xaf, 0x97, 0xa1, 0xd0, 0x01, 0xf4, 0x3b, 0x82, 0x4e, 0x31, 0xb8, 0x76, = 0x12, 0x41, 0x04, 0x29=0D +};=0D +=0D +//=0D +// Parallelhash Test Sample #2 from NIST Special Publication 800-185.=0D +//=0D +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 *InputSample2 =3D Input= Sample1; // Input of sample2 is same as sample1.=0D +GLOBAL_REMOVE_IF_UNREFERENCED UINTN InputSample2ByteLen =3D 24; = // Length of sample2 input data in bytes.=0D +GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID *CustomizationSample2 =3D "Para= llel Data"; // Customization string (S) of sample2.=0D +GLOBAL_REMOVE_IF_UNREFERENCED UINTN CustomSample2ByteLen =3D 13; = // Customization string length of sample2 in bytes.= =0D +GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample2 =3D 8; = // Block size of sample2.=0D +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 ExpectOutputSample2[] =3D {=0D + // Expected output data of sample2.=0D + 0xcd, 0xf1, 0x52, 0x89, 0xb5, 0x4f, 0x62, 0x12, 0xb4, 0xbc, 0x27, 0x05, = 0x28, 0xb4, 0x95, 0x26,=0D + 0x00, 0x6d, 0xd9, 0xb5, 0x4e, 0x2b, 0x6a, 0xdd, 0x1e, 0xf6, 0x90, 0x0d, = 0xda, 0x39, 0x63, 0xbb,=0D + 0x33, 0xa7, 0x24, 0x91, 0xf2, 0x36, 0x96, 0x9c, 0xa8, 0xaf, 0xae, 0xa2, = 0x9c, 0x68, 0x2d, 0x47,=0D + 0xa3, 0x93, 0xc0, 0x65, 0xb3, 0x8e, 0x29, 0xfa, 0xe6, 0x51, 0xa2, 0x09, = 0x1c, 0x83, 0x31, 0x10=0D +};=0D +=0D +//=0D +// Parallelhash Test Sample #3 from NIST Special Publication 800-185.=0D +//=0D +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 InputSample3[] =3D {=0D + // input data of sample3.=0D + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, = 0x10, 0x11, 0x12, 0x13,=0D + 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x20, 0x21, 0x22, 0x23, = 0x24, 0x25, 0x26, 0x27,=0D + 0x28, 0x29, 0x2a, 0x2b, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, = 0x38, 0x39, 0x3a, 0x3b,=0D + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, = 0x50, 0x51, 0x52, 0x53,=0D + 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b=0D +};=0D +GLOBAL_REMOVE_IF_UNREFERENCED UINTN InputSample3ByteLen =3D 72; = // Length of sample3 input data in bytes.=0D +GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID *CustomizationSample3 =3D "Para= llel Data"; // Customization string (S) of sample3.=0D +GLOBAL_REMOVE_IF_UNREFERENCED UINTN CustomSample3ByteLen =3D 13; = // Customization string length of sample3 in bytes.= =0D +GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample3 =3D 12; = // Block size of sample3.=0D +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 ExpectOutputSample3[] =3D {=0D + // Expected output data of sample3.=0D + 0x69, 0xd0, 0xfc, 0xb7, 0x64, 0xea, 0x05, 0x5d, 0xd0, 0x93, 0x34, 0xbc, = 0x60, 0x21, 0xcb, 0x7e,=0D + 0x4b, 0x61, 0x34, 0x8d, 0xff, 0x37, 0x5d, 0xa2, 0x62, 0x67, 0x1c, 0xde, = 0xc3, 0xef, 0xfa, 0x8d,=0D + 0x1b, 0x45, 0x68, 0xa6, 0xcc, 0xe1, 0x6b, 0x1c, 0xad, 0x94, 0x6d, 0xdd, = 0xe2, 0x7f, 0x6c, 0xe2,=0D + 0xb8, 0xde, 0xe4, 0xcd, 0x1b, 0x24, 0x85, 0x1e, 0xbf, 0x00, 0xeb, 0x90, = 0xd4, 0x38, 0x13, 0xe9=0D +};=0D +=0D +UNIT_TEST_STATUS=0D +EFIAPI=0D +TestVerifyParallelHash256HashAll (=0D + IN UNIT_TEST_CONTEXT Context=0D + )=0D +{=0D + BOOLEAN Status;=0D + UINT8 Output[64];=0D +=0D + //=0D + // Test #1 using sample1.=0D + //=0D + Status =3D ParallelHash256HashAll (=0D + InputSample1,=0D + InputSample1ByteLen,=0D + BlockSizeSample1,=0D + Output,=0D + OutputByteLen,=0D + CustomizationSample1,=0D + CustomSample1ByteLen=0D + );=0D + UT_ASSERT_TRUE (Status);=0D +=0D + // Check the output with the expected output.=0D + UT_ASSERT_MEM_EQUAL (Output, ExpectOutputSample1, OutputByteLen);=0D +=0D + //=0D + // Test #2 using sample2.=0D + //=0D + Status =3D ParallelHash256HashAll (=0D + InputSample2,=0D + InputSample2ByteLen,=0D + BlockSizeSample2,=0D + Output,=0D + OutputByteLen,=0D + CustomizationSample2,=0D + CustomSample2ByteLen=0D + );=0D + UT_ASSERT_TRUE (Status);=0D +=0D + // Check the output with the expected output.=0D + UT_ASSERT_MEM_EQUAL (Output, ExpectOutputSample2, OutputByteLen);=0D +=0D + //=0D + // Test #3 using sample3.=0D + //=0D + Status =3D ParallelHash256HashAll (=0D + InputSample3,=0D + InputSample3ByteLen,=0D + BlockSizeSample3,=0D + Output,=0D + OutputByteLen,=0D + CustomizationSample3,=0D + CustomSample3ByteLen=0D + );=0D + UT_ASSERT_TRUE (Status);=0D +=0D + // Check the output with the expected output.=0D + UT_ASSERT_MEM_EQUAL (Output, ExpectOutputSample3, OutputByteLen);=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +TEST_DESC mParallelhashTest[] =3D {=0D + //=0D + // -----Description------------------------------Class------------------= ----Function-----------------Pre---Post--Context=0D + //=0D + { "TestVerifyParallelHash256HashAll()", "CryptoPkg.BaseCryptLib.Parallel= Hash256HashAll", TestVerifyParallelHash256HashAll, NULL, NULL, NULL },=0D +};=0D +=0D +UINTN mParallelhashTestNum =3D ARRAY_SIZE (mParallelhashTest);=0D 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=0D #=0D # Copyright (c) Microsoft Corporation=0D -# Copyright (c) 2020, Intel Corporation. All rights reserved.
=0D +# Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.
=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D ##=0D {=0D @@ -34,6 +34,8 @@ "Library/OpensslLib/rand_pool.c",=0D # This has OpenSSL interfaces that aren't UEFI spec compliant= =0D "Library/Include/CrtLibSupport.h",=0D + # This has OpenSSL interfaces that aren't UEFI spec compliant= =0D + "Library/BaseCryptLib/Hash/CryptParallelHash.h",=0D # These directories contain auto-generated OpenSSL content=0D "Library/OpensslLib",=0D "Library/IntrinsicLib",=0D diff --git a/CryptoPkg/Include/Library/BaseCryptLib.h b/CryptoPkg/Include/L= ibrary/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 secur= ity=0D functionality enabling.=0D =0D -Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.
=0D +Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D @@ -753,6 +753,35 @@ Sha512HashAll ( OUT UINT8 *HashValue=0D );=0D =0D +/**=0D + Parallel hash function ParallelHash256, as defined in NIST's Special Pub= lication 800-185,=0D + published December 2016.=0D +=0D + @param[in] Input Pointer to the input message (X).=0D + @param[in] InputByteLen The number(>0) of input bytes provided for= the input data.=0D + @param[in] BlockSize The size of each block (B).=0D + @param[out] Output Pointer to the output buffer.=0D + @param[in] OutputByteLen The desired number of output bytes (L).=0D + @param[in] Customization Pointer to the customization string (S).=0D + @param[in] CustomByteLen The length of the customization string in = bytes.=0D +=0D + @retval TRUE ParallelHash256 digest computation succeeded.=0D + @retval FALSE ParallelHash256 digest computation failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +ParallelHash256HashAll (=0D + IN CONST VOID *Input,=0D + IN UINTN InputByteLen,=0D + IN UINTN BlockSize,=0D + OUT VOID *Output,=0D + IN UINTN OutputByteLen,=0D + IN CONST VOID *Customization,=0D + IN UINTN CustomByteLen=0D + );=0D +=0D /**=0D Retrieves the size, in bytes, of the context buffer required for SM3 has= h operations.=0D =0D diff --git a/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h b/CryptoP= kg/Include/Pcd/PcdCryptoServiceFamilyEnable.h index 5186a54759ae..77330961352e 100644 --- a/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h +++ b/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h @@ -2,7 +2,7 @@ Defines the PCD_CRYPTO_SERVICE_FAMILY_ENABLE structure associated with=0D gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.=0D =0D - Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.
=0D + Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D @@ -288,6 +288,12 @@ typedef struct { } Services;=0D UINT32 Family;=0D } TlsGet;=0D + union {=0D + struct {=0D + UINT8 HashAll : 1;=0D + } Services;=0D + UINT32 Family;=0D + } ParallelHash;=0D } PCD_CRYPTO_SERVICE_FAMILY_ENABLE;=0D =0D #endif=0D diff --git a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf b/CryptoPkg/Li= brary/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 issue= s such as=0D # buffer overflow or integer overflow.=0D #=0D -# Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.
= =0D +# Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.
= =0D # Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D @@ -34,6 +34,7 @@ Hash/CryptSha256.c=0D Hash/CryptSha512.c=0D Hash/CryptSm3.c=0D + Hash/CryptParallelHashNull.c=0D Hmac/CryptHmacSha256.c=0D Kdf/CryptHkdf.c=0D Cipher/CryptAes.c=0D diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h b/Cryp= toPkg/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=0D + ParallelHash related function and type declaration.=0D +=0D +Copyright (c) 2022, Intel Corporation. All rights reserved.
=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.=0D +Licensed under the OpenSSL license (the "License"). You may not use=0D +this file except in compliance with the License. You can obtain a copy=0D +in the file LICENSE in the source distribution or at=0D +https://www.openssl.org/source/license.html=0D +=0D +Copyright 2022 The eXtended Keccak Code Package (XKCP)=0D +https://github.com/XKCP/XKCP=0D +Keccak, designed by Guido Bertoni, Joan Daemen, Michael Peeters and Gilles= Van Assche.=0D +Implementation by the designers, hereby denoted as "the implementer".=0D +For more information, feedback or questions, please refer to the Keccak Te= am website:=0D +https://keccak.team/=0D +To the extent possible under law, the implementer has waived all copyright= =0D +and related or neighboring rights to the source code in this file.=0D +http://creativecommons.org/publicdomain/zero/1.0/=0D +**/=0D +=0D +#include "InternalCryptLib.h"=0D +=0D +#define KECCAK1600_WIDTH 1600=0D +=0D +//=0D +// This struct referring to m_sha3.c from opessl and modified its type nam= e.=0D +//=0D +typedef struct {=0D + uint64_t A[5][5];=0D + size_t block_size; /* cached ctx->digest->block_size */=0D + size_t md_size; /* output length, variable in XOF */=0D + size_t num; /* used bytes in below buffer */=0D + unsigned char buf[KECCAK1600_WIDTH / 8 - 32];=0D + unsigned char pad;=0D +} Keccak1600_Ctx;=0D +=0D +/**=0D + SHA3_absorb can be called multiple times, but at each invocation=0D + largest multiple of |r| out of |len| bytes are processed. Then=0D + remaining amount of bytes is returned. This is done to spare caller=0D + trouble of calculating the largest multiple of |r|. |r| can be viewed=0D + as blocksize. It is commonly (1600 - 256*n)/8, e.g. 168, 136, 104,=0D + 72, but can also be (1600 - 448)/8 =3D 144. All this means that message= =0D + padding and intermediate sub-block buffering, byte- or bitwise, is=0D + caller's responsibility.=0D +**/=0D +size_t=0D +SHA3_absorb (=0D + uint64_t A[5][5],=0D + const unsigned char *inp,=0D + size_t len,=0D + size_t r=0D + );=0D +=0D +/**=0D + SHA3_squeeze is called once at the end to generate |out| hash value=0D + of |len| bytes.=0D +**/=0D +void=0D +SHA3_squeeze (=0D + uint64_t A[5][5],=0D + unsigned char *out,=0D + size_t len,=0D + size_t r=0D + );=0D +=0D +/**=0D + Encode function from XKCP.=0D +=0D + Encodes the input as a byte string in a way that can be unambiguously pa= rsed=0D + from the beginning of the string by inserting the length of the byte str= ing=0D + before the byte string representation of input.=0D +=0D + @param[out] EncBuf Result of left encode.=0D + @param[in] Value Input of left encode.=0D +=0D + @retval EncLen Size of encode result in bytes.=0D +**/=0D +UINTN=0D +EFIAPI=0D +LeftEncode (=0D + OUT UINT8 *EncBuf,=0D + IN UINTN Value=0D + );=0D +=0D +/**=0D + Encode function from XKCP.=0D +=0D + Encodes the input as a byte string in a way that can be unambiguously pa= rsed=0D + from the end of the string by inserting the length of the byte string af= ter=0D + the byte string representation of input.=0D +=0D + @param[out] EncBuf Result of right encode.=0D + @param[in] Value Input of right encode.=0D +=0D + @retval EncLen Size of encode result in bytes.=0D +**/=0D +UINTN=0D +EFIAPI=0D +RightEncode (=0D + OUT UINT8 *EncBuf,=0D + IN UINTN Value=0D + );=0D +=0D +/**=0D + Keccak initial fuction.=0D +=0D + Set up state with specified capacity.=0D +=0D + @param[out] Context Pointer to the context being initialized.= =0D + @param[in] Pad Delimited Suffix.=0D + @param[in] BlockSize Size of context block.=0D + @param[in] MessageDigestLen Size of message digest in bytes.=0D +=0D + @retval 1 Initialize successfully.=0D + @retval 0 Fail to initialize.=0D +**/=0D +UINT8=0D +EFIAPI=0D +KeccakInit (=0D + OUT Keccak1600_Ctx *Context,=0D + IN UINT8 Pad,=0D + IN UINTN BlockSize,=0D + IN UINTN MessageDigstLen=0D + );=0D +=0D +/**=0D + Sha3 update fuction.=0D +=0D + This function performs Sha3 digest on a data buffer of the specified siz= e.=0D + It can be called multiple times to compute the digest of long or discont= inuous data streams.=0D +=0D + @param[in,out] Context Pointer to the Keccak context.=0D + @param[in] Data Pointer to the buffer containing the data to be= hashed.=0D + @param[in] DataSize Size of Data buffer in bytes.=0D +=0D + @retval 1 Update successfully.=0D +**/=0D +UINT8=0D +EFIAPI=0D +Sha3Update (=0D + IN OUT Keccak1600_Ctx *Context,=0D + IN const VOID *Data,=0D + IN UINTN DataSize=0D + );=0D +=0D +/**=0D + Completes computation of Sha3 message digest.=0D +=0D + This function completes sha3 hash computation and retrieves the digest v= alue into=0D + the specified memory. After this function has been called, the keccak co= ntext cannot=0D + be used again.=0D +=0D + @param[in, out] Context Pointer to the keccak context.=0D + @param[out] MessageDigest Pointer to a buffer that receives the me= ssage digest.=0D +=0D + @retval 1 Meaasge digest computation succeeded.=0D +**/=0D +UINT8=0D +EFIAPI=0D +Sha3Final (=0D + IN OUT Keccak1600_Ctx *Context,=0D + OUT UINT8 *MessageDigest=0D + );=0D +=0D +/**=0D + Computes the CSHAKE-256 message digest of a input data buffer.=0D +=0D + This function performs the CSHAKE-256 message digest of a given data buf= fer, and places=0D + the digest value into the specified memory.=0D +=0D + @param[in] Data Pointer to the buffer containing the dat= a to be hashed.=0D + @param[in] DataSize Size of Data buffer in bytes.=0D + @param[in] OutputLen Size of output in bytes.=0D + @param[in] Name Pointer to the function name string.=0D + @param[in] NameLen Size of the function name in bytes.=0D + @param[in] Customization Pointer to the customization string.=0D + @param[in] CustomizationLen Size of the customization string in byte= s.=0D + @param[out] HashValue Pointer to a buffer that receives the CS= HAKE-256 digest=0D + value.=0D +=0D + @retval TRUE CSHAKE-256 digest computation succeeded.=0D + @retval FALSE CSHAKE-256 digest computation failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +CShake256HashAll (=0D + IN CONST VOID *Data,=0D + IN UINTN DataSize,=0D + IN UINTN OutputLen,=0D + IN CONST VOID *Name,=0D + IN UINTN NameLen,=0D + IN CONST VOID *Customization,=0D + IN UINTN CustomizationLen,=0D + OUT UINT8 *HashValue=0D + );=0D diff --git a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf b/CryptoPkg/Lib= rary/BaseCryptLib/PeiCryptLib.inf index 0cab5f3ce36c..bf1563b06407 100644 --- a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf @@ -13,7 +13,7 @@ # PEM handler functions, and pseudorandom number generator functions are = not=0D # supported in this instance.=0D #=0D -# Copyright (c) 2010 - 2020, Intel Corporation. All rights reserved.
= =0D +# Copyright (c) 2010 - 2022, Intel Corporation. All rights reserved.
= =0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D ##=0D @@ -40,6 +40,7 @@ Hash/CryptSha256.c=0D Hash/CryptSm3.c=0D Hash/CryptSha512.c=0D + Hash/CryptParallelHashNull.c=0D Hmac/CryptHmacSha256.c=0D Kdf/CryptHkdf.c=0D Cipher/CryptAesNull.c=0D 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=0D # authenticode signature verification functions are not supported in this= instance.=0D #=0D -# Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.
= =0D +# Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.
= =0D # Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D @@ -40,6 +40,7 @@ Hash/CryptSha256.c=0D Hash/CryptSm3.c=0D Hash/CryptSha512.c=0D + Hash/CryptParallelHashNull.c=0D Hmac/CryptHmacSha256.c=0D Kdf/CryptHkdf.c=0D Cipher/CryptAes.c=0D diff --git a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf b/CryptoPkg/Lib= rary/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-Hellma= n functions, and=0D # authenticode signature verification functions are not supported in this= instance.=0D #=0D -# Copyright (c) 2010 - 2021, Intel Corporation. All rights reserved.
= =0D +# Copyright (c) 2010 - 2022, Intel Corporation. All rights reserved.
= =0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D ##=0D @@ -38,6 +38,10 @@ Hash/CryptSha256.c=0D Hash/CryptSm3.c=0D Hash/CryptSha512.c=0D + Hash/CryptSha3.c=0D + Hash/CryptXkcp.c=0D + Hash/CryptCShake256.c=0D + Hash/CryptParallelHash.c=0D Hmac/CryptHmacSha256.c=0D Kdf/CryptHkdfNull.c=0D Cipher/CryptAes.c=0D @@ -85,6 +89,8 @@ OpensslLib=0D IntrinsicLib=0D PrintLib=0D + MmServicesTableLib=0D + SynchronizationLib=0D =0D #=0D # Remove these [BuildOptions] after this library is cleaned up=0D diff --git a/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf b/Cryp= toPkg/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 issue= s such as=0D # buffer overflow or integer overflow.=0D #=0D -# Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.
= =0D +# Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.
= =0D # Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D @@ -34,6 +34,7 @@ Hash/CryptSha256Null.c=0D Hash/CryptSha512Null.c=0D Hash/CryptSm3Null.c=0D + Hash/CryptParallelHashNull.c=0D Hmac/CryptHmacSha256Null.c=0D Kdf/CryptHkdfNull.c=0D Cipher/CryptAesNull.c=0D 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-par= ty=0D cryptographic library.=0D =0D -Copyright (c) 2010 - 2021, Intel Corporation. All rights reserved.
=0D +Copyright (c) 2010 - 2022, Intel Corporation. All rights reserved.
=0D Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights = reserved.
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D @@ -111,6 +111,7 @@ typedef UINT8 u_char; typedef UINT32 uid_t;=0D typedef UINT32 gid_t;=0D typedef CHAR16 wchar_t;=0D +typedef UINT64 uint64_t;=0D =0D //=0D // File operations are not required for EFI building,=0D diff --git a/CryptoPkg/Private/Protocol/Crypto.h b/CryptoPkg/Private/Protoc= ol/Crypto.h index e378a8a8c60e..de45778c7d42 100644 --- a/CryptoPkg/Private/Protocol/Crypto.h +++ b/CryptoPkg/Private/Protocol/Crypto.h @@ -2,7 +2,7 @@ This Protocol provides Crypto services to DXE modules=0D =0D Copyright (C) Microsoft Corporation. All rights reserved.=0D - Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.
=0D + Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D @@ -21,7 +21,7 @@ /// the EDK II Crypto Protocol is extended, this version define must be=0D /// increased.=0D ///=0D -#define EDKII_CRYPTO_VERSION 7=0D +#define EDKII_CRYPTO_VERSION 8=0D =0D ///=0D /// EDK II Crypto Protocol forward declaration=0D @@ -3383,6 +3383,35 @@ EFI_STATUS IN OUT UINTN *DataSize=0D );=0D =0D +/**=0D + Parallel hash function ParallelHash256, as defined in NIST's Special Pub= lication 800-185,=0D + published December 2016.=0D +=0D + @param[in] Input Pointer to the input message (X).=0D + @param[in] InputByteLen The number(>0) of input bytes provided for= the input data.=0D + @param[in] BlockSize The size of each block (B).=0D + @param[out] Output Pointer to the output buffer.=0D + @param[in] OutputByteLen The desired number of output bytes (L).=0D + @param[in] Customization Pointer to the customization string (S).=0D + @param[in] CustomByteLen The length of the customization string in = bytes.=0D +=0D + @retval TRUE ParallelHash256 digest computation succeeded.=0D + @retval FALSE ParallelHash256 digest computation failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +typedef=0D +BOOLEAN=0D +(EFIAPI *EDKII_CRYPTO_PARALLEL_HASH_ALL)(=0D + IN CONST VOID *Input,=0D + IN UINTN InputByteLen,=0D + IN UINTN BlockSize,=0D + OUT VOID *Output,=0D + IN UINTN OutputByteLen,=0D + IN CONST VOID *Customization,=0D + IN UINTN CustomByteLen=0D + );=0D +=0D /**=0D Carries out the RSA-SSA signature generation with EMSA-PSS encoding sche= me.=0D =0D @@ -3641,6 +3670,8 @@ struct _EDKII_CRYPTO_PROTOCOL { EDKII_CRYPTO_TLS_GET_HOST_PUBLIC_CERT TlsGetHostPublicCert;= =0D EDKII_CRYPTO_TLS_GET_HOST_PRIVATE_KEY TlsGetHostPrivateKey;= =0D EDKII_CRYPTO_TLS_GET_CERT_REVOCATION_LIST TlsGetCertRevocationL= ist;=0D + /// Parallel hash=0D + EDKII_CRYPTO_PARALLEL_HASH_ALL ParallelHash256HashAl= l;=0D /// RSA PSS=0D EDKII_CRYPTO_RSA_PSS_SIGN RsaPssSign;=0D EDKII_CRYPTO_RSA_PSS_VERIFY RsaPssVerify;=0D diff --git a/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc b/CryptoPkg/Test/Cryp= toPkgHostUnitTest.dsc index ff0af36bcc80..c50a9cc4dc9f 100644 --- a/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc +++ b/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc @@ -2,6 +2,7 @@ # CryptoPkg DSC file used to build host-based unit tests.=0D #=0D # Copyright (c) Microsoft Corporation.
=0D +# Copyright (c) 2022, Intel Corporation. All rights reserved.
=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D ##=0D @@ -21,6 +22,9 @@ [LibraryClasses]=0D OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf=0D BaseCryptLib|CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf= =0D + MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTableLib.= inf=0D + SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchroniza= tionLib.inf=0D + TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplat= e.inf=0D =0D [LibraryClasses.AARCH64, LibraryClasses.ARM]=0D RngLib|MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf=0D diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibH= ost.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=0D #=0D # Copyright (c) Microsoft Corporation.
=0D +# Copyright (c) 2022, Intel Corporation. All rights reserved.
=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D ##=0D =0D @@ -35,6 +36,7 @@ Pkcs7EkuTests.c=0D OaepEncryptTests.c=0D RsaPssTests.c=0D + ParallelhashTests.c=0D =0D [Packages]=0D MdePkg/MdePkg.dec=0D @@ -45,3 +47,5 @@ DebugLib=0D BaseCryptLib=0D UnitTestLib=0D + MmServicesTableLib=0D + SynchronizationLib=0D --=20 2.26.2.windows.1