Thomas,

I think it would make this module simpler if you just use the 64-bit variant.

Mike

-----Original Message-----
From: Palmer, Thomas [mailto:thomas.pal...@hpe.com] 
Sent: Tuesday, October 06, 2015 11:00 AM
To: Kinney, Michael D; edk2-devel@lists.01.org
Subject: RE: [edk2] [PATCH] Pkg-Module: Integrate new RngLib into RngDxe

Mike,

        Thanks for your response.  I was trying to preserve the previous code 
as much as possible, so I did not rename the Word functions.

        Are you suggesting that I can remove the "Word" functions entirely and 
just use the 64 variants?  If so, I'll refactor my patch accordingly.

Thomas

-----Original Message-----
From: Kinney, Michael D [mailto:michael.d.kin...@intel.com] 
Sent: Tuesday, October 6, 2015 12:56 PM
To: Palmer, Thomas <thomas.pal...@hpe.com>; edk2-devel@lists.01.org; Kinney, 
Michael D <michael.d.kin...@intel.com>
Subject: RE: [edk2] [PATCH] Pkg-Module: Integrate new RngLib into RngDxe

Thomas,

In other EDK II functions, we use the name "Uintn" instead of "Word" for a 
function that returns a value that is the natural size of the executing CPU.

Also, I do not think you need the internal work function to generate a natural 
sized random number.

Both IA32 and X64 versions the BaseLib support the AsmRdRand64() function.  
Your implementation can always do work 64-bits at a time using just 
AsmRdRand64().

Mike


-----Original Message-----
From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Thomas 
Palmer
Sent: Tuesday, October 06, 2015 9:38 AM
To: edk2-devel@lists.01.org
Subject: [edk2] [PATCH] Pkg-Module: Integrate new RngLib into RngDxe

Use the new RngLib to provide the IA32/X64 random data for RngDxe.
Remove x86 specific functions from RdRand files.
Clean up files in RngDxe/IA32 and RngDxe/X64 that are subsumed by files in 
BaseRngLib.
A key piece to this change was creating a RdRandWord and RdRandGetWords 
functions that could work for both IA32 and X64 builds.  The RngLib provides 
functions to get 16,32, and 64 bit random values, but RngDxe uses RdRandWord to 
get a UINTN value.   I use sizeof (UINTN) to determine when to use 
GetRandomNumber32 or GetRandomNumber64

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Thomas Palmer <thomas.pal...@hpe.com>
---
 .../RngDxe/IA32/AsmRdRand.asm                      |   67 --------
 .../RandomNumberGenerator/RngDxe/IA32/GccRdRand.c  |   69 --------
 SecurityPkg/RandomNumberGenerator/RngDxe/RdRand.c  |  173 +++++--------------- 
 SecurityPkg/RandomNumberGenerator/RngDxe/RdRand.h  |  115 +------------
 SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c  |    9 +-
 .../RandomNumberGenerator/RngDxe/RngDxe.inf        |   14 +-
 .../RandomNumberGenerator/RngDxe/X64/AsmRdRand.asm |   83 ----------
 .../RandomNumberGenerator/RngDxe/X64/GccRdRand.c   |   95 -----------
 SecurityPkg/SecurityPkg.dsc                        |    3 +
 9 files changed, 47 insertions(+), 581 deletions(-)  delete mode 100644 
SecurityPkg/RandomNumberGenerator/RngDxe/IA32/AsmRdRand.asm
 delete mode 100644 SecurityPkg/RandomNumberGenerator/RngDxe/IA32/GccRdRand.c
 delete mode 100644 SecurityPkg/RandomNumberGenerator/RngDxe/X64/AsmRdRand.asm
 delete mode 100644 SecurityPkg/RandomNumberGenerator/RngDxe/X64/GccRdRand.c

diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/IA32/AsmRdRand.asm 
b/SecurityPkg/RandomNumberGenerator/RngDxe/IA32/AsmRdRand.asm
deleted file mode 100644
index 37b3830..0000000
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/IA32/AsmRdRand.asm
+++ /dev/null
@@ -1,67 +0,0 @@
-;------------------------------------------------------------------------------
-;
-; Copyright (c) 2013, Intel Corporation. All rights reserved.<BR> -; This 
program and the accompanying materials -; are licensed and made available under 
the terms and conditions of the BSD License -; which accompanies this 
distribution.  The full text of the license may be found at -; 
http://opensource.org/licenses/bsd-license.php.
-;
-; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -; 
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;
-; Module Name:
-;
-;   AsmRdRand.Asm
-;
-; Abstract:
-;
-;   Implementation for 16-, and 32- invocations of RDRAND instruction under 
32bit platform.
-;
-; Notes:
-;
-;   Visual Studio coding practices do not use inline asm since multiple 
compilers and 
-;   architectures are supported assembler not recognizing rdrand instruction 
so using DB's.
-;
-;------------------------------------------------------------------------------
-
-    .586P
-    .model flat, C
-    .code
-
-;------------------------------------------------------------------------------
-;  Generate a 16 bit random number
-;  Return TRUE if Rand generated successfully, or FALSE if not -;
-;  BOOLEAN EFIAPI RdRand16Step (UINT16 *Rand);   ECX
-;------------------------------------------------------------------------------
-RdRand16Step  PROC
-    ; rdrand   ax                  ; generate a 16 bit RN into ax, CF=1 if RN 
generated ok, otherwise CF=0
-    db     0fh, 0c7h, 0f0h         ; rdrand r16:  "0f c7 /6  ModRM:r/m(w)"
-    jb     rn16_ok                 ; jmp if CF=1
-    xor    eax, eax                ; reg=0 if CF=0
-    ret                            ; return with failure status
-rn16_ok:
-    mov    [ecx], ax
-    mov    eax, 1
-    ret
-RdRand16Step ENDP
-
-;------------------------------------------------------------------------------
-;  Generate a 32 bit random number
-;    Return TRUE if Rand generated successfully, or FALSE if not
-;
-;  BOOLEAN EFIAPI RdRand32Step (UINT32 *Rand);   ECX
-;------------------------------------------------------------------------------
-RdRand32Step  PROC
-    ; rdrand   eax                 ; generate a 32 bit RN into eax, CF=1 if RN 
generated ok, otherwise CF=0
-    db     0fh, 0c7h, 0f0h         ; rdrand r32:  "0f c7 /6  ModRM:r/m(w)"
-    jb     rn32_ok                 ; jmp if CF=1
-    xor    eax, eax                ; reg=0 if CF=0
-    ret                            ; return with failure status
-rn32_ok:
-    mov    [ecx], eax
-    mov    eax,  1
-    ret
-RdRand32Step  ENDP
-
-    END
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/IA32/GccRdRand.c 
b/SecurityPkg/RandomNumberGenerator/RngDxe/IA32/GccRdRand.c
deleted file mode 100644
index f42302a..0000000
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/IA32/GccRdRand.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/** @file
-  RDRAND Support Routines for GCC environment.
-
-Copyright (c) 2013, Intel Corporation. All rights reserved.<BR> -This program 
and the accompanying materials -are licensed and made available under the terms 
and conditions of the BSD License -which accompanies this distribution.  The 
full text of the license may be found at 
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT 
WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-/**
-  Generates a 16-bit random number through RDRAND instruction.
-
-  @param[out]  Rand          Buffer pointer to store the random result.
-
-  @retval TRUE               RDRAND call was successful.
-  @retval FALSE              Failed attempts to call RDRAND.
-
-**/
-BOOLEAN
-EFIAPI
-RdRand16Step (
-  OUT UINT16       *Rand
-  )
-{
-  UINT8  Carry;
-
-  //
-  // Uses byte code for RDRAND instruction,
-  // in case that GCC version has no direct support on RDRAND assembly.
-  //
-  __asm__ __volatile__ (
-    ".byte 0x66; .byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1"
-    :"=a"  (*Rand), 
-     "=qm" (Carry)
-    ); 
-
-  return (BOOLEAN) Carry;
-}
-
-/**
-  Generates a 32-bit random number through RDRAND instruction.
-
-  @param[out]  Rand          Buffer pointer to store the random result.
-
-  @retval TRUE               RDRAND call was successful.
-  @retval FALSE              Failed attempts to call RDRAND.
-
-**/
-BOOLEAN
-EFIAPI
-RdRand32Step (
-  OUT UINT32       *Rand
-  )
-{
-  UINT8  Carry;
-
-  __asm__ __volatile__ (
-    ".byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1"
-    :"=a"  (*Rand), 
-     "=qm" (Carry)
-    );
-
-  return (BOOLEAN) Carry;
-}
\ No newline at end of file
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RdRand.c 
b/SecurityPkg/RandomNumberGenerator/RngDxe/RdRand.c
index 7e618dc..2a21f7f 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/RdRand.c
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RdRand.c
@@ -2,6 +2,7 @@
   Support routines for RDRAND instruction access.
 
 Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
 This program and the accompanying materials  are licensed and made available 
