Revision: 18791
          http://sourceforge.net/p/edk2/code/18791
Author:   vanjeff
Date:     2015-11-16 06:52:09 +0000 (Mon, 16 Nov 2015)
Log Message:
-----------
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.

(Sync patch r18590 from main trunk.)

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Thomas Palmer <[email protected]>
Reviewed-by: Samer El-Haj-Mahmoud <[email protected]>
Reviewed-by: Michael Kinney <[email protected]>
Reviewed-by: Chao Zhang <[email protected]>
Reviewed-by: Qin Long <[email protected]>

Revision Links:
--------------
    http://sourceforge.net/p/edk2/code/18590

Modified Paths:
--------------
    branches/UDK2015/MdePkg/Include/Library/RngLib.h
    branches/UDK2015/MdePkg/Library/BaseRngLib/BaseRng.c

Modified: branches/UDK2015/MdePkg/Include/Library/RngLib.h
===================================================================
--- branches/UDK2015/MdePkg/Include/Library/RngLib.h    2015-11-16 06:51:08 UTC 
(rev 18790)
+++ branches/UDK2015/MdePkg/Include/Library/RngLib.h    2015-11-16 06:52:09 UTC 
(rev 18791)
@@ -66,4 +66,21 @@
   OUT     UINT64                    *Rand
   );
 
+/**
+  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
+  );
+
 #endif  // __RNG_LIB_H__

Modified: branches/UDK2015/MdePkg/Library/BaseRngLib/BaseRng.c
===================================================================
--- branches/UDK2015/MdePkg/Library/BaseRngLib/BaseRng.c        2015-11-16 
06:51:08 UTC (rev 18790)
+++ branches/UDK2015/MdePkg/Library/BaseRngLib/BaseRng.c        2015-11-16 
06:52:09 UTC (rev 18791)
@@ -155,3 +155,35 @@
 
   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);
+}


------------------------------------------------------------------------------
Presto, an open source distributed SQL query engine for big data, initially
developed by Facebook, enables you to easily query your data on Hadoop in a 
more interactive manner. Teradata is also now providing full enterprise
support for Presto. Download a free open source copy now.
http://pubads.g.doubleclick.net/gampad/clk?id=250295911&iu=/4140
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to