]>
Commit | Line | Data |
---|---|---|
97f98500 HT |
1 | /** @file\r |
2 | Defines base cryptographic library APIs.\r | |
3 | The Base Cryptographic Library provides implementations of basic cryptography\r | |
a8c44645 | 4 | primitives (Hash Serials, HMAC, RSA, Diffie-Hellman, etc) for UEFI security\r |
5 | functionality enabling.\r | |
97f98500 | 6 | \r |
9a1f14ad | 7 | Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>\r |
2009f6b4 | 8 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
97f98500 HT |
9 | \r |
10 | **/\r | |
11 | \r | |
12 | #ifndef __BASE_CRYPT_LIB_H__\r | |
13 | #define __BASE_CRYPT_LIB_H__\r | |
14 | \r | |
9e8841b4 QL |
15 | #include <Uefi/UefiBaseType.h>\r |
16 | \r | |
97f98500 HT |
17 | ///\r |
18 | /// MD5 digest size in bytes\r | |
19 | ///\r | |
7c342378 | 20 | #define MD5_DIGEST_SIZE 16\r |
97f98500 HT |
21 | \r |
22 | ///\r | |
23 | /// SHA-1 digest size in bytes.\r | |
24 | ///\r | |
7c342378 | 25 | #define SHA1_DIGEST_SIZE 20\r |
97f98500 HT |
26 | \r |
27 | ///\r | |
28 | /// SHA-256 digest size in bytes\r | |
29 | ///\r | |
30 | #define SHA256_DIGEST_SIZE 32\r | |
31 | \r | |
2ac68e8b QL |
32 | ///\r |
33 | /// SHA-384 digest size in bytes\r | |
34 | ///\r | |
35 | #define SHA384_DIGEST_SIZE 48\r | |
36 | \r | |
37 | ///\r | |
38 | /// SHA-512 digest size in bytes\r | |
39 | ///\r | |
40 | #define SHA512_DIGEST_SIZE 64\r | |
41 | \r | |
f0718d1d LX |
42 | ///\r |
43 | /// SM3 digest size in bytes\r | |
44 | ///\r | |
7c342378 | 45 | #define SM3_256_DIGEST_SIZE 32\r |
f0718d1d | 46 | \r |
a8c44645 | 47 | ///\r |
48 | /// TDES block size in bytes\r | |
49 | ///\r | |
7c342378 | 50 | #define TDES_BLOCK_SIZE 8\r |
a8c44645 | 51 | \r |
52 | ///\r | |
53 | /// AES block size in bytes\r | |
54 | ///\r | |
7c342378 | 55 | #define AES_BLOCK_SIZE 16\r |
a8c44645 | 56 | \r |
97f98500 HT |
57 | ///\r |
58 | /// RSA Key Tags Definition used in RsaSetKey() function for key component identification.\r | |
59 | ///\r | |
60 | typedef enum {\r | |
61 | RsaKeyN, ///< RSA public Modulus (N)\r | |
62 | RsaKeyE, ///< RSA Public exponent (e)\r | |
63 | RsaKeyD, ///< RSA Private exponent (d)\r | |
64 | RsaKeyP, ///< RSA secret prime factor of Modulus (p)\r | |
65 | RsaKeyQ, ///< RSA secret prime factor of Modules (q)\r | |
66 | RsaKeyDp, ///< p's CRT exponent (== d mod (p - 1))\r | |
67 | RsaKeyDq, ///< q's CRT exponent (== d mod (q - 1))\r | |
68 | RsaKeyQInv ///< The CRT coefficient (== 1/q mod p)\r | |
69 | } RSA_KEY_TAG;\r | |
70 | \r | |
7c342378 | 71 | // =====================================================================================\r |
97f98500 | 72 | // One-Way Cryptographic Hash Primitives\r |
7c342378 | 73 | // =====================================================================================\r |
97f98500 | 74 | \r |
e6a12a0f | 75 | #ifdef ENABLE_MD5_DEPRECATED_INTERFACES\r |
7c342378 | 76 | \r |
97f98500 HT |
77 | /**\r |
78 | Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r | |
79 | \r | |
532616bb | 80 | If this interface is not supported, then return zero.\r |
81 | \r | |
97f98500 | 82 | @return The size, in bytes, of the context buffer required for MD5 hash operations.\r |
532616bb | 83 | @retval 0 This interface is not supported.\r |
97f98500 HT |
84 | \r |
85 | **/\r | |
86 | UINTN\r | |
87 | EFIAPI\r | |
88 | Md5GetContextSize (\r | |
89 | VOID\r | |
90 | );\r | |
91 | \r | |
97f98500 HT |
92 | /**\r |
93 | Initializes user-supplied memory pointed by Md5Context as MD5 hash context for\r | |
94 | subsequent use.\r | |
95 | \r | |
16d2c32c | 96 | If Md5Context is NULL, then return FALSE.\r |
532616bb | 97 | If this interface is not supported, then return FALSE.\r |
97f98500 | 98 | \r |
a8c44645 | 99 | @param[out] Md5Context Pointer to MD5 context being initialized.\r |
97f98500 HT |
100 | \r |
101 | @retval TRUE MD5 context initialization succeeded.\r | |
102 | @retval FALSE MD5 context initialization failed.\r | |
532616bb | 103 | @retval FALSE This interface is not supported.\r |
97f98500 HT |
104 | \r |
105 | **/\r | |
106 | BOOLEAN\r | |
107 | EFIAPI\r | |
108 | Md5Init (\r | |
a8c44645 | 109 | OUT VOID *Md5Context\r |
97f98500 HT |
110 | );\r |
111 | \r | |
a8c44645 | 112 | /**\r |
113 | Makes a copy of an existing MD5 context.\r | |
114 | \r | |
16d2c32c | 115 | If Md5Context is NULL, then return FALSE.\r |
116 | If NewMd5Context is NULL, then return FALSE.\r | |
532616bb | 117 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 118 | \r |
119 | @param[in] Md5Context Pointer to MD5 context being copied.\r | |
120 | @param[out] NewMd5Context Pointer to new MD5 context.\r | |
121 | \r | |
122 | @retval TRUE MD5 context copy succeeded.\r | |
123 | @retval FALSE MD5 context copy failed.\r | |
532616bb | 124 | @retval FALSE This interface is not supported.\r |
a8c44645 | 125 | \r |
126 | **/\r | |
127 | BOOLEAN\r | |
128 | EFIAPI\r | |
129 | Md5Duplicate (\r | |
130 | IN CONST VOID *Md5Context,\r | |
131 | OUT VOID *NewMd5Context\r | |
132 | );\r | |
97f98500 HT |
133 | \r |
134 | /**\r | |
a8c44645 | 135 | Digests the input data and updates MD5 context.\r |
136 | \r | |
137 | This function performs MD5 digest on a data buffer of the specified size.\r | |
138 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
2998af86 | 139 | MD5 context should be already correctly initialized by Md5Init(), and should not be finalized\r |
a8c44645 | 140 | by Md5Final(). Behavior with invalid context is undefined.\r |
97f98500 | 141 | \r |
16d2c32c | 142 | If Md5Context is NULL, then return FALSE.\r |
532616bb | 143 | If this interface is not supported, then return FALSE.\r |
97f98500 HT |
144 | \r |
145 | @param[in, out] Md5Context Pointer to the MD5 context.\r | |
146 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
a8c44645 | 147 | @param[in] DataSize Size of Data buffer in bytes.\r |
97f98500 HT |
148 | \r |
149 | @retval TRUE MD5 data digest succeeded.\r | |
a8c44645 | 150 | @retval FALSE MD5 data digest failed.\r |
532616bb | 151 | @retval FALSE This interface is not supported.\r |
97f98500 HT |
152 | \r |
153 | **/\r | |
154 | BOOLEAN\r | |
155 | EFIAPI\r | |
156 | Md5Update (\r | |
157 | IN OUT VOID *Md5Context,\r | |
158 | IN CONST VOID *Data,\r | |
a8c44645 | 159 | IN UINTN DataSize\r |
97f98500 HT |
160 | );\r |
161 | \r | |
97f98500 | 162 | /**\r |
a8c44645 | 163 | Completes computation of the MD5 digest value.\r |
164 | \r | |
165 | This function completes MD5 hash computation and retrieves the digest value into\r | |
166 | the specified memory. After this function has been called, the MD5 context cannot\r | |
167 | be used again.\r | |
2998af86 | 168 | MD5 context should be already correctly initialized by Md5Init(), and should not be\r |
a8c44645 | 169 | finalized by Md5Final(). Behavior with invalid MD5 context is undefined.\r |
97f98500 | 170 | \r |
16d2c32c | 171 | If Md5Context is NULL, then return FALSE.\r |
172 | If HashValue is NULL, then return FALSE.\r | |
532616bb | 173 | If this interface is not supported, then return FALSE.\r |
97f98500 | 174 | \r |
a8c44645 | 175 | @param[in, out] Md5Context Pointer to the MD5 context.\r |
97f98500 HT |
176 | @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r |
177 | value (16 bytes).\r | |
178 | \r | |
179 | @retval TRUE MD5 digest computation succeeded.\r | |
180 | @retval FALSE MD5 digest computation failed.\r | |
532616bb | 181 | @retval FALSE This interface is not supported.\r |
97f98500 HT |
182 | \r |
183 | **/\r | |
184 | BOOLEAN\r | |
185 | EFIAPI\r | |
186 | Md5Final (\r | |
187 | IN OUT VOID *Md5Context,\r | |
188 | OUT UINT8 *HashValue\r | |
189 | );\r | |
190 | \r | |
b7d1ba0a QL |
191 | /**\r |
192 | Computes the MD5 message digest of a input data buffer.\r | |
193 | \r | |
194 | This function performs the MD5 message digest of a given data buffer, and places\r | |
195 | the digest value into the specified memory.\r | |
196 | \r | |
197 | If this interface is not supported, then return FALSE.\r | |
198 | \r | |
199 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
200 | @param[in] DataSize Size of Data buffer in bytes.\r | |
201 | @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r | |
202 | value (16 bytes).\r | |
203 | \r | |
204 | @retval TRUE MD5 digest computation succeeded.\r | |
205 | @retval FALSE MD5 digest computation failed.\r | |
206 | @retval FALSE This interface is not supported.\r | |
207 | \r | |
208 | **/\r | |
209 | BOOLEAN\r | |
210 | EFIAPI\r | |
211 | Md5HashAll (\r | |
212 | IN CONST VOID *Data,\r | |
213 | IN UINTN DataSize,\r | |
214 | OUT UINT8 *HashValue\r | |
215 | );\r | |
7c342378 | 216 | \r |
acfd5557 | 217 | #endif\r |
b7d1ba0a | 218 | \r |
0f01cec5 | 219 | #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES\r |
7c342378 | 220 | \r |
97f98500 HT |
221 | /**\r |
222 | Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.\r | |
223 | \r | |
532616bb | 224 | If this interface is not supported, then return zero.\r |
225 | \r | |
97f98500 | 226 | @return The size, in bytes, of the context buffer required for SHA-1 hash operations.\r |
532616bb | 227 | @retval 0 This interface is not supported.\r |
97f98500 HT |
228 | \r |
229 | **/\r | |
230 | UINTN\r | |
231 | EFIAPI\r | |
232 | Sha1GetContextSize (\r | |
233 | VOID\r | |
234 | );\r | |
235 | \r | |
97f98500 | 236 | /**\r |
a8c44645 | 237 | Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for\r |
97f98500 HT |
238 | subsequent use.\r |
239 | \r | |
16d2c32c | 240 | If Sha1Context is NULL, then return FALSE.\r |
532616bb | 241 | If this interface is not supported, then return FALSE.\r |
97f98500 | 242 | \r |
a8c44645 | 243 | @param[out] Sha1Context Pointer to SHA-1 context being initialized.\r |
97f98500 | 244 | \r |
a8c44645 | 245 | @retval TRUE SHA-1 context initialization succeeded.\r |
246 | @retval FALSE SHA-1 context initialization failed.\r | |
532616bb | 247 | @retval FALSE This interface is not supported.\r |
97f98500 HT |
248 | \r |
249 | **/\r | |
250 | BOOLEAN\r | |
251 | EFIAPI\r | |
252 | Sha1Init (\r | |
a8c44645 | 253 | OUT VOID *Sha1Context\r |
97f98500 HT |
254 | );\r |
255 | \r | |
a8c44645 | 256 | /**\r |
257 | Makes a copy of an existing SHA-1 context.\r | |
258 | \r | |
16d2c32c | 259 | If Sha1Context is NULL, then return FALSE.\r |
260 | If NewSha1Context is NULL, then return FALSE.\r | |
532616bb | 261 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 262 | \r |
263 | @param[in] Sha1Context Pointer to SHA-1 context being copied.\r | |
264 | @param[out] NewSha1Context Pointer to new SHA-1 context.\r | |
265 | \r | |
266 | @retval TRUE SHA-1 context copy succeeded.\r | |
267 | @retval FALSE SHA-1 context copy failed.\r | |
532616bb | 268 | @retval FALSE This interface is not supported.\r |
a8c44645 | 269 | \r |
270 | **/\r | |
271 | BOOLEAN\r | |
272 | EFIAPI\r | |
273 | Sha1Duplicate (\r | |
274 | IN CONST VOID *Sha1Context,\r | |
275 | OUT VOID *NewSha1Context\r | |
276 | );\r | |
97f98500 HT |
277 | \r |
278 | /**\r | |
a8c44645 | 279 | Digests the input data and updates SHA-1 context.\r |
280 | \r | |
281 | This function performs SHA-1 digest on a data buffer of the specified size.\r | |
282 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
2998af86 | 283 | SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized\r |
a8c44645 | 284 | by Sha1Final(). Behavior with invalid context is undefined.\r |
97f98500 | 285 | \r |
16d2c32c | 286 | If Sha1Context is NULL, then return FALSE.\r |
532616bb | 287 | If this interface is not supported, then return FALSE.\r |
97f98500 HT |
288 | \r |
289 | @param[in, out] Sha1Context Pointer to the SHA-1 context.\r | |
290 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
a8c44645 | 291 | @param[in] DataSize Size of Data buffer in bytes.\r |
97f98500 HT |
292 | \r |
293 | @retval TRUE SHA-1 data digest succeeded.\r | |
a8c44645 | 294 | @retval FALSE SHA-1 data digest failed.\r |
532616bb | 295 | @retval FALSE This interface is not supported.\r |
97f98500 HT |
296 | \r |
297 | **/\r | |
298 | BOOLEAN\r | |
299 | EFIAPI\r | |
300 | Sha1Update (\r | |
301 | IN OUT VOID *Sha1Context,\r | |
302 | IN CONST VOID *Data,\r | |
a8c44645 | 303 | IN UINTN DataSize\r |
97f98500 HT |
304 | );\r |
305 | \r | |
97f98500 | 306 | /**\r |
a8c44645 | 307 | Completes computation of the SHA-1 digest value.\r |
308 | \r | |
309 | This function completes SHA-1 hash computation and retrieves the digest value into\r | |
310 | the specified memory. After this function has been called, the SHA-1 context cannot\r | |
311 | be used again.\r | |
2998af86 | 312 | SHA-1 context should be already correctly initialized by Sha1Init(), and should not be\r |
a8c44645 | 313 | finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.\r |
97f98500 | 314 | \r |
16d2c32c | 315 | If Sha1Context is NULL, then return FALSE.\r |
316 | If HashValue is NULL, then return FALSE.\r | |
532616bb | 317 | If this interface is not supported, then return FALSE.\r |
97f98500 | 318 | \r |
a8c44645 | 319 | @param[in, out] Sha1Context Pointer to the SHA-1 context.\r |
97f98500 HT |
320 | @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r |
321 | value (20 bytes).\r | |
322 | \r | |
323 | @retval TRUE SHA-1 digest computation succeeded.\r | |
324 | @retval FALSE SHA-1 digest computation failed.\r | |
532616bb | 325 | @retval FALSE This interface is not supported.\r |
97f98500 HT |
326 | \r |
327 | **/\r | |
328 | BOOLEAN\r | |
329 | EFIAPI\r | |
330 | Sha1Final (\r | |
331 | IN OUT VOID *Sha1Context,\r | |
332 | OUT UINT8 *HashValue\r | |
333 | );\r | |
334 | \r | |
b7d1ba0a QL |
335 | /**\r |
336 | Computes the SHA-1 message digest of a input data buffer.\r | |
337 | \r | |
338 | This function performs the SHA-1 message digest of a given data buffer, and places\r | |
339 | the digest value into the specified memory.\r | |
340 | \r | |
341 | If this interface is not supported, then return FALSE.\r | |
342 | \r | |
343 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
344 | @param[in] DataSize Size of Data buffer in bytes.\r | |
345 | @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r | |
346 | value (20 bytes).\r | |
347 | \r | |
348 | @retval TRUE SHA-1 digest computation succeeded.\r | |
349 | @retval FALSE SHA-1 digest computation failed.\r | |
350 | @retval FALSE This interface is not supported.\r | |
351 | \r | |
352 | **/\r | |
353 | BOOLEAN\r | |
354 | EFIAPI\r | |
355 | Sha1HashAll (\r | |
356 | IN CONST VOID *Data,\r | |
357 | IN UINTN DataSize,\r | |
358 | OUT UINT8 *HashValue\r | |
359 | );\r | |
7c342378 | 360 | \r |
0f01cec5 | 361 | #endif\r |
b7d1ba0a | 362 | \r |
97f98500 | 363 | /**\r |
a8c44645 | 364 | Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.\r |
97f98500 | 365 | \r |
a8c44645 | 366 | @return The size, in bytes, of the context buffer required for SHA-256 hash operations.\r |
97f98500 HT |
367 | \r |
368 | **/\r | |
369 | UINTN\r | |
370 | EFIAPI\r | |
371 | Sha256GetContextSize (\r | |
372 | VOID\r | |
373 | );\r | |
374 | \r | |
97f98500 HT |
375 | /**\r |
376 | Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for\r | |
377 | subsequent use.\r | |
378 | \r | |
16d2c32c | 379 | If Sha256Context is NULL, then return FALSE.\r |
97f98500 | 380 | \r |
a8c44645 | 381 | @param[out] Sha256Context Pointer to SHA-256 context being initialized.\r |
97f98500 HT |
382 | \r |
383 | @retval TRUE SHA-256 context initialization succeeded.\r | |
384 | @retval FALSE SHA-256 context initialization failed.\r | |
385 | \r | |
386 | **/\r | |
387 | BOOLEAN\r | |
388 | EFIAPI\r | |
389 | Sha256Init (\r | |
a8c44645 | 390 | OUT VOID *Sha256Context\r |
97f98500 HT |
391 | );\r |
392 | \r | |
a8c44645 | 393 | /**\r |
394 | Makes a copy of an existing SHA-256 context.\r | |
395 | \r | |
16d2c32c | 396 | If Sha256Context is NULL, then return FALSE.\r |
397 | If NewSha256Context is NULL, then return FALSE.\r | |
532616bb | 398 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 399 | \r |
400 | @param[in] Sha256Context Pointer to SHA-256 context being copied.\r | |
401 | @param[out] NewSha256Context Pointer to new SHA-256 context.\r | |
402 | \r | |
403 | @retval TRUE SHA-256 context copy succeeded.\r | |
404 | @retval FALSE SHA-256 context copy failed.\r | |
532616bb | 405 | @retval FALSE This interface is not supported.\r |
a8c44645 | 406 | \r |
407 | **/\r | |
408 | BOOLEAN\r | |
409 | EFIAPI\r | |
410 | Sha256Duplicate (\r | |
411 | IN CONST VOID *Sha256Context,\r | |
412 | OUT VOID *NewSha256Context\r | |
413 | );\r | |
97f98500 HT |
414 | \r |
415 | /**\r | |
a8c44645 | 416 | Digests the input data and updates SHA-256 context.\r |
417 | \r | |
418 | This function performs SHA-256 digest on a data buffer of the specified size.\r | |
419 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
2998af86 | 420 | SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized\r |
a8c44645 | 421 | by Sha256Final(). Behavior with invalid context is undefined.\r |
97f98500 | 422 | \r |
16d2c32c | 423 | If Sha256Context is NULL, then return FALSE.\r |
97f98500 HT |
424 | \r |
425 | @param[in, out] Sha256Context Pointer to the SHA-256 context.\r | |
426 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
a8c44645 | 427 | @param[in] DataSize Size of Data buffer in bytes.\r |
97f98500 HT |
428 | \r |
429 | @retval TRUE SHA-256 data digest succeeded.\r | |
a8c44645 | 430 | @retval FALSE SHA-256 data digest failed.\r |
97f98500 HT |
431 | \r |
432 | **/\r | |
433 | BOOLEAN\r | |
434 | EFIAPI\r | |
435 | Sha256Update (\r | |
436 | IN OUT VOID *Sha256Context,\r | |
437 | IN CONST VOID *Data,\r | |
a8c44645 | 438 | IN UINTN DataSize\r |
97f98500 HT |
439 | );\r |
440 | \r | |
97f98500 | 441 | /**\r |
a8c44645 | 442 | Completes computation of the SHA-256 digest value.\r |
443 | \r | |
444 | This function completes SHA-256 hash computation and retrieves the digest value into\r | |
445 | the specified memory. After this function has been called, the SHA-256 context cannot\r | |
446 | be used again.\r | |
2998af86 | 447 | SHA-256 context should be already correctly initialized by Sha256Init(), and should not be\r |
a8c44645 | 448 | finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.\r |
97f98500 | 449 | \r |
16d2c32c | 450 | If Sha256Context is NULL, then return FALSE.\r |
451 | If HashValue is NULL, then return FALSE.\r | |
97f98500 | 452 | \r |
a8c44645 | 453 | @param[in, out] Sha256Context Pointer to the SHA-256 context.\r |
97f98500 HT |
454 | @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r |
455 | value (32 bytes).\r | |
456 | \r | |
457 | @retval TRUE SHA-256 digest computation succeeded.\r | |
458 | @retval FALSE SHA-256 digest computation failed.\r | |
459 | \r | |
460 | **/\r | |
461 | BOOLEAN\r | |
462 | EFIAPI\r | |
463 | Sha256Final (\r | |
464 | IN OUT VOID *Sha256Context,\r | |
465 | OUT UINT8 *HashValue\r | |
466 | );\r | |
467 | \r | |
b7d1ba0a QL |
468 | /**\r |
469 | Computes the SHA-256 message digest of a input data buffer.\r | |
470 | \r | |
471 | This function performs the SHA-256 message digest of a given data buffer, and places\r | |
472 | the digest value into the specified memory.\r | |
473 | \r | |
474 | If this interface is not supported, then return FALSE.\r | |
475 | \r | |
476 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
477 | @param[in] DataSize Size of Data buffer in bytes.\r | |
478 | @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r | |
479 | value (32 bytes).\r | |
480 | \r | |
481 | @retval TRUE SHA-256 digest computation succeeded.\r | |
482 | @retval FALSE SHA-256 digest computation failed.\r | |
483 | @retval FALSE This interface is not supported.\r | |
484 | \r | |
485 | **/\r | |
486 | BOOLEAN\r | |
487 | EFIAPI\r | |
488 | Sha256HashAll (\r | |
489 | IN CONST VOID *Data,\r | |
490 | IN UINTN DataSize,\r | |
491 | OUT UINT8 *HashValue\r | |
492 | );\r | |
493 | \r | |
2ac68e8b QL |
494 | /**\r |
495 | Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.\r | |
496 | \r | |
497 | @return The size, in bytes, of the context buffer required for SHA-384 hash operations.\r | |
498 | \r | |
499 | **/\r | |
500 | UINTN\r | |
501 | EFIAPI\r | |
502 | Sha384GetContextSize (\r | |
503 | VOID\r | |
504 | );\r | |
505 | \r | |
506 | /**\r | |
507 | Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for\r | |
508 | subsequent use.\r | |
509 | \r | |
510 | If Sha384Context is NULL, then return FALSE.\r | |
511 | \r | |
512 | @param[out] Sha384Context Pointer to SHA-384 context being initialized.\r | |
513 | \r | |
514 | @retval TRUE SHA-384 context initialization succeeded.\r | |
515 | @retval FALSE SHA-384 context initialization failed.\r | |
516 | \r | |
517 | **/\r | |
518 | BOOLEAN\r | |
519 | EFIAPI\r | |
520 | Sha384Init (\r | |
521 | OUT VOID *Sha384Context\r | |
522 | );\r | |
523 | \r | |
524 | /**\r | |
525 | Makes a copy of an existing SHA-384 context.\r | |
526 | \r | |
527 | If Sha384Context is NULL, then return FALSE.\r | |
528 | If NewSha384Context is NULL, then return FALSE.\r | |
529 | If this interface is not supported, then return FALSE.\r | |
530 | \r | |
531 | @param[in] Sha384Context Pointer to SHA-384 context being copied.\r | |
532 | @param[out] NewSha384Context Pointer to new SHA-384 context.\r | |
533 | \r | |
534 | @retval TRUE SHA-384 context copy succeeded.\r | |
535 | @retval FALSE SHA-384 context copy failed.\r | |
536 | @retval FALSE This interface is not supported.\r | |
537 | \r | |
538 | **/\r | |
539 | BOOLEAN\r | |
540 | EFIAPI\r | |
541 | Sha384Duplicate (\r | |
542 | IN CONST VOID *Sha384Context,\r | |
543 | OUT VOID *NewSha384Context\r | |
544 | );\r | |
545 | \r | |
546 | /**\r | |
547 | Digests the input data and updates SHA-384 context.\r | |
548 | \r | |
549 | This function performs SHA-384 digest on a data buffer of the specified size.\r | |
550 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
2998af86 | 551 | SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized\r |
2ac68e8b QL |
552 | by Sha384Final(). Behavior with invalid context is undefined.\r |
553 | \r | |
554 | If Sha384Context is NULL, then return FALSE.\r | |
555 | \r | |
556 | @param[in, out] Sha384Context Pointer to the SHA-384 context.\r | |
557 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
558 | @param[in] DataSize Size of Data buffer in bytes.\r | |
559 | \r | |
560 | @retval TRUE SHA-384 data digest succeeded.\r | |
561 | @retval FALSE SHA-384 data digest failed.\r | |
562 | \r | |
563 | **/\r | |
564 | BOOLEAN\r | |
565 | EFIAPI\r | |
566 | Sha384Update (\r | |
567 | IN OUT VOID *Sha384Context,\r | |
568 | IN CONST VOID *Data,\r | |
569 | IN UINTN DataSize\r | |
570 | );\r | |
571 | \r | |
572 | /**\r | |
573 | Completes computation of the SHA-384 digest value.\r | |
574 | \r | |
575 | This function completes SHA-384 hash computation and retrieves the digest value into\r | |
576 | the specified memory. After this function has been called, the SHA-384 context cannot\r | |
577 | be used again.\r | |
2998af86 | 578 | SHA-384 context should be already correctly initialized by Sha384Init(), and should not be\r |
2ac68e8b QL |
579 | finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.\r |
580 | \r | |
581 | If Sha384Context is NULL, then return FALSE.\r | |
582 | If HashValue is NULL, then return FALSE.\r | |
583 | \r | |
584 | @param[in, out] Sha384Context Pointer to the SHA-384 context.\r | |
585 | @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest\r | |
586 | value (48 bytes).\r | |
587 | \r | |
588 | @retval TRUE SHA-384 digest computation succeeded.\r | |
589 | @retval FALSE SHA-384 digest computation failed.\r | |
590 | \r | |
591 | **/\r | |
592 | BOOLEAN\r | |
593 | EFIAPI\r | |
594 | Sha384Final (\r | |
595 | IN OUT VOID *Sha384Context,\r | |
596 | OUT UINT8 *HashValue\r | |
597 | );\r | |
598 | \r | |
b7d1ba0a QL |
599 | /**\r |
600 | Computes the SHA-384 message digest of a input data buffer.\r | |
601 | \r | |
602 | This function performs the SHA-384 message digest of a given data buffer, and places\r | |
603 | the digest value into the specified memory.\r | |
604 | \r | |
605 | If this interface is not supported, then return FALSE.\r | |
606 | \r | |
607 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
608 | @param[in] DataSize Size of Data buffer in bytes.\r | |
609 | @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest\r | |
610 | value (48 bytes).\r | |
611 | \r | |
612 | @retval TRUE SHA-384 digest computation succeeded.\r | |
613 | @retval FALSE SHA-384 digest computation failed.\r | |
614 | @retval FALSE This interface is not supported.\r | |
615 | \r | |
616 | **/\r | |
617 | BOOLEAN\r | |
618 | EFIAPI\r | |
619 | Sha384HashAll (\r | |
620 | IN CONST VOID *Data,\r | |
621 | IN UINTN DataSize,\r | |
622 | OUT UINT8 *HashValue\r | |
623 | );\r | |
624 | \r | |
2ac68e8b QL |
625 | /**\r |
626 | Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.\r | |
627 | \r | |
628 | @return The size, in bytes, of the context buffer required for SHA-512 hash operations.\r | |
629 | \r | |
630 | **/\r | |
631 | UINTN\r | |
632 | EFIAPI\r | |
633 | Sha512GetContextSize (\r | |
634 | VOID\r | |
635 | );\r | |
636 | \r | |
637 | /**\r | |
638 | Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for\r | |
639 | subsequent use.\r | |
640 | \r | |
641 | If Sha512Context is NULL, then return FALSE.\r | |
642 | \r | |
643 | @param[out] Sha512Context Pointer to SHA-512 context being initialized.\r | |
644 | \r | |
645 | @retval TRUE SHA-512 context initialization succeeded.\r | |
646 | @retval FALSE SHA-512 context initialization failed.\r | |
647 | \r | |
648 | **/\r | |
649 | BOOLEAN\r | |
650 | EFIAPI\r | |
651 | Sha512Init (\r | |
652 | OUT VOID *Sha512Context\r | |
653 | );\r | |
654 | \r | |
655 | /**\r | |
656 | Makes a copy of an existing SHA-512 context.\r | |
657 | \r | |
658 | If Sha512Context is NULL, then return FALSE.\r | |
659 | If NewSha512Context is NULL, then return FALSE.\r | |
660 | If this interface is not supported, then return FALSE.\r | |
661 | \r | |
662 | @param[in] Sha512Context Pointer to SHA-512 context being copied.\r | |
663 | @param[out] NewSha512Context Pointer to new SHA-512 context.\r | |
664 | \r | |
665 | @retval TRUE SHA-512 context copy succeeded.\r | |
666 | @retval FALSE SHA-512 context copy failed.\r | |
667 | @retval FALSE This interface is not supported.\r | |
668 | \r | |
669 | **/\r | |
670 | BOOLEAN\r | |
671 | EFIAPI\r | |
672 | Sha512Duplicate (\r | |
673 | IN CONST VOID *Sha512Context,\r | |
674 | OUT VOID *NewSha512Context\r | |
675 | );\r | |
676 | \r | |
677 | /**\r | |
678 | Digests the input data and updates SHA-512 context.\r | |
679 | \r | |
680 | This function performs SHA-512 digest on a data buffer of the specified size.\r | |
681 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
2998af86 | 682 | SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized\r |
2ac68e8b QL |
683 | by Sha512Final(). Behavior with invalid context is undefined.\r |
684 | \r | |
685 | If Sha512Context is NULL, then return FALSE.\r | |
686 | \r | |
687 | @param[in, out] Sha512Context Pointer to the SHA-512 context.\r | |
688 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
689 | @param[in] DataSize Size of Data buffer in bytes.\r | |
690 | \r | |
691 | @retval TRUE SHA-512 data digest succeeded.\r | |
692 | @retval FALSE SHA-512 data digest failed.\r | |
693 | \r | |
694 | **/\r | |
695 | BOOLEAN\r | |
696 | EFIAPI\r | |
697 | Sha512Update (\r | |
698 | IN OUT VOID *Sha512Context,\r | |
699 | IN CONST VOID *Data,\r | |
700 | IN UINTN DataSize\r | |
701 | );\r | |
702 | \r | |
703 | /**\r | |
704 | Completes computation of the SHA-512 digest value.\r | |
705 | \r | |
706 | This function completes SHA-512 hash computation and retrieves the digest value into\r | |
707 | the specified memory. After this function has been called, the SHA-512 context cannot\r | |
708 | be used again.\r | |
2998af86 | 709 | SHA-512 context should be already correctly initialized by Sha512Init(), and should not be\r |
2ac68e8b QL |
710 | finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.\r |
711 | \r | |
712 | If Sha512Context is NULL, then return FALSE.\r | |
713 | If HashValue is NULL, then return FALSE.\r | |
714 | \r | |
715 | @param[in, out] Sha512Context Pointer to the SHA-512 context.\r | |
716 | @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest\r | |
717 | value (64 bytes).\r | |
718 | \r | |
719 | @retval TRUE SHA-512 digest computation succeeded.\r | |
720 | @retval FALSE SHA-512 digest computation failed.\r | |
721 | \r | |
722 | **/\r | |
723 | BOOLEAN\r | |
724 | EFIAPI\r | |
725 | Sha512Final (\r | |
726 | IN OUT VOID *Sha512Context,\r | |
727 | OUT UINT8 *HashValue\r | |
728 | );\r | |
97f98500 | 729 | \r |
b7d1ba0a QL |
730 | /**\r |
731 | Computes the SHA-512 message digest of a input data buffer.\r | |
732 | \r | |
733 | This function performs the SHA-512 message digest of a given data buffer, and places\r | |
734 | the digest value into the specified memory.\r | |
735 | \r | |
736 | If this interface is not supported, then return FALSE.\r | |
737 | \r | |
738 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
739 | @param[in] DataSize Size of Data buffer in bytes.\r | |
740 | @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest\r | |
741 | value (64 bytes).\r | |
742 | \r | |
743 | @retval TRUE SHA-512 digest computation succeeded.\r | |
744 | @retval FALSE SHA-512 digest computation failed.\r | |
745 | @retval FALSE This interface is not supported.\r | |
746 | \r | |
747 | **/\r | |
748 | BOOLEAN\r | |
749 | EFIAPI\r | |
750 | Sha512HashAll (\r | |
751 | IN CONST VOID *Data,\r | |
752 | IN UINTN DataSize,\r | |
753 | OUT UINT8 *HashValue\r | |
754 | );\r | |
755 | \r | |
f0718d1d LX |
756 | /**\r |
757 | Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.\r | |
758 | \r | |
759 | @return The size, in bytes, of the context buffer required for SM3 hash operations.\r | |
760 | \r | |
761 | **/\r | |
762 | UINTN\r | |
763 | EFIAPI\r | |
764 | Sm3GetContextSize (\r | |
765 | VOID\r | |
766 | );\r | |
767 | \r | |
768 | /**\r | |
769 | Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for\r | |
770 | subsequent use.\r | |
771 | \r | |
772 | If Sm3Context is NULL, then return FALSE.\r | |
773 | \r | |
774 | @param[out] Sm3Context Pointer to SM3 context being initialized.\r | |
775 | \r | |
776 | @retval TRUE SM3 context initialization succeeded.\r | |
777 | @retval FALSE SM3 context initialization failed.\r | |
778 | \r | |
779 | **/\r | |
780 | BOOLEAN\r | |
781 | EFIAPI\r | |
782 | Sm3Init (\r | |
783 | OUT VOID *Sm3Context\r | |
784 | );\r | |
785 | \r | |
786 | /**\r | |
787 | Makes a copy of an existing SM3 context.\r | |
788 | \r | |
789 | If Sm3Context is NULL, then return FALSE.\r | |
790 | If NewSm3Context is NULL, then return FALSE.\r | |
791 | If this interface is not supported, then return FALSE.\r | |
792 | \r | |
793 | @param[in] Sm3Context Pointer to SM3 context being copied.\r | |
794 | @param[out] NewSm3Context Pointer to new SM3 context.\r | |
795 | \r | |
796 | @retval TRUE SM3 context copy succeeded.\r | |
797 | @retval FALSE SM3 context copy failed.\r | |
798 | @retval FALSE This interface is not supported.\r | |
799 | \r | |
800 | **/\r | |
801 | BOOLEAN\r | |
802 | EFIAPI\r | |
803 | Sm3Duplicate (\r | |
804 | IN CONST VOID *Sm3Context,\r | |
805 | OUT VOID *NewSm3Context\r | |
806 | );\r | |
807 | \r | |
808 | /**\r | |
809 | Digests the input data and updates SM3 context.\r | |
810 | \r | |
811 | This function performs SM3 digest on a data buffer of the specified size.\r | |
812 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
813 | SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized\r | |
814 | by Sm3Final(). Behavior with invalid context is undefined.\r | |
815 | \r | |
816 | If Sm3Context is NULL, then return FALSE.\r | |
817 | \r | |
818 | @param[in, out] Sm3Context Pointer to the SM3 context.\r | |
819 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
820 | @param[in] DataSize Size of Data buffer in bytes.\r | |
821 | \r | |
822 | @retval TRUE SM3 data digest succeeded.\r | |
823 | @retval FALSE SM3 data digest failed.\r | |
824 | \r | |
825 | **/\r | |
826 | BOOLEAN\r | |
827 | EFIAPI\r | |
828 | Sm3Update (\r | |
829 | IN OUT VOID *Sm3Context,\r | |
830 | IN CONST VOID *Data,\r | |
831 | IN UINTN DataSize\r | |
832 | );\r | |
833 | \r | |
834 | /**\r | |
835 | Completes computation of the SM3 digest value.\r | |
836 | \r | |
837 | This function completes SM3 hash computation and retrieves the digest value into\r | |
838 | the specified memory. After this function has been called, the SM3 context cannot\r | |
839 | be used again.\r | |
840 | SM3 context should be already correctly initialized by Sm3Init(), and should not be\r | |
841 | finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.\r | |
842 | \r | |
843 | If Sm3Context is NULL, then return FALSE.\r | |
844 | If HashValue is NULL, then return FALSE.\r | |
845 | \r | |
846 | @param[in, out] Sm3Context Pointer to the SM3 context.\r | |
847 | @param[out] HashValue Pointer to a buffer that receives the SM3 digest\r | |
848 | value (32 bytes).\r | |
849 | \r | |
850 | @retval TRUE SM3 digest computation succeeded.\r | |
851 | @retval FALSE SM3 digest computation failed.\r | |
852 | \r | |
853 | **/\r | |
854 | BOOLEAN\r | |
855 | EFIAPI\r | |
856 | Sm3Final (\r | |
857 | IN OUT VOID *Sm3Context,\r | |
858 | OUT UINT8 *HashValue\r | |
859 | );\r | |
860 | \r | |
861 | /**\r | |
862 | Computes the SM3 message digest of a input data buffer.\r | |
863 | \r | |
864 | This function performs the SM3 message digest of a given data buffer, and places\r | |
865 | the digest value into the specified memory.\r | |
866 | \r | |
867 | If this interface is not supported, then return FALSE.\r | |
868 | \r | |
869 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
870 | @param[in] DataSize Size of Data buffer in bytes.\r | |
871 | @param[out] HashValue Pointer to a buffer that receives the SM3 digest\r | |
872 | value (32 bytes).\r | |
873 | \r | |
874 | @retval TRUE SM3 digest computation succeeded.\r | |
875 | @retval FALSE SM3 digest computation failed.\r | |
876 | @retval FALSE This interface is not supported.\r | |
877 | \r | |
878 | **/\r | |
879 | BOOLEAN\r | |
880 | EFIAPI\r | |
881 | Sm3HashAll (\r | |
882 | IN CONST VOID *Data,\r | |
883 | IN UINTN DataSize,\r | |
884 | OUT UINT8 *HashValue\r | |
885 | );\r | |
886 | \r | |
7c342378 | 887 | // =====================================================================================\r |
97f98500 | 888 | // MAC (Message Authentication Code) Primitive\r |
7c342378 | 889 | // =====================================================================================\r |
97f98500 | 890 | \r |
4c270243 QL |
891 | /**\r |
892 | Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.\r | |
893 | \r | |
894 | @return Pointer to the HMAC_CTX context that has been initialized.\r | |
895 | If the allocations fails, HmacSha256New() returns NULL.\r | |
896 | \r | |
897 | **/\r | |
898 | VOID *\r | |
899 | EFIAPI\r | |
900 | HmacSha256New (\r | |
901 | VOID\r | |
902 | );\r | |
903 | \r | |
904 | /**\r | |
905 | Release the specified HMAC_CTX context.\r | |
906 | \r | |
907 | @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.\r | |
908 | \r | |
909 | **/\r | |
910 | VOID\r | |
911 | EFIAPI\r | |
912 | HmacSha256Free (\r | |
913 | IN VOID *HmacSha256Ctx\r | |
914 | );\r | |
915 | \r | |
72009c62 | 916 | /**\r |
a23fdff6 JW |
917 | Set user-supplied key for subsequent use. It must be done before any\r |
918 | calling to HmacSha256Update().\r | |
72009c62 QL |
919 | \r |
920 | If HmacSha256Context is NULL, then return FALSE.\r | |
921 | If this interface is not supported, then return FALSE.\r | |
922 | \r | |
a23fdff6 | 923 | @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.\r |
72009c62 QL |
924 | @param[in] Key Pointer to the user-supplied key.\r |
925 | @param[in] KeySize Key size in bytes.\r | |
926 | \r | |
a23fdff6 JW |
927 | @retval TRUE The Key is set successfully.\r |
928 | @retval FALSE The Key is set unsuccessfully.\r | |
72009c62 QL |
929 | @retval FALSE This interface is not supported.\r |
930 | \r | |
931 | **/\r | |
932 | BOOLEAN\r | |
933 | EFIAPI\r | |
a23fdff6 | 934 | HmacSha256SetKey (\r |
72009c62 QL |
935 | OUT VOID *HmacSha256Context,\r |
936 | IN CONST UINT8 *Key,\r | |
937 | IN UINTN KeySize\r | |
938 | );\r | |
939 | \r | |
940 | /**\r | |
941 | Makes a copy of an existing HMAC-SHA256 context.\r | |
942 | \r | |
943 | If HmacSha256Context is NULL, then return FALSE.\r | |
944 | If NewHmacSha256Context is NULL, then return FALSE.\r | |
945 | If this interface is not supported, then return FALSE.\r | |
946 | \r | |
947 | @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.\r | |
948 | @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.\r | |
949 | \r | |
950 | @retval TRUE HMAC-SHA256 context copy succeeded.\r | |
951 | @retval FALSE HMAC-SHA256 context copy failed.\r | |
952 | @retval FALSE This interface is not supported.\r | |
953 | \r | |
954 | **/\r | |
955 | BOOLEAN\r | |
956 | EFIAPI\r | |
957 | HmacSha256Duplicate (\r | |
958 | IN CONST VOID *HmacSha256Context,\r | |
959 | OUT VOID *NewHmacSha256Context\r | |
960 | );\r | |
961 | \r | |
962 | /**\r | |
963 | Digests the input data and updates HMAC-SHA256 context.\r | |
964 | \r | |
965 | This function performs HMAC-SHA256 digest on a data buffer of the specified size.\r | |
966 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
a23fdff6 JW |
967 | HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r |
968 | by HmacSha256Final(). Behavior with invalid context is undefined.\r | |
72009c62 QL |
969 | \r |
970 | If HmacSha256Context is NULL, then return FALSE.\r | |
971 | If this interface is not supported, then return FALSE.\r | |
972 | \r | |
973 | @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r | |
974 | @param[in] Data Pointer to the buffer containing the data to be digested.\r | |
975 | @param[in] DataSize Size of Data buffer in bytes.\r | |
976 | \r | |
977 | @retval TRUE HMAC-SHA256 data digest succeeded.\r | |
978 | @retval FALSE HMAC-SHA256 data digest failed.\r | |
979 | @retval FALSE This interface is not supported.\r | |
980 | \r | |
981 | **/\r | |
982 | BOOLEAN\r | |
983 | EFIAPI\r | |
984 | HmacSha256Update (\r | |
985 | IN OUT VOID *HmacSha256Context,\r | |
986 | IN CONST VOID *Data,\r | |
987 | IN UINTN DataSize\r | |
988 | );\r | |
989 | \r | |
990 | /**\r | |
991 | Completes computation of the HMAC-SHA256 digest value.\r | |
992 | \r | |
993 | This function completes HMAC-SHA256 hash computation and retrieves the digest value into\r | |
994 | the specified memory. After this function has been called, the HMAC-SHA256 context cannot\r | |
995 | be used again.\r | |
a23fdff6 JW |
996 | HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r |
997 | by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.\r | |
72009c62 QL |
998 | \r |
999 | If HmacSha256Context is NULL, then return FALSE.\r | |
68ae7cd6 | 1000 | If HmacValue is NULL, then return FALSE.\r |
72009c62 QL |
1001 | If this interface is not supported, then return FALSE.\r |
1002 | \r | |
1003 | @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r | |
68ae7cd6 | 1004 | @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest\r |
72009c62 QL |
1005 | value (32 bytes).\r |
1006 | \r | |
1007 | @retval TRUE HMAC-SHA256 digest computation succeeded.\r | |
1008 | @retval FALSE HMAC-SHA256 digest computation failed.\r | |
1009 | @retval FALSE This interface is not supported.\r | |
1010 | \r | |
1011 | **/\r | |
1012 | BOOLEAN\r | |
1013 | EFIAPI\r | |
1014 | HmacSha256Final (\r | |
1015 | IN OUT VOID *HmacSha256Context,\r | |
1016 | OUT UINT8 *HmacValue\r | |
1017 | );\r | |
1018 | \r | |
7c342378 | 1019 | // =====================================================================================\r |
97f98500 | 1020 | // Symmetric Cryptography Primitive\r |
7c342378 | 1021 | // =====================================================================================\r |
97f98500 | 1022 | \r |
a8c44645 | 1023 | /**\r |
1024 | Retrieves the size, in bytes, of the context buffer required for AES operations.\r | |
1025 | \r | |
532616bb | 1026 | If this interface is not supported, then return zero.\r |
1027 | \r | |
a8c44645 | 1028 | @return The size, in bytes, of the context buffer required for AES operations.\r |
532616bb | 1029 | @retval 0 This interface is not supported.\r |
a8c44645 | 1030 | \r |
1031 | **/\r | |
1032 | UINTN\r | |
1033 | EFIAPI\r | |
1034 | AesGetContextSize (\r | |
1035 | VOID\r | |
1036 | );\r | |
1037 | \r | |
1038 | /**\r | |
1039 | Initializes user-supplied memory as AES context for subsequent use.\r | |
1040 | \r | |
1041 | This function initializes user-supplied memory pointed by AesContext as AES context.\r | |
6b8ebcb8 | 1042 | In addition, it sets up all AES key materials for subsequent encryption and decryption\r |
a8c44645 | 1043 | operations.\r |
1044 | There are 3 options for key length, 128 bits, 192 bits, and 256 bits.\r | |
1045 | \r | |
16d2c32c | 1046 | If AesContext is NULL, then return FALSE.\r |
1047 | If Key is NULL, then return FALSE.\r | |
1048 | If KeyLength is not valid, then return FALSE.\r | |
532616bb | 1049 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1050 | \r |
1051 | @param[out] AesContext Pointer to AES context being initialized.\r | |
1052 | @param[in] Key Pointer to the user-supplied AES key.\r | |
1053 | @param[in] KeyLength Length of AES key in bits.\r | |
1054 | \r | |
1055 | @retval TRUE AES context initialization succeeded.\r | |
1056 | @retval FALSE AES context initialization failed.\r | |
532616bb | 1057 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1058 | \r |
1059 | **/\r | |
1060 | BOOLEAN\r | |
1061 | EFIAPI\r | |
1062 | AesInit (\r | |
1063 | OUT VOID *AesContext,\r | |
1064 | IN CONST UINT8 *Key,\r | |
1065 | IN UINTN KeyLength\r | |
1066 | );\r | |
1067 | \r | |
a8c44645 | 1068 | /**\r |
1069 | Performs AES encryption on a data buffer of the specified size in CBC mode.\r | |
1070 | \r | |
1071 | This function performs AES encryption on data buffer pointed by Input, of specified\r | |
1072 | size of InputSize, in CBC mode.\r | |
1073 | InputSize must be multiple of block size (16 bytes). This function does not perform\r | |
1074 | padding. Caller must perform padding, if necessary, to ensure valid input data size.\r | |
1075 | Initialization vector should be one block size (16 bytes).\r | |
1076 | AesContext should be already correctly initialized by AesInit(). Behavior with\r | |
1077 | invalid AES context is undefined.\r | |
1078 | \r | |
16d2c32c | 1079 | If AesContext is NULL, then return FALSE.\r |
1080 | If Input is NULL, then return FALSE.\r | |
1081 | If InputSize is not multiple of block size (16 bytes), then return FALSE.\r | |
1082 | If Ivec is NULL, then return FALSE.\r | |
1083 | If Output is NULL, then return FALSE.\r | |
532616bb | 1084 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1085 | \r |
1086 | @param[in] AesContext Pointer to the AES context.\r | |
1087 | @param[in] Input Pointer to the buffer containing the data to be encrypted.\r | |
1088 | @param[in] InputSize Size of the Input buffer in bytes.\r | |
1089 | @param[in] Ivec Pointer to initialization vector.\r | |
1090 | @param[out] Output Pointer to a buffer that receives the AES encryption output.\r | |
1091 | \r | |
1092 | @retval TRUE AES encryption succeeded.\r | |
1093 | @retval FALSE AES encryption failed.\r | |
532616bb | 1094 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1095 | \r |
1096 | **/\r | |
1097 | BOOLEAN\r | |
1098 | EFIAPI\r | |
1099 | AesCbcEncrypt (\r | |
1100 | IN VOID *AesContext,\r | |
1101 | IN CONST UINT8 *Input,\r | |
1102 | IN UINTN InputSize,\r | |
1103 | IN CONST UINT8 *Ivec,\r | |
1104 | OUT UINT8 *Output\r | |
1105 | );\r | |
1106 | \r | |
1107 | /**\r | |
1108 | Performs AES decryption on a data buffer of the specified size in CBC mode.\r | |
1109 | \r | |
1110 | This function performs AES decryption on data buffer pointed by Input, of specified\r | |
1111 | size of InputSize, in CBC mode.\r | |
1112 | InputSize must be multiple of block size (16 bytes). This function does not perform\r | |
1113 | padding. Caller must perform padding, if necessary, to ensure valid input data size.\r | |
1114 | Initialization vector should be one block size (16 bytes).\r | |
1115 | AesContext should be already correctly initialized by AesInit(). Behavior with\r | |
1116 | invalid AES context is undefined.\r | |
1117 | \r | |
16d2c32c | 1118 | If AesContext is NULL, then return FALSE.\r |
1119 | If Input is NULL, then return FALSE.\r | |
1120 | If InputSize is not multiple of block size (16 bytes), then return FALSE.\r | |
1121 | If Ivec is NULL, then return FALSE.\r | |
1122 | If Output is NULL, then return FALSE.\r | |
532616bb | 1123 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1124 | \r |
1125 | @param[in] AesContext Pointer to the AES context.\r | |
1126 | @param[in] Input Pointer to the buffer containing the data to be encrypted.\r | |
1127 | @param[in] InputSize Size of the Input buffer in bytes.\r | |
1128 | @param[in] Ivec Pointer to initialization vector.\r | |
1129 | @param[out] Output Pointer to a buffer that receives the AES encryption output.\r | |
1130 | \r | |
1131 | @retval TRUE AES decryption succeeded.\r | |
1132 | @retval FALSE AES decryption failed.\r | |
532616bb | 1133 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1134 | \r |
1135 | **/\r | |
1136 | BOOLEAN\r | |
1137 | EFIAPI\r | |
1138 | AesCbcDecrypt (\r | |
1139 | IN VOID *AesContext,\r | |
1140 | IN CONST UINT8 *Input,\r | |
1141 | IN UINTN InputSize,\r | |
1142 | IN CONST UINT8 *Ivec,\r | |
1143 | OUT UINT8 *Output\r | |
1144 | );\r | |
1145 | \r | |
7c342378 | 1146 | // =====================================================================================\r |
97f98500 | 1147 | // Asymmetric Cryptography Primitive\r |
7c342378 | 1148 | // =====================================================================================\r |
97f98500 HT |
1149 | \r |
1150 | /**\r | |
a8c44645 | 1151 | Allocates and initializes one RSA context for subsequent use.\r |
97f98500 | 1152 | \r |
a8c44645 | 1153 | @return Pointer to the RSA context that has been initialized.\r |
97f98500 HT |
1154 | If the allocations fails, RsaNew() returns NULL.\r |
1155 | \r | |
1156 | **/\r | |
1157 | VOID *\r | |
1158 | EFIAPI\r | |
1159 | RsaNew (\r | |
1160 | VOID\r | |
1161 | );\r | |
1162 | \r | |
97f98500 | 1163 | /**\r |
a8c44645 | 1164 | Release the specified RSA context.\r |
1165 | \r | |
16d2c32c | 1166 | If RsaContext is NULL, then return FALSE.\r |
97f98500 HT |
1167 | \r |
1168 | @param[in] RsaContext Pointer to the RSA context to be released.\r | |
1169 | \r | |
1170 | **/\r | |
1171 | VOID\r | |
1172 | EFIAPI\r | |
1173 | RsaFree (\r | |
1174 | IN VOID *RsaContext\r | |
1175 | );\r | |
1176 | \r | |
97f98500 | 1177 | /**\r |
a8c44645 | 1178 | Sets the tag-designated key component into the established RSA context.\r |
1179 | \r | |
1180 | This function sets the tag-designated RSA key component into the established\r | |
1181 | RSA context from the user-specified non-negative integer (octet string format\r | |
1182 | represented in RSA PKCS#1).\r | |
2998af86 | 1183 | If BigNumber is NULL, then the specified key component in RSA context is cleared.\r |
97f98500 | 1184 | \r |
16d2c32c | 1185 | If RsaContext is NULL, then return FALSE.\r |
97f98500 HT |
1186 | \r |
1187 | @param[in, out] RsaContext Pointer to RSA context being set.\r | |
1188 | @param[in] KeyTag Tag of RSA key component being set.\r | |
1189 | @param[in] BigNumber Pointer to octet integer buffer.\r | |
2998af86 | 1190 | If NULL, then the specified key component in RSA\r |
a8c44645 | 1191 | context is cleared.\r |
1192 | @param[in] BnSize Size of big number buffer in bytes.\r | |
1193 | If BigNumber is NULL, then it is ignored.\r | |
97f98500 | 1194 | \r |
a8c44645 | 1195 | @retval TRUE RSA key component was set successfully.\r |
1196 | @retval FALSE Invalid RSA key component tag.\r | |
97f98500 HT |
1197 | \r |
1198 | **/\r | |
1199 | BOOLEAN\r | |
1200 | EFIAPI\r | |
1201 | RsaSetKey (\r | |
a8c44645 | 1202 | IN OUT VOID *RsaContext,\r |
1203 | IN RSA_KEY_TAG KeyTag,\r | |
1204 | IN CONST UINT8 *BigNumber,\r | |
1205 | IN UINTN BnSize\r | |
1206 | );\r | |
1207 | \r | |
1208 | /**\r | |
1209 | Gets the tag-designated RSA key component from the established RSA context.\r | |
1210 | \r | |
1211 | This function retrieves the tag-designated RSA key component from the\r | |
1212 | established RSA context as a non-negative integer (octet string format\r | |
1213 | represented in RSA PKCS#1).\r | |
1214 | If specified key component has not been set or has been cleared, then returned\r | |
1215 | BnSize is set to 0.\r | |
1216 | If the BigNumber buffer is too small to hold the contents of the key, FALSE\r | |
1217 | is returned and BnSize is set to the required buffer size to obtain the key.\r | |
1218 | \r | |
16d2c32c | 1219 | If RsaContext is NULL, then return FALSE.\r |
1220 | If BnSize is NULL, then return FALSE.\r | |
1221 | If BnSize is large enough but BigNumber is NULL, then return FALSE.\r | |
532616bb | 1222 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1223 | \r |
1224 | @param[in, out] RsaContext Pointer to RSA context being set.\r | |
1225 | @param[in] KeyTag Tag of RSA key component being set.\r | |
1226 | @param[out] BigNumber Pointer to octet integer buffer.\r | |
1227 | @param[in, out] BnSize On input, the size of big number buffer in bytes.\r | |
1228 | On output, the size of data returned in big number buffer in bytes.\r | |
1229 | \r | |
1230 | @retval TRUE RSA key component was retrieved successfully.\r | |
1231 | @retval FALSE Invalid RSA key component tag.\r | |
1232 | @retval FALSE BnSize is too small.\r | |
532616bb | 1233 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1234 | \r |
1235 | **/\r | |
1236 | BOOLEAN\r | |
1237 | EFIAPI\r | |
1238 | RsaGetKey (\r | |
1239 | IN OUT VOID *RsaContext,\r | |
1240 | IN RSA_KEY_TAG KeyTag,\r | |
1241 | OUT UINT8 *BigNumber,\r | |
1242 | IN OUT UINTN *BnSize\r | |
1243 | );\r | |
1244 | \r | |
1245 | /**\r | |
1246 | Generates RSA key components.\r | |
1247 | \r | |
1248 | This function generates RSA key components. It takes RSA public exponent E and\r | |
1249 | length in bits of RSA modulus N as input, and generates all key components.\r | |
1250 | If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.\r | |
1251 | \r | |
1252 | Before this function can be invoked, pseudorandom number generator must be correctly\r | |
1253 | initialized by RandomSeed().\r | |
1254 | \r | |
16d2c32c | 1255 | If RsaContext is NULL, then return FALSE.\r |
532616bb | 1256 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1257 | \r |
1258 | @param[in, out] RsaContext Pointer to RSA context being set.\r | |
1259 | @param[in] ModulusLength Length of RSA modulus N in bits.\r | |
1260 | @param[in] PublicExponent Pointer to RSA public exponent.\r | |
2ac68e8b | 1261 | @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.\r |
a8c44645 | 1262 | \r |
1263 | @retval TRUE RSA key component was generated successfully.\r | |
1264 | @retval FALSE Invalid RSA key component tag.\r | |
532616bb | 1265 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1266 | \r |
1267 | **/\r | |
1268 | BOOLEAN\r | |
1269 | EFIAPI\r | |
1270 | RsaGenerateKey (\r | |
1271 | IN OUT VOID *RsaContext,\r | |
1272 | IN UINTN ModulusLength,\r | |
1273 | IN CONST UINT8 *PublicExponent,\r | |
1274 | IN UINTN PublicExponentSize\r | |
1275 | );\r | |
1276 | \r | |
1277 | /**\r | |
1278 | Validates key components of RSA context.\r | |
952bd229 QL |
1279 | NOTE: This function performs integrity checks on all the RSA key material, so\r |
1280 | the RSA key structure must contain all the private key data.\r | |
a8c44645 | 1281 | \r |
2998af86 | 1282 | This function validates key components of RSA context in following aspects:\r |
a8c44645 | 1283 | - Whether p is a prime\r |
1284 | - Whether q is a prime\r | |
1285 | - Whether n = p * q\r | |
1286 | - Whether d*e = 1 mod lcm(p-1,q-1)\r | |
1287 | \r | |
16d2c32c | 1288 | If RsaContext is NULL, then return FALSE.\r |
532616bb | 1289 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1290 | \r |
1291 | @param[in] RsaContext Pointer to RSA context to check.\r | |
1292 | \r | |
1293 | @retval TRUE RSA key components are valid.\r | |
1294 | @retval FALSE RSA key components are not valid.\r | |
532616bb | 1295 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1296 | \r |
1297 | **/\r | |
1298 | BOOLEAN\r | |
1299 | EFIAPI\r | |
1300 | RsaCheckKey (\r | |
1301 | IN VOID *RsaContext\r | |
97f98500 HT |
1302 | );\r |
1303 | \r | |
a8c44645 | 1304 | /**\r |
1305 | Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.\r | |
1306 | \r | |
1307 | This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in\r | |
1308 | RSA PKCS#1.\r | |
1309 | If the Signature buffer is too small to hold the contents of signature, FALSE\r | |
1310 | is returned and SigSize is set to the required buffer size to obtain the signature.\r | |
1311 | \r | |
16d2c32c | 1312 | If RsaContext is NULL, then return FALSE.\r |
1313 | If MessageHash is NULL, then return FALSE.\r | |
1314 | If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.\r | |
1315 | If SigSize is large enough but Signature is NULL, then return FALSE.\r | |
532616bb | 1316 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1317 | \r |
1318 | @param[in] RsaContext Pointer to RSA context for signature generation.\r | |
1319 | @param[in] MessageHash Pointer to octet message hash to be signed.\r | |
1320 | @param[in] HashSize Size of the message hash in bytes.\r | |
1321 | @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.\r | |
1322 | @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r | |
b7d320f8 | 1323 | On output, the size of data returned in Signature buffer in bytes.\r |
a8c44645 | 1324 | \r |
1325 | @retval TRUE Signature successfully generated in PKCS1-v1_5.\r | |
1326 | @retval FALSE Signature generation failed.\r | |
1327 | @retval FALSE SigSize is too small.\r | |
532616bb | 1328 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1329 | \r |
1330 | **/\r | |
1331 | BOOLEAN\r | |
1332 | EFIAPI\r | |
1333 | RsaPkcs1Sign (\r | |
1334 | IN VOID *RsaContext,\r | |
1335 | IN CONST UINT8 *MessageHash,\r | |
1336 | IN UINTN HashSize,\r | |
1337 | OUT UINT8 *Signature,\r | |
1338 | IN OUT UINTN *SigSize\r | |
1339 | );\r | |
97f98500 HT |
1340 | \r |
1341 | /**\r | |
1342 | Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in\r | |
1343 | RSA PKCS#1.\r | |
1344 | \r | |
16d2c32c | 1345 | If RsaContext is NULL, then return FALSE.\r |
1346 | If MessageHash is NULL, then return FALSE.\r | |
1347 | If Signature is NULL, then return FALSE.\r | |
1348 | If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.\r | |
97f98500 HT |
1349 | \r |
1350 | @param[in] RsaContext Pointer to RSA context for signature verification.\r | |
1351 | @param[in] MessageHash Pointer to octet message hash to be checked.\r | |
a8c44645 | 1352 | @param[in] HashSize Size of the message hash in bytes.\r |
97f98500 | 1353 | @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.\r |
a8c44645 | 1354 | @param[in] SigSize Size of signature in bytes.\r |
97f98500 | 1355 | \r |
a8c44645 | 1356 | @retval TRUE Valid signature encoded in PKCS1-v1_5.\r |
1357 | @retval FALSE Invalid signature or invalid RSA context.\r | |
97f98500 HT |
1358 | \r |
1359 | **/\r | |
1360 | BOOLEAN\r | |
1361 | EFIAPI\r | |
1362 | RsaPkcs1Verify (\r | |
1363 | IN VOID *RsaContext,\r | |
1364 | IN CONST UINT8 *MessageHash,\r | |
a8c44645 | 1365 | IN UINTN HashSize,\r |
8c5720b4 | 1366 | IN CONST UINT8 *Signature,\r |
a8c44645 | 1367 | IN UINTN SigSize\r |
97f98500 HT |
1368 | );\r |
1369 | \r | |
22ac5cc9 SA |
1370 | /**\r |
1371 | Carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme.\r | |
1372 | \r | |
1373 | This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in\r | |
1374 | RFC 8017.\r | |
1375 | Mask generation function is the same as the message digest algorithm.\r | |
1376 | If the Signature buffer is too small to hold the contents of signature, FALSE\r | |
1377 | is returned and SigSize is set to the required buffer size to obtain the signature.\r | |
1378 | \r | |
1379 | If RsaContext is NULL, then return FALSE.\r | |
1380 | If Message is NULL, then return FALSE.\r | |
1381 | If MsgSize is zero or > INT_MAX, then return FALSE.\r | |
1382 | If DigestLen is NOT 32, 48 or 64, return FALSE.\r | |
20ca5288 | 1383 | If SaltLen is not equal to DigestLen, then return FALSE.\r |
22ac5cc9 SA |
1384 | If SigSize is large enough but Signature is NULL, then return FALSE.\r |
1385 | If this interface is not supported, then return FALSE.\r | |
1386 | \r | |
1387 | @param[in] RsaContext Pointer to RSA context for signature generation.\r | |
1388 | @param[in] Message Pointer to octet message to be signed.\r | |
1389 | @param[in] MsgSize Size of the message in bytes.\r | |
1390 | @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.\r | |
1391 | @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.\r | |
1392 | @param[out] Signature Pointer to buffer to receive RSA PSS signature.\r | |
1393 | @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r | |
1394 | On output, the size of data returned in Signature buffer in bytes.\r | |
1395 | \r | |
1396 | @retval TRUE Signature successfully generated in RSASSA-PSS.\r | |
1397 | @retval FALSE Signature generation failed.\r | |
1398 | @retval FALSE SigSize is too small.\r | |
1399 | @retval FALSE This interface is not supported.\r | |
1400 | \r | |
1401 | **/\r | |
1402 | BOOLEAN\r | |
1403 | EFIAPI\r | |
1404 | RsaPssSign (\r | |
1405 | IN VOID *RsaContext,\r | |
1406 | IN CONST UINT8 *Message,\r | |
1407 | IN UINTN MsgSize,\r | |
1408 | IN UINT16 DigestLen,\r | |
1409 | IN UINT16 SaltLen,\r | |
1410 | OUT UINT8 *Signature,\r | |
1411 | IN OUT UINTN *SigSize\r | |
1412 | );\r | |
1413 | \r | |
1414 | /**\r | |
1415 | Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.\r | |
1416 | Implementation determines salt length automatically from the signature encoding.\r | |
1417 | Mask generation function is the same as the message digest algorithm.\r | |
20ca5288 | 1418 | Salt length should be equal to digest length.\r |
22ac5cc9 SA |
1419 | \r |
1420 | @param[in] RsaContext Pointer to RSA context for signature verification.\r | |
1421 | @param[in] Message Pointer to octet message to be verified.\r | |
1422 | @param[in] MsgSize Size of the message in bytes.\r | |
1423 | @param[in] Signature Pointer to RSASSA-PSS signature to be verified.\r | |
1424 | @param[in] SigSize Size of signature in bytes.\r | |
1425 | @param[in] DigestLen Length of digest for RSA operation.\r | |
1426 | @param[in] SaltLen Salt length for PSS encoding.\r | |
1427 | \r | |
1428 | @retval TRUE Valid signature encoded in RSASSA-PSS.\r | |
1429 | @retval FALSE Invalid signature or invalid RSA context.\r | |
1430 | \r | |
1431 | **/\r | |
1432 | BOOLEAN\r | |
1433 | EFIAPI\r | |
1434 | RsaPssVerify (\r | |
1435 | IN VOID *RsaContext,\r | |
1436 | IN CONST UINT8 *Message,\r | |
1437 | IN UINTN MsgSize,\r | |
1438 | IN CONST UINT8 *Signature,\r | |
1439 | IN UINTN SigSize,\r | |
1440 | IN UINT16 DigestLen,\r | |
1441 | IN UINT16 SaltLen\r | |
1442 | );\r | |
1443 | \r | |
4a567c96 | 1444 | /**\r |
1445 | Retrieve the RSA Private Key from the password-protected PEM key data.\r | |
1446 | \r | |
532616bb | 1447 | If PemData is NULL, then return FALSE.\r |
1448 | If RsaContext is NULL, then return FALSE.\r | |
1449 | If this interface is not supported, then return FALSE.\r | |
1450 | \r | |
4a567c96 | 1451 | @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.\r |
1452 | @param[in] PemSize Size of the PEM key data in bytes.\r | |
1453 | @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.\r | |
1454 | @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r | |
1455 | RSA private key component. Use RsaFree() function to free the\r | |
1456 | resource.\r | |
1457 | \r | |
4a567c96 | 1458 | @retval TRUE RSA Private Key was retrieved successfully.\r |
1459 | @retval FALSE Invalid PEM key data or incorrect password.\r | |
532616bb | 1460 | @retval FALSE This interface is not supported.\r |
4a567c96 | 1461 | \r |
1462 | **/\r | |
1463 | BOOLEAN\r | |
1464 | EFIAPI\r | |
1465 | RsaGetPrivateKeyFromPem (\r | |
1466 | IN CONST UINT8 *PemData,\r | |
1467 | IN UINTN PemSize,\r | |
1468 | IN CONST CHAR8 *Password,\r | |
1469 | OUT VOID **RsaContext\r | |
1470 | );\r | |
1471 | \r | |
1472 | /**\r | |
1473 | Retrieve the RSA Public Key from one DER-encoded X509 certificate.\r | |
1474 | \r | |
532616bb | 1475 | If Cert is NULL, then return FALSE.\r |
1476 | If RsaContext is NULL, then return FALSE.\r | |
1477 | If this interface is not supported, then return FALSE.\r | |
1478 | \r | |
4a567c96 | 1479 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r |
1480 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
1481 | @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r | |
1482 | RSA public key component. Use RsaFree() function to free the\r | |
1483 | resource.\r | |
1484 | \r | |
4a567c96 | 1485 | @retval TRUE RSA Public Key was retrieved successfully.\r |
1486 | @retval FALSE Fail to retrieve RSA public key from X509 certificate.\r | |
532616bb | 1487 | @retval FALSE This interface is not supported.\r |
4a567c96 | 1488 | \r |
1489 | **/\r | |
1490 | BOOLEAN\r | |
1491 | EFIAPI\r | |
1492 | RsaGetPublicKeyFromX509 (\r | |
1493 | IN CONST UINT8 *Cert,\r | |
1494 | IN UINTN CertSize,\r | |
1495 | OUT VOID **RsaContext\r | |
1496 | );\r | |
1497 | \r | |
1498 | /**\r | |
1499 | Retrieve the subject bytes from one X.509 certificate.\r | |
1500 | \r | |
532616bb | 1501 | If Cert is NULL, then return FALSE.\r |
1502 | If SubjectSize is NULL, then return FALSE.\r | |
1503 | If this interface is not supported, then return FALSE.\r | |
1504 | \r | |
4a567c96 | 1505 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r |
1506 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
1507 | @param[out] CertSubject Pointer to the retrieved certificate subject bytes.\r | |
1508 | @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,\r | |
1509 | and the size of buffer returned CertSubject on output.\r | |
1510 | \r | |
4a567c96 | 1511 | @retval TRUE The certificate subject retrieved successfully.\r |
1512 | @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.\r | |
1513 | The SubjectSize will be updated with the required size.\r | |
532616bb | 1514 | @retval FALSE This interface is not supported.\r |
4a567c96 | 1515 | \r |
1516 | **/\r | |
1517 | BOOLEAN\r | |
1518 | EFIAPI\r | |
1519 | X509GetSubjectName (\r | |
1520 | IN CONST UINT8 *Cert,\r | |
1521 | IN UINTN CertSize,\r | |
1522 | OUT UINT8 *CertSubject,\r | |
1523 | IN OUT UINTN *SubjectSize\r | |
1524 | );\r | |
1525 | \r | |
5b7c2245 QL |
1526 | /**\r |
1527 | Retrieve the common name (CN) string from one X.509 certificate.\r | |
1528 | \r | |
1529 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r | |
1530 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
1531 | @param[out] CommonName Buffer to contain the retrieved certificate common\r | |
0b6457ef | 1532 | name string (UTF8). At most CommonNameSize bytes will be\r |
5b7c2245 QL |
1533 | written and the string will be null terminated. May be\r |
1534 | NULL in order to determine the size buffer needed.\r | |
1535 | @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,\r | |
1536 | and the size of buffer returned CommonName on output.\r | |
1537 | If CommonName is NULL then the amount of space needed\r | |
1538 | in buffer (including the final null) is returned.\r | |
1539 | \r | |
1540 | @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.\r | |
1541 | @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r | |
1542 | If CommonNameSize is NULL.\r | |
1543 | If CommonName is not NULL and *CommonNameSize is 0.\r | |
1544 | If Certificate is invalid.\r | |
1545 | @retval RETURN_NOT_FOUND If no CommonName entry exists.\r | |
1546 | @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size\r | |
630f67dd | 1547 | (including the final null) is returned in the\r |
5b7c2245 QL |
1548 | CommonNameSize parameter.\r |
1549 | @retval RETURN_UNSUPPORTED The operation is not supported.\r | |
1550 | \r | |
1551 | **/\r | |
1552 | RETURN_STATUS\r | |
1553 | EFIAPI\r | |
1554 | X509GetCommonName (\r | |
1555 | IN CONST UINT8 *Cert,\r | |
1556 | IN UINTN CertSize,\r | |
c8f46130 | 1557 | OUT CHAR8 *CommonName OPTIONAL,\r |
5b7c2245 QL |
1558 | IN OUT UINTN *CommonNameSize\r |
1559 | );\r | |
1560 | \r | |
e2a673b8 BB |
1561 | /**\r |
1562 | Retrieve the organization name (O) string from one X.509 certificate.\r | |
1563 | \r | |
1564 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r | |
1565 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
1566 | @param[out] NameBuffer Buffer to contain the retrieved certificate organization\r | |
1567 | name string. At most NameBufferSize bytes will be\r | |
1568 | written and the string will be null terminated. May be\r | |
1569 | NULL in order to determine the size buffer needed.\r | |
1570 | @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,\r | |
1571 | and the size of buffer returned Name on output.\r | |
1572 | If NameBuffer is NULL then the amount of space needed\r | |
1573 | in buffer (including the final null) is returned.\r | |
1574 | \r | |
1575 | @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.\r | |
1576 | @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r | |
1577 | If NameBufferSize is NULL.\r | |
1578 | If NameBuffer is not NULL and *CommonNameSize is 0.\r | |
1579 | If Certificate is invalid.\r | |
1580 | @retval RETURN_NOT_FOUND If no Organization Name entry exists.\r | |
1581 | @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size\r | |
1582 | (including the final null) is returned in the\r | |
1583 | CommonNameSize parameter.\r | |
1584 | @retval RETURN_UNSUPPORTED The operation is not supported.\r | |
1585 | \r | |
1586 | **/\r | |
1587 | RETURN_STATUS\r | |
1588 | EFIAPI\r | |
1589 | X509GetOrganizationName (\r | |
7c342378 MK |
1590 | IN CONST UINT8 *Cert,\r |
1591 | IN UINTN CertSize,\r | |
1592 | OUT CHAR8 *NameBuffer OPTIONAL,\r | |
1593 | IN OUT UINTN *NameBufferSize\r | |
e2a673b8 BB |
1594 | );\r |
1595 | \r | |
4a567c96 | 1596 | /**\r |
1597 | Verify one X509 certificate was issued by the trusted CA.\r | |
1598 | \r | |
532616bb | 1599 | If Cert is NULL, then return FALSE.\r |
1600 | If CACert is NULL, then return FALSE.\r | |
1601 | If this interface is not supported, then return FALSE.\r | |
1602 | \r | |
4a567c96 | 1603 | @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.\r |
1604 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
1605 | @param[in] CACert Pointer to the DER-encoded trusted CA certificate.\r | |
1606 | @param[in] CACertSize Size of the CA Certificate in bytes.\r | |
1607 | \r | |
4a567c96 | 1608 | @retval TRUE The certificate was issued by the trusted CA.\r |
1609 | @retval FALSE Invalid certificate or the certificate was not issued by the given\r | |
1610 | trusted CA.\r | |
532616bb | 1611 | @retval FALSE This interface is not supported.\r |
4a567c96 | 1612 | \r |
1613 | **/\r | |
1614 | BOOLEAN\r | |
1615 | EFIAPI\r | |
1616 | X509VerifyCert (\r | |
1617 | IN CONST UINT8 *Cert,\r | |
1618 | IN UINTN CertSize,\r | |
1619 | IN CONST UINT8 *CACert,\r | |
1620 | IN UINTN CACertSize\r | |
1621 | );\r | |
1622 | \r | |
b7d320f8 | 1623 | /**\r |
1624 | Construct a X509 object from DER-encoded certificate data.\r | |
1625 | \r | |
16d2c32c | 1626 | If Cert is NULL, then return FALSE.\r |
1627 | If SingleX509Cert is NULL, then return FALSE.\r | |
532616bb | 1628 | If this interface is not supported, then return FALSE.\r |
b7d320f8 | 1629 | \r |
1630 | @param[in] Cert Pointer to the DER-encoded certificate data.\r | |
1631 | @param[in] CertSize The size of certificate data in bytes.\r | |
1632 | @param[out] SingleX509Cert The generated X509 object.\r | |
1633 | \r | |
1634 | @retval TRUE The X509 object generation succeeded.\r | |
1635 | @retval FALSE The operation failed.\r | |
532616bb | 1636 | @retval FALSE This interface is not supported.\r |
b7d320f8 | 1637 | \r |
1638 | **/\r | |
1639 | BOOLEAN\r | |
1640 | EFIAPI\r | |
1641 | X509ConstructCertificate (\r | |
1642 | IN CONST UINT8 *Cert,\r | |
1643 | IN UINTN CertSize,\r | |
1644 | OUT UINT8 **SingleX509Cert\r | |
1645 | );\r | |
1646 | \r | |
66862136 MK |
1647 | /**\r |
1648 | Construct a X509 stack object from a list of DER-encoded certificate data.\r | |
1649 | \r | |
1650 | If X509Stack is NULL, then return FALSE.\r | |
1651 | If this interface is not supported, then return FALSE.\r | |
1652 | \r | |
1653 | @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r | |
1654 | On output, pointer to the X509 stack object with new\r | |
1655 | inserted X509 certificate.\r | |
1656 | @param[in] Args VA_LIST marker for the variable argument list.\r | |
1657 | A list of DER-encoded single certificate data followed\r | |
1658 | by certificate size. A NULL terminates the list. The\r | |
1659 | pairs are the arguments to X509ConstructCertificate().\r | |
1660 | \r | |
1661 | @retval TRUE The X509 stack construction succeeded.\r | |
1662 | @retval FALSE The construction operation failed.\r | |
1663 | @retval FALSE This interface is not supported.\r | |
1664 | \r | |
1665 | **/\r | |
1666 | BOOLEAN\r | |
1667 | EFIAPI\r | |
1668 | X509ConstructCertificateStackV (\r | |
1669 | IN OUT UINT8 **X509Stack,\r | |
1670 | IN VA_LIST Args\r | |
1671 | );\r | |
1672 | \r | |
b7d320f8 | 1673 | /**\r |
1674 | Construct a X509 stack object from a list of DER-encoded certificate data.\r | |
1675 | \r | |
16d2c32c | 1676 | If X509Stack is NULL, then return FALSE.\r |
532616bb | 1677 | If this interface is not supported, then return FALSE.\r |
b7d320f8 | 1678 | \r |
952bd229 | 1679 | @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r |
b7d320f8 | 1680 | On output, pointer to the X509 stack object with new\r |
1681 | inserted X509 certificate.\r | |
1682 | @param ... A list of DER-encoded single certificate data followed\r | |
1683 | by certificate size. A NULL terminates the list. The\r | |
1684 | pairs are the arguments to X509ConstructCertificate().\r | |
2ac68e8b | 1685 | \r |
b7d320f8 | 1686 | @retval TRUE The X509 stack construction succeeded.\r |
1687 | @retval FALSE The construction operation failed.\r | |
532616bb | 1688 | @retval FALSE This interface is not supported.\r |
b7d320f8 | 1689 | \r |
1690 | **/\r | |
1691 | BOOLEAN\r | |
1692 | EFIAPI\r | |
1693 | X509ConstructCertificateStack (\r | |
1694 | IN OUT UINT8 **X509Stack,\r | |
2ac68e8b | 1695 | ...\r |
b7d320f8 | 1696 | );\r |
1697 | \r | |
1698 | /**\r | |
1699 | Release the specified X509 object.\r | |
1700 | \r | |
532616bb | 1701 | If the interface is not supported, then ASSERT().\r |
b7d320f8 | 1702 | \r |
1703 | @param[in] X509Cert Pointer to the X509 object to be released.\r | |
1704 | \r | |
1705 | **/\r | |
1706 | VOID\r | |
1707 | EFIAPI\r | |
1708 | X509Free (\r | |
1709 | IN VOID *X509Cert\r | |
1710 | );\r | |
1711 | \r | |
1712 | /**\r | |
1713 | Release the specified X509 stack object.\r | |
1714 | \r | |
532616bb | 1715 | If the interface is not supported, then ASSERT().\r |
b7d320f8 | 1716 | \r |
1717 | @param[in] X509Stack Pointer to the X509 stack object to be released.\r | |
1718 | \r | |
1719 | **/\r | |
1720 | VOID\r | |
1721 | EFIAPI\r | |
1722 | X509StackFree (\r | |
1723 | IN VOID *X509Stack\r | |
1724 | );\r | |
1725 | \r | |
12d95665 LQ |
1726 | /**\r |
1727 | Retrieve the TBSCertificate from one given X.509 certificate.\r | |
1728 | \r | |
1729 | @param[in] Cert Pointer to the given DER-encoded X509 certificate.\r | |
1730 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
1731 | @param[out] TBSCert DER-Encoded To-Be-Signed certificate.\r | |
1732 | @param[out] TBSCertSize Size of the TBS certificate in bytes.\r | |
1733 | \r | |
1734 | If Cert is NULL, then return FALSE.\r | |
1735 | If TBSCert is NULL, then return FALSE.\r | |
1736 | If TBSCertSize is NULL, then return FALSE.\r | |
1737 | If this interface is not supported, then return FALSE.\r | |
1738 | \r | |
1739 | @retval TRUE The TBSCertificate was retrieved successfully.\r | |
1740 | @retval FALSE Invalid X.509 certificate.\r | |
1741 | \r | |
1742 | **/\r | |
1743 | BOOLEAN\r | |
1744 | EFIAPI\r | |
1745 | X509GetTBSCert (\r | |
1746 | IN CONST UINT8 *Cert,\r | |
1747 | IN UINTN CertSize,\r | |
1748 | OUT UINT8 **TBSCert,\r | |
1749 | OUT UINTN *TBSCertSize\r | |
1750 | );\r | |
1751 | \r | |
a8f37449 QL |
1752 | /**\r |
1753 | Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0\r | |
1754 | password based encryption key derivation function PBKDF2, as specified in RFC 2898.\r | |
1755 | \r | |
1756 | If Password or Salt or OutKey is NULL, then return FALSE.\r | |
1757 | If the hash algorithm could not be determined, then return FALSE.\r | |
1758 | If this interface is not supported, then return FALSE.\r | |
1759 | \r | |
1760 | @param[in] PasswordLength Length of input password in bytes.\r | |
1761 | @param[in] Password Pointer to the array for the password.\r | |
1762 | @param[in] SaltLength Size of the Salt in bytes.\r | |
1763 | @param[in] Salt Pointer to the Salt.\r | |
1764 | @param[in] IterationCount Number of iterations to perform. Its value should be\r | |
1765 | greater than or equal to 1.\r | |
1766 | @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).\r | |
1767 | NOTE: DigestSize will be used to determine the hash algorithm.\r | |
1768 | Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.\r | |
1769 | @param[in] KeyLength Size of the derived key buffer in bytes.\r | |
1770 | @param[out] OutKey Pointer to the output derived key buffer.\r | |
1771 | \r | |
1772 | @retval TRUE A key was derived successfully.\r | |
1773 | @retval FALSE One of the pointers was NULL or one of the sizes was too large.\r | |
1774 | @retval FALSE The hash algorithm could not be determined from the digest size.\r | |
1775 | @retval FALSE The key derivation operation failed.\r | |
1776 | @retval FALSE This interface is not supported.\r | |
1777 | \r | |
1778 | **/\r | |
1779 | BOOLEAN\r | |
1780 | EFIAPI\r | |
1781 | Pkcs5HashPassword (\r | |
1782 | IN UINTN PasswordLength,\r | |
1783 | IN CONST CHAR8 *Password,\r | |
1784 | IN UINTN SaltLength,\r | |
1785 | IN CONST UINT8 *Salt,\r | |
1786 | IN UINTN IterationCount,\r | |
1787 | IN UINTN DigestSize,\r | |
1788 | IN UINTN KeyLength,\r | |
1789 | OUT UINT8 *OutKey\r | |
1790 | );\r | |
1791 | \r | |
aed90bee BB |
1792 | /**\r |
1793 | Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the\r | |
1794 | encrypted message in a newly allocated buffer.\r | |
1795 | \r | |
1796 | Things that can cause a failure include:\r | |
1797 | - X509 key size does not match any known key size.\r | |
1798 | - Fail to parse X509 certificate.\r | |
1799 | - Fail to allocate an intermediate buffer.\r | |
1800 | - Null pointer provided for a non-optional parameter.\r | |
1801 | - Data size is too large for the provided key size (max size is a function of key size\r | |
1802 | and hash digest size).\r | |
1803 | \r | |
1804 | @param[in] PublicKey A pointer to the DER-encoded X509 certificate that\r | |
1805 | will be used to encrypt the data.\r | |
1806 | @param[in] PublicKeySize Size of the X509 cert buffer.\r | |
1807 | @param[in] InData Data to be encrypted.\r | |
1808 | @param[in] InDataSize Size of the data buffer.\r | |
1809 | @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer\r | |
1810 | to be used when initializing the PRNG. NULL otherwise.\r | |
1811 | @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.\r | |
1812 | 0 otherwise.\r | |
1813 | @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted\r | |
1814 | message.\r | |
1815 | @param[out] EncryptedDataSize Size of the encrypted message buffer.\r | |
1816 | \r | |
1817 | @retval TRUE Encryption was successful.\r | |
1818 | @retval FALSE Encryption failed.\r | |
1819 | \r | |
1820 | **/\r | |
1821 | BOOLEAN\r | |
1822 | EFIAPI\r | |
1823 | Pkcs1v2Encrypt (\r | |
1824 | IN CONST UINT8 *PublicKey,\r | |
1825 | IN UINTN PublicKeySize,\r | |
1826 | IN UINT8 *InData,\r | |
1827 | IN UINTN InDataSize,\r | |
c8f46130 MK |
1828 | IN CONST UINT8 *PrngSeed OPTIONAL,\r |
1829 | IN UINTN PrngSeedSize OPTIONAL,\r | |
aed90bee BB |
1830 | OUT UINT8 **EncryptedData,\r |
1831 | OUT UINTN *EncryptedDataSize\r | |
1832 | );\r | |
1833 | \r | |
3702637a | 1834 | /**\r |
1835 | The 3rd parameter of Pkcs7GetSigners will return all embedded\r | |
1836 | X.509 certificate in one given PKCS7 signature. The format is:\r | |
1837 | //\r | |
1838 | // UINT8 CertNumber;\r | |
1839 | // UINT32 Cert1Length;\r | |
1840 | // UINT8 Cert1[];\r | |
1841 | // UINT32 Cert2Length;\r | |
1842 | // UINT8 Cert2[];\r | |
1843 | // ...\r | |
1844 | // UINT32 CertnLength;\r | |
1845 | // UINT8 Certn[];\r | |
1846 | //\r | |
1847 | \r | |
1848 | The two following C-structure are used for parsing CertStack more clearly.\r | |
1849 | **/\r | |
1850 | #pragma pack(1)\r | |
1851 | \r | |
1852 | typedef struct {\r | |
1853 | UINT32 CertDataLength; // The length in bytes of X.509 certificate.\r | |
1854 | UINT8 CertDataBuffer[0]; // The X.509 certificate content (DER).\r | |
1855 | } EFI_CERT_DATA;\r | |
1856 | \r | |
1857 | typedef struct {\r | |
7c342378 MK |
1858 | UINT8 CertNumber; // Number of X.509 certificate.\r |
1859 | // EFI_CERT_DATA CertArray[]; // An array of X.509 certificate.\r | |
3702637a | 1860 | } EFI_CERT_STACK;\r |
1861 | \r | |
1862 | #pragma pack()\r | |
1863 | \r | |
e8b4eb04 | 1864 | /**\r |
1865 | Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:\r | |
1866 | Cryptographic Message Syntax Standard". The input signed data could be wrapped\r | |
1867 | in a ContentInfo structure.\r | |
1868 | \r | |
1869 | If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then\r | |
2998af86 | 1870 | return FALSE. If P7Length overflow, then return FALSE.\r |
532616bb | 1871 | If this interface is not supported, then return FALSE.\r |
e8b4eb04 | 1872 | \r |
1873 | @param[in] P7Data Pointer to the PKCS#7 message to verify.\r | |
1874 | @param[in] P7Length Length of the PKCS#7 message in bytes.\r | |
1875 | @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.\r | |
6fe575d0 LQ |
1876 | It's caller's responsibility to free the buffer with\r |
1877 | Pkcs7FreeSigners().\r | |
3702637a | 1878 | This data structure is EFI_CERT_STACK type.\r |
e8b4eb04 | 1879 | @param[out] StackLength Length of signer's certificates in bytes.\r |
1880 | @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.\r | |
6fe575d0 LQ |
1881 | It's caller's responsibility to free the buffer with\r |
1882 | Pkcs7FreeSigners().\r | |
e8b4eb04 | 1883 | @param[out] CertLength Length of the trusted certificate in bytes.\r |
1884 | \r | |
1885 | @retval TRUE The operation is finished successfully.\r | |
1886 | @retval FALSE Error occurs during the operation.\r | |
532616bb | 1887 | @retval FALSE This interface is not supported.\r |
e8b4eb04 | 1888 | \r |
1889 | **/\r | |
1890 | BOOLEAN\r | |
1891 | EFIAPI\r | |
1892 | Pkcs7GetSigners (\r | |
1893 | IN CONST UINT8 *P7Data,\r | |
1894 | IN UINTN P7Length,\r | |
1895 | OUT UINT8 **CertStack,\r | |
1896 | OUT UINTN *StackLength,\r | |
1897 | OUT UINT8 **TrustedCert,\r | |
1898 | OUT UINTN *CertLength\r | |
1899 | );\r | |
1900 | \r | |
1901 | /**\r | |
1902 | Wrap function to use free() to free allocated memory for certificates.\r | |
1903 | \r | |
532616bb | 1904 | If this interface is not supported, then ASSERT().\r |
1905 | \r | |
e8b4eb04 | 1906 | @param[in] Certs Pointer to the certificates to be freed.\r |
1907 | \r | |
1908 | **/\r | |
1909 | VOID\r | |
1910 | EFIAPI\r | |
1911 | Pkcs7FreeSigners (\r | |
7c342378 | 1912 | IN UINT8 *Certs\r |
45419de6 QL |
1913 | );\r |
1914 | \r | |
1915 | /**\r | |
1916 | Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:\r | |
1917 | Cryptographic Message Syntax Standard", and outputs two certificate lists chained and\r | |
1918 | unchained to the signer's certificates.\r | |
1919 | The input signed data could be wrapped in a ContentInfo structure.\r | |
1920 | \r | |
1921 | @param[in] P7Data Pointer to the PKCS#7 message.\r | |
1922 | @param[in] P7Length Length of the PKCS#7 message in bytes.\r | |
0f5f6b3d | 1923 | @param[out] SignerChainCerts Pointer to the certificates list chained to signer's\r |
6fe575d0 LQ |
1924 | certificate. It's caller's responsibility to free the buffer\r |
1925 | with Pkcs7FreeSigners().\r | |
3702637a | 1926 | This data structure is EFI_CERT_STACK type.\r |
45419de6 QL |
1927 | @param[out] ChainLength Length of the chained certificates list buffer in bytes.\r |
1928 | @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's\r | |
6fe575d0 | 1929 | responsibility to free the buffer with Pkcs7FreeSigners().\r |
3702637a | 1930 | This data structure is EFI_CERT_STACK type.\r |
45419de6 QL |
1931 | @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.\r |
1932 | \r | |
1933 | @retval TRUE The operation is finished successfully.\r | |
1934 | @retval FALSE Error occurs during the operation.\r | |
1935 | \r | |
1936 | **/\r | |
1937 | BOOLEAN\r | |
1938 | EFIAPI\r | |
1939 | Pkcs7GetCertificatesList (\r | |
1940 | IN CONST UINT8 *P7Data,\r | |
1941 | IN UINTN P7Length,\r | |
1942 | OUT UINT8 **SignerChainCerts,\r | |
1943 | OUT UINTN *ChainLength,\r | |
1944 | OUT UINT8 **UnchainCerts,\r | |
1945 | OUT UINTN *UnchainLength\r | |
e8b4eb04 | 1946 | );\r |
1947 | \r | |
b7d320f8 | 1948 | /**\r |
1949 | Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message\r | |
1950 | Syntax Standard, version 1.5". This interface is only intended to be used for\r | |
1951 | application to perform PKCS#7 functionality validation.\r | |
1952 | \r | |
532616bb | 1953 | If this interface is not supported, then return FALSE.\r |
1954 | \r | |
b7d320f8 | 1955 | @param[in] PrivateKey Pointer to the PEM-formatted private key data for\r |
1956 | data signing.\r | |
1957 | @param[in] PrivateKeySize Size of the PEM private key data in bytes.\r | |
1958 | @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM\r | |
1959 | key data.\r | |
1960 | @param[in] InData Pointer to the content to be signed.\r | |
1961 | @param[in] InDataSize Size of InData in bytes.\r | |
1962 | @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.\r | |
1963 | @param[in] OtherCerts Pointer to an optional additional set of certificates to\r | |
1964 | include in the PKCS#7 signedData (e.g. any intermediate\r | |
1965 | CAs in the chain).\r | |
6fe575d0 LQ |
1966 | @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's\r |
1967 | responsibility to free the buffer with FreePool().\r | |
b7d320f8 | 1968 | @param[out] SignedDataSize Size of SignedData in bytes.\r |
1969 | \r | |
1970 | @retval TRUE PKCS#7 data signing succeeded.\r | |
1971 | @retval FALSE PKCS#7 data signing failed.\r | |
532616bb | 1972 | @retval FALSE This interface is not supported.\r |
b7d320f8 | 1973 | \r |
1974 | **/\r | |
1975 | BOOLEAN\r | |
1976 | EFIAPI\r | |
1977 | Pkcs7Sign (\r | |
1978 | IN CONST UINT8 *PrivateKey,\r | |
1979 | IN UINTN PrivateKeySize,\r | |
1980 | IN CONST UINT8 *KeyPassword,\r | |
1981 | IN UINT8 *InData,\r | |
1982 | IN UINTN InDataSize,\r | |
1983 | IN UINT8 *SignCert,\r | |
1984 | IN UINT8 *OtherCerts OPTIONAL,\r | |
1985 | OUT UINT8 **SignedData,\r | |
1986 | OUT UINTN *SignedDataSize\r | |
1987 | );\r | |
1988 | \r | |
97f98500 | 1989 | /**\r |
2998af86 | 1990 | Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:\r |
e8b4eb04 | 1991 | Cryptographic Message Syntax Standard". The input signed data could be wrapped\r |
1992 | in a ContentInfo structure.\r | |
97f98500 | 1993 | \r |
e8b4eb04 | 1994 | If P7Data, TrustedCert or InData is NULL, then return FALSE.\r |
2998af86 | 1995 | If P7Length, CertLength or DataLength overflow, then return FALSE.\r |
532616bb | 1996 | If this interface is not supported, then return FALSE.\r |
97f98500 HT |
1997 | \r |
1998 | @param[in] P7Data Pointer to the PKCS#7 message to verify.\r | |
e8b4eb04 | 1999 | @param[in] P7Length Length of the PKCS#7 message in bytes.\r |
97f98500 HT |
2000 | @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r |
2001 | is used for certificate chain verification.\r | |
e8b4eb04 | 2002 | @param[in] CertLength Length of the trusted certificate in bytes.\r |
97f98500 | 2003 | @param[in] InData Pointer to the content to be verified.\r |
e8b4eb04 | 2004 | @param[in] DataLength Length of InData in bytes.\r |
97f98500 | 2005 | \r |
a8c44645 | 2006 | @retval TRUE The specified PKCS#7 signed data is valid.\r |
2007 | @retval FALSE Invalid PKCS#7 signed data.\r | |
532616bb | 2008 | @retval FALSE This interface is not supported.\r |
97f98500 HT |
2009 | \r |
2010 | **/\r | |
2011 | BOOLEAN\r | |
2012 | EFIAPI\r | |
2013 | Pkcs7Verify (\r | |
2014 | IN CONST UINT8 *P7Data,\r | |
e8b4eb04 | 2015 | IN UINTN P7Length,\r |
97f98500 | 2016 | IN CONST UINT8 *TrustedCert,\r |
e8b4eb04 | 2017 | IN UINTN CertLength,\r |
97f98500 | 2018 | IN CONST UINT8 *InData,\r |
e8b4eb04 | 2019 | IN UINTN DataLength\r |
a8c44645 | 2020 | );\r |
2021 | \r | |
1796a394 BB |
2022 | /**\r |
2023 | This function receives a PKCS7 formatted signature, and then verifies that\r | |
2024 | the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity\r | |
2025 | leaf signing certificate.\r | |
2026 | Note that this function does not validate the certificate chain.\r | |
2027 | \r | |
2028 | Applications for custom EKU's are quite flexible. For example, a policy EKU\r | |
2029 | may be present in an Issuing Certificate Authority (CA), and any sub-ordinate\r | |
2030 | certificate issued might also contain this EKU, thus constraining the\r | |
2031 | sub-ordinate certificate. Other applications might allow a certificate\r | |
2032 | embedded in a device to specify that other Object Identifiers (OIDs) are\r | |
2033 | present which contains binary data specifying custom capabilities that\r | |
2034 | the device is able to do.\r | |
2035 | \r | |
2036 | @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array\r | |
2037 | containing the content block with both the signature,\r | |
2038 | the signer's certificate, and any necessary intermediate\r | |
2039 | certificates.\r | |
2040 | @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.\r | |
2041 | @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of\r | |
2042 | required EKUs that must be present in the signature.\r | |
2043 | @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.\r | |
2044 | @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's\r | |
2045 | must be present in the leaf signer. If it is\r | |
2046 | FALSE, then we will succeed if we find any\r | |
2047 | of the specified EKU's.\r | |
2048 | \r | |
2049 | @retval EFI_SUCCESS The required EKUs were found in the signature.\r | |
2050 | @retval EFI_INVALID_PARAMETER A parameter was invalid.\r | |
2051 | @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.\r | |
2052 | \r | |
2053 | **/\r | |
2054 | RETURN_STATUS\r | |
2055 | EFIAPI\r | |
2056 | VerifyEKUsInPkcs7Signature (\r | |
2057 | IN CONST UINT8 *Pkcs7Signature,\r | |
2058 | IN CONST UINT32 SignatureSize,\r | |
2059 | IN CONST CHAR8 *RequiredEKUs[],\r | |
2060 | IN CONST UINT32 RequiredEKUsSize,\r | |
2061 | IN BOOLEAN RequireAllPresent\r | |
2062 | );\r | |
2063 | \r | |
afeb55e4 QL |
2064 | /**\r |
2065 | Extracts the attached content from a PKCS#7 signed data if existed. The input signed\r | |
2066 | data could be wrapped in a ContentInfo structure.\r | |
2067 | \r | |
2068 | If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,\r | |
2998af86 | 2069 | then return FALSE. If the P7Data is not correctly formatted, then return FALSE.\r |
afeb55e4 QL |
2070 | \r |
2071 | Caution: This function may receive untrusted input. So this function will do\r | |
2072 | basic check for PKCS#7 data structure.\r | |
2073 | \r | |
2074 | @param[in] P7Data Pointer to the PKCS#7 signed data to process.\r | |
2075 | @param[in] P7Length Length of the PKCS#7 signed data in bytes.\r | |
2076 | @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.\r | |
6fe575d0 | 2077 | It's caller's responsibility to free the buffer with FreePool().\r |
afeb55e4 QL |
2078 | @param[out] ContentSize The size of the extracted content in bytes.\r |
2079 | \r | |
2080 | @retval TRUE The P7Data was correctly formatted for processing.\r | |
2081 | @retval FALSE The P7Data was not correctly formatted for processing.\r | |
2082 | \r | |
0c9fc4b1 | 2083 | **/\r |
afeb55e4 QL |
2084 | BOOLEAN\r |
2085 | EFIAPI\r | |
2086 | Pkcs7GetAttachedContent (\r | |
2087 | IN CONST UINT8 *P7Data,\r | |
2088 | IN UINTN P7Length,\r | |
2089 | OUT VOID **Content,\r | |
2090 | OUT UINTN *ContentSize\r | |
2091 | );\r | |
2092 | \r | |
b7d320f8 | 2093 | /**\r |
2998af86 | 2094 | Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows\r |
b7d320f8 | 2095 | Authenticode Portable Executable Signature Format".\r |
2096 | \r | |
16d2c32c | 2097 | If AuthData is NULL, then return FALSE.\r |
2098 | If ImageHash is NULL, then return FALSE.\r | |
532616bb | 2099 | If this interface is not supported, then return FALSE.\r |
b7d320f8 | 2100 | \r |
2101 | @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r | |
2102 | PE/COFF image to be verified.\r | |
2103 | @param[in] DataSize Size of the Authenticode Signature in bytes.\r | |
2104 | @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r | |
2105 | is used for certificate chain verification.\r | |
2106 | @param[in] CertSize Size of the trusted certificate in bytes.\r | |
2998af86 | 2107 | @param[in] ImageHash Pointer to the original image file hash value. The procedure\r |
b7d320f8 | 2108 | for calculating the image hash value is described in Authenticode\r |
2109 | specification.\r | |
2110 | @param[in] HashSize Size of Image hash value in bytes.\r | |
2111 | \r | |
2112 | @retval TRUE The specified Authenticode Signature is valid.\r | |
2113 | @retval FALSE Invalid Authenticode Signature.\r | |
532616bb | 2114 | @retval FALSE This interface is not supported.\r |
b7d320f8 | 2115 | \r |
2116 | **/\r | |
2117 | BOOLEAN\r | |
2118 | EFIAPI\r | |
2119 | AuthenticodeVerify (\r | |
2120 | IN CONST UINT8 *AuthData,\r | |
2121 | IN UINTN DataSize,\r | |
2122 | IN CONST UINT8 *TrustedCert,\r | |
2123 | IN UINTN CertSize,\r | |
2124 | IN CONST UINT8 *ImageHash,\r | |
2125 | IN UINTN HashSize\r | |
2126 | );\r | |
2127 | \r | |
2ac68e8b | 2128 | /**\r |
2998af86 | 2129 | Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode\r |
2ac68e8b QL |
2130 | signature.\r |
2131 | \r | |
2132 | If AuthData is NULL, then return FALSE.\r | |
12d95665 | 2133 | If this interface is not supported, then return FALSE.\r |
2ac68e8b QL |
2134 | \r |
2135 | @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r | |
2136 | PE/COFF image to be verified.\r | |
2137 | @param[in] DataSize Size of the Authenticode Signature in bytes.\r | |
2138 | @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which\r | |
2139 | is used for TSA certificate chain verification.\r | |
2140 | @param[in] CertSize Size of the trusted certificate in bytes.\r | |
2141 | @param[out] SigningTime Return the time of timestamp generation time if the timestamp\r | |
2142 | signature is valid.\r | |
2143 | \r | |
2144 | @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.\r | |
2145 | @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.\r | |
2146 | \r | |
2147 | **/\r | |
2148 | BOOLEAN\r | |
2149 | EFIAPI\r | |
2150 | ImageTimestampVerify (\r | |
2151 | IN CONST UINT8 *AuthData,\r | |
2152 | IN UINTN DataSize,\r | |
2153 | IN CONST UINT8 *TsaCert,\r | |
2154 | IN UINTN CertSize,\r | |
2155 | OUT EFI_TIME *SigningTime\r | |
2156 | );\r | |
2157 | \r | |
7c342378 | 2158 | // =====================================================================================\r |
a8c44645 | 2159 | // DH Key Exchange Primitive\r |
7c342378 | 2160 | // =====================================================================================\r |
a8c44645 | 2161 | \r |
2162 | /**\r | |
2163 | Allocates and Initializes one Diffie-Hellman Context for subsequent use.\r | |
2164 | \r | |
2165 | @return Pointer to the Diffie-Hellman Context that has been initialized.\r | |
2166 | If the allocations fails, DhNew() returns NULL.\r | |
532616bb | 2167 | If the interface is not supported, DhNew() returns NULL.\r |
a8c44645 | 2168 | \r |
2169 | **/\r | |
2170 | VOID *\r | |
2171 | EFIAPI\r | |
2172 | DhNew (\r | |
2173 | VOID\r | |
2174 | );\r | |
2175 | \r | |
2176 | /**\r | |
2177 | Release the specified DH context.\r | |
2178 | \r | |
532616bb | 2179 | If the interface is not supported, then ASSERT().\r |
a8c44645 | 2180 | \r |
2181 | @param[in] DhContext Pointer to the DH context to be released.\r | |
2182 | \r | |
2183 | **/\r | |
2184 | VOID\r | |
2185 | EFIAPI\r | |
2186 | DhFree (\r | |
2187 | IN VOID *DhContext\r | |
2188 | );\r | |
2189 | \r | |
2190 | /**\r | |
2191 | Generates DH parameter.\r | |
2192 | \r | |
2193 | Given generator g, and length of prime number p in bits, this function generates p,\r | |
2194 | and sets DH context according to value of g and p.\r | |
2ac68e8b | 2195 | \r |
a8c44645 | 2196 | Before this function can be invoked, pseudorandom number generator must be correctly\r |
2197 | initialized by RandomSeed().\r | |
2198 | \r | |
16d2c32c | 2199 | If DhContext is NULL, then return FALSE.\r |
2200 | If Prime is NULL, then return FALSE.\r | |
532616bb | 2201 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 2202 | \r |
2203 | @param[in, out] DhContext Pointer to the DH context.\r | |
2204 | @param[in] Generator Value of generator.\r | |
2205 | @param[in] PrimeLength Length in bits of prime to be generated.\r | |
2206 | @param[out] Prime Pointer to the buffer to receive the generated prime number.\r | |
2207 | \r | |
2998af86 | 2208 | @retval TRUE DH parameter generation succeeded.\r |
a8c44645 | 2209 | @retval FALSE Value of Generator is not supported.\r |
2210 | @retval FALSE PRNG fails to generate random prime number with PrimeLength.\r | |
532616bb | 2211 | @retval FALSE This interface is not supported.\r |
a8c44645 | 2212 | \r |
2213 | **/\r | |
2214 | BOOLEAN\r | |
2215 | EFIAPI\r | |
2216 | DhGenerateParameter (\r | |
2217 | IN OUT VOID *DhContext,\r | |
2218 | IN UINTN Generator,\r | |
2219 | IN UINTN PrimeLength,\r | |
2220 | OUT UINT8 *Prime\r | |
2221 | );\r | |
2222 | \r | |
2223 | /**\r | |
2224 | Sets generator and prime parameters for DH.\r | |
2225 | \r | |
2226 | Given generator g, and prime number p, this function and sets DH\r | |
2227 | context accordingly.\r | |
2228 | \r | |
16d2c32c | 2229 | If DhContext is NULL, then return FALSE.\r |
2230 | If Prime is NULL, then return FALSE.\r | |
532616bb | 2231 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 2232 | \r |
2233 | @param[in, out] DhContext Pointer to the DH context.\r | |
2234 | @param[in] Generator Value of generator.\r | |
2235 | @param[in] PrimeLength Length in bits of prime to be generated.\r | |
2236 | @param[in] Prime Pointer to the prime number.\r | |
2237 | \r | |
2998af86 | 2238 | @retval TRUE DH parameter setting succeeded.\r |
a8c44645 | 2239 | @retval FALSE Value of Generator is not supported.\r |
2240 | @retval FALSE Value of Generator is not suitable for the Prime.\r | |
2241 | @retval FALSE Value of Prime is not a prime number.\r | |
2242 | @retval FALSE Value of Prime is not a safe prime number.\r | |
532616bb | 2243 | @retval FALSE This interface is not supported.\r |
a8c44645 | 2244 | \r |
2245 | **/\r | |
2246 | BOOLEAN\r | |
2247 | EFIAPI\r | |
2248 | DhSetParameter (\r | |
2249 | IN OUT VOID *DhContext,\r | |
2250 | IN UINTN Generator,\r | |
2251 | IN UINTN PrimeLength,\r | |
2252 | IN CONST UINT8 *Prime\r | |
97f98500 HT |
2253 | );\r |
2254 | \r | |
a8c44645 | 2255 | /**\r |
2256 | Generates DH public key.\r | |
2257 | \r | |
2ac68e8b | 2258 | This function generates random secret exponent, and computes the public key, which is\r |
a8c44645 | 2259 | returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.\r |
2260 | If the PublicKey buffer is too small to hold the public key, FALSE is returned and\r | |
2261 | PublicKeySize is set to the required buffer size to obtain the public key.\r | |
2262 | \r | |
16d2c32c | 2263 | If DhContext is NULL, then return FALSE.\r |
2264 | If PublicKeySize is NULL, then return FALSE.\r | |
2265 | If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.\r | |
532616bb | 2266 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 2267 | \r |
2268 | @param[in, out] DhContext Pointer to the DH context.\r | |
2269 | @param[out] PublicKey Pointer to the buffer to receive generated public key.\r | |
2270 | @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.\r | |
2271 | On output, the size of data returned in PublicKey buffer in bytes.\r | |
2272 | \r | |
2273 | @retval TRUE DH public key generation succeeded.\r | |
2274 | @retval FALSE DH public key generation failed.\r | |
2275 | @retval FALSE PublicKeySize is not large enough.\r | |
532616bb | 2276 | @retval FALSE This interface is not supported.\r |
a8c44645 | 2277 | \r |
2278 | **/\r | |
2279 | BOOLEAN\r | |
2280 | EFIAPI\r | |
2281 | DhGenerateKey (\r | |
2282 | IN OUT VOID *DhContext,\r | |
2283 | OUT UINT8 *PublicKey,\r | |
2284 | IN OUT UINTN *PublicKeySize\r | |
2285 | );\r | |
2286 | \r | |
2287 | /**\r | |
2288 | Computes exchanged common key.\r | |
2289 | \r | |
2290 | Given peer's public key, this function computes the exchanged common key, based on its own\r | |
dda39f3a | 2291 | context including value of prime modulus and random secret exponent.\r |
a8c44645 | 2292 | \r |
16d2c32c | 2293 | If DhContext is NULL, then return FALSE.\r |
2294 | If PeerPublicKey is NULL, then return FALSE.\r | |
2295 | If KeySize is NULL, then return FALSE.\r | |
dda39f3a | 2296 | If Key is NULL, then return FALSE.\r |
2297 | If KeySize is not large enough, then return FALSE.\r | |
532616bb | 2298 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 2299 | \r |
2300 | @param[in, out] DhContext Pointer to the DH context.\r | |
2301 | @param[in] PeerPublicKey Pointer to the peer's public key.\r | |
2302 | @param[in] PeerPublicKeySize Size of peer's public key in bytes.\r | |
2303 | @param[out] Key Pointer to the buffer to receive generated key.\r | |
2304 | @param[in, out] KeySize On input, the size of Key buffer in bytes.\r | |
2305 | On output, the size of data returned in Key buffer in bytes.\r | |
2306 | \r | |
2307 | @retval TRUE DH exchanged key generation succeeded.\r | |
2308 | @retval FALSE DH exchanged key generation failed.\r | |
2309 | @retval FALSE KeySize is not large enough.\r | |
532616bb | 2310 | @retval FALSE This interface is not supported.\r |
a8c44645 | 2311 | \r |
2312 | **/\r | |
2313 | BOOLEAN\r | |
2314 | EFIAPI\r | |
2315 | DhComputeKey (\r | |
2316 | IN OUT VOID *DhContext,\r | |
2317 | IN CONST UINT8 *PeerPublicKey,\r | |
2318 | IN UINTN PeerPublicKeySize,\r | |
2319 | OUT UINT8 *Key,\r | |
2320 | IN OUT UINTN *KeySize\r | |
2321 | );\r | |
2322 | \r | |
7c342378 | 2323 | // =====================================================================================\r |
a8c44645 | 2324 | // Pseudo-Random Generation Primitive\r |
7c342378 | 2325 | // =====================================================================================\r |
a8c44645 | 2326 | \r |
2327 | /**\r | |
2328 | Sets up the seed value for the pseudorandom number generator.\r | |
2329 | \r | |
2330 | This function sets up the seed value for the pseudorandom number generator.\r | |
2331 | If Seed is not NULL, then the seed passed in is used.\r | |
2332 | If Seed is NULL, then default seed is used.\r | |
532616bb | 2333 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 2334 | \r |
2335 | @param[in] Seed Pointer to seed value.\r | |
2336 | If NULL, default seed is used.\r | |
2337 | @param[in] SeedSize Size of seed value.\r | |
2338 | If Seed is NULL, this parameter is ignored.\r | |
2339 | \r | |
2340 | @retval TRUE Pseudorandom number generator has enough entropy for random generation.\r | |
2341 | @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.\r | |
532616bb | 2342 | @retval FALSE This interface is not supported.\r |
a8c44645 | 2343 | \r |
2344 | **/\r | |
2345 | BOOLEAN\r | |
2346 | EFIAPI\r | |
2347 | RandomSeed (\r | |
2348 | IN CONST UINT8 *Seed OPTIONAL,\r | |
2349 | IN UINTN SeedSize\r | |
2350 | );\r | |
2351 | \r | |
2352 | /**\r | |
2353 | Generates a pseudorandom byte stream of the specified size.\r | |
2354 | \r | |
16d2c32c | 2355 | If Output is NULL, then return FALSE.\r |
532616bb | 2356 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 2357 | \r |
2358 | @param[out] Output Pointer to buffer to receive random value.\r | |
2998af86 | 2359 | @param[in] Size Size of random bytes to generate.\r |
a8c44645 | 2360 | \r |
2361 | @retval TRUE Pseudorandom byte stream generated successfully.\r | |
2362 | @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.\r | |
532616bb | 2363 | @retval FALSE This interface is not supported.\r |
a8c44645 | 2364 | \r |
2365 | **/\r | |
2366 | BOOLEAN\r | |
2367 | EFIAPI\r | |
2368 | RandomBytes (\r | |
2369 | OUT UINT8 *Output,\r | |
2370 | IN UINTN Size\r | |
2371 | );\r | |
97f98500 | 2372 | \r |
7c342378 | 2373 | // =====================================================================================\r |
4b1b7c19 | 2374 | // Key Derivation Function Primitive\r |
7c342378 | 2375 | // =====================================================================================\r |
4b1b7c19 GW |
2376 | \r |
2377 | /**\r | |
2378 | Derive key data using HMAC-SHA256 based KDF.\r | |
2379 | \r | |
2380 | @param[in] Key Pointer to the user-supplied key.\r | |
2381 | @param[in] KeySize Key size in bytes.\r | |
2382 | @param[in] Salt Pointer to the salt(non-secret) value.\r | |
2383 | @param[in] SaltSize Salt size in bytes.\r | |
2384 | @param[in] Info Pointer to the application specific info.\r | |
2385 | @param[in] InfoSize Info size in bytes.\r | |
944bd5cf | 2386 | @param[out] Out Pointer to buffer to receive hkdf value.\r |
4b1b7c19 GW |
2387 | @param[in] OutSize Size of hkdf bytes to generate.\r |
2388 | \r | |
2389 | @retval TRUE Hkdf generated successfully.\r | |
2390 | @retval FALSE Hkdf generation failed.\r | |
2391 | \r | |
2392 | **/\r | |
2393 | BOOLEAN\r | |
2394 | EFIAPI\r | |
2395 | HkdfSha256ExtractAndExpand (\r | |
2396 | IN CONST UINT8 *Key,\r | |
2397 | IN UINTN KeySize,\r | |
2398 | IN CONST UINT8 *Salt,\r | |
2399 | IN UINTN SaltSize,\r | |
2400 | IN CONST UINT8 *Info,\r | |
2401 | IN UINTN InfoSize,\r | |
2402 | OUT UINT8 *Out,\r | |
2403 | IN UINTN OutSize\r | |
2404 | );\r | |
2405 | \r | |
afeb55e4 | 2406 | #endif // __BASE_CRYPT_LIB_H__\r |