diff options
author | Zhihao Li <zhihao.li@intel.com> | 2022-11-30 22:21:02 +0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2022-12-02 14:12:51 +0000 |
commit | 5d5be45bd11117c1e479863125e7d772e54772c9 (patch) | |
tree | 2c8421ac1e19fd33a824ef028b4d2f54e5d29e8b /CryptoPkg/Library | |
parent | 47d988387efc8b45561f542f7a8e5b6a43979a8c (diff) | |
download | edk2-5d5be45bd11117c1e479863125e7d772e54772c9.zip edk2-5d5be45bd11117c1e479863125e7d772e54772c9.tar.gz edk2-5d5be45bd11117c1e479863125e7d772e54772c9.tar.bz2 |
CryptPkg: Enable CryptoPkg BaseCryptLib ParallelHash for PEI and DXE
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4097
The BaseCryptLib in the CryptoPkg currently supports ParallelHash
algorithm for SMM. The MP Services PPI and MP Services Protocol
could be used to enable ParallelHash in PEI and DXE
versions of the BaseCryptLib.
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Signed-off-by: Zhihao Li <zhihao.li@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Diffstat (limited to 'CryptoPkg/Library')
8 files changed, 183 insertions, 27 deletions
diff --git a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf index 213813c..5be1724 100644 --- a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf @@ -35,7 +35,11 @@ Hash/CryptSha256.c
Hash/CryptSha512.c
Hash/CryptSm3.c
- Hash/CryptParallelHashNull.c
+ Hash/CryptSha3.c
+ Hash/CryptXkcp.c
+ Hash/CryptCShake256.c
+ Hash/CryptParallelHash.c
+ Hash/CryptDispatchApDxe.c
Hmac/CryptHmac.c
Kdf/CryptHkdf.c
Cipher/CryptAes.c
@@ -93,6 +97,11 @@ OpensslLib
IntrinsicLib
PrintLib
+ UefiBootServicesTableLib
+ SynchronizationLib
+
+[Protocols]
+ gEfiMpServiceProtocolGuid
#
# Remove these [BuildOptions] after this library is cleaned up
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c new file mode 100644 index 0000000..607aa7c --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c @@ -0,0 +1,49 @@ +/** @file
+ Dispatch Block to Aps in Dxe phase for parallelhash algorithm.
+
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "CryptParallelHash.h"
+#include <Library/UefiBootServicesTableLib.h>
+#include <Protocol/MpService.h>
+
+/**
+ Dispatch the block task to each AP in PEI phase.
+
+**/
+VOID
+EFIAPI
+DispatchBlockToAp (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ EFI_MP_SERVICES_PROTOCOL *MpServices;
+
+ Status = gBS->LocateProtocol (
+ &gEfiMpServiceProtocolGuid,
+ NULL,
+ (VOID **)&MpServices
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // Failed to locate MpServices Protocol, do parallel hash by one core.
+ //
+ DEBUG ((DEBUG_ERROR, "[DispatchBlockToApDxe] Failed to locate MpServices Protocol. Status = %r\n", Status));
+ return;
+ }
+
+ Status = MpServices->StartupAllAPs (
+ MpServices,
+ ParallelHashApExecute,
+ FALSE,
+ NULL,
+ 0,
+ NULL,
+ NULL
+ );
+ return;
+}
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c new file mode 100644 index 0000000..0237fb3 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c @@ -0,0 +1,35 @@ +/** @file
+ Dispatch the block task to each AP in Smm mode for parallelhash algorithm.
+
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "CryptParallelHash.h"
+#include <Library/MmServicesTableLib.h>
+
+/**
+ Dispatch the block task to each AP in SMM mode.
+
+**/
+VOID
+EFIAPI
+DispatchBlockToAp (
+ VOID
+ )
+{
+ UINTN Index;
+
+ if (gMmst == NULL) {
+ return;
+ }
+
+ for (Index = 0; Index < gMmst->NumberOfCpus; Index++) {
+ if (Index != gMmst->CurrentlyExecutingCpu) {
+ gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NULL);
+ }
+ }
+
+ return;
+}
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c new file mode 100644 index 0000000..9ddd23d --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c @@ -0,0 +1,54 @@ +/** @file
+ Dispatch Block to Aps in Pei phase for parallelhash algorithm.
+
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "CryptParallelHash.h"
+#include <Library/PeiServicesTablePointerLib.h>
+#include <PiPei.h>
+#include <Ppi/MpServices.h>
+#include <Library/PeiServicesLib.h>
+
+/**
+ Dispatch the block task to each AP in PEI phase.
+
+**/
+VOID
+EFIAPI
+DispatchBlockToAp (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ CONST EFI_PEI_SERVICES **PeiServices;
+ EFI_PEI_MP_SERVICES_PPI *MpServicesPpi;
+
+ PeiServices = GetPeiServicesTablePointer ();
+ Status = (*PeiServices)->LocatePpi (
+ PeiServices,
+ &gEfiPeiMpServicesPpiGuid,
+ 0,
+ NULL,
+ (VOID **)&MpServicesPpi
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // Failed to locate MpServices Ppi, do parallel hash by one core.
+ //
+ DEBUG ((DEBUG_ERROR, "[DispatchBlockToApPei] Failed to locate MpServices Ppi. Status = %r\n", Status));
+ return;
+ }
+
+ Status = MpServicesPpi->StartupAllAPs (
+ (CONST EFI_PEI_SERVICES **)PeiServices,
+ MpServicesPpi,
+ ParallelHashApExecute,
+ FALSE,
+ 0,
+ NULL
+ );
+ return;
+}
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c index f7ce9db..2931123 100644 --- a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c @@ -7,7 +7,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/
#include "CryptParallelHash.h"
-#include <Library/MmServicesTableLib.h>
#include <Library/SynchronizationLib.h>
#define PARALLELHASH_CUSTOMIZATION "ParallelHash"
@@ -70,27 +69,6 @@ ParallelHashApExecute ( }
/**
- Dispatch the block task to each AP in SMM mode.
-
-**/
-VOID
-EFIAPI
-MmDispatchBlockToAP (
- VOID
- )
-{
- UINTN Index;
-
- for (Index = 0; Index < gMmst->NumberOfCpus; Index++) {
- if (Index != gMmst->CurrentlyExecutingCpu) {
- gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NULL);
- }
- }
-
- return;
-}
-
-/**
Parallel hash function ParallelHash256, as defined in NIST's Special Publication 800-185,
published December 2016.
@@ -197,9 +175,7 @@ ParallelHash256HashAll ( //
// Dispatch blocklist to each AP.
//
- if (gMmst != NULL) {
- MmDispatchBlockToAP ();
- }
+ DispatchBlockToAp ();
//
// Wait until all block hash completed.
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h index dcfe200..03a1a58 100644 --- a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h @@ -201,3 +201,26 @@ CShake256HashAll ( IN UINTN CustomizationLen,
OUT UINT8 *HashValue
);
+
+/**
+ Complete computation of digest of each block.
+
+ Each AP perform the function called by BSP.
+
+ @param[in] ProcedureArgument Argument of the procedure.
+**/
+VOID
+EFIAPI
+ParallelHashApExecute (
+ IN VOID *ProcedureArgument
+ );
+
+/**
+ Dispatch the block task to each AP.
+
+**/
+VOID
+EFIAPI
+DispatchBlockToAp (
+ VOID
+ );
diff --git a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf index b162964..2aafa5f 100644 --- a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf @@ -40,7 +40,11 @@ Hash/CryptSha256.c
Hash/CryptSm3.c
Hash/CryptSha512.c
- Hash/CryptParallelHashNull.c
+ Hash/CryptSha3.c
+ Hash/CryptXkcp.c
+ Hash/CryptCShake256.c
+ Hash/CryptParallelHash.c
+ Hash/CryptDispatchApPei.c
Hmac/CryptHmac.c
Kdf/CryptHkdf.c
Cipher/CryptAesNull.c
@@ -80,7 +84,12 @@ OpensslLib
IntrinsicLib
PrintLib
+ PeiServicesTablePointerLib
+ PeiServicesLib
+ SynchronizationLib
+[Ppis]
+ gEfiPeiMpServicesPpiGuid
#
# Remove these [BuildOptions] after this library is cleaned up
#
diff --git a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf index 0af7a3f..00ea7bf 100644 --- a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf +++ b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf @@ -42,6 +42,7 @@ Hash/CryptXkcp.c
Hash/CryptCShake256.c
Hash/CryptParallelHash.c
+ Hash/CryptDispatchApMm.c
Hmac/CryptHmac.c
Kdf/CryptHkdfNull.c
Cipher/CryptAes.c
|