Home | History | Annotate | Download | only in BaseLib
      1 /** @file
      2   IA-32/x64 AsmRdRandxx()
      3   Generates random number through CPU RdRand instruction.
      4 
      5   Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
      6   This program and the accompanying materials
      7   are licensed and made available under the terms and conditions of the BSD License
      8   which accompanies this distribution.  The full text of the license may be found at
      9   http://opensource.org/licenses/bsd-license.php.
     10 
     11   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     12   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     13 
     14 **/
     15 
     16 #include "BaseLibInternals.h"
     17 
     18 /**
     19   Generates a 16-bit random number through RDRAND instruction.
     20 
     21   if Rand is NULL, then ASSERT().
     22 
     23   @param[out]  Rand     Buffer pointer to store the random result.
     24 
     25   @retval TRUE          RDRAND call was successful.
     26   @retval FALSE         Failed attempts to call RDRAND.
     27 
     28  **/
     29 BOOLEAN
     30 EFIAPI
     31 AsmRdRand16 (
     32   OUT     UINT16                    *Rand
     33   )
     34 {
     35   ASSERT (Rand != NULL);
     36   return InternalX86RdRand16 (Rand);
     37 }
     38 
     39 /**
     40   Generates a 32-bit random number through RDRAND instruction.
     41 
     42   if Rand is NULL, then ASSERT().
     43 
     44   @param[out]  Rand     Buffer pointer to store the random result.
     45 
     46   @retval TRUE          RDRAND call was successful.
     47   @retval FALSE         Failed attempts to call RDRAND.
     48 
     49 **/
     50 BOOLEAN
     51 EFIAPI
     52 AsmRdRand32 (
     53   OUT     UINT32                    *Rand
     54   )
     55 {
     56   ASSERT (Rand != NULL);
     57   return InternalX86RdRand32 (Rand);
     58 }
     59 
     60 /**
     61   Generates a 64-bit random number through RDRAND instruction.
     62 
     63   if Rand is NULL, then ASSERT().
     64 
     65   @param[out]  Rand     Buffer pointer to store the random result.
     66 
     67   @retval TRUE          RDRAND call was successful.
     68   @retval FALSE         Failed attempts to call RDRAND.
     69 
     70 **/
     71 BOOLEAN
     72 EFIAPI
     73 AsmRdRand64  (
     74   OUT     UINT64                    *Rand
     75   )
     76 {
     77   ASSERT (Rand != NULL);
     78   return InternalX86RdRand64 (Rand);
     79 }
     80