]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/RandomNumberGenerator/RngDxe/X64/RdRandWord.c
SecurityPkg: Integrate new RngLib into RngDxe
[mirror_edk2.git] / SecurityPkg / RandomNumberGenerator / RngDxe / X64 / RdRandWord.c
CommitLineData
3aa8dc6c
LQ
1/** @file\r
2 RDRAND Support Routines.\r
3\r
4Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "RdRand.h"\r
16\r
17/**\r
18 Calls RDRAND to request a word-length random number.\r
19\r
20 @param[out] Rand Buffer pointer to store the random number.\r
21 @param[in] NeedRetry Determine whether or not to loop retry.\r
22\r
23 @retval EFI_SUCCESS Random word generation succeeded.\r
24 @retval EFI_NOT_READY Failed to request random word.\r
25\r
26**/\r
27EFI_STATUS\r
28EFIAPI\r
29RdRandWord (\r
30 OUT UINTN *Rand,\r
31 IN BOOLEAN NeedRetry\r
32 )\r
33{\r
34 return RdRand64 (Rand, NeedRetry);\r
35}\r
36\r
37/**\r
38 Calls RDRAND to request multiple word-length random numbers.\r
39\r
40 @param[in] Length Size of the buffer, in words, to fill with.\r
41 @param[out] RandBuffer Pointer to the buffer to store the random result.\r
42\r
43 @retval EFI_SUCCESS Random words generation succeeded.\r
44 @retval EFI_NOT_READY Failed to request random words.\r
45\r
46**/\r
47EFI_STATUS\r
48EFIAPI\r
49RdRandGetWords (\r
50 IN UINTN Length,\r
51 OUT UINTN *RandBuffer\r
52 )\r
53{\r
54 EFI_STATUS Status;\r
55 UINT32 Index;\r
56\r
57 for (Index = 0; Index < Length; Index++) {\r
58 //\r
59 // Obtain one word-length (64-bit) Random Number with possible retry-loop.\r
60 //\r
61 Status = RdRand64 (RandBuffer, TRUE);\r
62 if (EFI_ERROR (Status)) {\r
63 return Status;\r
64 }\r
65 \r
66 RandBuffer++;\r
67 }\r
68\r
69 return EFI_SUCCESS;\r
70}