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