]>
git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/RandomNumberGenerator/RngDxe/IA32/RdRandWord.c
2 RDRAND Support Routines.
4 Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Generates a 64-bit random number through RDRAND instruction.
20 @param[out] Rand Buffer pointer to store the random result.
22 @retval TRUE RDRAND call was successful.
23 @retval FALSE Failed attempts to call RDRAND.
36 // Generating a 64-bit rand on a 32-bit system by
37 // mapping two 32-bit RDRAND instructions.
39 if (!RdRand32Step (&RandLow
)) {
42 if (!RdRand32Step (&RandHigh
)) {
46 *Rand
= (UINT64
) RandLow
| LShiftU64 ((UINT64
)RandHigh
, 32);
52 Calls RDRAND to request a word-length random number.
54 @param[out] Rand Buffer pointer to store the random number.
55 @param[in] NeedRetry Determine whether or not to loop retry.
57 @retval EFI_SUCCESS Random word generation succeeded.
58 @retval EFI_NOT_READY Failed to request random word.
68 return RdRand32 (Rand
, NeedRetry
);
72 Calls RDRAND to request multiple word-length random numbers.
74 @param[in] Length Size of the buffer, in words, to fill with.
75 @param[out] RandBuffer Pointer to the buffer to store the random result.
77 @retval EFI_SUCCESS Random words generation succeeded.
78 @retval EFI_NOT_READY Failed to request random words.
91 for (Index
= 0; Index
< Length
; Index
++) {
93 // Obtain one word-length (32-bit) Random Number with possible retry-loop.
95 Status
= RdRand32 (RandBuffer
, TRUE
);
96 if (EFI_ERROR (Status
)) {