]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SecurityPkg/RngDxe: Add Arm support of RngDxe
authorPierre Gondois <pierre.gondois@arm.com>
Fri, 28 Oct 2022 15:32:58 +0000 (17:32 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sun, 6 Nov 2022 16:32:28 +0000 (16:32 +0000)
Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668)

Add RngDxe support for Arm. This implementation uses the ArmTrngLib
to support the RawAlgorithm and doens't support the RNDR instruction.

To re-use the RngGetRNG(), RngGetInfo() and FreeAvailableAlgorithms()
functions, create Arm/AArch64 files which implement the arch specific
function GetAvailableAlgorithms(). Indeed, FEAT_RNG instruction is not
supported on Arm.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Acked-by: Jiewen Yao <jiewen.yao@intel.com>
SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c [new file with mode: 0644]
SecurityPkg/RandomNumberGenerator/RngDxe/Arm/ArmAlgo.c [new file with mode: 0644]
SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c
SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
SecurityPkg/SecurityPkg.dsc

diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c
new file mode 100644 (file)
index 0000000..e8be217
--- /dev/null
@@ -0,0 +1,72 @@
+/** @file\r
+  Aarch64 specific code.\r
+\r
+  Copyright (c) 2022, Arm Limited. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+**/\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/ArmTrngLib.h>\r
+\r
+#include "RngDxeInternals.h"\r
+\r
+// Maximum number of Rng algorithms.\r
+#define RNG_AVAILABLE_ALGO_MAX  2\r
+\r
+/** Allocate and initialize mAvailableAlgoArray with the available\r
+    Rng algorithms. Also update mAvailableAlgoArrayCount.\r
+\r
+  @retval EFI_SUCCESS             The function completed successfully.\r
+  @retval EFI_OUT_OF_RESOURCES    Could not allocate memory.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetAvailableAlgorithms (\r
+  VOID\r
+  )\r
+{\r
+  UINT64  DummyRand;\r
+  UINT16  MajorRevision;\r
+  UINT16  MinorRevision;\r
+\r
+  // Rng algorithms 2 times, one for the allocation, one to populate.\r
+  mAvailableAlgoArray = AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX);\r
+  if (mAvailableAlgoArray == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm.\r
+  if (!EFI_ERROR (RngGetBytes (sizeof (DummyRand), (UINT8 *)&DummyRand))) {\r
+    CopyMem (\r
+      &mAvailableAlgoArray[mAvailableAlgoArrayCount],\r
+      PcdGetPtr (PcdCpuRngSupportedAlgorithm),\r
+      sizeof (EFI_RNG_ALGORITHM)\r
+      );\r
+    mAvailableAlgoArrayCount++;\r
+\r
+    DEBUG_CODE_BEGIN ();\r
+    if (IsZeroGuid (PcdGetPtr (PcdCpuRngSupportedAlgorithm))) {\r
+      DEBUG ((\r
+        DEBUG_WARN,\r
+        "PcdCpuRngSupportedAlgorithm should be a non-zero GUID\n"\r
+        ));\r
+    }\r
+\r
+    DEBUG_CODE_END ();\r
+  }\r
+\r
+  // Raw algorithm (Trng)\r
+  if (!EFI_ERROR (GetArmTrngVersion (&MajorRevision, &MinorRevision))) {\r
+    CopyMem (\r
+      &mAvailableAlgoArray[mAvailableAlgoArrayCount],\r
+      &gEfiRngAlgorithmRaw,\r
+      sizeof (EFI_RNG_ALGORITHM)\r
+      );\r
+    mAvailableAlgoArrayCount++;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Arm/ArmAlgo.c b/SecurityPkg/RandomNumberGenerator/RngDxe/Arm/ArmAlgo.c
new file mode 100644 (file)
index 0000000..4b24f5c
--- /dev/null
@@ -0,0 +1,51 @@
+/** @file\r
+  Arm specific code.\r
+\r
+  Copyright (c) 2022, Arm Limited. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+**/\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/ArmTrngLib.h>\r
+\r
+#include "RngDxeInternals.h"\r
+\r
+// Maximum number of Rng algorithms.\r
+#define RNG_AVAILABLE_ALGO_MAX  1\r
+\r
+/** Allocate and initialize mAvailableAlgoArray with the available\r
+    Rng algorithms. Also update mAvailableAlgoArrayCount.\r
+\r
+  @retval EFI_SUCCESS             The function completed successfully.\r
+  @retval EFI_OUT_OF_RESOURCES    Could not allocate memory.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetAvailableAlgorithms (\r
+  VOID\r
+  )\r
+{\r
+  UINT16  MajorRevision;\r
+  UINT16  MinorRevision;\r
+\r
+  // Rng algorithms 2 times, one for the allocation, one to populate.\r
+  mAvailableAlgoArray = AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX);\r
+  if (mAvailableAlgoArray == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  // Raw algorithm (Trng)\r
+  if (!EFI_ERROR (GetArmTrngVersion (&MajorRevision, &MinorRevision))) {\r
+    CopyMem (\r
+      &mAvailableAlgoArray[mAvailableAlgoArrayCount],\r
+      &gEfiRngAlgorithmRaw,\r
+      sizeof (EFI_RNG_ALGORITHM)\r
+      );\r
+    mAvailableAlgoArrayCount++;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
index 318876d6933042362dd88d40e8fe29ec800318bb..5ba319899ce97243f08f2e8fcb9fb8cdb4095d49 100644 (file)
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/RngLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/ArmTrngLib.h>\r
 #include <Protocol/Rng.h>\r
 \r
 #include "RngDxeInternals.h"\r
 \r
-// Maximum number of Rng algorithms.\r
-#define RNG_AVAILABLE_ALGO_MAX  2\r
-\r
-/** Allocate and initialize mAvailableAlgoArray with the available\r
-    Rng algorithms. Also update mAvailableAlgoArrayCount.\r
-\r
-  @retval EFI_SUCCESS             The function completed successfully.\r
-  @retval EFI_OUT_OF_RESOURCES    Could not allocate memory.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-GetAvailableAlgorithms (\r
-  VOID\r
-  )\r
-{\r
-  UINT64  DummyRand;\r
-  UINT16  MajorRevision;\r
-  UINT16  MinorRevision;\r
-\r
-  // Rng algorithms 2 times, one for the allocation, one to populate.\r
-  mAvailableAlgoArray = AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX);\r
-  if (mAvailableAlgoArray == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm.\r
-  if (!EFI_ERROR (RngGetBytes (sizeof (DummyRand), (UINT8 *)&DummyRand))) {\r
-    CopyMem (\r
-      &mAvailableAlgoArray[mAvailableAlgoArrayCount],\r
-      PcdGetPtr (PcdCpuRngSupportedAlgorithm),\r
-      sizeof (EFI_RNG_ALGORITHM)\r
-      );\r
-    mAvailableAlgoArrayCount++;\r
-\r
-    DEBUG_CODE_BEGIN ();\r
-    if (IsZeroGuid (PcdGetPtr (PcdCpuRngSupportedAlgorithm))) {\r
-      DEBUG ((\r
-        DEBUG_WARN,\r
-        "PcdCpuRngSupportedAlgorithm should be a non-zero GUID\n"\r
-        ));\r
-    }\r
-\r
-    DEBUG_CODE_END ();\r
-  }\r
-\r
-  // Raw algorithm (Trng)\r
-  if (!EFI_ERROR (GetArmTrngVersion (&MajorRevision, &MinorRevision))) {\r
-    CopyMem (\r
-      &mAvailableAlgoArray[mAvailableAlgoArrayCount],\r
-      &gEfiRngAlgorithmRaw,\r
-      sizeof (EFI_RNG_ALGORITHM)\r
-      );\r
-    mAvailableAlgoArrayCount++;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
 /** Free mAvailableAlgoArray.\r
 **/\r
 VOID\r
