]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg: Create GetRandomNumber128 in RngLib
authorThomas Palmer <thomas.palmer@hpe.com>
Fri, 9 Oct 2015 06:03:17 +0000 (06:03 +0000)
committerqlong <qlong@Edk2>
Fri, 9 Oct 2015 06:03:17 +0000 (06:03 +0000)
Declare GetRandomNumber128 in RngLib.h.
Create GetRandomNumber128 in BaseRngLib, which is simply calling
GetRandomNumber64 twice.

A GetRandomNumber128 function allows platforms with 128bit HWRNGs to
save on IO overhead that comes from having to prime the HWRNG device
before each read operation.
Using the HWRNG installed on the HP ProLiant m400 moonshot cartridge,
this will save about 50ms per RAW Entropy operation as compared with
calling GetRandomNumber64 twice.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Thomas Palmer <thomas.palmer@hpe.com>
Reviewed-by: Samer El-Haj-Mahmoud <elhaj@hpe.com>
Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>
Reviewed-by: Chao Zhang <chao.b.zhang@intel.com>
Reviewed-by: Qin Long <qin.long@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18590 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Include/Library/RngLib.h
MdePkg/Library/BaseRngLib/BaseRng.c

index 157a93139c241399e4e504d6c2302ee525217665..ece43941688f8edae9ce2f1268358b0bcc6e3ca8 100644 (file)
@@ -66,4 +66,21 @@ GetRandomNumber64 (
   OUT     UINT64                    *Rand\r
   );\r
 \r
+/**\r
+  Generates a 128-bit random number.\r
+\r
+  if Rand is NULL, then ASSERT().\r
+\r
+  @param[out] Rand     Buffer pointer to store the 128-bit random value.\r
+\r
+  @retval TRUE         Random number generated successfully.\r
+  @retval FALSE        Failed to generate the random number.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+GetRandomNumber128 (\r
+  OUT     UINT64                    *Rand\r
+  );\r
+\r
 #endif  // __RNG_LIB_H__\r
index 279df3013c9f77975b96806b86dc55d48625aa0e..2c8df56286111a3e5fff78353b206790fa7d006f 100644 (file)
@@ -155,3 +155,35 @@ GetRandomNumber64 (
 \r
   return FALSE;\r
 }\r
+\r
+/**\r
+  Generates a 128-bit random number.\r
+\r
+  if Rand is NULL, then ASSERT().\r
+\r
+  @param[out] Rand     Buffer pointer to store the 128-bit random value.\r
+\r
+  @retval TRUE         Random number generated successfully.\r
+  @retval FALSE        Failed to generate the random number.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+GetRandomNumber128 (\r
+  OUT     UINT64                    *Rand\r
+  )\r
+{\r
+  ASSERT (Rand != NULL);\r
+\r
+  //\r
+  // Read first 64 bits\r
+  //\r
+  if (!GetRandomNumber64 (Rand)) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Read second 64 bits\r
+  //\r
+  return GetRandomNumber64 (++Rand);\r
+}\r