summaryrefslogtreecommitdiffstats
path: root/MdePkg/Library/BaseRngLib
diff options
context:
space:
mode:
authorThomas Palmer <thomas.palmer@hpe.com>2015-10-09 06:03:17 +0000
committerqlong <qlong@Edk2>2015-10-09 06:03:17 +0000
commitc8b6f16d7d3b0c225cf34bd1c750373c9b251284 (patch)
treedca4e2fffb1c982a764452e4988cfeea6b5becc9 /MdePkg/Library/BaseRngLib
parent64df44b7e5d005598828c990500c2427bb131e8f (diff)
downloadedk2-c8b6f16d7d3b0c225cf34bd1c750373c9b251284.tar.gz
edk2-c8b6f16d7d3b0c225cf34bd1c750373c9b251284.tar.bz2
edk2-c8b6f16d7d3b0c225cf34bd1c750373c9b251284.zip
MdePkg: Create GetRandomNumber128 in RngLib
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
Diffstat (limited to 'MdePkg/Library/BaseRngLib')
-rw-r--r--MdePkg/Library/BaseRngLib/BaseRng.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/MdePkg/Library/BaseRngLib/BaseRng.c b/MdePkg/Library/BaseRngLib/BaseRng.c
index 279df3013c..2c8df56286 100644
--- a/MdePkg/Library/BaseRngLib/BaseRng.c
+++ b/MdePkg/Library/BaseRngLib/BaseRng.c
@@ -155,3 +155,35 @@ GetRandomNumber64 (
return FALSE;
}
+
+/**
+ Generates a 128-bit random number.
+
+ if Rand is NULL, then ASSERT().
+
+ @param[out] Rand Buffer pointer to store the 128-bit random value.
+
+ @retval TRUE Random number generated successfully.
+ @retval FALSE Failed to generate the random number.
+
+**/
+BOOLEAN
+EFIAPI
+GetRandomNumber128 (
+ OUT UINT64 *Rand
+ )
+{
+ ASSERT (Rand != NULL);
+
+ //
+ // Read first 64 bits
+ //
+ if (!GetRandomNumber64 (Rand)) {
+ return FALSE;
+ }
+
+ //
+ // Read second 64 bits
+ //
+ return GetRandomNumber64 (++Rand);
+}