index 1d0bdef57da4f3e9b908ca8645a26cfd117dfab3..c8e0ee4ae5d9b621d2d48a1f351e1d2d6f631b2d 100644 (file)
@@ -28,7 +28,7 @@
 #\r
 # The following information is for reference only and not required by the build tools.\r
 #\r
-#  VALID_ARCHITECTURES           = IA32 X64 AARCH64\r
+#  VALID_ARCHITECTURES           = IA32 X64 AARCH64 ARM\r
 #\r
 \r
 [Sources.common]\r
   Rand/AesCore.c\r
   Rand/AesCore.h\r
 \r
-[Sources.AARCH64]\r
+[Sources.AARCH64, Sources.ARM]\r
   ArmRngDxe.c\r
   ArmTrng.c\r
 \r
+[Sources.AARCH64]\r
+  AArch64/AArch64Algo.c\r
+\r
+[Sources.ARM]\r
+  Arm/ArmAlgo.c\r
+\r
 [Packages]\r
   MdeModulePkg/MdeModulePkg.dec\r
   MdePkg/MdePkg.dec\r
@@ -59,7 +65,7 @@
   TimerLib\r
   RngLib\r
 \r
-[LibraryClasses.AARCH64]\r
+[LibraryClasses.AARCH64, LibraryClasses.ARM]\r
   ArmTrngLib\r
 \r
 [Guids]\r
index f71ab7738efe68e6fefbdd4aee7c722ea8ed0c25..30d911d8a1418eca15846fe86d496c6d30803f10 100644 (file)
   SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.inf\r
   SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf\r
 \r
-[Components.IA32, Components.X64, Components.AARCH64]\r
+[Components.IA32, Components.X64, Components.AARCH64, Components.ARM]\r
   #\r
   # Random Number Generator\r
   #\r