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