under the terms and conditions of the BSD License  which accompanies this 
distribution.  The full text of the license may be found at @@ -11,175 +12,75 
@@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,  
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
 **/
+#include <Library/RngLib.h>
 
 #include "RdRand.h"
 #include "AesCore.h"
 
-//
-// Bit mask used to determine if RdRand instruction is supported.
-//
-#define RDRAND_MASK    0x40000000
-
-/**
-  Determines whether or not RDRAND instruction is supported by the host 
hardware.
-
-  @retval EFI_SUCCESS          RDRAND instruction supported.
-  @retval EFI_UNSUPPORTED      RDRAND instruction not supported.
-
-**/
-EFI_STATUS
-EFIAPI
-IsRdRandSupported (
-  VOID
-  )
-{
-  EFI_STATUS  Status;
-  UINT32      RegEax;
-  UINT32      RegEbx;
-  UINT32      RegEcx;
-  UINT32      RegEdx;
-  BOOLEAN     IsIntelCpu;
-
-  Status     = EFI_UNSUPPORTED;
-  IsIntelCpu = FALSE;
-
-  //
-  // Checks whether the current processor is an Intel product by CPUID.
-  //
-  AsmCpuid (0, &RegEax, &RegEbx, &RegEcx, &RegEdx);
-  if ((CompareMem ((CHAR8 *)(&RegEbx), "Genu", 4) == 0) &&
-      (CompareMem ((CHAR8 *)(&RegEdx), "ineI", 4) == 0) &&
-      (CompareMem ((CHAR8 *)(&RegEcx), "ntel", 4) == 0)) {
-    IsIntelCpu = TRUE;
-  }
-
-  if (IsIntelCpu) {
-    //
-    // Determine RDRAND support by examining bit 30 of the ECX register 
returned by CPUID.
-    // A value of 1 indicates that processor supports RDRAND instruction.
-    //
-    AsmCpuid (1, 0, 0, &RegEcx, 0);
-
-    if ((RegEcx & RDRAND_MASK) == RDRAND_MASK) {
-      Status = EFI_SUCCESS;
-    }
-  }
-
-  return Status;
-}
-
 /**
-  Calls RDRAND to obtain a 16-bit random number.
+  Calls RDRAND to request a word-length random number.
 
-  @param[out]  Rand          Buffer pointer to store the random result.
+  @param[out]  Rand          Buffer pointer to store the random number.
   @param[in]   NeedRetry     Determine whether or not to loop retry.
 
-  @retval EFI_SUCCESS        RDRAND call was successful.
-  @retval EFI_NOT_READY      Failed attempts to call RDRAND.
+  @retval EFI_SUCCESS        Random word generation succeeded.
+  @retval EFI_NOT_READY      Failed to request random word.
 
 **/
 EFI_STATUS
 EFIAPI
