From nobody Fri May 17 03:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+86615+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+86615+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1644570394; cv=none; d=zohomail.com; s=zohoarc; b=Diqpy2Ab1PCro0vbUQELrTVSHXRalDYZBFdzX+duoxJTX6cZohfbviV1uEZLMlU5za68wGNAogG9xxBjBAYrATNnKDbKFKwFsz+Cy1ruFJrRoBRs0iGNORRmjUQeTs6idIbV3mQz+h9x39+nY6ssBAqp8OZhvhxZLz+RMrvkDx0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644570394; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=2ZULtBF6XOKSMBDlIKhUV/8xn9S68GO70smeB4geb1U=; b=jGyx3tb0gpvHpJVvWowpYdJ29dkzZ3Gmy1YdZMB0XPd5dByzp7fiyZlAn00LPeF+N2dVlZ+xxfJOQ78HZKlhYHyDEdo8v25wderSbZRHAiJiefyz+Jp2KyB1h5HT4cfioV2WNyepyF4y98J/pKTYnpct3SHjWofO0DWaktaSiIg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+86615+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1644570394448215.66114986748084; Fri, 11 Feb 2022 01:06:34 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id u8JXYY1788612xq2hs55CxzG; Fri, 11 Feb 2022 01:06:33 -0800 X-Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web12.5182.1644570393257412245 for ; Fri, 11 Feb 2022 01:06:33 -0800 X-IronPort-AV: E=McAfee;i="6200,9189,10254"; a="249902887" X-IronPort-AV: E=Sophos;i="5.88,360,1635231600"; d="scan'208";a="249902887" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Feb 2022 01:05:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,360,1635231600"; d="scan'208";a="542009254" X-Received: from win_li.ccr.corp.intel.com ([10.239.157.34]) by orsmga008.jf.intel.com with ESMTP; 11 Feb 2022 01:05:23 -0800 From: "Li, Zhihao" To: devel@edk2.groups.io Cc: Jiewen Yao , Jian J Wang , Xiaoyu Lu , Guomin Jiang , Siyuan Fu Subject: [edk2-devel] [PATCH v1] CryptoPkg: Add new hash algorithm ParallelHash256HashAll in BaseCryptLib. Date: Fri, 11 Feb 2022 17:05:22 +0800 Message-Id: <20220211090522.1497-1-zhihao.li@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,zhihao.li@intel.com X-Gm-Message-State: cHsuyzKomjyPSEqHXrwm3ZQIx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1644570393; bh=XKfXquVHNBqCHw1e1Pev6h0ladz+2lWWVG8shNedjkI=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=w6VdWDqOdgF1OSPsAHO6/kHU0+yWU2vAnAIFLCJ6zZ9bkOwTDziFAR5mLxjxqjY8UCg M8KpFRmDSvB3EvycBVGoQF6eb1xjKQMXWVYFxh77qPpiCO5JGglotRFlNiXKBSFFee1fA 5OJguqAd8hmhdDcUPa/SqFCyTnhX36YY0MQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1644570395631100001 Content-Type: text/plain; charset="utf-8" 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. Cc: Jiewen Yao Cc: Jian J Wang Cc: Xiaoyu Lu Cc: Guomin Jiang Cc: Siyuan Fu Signed-off-by: Zhihao Li --- CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c | 3= 13 ++++++++++++++++++++ CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c | 2= 75 +++++++++++++++++ CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c | 1= 02 +++++++ CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c | = 53 ++++ CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests.c | 1= 52 ++++++++++ CryptoPkg/CryptoPkg.dec | = 9 +- CryptoPkg/Include/Library/BaseCryptLib.h | = 29 +- CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf | = 12 +- CryptoPkg/Library/Include/CrtLibSupport.h | = 5 +- CryptoPkg/Library/Include/sha3.h | = 32 ++ CryptoPkg/Library/Include/xkcp.h | = 23 ++ CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h | = 3 +- CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf | = 7 + CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf | = 6 + 14 files changed, 1016 insertions(+), 5 deletions(-) diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c b/CryptoP= kg/Library/BaseCryptLib/Hash/CryptCShake256.c new file mode 100644 index 0000000000..5efced3f46 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptCShake256.c @@ -0,0 +1,313 @@ +/** @file + cSHAKE-256 Digest Wrapper Implementations. + +Copyright (c) 2022, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "InternalCryptLib.h" +#include "sha3.h" +#include "xkcp.h" + +#define CSHAKE256_SECURITY_STRENGTH 256 +#define CSHAKE256_RATE_IN_BYTES 136 + +const CHAR8 mZeroPadding[CSHAKE256_RATE_IN_BYTES] =3D {0}; + +UINTN +EFIAPI +LeftEncode ( + OUT UINT8 *Encbuf, + IN UINTN Value + ) +{ + return left_encode (Encbuf, Value); +} + +UINTN +EFIAPI +RightEncode ( + OUT UINT8 *Encbuf, + IN UINTN Value + ) +{ + return right_encode (Encbuf, Value); +} + +/** + Retrieves the size, in bytes, of the context buffer required for cSHAKE-= 256 hash operations. + + @return The size, in bytes, of the context buffer required for cSHAKE-2= 56 hash operations. + +**/ +UINTN +EFIAPI +CShake256GetContextSize ( + VOID + ) +{ + return (UINTN) (sizeof (KECCAK1600_CTX)); +} + +/** + Initializes user-supplied memory pointed by CShake256Context as cSHAKE-2= 56 hash context for + subsequent use. + + @param[out] CShake256Context Pointer to cSHAKE-256 context being initi= alized. + @param[in] OutputLen The desired number of output length in by= tes. + @param[in] Name Pointer to the function name string. + @param[in] NameLen The length of the function name in bytes. + @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; + unsigned char EncBuf[sizeof(size_t)+1]; + UINTN EncLen; + UINTN AbsorbLen; + UINTN PadLen; + + // + // Check input parameters. + // + if (CShake256Context =3D=3D NULL || + OutputLen =3D=3D 0 || + (NameLen !=3D 0 && Name =3D=3D NULL) || + (CustomizationLen !=3D 0 && 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 equivale= nt to + // SHAKE as defined in FIPS 202. + // + return (BOOLEAN) init ( + (KECCAK1600_CTX *) CShake256Context, + '\x1f', + (KECCAK1600_WIDTH - CSHAKE256_SECURITY_STRENGTH * 2)= / 8, + OutputLen + ); + } + + Status =3D (BOOLEAN) init ( + (KECCAK1600_CTX *) CShake256Context, + '\x04', + (KECCAK1600_WIDTH - CSHAKE256_SECURITY_STRENGTH * 2)= / 8, + OutputLen + ); + if (!Status) { + return FALSE; + } + + AbsorbLen =3D 0; + // + // Absorb Absorb bytepad(.., rate). + // + EncLen =3D left_encode (EncBuf, CSHAKE256_RATE_IN_BYTES); + Status =3D (BOOLEAN) sha3_update ((KECCAK1600_CTX *) CShake256Context, E= ncBuf, EncLen); + if (!Status) { + return FALSE; + } + AbsorbLen +=3D EncLen; + + // + // Absorb encode_string(N). + // + EncLen =3D left_encode (EncBuf, NameLen * 8); + Status =3D (BOOLEAN) sha3_update ((KECCAK1600_CTX *) CShake256Context, E= ncBuf, EncLen); + if (!Status) { + return FALSE; + } + AbsorbLen +=3D EncLen; + Status =3D (BOOLEAN) sha3_update ((KECCAK1600_CTX *) CShake256Context, N= ame, NameLen); + if (!Status) { + return FALSE; + } + AbsorbLen +=3D NameLen; + + // + // Absorb encode_string(S). + // + EncLen =3D left_encode (EncBuf, CustomizationLen * 8); + Status =3D (BOOLEAN) sha3_update ((KECCAK1600_CTX *) CShake256Context, E= ncBuf, EncLen); + if (!Status) { + return FALSE; + } + AbsorbLen +=3D EncLen; + Status =3D (BOOLEAN) sha3_update ((KECCAK1600_CTX *) CShake256Context, C= ustomization, 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) sha3_update ((KECCAK1600_CTX *) CShake256Context, m= ZeroPadding, 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 specifi= ed size. + It can be called multiple times to compute the digest of long or discont= inuous data streams. + cSHAKE-256 context should be already correctly initialized by CShake256I= nit(), and should not be finalized + by CShake256Final(). Behavior with invalid context is undefined. + + @param[in, out] CShake256Context Pointer to the cSHAKE-256 context. + @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 checked in= OpenSSL. + // + if (Data =3D=3D NULL && DataSize !=3D 0) { + return FALSE; + } + + return (BOOLEAN)(sha3_update ((KECCAK1600_CTX *) CShake256Context, Data,= DataSize)); +} + +/** + Completes computation of the cSHAKE-256 digest value. + + This function completes cSHAKE-256 hash computation and retrieves the di= gest value into + the specified memory. After this function has been called, the cSHAKE-25= 6 context cannot + be used again. + cSHAKE-256 context should be already correctly initialized by CShake256I= nit(), and should not be + finalized by CShake256Final(). Behavior with invalid cSHAKE-256 context = is undefined. + + @param[in, out] CShake256Context Pointer to the cSHAKE-256 context. + @param[out] HashValue Pointer to a buffer that receives the= cSHAKE-256 digest + value. + + @retval TRUE cSHAKE-256 digest computation succeeded. + @retval FALSE cSHAKE-256 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +CShake256Final ( + IN OUT VOID *CShake256Context, + OUT UINT8 *HashValue + ) +{ + // + // Check input parameters. + // + if (CShake256Context =3D=3D NULL || HashValue =3D=3D NULL) { + return FALSE; + } + + // + // cSHAKE-256 Hash Finalization. + // + return (BOOLEAN) (sha3_final ((KECCAK1600_CTX *) CShake256Context, HashV= alue)); +} + +/** + Computes the CSHAKE-256 message digest of a input data buffer. + + This function performs the CSHAKE-256 message digest of a given data buf= fer, and places + the digest value into the specified memory. + + @param[in] Data Pointer to the buffer containing the dat= a 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 byte= s. + @param[out] HashValue Pointer to a buffer that receives the CS= HAKE-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/Cryp= toPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c new file mode 100644 index 0000000000..3eaa7c2ceb --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c @@ -0,0 +1,275 @@ +/** @file + ParallelHash Implementation. + +Copyright (c) 2022, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "InternalCryptLib.h" +#include +#include +#include + + +UINT16 mBlockNum; +UINTN mBlockSize; +UINTN mLastBlockSize; +UINT8 *mInput; +UINTN mBlockResultSize; +UINT8 *mBlockHashResult; +BOOLEAN *mBlockIsCompleted; +SPIN_LOCK *mSpinLockList; + +UINTN LeftEncode (OUT UINT8 *Encbuf, IN UINTN Value); +UINTN RightEncode (OUT UINT8 *Encbuf, IN UINTN Value); + +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 + ); + +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 : mBlockS= ize, + mBlockResultSize, + NULL, + 0, + NULL, + 0, + mBlockHashResult + Index * mBlockResultSize + ); + if (!EFI_ERROR (Status)){ + mBlockIsCompleted[Index] =3D TRUE; + } + ReleaseSpinLock (&mSpinLockList[Index]); + } + } +} + +/** + Parallel hash function ParallelHash256, as defined in NIST's Special Pub= lication 800-185, + published December 2016. + + @param Input[in] Pointer to the input message (X). + @param InputByteLen[in] The number(>0) of input bytes provided for = the input data. + @param Output[out] Pointer to the output buffer. + @param OutputByteLen[in] The desired number of output bytes (L). + @param Customization[in] Pointer to the customization string (S). + @param CustomByteLen[in] The length of the customization string in b= ytes. + + @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, + 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; + EFI_STATUS Status; + UINTN StartedApNum; + BOOLEAN AllCompleted; + UINTN Offset; + BOOLEAN ReturnValue; + + if (InputByteLen =3D=3D 0 || OutputByteLen =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; + } + + // + // Get Block number n. + // + mBlockNum =3D PcdGet16 (PcdParallelHashBlockNumber); + + if (mBlockNum < 1 || InputByteLen < mBlockNum - 1){ + return FALSE; + } + + // + // Set hash result size of each block in bytes. + // + mBlockResultSize =3D OutputByteLen; + + // + // calculate the block byte length B. + // + mBlockSize =3D InputByteLen % mBlockNum =3D=3D 0 ? InputByteLen / mBlock= Num : InputByteLen / (mBlockNum - 1); + + // + // 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 and S= pinLock. + // + CombinedInputSize =3D EncSizeB + EncSizeN + EncSizeL + mBlockNum * mBloc= kResultSize; + 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 || mSpinL= ockList =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 Input; + mLastBlockSize =3D InputByteLen % mBlockSize =3D=3D 0 ? mBlockSize : Inp= utByteLen % mBlockSize; + + // + // Initialize SpinLock for each result block. + // + for (Index =3D 0; Index < mBlockNum; Index++) { + InitializeSpinLock (&mSpinLockList[Index]); + } + + // + // Dispatch blocklist to each AP. + // + StartedApNum =3D 0; + for (Index =3D 0; Index < gMmst->NumberOfCpus; Index++) { + if (Index !=3D gMmst->CurrentlyExecutingCpu) { + Status =3D gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NUL= L); + if (!EFI_ERROR (Status)) { + StartedApNum++; + } + } + } + + // + // 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)) ? mLastBlockSize : mBl= ockSize, + 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 (mSpinLockList); + } + if (mBlockIsCompleted !=3D NULL){ + FreePool (mBlockIsCompleted); + } + + return ReturnValue; +} diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c b/CryptoPkg/Li= brary/BaseCryptLib/Hash/CryptSha3.c new file mode 100644 index 0000000000..b170c463de --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptSha3.c @@ -0,0 +1,102 @@ +/** @file + SHA3 realted functions from OpenSSL. + +Copyright (c) 2022, Intel Corporation. All rights 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 copy +in the file LICENSE in the source distribution or at +https://www.openssl.org/source/license.html + +**/ + +#include "sha3.h" + +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); + +int init(KECCAK1600_CTX *ctx, unsigned char pad, size_t bsz, size_t md_siz= e) +{ + if (bsz <=3D sizeof(ctx->buf)) { + memset(ctx->A, 0, sizeof(ctx->A)); + + ctx->num =3D 0; + ctx->block_size =3D bsz; + ctx->md_size =3D md_size; + ctx->pad =3D pad; + + return 1; + } + + return 0; +} + + +int sha3_update(KECCAK1600_CTX *ctx, const void *_inp, size_t len) +{ + const unsigned char *inp =3D _inp; + size_t bsz =3D ctx->block_size; + size_t num, rem; + + if (len =3D=3D 0) + return 1; + + if ((num =3D ctx->num) !=3D 0) { /* process intermediate buffer? = */ + rem =3D bsz - num; + + if (len < rem) { + memcpy(ctx->buf + num, inp, len); + ctx->num +=3D len; + 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(ctx->buf + num, inp, rem); + inp +=3D rem, len -=3D rem; + (void)SHA3_absorb(ctx->A, ctx->buf, bsz, bsz); + ctx->num =3D 0; + /* ctx->buf is processed, ctx->num is guaranteed to be zero */ + } + + if (len >=3D bsz) + rem =3D SHA3_absorb(ctx->A, inp, len, bsz); + else + rem =3D len; + + if (rem) { + memcpy(ctx->buf, inp + len - rem, rem); + ctx->num =3D rem; + } + + return 1; +} + +int sha3_final(KECCAK1600_CTX *ctx, unsigned char *md) +{ + size_t bsz =3D ctx->block_size; + size_t num =3D ctx->num; + + if (ctx->md_size =3D=3D 0) + return 1; + + /* + * Pad the data with 10*1. Note that |num| can be |bsz - 1| + * in which case both byte operations below are performed on + * same byte... + */ + memset(ctx->buf + num, 0, bsz - num); + ctx->buf[num] =3D ctx->pad; + ctx->buf[bsz - 1] |=3D 0x80; + + (void)SHA3_absorb(ctx->A, ctx->buf, bsz, bsz); + + SHA3_squeeze(ctx->A, md, ctx->md_size, bsz); + + return 1; +} diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c b/CryptoPkg/Li= brary/BaseCryptLib/Hash/CryptXkcp.c new file mode 100644 index 0000000000..b2a40ee044 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c @@ -0,0 +1,53 @@ +/** @file + Encode realted functions from Xkcp. + +Copyright (c) 2022, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +The eXtended Keccak Code Package (XKCP) +https://github.com/XKCP/XKCP +Keccak, designed by Guido Bertoni, Joan Daemen, Micha=C3=ABl Peeters and G= illes Van Assche. +Implementation by the designers, hereby denoted as "the implementer". +For more information, feedback or questions, please refer to the Keccak Te= am 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 "xkcp.h" + +unsigned int left_encode(unsigned char * encbuf, size_t value) +{ + unsigned int n, i; + size_t v; + + for ( v =3D value, n =3D 0; v && (n < sizeof(size_t)); ++n, v >>=3D 8 ) + ; /* empty */ + if (n =3D=3D 0) + n =3D 1; + for ( i =3D 1; i <=3D n; ++i ) + { + encbuf[i] =3D (unsigned char)(value >> (8 * (n-i))); + } + encbuf[0] =3D (unsigned char)n; + return n + 1; +} + +unsigned int right_encode(unsigned char * encbuf, size_t value) +{ + unsigned int n, i; + size_t v; + + for ( v =3D value, n =3D 0; v && (n < sizeof(size_t)); ++n, v >>=3D 8 ) + ; /* empty */ + if (n =3D=3D 0) + n =3D 1; + for ( i =3D 1; i <=3D n; ++i ) + { + encbuf[i-1] =3D (unsigned char)(value >> (8 * (n-i))); + } + encbuf[n] =3D (unsigned char)n; + return n + 1; +} diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests= .c b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests.c new file mode 100644 index 0000000000..052ab3a0d6 --- /dev/null +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/ParallelhashTests.c @@ -0,0 +1,152 @@ +/** @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, 0x13, = 0x14, 0x15, 0x16, 0x17, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27 +}; +GLOBAL_REMOVE_IF_UNREFERENCED UINTN InputSample1ByteLen =3D 24= ; // Length of sample1 input data in bytes. +GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID *CustomizationSample1 =3D ""= ; // Customization string (S) of sample1. +GLOBAL_REMOVE_IF_UNREFERENCED UINTN CustomSample1ByteLen =3D 0;= // Customization string length of sample1 in bytes. +GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample1 =3D 8;= // Block size of sample1. +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 ExpectOutputSample1[] =3D { + // Expected output data of sample1. + 0xbc, 0x1e, 0xf1, 0x24, 0xda, 0x34, 0x49, 0x5e, 0x94, 0x8e, 0xad, 0x20, = 0x7d, 0xd9, 0x84, 0x22, + 0x35, 0xda, 0x43, 0x2d, 0x2b, 0xbc, 0x54, 0xb4, 0xc1, 0x10, 0xe6, 0x4c, = 0x45, 0x11, 0x05, 0x53, + 0x1b, 0x7f, 0x2a, 0x3e, 0x0c, 0xe0, 0x55, 0xc0, 0x28, 0x05, 0xe7, 0xc2, = 0xde, 0x1f, 0xb7, 0x46, + 0xaf, 0x97, 0xa1, 0xd0, 0x01, 0xf4, 0x3b, 0x82, 0x4e, 0x31, 0xb8, 0x76, = 0x12, 0x41, 0x04, 0x29 +}; + +// +// Parallelhash Test Sample #2 from NIST Special Publication 800-185. +// +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 *InputSample2 =3D In= putSample1; // 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 "P= arallel Data"; // Customization string (S) of sample2. +GLOBAL_REMOVE_IF_UNREFERENCED UINTN CustomSample2ByteLen =3D 13= ; // Customization string length of sample2 in bytes. +GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample2 =3D 8;= // Block size of sample2. +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 ExpectOutputSample2[] =3D { + // Expected output data of sample2. + 0xcd, 0xf1, 0x52, 0x89, 0xb5, 0x4f, 0x62, 0x12, 0xb4, 0xbc, 0x27, 0x05, = 0x28, 0xb4, 0x95, 0x26, + 0x00, 0x6d, 0xd9, 0xb5, 0x4e, 0x2b, 0x6a, 0xdd, 0x1e, 0xf6, 0x90, 0x0d, = 0xda, 0x39, 0x63, 0xbb, + 0x33, 0xa7, 0x24, 0x91, 0xf2, 0x36, 0x96, 0x9c, 0xa8, 0xaf, 0xae, 0xa2, = 0x9c, 0x68, 0x2d, 0x47, + 0xa3, 0x93, 0xc0, 0x65, 0xb3, 0x8e, 0x29, 0xfa, 0xe6, 0x51, 0xa2, 0x09, = 0x1c, 0x83, 0x31, 0x10 +}; + +// +// Parallelhash Test Sample #3 from NIST Special Publication 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, 0x0b, = 0x10, 0x11, 0x12, 0x13, + 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x20, 0x21, 0x22, 0x23, = 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, = 0x38, 0x39, 0x3a, 0x3b, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, = 0x50, 0x51, 0x52, 0x53, + 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b +}; +GLOBAL_REMOVE_IF_UNREFERENCED UINTN InputSample3ByteLen =3D 72= ; // Length of sample3 input data in bytes. +GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID *CustomizationSample3 =3D "P= arallel Data"; // Customization string (S) of sample3. +GLOBAL_REMOVE_IF_UNREFERENCED UINTN CustomSample3ByteLen =3D 13= ; // Customization string length of sample3 in bytes. +GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample3 =3D 12= ; // Block size of sample3. +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 ExpectOutputSample3[] =3D { + // Expected output data of sample3. + 0x69, 0xd0, 0xfc, 0xb7, 0x64, 0xea, 0x05, 0x5d, 0xd0, 0x93, 0x34, 0xbc, = 0x60, 0x21, 0xcb, 0x7e, + 0x4b, 0x61, 0x34, 0x8d, 0xff, 0x37, 0x5d, 0xa2, 0x62, 0x67, 0x1c, 0xde, = 0xc3, 0xef, 0xfa, 0x8d, + 0x1b, 0x45, 0x68, 0xa6, 0xcc, 0xe1, 0x6b, 0x1c, 0xad, 0x94, 0x6d, 0xdd, = 0xe2, 0x7f, 0x6c, 0xe2, + 0xb8, 0xde, 0xe4, 0xcd, 0x1b, 0x24, 0x85, 0x1e, 0xbf, 0x00, 0xeb, 0x90, = 0xd4, 0x38, 0x13, 0xe9 +}; + +UNIT_TEST_STATUS +EFIAPI +TestVerifyParallelHash256HashAll ( + IN UNIT_TEST_CONTEXT Context + ) +{ + BOOLEAN Status; + UINT16 OriginalParallelHashBlockNumber; + UINT8 Output[64]; + + // Restore original PcdParallelHashBlockNumber. + OriginalParallelHashBlockNumber =3D PcdGet16 (PcdParallelHashBlockNumber= ); + + // + // Test #1 using sample1. + // + PcdSet16S (PcdParallelHashBlockNumber, InputSample1ByteLen / BlockSizeSa= mple1); + Status =3D ParallelHash256HashAll ( + InputSample1, + InputSample1ByteLen, + 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. + // + PcdSet16S (PcdParallelHashBlockNumber, InputSample2ByteLen / BlockSizeSa= mple2); + Status =3D ParallelHash256HashAll ( + InputSample2, + InputSample2ByteLen, + 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. + // + PcdSet16S (PcdParallelHashBlockNumber, InputSample3ByteLen / BlockSizeSa= mple3); + Status =3D ParallelHash256HashAll ( + InputSample3, + InputSample3ByteLen, + Output, + OutputByteLen, + CustomizationSample3, + CustomSample3ByteLen + ); + UT_ASSERT_TRUE (Status); + + // Check the output with the expected output. + UT_ASSERT_MEM_EQUAL (Output, ExpectOutputSample3, OutputByteLen); + + // Recover original PcdParallelHashBlockNumber. + PcdSet16S (PcdParallelHashBlockNumber, OriginalParallelHashBlockNumber); + + return EFI_SUCCESS; +} + +TEST_DESC mParallelhashTest[] =3D { + // + // -----Description------------------------------Class------------------= ----Function-----------------Pre---Post--Context + // + { "TestVerifyParallelHash256HashAll()", "CryptoPkg.BaseCryptLib.Parallel= Hash256HashAll", TestVerifyParallelHash256HashAll, NULL, NULL, NULL }, +}; + +UINTN mParallelhashTestNum =3D ARRAY_SIZE (mParallelhashTest); diff --git a/CryptoPkg/CryptoPkg.dec b/CryptoPkg/CryptoPkg.dec index 5888941bab..3af55d9c10 100644 --- a/CryptoPkg/CryptoPkg.dec +++ b/CryptoPkg/CryptoPkg.dec @@ -4,7 +4,7 @@ # This Package provides cryptographic-related libraries for UEFI security= modules. # It also provides a test application to test libraries. # -# 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 # ## @@ -81,5 +81,12 @@ # @ValidList 0x80000001 | 0x00000001, 0x00000002, 0x00000004, 0x00000008= , 0x00000010 gEfiCryptoPkgTokenSpaceGuid.PcdHashApiLibPolicy|0x00000002|UINT32|0x0000= 0001 =20 +[PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] + ## This PCD indicates the block number of parallel hash + # Based on the value set, parallel hash can chose the block + # number to calculate specific hash.
+ # The number can be set by platform team according to the core number. + gEfiCryptoPkgTokenSpaceGuid.PcdParallelHashBlockNumber|0x0100|UINT16|0x0= 0000003 + [UserExtensions.TianoCore."ExtraFiles"] CryptoPkgExtra.uni diff --git a/CryptoPkg/Include/Library/BaseCryptLib.h b/CryptoPkg/Include/L= ibrary/BaseCryptLib.h index f4bc7c0d73..0b274b1257 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 functionality enabling. =20 -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 =20 **/ @@ -753,6 +753,33 @@ Sha512HashAll ( OUT UINT8 *HashValue ); =20 +/** + Parallel hash function ParallelHash256, as defined in NIST's Special Pub= lication 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[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, + 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 has= h operations. =20 diff --git a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf b/CryptoPkg/Lib= rary/BaseCryptLib/SmmCryptLib.inf index e6470d7a21..70159163d4 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 # authenticode signature verification functions are not supported in this= instance. # -# Copyright (c) 2010 - 2021, Intel Corporation. All rights reserved.
+# Copyright (c) 2010 - 2022, Intel Corporation. All rights reserved.
# 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,9 @@ OpensslLib IntrinsicLib PrintLib + MmServicesTableLib + SynchronizationLib + PcdLib =20 # # Remove these [BuildOptions] after this library is cleaned up @@ -101,3 +108,6 @@ GCC:*_CLANG35_*_CC_FLAGS =3D -std=3Dc99 GCC:*_CLANG38_*_CC_FLAGS =3D -std=3Dc99 GCC:*_CLANGPDB_*_CC_FLAGS =3D -std=3Dc99 -Wno-error=3Dincompatible-point= er-types + +[Pcd] + gEfiCryptoPkgTokenSpaceGuid.PcdParallelHashBlockNumber diff --git a/CryptoPkg/Library/Include/CrtLibSupport.h b/CryptoPkg/Library/= Include/CrtLibSupport.h index d257dca8fa..35d9c62a0b 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 cryptographic library. =20 -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 rights = reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -21,6 +21,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #define MAX_STRING_SIZE 0x1000 =20 +#define PARALLELHASH_CUSTOMIZATION "ParallelHash" + // // We already have "no-ui" in out Configure invocation. // but the code still fails to compile. @@ -111,6 +113,7 @@ typedef UINT8 u_char; typedef UINT32 uid_t; typedef UINT32 gid_t; typedef CHAR16 wchar_t; +typedef UINT64 uint64_t; =20 // // File operations are not required for EFI building, diff --git a/CryptoPkg/Library/Include/sha3.h b/CryptoPkg/Library/Include/s= ha3.h new file mode 100644 index 0000000000..71b4c75548 --- /dev/null +++ b/CryptoPkg/Library/Include/sha3.h @@ -0,0 +1,32 @@ +/** @file + SHA3 realted functions from OpenSSL. + +Copyright (c) 2022, Intel Corporation. All rights 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 copy +in the file LICENSE in the source distribution or at +https://www.openssl.org/source/license.html + +**/ + +#include + +#define KECCAK1600_WIDTH 1600 + +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; + +int init(KECCAK1600_CTX *ctx, unsigned char pad, size_t bsz, size_t md_siz= e); + +int sha3_update(KECCAK1600_CTX *ctx, const void *_inp, size_t len); + +int sha3_final(KECCAK1600_CTX *ctx, unsigned char *md); diff --git a/CryptoPkg/Library/Include/xkcp.h b/CryptoPkg/Library/Include/x= kcp.h new file mode 100644 index 0000000000..b328d672e4 --- /dev/null +++ b/CryptoPkg/Library/Include/xkcp.h @@ -0,0 +1,23 @@ +/** @file + Encode realted functions from Xkcp. + +Copyright (c) 2022, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +The eXtended Keccak Code Package (XKCP) +https://github.com/XKCP/XKCP +Keccak, designed by Guido Bertoni, Joan Daemen, Micha=C3=ABl Peeters and G= illes Van Assche. +Implementation by the designers, hereby denoted as "the implementer". +For more information, feedback or questions, please refer to the Keccak Te= am 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 + +unsigned int left_encode(unsigned char * encbuf, size_t value); + +unsigned int right_encode(unsigned char * encbuf, size_t value); diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.= h b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h index a6b3482742..0bffd687c2 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h @@ -1,7 +1,7 @@ /** @file Application for Cryptographic Primitives Validation. =20 -Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -19,6 +19,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include // #include #include // #include diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibH= ost.inf b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost= .inf index 00c8692650..61a59d6a47 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 ## =20 @@ -35,6 +36,7 @@ Pkcs7EkuTests.c OaepEncryptTests.c RsaPssTests.c + ParallelhashTests.c =20 [Packages] MdePkg/MdePkg.dec @@ -45,3 +47,8 @@ DebugLib BaseCryptLib UnitTestLib + PcdLib + +[Pcd] + gEfiCryptoPkgTokenSpaceGuid.PcdParallelHashBlockNumber + diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibS= hell.inf b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShe= ll.inf index ca789aa6ad..682f25a754 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibShell.inf @@ -2,6 +2,7 @@ # BaseCryptLib UnitTest built for execution in UEFI Shell. # # Copyright (c) Microsoft Corporation.
+# Copyright (c) 2022, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent ## =20 @@ -36,6 +37,7 @@ Pkcs7EkuTests.c OaepEncryptTests.c RsaPssTests.c + ParallelhashTests.c =20 [Packages] MdePkg/MdePkg.dec @@ -48,3 +50,7 @@ UnitTestLib PrintLib BaseCryptLib + PcdLib + +[Pcd] + gEfiCryptoPkgTokenSpaceGuid.PcdParallelHashBlockNumber --=20 2.26.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#86615): https://edk2.groups.io/g/devel/message/86615 Mute This Topic: https://groups.io/mt/89067196/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-