From: Pierre Gondois <pierre.gond...@arm.com>

Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668)

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

Signed-off-by: Pierre Gondois <pierre.gond...@arm.com>
---
 SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c | 8 ++++++--
 SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf  | 9 ++++++---
 SecurityPkg/SecurityPkg.dsc                          | 2 +-
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c 
b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c
index ffa32a29dc6a..4775252d30b6 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c
@@ -22,6 +22,7 @@
 
 **/
 
+#include <Library/ArmLib.h>
 #include <Library/BaseLib.h>
 #include <Library/BaseMemoryLib.h>
 #include <Library/UefiBootServicesTableLib.h>
@@ -55,8 +56,9 @@ RngInitAvailableAlgoArray (
   UINT16  MajorRevision;
   UINT16  MinorRevision;
 
-  // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm.
-  if (!EFI_ERROR (RngGetBytes (sizeof (Rand), (UINT8 *)&Rand))) {
+ #ifdef MDE_CPU_AARCH64
+  // Check FEAT_RNG before advertising PcdCpuRngSupportedAlgorithm.
+  if (ArmHasRngExt ()) {
     CopyMem (
       &mAvailableAlgoArray[mAvailableAlgoArrayCount],
       PcdGetPtr (PcdCpuRngSupportedAlgorithm),
@@ -75,6 +77,8 @@ RngInitAvailableAlgoArray (
     DEBUG_CODE_END ();
   }
 
+ #endif
+
   // Raw algorithm (Trng)
   if (!EFI_ERROR (GetTrngVersion (&MajorRevision, &MinorRevision))) {
     CopyMem (
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf 
b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
index d2d0ff9ebb98..599a3085102d 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
@@ -27,7 +27,7 @@ [Defines]
 #
 # The following information is for reference only and not required by the 
build tools.
 #
-#  VALID_ARCHITECTURES           = IA32 X64 AARCH64
+#  VALID_ARCHITECTURES           = IA32 X64 AARCH64 ARM
 #
 
 [Sources.common]
@@ -40,7 +40,7 @@ [Sources.IA32, Sources.X64]
   Rand/AesCore.c
   Rand/AesCore.h
 
-[Sources.AARCH64]
+[Sources.AARCH64, Sources.ARM]
   ArmRngDxe.c
   ArmTrng.c
 
@@ -49,6 +49,9 @@ [Packages]
   MdePkg/MdePkg.dec
   SecurityPkg/SecurityPkg.dec
 
+[Packages.AARCH64, Packages.ARM]
+  ArmPkg/ArmPkg.dec
+
 [LibraryClasses]
   UefiLib
   UefiBootServicesTableLib
@@ -58,7 +61,7 @@ [LibraryClasses]
   TimerLib
   RngLib
 
-[LibraryClasses.AARCH64]
+[LibraryClasses.AARCH64, LibraryClasses.ARM]
   TrngLib
 
 [Guids]
diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc
index 490076542a33..882d639489ea 100644
--- a/SecurityPkg/SecurityPkg.dsc
+++ b/SecurityPkg/SecurityPkg.dsc
@@ -292,7 +292,7 @@ [Components.IA32, Components.X64, Components.ARM, 
Components.AARCH64]
   SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.inf
   
SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf
 
-[Components.IA32, Components.X64, Components.AARCH64]
+[Components.IA32, Components.X64, Components.AARCH64, Components.ARM]
   #
   # Random Number Generator
   #
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#90873): https://edk2.groups.io/g/devel/message/90873
Mute This Topic: https://groups.io/mt/92066759/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to