]> git.proxmox.com Git - mirror_edk2.git/commitdiff
CryptPkg: Enable CryptoPkg BaseCryptLib ParallelHash for PEI and DXE
authorZhihao Li <zhihao.li@intel.com>
Wed, 30 Nov 2022 14:21:02 +0000 (22:21 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 2 Dec 2022 14:12:51 +0000 (14:12 +0000)
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>
CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c [new file with mode: 0644]
CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c [new file with mode: 0644]
CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c [new file with mode: 0644]
CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h
CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf

index 213813cad9716a7335ca819e62bf912122332173..5be1724f0852bab644ccfaf09cdc85aa5293c53e 100644 (file)
   Hash/CryptSha256.c\r
   Hash/CryptSha512.c\r
   Hash/CryptSm3.c\r
-  Hash/CryptParallelHashNull.c\r
+  Hash/CryptSha3.c\r
+  Hash/CryptXkcp.c\r
+  Hash/CryptCShake256.c\r
+  Hash/CryptParallelHash.c\r
+  Hash/CryptDispatchApDxe.c\r
   Hmac/CryptHmac.c\r
   Kdf/CryptHkdf.c\r
   Cipher/CryptAes.c\r
   OpensslLib\r
   IntrinsicLib\r
   PrintLib\r
+  UefiBootServicesTableLib\r
+  SynchronizationLib\r
+\r
+[Protocols]\r
+  gEfiMpServiceProtocolGuid\r
 \r
 #\r
 # Remove these [BuildOptions] after this library is cleaned up\r
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c
new file mode 100644 (file)
index 0000000..607aa7c
--- /dev/null
@@ -0,0 +1,49 @@
+/** @file\r
+  Dispatch Block to Aps in Dxe phase for parallelhash algorithm.\r
+\r
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include "CryptParallelHash.h"\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Protocol/MpService.h>\r
+\r
+/**\r
+  Dispatch the block task to each AP in PEI phase.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DispatchBlockToAp (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_MP_SERVICES_PROTOCOL  *MpServices;\r
+\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiMpServiceProtocolGuid,\r
+                  NULL,\r
+                  (VOID **)&MpServices\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Failed to locate MpServices Protocol, do parallel hash by one core.\r
+    //\r
+    DEBUG ((DEBUG_ERROR, "[DispatchBlockToApDxe] Failed to locate MpServices Protocol. Status = %r\n", Status));\r
+    return;\r
+  }\r
+\r
+  Status = MpServices->StartupAllAPs (\r
+                         MpServices,\r
+                         ParallelHashApExecute,\r
+                         FALSE,\r
+                         NULL,\r
+                         0,\r
+                         NULL,\r
+                         NULL\r
+                         );\r
+  return;\r
+}\r
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c
new file mode 100644 (file)
index 0000000..0237fb3
--- /dev/null
@@ -0,0 +1,35 @@
+/** @file\r
+  Dispatch the block task to each AP in Smm mode for parallelhash algorithm.\r
+\r
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include "CryptParallelHash.h"\r
+#include <Library/MmServicesTableLib.h>\r
+\r
+/**\r
+  Dispatch the block task to each AP in SMM mode.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DispatchBlockToAp (\r
+  VOID\r
+  )\r
+{\r
+  UINTN  Index;\r
+\r
+  if (gMmst == NULL) {\r
+    return;\r
+  }\r
+\r
+  for (Index = 0; Index < gMmst->NumberOfCpus; Index++) {\r
+    if (Index != gMmst->CurrentlyExecutingCpu) {\r
+      gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NULL);\r
+    }\r
+  }\r
+\r
+  return;\r
+}\r
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c
new file mode 100644 (file)
index 0000000..9ddd23d
--- /dev/null
@@ -0,0 +1,54 @@
+/** @file\r
+  Dispatch Block to Aps in Pei phase for parallelhash algorithm.\r
+\r
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include "CryptParallelHash.h"\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+#include <PiPei.h>\r
+#include <Ppi/MpServices.h>\r
+#include <Library/PeiServicesLib.h>\r
+\r
+/**\r
+  Dispatch the block task to each AP in PEI phase.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DispatchBlockToAp (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS               Status;\r
+  CONST EFI_PEI_SERVICES   **PeiServices;\r
+  EFI_PEI_MP_SERVICES_PPI  *MpServicesPpi;\r
+\r
+  PeiServices = GetPeiServicesTablePointer ();\r
+  Status      = (*PeiServices)->LocatePpi (\r
+                                  PeiServices,\r
+                                  &gEfiPeiMpServicesPpiGuid,\r
+                                  0,\r
+                                  NULL,\r
+                                  (VOID **)&MpServicesPpi\r
+                                  );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Failed to locate MpServices Ppi, do parallel hash by one core.\r
+    //\r
+    DEBUG ((DEBUG_ERROR, "[DispatchBlockToApPei] Failed to locate MpServices Ppi. Status = %r\n", Status));\r
+    return;\r
+  }\r
+\r
+  Status = MpServicesPpi->StartupAllAPs (\r
+                            (CONST EFI_PEI_SERVICES **)PeiServices,\r
+                            MpServicesPpi,\r
+                            ParallelHashApExecute,\r
+                            FALSE,\r
+                            0,\r
+                            NULL\r
+                            );\r
+  return;\r
+}\r
index f7ce9dbf523e9d518e4361e013a6874f81bf6f9c..2931123736e36ecd4309cee36c6f46f2cd5e5956 100644 (file)
@@ -7,7 +7,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 **/\r
 \r
 #include "CryptParallelHash.h"\r
-#include <Library/MmServicesTableLib.h>\r
 #include <Library/SynchronizationLib.h>\r
 \r
 #define PARALLELHASH_CUSTOMIZATION  "ParallelHash"\r
@@ -69,27 +68,6 @@ ParallelHashApExecute (
   }\r
 }\r
 \r
