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