]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/RandomNumberGenerator/RngDxe/X64/RdRandWord.c
Add UEFI RNG Protocol support. The driver will leverage Intel Secure Key technology...
[mirror_edk2.git] / SecurityPkg / RandomNumberGenerator / RngDxe / X64 / RdRandWord.c
1 /** @file
2 RDRAND Support Routines.
3
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
9
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.
12
13 **/
14
15 #include "RdRand.h"
16
17 /**
18 Calls RDRAND to request a word-length random number.
19
20 @param[out] Rand Buffer pointer to store the random number.
21 @param[in] NeedRetry Determine whether or not to loop retry.
22
23 @retval EFI_SUCCESS Random word generation succeeded.
24 @retval EFI_NOT_READY Failed to request random word.
25
26 **/
27 EFI_STATUS
28 EFIAPI
29 RdRandWord (
30 OUT UINTN *Rand,
31 IN BOOLEAN NeedRetry
32 )
33 {
34 return RdRand64 (Rand, NeedRetry);
35 }
36
37 /**
38 Calls RDRAND to request multiple word-length random numbers.
39
40 @param[in] Length Size of the buffer, in words, to fill with.
41 @param[out] RandBuffer Pointer to the buffer to store the random result.
42
43 @retval EFI_SUCCESS Random words generation succeeded.
44 @retval EFI_NOT_READY Failed to request random words.
45
46 **/
47 EFI_STATUS
48 EFIAPI
49 RdRandGetWords (
50 IN UINTN Length,
51 OUT UINTN *RandBuffer
52 )
53 {
54 EFI_STATUS Status;
55 UINT32 Index;
56
57 for (Index = 0; Index < Length; Index++) {
58 //
59 // Obtain one word-length (64-bit) Random Number with possible retry-loop.
60 //
61 Status = RdRand64 (RandBuffer, TRUE);
62 if (EFI_ERROR (Status)) {
63 return Status;
64 }
65
66 RandBuffer++;
67 }
68
69 return EFI_SUCCESS;
70 }