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