SecurityPkg: 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. Simplify RngDxe by using WriteUnaligned64 for all platforms. Use GetRandomNumber128 in RngDxe to leverage 128 bit support provided by some HW RNG devices. 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@18591 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@@ -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
|
||||
@@ -28,154 +29,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#include <Library/TimerLib.h>
|
||||
#include <Protocol/Rng.h>
|
||||
|
||||
//
|
||||
// The maximun number of retries to obtain one available random number.
|
||||
//
|
||||
#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.
|
||||
@param[in] NeedRetry Determine whether or not to loop retry.
|
||||
|
||||
@retval EFI_SUCCESS Random word generation succeeded.
|
||||
@retval EFI_NOT_READY Failed to request random word.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
RdRandWord (
|
||||
OUT UINTN *Rand,
|
||||
IN BOOLEAN NeedRetry
|
||||
);
|
||||
|
||||
/**
|
||||
Calls RDRAND to request multiple word-length random numbers.
|
||||
|
||||
@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 Random words generation succeeded.
|
||||
@retval EFI_NOT_READY Failed to request random words.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
RdRandGetWords (
|
||||
IN UINTN Length,
|
||||
OUT UINTN *RandBuffer
|
||||
);
|
||||
|
||||
/**
|
||||
Calls RDRAND to fill a buffer of arbitrary size with random bytes.
|
||||
|
||||
@@ -210,4 +63,4 @@ RdRandGenerateEntropy (
|
||||
OUT UINT8 *Entropy
|
||||
);
|
||||
|
||||
#endif // __RD_RAND_H__
|
||||
#endif // __RD_RAND_H__
|
||||
|
Reference in New Issue
Block a user