-/**\r
-  Dispatch the block task to each AP in SMM mode.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-MmDispatchBlockToAP (\r
-  VOID\r
-  )\r
-{\r
-  UINTN  Index;\r
-\r
-  for (Index = 0; Index < gMmst->NumberOfCpus; Index++) {\r
-    if (Index != gMmst->CurrentlyExecutingCpu) {\r
-      gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NULL);\r
-    }\r
-  }\r
-\r
-  return;\r
-}\r
-\r
 /**\r
   Parallel hash function ParallelHash256, as defined in NIST's Special Publication 800-185,\r
   published December 2016.\r
@@ -197,9 +175,7 @@ ParallelHash256HashAll (
   //\r
   // Dispatch blocklist to each AP.\r
   //\r
-  if (gMmst != NULL) {\r
-    MmDispatchBlockToAP ();\r
-  }\r
+  DispatchBlockToAp ();\r
 \r
   //\r
   // Wait until all block hash completed.\r
index dcfe200e5829faf46eed1c0bc72123635b91c7d1..03a1a58cb8e7410b4565f680f483e2f885ce8e29 100644 (file)
@@ -201,3 +201,26 @@ CShake256HashAll (
   IN   UINTN       CustomizationLen,\r
   OUT  UINT8       *HashValue\r
   );\r
+\r
+/**\r
+  Complete computation of digest of each block.\r
+\r
+  Each AP perform the function called by BSP.\r
+\r
+  @param[in] ProcedureArgument Argument of the procedure.\r
+**/\r
+VOID\r
+EFIAPI\r
+ParallelHashApExecute (\r
+  IN VOID  *ProcedureArgument\r
+  );\r
+\r
+/**\r
+  Dispatch the block task to each AP.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DispatchBlockToAp (\r
+  VOID\r
+  );\r
index b1629647f9c6661664aee5cc8749cf96b9b3bcef..2aafa5f0ac9aba03d871c67936ebd1c98eaeee16 100644 (file)
   Hash/CryptSha256.c\r
   Hash/CryptSm3.c\r
   Hash/CryptSha512.c\r
-  Hash/CryptParallelHashNull.c\r
+  Hash/CryptSha3.c\r
+  Hash/CryptXkcp.c\r
+  Hash/CryptCShake256.c\r
+  Hash/CryptParallelHash.c\r
+  Hash/CryptDispatchApPei.c\r
   Hmac/CryptHmac.c\r
   Kdf/CryptHkdf.c\r
   Cipher/CryptAesNull.c\r
   OpensslLib\r
   IntrinsicLib\r
   PrintLib\r
+  PeiServicesTablePointerLib\r
+  PeiServicesLib\r
+  SynchronizationLib\r
 \r
+[Ppis]\r
+  gEfiPeiMpServicesPpiGuid\r
 #\r
 # Remove these [BuildOptions] after this library is cleaned up\r
 #\r
index 0af7a3f96e8f01a78a68128fc8067f8eab6bf0af..00ea7bf4c5df3d8d52c86cd969e6df2c0b9aaad2 100644 (file)
@@ -42,6 +42,7 @@
   Hash/CryptXkcp.c\r
   Hash/CryptCShake256.c\r
   Hash/CryptParallelHash.c\r
+  Hash/CryptDispatchApMm.c\r
   Hmac/CryptHmac.c\r
   Kdf/CryptHkdfNull.c\r
   Cipher/CryptAes.c\r