-RdRand16 (
-  OUT UINT16       *Rand,
-  IN BOOLEAN       NeedRetry
+RdRandWord (
+  OUT UINTN        *Rand
   )
 {
-  UINT32      Index;
-  UINT32      RetryCount;
+  BOOLEAN          IsRandom;
 
-  if (NeedRetry) {
-    RetryCount = RETRY_LIMIT;
+  if (sizeof (UINTN) == sizeof (UINT64)) {
+    IsRandom = GetRandomNumber64 ((UINT64*)Rand);
   } else {
-    RetryCount = 1;
+    IsRandom = GetRandomNumber32 ((UINT32*)Rand);
   }
 
-  //
-  // Perform a single call to RDRAND, or enter a loop call until RDRAND 
succeeds.
-  //
-  for (Index = 0; Index < RetryCount; Index++) {
-    if (RdRand16Step (Rand)) {
-      return EFI_SUCCESS;
-    }
+  if (EFI_ERROR (IsRandom)) {
+    return EFI_NOT_READY;
   }
-  
-  return EFI_NOT_READY;
-}
-
-/**
-  Calls RDRAND to obtain a 32-bit random number.
-
-  @param[out]  Rand          Buffer pointer to store the random result.
-  @param[in]   NeedRetry     Determine whether or not to loop retry.
 
-  @retval EFI_SUCCESS        RDRAND call was successful.
-  @retval EFI_NOT_READY      Failed attempts to call RDRAND.
-
-**/
-EFI_STATUS
-EFIAPI
-RdRand32 (
-  OUT UINT32       *Rand,
-  IN BOOLEAN       NeedRetry
-  )
-{
-  UINT32      Index;
-  UINT32      RetryCount;
-
-  if (NeedRetry) {
-    RetryCount = RETRY_LIMIT;
-  } else {
-    RetryCount = 1;
-  }
-
-  //
-  // Perform a single call to RDRAND, or enter a loop call until RDRAND 
succeeds.
-  //
-  for (Index = 0; Index < RetryCount; Index++) {
-    if (RdRand32Step (Rand)) {
-      return EFI_SUCCESS;
-    }
-  }
-  
-  return EFI_NOT_READY;
+  return EFI_SUCCESS;
 }
 
 /**
-  Calls RDRAND to obtain a 64-bit random number.
+  Calls RDRAND to request multiple word-length random numbers.
 
-  @param[out]  Rand          Buffer pointer to store the random result.
-  @param[in]   NeedRetry     Determine whether or not to loop retry.
+  @param[in]   Length        Size of the buffer, in words, to fill with.
+  @param[out]  RandBuffer    Pointer to the buffer to store the random result.
 
-  @retval EFI_SUCCESS        RDRAND call was successful.
-  @retval EFI_NOT_READY      Failed attempts to call RDRAND.
+  @retval EFI_SUCCESS        Random words generation succeeded.
+  @retval EFI_NOT_READY      Failed to request random words.
 
 **/
 EFI_STATUS
 EFIAPI
-RdRand64 (
-  OUT UINT64       *Rand,
-  IN BOOLEAN       NeedRetry
+RdRandGetWords (
+  IN UINTN         Length,
+  OUT UINTN        *RandBuffer
   )
 {
+  EFI_STATUS  Status;
   UINT32      Index;
-  UINT32      RetryCount;
 
-  if (NeedRetry) {
-    RetryCount = RETRY_LIMIT;
-  } else {
-    RetryCount = 1;
-  }
-
-  //
-  // Perform a single call to RDRAND, or enter a loop call until RDRAND 
succeeds.
-  //
-  for (Index = 0; Index < RetryCount; Index++) {
-    if (RdRand64Step (Rand)) {
-      return EFI_SUCCESS;
+  for (Index = 0; Index < Length; Index++) {
+    //
+    // Obtain one word-length Random Number with possible retry-loop.
+    //
+    Status = RdRandWord (RandBuffer);
+    if (EFI_ERROR (Status)) {
+      return Status;
     }
+    
+    RandBuffer++;
   }
-  
-  return EFI_NOT_READY;
+
+  return EFI_SUCCESS;
 }
 
 /**
@@ -241,7 +142,7 @@ RdRandGetBytes (
   // Obtain a temporary random number for use in the residuals. Failout if 
retry fails.
   //
   if (StartLen > 0) {
-    Status = RdRandWord ((UINTN *) &TempRand, TRUE);
+    Status = RdRandWord (&TempRand);
     if (EFI_ERROR (Status)) {
       return Status;
     }
@@ -266,7 +167,7 @@ RdRandGetBytes (
   // Populate the final mis-aligned block.
   //
   if (Residual > 0) {
-    Status = RdRandWord ((UINTN *)&TempRand, TRUE);
+    Status = RdRandWord (&TempRand);
     if (EFI_ERROR (Status)) {
       return Status;
     }
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RdRand.h 
b/SecurityPkg/RandomNumberGenerator/RngDxe/RdRand.h
index 20fd9fb..b9be79a 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/RdRand.h
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RdRand.h
@@ -9,6 +9,7 @@
   Secure Key technology.
 
 Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -34,115 +35,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 #define RETRY_LIMIT    10
 
 /**
-  Determines whether or not RDRAND instruction is supported by the host 
hardware.
-
-  @retval EFI_SUCCESS          RDRAND instruction supported.
-  @retval EFI_UNSUPPORTED      RDRAND instruction not supported.
-
-**/
-EFI_STATUS
-EFIAPI
-IsRdRandSupported (
-  VOID
-  );
-
-/**
-  Generates a 16-bit random number through RDRAND instruction.
-
-  @param[out]  Rand          Buffer pointer to store the random result.
-
-  @retval TRUE               RDRAND call was successful.
-  @retval FALSE              Failed attempts to call RDRAND.
-
-**/
-BOOLEAN
-EFIAPI
-RdRand16Step (
-  OUT UINT16       *Rand
-  );
-
-/**
-  Generates a 32-bit random number through RDRAND instruction.
-
-  @param[out]  Rand          Buffer pointer to store the random result.
-
-  @retval TRUE               RDRAND call was successful.
-  @retval FALSE              Failed attempts to call RDRAND.
-
-**/
-BOOLEAN
-EFIAPI
-RdRand32Step (
-  OUT UINT32       *Rand
-  );
-
-/**
-  Generates a 64-bit random number through RDRAND instruction.
-
-  @param[out]  Rand          Buffer pointer to store the random result.
-
-  @retval TRUE               RDRAND call was successful.
-  @retval FALSE              Failed attempts to call RDRAND.
-
-**/
-BOOLEAN
-EFIAPI
-RdRand64Step  (
-  OUT UINT64   *Rand
-  );
-
-/**
-  Calls RDRAND to obtain a 16-bit random number.
-
-  @param[out]  Rand          Buffer pointer to store the random result.
-  @param[in]   NeedRetry     Determine whether or not to loop retry.
-
-  @retval EFI_SUCCESS        RDRAND call was successful.
-  @retval EFI_NOT_READY      Failed attempts to call RDRAND.
-
-**/
-EFI_STATUS
-EFIAPI
-RdRand16 (
-  OUT UINT16       *Rand,
-  IN BOOLEAN       NeedRetry
-  );
-
-/**
-  Calls RDRAND to obtain a 32-bit random number.
-
-  @param[out]  Rand          Buffer pointer to store the random result.
-  @param[in]   NeedRetry     Determine whether or not to loop retry.
-
-  @retval EFI_SUCCESS        RDRAND call was successful.
-  @retval EFI_NOT_READY      Failed attempts to call RDRAND.
-
-**/
-EFI_STATUS
-EFIAPI
-RdRand32 (
-  OUT UINT32       *Rand,
-  IN BOOLEAN       NeedRetry
-  );
-
-/**
-  Calls RDRAND to obtain a 64-bit random number.
-
-  @param[out]  Rand          Buffer pointer to store the random result.
-  @param[in]   NeedRetry     Determine whether or not to loop retry.
-
-  @retval EFI_SUCCESS        RDRAND call was successful.
-  @retval EFI_NOT_READY      Failed attempts to call RDRAND.
-
-**/
-EFI_STATUS
-EFIAPI
-RdRand64 (
-  OUT UINT64       *Rand,
-  IN BOOLEAN       NeedRetry
-  );
-  
-/**
   Calls RDRAND to request a word-length random number.
 
   @param[out]  Rand          Buffer pointer to store the random number.
@@ -155,8 +47,7 @@ RdRand64 (
 EFI_STATUS
 EFIAPI
 RdRandWord (
-  OUT UINTN        *Rand,
-  IN BOOLEAN       NeedRetry
+  OUT UINTN        *Rand
   );
 
 /**
@@ -210,4 +101,4 @@ RdRandGenerateEntropy (
   OUT UINT8        *Entropy
   );
 
-#endif  // __RD_RAND_H__
\ No newline at end of file
+#endif  // __RD_RAND_H__
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c 
b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c
index 98ef3b3..5c04673 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c
@@ -15,6 +15,7 @@
    - EFI_RNG_ALGORITHM_X9_31_AES_GUID         - Unsupported
 
 Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
 This program and the accompanying materials 
 are licensed and made available under the terms and conditions of the BSD 
License 
 which accompanies this distribution.  The full text of the license may be 
found at 
@@ -197,14 +198,6 @@ RngDriverEntry (
   EFI_HANDLE    Handle;
 
   //
-  // Verify RdRand support on Platform.
-  //
-  Status = IsRdRandSupported ();
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  //
   // Install UEFI RNG (Random Number Generator) Protocol
   //
   Handle = NULL;
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf 
b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
index d57c2d8..4d668a1 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
@@ -9,6 +9,7 @@
 #  Secure Key technology.
 #
 #  Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>
+#  (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD 
License
 #  which accompanies this distribution. The full text of the license may be 
found at
@@ -41,16 +42,6 @@
   AesCore.c
   AesCore.h
 
-[Sources.IA32]
-  IA32/RdRandWord.c
-  IA32/AsmRdRand.asm
-  IA32/GccRdRand.c          | GCC
-
-[Sources.X64]
-  X64/RdRandWord.c
-  X64/AsmRdRand.asm
-  X64/GccRdRand.c           | GCC
-
 [Packages]
   MdePkg/MdePkg.dec
   SecurityPkg/SecurityPkg.dec
@@ -62,6 +53,7 @@
   DebugLib     
   UefiDriverEntryPoint
   TimerLib
+  RngLib
 
 [Guids]
   gEfiRngAlgorithmSp80090Ctr256Guid   ## SOMETIMES_PRODUCES    ## GUID        
# Unique ID of the algorithm for RNG
@@ -77,4 +69,4 @@
   XCODE:*_*_*_CC_FLAGS = -mmmx -msse
 
 [UserExtensions.TianoCore."ExtraFiles"]
-  RngDxeExtra.uni
\ No newline at end of file
+  RngDxeExtra.uni
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/X64/AsmRdRand.asm 
b/SecurityPkg/RandomNumberGenerator/RngDxe/X64/AsmRdRand.asm
deleted file mode 100644
index 8a4fe65..0000000
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/X64/AsmRdRand.asm
+++ /dev/null
@@ -1,83 +0,0 @@
-;------------------------------------------------------------------------------
-;
-; Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
-; This program and the accompanying materials
-; are licensed and made available under the terms and conditions of the BSD 
License
-; which accompanies this distribution.  The full text of the license may be 
found at
-; http://opensource.org/licenses/bsd-license.php.
-;
-; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;
-; Module Name:
-;
-;   AsmRdRand.Asm
-;
-; Abstract:
-;
-;   Implementation for 16-, 32-, and 64-bit invocations of RDRAND instruction 
under 64bit platform.
-;
-; Notes:
-;
-;   Visual Studio coding practices do not use inline asm since multiple 
compilers and 
-;   architectures are supported assembler not recognizing rdrand instruction 
so using DB's.
-;
-;------------------------------------------------------------------------------
-
-    .code
- 
-;------------------------------------------------------------------------------
-;  Generate a 16 bit random number
-;  Return TRUE if Rand generated successfully, or FALSE if not
-;
-;  BOOLEAN EFIAPI RdRand16Step (UINT16 *Rand);   RCX
-;------------------------------------------------------------------------------
-RdRand16Step  PROC
-    ; rdrand   ax                  ; generate a 16 bit RN into ax, CF=1 if RN 
generated ok, otherwise CF=0
-    db     0fh, 0c7h, 0f0h         ; rdrand r16:  "0f c7 /6  ModRM:r/m(w)"
-    jb     rn16_ok                 ; jmp if CF=1
-    xor    rax, rax                ; reg=0 if CF=0
-    ret                            ; return with failure status
-rn16_ok:
-    mov    [rcx], ax
-    mov    rax, 1
-    ret
-RdRand16Step ENDP
-
-;------------------------------------------------------------------------------
-;  Generate a 32 bit random number
-;    Return TRUE if Rand generated successfully, or FALSE if not
-;
-;  BOOLEAN EFIAPI RdRand32Step (UINT32 *Rand);   RCX
-;------------------------------------------------------------------------------
-RdRand32Step  PROC
-    ; rdrand   eax                 ; generate a 32 bit RN into eax, CF=1 if RN 
generated ok, otherwise CF=0
-    db     0fh, 0c7h, 0f0h         ; rdrand r32:  "0f c7 /6  ModRM:r/m(w)"
-    jb     rn32_ok                 ; jmp if CF=1
-    xor    rax, rax                ; reg=0 if CF=0
-    ret                            ; return with failure status
-rn32_ok:
-    mov    [rcx], eax
-    mov    rax,  1
-    ret
-RdRand32Step ENDP
-
-;------------------------------------------------------------------------------
-;  Generate a 64 bit random number
-;    Return TRUE if RN generated successfully, or FALSE if not
-;
-;  BOOLEAN EFIAPI RdRand64Step (UINT64 *Random);   RCX
-;------------------------------------------------------------------------------
-RdRand64Step  PROC
-    ; rdrand   rax                 ; generate a 64 bit RN into rax, CF=1 if RN 
generated ok, otherwise CF=0
-    db     048h, 0fh, 0c7h, 0f0h   ; rdrand r64: "REX.W + 0F C7 /6 
ModRM:r/m(w)" 
-    jb     rn64_ok                 ; jmp if CF=1
-    xor    rax, rax                ; reg=0 if CF=0
-    ret                            ; return with failure status
-rn64_ok:
-    mov    [rcx], rax
-    mov    rax, 1
-    ret
-RdRand64Step ENDP
-
-    END
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/X64/GccRdRand.c 
b/SecurityPkg/RandomNumberGenerator/RngDxe/X64/GccRdRand.c
deleted file mode 100644
index d28336d..0000000
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/X64/GccRdRand.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/** @file
-  RDRAND Support Routines for GCC environment.
-
-Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
-This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD 
License
-which accompanies this distribution.  The full text of the license may be 
found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-/**
-  Generates a 16-bit random number through RDRAND instruction.
-
-  @param[out]  Rand          Buffer pointer to store the random result.
-
-  @retval TRUE               RDRAND call was successful.
-  @retval FALSE              Failed attempts to call RDRAND.
-
-**/
-BOOLEAN
-EFIAPI
-RdRand16Step (
-  OUT UINT16       *Rand
-  )
-{
-  UINT8  Carry;
-
-  //
-  // Uses byte code for RDRAND instruction,
-  // in case that GCC version has no direct support on RDRAND assembly.
-  //
-  __asm__ __volatile__ (
-    ".byte 0x66; .byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1"
-    :"=a"  (*Rand),
-     "=qm" (Carry)
-    ); 
-
-  return (BOOLEAN) Carry;
-}
-
-/**
-  Generates a 32-bit random number through RDRAND instruction.
-
-  @param[out]  Rand          Buffer pointer to store the random result.
-
-  @retval TRUE               RDRAND call was successful.
-  @retval FALSE              Failed attempts to call RDRAND.
-
-**/
-BOOLEAN
-EFIAPI
-RdRand32Step (
-  OUT UINT32       *Rand
-  )
-{
-  UINT8  Carry;
-
-  __asm__ __volatile__ (
-    ".byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1"
-    :"=a"  (*Rand), 
-     "=qm" (Carry)
-    );
-
-  return (BOOLEAN) Carry;
-}
-
-/**
-  Generates a 64-bit random number through RDRAND instruction.
-
-  @param[out]  Rand          Buffer pointer to store the random result.
-
-  @retval TRUE               RDRAND call was successful.
-  @retval FALSE              Failed attempts to call RDRAND.
-
-**/
-BOOLEAN
-EFIAPI
-RdRand64Step  (
-  OUT UINT64   *Rand
-  )
-{
-  UINT8  Carry;
-
-  __asm__ __volatile__ (
-    ".byte 0x48; .byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1"
-    :"=a"  (*Rand), 
-     "=qm" (Carry)
-    );
-  
-  return (BOOLEAN) Carry;
-}
diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc
index 6e2ca5c..0908b26 100644
--- a/SecurityPkg/SecurityPkg.dsc
+++ b/SecurityPkg/SecurityPkg.dsc
@@ -2,6 +2,7 @@
 #  Security Module Package for All Architectures.
 #
 # Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
+# (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
 # This program and the accompanying materials
 # are licensed and made available under the terms and conditions of the BSD 
License
 # which accompanies this distribution. The full text of the license may be 
found at
@@ -61,6 +62,7 @@
   TcgPpVendorLib|SecurityPkg/Library/TcgPpVendorLibNull/TcgPpVendorLibNull.inf
   
Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
   
TrEEPpVendorLib|SecurityPkg/Library/TrEEPpVendorLibNull/TrEEPpVendorLibNull.inf
+  RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf
 
 [LibraryClasses.common.PEIM]
   PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf
@@ -74,6 +76,7 @@
   Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12DeviceLibDTpm.inf
   Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
   
Tcg2PhysicalPresenceLib|SecurityPkg/Library/PeiTcg2PhysicalPresenceLib/PeiTcg2PhysicalPresenceLib.inf
+  RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf
 
 [LibraryClasses.common.DXE_DRIVER]
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
-- 
1.7.9.5

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to