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