]>
Commit | Line | Data |
---|---|---|
3aa8dc6c LQ |
1 | /** @file\r |
2 | Header for the RDRAND APIs used by RNG DXE driver.\r | |
3 | \r | |
4 | Support API definitions for RDRAND instruction access, which will leverage\r | |
5 | Intel Secure Key technology to provide high-quality random numbers for use\r | |
6 | in applications, or entropy for seeding other random number generators.\r | |
7 | Refer to http://software.intel.com/en-us/articles/intel-digital-random-number\r | |
8 | -generator-drng-software-implementation-guide/ for more information about Intel\r | |
9 | Secure Key technology.\r | |
10 | \r | |
11 | Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r | |
12 | This program and the accompanying materials\r | |
13 | are licensed and made available under the terms and conditions of the BSD License\r | |
14 | which accompanies this distribution. The full text of the license may be found at\r | |
15 | http://opensource.org/licenses/bsd-license.php\r | |
16 | \r | |
17 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
18 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
19 | \r | |
20 | **/\r | |
21 | \r | |
22 | #ifndef __RD_RAND_H__\r | |
23 | #define __RD_RAND_H__\r | |
24 | \r | |
25 | #include <Library/BaseLib.h>\r | |
26 | #include <Library/BaseMemoryLib.h>\r | |
27 | #include <Library/UefiBootServicesTableLib.h>\r | |
28 | #include <Library/TimerLib.h>\r | |
29 | #include <Protocol/Rng.h>\r | |
30 | \r | |
31 | //\r | |
32 | // The maximun number of retries to obtain one available random number. \r | |
33 | //\r | |
34 | #define RETRY_LIMIT 10\r | |
35 | \r | |
36 | /**\r | |
37 | Determines whether or not RDRAND instruction is supported by the host hardware.\r | |
38 | \r | |
39 | @retval EFI_SUCCESS RDRAND instruction supported.\r | |
40 | @retval EFI_UNSUPPORTED RDRAND instruction not supported.\r | |
41 | \r | |
42 | **/\r | |
43 | EFI_STATUS\r | |
44 | EFIAPI\r | |
45 | IsRdRandSupported (\r | |
46 | VOID\r | |
47 | );\r | |
48 | \r | |
49 | /**\r | |
50 | Generates a 16-bit random number through RDRAND instruction.\r | |
51 | \r | |
52 | @param[out] Rand Buffer pointer to store the random result.\r | |
53 | \r | |
54 | @retval TRUE RDRAND call was successful.\r | |
55 | @retval FALSE Failed attempts to call RDRAND.\r | |
56 | \r | |
57 | **/\r | |
58 | BOOLEAN\r | |
59 | EFIAPI\r | |
60 | RdRand16Step (\r | |
61 | OUT UINT16 *Rand\r | |
62 | );\r | |
63 | \r | |
64 | /**\r | |
65 | Generates a 32-bit random number through RDRAND instruction.\r | |
66 | \r | |
67 | @param[out] Rand Buffer pointer to store the random result.\r | |
68 | \r | |
69 | @retval TRUE RDRAND call was successful.\r | |
70 | @retval FALSE Failed attempts to call RDRAND.\r | |
71 | \r | |
72 | **/\r | |
73 | BOOLEAN\r | |
74 | EFIAPI\r | |
75 | RdRand32Step (\r | |
76 | OUT UINT32 *Rand\r | |
77 | );\r | |
78 | \r | |
79 | /**\r | |
80 | Generates a 64-bit random number through RDRAND instruction.\r | |
81 | \r | |
82 | @param[out] Rand Buffer pointer to store the random result.\r | |
83 | \r | |
84 | @retval TRUE RDRAND call was successful.\r | |
85 | @retval FALSE Failed attempts to call RDRAND.\r | |
86 | \r | |
87 | **/\r | |
88 | BOOLEAN\r | |
89 | EFIAPI\r | |
90 | RdRand64Step (\r | |
91 | OUT UINT64 *Rand\r | |
92 | );\r | |
93 | \r | |
94 | /**\r | |
95 | Calls RDRAND to obtain a 16-bit random number.\r | |
96 | \r | |
97 | @param[out] Rand Buffer pointer to store the random result.\r | |
98 | @param[in] NeedRetry Determine whether or not to loop retry.\r | |
99 | \r | |
100 | @retval EFI_SUCCESS RDRAND call was successful.\r | |
101 | @retval EFI_NOT_READY Failed attempts to call RDRAND.\r | |
102 | \r | |
103 | **/\r | |
104 | EFI_STATUS\r | |
105 | EFIAPI\r | |
106 | RdRand16 (\r | |
107 | OUT UINT16 *Rand,\r | |
108 | IN BOOLEAN NeedRetry\r | |
109 | );\r | |
110 | \r | |
111 | /**\r | |
112 | Calls RDRAND to obtain a 32-bit random number.\r | |
113 | \r | |
114 | @param[out] Rand Buffer pointer to store the random result.\r | |
115 | @param[in] NeedRetry Determine whether or not to loop retry.\r | |
116 | \r | |
117 | @retval EFI_SUCCESS RDRAND call was successful.\r | |
118 | @retval EFI_NOT_READY Failed attempts to call RDRAND.\r | |
119 | \r | |
120 | **/\r | |
121 | EFI_STATUS\r | |
122 | EFIAPI\r | |
123 | RdRand32 (\r | |
124 | OUT UINT32 *Rand,\r | |
125 | IN BOOLEAN NeedRetry\r | |
126 | );\r | |
127 | \r | |
128 | /**\r | |
129 | Calls RDRAND to obtain a 64-bit random number.\r | |
130 | \r | |
131 | @param[out] Rand Buffer pointer to store the random result.\r | |
132 | @param[in] NeedRetry Determine whether or not to loop retry.\r | |
133 | \r | |
134 | @retval EFI_SUCCESS RDRAND call was successful.\r | |
135 | @retval EFI_NOT_READY Failed attempts to call RDRAND.\r | |
136 | \r | |
137 | **/\r | |
138 | EFI_STATUS\r | |
139 | EFIAPI\r | |
140 | RdRand64 (\r | |
141 | OUT UINT64 *Rand,\r | |
142 | IN BOOLEAN NeedRetry\r | |
143 | );\r | |
144 | \r | |
145 | /**\r | |
146 | Calls RDRAND to request a word-length random number.\r | |
147 | \r | |
148 | @param[out] Rand Buffer pointer to store the random number.\r | |
149 | @param[in] NeedRetry Determine whether or not to loop retry.\r | |
150 | \r | |
151 | @retval EFI_SUCCESS Random word generation succeeded.\r | |
152 | @retval EFI_NOT_READY Failed to request random word.\r | |
153 | \r | |
154 | **/\r | |
155 | EFI_STATUS\r | |
156 | EFIAPI\r | |
157 | RdRandWord (\r | |
158 | OUT UINTN *Rand,\r | |
159 | IN BOOLEAN NeedRetry\r | |
160 | );\r | |
161 | \r | |
162 | /**\r | |
163 | Calls RDRAND to request multiple word-length random numbers.\r | |
164 | \r | |
165 | @param[in] Length Size of the buffer, in words, to fill with.\r | |
166 | @param[out] RandBuffer Pointer to the buffer to store the random result.\r | |
167 | \r | |
168 | @retval EFI_SUCCESS Random words generation succeeded.\r | |
169 | @retval EFI_NOT_READY Failed to request random words.\r | |
170 | \r | |
171 | **/\r | |
172 | EFI_STATUS\r | |
173 | EFIAPI\r | |
174 | RdRandGetWords (\r | |
175 | IN UINTN Length,\r | |
176 | OUT UINTN *RandBuffer\r | |
177 | );\r | |
178 | \r | |
179 | /**\r | |
180 | Calls RDRAND to fill a buffer of arbitrary size with random bytes.\r | |
181 | \r | |
182 | @param[in] Length Size of the buffer, in bytes, to fill with.\r | |
183 | @param[out] RandBuffer Pointer to the buffer to store the random result.\r | |
184 | \r | |
185 | @retval EFI_SUCCESS Random bytes generation succeeded.\r | |
186 | @retval EFI_NOT_READY Failed to request random bytes.\r | |
187 | \r | |
188 | **/\r | |
189 | EFI_STATUS\r | |
190 | EFIAPI\r | |
191 | RdRandGetBytes (\r | |
192 | IN UINTN Length,\r | |
193 | OUT UINT8 *RandBuffer\r | |
194 | );\r | |
195 | \r | |
196 | /**\r | |
197 | Generate high-quality entropy source through RDRAND.\r | |
198 | \r | |
199 | @param[in] Length Size of the buffer, in bytes, to fill with.\r | |
200 | @param[out] Entropy Pointer to the buffer to store the entropy data.\r | |
201 | \r | |
202 | @retval EFI_SUCCESS Entropy generation succeeded.\r | |
203 | @retval EFI_NOT_READY Failed to request random data.\r | |
204 | \r | |
205 | **/\r | |
206 | EFI_STATUS\r | |
207 | EFIAPI\r | |
208 | RdRandGenerateEntropy (\r | |
209 | IN UINTN Length,\r | |
210 | OUT UINT8 *Entropy\r | |
211 | );\r | |
212 | \r | |
213 | #endif // __RD_RAND_H__ |