]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Include/Library/BaseCryptLib.h
OvmfPkg/VirtioNetDxe: Check ChildHandle argument in GetControllerName
[mirror_edk2.git] / CryptoPkg / Include / Library / BaseCryptLib.h
CommitLineData
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
c1e66210 7Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.<BR>\r
2009f6b4 8SPDX-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
988e4d8f
YL
17#define CRYPTO_NID_NULL 0x0000\r
18\r
19// Key Exchange\r
20#define CRYPTO_NID_SECP256R1 0x0204\r
21#define CRYPTO_NID_SECP384R1 0x0205\r
22#define CRYPTO_NID_SECP521R1 0x0206\r
23\r
97f98500
HT
24///\r
25/// MD5 digest size in bytes\r
26///\r
7c342378 27#define MD5_DIGEST_SIZE 16\r
97f98500
HT
28\r
29///\r
30/// SHA-1 digest size in bytes.\r
31///\r
7c342378 32#define SHA1_DIGEST_SIZE 20\r
97f98500
HT
33\r
34///\r
35/// SHA-256 digest size in bytes\r
36///\r
37#define SHA256_DIGEST_SIZE 32\r
38\r
2ac68e8b
QL
39///\r
40/// SHA-384 digest size in bytes\r
41///\r
42#define SHA384_DIGEST_SIZE 48\r
43\r
44///\r
45/// SHA-512 digest size in bytes\r
46///\r
47#define SHA512_DIGEST_SIZE 64\r
48\r
f0718d1d
LX
49///\r
50/// SM3 digest size in bytes\r
51///\r
7c342378 52#define SM3_256_DIGEST_SIZE 32\r
f0718d1d 53\r
a8c44645 54///\r
55/// TDES block size in bytes\r
56///\r
7c342378 57#define TDES_BLOCK_SIZE 8\r
a8c44645 58\r
59///\r
60/// AES block size in bytes\r
61///\r
7c342378 62#define AES_BLOCK_SIZE 16\r
a8c44645 63\r
97f98500
HT
64///\r
65/// RSA Key Tags Definition used in RsaSetKey() function for key component identification.\r
66///\r
67typedef enum {\r
68 RsaKeyN, ///< RSA public Modulus (N)\r
69 RsaKeyE, ///< RSA Public exponent (e)\r
70 RsaKeyD, ///< RSA Private exponent (d)\r
71 RsaKeyP, ///< RSA secret prime factor of Modulus (p)\r
72 RsaKeyQ, ///< RSA secret prime factor of Modules (q)\r
73 RsaKeyDp, ///< p's CRT exponent (== d mod (p - 1))\r
74 RsaKeyDq, ///< q's CRT exponent (== d mod (q - 1))\r
75 RsaKeyQInv ///< The CRT coefficient (== 1/q mod p)\r
76} RSA_KEY_TAG;\r
77\r
7c342378 78// =====================================================================================\r
97f98500 79// One-Way Cryptographic Hash Primitives\r
7c342378 80// =====================================================================================\r
97f98500 81\r
e6a12a0f 82#ifdef ENABLE_MD5_DEPRECATED_INTERFACES\r
7c342378 83\r
97f98500
HT
84/**\r
85 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r
86\r
532616bb 87 If this interface is not supported, then return zero.\r
88\r
97f98500 89 @return The size, in bytes, of the context buffer required for MD5 hash operations.\r
532616bb 90 @retval 0 This interface is not supported.\r
97f98500
HT
91\r
92**/\r
93UINTN\r
94EFIAPI\r
95Md5GetContextSize (\r
96 VOID\r
97 );\r
98\r
97f98500
HT
99/**\r
100 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for\r
101 subsequent use.\r
102\r
16d2c32c 103 If Md5Context is NULL, then return FALSE.\r
532616bb 104 If this interface is not supported, then return FALSE.\r
97f98500 105\r
a8c44645 106 @param[out] Md5Context Pointer to MD5 context being initialized.\r
97f98500
HT
107\r
108 @retval TRUE MD5 context initialization succeeded.\r
109 @retval FALSE MD5 context initialization failed.\r
532616bb 110 @retval FALSE This interface is not supported.\r
97f98500
HT
111\r
112**/\r
113BOOLEAN\r
114EFIAPI\r
115Md5Init (\r
a8c44645 116 OUT VOID *Md5Context\r
97f98500
HT
117 );\r
118\r
a8c44645 119/**\r
120 Makes a copy of an existing MD5 context.\r
121\r
16d2c32c 122 If Md5Context is NULL, then return FALSE.\r
123 If NewMd5Context is NULL, then return FALSE.\r
532616bb 124 If this interface is not supported, then return FALSE.\r
a8c44645 125\r
126 @param[in] Md5Context Pointer to MD5 context being copied.\r
127 @param[out] NewMd5Context Pointer to new MD5 context.\r
128\r
129 @retval TRUE MD5 context copy succeeded.\r
130 @retval FALSE MD5 context copy failed.\r
532616bb 131 @retval FALSE This interface is not supported.\r
a8c44645 132\r
133**/\r
134BOOLEAN\r
135EFIAPI\r
136Md5Duplicate (\r
137 IN CONST VOID *Md5Context,\r
138 OUT VOID *NewMd5Context\r
139 );\r
97f98500
HT
140\r
141/**\r
a8c44645 142 Digests the input data and updates MD5 context.\r
143\r
144 This function performs MD5 digest on a data buffer of the specified size.\r
145 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
2998af86 146 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized\r
a8c44645 147 by Md5Final(). Behavior with invalid context is undefined.\r
97f98500 148\r
16d2c32c 149 If Md5Context is NULL, then return FALSE.\r
532616bb 150 If this interface is not supported, then return FALSE.\r
97f98500
HT
151\r
152 @param[in, out] Md5Context Pointer to the MD5 context.\r
153 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
a8c44645 154 @param[in] DataSize Size of Data buffer in bytes.\r
97f98500
HT
155\r
156 @retval TRUE MD5 data digest succeeded.\r
a8c44645 157 @retval FALSE MD5 data digest failed.\r
532616bb 158 @retval FALSE This interface is not supported.\r
97f98500
HT
159\r
160**/\r
161BOOLEAN\r
162EFIAPI\r
163Md5Update (\r
164 IN OUT VOID *Md5Context,\r
165 IN CONST VOID *Data,\r
a8c44645 166 IN UINTN DataSize\r
97f98500
HT
167 );\r
168\r
97f98500 169/**\r
a8c44645 170 Completes computation of the MD5 digest value.\r
171\r
172 This function completes MD5 hash computation and retrieves the digest value into\r
173 the specified memory. After this function has been called, the MD5 context cannot\r
174 be used again.\r
2998af86 175 MD5 context should be already correctly initialized by Md5Init(), and should not be\r
a8c44645 176 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.\r
97f98500 177\r
16d2c32c 178 If Md5Context is NULL, then return FALSE.\r
179 If HashValue is NULL, then return FALSE.\r
532616bb 180 If this interface is not supported, then return FALSE.\r
97f98500 181\r
a8c44645 182 @param[in, out] Md5Context Pointer to the MD5 context.\r
97f98500
HT
183 @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r
184 value (16 bytes).\r
185\r
186 @retval TRUE MD5 digest computation succeeded.\r
187 @retval FALSE MD5 digest computation failed.\r
532616bb 188 @retval FALSE This interface is not supported.\r
97f98500
HT
189\r
190**/\r
191BOOLEAN\r
192EFIAPI\r
193Md5Final (\r
194 IN OUT VOID *Md5Context,\r
195 OUT UINT8 *HashValue\r
196 );\r
197\r
b7d1ba0a
QL
198/**\r
199 Computes the MD5 message digest of a input data buffer.\r
200\r
201 This function performs the MD5 message digest of a given data buffer, and places\r
202 the digest value into the specified memory.\r
203\r
204 If this interface is not supported, then return FALSE.\r
205\r
206 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
207 @param[in] DataSize Size of Data buffer in bytes.\r
208 @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r
209 value (16 bytes).\r
210\r
211 @retval TRUE MD5 digest computation succeeded.\r
212 @retval FALSE MD5 digest computation failed.\r
213 @retval FALSE This interface is not supported.\r
214\r
215**/\r
216BOOLEAN\r
217EFIAPI\r
218Md5HashAll (\r
219 IN CONST VOID *Data,\r
220 IN UINTN DataSize,\r
221 OUT UINT8 *HashValue\r
222 );\r
7c342378 223\r
acfd5557 224#endif\r
b7d1ba0a 225\r
0f01cec5 226#ifndef DISABLE_SHA1_DEPRECATED_INTERFACES\r
7c342378 227\r
97f98500
HT
228/**\r
229 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.\r
230\r
532616bb 231 If this interface is not supported, then return zero.\r
232\r
97f98500 233 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.\r
532616bb 234 @retval 0 This interface is not supported.\r
97f98500
HT
235\r
236**/\r
237UINTN\r
238EFIAPI\r
239Sha1GetContextSize (\r
240 VOID\r
241 );\r
242\r
97f98500 243/**\r
a8c44645 244 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for\r
97f98500
HT
245 subsequent use.\r
246\r
16d2c32c 247 If Sha1Context is NULL, then return FALSE.\r
532616bb 248 If this interface is not supported, then return FALSE.\r
97f98500 249\r
a8c44645 250 @param[out] Sha1Context Pointer to SHA-1 context being initialized.\r
97f98500 251\r
a8c44645 252 @retval TRUE SHA-1 context initialization succeeded.\r
253 @retval FALSE SHA-1 context initialization failed.\r
532616bb 254 @retval FALSE This interface is not supported.\r
97f98500
HT
255\r
256**/\r
257BOOLEAN\r
258EFIAPI\r
259Sha1Init (\r
a8c44645 260 OUT VOID *Sha1Context\r
97f98500
HT
261 );\r
262\r
a8c44645 263/**\r
264 Makes a copy of an existing SHA-1 context.\r
265\r
16d2c32c 266 If Sha1Context is NULL, then return FALSE.\r
267 If NewSha1Context is NULL, then return FALSE.\r
532616bb 268 If this interface is not supported, then return FALSE.\r
a8c44645 269\r
270 @param[in] Sha1Context Pointer to SHA-1 context being copied.\r
271 @param[out] NewSha1Context Pointer to new SHA-1 context.\r
272\r
273 @retval TRUE SHA-1 context copy succeeded.\r
274 @retval FALSE SHA-1 context copy failed.\r
532616bb 275 @retval FALSE This interface is not supported.\r
a8c44645 276\r
277**/\r
278BOOLEAN\r
279EFIAPI\r
280Sha1Duplicate (\r
281 IN CONST VOID *Sha1Context,\r
282 OUT VOID *NewSha1Context\r
283 );\r
97f98500
HT
284\r
285/**\r
a8c44645 286 Digests the input data and updates SHA-1 context.\r
287\r
288 This function performs SHA-1 digest on a data buffer of the specified size.\r
289 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
2998af86 290 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized\r
a8c44645 291 by Sha1Final(). Behavior with invalid context is undefined.\r
97f98500 292\r
16d2c32c 293 If Sha1Context is NULL, then return FALSE.\r
532616bb 294 If this interface is not supported, then return FALSE.\r
97f98500
HT
295\r
296 @param[in, out] Sha1Context Pointer to the SHA-1 context.\r
297 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
a8c44645 298 @param[in] DataSize Size of Data buffer in bytes.\r
97f98500
HT
299\r
300 @retval TRUE SHA-1 data digest succeeded.\r
a8c44645 301 @retval FALSE SHA-1 data digest failed.\r
532616bb 302 @retval FALSE This interface is not supported.\r
97f98500
HT
303\r
304**/\r
305BOOLEAN\r
306EFIAPI\r
307Sha1Update (\r
308 IN OUT VOID *Sha1Context,\r
309 IN CONST VOID *Data,\r
a8c44645 310 IN UINTN DataSize\r
97f98500
HT
311 );\r
312\r
97f98500 313/**\r
a8c44645 314 Completes computation of the SHA-1 digest value.\r
315\r
316 This function completes SHA-1 hash computation and retrieves the digest value into\r
317 the specified memory. After this function has been called, the SHA-1 context cannot\r
318 be used again.\r
2998af86 319 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be\r
a8c44645 320 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.\r
97f98500 321\r
16d2c32c 322 If Sha1Context is NULL, then return FALSE.\r
323 If HashValue is NULL, then return FALSE.\r
532616bb 324 If this interface is not supported, then return FALSE.\r
97f98500 325\r
a8c44645 326 @param[in, out] Sha1Context Pointer to the SHA-1 context.\r
97f98500
HT
327 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r
328 value (20 bytes).\r
329\r
330 @retval TRUE SHA-1 digest computation succeeded.\r
331 @retval FALSE SHA-1 digest computation failed.\r
532616bb 332 @retval FALSE This interface is not supported.\r
97f98500
HT
333\r
334**/\r
335BOOLEAN\r
336EFIAPI\r
337Sha1Final (\r
338 IN OUT VOID *Sha1Context,\r
339 OUT UINT8 *HashValue\r
340 );\r
341\r
b7d1ba0a
QL
342/**\r
343 Computes the SHA-1 message digest of a input data buffer.\r
344\r
345 This function performs the SHA-1 message digest of a given data buffer, and places\r
346 the digest value into the specified memory.\r
347\r
348 If this interface is not supported, then return FALSE.\r
349\r
350 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
351 @param[in] DataSize Size of Data buffer in bytes.\r
352 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r
353 value (20 bytes).\r
354\r
355 @retval TRUE SHA-1 digest computation succeeded.\r
356 @retval FALSE SHA-1 digest computation failed.\r
357 @retval FALSE This interface is not supported.\r
358\r
359**/\r
360BOOLEAN\r
361EFIAPI\r
362Sha1HashAll (\r
363 IN CONST VOID *Data,\r
364 IN UINTN DataSize,\r
365 OUT UINT8 *HashValue\r
366 );\r
7c342378 367\r
0f01cec5 368#endif\r
b7d1ba0a 369\r
97f98500 370/**\r
a8c44645 371 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.\r
97f98500 372\r
a8c44645 373 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.\r
97f98500
HT
374\r
375**/\r
376UINTN\r
377EFIAPI\r
378Sha256GetContextSize (\r
379 VOID\r
380 );\r
381\r
97f98500
HT
382/**\r
383 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for\r
384 subsequent use.\r
385\r
16d2c32c 386 If Sha256Context is NULL, then return FALSE.\r
97f98500 387\r
a8c44645 388 @param[out] Sha256Context Pointer to SHA-256 context being initialized.\r
97f98500
HT
389\r
390 @retval TRUE SHA-256 context initialization succeeded.\r
391 @retval FALSE SHA-256 context initialization failed.\r
392\r
393**/\r
394BOOLEAN\r
395EFIAPI\r
396Sha256Init (\r
a8c44645 397 OUT VOID *Sha256Context\r
97f98500
HT
398 );\r
399\r
a8c44645 400/**\r
401 Makes a copy of an existing SHA-256 context.\r
402\r
16d2c32c 403 If Sha256Context is NULL, then return FALSE.\r
404 If NewSha256Context is NULL, then return FALSE.\r
532616bb 405 If this interface is not supported, then return FALSE.\r
a8c44645 406\r
407 @param[in] Sha256Context Pointer to SHA-256 context being copied.\r
408 @param[out] NewSha256Context Pointer to new SHA-256 context.\r
409\r
410 @retval TRUE SHA-256 context copy succeeded.\r
411 @retval FALSE SHA-256 context copy failed.\r
532616bb 412 @retval FALSE This interface is not supported.\r
a8c44645 413\r
414**/\r
415BOOLEAN\r
416EFIAPI\r
417Sha256Duplicate (\r
418 IN CONST VOID *Sha256Context,\r
419 OUT VOID *NewSha256Context\r
420 );\r
97f98500
HT
421\r
422/**\r
a8c44645 423 Digests the input data and updates SHA-256 context.\r
424\r
425 This function performs SHA-256 digest on a data buffer of the specified size.\r
426 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
2998af86 427 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized\r
a8c44645 428 by Sha256Final(). Behavior with invalid context is undefined.\r
97f98500 429\r
16d2c32c 430 If Sha256Context is NULL, then return FALSE.\r
97f98500
HT
431\r
432 @param[in, out] Sha256Context Pointer to the SHA-256 context.\r
433 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
a8c44645 434 @param[in] DataSize Size of Data buffer in bytes.\r
97f98500
HT
435\r
436 @retval TRUE SHA-256 data digest succeeded.\r
a8c44645 437 @retval FALSE SHA-256 data digest failed.\r
97f98500
HT
438\r
439**/\r
440BOOLEAN\r
441EFIAPI\r
442Sha256Update (\r
443 IN OUT VOID *Sha256Context,\r
444 IN CONST VOID *Data,\r
a8c44645 445 IN UINTN DataSize\r
97f98500
HT
446 );\r
447\r
97f98500 448/**\r
a8c44645 449 Completes computation of the SHA-256 digest value.\r
450\r
451 This function completes SHA-256 hash computation and retrieves the digest value into\r
452 the specified memory. After this function has been called, the SHA-256 context cannot\r
453 be used again.\r
2998af86 454 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be\r
a8c44645 455 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.\r
97f98500 456\r
16d2c32c 457 If Sha256Context is NULL, then return FALSE.\r
458 If HashValue is NULL, then return FALSE.\r
97f98500 459\r
a8c44645 460 @param[in, out] Sha256Context Pointer to the SHA-256 context.\r
97f98500
HT
461 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r
462 value (32 bytes).\r
463\r
464 @retval TRUE SHA-256 digest computation succeeded.\r
465 @retval FALSE SHA-256 digest computation failed.\r
466\r
467**/\r
468BOOLEAN\r
469EFIAPI\r
470Sha256Final (\r
471 IN OUT VOID *Sha256Context,\r
472 OUT UINT8 *HashValue\r
473 );\r
474\r
b7d1ba0a
QL
475/**\r
476 Computes the SHA-256 message digest of a input data buffer.\r
477\r
478 This function performs the SHA-256 message digest of a given data buffer, and places\r
479 the digest value into the specified memory.\r
480\r
481 If this interface is not supported, then return FALSE.\r
482\r
483 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
484 @param[in] DataSize Size of Data buffer in bytes.\r
485 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r
486 value (32 bytes).\r
487\r
488 @retval TRUE SHA-256 digest computation succeeded.\r
489 @retval FALSE SHA-256 digest computation failed.\r
490 @retval FALSE This interface is not supported.\r
491\r
492**/\r
493BOOLEAN\r
494EFIAPI\r
495Sha256HashAll (\r
496 IN CONST VOID *Data,\r
497 IN UINTN DataSize,\r
498 OUT UINT8 *HashValue\r
499 );\r
500\r
2ac68e8b
QL
501/**\r
502 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.\r
503\r
504 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.\r
505\r
506**/\r
507UINTN\r
508EFIAPI\r
509Sha384GetContextSize (\r
510 VOID\r
511 );\r
512\r
513/**\r
514 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for\r
515 subsequent use.\r
516\r
517 If Sha384Context is NULL, then return FALSE.\r
518\r
519 @param[out] Sha384Context Pointer to SHA-384 context being initialized.\r
520\r
521 @retval TRUE SHA-384 context initialization succeeded.\r
522 @retval FALSE SHA-384 context initialization failed.\r
523\r
524**/\r
525BOOLEAN\r
526EFIAPI\r
527Sha384Init (\r
528 OUT VOID *Sha384Context\r
529 );\r
530\r
531/**\r
532 Makes a copy of an existing SHA-384 context.\r
533\r
534 If Sha384Context is NULL, then return FALSE.\r
535 If NewSha384Context is NULL, then return FALSE.\r
536 If this interface is not supported, then return FALSE.\r
537\r
538 @param[in] Sha384Context Pointer to SHA-384 context being copied.\r
539 @param[out] NewSha384Context Pointer to new SHA-384 context.\r
540\r
541 @retval TRUE SHA-384 context copy succeeded.\r
542 @retval FALSE SHA-384 context copy failed.\r
543 @retval FALSE This interface is not supported.\r
544\r
545**/\r
546BOOLEAN\r
547EFIAPI\r
548Sha384Duplicate (\r
549 IN CONST VOID *Sha384Context,\r
550 OUT VOID *NewSha384Context\r
551 );\r
552\r
553/**\r
554 Digests the input data and updates SHA-384 context.\r
555\r
556 This function performs SHA-384 digest on a data buffer of the specified size.\r
557 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
2998af86 558 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized\r
2ac68e8b
QL
559 by Sha384Final(). Behavior with invalid context is undefined.\r
560\r
561 If Sha384Context is NULL, then return FALSE.\r
562\r
563 @param[in, out] Sha384Context Pointer to the SHA-384 context.\r
564 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
565 @param[in] DataSize Size of Data buffer in bytes.\r
566\r
567 @retval TRUE SHA-384 data digest succeeded.\r
568 @retval FALSE SHA-384 data digest failed.\r
569\r
570**/\r
571BOOLEAN\r
572EFIAPI\r
573Sha384Update (\r
574 IN OUT VOID *Sha384Context,\r
575 IN CONST VOID *Data,\r
576 IN UINTN DataSize\r
577 );\r
578\r
579/**\r
580 Completes computation of the SHA-384 digest value.\r
581\r
582 This function completes SHA-384 hash computation and retrieves the digest value into\r
583 the specified memory. After this function has been called, the SHA-384 context cannot\r
584 be used again.\r
2998af86 585 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be\r
2ac68e8b
QL
586 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.\r
587\r
588 If Sha384Context is NULL, then return FALSE.\r
589 If HashValue is NULL, then return FALSE.\r
590\r
591 @param[in, out] Sha384Context Pointer to the SHA-384 context.\r
592 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest\r
593 value (48 bytes).\r
594\r
595 @retval TRUE SHA-384 digest computation succeeded.\r
596 @retval FALSE SHA-384 digest computation failed.\r
597\r
598**/\r
599BOOLEAN\r
600EFIAPI\r
601Sha384Final (\r
602 IN OUT VOID *Sha384Context,\r
603 OUT UINT8 *HashValue\r
604 );\r
605\r
b7d1ba0a
QL
606/**\r
607 Computes the SHA-384 message digest of a input data buffer.\r
608\r
609 This function performs the SHA-384 message digest of a given data buffer, and places\r
610 the digest value into the specified memory.\r
611\r
612 If this interface is not supported, then return FALSE.\r
613\r
614 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
615 @param[in] DataSize Size of Data buffer in bytes.\r
616 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest\r
617 value (48 bytes).\r
618\r
619 @retval TRUE SHA-384 digest computation succeeded.\r
620 @retval FALSE SHA-384 digest computation failed.\r
621 @retval FALSE This interface is not supported.\r
622\r
623**/\r
624BOOLEAN\r
625EFIAPI\r
626Sha384HashAll (\r
627 IN CONST VOID *Data,\r
628 IN UINTN DataSize,\r
629 OUT UINT8 *HashValue\r
630 );\r
631\r
2ac68e8b
QL
632/**\r
633 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.\r
634\r
635 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.\r
636\r
637**/\r
638UINTN\r
639EFIAPI\r
640Sha512GetContextSize (\r
641 VOID\r
642 );\r
643\r
644/**\r
645 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for\r
646 subsequent use.\r
647\r
648 If Sha512Context is NULL, then return FALSE.\r
649\r
650 @param[out] Sha512Context Pointer to SHA-512 context being initialized.\r
651\r
652 @retval TRUE SHA-512 context initialization succeeded.\r
653 @retval FALSE SHA-512 context initialization failed.\r
654\r
655**/\r
656BOOLEAN\r
657EFIAPI\r
658Sha512Init (\r
659 OUT VOID *Sha512Context\r
660 );\r
661\r
662/**\r
663 Makes a copy of an existing SHA-512 context.\r
664\r
665 If Sha512Context is NULL, then return FALSE.\r
666 If NewSha512Context is NULL, then return FALSE.\r
667 If this interface is not supported, then return FALSE.\r
668\r
669 @param[in] Sha512Context Pointer to SHA-512 context being copied.\r
670 @param[out] NewSha512Context Pointer to new SHA-512 context.\r
671\r
672 @retval TRUE SHA-512 context copy succeeded.\r
673 @retval FALSE SHA-512 context copy failed.\r
674 @retval FALSE This interface is not supported.\r
675\r
676**/\r
677BOOLEAN\r
678EFIAPI\r
679Sha512Duplicate (\r
680 IN CONST VOID *Sha512Context,\r
681 OUT VOID *NewSha512Context\r
682 );\r
683\r
684/**\r
685 Digests the input data and updates SHA-512 context.\r
686\r
687 This function performs SHA-512 digest on a data buffer of the specified size.\r
688 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
2998af86 689 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized\r
2ac68e8b
QL
690 by Sha512Final(). Behavior with invalid context is undefined.\r
691\r
692 If Sha512Context is NULL, then return FALSE.\r
693\r
694 @param[in, out] Sha512Context Pointer to the SHA-512 context.\r
695 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
696 @param[in] DataSize Size of Data buffer in bytes.\r
697\r
698 @retval TRUE SHA-512 data digest succeeded.\r
699 @retval FALSE SHA-512 data digest failed.\r
700\r
701**/\r
702BOOLEAN\r
703EFIAPI\r
704Sha512Update (\r
705 IN OUT VOID *Sha512Context,\r
706 IN CONST VOID *Data,\r
707 IN UINTN DataSize\r
708 );\r
709\r
710/**\r
711 Completes computation of the SHA-512 digest value.\r
712\r
713 This function completes SHA-512 hash computation and retrieves the digest value into\r
714 the specified memory. After this function has been called, the SHA-512 context cannot\r
715 be used again.\r
2998af86 716 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be\r
2ac68e8b
QL
717 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.\r
718\r
719 If Sha512Context is NULL, then return FALSE.\r
720 If HashValue is NULL, then return FALSE.\r
721\r
722 @param[in, out] Sha512Context Pointer to the SHA-512 context.\r
723 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest\r
724 value (64 bytes).\r
725\r
726 @retval TRUE SHA-512 digest computation succeeded.\r
727 @retval FALSE SHA-512 digest computation failed.\r
728\r
729**/\r
730BOOLEAN\r
731EFIAPI\r
732Sha512Final (\r
733 IN OUT VOID *Sha512Context,\r
734 OUT UINT8 *HashValue\r
735 );\r
97f98500 736\r
b7d1ba0a
QL
737/**\r
738 Computes the SHA-512 message digest of a input data buffer.\r
739\r
740 This function performs the SHA-512 message digest of a given data buffer, and places\r
741 the digest value into the specified memory.\r
742\r
743 If this interface is not supported, then return FALSE.\r
744\r
745 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
746 @param[in] DataSize Size of Data buffer in bytes.\r
747 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest\r
748 value (64 bytes).\r
749\r
750 @retval TRUE SHA-512 digest computation succeeded.\r
751 @retval FALSE SHA-512 digest computation failed.\r
752 @retval FALSE This interface is not supported.\r
753\r
754**/\r
755BOOLEAN\r
756EFIAPI\r
757Sha512HashAll (\r
758 IN CONST VOID *Data,\r
759 IN UINTN DataSize,\r
760 OUT UINT8 *HashValue\r
761 );\r
762\r
c1e66210
ZL
763/**\r
764 Parallel hash function ParallelHash256, as defined in NIST's Special Publication 800-185,\r
765 published December 2016.\r
766\r
767 @param[in] Input Pointer to the input message (X).\r
768 @param[in] InputByteLen The number(>0) of input bytes provided for the input data.\r
769 @param[in] BlockSize The size of each block (B).\r
770 @param[out] Output Pointer to the output buffer.\r
771 @param[in] OutputByteLen The desired number of output bytes (L).\r
772 @param[in] Customization Pointer to the customization string (S).\r
773 @param[in] CustomByteLen The length of the customization string in bytes.\r
774\r
775 @retval TRUE ParallelHash256 digest computation succeeded.\r
776 @retval FALSE ParallelHash256 digest computation failed.\r
777 @retval FALSE This interface is not supported.\r
778\r
779**/\r
780BOOLEAN\r
781EFIAPI\r
782ParallelHash256HashAll (\r
783 IN CONST VOID *Input,\r
784 IN UINTN InputByteLen,\r
785 IN UINTN BlockSize,\r
786 OUT VOID *Output,\r
787 IN UINTN OutputByteLen,\r
788 IN CONST VOID *Customization,\r
789 IN UINTN CustomByteLen\r
790 );\r
791\r
f0718d1d
LX
792/**\r
793 Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.\r
794\r
795 @return The size, in bytes, of the context buffer required for SM3 hash operations.\r
796\r
797**/\r
798UINTN\r
799EFIAPI\r
800Sm3GetContextSize (\r
801 VOID\r
802 );\r
803\r
804/**\r
805 Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for\r
806 subsequent use.\r
807\r
808 If Sm3Context is NULL, then return FALSE.\r
809\r
810 @param[out] Sm3Context Pointer to SM3 context being initialized.\r
811\r
812 @retval TRUE SM3 context initialization succeeded.\r
813 @retval FALSE SM3 context initialization failed.\r
814\r
815**/\r
816BOOLEAN\r
817EFIAPI\r
818Sm3Init (\r
819 OUT VOID *Sm3Context\r
820 );\r
821\r
822/**\r
823 Makes a copy of an existing SM3 context.\r
824\r
825 If Sm3Context is NULL, then return FALSE.\r
826 If NewSm3Context is NULL, then return FALSE.\r
827 If this interface is not supported, then return FALSE.\r
828\r
829 @param[in] Sm3Context Pointer to SM3 context being copied.\r
830 @param[out] NewSm3Context Pointer to new SM3 context.\r
831\r
832 @retval TRUE SM3 context copy succeeded.\r
833 @retval FALSE SM3 context copy failed.\r
834 @retval FALSE This interface is not supported.\r
835\r
836**/\r
837BOOLEAN\r
838EFIAPI\r
839Sm3Duplicate (\r
840 IN CONST VOID *Sm3Context,\r
841 OUT VOID *NewSm3Context\r
842 );\r
843\r
844/**\r
845 Digests the input data and updates SM3 context.\r
846\r
847 This function performs SM3 digest on a data buffer of the specified size.\r
848 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
849 SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized\r
850 by Sm3Final(). Behavior with invalid context is undefined.\r
851\r
852 If Sm3Context is NULL, then return FALSE.\r
853\r
854 @param[in, out] Sm3Context Pointer to the SM3 context.\r
855 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
856 @param[in] DataSize Size of Data buffer in bytes.\r
857\r
858 @retval TRUE SM3 data digest succeeded.\r
859 @retval FALSE SM3 data digest failed.\r
860\r
861**/\r
862BOOLEAN\r
863EFIAPI\r
864Sm3Update (\r
865 IN OUT VOID *Sm3Context,\r
866 IN CONST VOID *Data,\r
867 IN UINTN DataSize\r
868 );\r
869\r
870/**\r
871 Completes computation of the SM3 digest value.\r
872\r
873 This function completes SM3 hash computation and retrieves the digest value into\r
874 the specified memory. After this function has been called, the SM3 context cannot\r
875 be used again.\r
876 SM3 context should be already correctly initialized by Sm3Init(), and should not be\r
877 finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.\r
878\r
879 If Sm3Context is NULL, then return FALSE.\r
880 If HashValue is NULL, then return FALSE.\r
881\r
882 @param[in, out] Sm3Context Pointer to the SM3 context.\r
883 @param[out] HashValue Pointer to a buffer that receives the SM3 digest\r
884 value (32 bytes).\r
885\r
886 @retval TRUE SM3 digest computation succeeded.\r
887 @retval FALSE SM3 digest computation failed.\r
888\r
889**/\r
890BOOLEAN\r
891EFIAPI\r
892Sm3Final (\r
893 IN OUT VOID *Sm3Context,\r
894 OUT UINT8 *HashValue\r
895 );\r
896\r
897/**\r
898 Computes the SM3 message digest of a input data buffer.\r
899\r
900 This function performs the SM3 message digest of a given data buffer, and places\r
901 the digest value into the specified memory.\r
902\r
903 If this interface is not supported, then return FALSE.\r
904\r
905 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
906 @param[in] DataSize Size of Data buffer in bytes.\r
907 @param[out] HashValue Pointer to a buffer that receives the SM3 digest\r
908 value (32 bytes).\r
909\r
910 @retval TRUE SM3 digest computation succeeded.\r
911 @retval FALSE SM3 digest computation failed.\r
912 @retval FALSE This interface is not supported.\r
913\r
914**/\r
915BOOLEAN\r
916EFIAPI\r
917Sm3HashAll (\r
918 IN CONST VOID *Data,\r
919 IN UINTN DataSize,\r
920 OUT UINT8 *HashValue\r
921 );\r
922\r
7c342378 923// =====================================================================================\r
97f98500 924// MAC (Message Authentication Code) Primitive\r
7c342378 925// =====================================================================================\r
97f98500 926\r
4c270243
QL
927/**\r
928 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.\r
929\r
930 @return Pointer to the HMAC_CTX context that has been initialized.\r
931 If the allocations fails, HmacSha256New() returns NULL.\r
932\r
933**/\r
934VOID *\r
935EFIAPI\r
936HmacSha256New (\r
937 VOID\r
938 );\r
939\r
940/**\r
941 Release the specified HMAC_CTX context.\r
942\r
943 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.\r
944\r
945**/\r
946VOID\r
947EFIAPI\r
948HmacSha256Free (\r
949 IN VOID *HmacSha256Ctx\r
950 );\r
951\r
72009c62 952/**\r
a23fdff6
JW
953 Set user-supplied key for subsequent use. It must be done before any\r
954 calling to HmacSha256Update().\r
72009c62
QL
955\r
956 If HmacSha256Context is NULL, then return FALSE.\r
957 If this interface is not supported, then return FALSE.\r
958\r
a23fdff6 959 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.\r
72009c62
QL
960 @param[in] Key Pointer to the user-supplied key.\r
961 @param[in] KeySize Key size in bytes.\r
962\r
a23fdff6
JW
963 @retval TRUE The Key is set successfully.\r
964 @retval FALSE The Key is set unsuccessfully.\r
72009c62
QL
965 @retval FALSE This interface is not supported.\r
966\r
967**/\r
968BOOLEAN\r
969EFIAPI\r
a23fdff6 970HmacSha256SetKey (\r
72009c62
QL
971 OUT VOID *HmacSha256Context,\r
972 IN CONST UINT8 *Key,\r
973 IN UINTN KeySize\r
974 );\r
975\r
976/**\r
977 Makes a copy of an existing HMAC-SHA256 context.\r
978\r
979 If HmacSha256Context is NULL, then return FALSE.\r
980 If NewHmacSha256Context is NULL, then return FALSE.\r
981 If this interface is not supported, then return FALSE.\r
982\r
983 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.\r
984 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.\r
985\r
986 @retval TRUE HMAC-SHA256 context copy succeeded.\r
987 @retval FALSE HMAC-SHA256 context copy failed.\r
988 @retval FALSE This interface is not supported.\r
989\r
990**/\r
991BOOLEAN\r
992EFIAPI\r
993HmacSha256Duplicate (\r
994 IN CONST VOID *HmacSha256Context,\r
995 OUT VOID *NewHmacSha256Context\r
996 );\r
997\r
998/**\r
999 Digests the input data and updates HMAC-SHA256 context.\r
1000\r
1001 This function performs HMAC-SHA256 digest on a data buffer of the specified size.\r
1002 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
a23fdff6
JW
1003 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r
1004 by HmacSha256Final(). Behavior with invalid context is undefined.\r
72009c62
QL
1005\r
1006 If HmacSha256Context is NULL, then return FALSE.\r
1007 If this interface is not supported, then return FALSE.\r
1008\r
1009 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r
1010 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1011 @param[in] DataSize Size of Data buffer in bytes.\r
1012\r
1013 @retval TRUE HMAC-SHA256 data digest succeeded.\r
1014 @retval FALSE HMAC-SHA256 data digest failed.\r
1015 @retval FALSE This interface is not supported.\r
1016\r
1017**/\r
1018BOOLEAN\r
1019EFIAPI\r
1020HmacSha256Update (\r
1021 IN OUT VOID *HmacSha256Context,\r
1022 IN CONST VOID *Data,\r
1023 IN UINTN DataSize\r
1024 );\r
1025\r
1026/**\r
1027 Completes computation of the HMAC-SHA256 digest value.\r
1028\r
1029 This function completes HMAC-SHA256 hash computation and retrieves the digest value into\r
1030 the specified memory. After this function has been called, the HMAC-SHA256 context cannot\r
1031 be used again.\r
a23fdff6
JW
1032 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r
1033 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.\r
72009c62
QL
1034\r
1035 If HmacSha256Context is NULL, then return FALSE.\r
68ae7cd6 1036 If HmacValue is NULL, then return FALSE.\r
72009c62
QL
1037 If this interface is not supported, then return FALSE.\r
1038\r
1039 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r
68ae7cd6 1040 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest\r
72009c62
QL
1041 value (32 bytes).\r
1042\r
1043 @retval TRUE HMAC-SHA256 digest computation succeeded.\r
1044 @retval FALSE HMAC-SHA256 digest computation failed.\r
1045 @retval FALSE This interface is not supported.\r
1046\r
1047**/\r
1048BOOLEAN\r
1049EFIAPI\r
1050HmacSha256Final (\r
1051 IN OUT VOID *HmacSha256Context,\r
1052 OUT UINT8 *HmacValue\r
1053 );\r
1054\r
7bb42e32
QZ
1055/**\r
1056 Computes the HMAC-SHA256 digest of a input data buffer.\r
1057\r
1058 This function performs the HMAC-SHA256 digest of a given data buffer, and places\r
1059 the digest value into the specified memory.\r
1060\r
1061 If this interface is not supported, then return FALSE.\r
1062\r
1063 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1064 @param[in] DataSize Size of Data buffer in bytes.\r
1065 @param[in] Key Pointer to the user-supplied key.\r
1066 @param[in] KeySize Key size in bytes.\r
1067 @param[out] HashValue Pointer to a buffer that receives the HMAC-SHA256 digest\r
1068 value (32 bytes).\r
1069\r
1070 @retval TRUE HMAC-SHA256 digest computation succeeded.\r
1071 @retval FALSE HMAC-SHA256 digest computation failed.\r
1072 @retval FALSE This interface is not supported.\r
1073\r
1074**/\r
1075BOOLEAN\r
1076EFIAPI\r
1077HmacSha256All (\r
1078 IN CONST VOID *Data,\r
1079 IN UINTN DataSize,\r
1080 IN CONST UINT8 *Key,\r
1081 IN UINTN KeySize,\r
1082 OUT UINT8 *HmacValue\r
1083 );\r
1084\r
1085/**\r
1086 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA384 use.\r
1087\r
1088 @return Pointer to the HMAC_CTX context that has been initialized.\r
1089 If the allocations fails, HmacSha384New() returns NULL.\r
1090\r
1091**/\r
1092VOID *\r
1093EFIAPI\r
1094HmacSha384New (\r
1095 VOID\r
1096 );\r
1097\r
1098/**\r
1099 Release the specified HMAC_CTX context.\r
1100\r
1101 @param[in] HmacSha384Ctx Pointer to the HMAC_CTX context to be released.\r
1102\r
1103**/\r
1104VOID\r
1105EFIAPI\r
1106HmacSha384Free (\r
1107 IN VOID *HmacSha384Ctx\r
1108 );\r
1109\r
1110/**\r
1111 Set user-supplied key for subsequent use. It must be done before any\r
1112 calling to HmacSha384Update().\r
1113\r
1114 If HmacSha384Context is NULL, then return FALSE.\r
1115 If this interface is not supported, then return FALSE.\r
1116\r
1117 @param[out] HmacSha384Context Pointer to HMAC-SHA384 context.\r
1118 @param[in] Key Pointer to the user-supplied key.\r
1119 @param[in] KeySize Key size in bytes.\r
1120\r
1121 @retval TRUE The Key is set successfully.\r
1122 @retval FALSE The Key is set unsuccessfully.\r
1123 @retval FALSE This interface is not supported.\r
1124\r
1125**/\r
1126BOOLEAN\r
1127EFIAPI\r
1128HmacSha384SetKey (\r
1129 OUT VOID *HmacSha384Context,\r
1130 IN CONST UINT8 *Key,\r
1131 IN UINTN KeySize\r
1132 );\r
1133\r
1134/**\r
1135 Makes a copy of an existing HMAC-SHA384 context.\r
1136\r
1137 If HmacSha384Context is NULL, then return FALSE.\r
1138 If NewHmacSha384Context is NULL, then return FALSE.\r
1139 If this interface is not supported, then return FALSE.\r
1140\r
1141 @param[in] HmacSha384Context Pointer to HMAC-SHA384 context being copied.\r
1142 @param[out] NewHmacSha384Context Pointer to new HMAC-SHA384 context.\r
1143\r
1144 @retval TRUE HMAC-SHA384 context copy succeeded.\r
1145 @retval FALSE HMAC-SHA384 context copy failed.\r
1146 @retval FALSE This interface is not supported.\r
1147\r
1148**/\r
1149BOOLEAN\r
1150EFIAPI\r
1151HmacSha384Duplicate (\r
1152 IN CONST VOID *HmacSha384Context,\r
1153 OUT VOID *NewHmacSha384Context\r
1154 );\r
1155\r
1156/**\r
1157 Digests the input data and updates HMAC-SHA384 context.\r
1158\r
1159 This function performs HMAC-SHA384 digest on a data buffer of the specified size.\r
1160 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
1161 HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized\r
1162 by HmacSha384Final(). Behavior with invalid context is undefined.\r
1163\r
1164 If HmacSha384Context is NULL, then return FALSE.\r
1165 If this interface is not supported, then return FALSE.\r
1166\r
1167 @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.\r
1168 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1169 @param[in] DataSize Size of Data buffer in bytes.\r
1170\r
1171 @retval TRUE HMAC-SHA384 data digest succeeded.\r
1172 @retval FALSE HMAC-SHA384 data digest failed.\r
1173 @retval FALSE This interface is not supported.\r
1174\r
1175**/\r
1176BOOLEAN\r
1177EFIAPI\r
1178HmacSha384Update (\r
1179 IN OUT VOID *HmacSha384Context,\r
1180 IN CONST VOID *Data,\r
1181 IN UINTN DataSize\r
1182 );\r
1183\r
1184/**\r
1185 Completes computation of the HMAC-SHA384 digest value.\r
1186\r
1187 This function completes HMAC-SHA384 hash computation and retrieves the digest value into\r
1188 the specified memory. After this function has been called, the HMAC-SHA384 context cannot\r
1189 be used again.\r
1190 HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized\r
1191 by HmacSha384Final(). Behavior with invalid HMAC-SHA384 context is undefined.\r
1192\r
1193 If HmacSha384Context is NULL, then return FALSE.\r
1194 If HmacValue is NULL, then return FALSE.\r
1195 If this interface is not supported, then return FALSE.\r
1196\r
1197 @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.\r
1198 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA384 digest\r
1199 value (48 bytes).\r
1200\r
1201 @retval TRUE HMAC-SHA384 digest computation succeeded.\r
1202 @retval FALSE HMAC-SHA384 digest computation failed.\r
1203 @retval FALSE This interface is not supported.\r
1204\r
1205**/\r
1206BOOLEAN\r
1207EFIAPI\r
1208HmacSha384Final (\r
1209 IN OUT VOID *HmacSha384Context,\r
1210 OUT UINT8 *HmacValue\r
1211 );\r
1212\r
1213/**\r
1214 Computes the HMAC-SHA384 digest of a input data buffer.\r
1215\r
1216 This function performs the HMAC-SHA384 digest of a given data buffer, and places\r
1217 the digest value into the specified memory.\r
1218\r
1219 If this interface is not supported, then return FALSE.\r
1220\r
1221 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1222 @param[in] DataSize Size of Data buffer in bytes.\r
1223 @param[in] Key Pointer to the user-supplied key.\r
1224 @param[in] KeySize Key size in bytes.\r
1225 @param[out] HashValue Pointer to a buffer that receives the HMAC-SHA384 digest\r
1226 value (48 bytes).\r
1227\r
1228 @retval TRUE HMAC-SHA384 digest computation succeeded.\r
1229 @retval FALSE HMAC-SHA384 digest computation failed.\r
1230 @retval FALSE This interface is not supported.\r
1231\r
1232**/\r
1233BOOLEAN\r
1234EFIAPI\r
1235HmacSha384All (\r
1236 IN CONST VOID *Data,\r
1237 IN UINTN DataSize,\r
1238 IN CONST UINT8 *Key,\r
1239 IN UINTN KeySize,\r
1240 OUT UINT8 *HmacValue\r
1241 );\r
1242\r
7c342378 1243// =====================================================================================\r
97f98500 1244// Symmetric Cryptography Primitive\r
7c342378 1245// =====================================================================================\r
97f98500 1246\r
a8c44645 1247/**\r
1248 Retrieves the size, in bytes, of the context buffer required for AES operations.\r
1249\r
532616bb 1250 If this interface is not supported, then return zero.\r
1251\r
a8c44645 1252 @return The size, in bytes, of the context buffer required for AES operations.\r
532616bb 1253 @retval 0 This interface is not supported.\r
a8c44645 1254\r
1255**/\r
1256UINTN\r
1257EFIAPI\r
1258AesGetContextSize (\r
1259 VOID\r
1260 );\r
1261\r
1262/**\r
1263 Initializes user-supplied memory as AES context for subsequent use.\r
1264\r
1265 This function initializes user-supplied memory pointed by AesContext as AES context.\r
6b8ebcb8 1266 In addition, it sets up all AES key materials for subsequent encryption and decryption\r
a8c44645 1267 operations.\r
1268 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.\r
1269\r
16d2c32c 1270 If AesContext is NULL, then return FALSE.\r
1271 If Key is NULL, then return FALSE.\r
1272 If KeyLength is not valid, then return FALSE.\r
532616bb 1273 If this interface is not supported, then return FALSE.\r
a8c44645 1274\r
1275 @param[out] AesContext Pointer to AES context being initialized.\r
1276 @param[in] Key Pointer to the user-supplied AES key.\r
1277 @param[in] KeyLength Length of AES key in bits.\r
1278\r
1279 @retval TRUE AES context initialization succeeded.\r
1280 @retval FALSE AES context initialization failed.\r
532616bb 1281 @retval FALSE This interface is not supported.\r
a8c44645 1282\r
1283**/\r
1284BOOLEAN\r
1285EFIAPI\r
1286AesInit (\r
1287 OUT VOID *AesContext,\r
1288 IN CONST UINT8 *Key,\r
1289 IN UINTN KeyLength\r
1290 );\r
1291\r
a8c44645 1292/**\r
1293 Performs AES encryption on a data buffer of the specified size in CBC mode.\r
1294\r
1295 This function performs AES encryption on data buffer pointed by Input, of specified\r
1296 size of InputSize, in CBC mode.\r
1297 InputSize must be multiple of block size (16 bytes). This function does not perform\r
1298 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
1299 Initialization vector should be one block size (16 bytes).\r
1300 AesContext should be already correctly initialized by AesInit(). Behavior with\r
1301 invalid AES context is undefined.\r
1302\r
16d2c32c 1303 If AesContext is NULL, then return FALSE.\r
1304 If Input is NULL, then return FALSE.\r
1305 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
1306 If Ivec is NULL, then return FALSE.\r
1307 If Output is NULL, then return FALSE.\r
532616bb 1308 If this interface is not supported, then return FALSE.\r
a8c44645 1309\r
1310 @param[in] AesContext Pointer to the AES context.\r
1311 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
1312 @param[in] InputSize Size of the Input buffer in bytes.\r
1313 @param[in] Ivec Pointer to initialization vector.\r
1314 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
1315\r
1316 @retval TRUE AES encryption succeeded.\r
1317 @retval FALSE AES encryption failed.\r
532616bb 1318 @retval FALSE This interface is not supported.\r
a8c44645 1319\r
1320**/\r
1321BOOLEAN\r
1322EFIAPI\r
1323AesCbcEncrypt (\r
1324 IN VOID *AesContext,\r
1325 IN CONST UINT8 *Input,\r
1326 IN UINTN InputSize,\r
1327 IN CONST UINT8 *Ivec,\r
1328 OUT UINT8 *Output\r
1329 );\r
1330\r
1331/**\r
1332 Performs AES decryption on a data buffer of the specified size in CBC mode.\r
1333\r
1334 This function performs AES decryption on data buffer pointed by Input, of specified\r
1335 size of InputSize, in CBC mode.\r
1336 InputSize must be multiple of block size (16 bytes). This function does not perform\r
1337 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
1338 Initialization vector should be one block size (16 bytes).\r
1339 AesContext should be already correctly initialized by AesInit(). Behavior with\r
1340 invalid AES context is undefined.\r
1341\r
16d2c32c 1342 If AesContext is NULL, then return FALSE.\r
1343 If Input is NULL, then return FALSE.\r
1344 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
1345 If Ivec is NULL, then return FALSE.\r
1346 If Output is NULL, then return FALSE.\r
532616bb 1347 If this interface is not supported, then return FALSE.\r
a8c44645 1348\r
1349 @param[in] AesContext Pointer to the AES context.\r
1350 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
1351 @param[in] InputSize Size of the Input buffer in bytes.\r
1352 @param[in] Ivec Pointer to initialization vector.\r
1353 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
1354\r
1355 @retval TRUE AES decryption succeeded.\r
1356 @retval FALSE AES decryption failed.\r
532616bb 1357 @retval FALSE This interface is not supported.\r
a8c44645 1358\r
1359**/\r
1360BOOLEAN\r
1361EFIAPI\r
1362AesCbcDecrypt (\r
1363 IN VOID *AesContext,\r
1364 IN CONST UINT8 *Input,\r
1365 IN UINTN InputSize,\r
1366 IN CONST UINT8 *Ivec,\r
1367 OUT UINT8 *Output\r
1368 );\r
1369\r
acbc5747
QZ
1370// =====================================================================================\r
1371// Authenticated Encryption with Associated Data (AEAD) Cryptography Primitive\r
1372// =====================================================================================\r
1373\r
1374/**\r
1375 Performs AEAD AES-GCM authenticated encryption on a data buffer and additional authenticated data (AAD).\r
1376\r
1377 IvSize must be 12, otherwise FALSE is returned.\r
1378 KeySize must be 16, 24 or 32, otherwise FALSE is returned.\r
1379 TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.\r
1380\r
1381 @param[in] Key Pointer to the encryption key.\r
1382 @param[in] KeySize Size of the encryption key in bytes.\r
1383 @param[in] Iv Pointer to the IV value.\r
1384 @param[in] IvSize Size of the IV value in bytes.\r
1385 @param[in] AData Pointer to the additional authenticated data (AAD).\r
1386 @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.\r
1387 @param[in] DataIn Pointer to the input data buffer to be encrypted.\r
1388 @param[in] DataInSize Size of the input data buffer in bytes.\r
1389 @param[out] TagOut Pointer to a buffer that receives the authentication tag output.\r
1390 @param[in] TagSize Size of the authentication tag in bytes.\r
1391 @param[out] DataOut Pointer to a buffer that receives the encryption output.\r
1392 @param[out] DataOutSize Size of the output data buffer in bytes.\r
1393\r
1394 @retval TRUE AEAD AES-GCM authenticated encryption succeeded.\r
1395 @retval FALSE AEAD AES-GCM authenticated encryption failed.\r
1396\r
1397**/\r
1398BOOLEAN\r
1399EFIAPI\r
1400AeadAesGcmEncrypt (\r
1401 IN CONST UINT8 *Key,\r
1402 IN UINTN KeySize,\r
1403 IN CONST UINT8 *Iv,\r
1404 IN UINTN IvSize,\r
1405 IN CONST UINT8 *AData,\r
1406 IN UINTN ADataSize,\r
1407 IN CONST UINT8 *DataIn,\r
1408 IN UINTN DataInSize,\r
1409 OUT UINT8 *TagOut,\r
1410 IN UINTN TagSize,\r
1411 OUT UINT8 *DataOut,\r
1412 OUT UINTN *DataOutSize\r
1413 );\r
1414\r
1415/**\r
1416 Performs AEAD AES-GCM authenticated decryption on a data buffer and additional authenticated data (AAD).\r
1417\r
1418 IvSize must be 12, otherwise FALSE is returned.\r
1419 KeySize must be 16, 24 or 32, otherwise FALSE is returned.\r
1420 TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.\r
1421 If additional authenticated data verification fails, FALSE is returned.\r
1422\r
1423 @param[in] Key Pointer to the encryption key.\r
1424 @param[in] KeySize Size of the encryption key in bytes.\r
1425 @param[in] Iv Pointer to the IV value.\r
1426 @param[in] IvSize Size of the IV value in bytes.\r
1427 @param[in] AData Pointer to the additional authenticated data (AAD).\r
1428 @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.\r
1429 @param[in] DataIn Pointer to the input data buffer to be decrypted.\r
1430 @param[in] DataInSize Size of the input data buffer in bytes.\r
1431 @param[in] Tag Pointer to a buffer that contains the authentication tag.\r
1432 @param[in] TagSize Size of the authentication tag in bytes.\r
1433 @param[out] DataOut Pointer to a buffer that receives the decryption output.\r
1434 @param[out] DataOutSize Size of the output data buffer in bytes.\r
1435\r
1436 @retval TRUE AEAD AES-GCM authenticated decryption succeeded.\r
1437 @retval FALSE AEAD AES-GCM authenticated decryption failed.\r
1438\r
1439**/\r
1440BOOLEAN\r
1441EFIAPI\r
1442AeadAesGcmDecrypt (\r
1443 IN CONST UINT8 *Key,\r
1444 IN UINTN KeySize,\r
1445 IN CONST UINT8 *Iv,\r
1446 IN UINTN IvSize,\r
1447 IN CONST UINT8 *AData,\r
1448 IN UINTN ADataSize,\r
1449 IN CONST UINT8 *DataIn,\r
1450 IN UINTN DataInSize,\r
1451 IN CONST UINT8 *Tag,\r
1452 IN UINTN TagSize,\r
1453 OUT UINT8 *DataOut,\r
1454 OUT UINTN *DataOutSize\r
1455 );\r
1456\r
7c342378 1457// =====================================================================================\r
97f98500 1458// Asymmetric Cryptography Primitive\r
7c342378 1459// =====================================================================================\r
97f98500
HT
1460\r
1461/**\r
a8c44645 1462 Allocates and initializes one RSA context for subsequent use.\r
97f98500 1463\r
a8c44645 1464 @return Pointer to the RSA context that has been initialized.\r
97f98500
HT
1465 If the allocations fails, RsaNew() returns NULL.\r
1466\r
1467**/\r
1468VOID *\r
1469EFIAPI\r
1470RsaNew (\r
1471 VOID\r
1472 );\r
1473\r
97f98500 1474/**\r
a8c44645 1475 Release the specified RSA context.\r
1476\r
16d2c32c 1477 If RsaContext is NULL, then return FALSE.\r
97f98500
HT
1478\r
1479 @param[in] RsaContext Pointer to the RSA context to be released.\r
1480\r
1481**/\r
1482VOID\r
1483EFIAPI\r
1484RsaFree (\r
1485 IN VOID *RsaContext\r
1486 );\r
1487\r
97f98500 1488/**\r
a8c44645 1489 Sets the tag-designated key component into the established RSA context.\r
1490\r
1491 This function sets the tag-designated RSA key component into the established\r
1492 RSA context from the user-specified non-negative integer (octet string format\r
1493 represented in RSA PKCS#1).\r
2998af86 1494 If BigNumber is NULL, then the specified key component in RSA context is cleared.\r
97f98500 1495\r
16d2c32c 1496 If RsaContext is NULL, then return FALSE.\r
97f98500
HT
1497\r
1498 @param[in, out] RsaContext Pointer to RSA context being set.\r
1499 @param[in] KeyTag Tag of RSA key component being set.\r
1500 @param[in] BigNumber Pointer to octet integer buffer.\r
2998af86 1501 If NULL, then the specified key component in RSA\r
a8c44645 1502 context is cleared.\r
1503 @param[in] BnSize Size of big number buffer in bytes.\r
1504 If BigNumber is NULL, then it is ignored.\r
97f98500 1505\r
a8c44645 1506 @retval TRUE RSA key component was set successfully.\r
1507 @retval FALSE Invalid RSA key component tag.\r
97f98500
HT
1508\r
1509**/\r
1510BOOLEAN\r
1511EFIAPI\r
1512RsaSetKey (\r
a8c44645 1513 IN OUT VOID *RsaContext,\r
1514 IN RSA_KEY_TAG KeyTag,\r
1515 IN CONST UINT8 *BigNumber,\r
1516 IN UINTN BnSize\r
1517 );\r
1518\r
1519/**\r
1520 Gets the tag-designated RSA key component from the established RSA context.\r
1521\r
1522 This function retrieves the tag-designated RSA key component from the\r
1523 established RSA context as a non-negative integer (octet string format\r
1524 represented in RSA PKCS#1).\r
1525 If specified key component has not been set or has been cleared, then returned\r
1526 BnSize is set to 0.\r
1527 If the BigNumber buffer is too small to hold the contents of the key, FALSE\r
1528 is returned and BnSize is set to the required buffer size to obtain the key.\r
1529\r
16d2c32c 1530 If RsaContext is NULL, then return FALSE.\r
1531 If BnSize is NULL, then return FALSE.\r
1532 If BnSize is large enough but BigNumber is NULL, then return FALSE.\r
532616bb 1533 If this interface is not supported, then return FALSE.\r
a8c44645 1534\r
1535 @param[in, out] RsaContext Pointer to RSA context being set.\r
1536 @param[in] KeyTag Tag of RSA key component being set.\r
1537 @param[out] BigNumber Pointer to octet integer buffer.\r
1538 @param[in, out] BnSize On input, the size of big number buffer in bytes.\r
1539 On output, the size of data returned in big number buffer in bytes.\r
1540\r
1541 @retval TRUE RSA key component was retrieved successfully.\r
1542 @retval FALSE Invalid RSA key component tag.\r
1543 @retval FALSE BnSize is too small.\r
532616bb 1544 @retval FALSE This interface is not supported.\r
a8c44645 1545\r
1546**/\r
1547BOOLEAN\r
1548EFIAPI\r
1549RsaGetKey (\r
1550 IN OUT VOID *RsaContext,\r
1551 IN RSA_KEY_TAG KeyTag,\r
1552 OUT UINT8 *BigNumber,\r
1553 IN OUT UINTN *BnSize\r
1554 );\r
1555\r
1556/**\r
1557 Generates RSA key components.\r
1558\r
1559 This function generates RSA key components. It takes RSA public exponent E and\r
1560 length in bits of RSA modulus N as input, and generates all key components.\r
1561 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.\r
1562\r
1563 Before this function can be invoked, pseudorandom number generator must be correctly\r
1564 initialized by RandomSeed().\r
1565\r
16d2c32c 1566 If RsaContext is NULL, then return FALSE.\r
532616bb 1567 If this interface is not supported, then return FALSE.\r
a8c44645 1568\r
1569 @param[in, out] RsaContext Pointer to RSA context being set.\r
1570 @param[in] ModulusLength Length of RSA modulus N in bits.\r
1571 @param[in] PublicExponent Pointer to RSA public exponent.\r
2ac68e8b 1572 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.\r
a8c44645 1573\r
1574 @retval TRUE RSA key component was generated successfully.\r
1575 @retval FALSE Invalid RSA key component tag.\r
532616bb 1576 @retval FALSE This interface is not supported.\r
a8c44645 1577\r
1578**/\r
1579BOOLEAN\r
1580EFIAPI\r
1581RsaGenerateKey (\r
1582 IN OUT VOID *RsaContext,\r
1583 IN UINTN ModulusLength,\r
1584 IN CONST UINT8 *PublicExponent,\r
1585 IN UINTN PublicExponentSize\r
1586 );\r
1587\r
1588/**\r
1589 Validates key components of RSA context.\r
952bd229
QL
1590 NOTE: This function performs integrity checks on all the RSA key material, so\r
1591 the RSA key structure must contain all the private key data.\r
a8c44645 1592\r
2998af86 1593 This function validates key components of RSA context in following aspects:\r
a8c44645 1594 - Whether p is a prime\r
1595 - Whether q is a prime\r
1596 - Whether n = p * q\r
1597 - Whether d*e = 1 mod lcm(p-1,q-1)\r
1598\r
16d2c32c 1599 If RsaContext is NULL, then return FALSE.\r
532616bb 1600 If this interface is not supported, then return FALSE.\r
a8c44645 1601\r
1602 @param[in] RsaContext Pointer to RSA context to check.\r
1603\r
1604 @retval TRUE RSA key components are valid.\r
1605 @retval FALSE RSA key components are not valid.\r
532616bb 1606 @retval FALSE This interface is not supported.\r
a8c44645 1607\r
1608**/\r
1609BOOLEAN\r
1610EFIAPI\r
1611RsaCheckKey (\r
1612 IN VOID *RsaContext\r
97f98500
HT
1613 );\r
1614\r
a8c44645 1615/**\r
1616 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.\r
1617\r
1618 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in\r
1619 RSA PKCS#1.\r
1620 If the Signature buffer is too small to hold the contents of signature, FALSE\r
1621 is returned and SigSize is set to the required buffer size to obtain the signature.\r
1622\r
16d2c32c 1623 If RsaContext is NULL, then return FALSE.\r
1624 If MessageHash is NULL, then return FALSE.\r
1625 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.\r
1626 If SigSize is large enough but Signature is NULL, then return FALSE.\r
532616bb 1627 If this interface is not supported, then return FALSE.\r
a8c44645 1628\r
1629 @param[in] RsaContext Pointer to RSA context for signature generation.\r
1630 @param[in] MessageHash Pointer to octet message hash to be signed.\r
1631 @param[in] HashSize Size of the message hash in bytes.\r
1632 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.\r
1633 @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r
b7d320f8 1634 On output, the size of data returned in Signature buffer in bytes.\r
a8c44645 1635\r
1636 @retval TRUE Signature successfully generated in PKCS1-v1_5.\r
1637 @retval FALSE Signature generation failed.\r
1638 @retval FALSE SigSize is too small.\r
532616bb 1639 @retval FALSE This interface is not supported.\r
a8c44645 1640\r
1641**/\r
1642BOOLEAN\r
1643EFIAPI\r
1644RsaPkcs1Sign (\r
1645 IN VOID *RsaContext,\r
1646 IN CONST UINT8 *MessageHash,\r
1647 IN UINTN HashSize,\r
1648 OUT UINT8 *Signature,\r
1649 IN OUT UINTN *SigSize\r
1650 );\r
97f98500
HT
1651\r
1652/**\r
1653 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in\r
1654 RSA PKCS#1.\r
1655\r
16d2c32c 1656 If RsaContext is NULL, then return FALSE.\r
1657 If MessageHash is NULL, then return FALSE.\r
1658 If Signature is NULL, then return FALSE.\r
1659 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.\r
97f98500
HT
1660\r
1661 @param[in] RsaContext Pointer to RSA context for signature verification.\r
1662 @param[in] MessageHash Pointer to octet message hash to be checked.\r
a8c44645 1663 @param[in] HashSize Size of the message hash in bytes.\r
97f98500 1664 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.\r
a8c44645 1665 @param[in] SigSize Size of signature in bytes.\r
97f98500 1666\r
a8c44645 1667 @retval TRUE Valid signature encoded in PKCS1-v1_5.\r
1668 @retval FALSE Invalid signature or invalid RSA context.\r
97f98500
HT
1669\r
1670**/\r
1671BOOLEAN\r
1672EFIAPI\r
1673RsaPkcs1Verify (\r
1674 IN VOID *RsaContext,\r
1675 IN CONST UINT8 *MessageHash,\r
a8c44645 1676 IN UINTN HashSize,\r
8c5720b4 1677 IN CONST UINT8 *Signature,\r
a8c44645 1678 IN UINTN SigSize\r
97f98500
HT
1679 );\r
1680\r
22ac5cc9
SA
1681/**\r
1682 Carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme.\r
1683\r
1684 This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in\r
1685 RFC 8017.\r
1686 Mask generation function is the same as the message digest algorithm.\r
1687 If the Signature buffer is too small to hold the contents of signature, FALSE\r
1688 is returned and SigSize is set to the required buffer size to obtain the signature.\r
1689\r
1690 If RsaContext is NULL, then return FALSE.\r
1691 If Message is NULL, then return FALSE.\r
1692 If MsgSize is zero or > INT_MAX, then return FALSE.\r
1693 If DigestLen is NOT 32, 48 or 64, return FALSE.\r
20ca5288 1694 If SaltLen is not equal to DigestLen, then return FALSE.\r
22ac5cc9
SA
1695 If SigSize is large enough but Signature is NULL, then return FALSE.\r
1696 If this interface is not supported, then return FALSE.\r
1697\r
1698 @param[in] RsaContext Pointer to RSA context for signature generation.\r
1699 @param[in] Message Pointer to octet message to be signed.\r
1700 @param[in] MsgSize Size of the message in bytes.\r
1701 @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.\r
1702 @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.\r
1703 @param[out] Signature Pointer to buffer to receive RSA PSS signature.\r
1704 @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r
1705 On output, the size of data returned in Signature buffer in bytes.\r
1706\r
1707 @retval TRUE Signature successfully generated in RSASSA-PSS.\r
1708 @retval FALSE Signature generation failed.\r
1709 @retval FALSE SigSize is too small.\r
1710 @retval FALSE This interface is not supported.\r
1711\r
1712**/\r
1713BOOLEAN\r
1714EFIAPI\r
1715RsaPssSign (\r
1716 IN VOID *RsaContext,\r
1717 IN CONST UINT8 *Message,\r
1718 IN UINTN MsgSize,\r
1719 IN UINT16 DigestLen,\r
1720 IN UINT16 SaltLen,\r
1721 OUT UINT8 *Signature,\r
1722 IN OUT UINTN *SigSize\r
1723 );\r
1724\r
1725/**\r
1726 Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.\r
1727 Implementation determines salt length automatically from the signature encoding.\r
1728 Mask generation function is the same as the message digest algorithm.\r
20ca5288 1729 Salt length should be equal to digest length.\r
22ac5cc9
SA
1730\r
1731 @param[in] RsaContext Pointer to RSA context for signature verification.\r
1732 @param[in] Message Pointer to octet message to be verified.\r
1733 @param[in] MsgSize Size of the message in bytes.\r
1734 @param[in] Signature Pointer to RSASSA-PSS signature to be verified.\r
1735 @param[in] SigSize Size of signature in bytes.\r
1736 @param[in] DigestLen Length of digest for RSA operation.\r
1737 @param[in] SaltLen Salt length for PSS encoding.\r
1738\r
1739 @retval TRUE Valid signature encoded in RSASSA-PSS.\r
1740 @retval FALSE Invalid signature or invalid RSA context.\r
1741\r
1742**/\r
1743BOOLEAN\r
1744EFIAPI\r
1745RsaPssVerify (\r
1746 IN VOID *RsaContext,\r
1747 IN CONST UINT8 *Message,\r
1748 IN UINTN MsgSize,\r
1749 IN CONST UINT8 *Signature,\r
1750 IN UINTN SigSize,\r
1751 IN UINT16 DigestLen,\r
1752 IN UINT16 SaltLen\r
1753 );\r
1754\r
4a567c96 1755/**\r
1756 Retrieve the RSA Private Key from the password-protected PEM key data.\r
1757\r
532616bb 1758 If PemData is NULL, then return FALSE.\r
1759 If RsaContext is NULL, then return FALSE.\r
1760 If this interface is not supported, then return FALSE.\r
1761\r
4a567c96 1762 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.\r
1763 @param[in] PemSize Size of the PEM key data in bytes.\r
1764 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.\r
1765 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
1766 RSA private key component. Use RsaFree() function to free the\r
1767 resource.\r
1768\r
4a567c96 1769 @retval TRUE RSA Private Key was retrieved successfully.\r
1770 @retval FALSE Invalid PEM key data or incorrect password.\r
532616bb 1771 @retval FALSE This interface is not supported.\r
4a567c96 1772\r
1773**/\r
1774BOOLEAN\r
1775EFIAPI\r
1776RsaGetPrivateKeyFromPem (\r
1777 IN CONST UINT8 *PemData,\r
1778 IN UINTN PemSize,\r
1779 IN CONST CHAR8 *Password,\r
1780 OUT VOID **RsaContext\r
1781 );\r
1782\r
1783/**\r
1784 Retrieve the RSA Public Key from one DER-encoded X509 certificate.\r
1785\r
532616bb 1786 If Cert is NULL, then return FALSE.\r
1787 If RsaContext is NULL, then return FALSE.\r
1788 If this interface is not supported, then return FALSE.\r
1789\r
4a567c96 1790 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1791 @param[in] CertSize Size of the X509 certificate in bytes.\r
1792 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
1793 RSA public key component. Use RsaFree() function to free the\r
1794 resource.\r
1795\r
4a567c96 1796 @retval TRUE RSA Public Key was retrieved successfully.\r
1797 @retval FALSE Fail to retrieve RSA public key from X509 certificate.\r
532616bb 1798 @retval FALSE This interface is not supported.\r
4a567c96 1799\r
1800**/\r
1801BOOLEAN\r
1802EFIAPI\r
1803RsaGetPublicKeyFromX509 (\r
1804 IN CONST UINT8 *Cert,\r
1805 IN UINTN CertSize,\r
1806 OUT VOID **RsaContext\r
1807 );\r
1808\r
1809/**\r
1810 Retrieve the subject bytes from one X.509 certificate.\r
1811\r
532616bb 1812 If Cert is NULL, then return FALSE.\r
1813 If SubjectSize is NULL, then return FALSE.\r
1814 If this interface is not supported, then return FALSE.\r
1815\r
4a567c96 1816 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1817 @param[in] CertSize Size of the X509 certificate in bytes.\r
1818 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.\r
1819 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,\r
1820 and the size of buffer returned CertSubject on output.\r
1821\r
4a567c96 1822 @retval TRUE The certificate subject retrieved successfully.\r
1823 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.\r
1824 The SubjectSize will be updated with the required size.\r
532616bb 1825 @retval FALSE This interface is not supported.\r
4a567c96 1826\r
1827**/\r
1828BOOLEAN\r
1829EFIAPI\r
1830X509GetSubjectName (\r
1831 IN CONST UINT8 *Cert,\r
1832 IN UINTN CertSize,\r
1833 OUT UINT8 *CertSubject,\r
1834 IN OUT UINTN *SubjectSize\r
1835 );\r
1836\r
5b7c2245
QL
1837/**\r
1838 Retrieve the common name (CN) string from one X.509 certificate.\r
1839\r
1840 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1841 @param[in] CertSize Size of the X509 certificate in bytes.\r
1842 @param[out] CommonName Buffer to contain the retrieved certificate common\r
0b6457ef 1843 name string (UTF8). At most CommonNameSize bytes will be\r
5b7c2245
QL
1844 written and the string will be null terminated. May be\r
1845 NULL in order to determine the size buffer needed.\r
1846 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,\r
1847 and the size of buffer returned CommonName on output.\r
1848 If CommonName is NULL then the amount of space needed\r
1849 in buffer (including the final null) is returned.\r
1850\r
1851 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.\r
1852 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
1853 If CommonNameSize is NULL.\r
1854 If CommonName is not NULL and *CommonNameSize is 0.\r
1855 If Certificate is invalid.\r
1856 @retval RETURN_NOT_FOUND If no CommonName entry exists.\r
1857 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size\r
630f67dd 1858 (including the final null) is returned in the\r
5b7c2245
QL
1859 CommonNameSize parameter.\r
1860 @retval RETURN_UNSUPPORTED The operation is not supported.\r
1861\r
1862**/\r
1863RETURN_STATUS\r
1864EFIAPI\r
1865X509GetCommonName (\r
1866 IN CONST UINT8 *Cert,\r
1867 IN UINTN CertSize,\r
c8f46130 1868 OUT CHAR8 *CommonName OPTIONAL,\r
5b7c2245
QL
1869 IN OUT UINTN *CommonNameSize\r
1870 );\r
1871\r
e2a673b8
BB
1872/**\r
1873 Retrieve the organization name (O) string from one X.509 certificate.\r
1874\r
1875 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1876 @param[in] CertSize Size of the X509 certificate in bytes.\r
1877 @param[out] NameBuffer Buffer to contain the retrieved certificate organization\r
1878 name string. At most NameBufferSize bytes will be\r
1879 written and the string will be null terminated. May be\r
1880 NULL in order to determine the size buffer needed.\r
1881 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,\r
1882 and the size of buffer returned Name on output.\r
1883 If NameBuffer is NULL then the amount of space needed\r
1884 in buffer (including the final null) is returned.\r
1885\r
1886 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.\r
1887 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
1888 If NameBufferSize is NULL.\r
1889 If NameBuffer is not NULL and *CommonNameSize is 0.\r
1890 If Certificate is invalid.\r
1891 @retval RETURN_NOT_FOUND If no Organization Name entry exists.\r
1892 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size\r
1893 (including the final null) is returned in the\r
1894 CommonNameSize parameter.\r
1895 @retval RETURN_UNSUPPORTED The operation is not supported.\r
1896\r
1897**/\r
1898RETURN_STATUS\r
1899EFIAPI\r
1900X509GetOrganizationName (\r
7c342378
MK
1901 IN CONST UINT8 *Cert,\r
1902 IN UINTN CertSize,\r
1903 OUT CHAR8 *NameBuffer OPTIONAL,\r
1904 IN OUT UINTN *NameBufferSize\r
e2a673b8
BB
1905 );\r
1906\r
4a567c96 1907/**\r
1908 Verify one X509 certificate was issued by the trusted CA.\r
1909\r
532616bb 1910 If Cert is NULL, then return FALSE.\r
1911 If CACert is NULL, then return FALSE.\r
1912 If this interface is not supported, then return FALSE.\r
1913\r
4a567c96 1914 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.\r
1915 @param[in] CertSize Size of the X509 certificate in bytes.\r
1916 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.\r
1917 @param[in] CACertSize Size of the CA Certificate in bytes.\r
1918\r
4a567c96 1919 @retval TRUE The certificate was issued by the trusted CA.\r
1920 @retval FALSE Invalid certificate or the certificate was not issued by the given\r
1921 trusted CA.\r
532616bb 1922 @retval FALSE This interface is not supported.\r
4a567c96 1923\r
1924**/\r
1925BOOLEAN\r
1926EFIAPI\r
1927X509VerifyCert (\r
1928 IN CONST UINT8 *Cert,\r
1929 IN UINTN CertSize,\r
1930 IN CONST UINT8 *CACert,\r
1931 IN UINTN CACertSize\r
1932 );\r
1933\r
b7d320f8 1934/**\r
1935 Construct a X509 object from DER-encoded certificate data.\r
1936\r
16d2c32c 1937 If Cert is NULL, then return FALSE.\r
1938 If SingleX509Cert is NULL, then return FALSE.\r
532616bb 1939 If this interface is not supported, then return FALSE.\r
b7d320f8 1940\r
1941 @param[in] Cert Pointer to the DER-encoded certificate data.\r
1942 @param[in] CertSize The size of certificate data in bytes.\r
1943 @param[out] SingleX509Cert The generated X509 object.\r
1944\r
1945 @retval TRUE The X509 object generation succeeded.\r
1946 @retval FALSE The operation failed.\r
532616bb 1947 @retval FALSE This interface is not supported.\r
b7d320f8 1948\r
1949**/\r
1950BOOLEAN\r
1951EFIAPI\r
1952X509ConstructCertificate (\r
1953 IN CONST UINT8 *Cert,\r
1954 IN UINTN CertSize,\r
1955 OUT UINT8 **SingleX509Cert\r
1956 );\r
1957\r
66862136
MK
1958/**\r
1959 Construct a X509 stack object from a list of DER-encoded certificate data.\r
1960\r
1961 If X509Stack is NULL, then return FALSE.\r
1962 If this interface is not supported, then return FALSE.\r
1963\r
1964 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
1965 On output, pointer to the X509 stack object with new\r
1966 inserted X509 certificate.\r
1967 @param[in] Args VA_LIST marker for the variable argument list.\r
1968 A list of DER-encoded single certificate data followed\r
1969 by certificate size. A NULL terminates the list. The\r
1970 pairs are the arguments to X509ConstructCertificate().\r
1971\r
1972 @retval TRUE The X509 stack construction succeeded.\r
1973 @retval FALSE The construction operation failed.\r
1974 @retval FALSE This interface is not supported.\r
1975\r
1976**/\r
1977BOOLEAN\r
1978EFIAPI\r
1979X509ConstructCertificateStackV (\r
1980 IN OUT UINT8 **X509Stack,\r
1981 IN VA_LIST Args\r
1982 );\r
1983\r
b7d320f8 1984/**\r
1985 Construct a X509 stack object from a list of DER-encoded certificate data.\r
1986\r
16d2c32c 1987 If X509Stack is NULL, then return FALSE.\r
532616bb 1988 If this interface is not supported, then return FALSE.\r
b7d320f8 1989\r
952bd229 1990 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
b7d320f8 1991 On output, pointer to the X509 stack object with new\r
1992 inserted X509 certificate.\r
1993 @param ... A list of DER-encoded single certificate data followed\r
1994 by certificate size. A NULL terminates the list. The\r
1995 pairs are the arguments to X509ConstructCertificate().\r
2ac68e8b 1996\r
b7d320f8 1997 @retval TRUE The X509 stack construction succeeded.\r
1998 @retval FALSE The construction operation failed.\r
532616bb 1999 @retval FALSE This interface is not supported.\r
b7d320f8 2000\r
2001**/\r
2002BOOLEAN\r
2003EFIAPI\r
2004X509ConstructCertificateStack (\r
2005 IN OUT UINT8 **X509Stack,\r
2ac68e8b 2006 ...\r
b7d320f8 2007 );\r
2008\r
2009/**\r
2010 Release the specified X509 object.\r
2011\r
532616bb 2012 If the interface is not supported, then ASSERT().\r
b7d320f8 2013\r
2014 @param[in] X509Cert Pointer to the X509 object to be released.\r
2015\r
2016**/\r
2017VOID\r
2018EFIAPI\r
2019X509Free (\r
2020 IN VOID *X509Cert\r
2021 );\r
2022\r
2023/**\r
2024 Release the specified X509 stack object.\r
2025\r
532616bb 2026 If the interface is not supported, then ASSERT().\r
b7d320f8 2027\r
2028 @param[in] X509Stack Pointer to the X509 stack object to be released.\r
2029\r
2030**/\r
2031VOID\r
2032EFIAPI\r
2033X509StackFree (\r
2034 IN VOID *X509Stack\r
2035 );\r
2036\r
12d95665
LQ
2037/**\r
2038 Retrieve the TBSCertificate from one given X.509 certificate.\r
2039\r
2040 @param[in] Cert Pointer to the given DER-encoded X509 certificate.\r
2041 @param[in] CertSize Size of the X509 certificate in bytes.\r
2042 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.\r
2043 @param[out] TBSCertSize Size of the TBS certificate in bytes.\r
2044\r
2045 If Cert is NULL, then return FALSE.\r
2046 If TBSCert is NULL, then return FALSE.\r
2047 If TBSCertSize is NULL, then return FALSE.\r
2048 If this interface is not supported, then return FALSE.\r
2049\r
2050 @retval TRUE The TBSCertificate was retrieved successfully.\r
2051 @retval FALSE Invalid X.509 certificate.\r
2052\r
2053**/\r
2054BOOLEAN\r
2055EFIAPI\r
2056X509GetTBSCert (\r
2057 IN CONST UINT8 *Cert,\r
2058 IN UINTN CertSize,\r
2059 OUT UINT8 **TBSCert,\r
2060 OUT UINTN *TBSCertSize\r
2061 );\r
2062\r
a8f37449
QL
2063/**\r
2064 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0\r
2065 password based encryption key derivation function PBKDF2, as specified in RFC 2898.\r
2066\r
2067 If Password or Salt or OutKey is NULL, then return FALSE.\r
2068 If the hash algorithm could not be determined, then return FALSE.\r
2069 If this interface is not supported, then return FALSE.\r
2070\r
2071 @param[in] PasswordLength Length of input password in bytes.\r
2072 @param[in] Password Pointer to the array for the password.\r
2073 @param[in] SaltLength Size of the Salt in bytes.\r
2074 @param[in] Salt Pointer to the Salt.\r
2075 @param[in] IterationCount Number of iterations to perform. Its value should be\r
2076 greater than or equal to 1.\r
2077 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).\r
2078 NOTE: DigestSize will be used to determine the hash algorithm.\r
2079 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.\r
2080 @param[in] KeyLength Size of the derived key buffer in bytes.\r
2081 @param[out] OutKey Pointer to the output derived key buffer.\r
2082\r
2083 @retval TRUE A key was derived successfully.\r
2084 @retval FALSE One of the pointers was NULL or one of the sizes was too large.\r
2085 @retval FALSE The hash algorithm could not be determined from the digest size.\r
2086 @retval FALSE The key derivation operation failed.\r
2087 @retval FALSE This interface is not supported.\r
2088\r
2089**/\r
2090BOOLEAN\r
2091EFIAPI\r
2092Pkcs5HashPassword (\r
2093 IN UINTN PasswordLength,\r
2094 IN CONST CHAR8 *Password,\r
2095 IN UINTN SaltLength,\r
2096 IN CONST UINT8 *Salt,\r
2097 IN UINTN IterationCount,\r
2098 IN UINTN DigestSize,\r
2099 IN UINTN KeyLength,\r
2100 OUT UINT8 *OutKey\r
2101 );\r
2102\r
aed90bee
BB
2103/**\r
2104 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the\r
2105 encrypted message in a newly allocated buffer.\r
2106\r
2107 Things that can cause a failure include:\r
2108 - X509 key size does not match any known key size.\r
2109 - Fail to parse X509 certificate.\r
2110 - Fail to allocate an intermediate buffer.\r
2111 - Null pointer provided for a non-optional parameter.\r
2112 - Data size is too large for the provided key size (max size is a function of key size\r
2113 and hash digest size).\r
2114\r
2115 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that\r
2116 will be used to encrypt the data.\r
2117 @param[in] PublicKeySize Size of the X509 cert buffer.\r
2118 @param[in] InData Data to be encrypted.\r
2119 @param[in] InDataSize Size of the data buffer.\r
2120 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer\r
2121 to be used when initializing the PRNG. NULL otherwise.\r
2122 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.\r
2123 0 otherwise.\r
2124 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted\r
2125 message.\r
2126 @param[out] EncryptedDataSize Size of the encrypted message buffer.\r
2127\r
2128 @retval TRUE Encryption was successful.\r
2129 @retval FALSE Encryption failed.\r
2130\r
2131**/\r
2132BOOLEAN\r
2133EFIAPI\r
2134Pkcs1v2Encrypt (\r
2135 IN CONST UINT8 *PublicKey,\r
2136 IN UINTN PublicKeySize,\r
2137 IN UINT8 *InData,\r
2138 IN UINTN InDataSize,\r
c8f46130
MK
2139 IN CONST UINT8 *PrngSeed OPTIONAL,\r
2140 IN UINTN PrngSeedSize OPTIONAL,\r
aed90bee
BB
2141 OUT UINT8 **EncryptedData,\r
2142 OUT UINTN *EncryptedDataSize\r
2143 );\r
2144\r
3702637a 2145/**\r
2146 The 3rd parameter of Pkcs7GetSigners will return all embedded\r
2147 X.509 certificate in one given PKCS7 signature. The format is:\r
2148 //\r
2149 // UINT8 CertNumber;\r
2150 // UINT32 Cert1Length;\r
2151 // UINT8 Cert1[];\r
2152 // UINT32 Cert2Length;\r
2153 // UINT8 Cert2[];\r
2154 // ...\r
2155 // UINT32 CertnLength;\r
2156 // UINT8 Certn[];\r
2157 //\r
2158\r
2159 The two following C-structure are used for parsing CertStack more clearly.\r
2160**/\r
2161#pragma pack(1)\r
2162\r
2163typedef struct {\r
2164 UINT32 CertDataLength; // The length in bytes of X.509 certificate.\r
2165 UINT8 CertDataBuffer[0]; // The X.509 certificate content (DER).\r
2166} EFI_CERT_DATA;\r
2167\r
2168typedef struct {\r
7c342378
MK
2169 UINT8 CertNumber; // Number of X.509 certificate.\r
2170 // EFI_CERT_DATA CertArray[]; // An array of X.509 certificate.\r
3702637a 2171} EFI_CERT_STACK;\r
2172\r
2173#pragma pack()\r
2174\r
e8b4eb04 2175/**\r
2176 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:\r
2177 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
2178 in a ContentInfo structure.\r
2179\r
2180 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then\r
2998af86 2181 return FALSE. If P7Length overflow, then return FALSE.\r
532616bb 2182 If this interface is not supported, then return FALSE.\r
e8b4eb04 2183\r
2184 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
2185 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
2186 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.\r
6fe575d0
LQ
2187 It's caller's responsibility to free the buffer with\r
2188 Pkcs7FreeSigners().\r
3702637a 2189 This data structure is EFI_CERT_STACK type.\r
e8b4eb04 2190 @param[out] StackLength Length of signer's certificates in bytes.\r
2191 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.\r
6fe575d0
LQ
2192 It's caller's responsibility to free the buffer with\r
2193 Pkcs7FreeSigners().\r
e8b4eb04 2194 @param[out] CertLength Length of the trusted certificate in bytes.\r
2195\r
2196 @retval TRUE The operation is finished successfully.\r
2197 @retval FALSE Error occurs during the operation.\r
532616bb 2198 @retval FALSE This interface is not supported.\r
e8b4eb04 2199\r
2200**/\r
2201BOOLEAN\r
2202EFIAPI\r
2203Pkcs7GetSigners (\r
2204 IN CONST UINT8 *P7Data,\r
2205 IN UINTN P7Length,\r
2206 OUT UINT8 **CertStack,\r
2207 OUT UINTN *StackLength,\r
2208 OUT UINT8 **TrustedCert,\r
2209 OUT UINTN *CertLength\r
2210 );\r
2211\r
2212/**\r
2213 Wrap function to use free() to free allocated memory for certificates.\r
2214\r
532616bb 2215 If this interface is not supported, then ASSERT().\r
2216\r
e8b4eb04 2217 @param[in] Certs Pointer to the certificates to be freed.\r
2218\r
2219**/\r
2220VOID\r
2221EFIAPI\r
2222Pkcs7FreeSigners (\r
7c342378 2223 IN UINT8 *Certs\r
45419de6
QL
2224 );\r
2225\r
2226/**\r
2227 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:\r
2228 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and\r
2229 unchained to the signer's certificates.\r
2230 The input signed data could be wrapped in a ContentInfo structure.\r
2231\r
2232 @param[in] P7Data Pointer to the PKCS#7 message.\r
2233 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
0f5f6b3d 2234 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's\r
6fe575d0
LQ
2235 certificate. It's caller's responsibility to free the buffer\r
2236 with Pkcs7FreeSigners().\r
3702637a 2237 This data structure is EFI_CERT_STACK type.\r
45419de6
QL
2238 @param[out] ChainLength Length of the chained certificates list buffer in bytes.\r
2239 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's\r
6fe575d0 2240 responsibility to free the buffer with Pkcs7FreeSigners().\r
3702637a 2241 This data structure is EFI_CERT_STACK type.\r
45419de6
QL
2242 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.\r
2243\r
2244 @retval TRUE The operation is finished successfully.\r
2245 @retval FALSE Error occurs during the operation.\r
2246\r
2247**/\r
2248BOOLEAN\r
2249EFIAPI\r
2250Pkcs7GetCertificatesList (\r
2251 IN CONST UINT8 *P7Data,\r
2252 IN UINTN P7Length,\r
2253 OUT UINT8 **SignerChainCerts,\r
2254 OUT UINTN *ChainLength,\r
2255 OUT UINT8 **UnchainCerts,\r
2256 OUT UINTN *UnchainLength\r
e8b4eb04 2257 );\r
2258\r
b7d320f8 2259/**\r
2260 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message\r
2261 Syntax Standard, version 1.5". This interface is only intended to be used for\r
2262 application to perform PKCS#7 functionality validation.\r
2263\r
532616bb 2264 If this interface is not supported, then return FALSE.\r
2265\r
b7d320f8 2266 @param[in] PrivateKey Pointer to the PEM-formatted private key data for\r
2267 data signing.\r
2268 @param[in] PrivateKeySize Size of the PEM private key data in bytes.\r
2269 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM\r
2270 key data.\r
2271 @param[in] InData Pointer to the content to be signed.\r
2272 @param[in] InDataSize Size of InData in bytes.\r
2273 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.\r
2274 @param[in] OtherCerts Pointer to an optional additional set of certificates to\r
2275 include in the PKCS#7 signedData (e.g. any intermediate\r
2276 CAs in the chain).\r
6fe575d0
LQ
2277 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's\r
2278 responsibility to free the buffer with FreePool().\r
b7d320f8 2279 @param[out] SignedDataSize Size of SignedData in bytes.\r
2280\r
2281 @retval TRUE PKCS#7 data signing succeeded.\r
2282 @retval FALSE PKCS#7 data signing failed.\r
532616bb 2283 @retval FALSE This interface is not supported.\r
b7d320f8 2284\r
2285**/\r
2286BOOLEAN\r
2287EFIAPI\r
2288Pkcs7Sign (\r
2289 IN CONST UINT8 *PrivateKey,\r
2290 IN UINTN PrivateKeySize,\r
2291 IN CONST UINT8 *KeyPassword,\r
2292 IN UINT8 *InData,\r
2293 IN UINTN InDataSize,\r
2294 IN UINT8 *SignCert,\r
2295 IN UINT8 *OtherCerts OPTIONAL,\r
2296 OUT UINT8 **SignedData,\r
2297 OUT UINTN *SignedDataSize\r
2298 );\r
2299\r
97f98500 2300/**\r
2998af86 2301 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:\r
e8b4eb04 2302 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
2303 in a ContentInfo structure.\r
97f98500 2304\r
e8b4eb04 2305 If P7Data, TrustedCert or InData is NULL, then return FALSE.\r
2998af86 2306 If P7Length, CertLength or DataLength overflow, then return FALSE.\r
532616bb 2307 If this interface is not supported, then return FALSE.\r
97f98500
HT
2308\r
2309 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
e8b4eb04 2310 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
97f98500
HT
2311 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
2312 is used for certificate chain verification.\r
e8b4eb04 2313 @param[in] CertLength Length of the trusted certificate in bytes.\r
97f98500 2314 @param[in] InData Pointer to the content to be verified.\r
e8b4eb04 2315 @param[in] DataLength Length of InData in bytes.\r
97f98500 2316\r
a8c44645 2317 @retval TRUE The specified PKCS#7 signed data is valid.\r
2318 @retval FALSE Invalid PKCS#7 signed data.\r
532616bb 2319 @retval FALSE This interface is not supported.\r
97f98500
HT
2320\r
2321**/\r
2322BOOLEAN\r
2323EFIAPI\r
2324Pkcs7Verify (\r
2325 IN CONST UINT8 *P7Data,\r
e8b4eb04 2326 IN UINTN P7Length,\r
97f98500 2327 IN CONST UINT8 *TrustedCert,\r
e8b4eb04 2328 IN UINTN CertLength,\r
97f98500 2329 IN CONST UINT8 *InData,\r
e8b4eb04 2330 IN UINTN DataLength\r
a8c44645 2331 );\r
2332\r
1796a394
BB
2333/**\r
2334 This function receives a PKCS7 formatted signature, and then verifies that\r
2335 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity\r
2336 leaf signing certificate.\r
2337 Note that this function does not validate the certificate chain.\r
2338\r
2339 Applications for custom EKU's are quite flexible. For example, a policy EKU\r
2340 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate\r
2341 certificate issued might also contain this EKU, thus constraining the\r
2342 sub-ordinate certificate. Other applications might allow a certificate\r
2343 embedded in a device to specify that other Object Identifiers (OIDs) are\r
2344 present which contains binary data specifying custom capabilities that\r
2345 the device is able to do.\r
2346\r
2347 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array\r
2348 containing the content block with both the signature,\r
2349 the signer's certificate, and any necessary intermediate\r
2350 certificates.\r
2351 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.\r
2352 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of\r
2353 required EKUs that must be present in the signature.\r
2354 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.\r
2355 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's\r
2356 must be present in the leaf signer. If it is\r
2357 FALSE, then we will succeed if we find any\r
2358 of the specified EKU's.\r
2359\r
2360 @retval EFI_SUCCESS The required EKUs were found in the signature.\r
2361 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
2362 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.\r
2363\r
2364**/\r
2365RETURN_STATUS\r
2366EFIAPI\r
2367VerifyEKUsInPkcs7Signature (\r
2368 IN CONST UINT8 *Pkcs7Signature,\r
2369 IN CONST UINT32 SignatureSize,\r
2370 IN CONST CHAR8 *RequiredEKUs[],\r
2371 IN CONST UINT32 RequiredEKUsSize,\r
2372 IN BOOLEAN RequireAllPresent\r
2373 );\r
2374\r
afeb55e4
QL
2375/**\r
2376 Extracts the attached content from a PKCS#7 signed data if existed. The input signed\r
2377 data could be wrapped in a ContentInfo structure.\r
2378\r
2379 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,\r
2998af86 2380 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.\r
afeb55e4
QL
2381\r
2382 Caution: This function may receive untrusted input. So this function will do\r
2383 basic check for PKCS#7 data structure.\r
2384\r
2385 @param[in] P7Data Pointer to the PKCS#7 signed data to process.\r
2386 @param[in] P7Length Length of the PKCS#7 signed data in bytes.\r
2387 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.\r
6fe575d0 2388 It's caller's responsibility to free the buffer with FreePool().\r
afeb55e4
QL
2389 @param[out] ContentSize The size of the extracted content in bytes.\r
2390\r
2391 @retval TRUE The P7Data was correctly formatted for processing.\r
2392 @retval FALSE The P7Data was not correctly formatted for processing.\r
2393\r
0c9fc4b1 2394**/\r
afeb55e4
QL
2395BOOLEAN\r
2396EFIAPI\r
2397Pkcs7GetAttachedContent (\r
2398 IN CONST UINT8 *P7Data,\r
2399 IN UINTN P7Length,\r
2400 OUT VOID **Content,\r
2401 OUT UINTN *ContentSize\r
2402 );\r
2403\r
b7d320f8 2404/**\r
2998af86 2405 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows\r
b7d320f8 2406 Authenticode Portable Executable Signature Format".\r
2407\r
16d2c32c 2408 If AuthData is NULL, then return FALSE.\r
2409 If ImageHash is NULL, then return FALSE.\r
532616bb 2410 If this interface is not supported, then return FALSE.\r
b7d320f8 2411\r
2412 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
2413 PE/COFF image to be verified.\r
2414 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
2415 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
2416 is used for certificate chain verification.\r
2417 @param[in] CertSize Size of the trusted certificate in bytes.\r
2998af86 2418 @param[in] ImageHash Pointer to the original image file hash value. The procedure\r
b7d320f8 2419 for calculating the image hash value is described in Authenticode\r
2420 specification.\r
2421 @param[in] HashSize Size of Image hash value in bytes.\r
2422\r
2423 @retval TRUE The specified Authenticode Signature is valid.\r
2424 @retval FALSE Invalid Authenticode Signature.\r
532616bb 2425 @retval FALSE This interface is not supported.\r
b7d320f8 2426\r
2427**/\r
2428BOOLEAN\r
2429EFIAPI\r
2430AuthenticodeVerify (\r
2431 IN CONST UINT8 *AuthData,\r
2432 IN UINTN DataSize,\r
2433 IN CONST UINT8 *TrustedCert,\r
2434 IN UINTN CertSize,\r
2435 IN CONST UINT8 *ImageHash,\r
2436 IN UINTN HashSize\r
2437 );\r
2438\r
2ac68e8b 2439/**\r
2998af86 2440 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode\r
2ac68e8b
QL
2441 signature.\r
2442\r
2443 If AuthData is NULL, then return FALSE.\r
12d95665 2444 If this interface is not supported, then return FALSE.\r
2ac68e8b
QL
2445\r
2446 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
2447 PE/COFF image to be verified.\r
2448 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
2449 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which\r
2450 is used for TSA certificate chain verification.\r
2451 @param[in] CertSize Size of the trusted certificate in bytes.\r
2452 @param[out] SigningTime Return the time of timestamp generation time if the timestamp\r
2453 signature is valid.\r
2454\r
2455 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.\r
2456 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.\r
2457\r
2458**/\r
2459BOOLEAN\r
2460EFIAPI\r
2461ImageTimestampVerify (\r
2462 IN CONST UINT8 *AuthData,\r
2463 IN UINTN DataSize,\r
2464 IN CONST UINT8 *TsaCert,\r
2465 IN UINTN CertSize,\r
2466 OUT EFI_TIME *SigningTime\r
2467 );\r
2468\r
7c342378 2469// =====================================================================================\r
a8c44645 2470// DH Key Exchange Primitive\r
7c342378 2471// =====================================================================================\r
a8c44645 2472\r
2473/**\r
2474 Allocates and Initializes one Diffie-Hellman Context for subsequent use.\r
2475\r
2476 @return Pointer to the Diffie-Hellman Context that has been initialized.\r
2477 If the allocations fails, DhNew() returns NULL.\r
532616bb 2478 If the interface is not supported, DhNew() returns NULL.\r
a8c44645 2479\r
2480**/\r
2481VOID *\r
2482EFIAPI\r
2483DhNew (\r
2484 VOID\r
2485 );\r
2486\r
2487/**\r
2488 Release the specified DH context.\r
2489\r
532616bb 2490 If the interface is not supported, then ASSERT().\r
a8c44645 2491\r
2492 @param[in] DhContext Pointer to the DH context to be released.\r
2493\r
2494**/\r
2495VOID\r
2496EFIAPI\r
2497DhFree (\r
2498 IN VOID *DhContext\r
2499 );\r
2500\r
2501/**\r
2502 Generates DH parameter.\r
2503\r
2504 Given generator g, and length of prime number p in bits, this function generates p,\r
2505 and sets DH context according to value of g and p.\r
2ac68e8b 2506\r
a8c44645 2507 Before this function can be invoked, pseudorandom number generator must be correctly\r
2508 initialized by RandomSeed().\r
2509\r
16d2c32c 2510 If DhContext is NULL, then return FALSE.\r
2511 If Prime is NULL, then return FALSE.\r
532616bb 2512 If this interface is not supported, then return FALSE.\r
a8c44645 2513\r
2514 @param[in, out] DhContext Pointer to the DH context.\r
2515 @param[in] Generator Value of generator.\r
2516 @param[in] PrimeLength Length in bits of prime to be generated.\r
2517 @param[out] Prime Pointer to the buffer to receive the generated prime number.\r
2518\r
2998af86 2519 @retval TRUE DH parameter generation succeeded.\r
a8c44645 2520 @retval FALSE Value of Generator is not supported.\r
2521 @retval FALSE PRNG fails to generate random prime number with PrimeLength.\r
532616bb 2522 @retval FALSE This interface is not supported.\r
a8c44645 2523\r
2524**/\r
2525BOOLEAN\r
2526EFIAPI\r
2527DhGenerateParameter (\r
2528 IN OUT VOID *DhContext,\r
2529 IN UINTN Generator,\r
2530 IN UINTN PrimeLength,\r
2531 OUT UINT8 *Prime\r
2532 );\r
2533\r
2534/**\r
2535 Sets generator and prime parameters for DH.\r
2536\r
2537 Given generator g, and prime number p, this function and sets DH\r
2538 context accordingly.\r
2539\r
16d2c32c 2540 If DhContext is NULL, then return FALSE.\r
2541 If Prime is NULL, then return FALSE.\r
532616bb 2542 If this interface is not supported, then return FALSE.\r
a8c44645 2543\r
2544 @param[in, out] DhContext Pointer to the DH context.\r
2545 @param[in] Generator Value of generator.\r
2546 @param[in] PrimeLength Length in bits of prime to be generated.\r
2547 @param[in] Prime Pointer to the prime number.\r
2548\r
2998af86 2549 @retval TRUE DH parameter setting succeeded.\r
a8c44645 2550 @retval FALSE Value of Generator is not supported.\r
2551 @retval FALSE Value of Generator is not suitable for the Prime.\r
2552 @retval FALSE Value of Prime is not a prime number.\r
2553 @retval FALSE Value of Prime is not a safe prime number.\r
532616bb 2554 @retval FALSE This interface is not supported.\r
a8c44645 2555\r
2556**/\r
2557BOOLEAN\r
2558EFIAPI\r
2559DhSetParameter (\r
2560 IN OUT VOID *DhContext,\r
2561 IN UINTN Generator,\r
2562 IN UINTN PrimeLength,\r
2563 IN CONST UINT8 *Prime\r
97f98500
HT
2564 );\r
2565\r
a8c44645 2566/**\r
2567 Generates DH public key.\r
2568\r
2ac68e8b 2569 This function generates random secret exponent, and computes the public key, which is\r
a8c44645 2570 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.\r
2571 If the PublicKey buffer is too small to hold the public key, FALSE is returned and\r
2572 PublicKeySize is set to the required buffer size to obtain the public key.\r
2573\r
16d2c32c 2574 If DhContext is NULL, then return FALSE.\r
2575 If PublicKeySize is NULL, then return FALSE.\r
2576 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.\r
532616bb 2577 If this interface is not supported, then return FALSE.\r
a8c44645 2578\r
2579 @param[in, out] DhContext Pointer to the DH context.\r
2580 @param[out] PublicKey Pointer to the buffer to receive generated public key.\r
2581 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.\r
2582 On output, the size of data returned in PublicKey buffer in bytes.\r
2583\r
2584 @retval TRUE DH public key generation succeeded.\r
2585 @retval FALSE DH public key generation failed.\r
2586 @retval FALSE PublicKeySize is not large enough.\r
532616bb 2587 @retval FALSE This interface is not supported.\r
a8c44645 2588\r
2589**/\r
2590BOOLEAN\r
2591EFIAPI\r
2592DhGenerateKey (\r
2593 IN OUT VOID *DhContext,\r
2594 OUT UINT8 *PublicKey,\r
2595 IN OUT UINTN *PublicKeySize\r
2596 );\r
2597\r
2598/**\r
2599 Computes exchanged common key.\r
2600\r
2601 Given peer's public key, this function computes the exchanged common key, based on its own\r
dda39f3a 2602 context including value of prime modulus and random secret exponent.\r
a8c44645 2603\r
16d2c32c 2604 If DhContext is NULL, then return FALSE.\r
2605 If PeerPublicKey is NULL, then return FALSE.\r
2606 If KeySize is NULL, then return FALSE.\r
dda39f3a 2607 If Key is NULL, then return FALSE.\r
2608 If KeySize is not large enough, then return FALSE.\r
532616bb 2609 If this interface is not supported, then return FALSE.\r
a8c44645 2610\r
2611 @param[in, out] DhContext Pointer to the DH context.\r
2612 @param[in] PeerPublicKey Pointer to the peer's public key.\r
2613 @param[in] PeerPublicKeySize Size of peer's public key in bytes.\r
2614 @param[out] Key Pointer to the buffer to receive generated key.\r
2615 @param[in, out] KeySize On input, the size of Key buffer in bytes.\r
2616 On output, the size of data returned in Key buffer in bytes.\r
2617\r
2618 @retval TRUE DH exchanged key generation succeeded.\r
2619 @retval FALSE DH exchanged key generation failed.\r
2620 @retval FALSE KeySize is not large enough.\r
532616bb 2621 @retval FALSE This interface is not supported.\r
a8c44645 2622\r
2623**/\r
2624BOOLEAN\r
2625EFIAPI\r
2626DhComputeKey (\r
2627 IN OUT VOID *DhContext,\r
2628 IN CONST UINT8 *PeerPublicKey,\r
2629 IN UINTN PeerPublicKeySize,\r
2630 OUT UINT8 *Key,\r
2631 IN OUT UINTN *KeySize\r
2632 );\r
2633\r
7c342378 2634// =====================================================================================\r
a8c44645 2635// Pseudo-Random Generation Primitive\r
7c342378 2636// =====================================================================================\r
a8c44645 2637\r
2638/**\r
2639 Sets up the seed value for the pseudorandom number generator.\r
2640\r
2641 This function sets up the seed value for the pseudorandom number generator.\r
2642 If Seed is not NULL, then the seed passed in is used.\r
2643 If Seed is NULL, then default seed is used.\r
532616bb 2644 If this interface is not supported, then return FALSE.\r
a8c44645 2645\r
2646 @param[in] Seed Pointer to seed value.\r
2647 If NULL, default seed is used.\r
2648 @param[in] SeedSize Size of seed value.\r
2649 If Seed is NULL, this parameter is ignored.\r
2650\r
2651 @retval TRUE Pseudorandom number generator has enough entropy for random generation.\r
2652 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.\r
532616bb 2653 @retval FALSE This interface is not supported.\r
a8c44645 2654\r
2655**/\r
2656BOOLEAN\r
2657EFIAPI\r
2658RandomSeed (\r
2659 IN CONST UINT8 *Seed OPTIONAL,\r
2660 IN UINTN SeedSize\r
2661 );\r
2662\r
2663/**\r
2664 Generates a pseudorandom byte stream of the specified size.\r
2665\r
16d2c32c 2666 If Output is NULL, then return FALSE.\r
532616bb 2667 If this interface is not supported, then return FALSE.\r
a8c44645 2668\r
2669 @param[out] Output Pointer to buffer to receive random value.\r
2998af86 2670 @param[in] Size Size of random bytes to generate.\r
a8c44645 2671\r
2672 @retval TRUE Pseudorandom byte stream generated successfully.\r
2673 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.\r
532616bb 2674 @retval FALSE This interface is not supported.\r
a8c44645 2675\r
2676**/\r
2677BOOLEAN\r
2678EFIAPI\r
2679RandomBytes (\r
2680 OUT UINT8 *Output,\r
2681 IN UINTN Size\r
2682 );\r
97f98500 2683\r
7c342378 2684// =====================================================================================\r
4b1b7c19 2685// Key Derivation Function Primitive\r
7c342378 2686// =====================================================================================\r
4b1b7c19
GW
2687\r
2688/**\r
2689 Derive key data using HMAC-SHA256 based KDF.\r
2690\r
2691 @param[in] Key Pointer to the user-supplied key.\r
2692 @param[in] KeySize Key size in bytes.\r
2693 @param[in] Salt Pointer to the salt(non-secret) value.\r
2694 @param[in] SaltSize Salt size in bytes.\r
2695 @param[in] Info Pointer to the application specific info.\r
2696 @param[in] InfoSize Info size in bytes.\r
944bd5cf 2697 @param[out] Out Pointer to buffer to receive hkdf value.\r
4b1b7c19
GW
2698 @param[in] OutSize Size of hkdf bytes to generate.\r
2699\r
2700 @retval TRUE Hkdf generated successfully.\r
2701 @retval FALSE Hkdf generation failed.\r
2702\r
2703**/\r
2704BOOLEAN\r
2705EFIAPI\r
2706HkdfSha256ExtractAndExpand (\r
2707 IN CONST UINT8 *Key,\r
2708 IN UINTN KeySize,\r
2709 IN CONST UINT8 *Salt,\r
2710 IN UINTN SaltSize,\r
2711 IN CONST UINT8 *Info,\r
2712 IN UINTN InfoSize,\r
2713 OUT UINT8 *Out,\r
2714 IN UINTN OutSize\r
2715 );\r
2716\r
13364762
QZ
2717/**\r
2718 Derive SHA256 HMAC-based Extract key Derivation Function (HKDF).\r
2719\r
2720 @param[in] Key Pointer to the user-supplied key.\r
2721 @param[in] KeySize key size in bytes.\r
2722 @param[in] Salt Pointer to the salt(non-secret) value.\r
2723 @param[in] SaltSize salt size in bytes.\r
2724 @param[out] PrkOut Pointer to buffer to receive hkdf value.\r
2725 @param[in] PrkOutSize size of hkdf bytes to generate.\r
2726\r
2727 @retval true Hkdf generated successfully.\r
2728 @retval false Hkdf generation failed.\r
2729\r
2730**/\r
2731BOOLEAN\r
2732EFIAPI\r
2733HkdfSha256Extract (\r
2734 IN CONST UINT8 *Key,\r
2735 IN UINTN KeySize,\r
2736 IN CONST UINT8 *Salt,\r
2737 IN UINTN SaltSize,\r
2738 OUT UINT8 *PrkOut,\r
2739 UINTN PrkOutSize\r
2740 );\r
2741\r
2742/**\r
2743 Derive SHA256 HMAC-based Expand Key Derivation Function (HKDF).\r
2744\r
2745 @param[in] Prk Pointer to the user-supplied key.\r
2746 @param[in] PrkSize Key size in bytes.\r
2747 @param[in] Info Pointer to the application specific info.\r
2748 @param[in] InfoSize Info size in bytes.\r
2749 @param[out] Out Pointer to buffer to receive hkdf value.\r
2750 @param[in] OutSize Size of hkdf bytes to generate.\r
2751\r
2752 @retval TRUE Hkdf generated successfully.\r
2753 @retval FALSE Hkdf generation failed.\r
2754\r
2755**/\r
2756BOOLEAN\r
2757EFIAPI\r
2758HkdfSha256Expand (\r
2759 IN CONST UINT8 *Prk,\r
2760 IN UINTN PrkSize,\r
2761 IN CONST UINT8 *Info,\r
2762 IN UINTN InfoSize,\r
2763 OUT UINT8 *Out,\r
2764 IN UINTN OutSize\r
2765 );\r
2766\r
2767/**\r
2768 Derive SHA384 HMAC-based Extract-and-Expand Key Derivation Function (HKDF).\r
2769\r
2770 @param[in] Key Pointer to the user-supplied key.\r
2771 @param[in] KeySize Key size in bytes.\r
2772 @param[in] Salt Pointer to the salt(non-secret) value.\r
2773 @param[in] SaltSize Salt size in bytes.\r
2774 @param[in] Info Pointer to the application specific info.\r
2775 @param[in] InfoSize Info size in bytes.\r
2776 @param[out] Out Pointer to buffer to receive hkdf value.\r
2777 @param[in] OutSize Size of hkdf bytes to generate.\r
2778\r
2779 @retval TRUE Hkdf generated successfully.\r
2780 @retval FALSE Hkdf generation failed.\r
2781\r
2782**/\r
2783BOOLEAN\r
2784EFIAPI\r
2785HkdfSha384ExtractAndExpand (\r
2786 IN CONST UINT8 *Key,\r
2787 IN UINTN KeySize,\r
2788 IN CONST UINT8 *Salt,\r
2789 IN UINTN SaltSize,\r
2790 IN CONST UINT8 *Info,\r
2791 IN UINTN InfoSize,\r
2792 OUT UINT8 *Out,\r
2793 IN UINTN OutSize\r
2794 );\r
2795\r
2796/**\r
2797 Derive SHA384 HMAC-based Extract key Derivation Function (HKDF).\r
2798\r
2799 @param[in] Key Pointer to the user-supplied key.\r
2800 @param[in] KeySize key size in bytes.\r
2801 @param[in] Salt Pointer to the salt(non-secret) value.\r
2802 @param[in] SaltSize salt size in bytes.\r
2803 @param[out] PrkOut Pointer to buffer to receive hkdf value.\r
2804 @param[in] PrkOutSize size of hkdf bytes to generate.\r
2805\r
2806 @retval true Hkdf generated successfully.\r
2807 @retval false Hkdf generation failed.\r
2808\r
2809**/\r
2810BOOLEAN\r
2811EFIAPI\r
2812HkdfSha384Extract (\r
2813 IN CONST UINT8 *Key,\r
2814 IN UINTN KeySize,\r
2815 IN CONST UINT8 *Salt,\r
2816 IN UINTN SaltSize,\r
2817 OUT UINT8 *PrkOut,\r
2818 UINTN PrkOutSize\r
2819 );\r
2820\r
2821/**\r
2822 Derive SHA384 HMAC-based Expand Key Derivation Function (HKDF).\r
2823\r
2824 @param[in] Prk Pointer to the user-supplied key.\r
2825 @param[in] PrkSize Key size in bytes.\r
2826 @param[in] Info Pointer to the application specific info.\r
2827 @param[in] InfoSize Info size in bytes.\r
2828 @param[out] Out Pointer to buffer to receive hkdf value.\r
2829 @param[in] OutSize Size of hkdf bytes to generate.\r
2830\r
2831 @retval TRUE Hkdf generated successfully.\r
2832 @retval FALSE Hkdf generation failed.\r
2833\r
2834**/\r
2835BOOLEAN\r
2836EFIAPI\r
2837HkdfSha384Expand (\r
2838 IN CONST UINT8 *Prk,\r
2839 IN UINTN PrkSize,\r
2840 IN CONST UINT8 *Info,\r
2841 IN UINTN InfoSize,\r
2842 OUT UINT8 *Out,\r
2843 IN UINTN OutSize\r
2844 );\r
2845\r
fd0ad0c3
YL
2846// =====================================================================================\r
2847// Big number primitives\r
2848// =====================================================================================\r
2849\r
2850/**\r
2851 Allocate new Big Number.\r
2852\r
2853 @retval New BigNum opaque structure or NULL on failure.\r
2854**/\r
2855VOID *\r
2856EFIAPI\r
2857BigNumInit (\r
2858 VOID\r
2859 );\r
2860\r
2861/**\r
2862 Allocate new Big Number and assign the provided value to it.\r
2863\r
2864 @param[in] Buf Big endian encoded buffer.\r
2865 @param[in] Len Buffer length.\r
2866\r
2867 @retval New BigNum opaque structure or NULL on failure.\r
2868**/\r
2869VOID *\r
2870EFIAPI\r
2871BigNumFromBin (\r
2872 IN CONST UINT8 *Buf,\r
2873 IN UINTN Len\r
2874 );\r
2875\r
2876/**\r
2877 Convert the absolute value of Bn into big-endian form and store it at Buf.\r
2878 The Buf array should have at least BigNumBytes() in it.\r
2879\r
2880 @param[in] Bn Big number to convert.\r
2881 @param[out] Buf Output buffer.\r
2882\r
2883 @retval The length of the big-endian number placed at Buf or -1 on error.\r
2884**/\r
2885INTN\r
2886EFIAPI\r
2887BigNumToBin (\r
2888 IN CONST VOID *Bn,\r
2889 OUT UINT8 *Buf\r
2890 );\r
2891\r
2892/**\r
2893 Free the Big Number.\r
2894\r
2895 @param[in] Bn Big number to free.\r
2896 @param[in] Clear TRUE if the buffer should be cleared.\r
2897**/\r
2898VOID\r
2899EFIAPI\r
2900BigNumFree (\r
2901 IN VOID *Bn,\r
2902 IN BOOLEAN Clear\r
2903 );\r
2904\r
2905/**\r
2906 Calculate the sum of two Big Numbers.\r
2907 Please note, all "out" Big number arguments should be properly initialized\r
2908 by calling to BigNumInit() or BigNumFromBin() functions.\r
2909\r
2910 @param[in] BnA Big number.\r
2911 @param[in] BnB Big number.\r
2912 @param[out] BnRes The result of BnA + BnB.\r
2913\r
2914 @retval TRUE On success.\r
2915 @retval FALSE Otherwise.\r
2916**/\r
2917BOOLEAN\r
2918EFIAPI\r
2919BigNumAdd (\r
2920 IN CONST VOID *BnA,\r
2921 IN CONST VOID *BnB,\r
2922 OUT VOID *BnRes\r
2923 );\r
2924\r
2925/**\r
2926 Subtract two Big Numbers.\r
2927 Please note, all "out" Big number arguments should be properly initialized\r
2928 by calling to BigNumInit() or BigNumFromBin() functions.\r
2929\r
2930 @param[in] BnA Big number.\r
2931 @param[in] BnB Big number.\r
2932 @param[out] BnRes The result of BnA - BnB.\r
2933\r
2934 @retval TRUE On success.\r
2935 @retval FALSE Otherwise.\r
2936**/\r
2937BOOLEAN\r
2938EFIAPI\r
2939BigNumSub (\r
2940 IN CONST VOID *BnA,\r
2941 IN CONST VOID *BnB,\r
2942 OUT VOID *BnRes\r
2943 );\r
2944\r
2945/**\r
2946 Calculate remainder: BnRes = BnA % BnB.\r
2947 Please note, all "out" Big number arguments should be properly initialized\r
2948 by calling to BigNumInit() or BigNumFromBin() functions.\r
2949\r
2950 @param[in] BnA Big number.\r
2951 @param[in] BnB Big number.\r
2952 @param[out] BnRes The result of BnA % BnB.\r
2953\r
2954 @retval TRUE On success.\r
2955 @retval FALSE Otherwise.\r
2956**/\r
2957BOOLEAN\r
2958EFIAPI\r
2959BigNumMod (\r
2960 IN CONST VOID *BnA,\r
2961 IN CONST VOID *BnB,\r
2962 OUT VOID *BnRes\r
2963 );\r
2964\r
2965/**\r
2966 Compute BnA to the BnP-th power modulo BnM.\r
2967 Please note, all "out" Big number arguments should be properly initialized\r
2968 by calling to BigNumInit() or BigNumFromBin() functions.\r
2969\r
2970 @param[in] BnA Big number.\r
2971 @param[in] BnP Big number (power).\r
2972 @param[in] BnM Big number (modulo).\r
2973 @param[out] BnRes The result of (BnA ^ BnP) % BnM.\r
2974\r
2975 @retval TRUE On success.\r
2976 @retval FALSE Otherwise.\r
2977**/\r
2978BOOLEAN\r
2979EFIAPI\r
2980BigNumExpMod (\r
2981 IN CONST VOID *BnA,\r
2982 IN CONST VOID *BnP,\r
2983 IN CONST VOID *BnM,\r
2984 OUT VOID *BnRes\r
2985 );\r
2986\r
2987/**\r
2988 Compute BnA inverse modulo BnM.\r
2989 Please note, all "out" Big number arguments should be properly initialized\r
2990 by calling to BigNumInit() or BigNumFromBin() functions.\r
2991\r
2992 @param[in] BnA Big number.\r
2993 @param[in] BnM Big number (modulo).\r
2994 @param[out] BnRes The result, such that (BnA * BnRes) % BnM == 1.\r
2995\r
2996 @retval TRUE On success.\r
2997 @retval FALSE Otherwise.\r
2998**/\r
2999BOOLEAN\r
3000EFIAPI\r
3001BigNumInverseMod (\r
3002 IN CONST VOID *BnA,\r
3003 IN CONST VOID *BnM,\r
3004 OUT VOID *BnRes\r
3005 );\r
3006\r
3007/**\r
3008 Divide two Big Numbers.\r
3009 Please note, all "out" Big number arguments should be properly initialized\r
3010 by calling to BigNumInit() or BigNumFromBin() functions.\r
3011\r
3012 @param[in] BnA Big number.\r
3013 @param[in] BnB Big number.\r
3014 @param[out] BnRes The result, such that BnA / BnB.\r
3015\r
3016 @retval TRUE On success.\r
3017 @retval FALSE Otherwise.\r
3018**/\r
3019BOOLEAN\r
3020EFIAPI\r
3021BigNumDiv (\r
3022 IN CONST VOID *BnA,\r
3023 IN CONST VOID *BnB,\r
3024 OUT VOID *BnRes\r
3025 );\r
3026\r
3027/**\r
3028 Multiply two Big Numbers modulo BnM.\r
3029 Please note, all "out" Big number arguments should be properly initialized\r
3030 by calling to BigNumInit() or BigNumFromBin() functions.\r
3031\r
3032 @param[in] BnA Big number.\r
3033 @param[in] BnB Big number.\r
3034 @param[in] BnM Big number (modulo).\r
3035 @param[out] BnRes The result, such that (BnA * BnB) % BnM.\r
3036\r
3037 @retval TRUE On success.\r
3038 @retval FALSE Otherwise.\r
3039**/\r
3040BOOLEAN\r
3041EFIAPI\r
3042BigNumMulMod (\r
3043 IN CONST VOID *BnA,\r
3044 IN CONST VOID *BnB,\r
3045 IN CONST VOID *BnM,\r
3046 OUT VOID *BnRes\r
3047 );\r
3048\r
3049/**\r
3050 Compare two Big Numbers.\r
3051\r
3052 @param[in] BnA Big number.\r
3053 @param[in] BnB Big number.\r
3054\r
3055 @retval 0 BnA == BnB.\r
3056 @retval 1 BnA > BnB.\r
3057 @retval -1 BnA < BnB.\r
3058**/\r
3059INTN\r
3060EFIAPI\r
3061BigNumCmp (\r
3062 IN CONST VOID *BnA,\r
3063 IN CONST VOID *BnB\r
3064 );\r
3065\r
3066/**\r
3067 Get number of bits in Bn.\r
3068\r
3069 @param[in] Bn Big number.\r
3070\r
3071 @retval Number of bits.\r
3072**/\r
3073\r
3074UINTN\r
3075EFIAPI\r
3076BigNumBits (\r
3077 IN CONST VOID *Bn\r
3078 );\r
3079\r
3080/**\r
3081 Get number of bytes in Bn.\r
3082\r
3083 @param[in] Bn Big number.\r
3084\r
3085 @retval Number of bytes.\r
3086**/\r
3087UINTN\r
3088EFIAPI\r
3089BigNumBytes (\r
3090 IN CONST VOID *Bn\r
3091 );\r
3092\r
3093/**\r
3094 Checks if Big Number equals to the given Num.\r
3095\r
3096 @param[in] Bn Big number.\r
3097 @param[in] Num Number.\r
3098\r
3099 @retval TRUE iff Bn == Num.\r
3100 @retval FALSE otherwise.\r
3101**/\r
3102BOOLEAN\r
3103EFIAPI\r
3104BigNumIsWord (\r
3105 IN CONST VOID *Bn,\r
3106 IN UINTN Num\r
3107 );\r
3108\r
3109/**\r
3110 Checks if Big Number is odd.\r
3111\r
3112 @param[in] Bn Big number.\r
3113\r
3114 @retval TRUE Bn is odd (Bn % 2 == 1).\r
3115 @retval FALSE otherwise.\r
3116**/\r
3117BOOLEAN\r
3118EFIAPI\r
3119BigNumIsOdd (\r
3120 IN CONST VOID *Bn\r
3121 );\r
3122\r
3123/**\r
3124 Copy Big number.\r
3125\r
3126 @param[out] BnDst Destination.\r
3127 @param[in] BnSrc Source.\r
3128\r
3129 @retval BnDst on success.\r
3130 @retval NULL otherwise.\r
3131**/\r
3132VOID *\r
3133EFIAPI\r
3134BigNumCopy (\r
3135 OUT VOID *BnDst,\r
3136 IN CONST VOID *BnSrc\r
3137 );\r
3138\r
3139/**\r
3140 Get constant Big number with value of "1".\r
3141 This may be used to save expensive allocations.\r
3142\r
3143 @retval Big Number with value of 1.\r
3144**/\r
3145CONST VOID *\r
3146EFIAPI\r
3147BigNumValueOne (\r
3148 VOID\r
3149 );\r
3150\r
3151/**\r
3152 Shift right Big Number.\r
3153 Please note, all "out" Big number arguments should be properly initialized\r
3154 by calling to BigNumInit() or BigNumFromBin() functions.\r
3155\r
3156 @param[in] Bn Big number.\r
3157 @param[in] N Number of bits to shift.\r
3158 @param[out] BnRes The result.\r
3159\r
3160 @retval TRUE On success.\r
3161 @retval FALSE Otherwise.\r
3162**/\r
3163BOOLEAN\r
3164EFIAPI\r
3165BigNumRShift (\r
3166 IN CONST VOID *Bn,\r
3167 IN UINTN N,\r
3168 OUT VOID *BnRes\r
3169 );\r
3170\r
3171/**\r
3172 Mark Big Number for constant time computations.\r
3173 This function should be called before any constant time computations are\r
3174 performed on the given Big number.\r
3175\r
3176 @param[in] Bn Big number.\r
3177**/\r
3178VOID\r
3179EFIAPI\r
3180BigNumConstTime (\r
3181 IN VOID *Bn\r
3182 );\r
3183\r
3184/**\r
3185 Calculate square modulo.\r
3186 Please note, all "out" Big number arguments should be properly initialized\r
3187 by calling to BigNumInit() or BigNumFromBin() functions.\r
3188\r
3189 @param[in] BnA Big number.\r
3190 @param[in] BnM Big number (modulo).\r
3191 @param[out] BnRes The result, such that (BnA ^ 2) % BnM.\r
3192\r
3193 @retval TRUE On success.\r
3194 @retval FALSE Otherwise.\r
3195**/\r
3196BOOLEAN\r
3197EFIAPI\r
3198BigNumSqrMod (\r
3199 IN CONST VOID *BnA,\r
3200 IN CONST VOID *BnM,\r
3201 OUT VOID *BnRes\r
3202 );\r
3203\r
3204/**\r
3205 Create new Big Number computation context. This is an opaque structure\r
3206 which should be passed to any function that requires it. The BN context is\r
3207 needed to optimize calculations and expensive allocations.\r
3208\r
3209 @retval Big Number context struct or NULL on failure.\r
3210**/\r
3211VOID *\r
3212EFIAPI\r
3213BigNumNewContext (\r
3214 VOID\r
3215 );\r
3216\r
3217/**\r
3218 Free Big Number context that was allocated with BigNumNewContext().\r
3219\r
3220 @param[in] BnCtx Big number context to free.\r
3221**/\r
3222VOID\r
3223EFIAPI\r
3224BigNumContextFree (\r
3225 IN VOID *BnCtx\r
3226 );\r
3227\r
3228/**\r
3229 Set Big Number to a given value.\r
3230\r
3231 @param[in] Bn Big number to set.\r
3232 @param[in] Val Value to set.\r
3233\r
3234 @retval TRUE On success.\r
3235 @retval FALSE Otherwise.\r
3236**/\r
3237BOOLEAN\r
3238EFIAPI\r
3239BigNumSetUint (\r
3240 IN VOID *Bn,\r
3241 IN UINTN Val\r
3242 );\r
3243\r
3244/**\r
3245 Add two Big Numbers modulo BnM.\r
3246\r
3247 @param[in] BnA Big number.\r
3248 @param[in] BnB Big number.\r
3249 @param[in] BnM Big number (modulo).\r
3250 @param[out] BnRes The result, such that (BnA + BnB) % BnM.\r
3251\r
3252 @retval TRUE On success.\r
3253 @retval FALSE Otherwise.\r
3254**/\r
3255BOOLEAN\r
3256EFIAPI\r
3257BigNumAddMod (\r
3258 IN CONST VOID *BnA,\r
3259 IN CONST VOID *BnB,\r
3260 IN CONST VOID *BnM,\r
3261 OUT VOID *BnRes\r
3262 );\r
3263\r
988e4d8f
YL
3264// =====================================================================================\r
3265// Basic Elliptic Curve Primitives\r
3266// =====================================================================================\r
3267\r
3268/**\r
3269 Initialize new opaque EcGroup object. This object represents an EC curve and\r
3270 and is used for calculation within this group. This object should be freed\r
3271 using EcGroupFree() function.\r
3272\r
3273 @param[in] CryptoNid Identifying number for the ECC curve (Defined in\r
3274 BaseCryptLib.h).\r
3275\r
3276 @retval EcGroup object On success.\r
3277 @retval NULL On failure.\r
3278**/\r
3279VOID *\r
3280EFIAPI\r
3281EcGroupInit (\r
3282 IN UINTN CryptoNid\r
3283 );\r
3284\r
3285/**\r
3286 Get EC curve parameters. While elliptic curve equation is Y^2 mod P = (X^3 + AX + B) Mod P.\r
3287 This function will set the provided Big Number objects to the corresponding\r
3288 values. The caller needs to make sure all the "out" BigNumber parameters\r
3289 are properly initialized.\r
3290\r
3291 @param[in] EcGroup EC group object.\r
3292 @param[out] BnPrime Group prime number.\r
3293 @param[out] BnA A coefficient.\r
3294 @param[out] BnB B coefficient.\r
3295 @param[in] BnCtx BN context.\r
3296\r
3297 @retval TRUE On success.\r
3298 @retval FALSE Otherwise.\r
3299**/\r
3300BOOLEAN\r
3301EFIAPI\r
3302EcGroupGetCurve (\r
3303 IN CONST VOID *EcGroup,\r
3304 OUT VOID *BnPrime,\r
3305 OUT VOID *BnA,\r
3306 OUT VOID *BnB,\r
3307 IN VOID *BnCtx\r
3308 );\r
3309\r
3310/**\r
3311 Get EC group order.\r
3312 This function will set the provided Big Number object to the corresponding\r
3313 value. The caller needs to make sure that the "out" BigNumber parameter\r
3314 is properly initialized.\r
3315\r
3316 @param[in] EcGroup EC group object.\r
3317 @param[out] BnOrder Group prime number.\r
3318\r
3319 @retval TRUE On success.\r
3320 @retval FALSE Otherwise.\r
3321**/\r
3322BOOLEAN\r
3323EFIAPI\r
3324EcGroupGetOrder (\r
3325 IN VOID *EcGroup,\r
3326 OUT VOID *BnOrder\r
3327 );\r
3328\r
3329/**\r
3330 Free previously allocated EC group object using EcGroupInit().\r
3331\r
3332 @param[in] EcGroup EC group object to free.\r
3333**/\r
3334VOID\r
3335EFIAPI\r
3336EcGroupFree (\r
3337 IN VOID *EcGroup\r
3338 );\r
3339\r
3340/**\r
3341 Initialize new opaque EC Point object. This object represents an EC point\r
3342 within the given EC group (curve).\r
3343\r
3344 @param[in] EC Group, properly initialized using EcGroupInit().\r
3345\r
3346 @retval EC Point object On success.\r
3347 @retval NULL On failure.\r
3348**/\r
3349VOID *\r
3350EFIAPI\r
3351EcPointInit (\r
3352 IN CONST VOID *EcGroup\r
3353 );\r
3354\r
3355/**\r
3356 Free previously allocated EC Point object using EcPointInit().\r
3357\r
3358 @param[in] EcPoint EC Point to free.\r
3359 @param[in] Clear TRUE iff the memory should be cleared.\r
3360**/\r
3361VOID\r
3362EFIAPI\r
3363EcPointDeInit (\r
3364 IN VOID *EcPoint,\r
3365 IN BOOLEAN Clear\r
3366 );\r
3367\r
3368/**\r
3369 Get EC point affine (x,y) coordinates.\r
3370 This function will set the provided Big Number objects to the corresponding\r
3371 values. The caller needs to make sure all the "out" BigNumber parameters\r
3372 are properly initialized.\r
3373\r
3374 @param[in] EcGroup EC group object.\r
3375 @param[in] EcPoint EC point object.\r
3376 @param[out] BnX X coordinate.\r
3377 @param[out] BnY Y coordinate.\r
3378 @param[in] BnCtx BN context, created with BigNumNewContext().\r
3379\r
3380 @retval TRUE On success.\r
3381 @retval FALSE Otherwise.\r
3382**/\r
3383BOOLEAN\r
3384EFIAPI\r
3385EcPointGetAffineCoordinates (\r
3386 IN CONST VOID *EcGroup,\r
3387 IN CONST VOID *EcPoint,\r
3388 OUT VOID *BnX,\r
3389 OUT VOID *BnY,\r
3390 IN VOID *BnCtx\r
3391 );\r
3392\r
3393/**\r
3394 Set EC point affine (x,y) coordinates.\r
3395\r
3396 @param[in] EcGroup EC group object.\r
3397 @param[in] EcPoint EC point object.\r
3398 @param[in] BnX X coordinate.\r
3399 @param[in] BnY Y coordinate.\r
3400 @param[in] BnCtx BN context, created with BigNumNewContext().\r
3401\r
3402 @retval TRUE On success.\r
3403 @retval FALSE Otherwise.\r
3404**/\r
3405BOOLEAN\r
3406EFIAPI\r
3407EcPointSetAffineCoordinates (\r
3408 IN CONST VOID *EcGroup,\r
3409 IN VOID *EcPoint,\r
3410 IN CONST VOID *BnX,\r
3411 IN CONST VOID *BnY,\r
3412 IN VOID *BnCtx\r
3413 );\r
3414\r
3415/**\r
3416 EC Point addition. EcPointResult = EcPointA + EcPointB.\r
3417\r
3418 @param[in] EcGroup EC group object.\r
3419 @param[out] EcPointResult EC point to hold the result. The point should\r
3420 be properly initialized.\r
3421 @param[in] EcPointA EC Point.\r
3422 @param[in] EcPointB EC Point.\r
3423 @param[in] BnCtx BN context, created with BigNumNewContext().\r
3424\r
3425 @retval TRUE On success.\r
3426 @retval FALSE Otherwise.\r
3427**/\r
3428BOOLEAN\r
3429EFIAPI\r
3430EcPointAdd (\r
3431 IN CONST VOID *EcGroup,\r
3432 OUT VOID *EcPointResult,\r
3433 IN CONST VOID *EcPointA,\r
3434 IN CONST VOID *EcPointB,\r
3435 IN VOID *BnCtx\r
3436 );\r
3437\r
3438/**\r
3439 Variable EC point multiplication. EcPointResult = EcPoint * BnPScalar.\r
3440\r
3441 @param[in] EcGroup EC group object.\r
3442 @param[out] EcPointResult EC point to hold the result. The point should\r
3443 be properly initialized.\r
3444 @param[in] EcPoint EC Point.\r
3445 @param[in] BnPScalar P Scalar.\r
3446 @param[in] BnCtx BN context, created with BigNumNewContext().\r
3447\r
3448 @retval TRUE On success.\r
3449 @retval FALSE Otherwise.\r
3450**/\r
3451BOOLEAN\r
3452EFIAPI\r
3453EcPointMul (\r
3454 IN CONST VOID *EcGroup,\r
3455 OUT VOID *EcPointResult,\r
3456 IN CONST VOID *EcPoint,\r
3457 IN CONST VOID *BnPScalar,\r
3458 IN VOID *BnCtx\r
3459 );\r
3460\r
3461/**\r
3462 Calculate the inverse of the supplied EC point.\r
3463\r
3464 @param[in] EcGroup EC group object.\r
3465 @param[in,out] EcPoint EC point to invert.\r
3466 @param[in] BnCtx BN context, created with BigNumNewContext().\r
3467\r
3468 @retval TRUE On success.\r
3469 @retval FALSE Otherwise.\r
3470**/\r
3471BOOLEAN\r
3472EFIAPI\r
3473EcPointInvert (\r
3474 IN CONST VOID *EcGroup,\r
3475 IN OUT VOID *EcPoint,\r
3476 IN VOID *BnCtx\r
3477 );\r
3478\r
3479/**\r
3480 Check if the supplied point is on EC curve.\r
3481\r
3482 @param[in] EcGroup EC group object.\r
3483 @param[in] EcPoint EC point to check.\r
3484 @param[in] BnCtx BN context, created with BigNumNewContext().\r
3485\r
3486 @retval TRUE On curve.\r
3487 @retval FALSE Otherwise.\r
3488**/\r
3489BOOLEAN\r
3490EFIAPI\r
3491EcPointIsOnCurve (\r
3492 IN CONST VOID *EcGroup,\r
3493 IN CONST VOID *EcPoint,\r
3494 IN VOID *BnCtx\r
3495 );\r
3496\r
3497/**\r
3498 Check if the supplied point is at infinity.\r
3499\r
3500 @param[in] EcGroup EC group object.\r
3501 @param[in] EcPoint EC point to check.\r
3502\r
3503 @retval TRUE At infinity.\r
3504 @retval FALSE Otherwise.\r
3505**/\r
3506BOOLEAN\r
3507EFIAPI\r
3508EcPointIsAtInfinity (\r
3509 IN CONST VOID *EcGroup,\r
3510 IN CONST VOID *EcPoint\r
3511 );\r
3512\r
3513/**\r
3514 Check if EC points are equal.\r
3515\r
3516 @param[in] EcGroup EC group object.\r
3517 @param[in] EcPointA EC point A.\r
3518 @param[in] EcPointB EC point B.\r
3519 @param[in] BnCtx BN context, created with BigNumNewContext().\r
3520\r
3521 @retval TRUE A == B.\r
3522 @retval FALSE Otherwise.\r
3523**/\r
3524BOOLEAN\r
3525EFIAPI\r
3526EcPointEqual (\r
3527 IN CONST VOID *EcGroup,\r
3528 IN CONST VOID *EcPointA,\r
3529 IN CONST VOID *EcPointB,\r
3530 IN VOID *BnCtx\r
3531 );\r
3532\r
3533/**\r
3534 Set EC point compressed coordinates. Points can be described in terms of\r
3535 their compressed coordinates. For a point (x, y), for any given value for x\r
3536 such that the point is on the curve there will only ever be two possible\r
3537 values for y. Therefore, a point can be set using this function where BnX is\r
3538 the x coordinate and YBit is a value 0 or 1 to identify which of the two\r
3539 possible values for y should be used.\r
3540\r
3541 @param[in] EcGroup EC group object.\r
3542 @param[in] EcPoint EC Point.\r
3543 @param[in] BnX X coordinate.\r
3544 @param[in] YBit 0 or 1 to identify which Y value is used.\r
3545 @param[in] BnCtx BN context, created with BigNumNewContext().\r
3546\r
3547 @retval TRUE On success.\r
3548 @retval FALSE Otherwise.\r
3549**/\r
3550BOOLEAN\r
3551EFIAPI\r
3552EcPointSetCompressedCoordinates (\r
3553 IN CONST VOID *EcGroup,\r
3554 IN VOID *EcPoint,\r
3555 IN CONST VOID *BnX,\r
3556 IN UINT8 YBit,\r
3557 IN VOID *BnCtx\r
3558 );\r
3559\r
3560// =====================================================================================\r
3561// Elliptic Curve Diffie Hellman Primitives\r
3562// =====================================================================================\r
3563\r
3564/**\r
3565 Allocates and Initializes one Elliptic Curve Context for subsequent use\r
3566 with the NID.\r
3567\r
3568 @param[in] Nid cipher NID\r
3569 @return Pointer to the Elliptic Curve Context that has been initialized.\r
3570 If the allocations fails, EcNewByNid() returns NULL.\r
3571**/\r
3572VOID *\r
3573EFIAPI\r
3574EcNewByNid (\r
3575 IN UINTN Nid\r
3576 );\r
3577\r
3578/**\r
3579 Release the specified EC context.\r
3580\r
3581 @param[in] EcContext Pointer to the EC context to be released.\r
3582**/\r
3583VOID\r
3584EFIAPI\r
3585EcFree (\r
3586 IN VOID *EcContext\r
3587 );\r
3588\r
3589/**\r
3590 Generates EC key and returns EC public key (X, Y), Please note, this function uses\r
3591 pseudo random number generator. The caller must make sure RandomSeed()\r
3592 function was properly called before.\r
3593 The Ec context should be correctly initialized by EcNewByNid.\r
3594 This function generates random secret, and computes the public key (X, Y), which is\r
3595 returned via parameter Public, PublicSize.\r
3596 X is the first half of Public with size being PublicSize / 2,\r
3597 Y is the second half of Public with size being PublicSize / 2.\r
3598 EC context is updated accordingly.\r
3599 If the Public buffer is too small to hold the public X, Y, FALSE is returned and\r
3600 PublicSize is set to the required buffer size to obtain the public X, Y.\r
3601 For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.\r
3602 For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.\r
3603 For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.\r
3604 If EcContext is NULL, then return FALSE.\r
3605 If PublicSize is NULL, then return FALSE.\r
3606 If PublicSize is large enough but Public is NULL, then return FALSE.\r
3607 @param[in, out] EcContext Pointer to the EC context.\r
3608 @param[out] PublicKey Pointer to t buffer to receive generated public X,Y.\r
3609 @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.\r
3610 On output, the size of data returned in Public buffer in bytes.\r
3611 @retval TRUE EC public X,Y generation succeeded.\r
3612 @retval FALSE EC public X,Y generation failed.\r
3613 @retval FALSE PublicKeySize is not large enough.\r
3614**/\r
3615BOOLEAN\r
3616EFIAPI\r
3617EcGenerateKey (\r
3618 IN OUT VOID *EcContext,\r
3619 OUT UINT8 *PublicKey,\r
3620 IN OUT UINTN *PublicKeySize\r
3621 );\r
3622\r
3623/**\r
3624 Gets the public key component from the established EC context.\r
3625 The Ec context should be correctly initialized by EcNewByNid, and successfully\r
3626 generate key pair from EcGenerateKey().\r
3627 For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.\r
3628 For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.\r
3629 For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.\r
3630 @param[in, out] EcContext Pointer to EC context being set.\r
3631 @param[out] PublicKey Pointer to t buffer to receive generated public X,Y.\r
3632 @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.\r
3633 On output, the size of data returned in Public buffer in bytes.\r
3634 @retval TRUE EC key component was retrieved successfully.\r
3635 @retval FALSE Invalid EC key component.\r
3636**/\r
3637BOOLEAN\r
3638EFIAPI\r
3639EcGetPubKey (\r
3640 IN OUT VOID *EcContext,\r
3641 OUT UINT8 *PublicKey,\r
3642 IN OUT UINTN *PublicKeySize\r
3643 );\r
3644\r
3645/**\r
3646 Computes exchanged common key.\r
3647 Given peer's public key (X, Y), this function computes the exchanged common key,\r
3648 based on its own context including value of curve parameter and random secret.\r
3649 X is the first half of PeerPublic with size being PeerPublicSize / 2,\r
3650 Y is the second half of PeerPublic with size being PeerPublicSize / 2.\r
3651 If EcContext is NULL, then return FALSE.\r
3652 If PeerPublic is NULL, then return FALSE.\r
3653 If PeerPublicSize is 0, then return FALSE.\r
3654 If Key is NULL, then return FALSE.\r
3655 If KeySize is not large enough, then return FALSE.\r
3656 For P-256, the PeerPublicSize is 64. First 32-byte is X, Second 32-byte is Y.\r
3657 For P-384, the PeerPublicSize is 96. First 48-byte is X, Second 48-byte is Y.\r
3658 For P-521, the PeerPublicSize is 132. First 66-byte is X, Second 66-byte is Y.\r
3659 @param[in, out] EcContext Pointer to the EC context.\r
3660 @param[in] PeerPublic Pointer to the peer's public X,Y.\r
3661 @param[in] PeerPublicSize Size of peer's public X,Y in bytes.\r
3662 @param[in] CompressFlag Flag of PeerPublic is compressed or not.\r
3663 @param[out] Key Pointer to the buffer to receive generated key.\r
3664 @param[in, out] KeySize On input, the size of Key buffer in bytes.\r
3665 On output, the size of data returned in Key buffer in bytes.\r
3666 @retval TRUE EC exchanged key generation succeeded.\r
3667 @retval FALSE EC exchanged key generation failed.\r
3668 @retval FALSE KeySize is not large enough.\r
3669**/\r
3670BOOLEAN\r
3671EFIAPI\r
3672EcDhComputeKey (\r
3673 IN OUT VOID *EcContext,\r
3674 IN CONST UINT8 *PeerPublic,\r
3675 IN UINTN PeerPublicSize,\r
3676 IN CONST INT32 *CompressFlag,\r
3677 OUT UINT8 *Key,\r
3678 IN OUT UINTN *KeySize\r
3679 );\r
3680\r
afeb55e4 3681#endif // __BASE_CRYPT_LIB_H__\r