]> git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Include/Library/BaseCryptLib.h
CryptoPkg: Remove deprecated function usage in X509GetCommonName()
[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 - 2018, 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 initialized 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 initialized 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 initialized 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 initialized 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 initialized 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 initialized 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 initialized 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 initialized 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 initialized 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 initialized 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 initialized 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 initialized 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 (NOTE: This API is deprecated.
901 Use HmacMd5New() / HmacMd5Free() for HMAC-MD5 Context operations.)
902
903 If this interface is not supported, then return zero.
904
905 @return The size, in bytes, of the context buffer required for HMAC-MD5 operations.
906 @retval 0 This interface is not supported.
907
908 **/
909 UINTN
910 EFIAPI
911 HmacMd5GetContextSize (
912 VOID
913 );
914
915 /**
916 Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD5 use.
917
918 If this interface is not supported, then return NULL.
919
920 @return Pointer to the HMAC_CTX context that has been initialized.
921 If the allocations fails, HmacMd5New() returns NULL.
922 @retval NULL This interface is not supported.
923
924 **/
925 VOID *
926 EFIAPI
927 HmacMd5New (
928 VOID
929 );
930
931 /**
932 Release the specified HMAC_CTX context.
933
934 If this interface is not supported, then do nothing.
935
936 @param[in] HmacMd5Ctx Pointer to the HMAC_CTX context to be released.
937
938 **/
939 VOID
940 EFIAPI
941 HmacMd5Free (
942 IN VOID *HmacMd5Ctx
943 );
944
945 /**
946 Initializes user-supplied memory pointed by HmacMd5Context as HMAC-MD5 context for
947 subsequent use.
948
949 If HmacMd5Context is NULL, then return FALSE.
950 If this interface is not supported, then return FALSE.
951
952 @param[out] HmacMd5Context Pointer to HMAC-MD5 context being initialized.
953 @param[in] Key Pointer to the user-supplied key.
954 @param[in] KeySize Key size in bytes.
955
956 @retval TRUE HMAC-MD5 context initialization succeeded.
957 @retval FALSE HMAC-MD5 context initialization failed.
958 @retval FALSE This interface is not supported.
959
960 **/
961 BOOLEAN
962 EFIAPI
963 HmacMd5Init (
964 OUT VOID *HmacMd5Context,
965 IN CONST UINT8 *Key,
966 IN UINTN KeySize
967 );
968
969 /**
970 Makes a copy of an existing HMAC-MD5 context.
971
972 If HmacMd5Context is NULL, then return FALSE.
973 If NewHmacMd5Context is NULL, then return FALSE.
974 If this interface is not supported, then return FALSE.
975
976 @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied.
977 @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context.
978
979 @retval TRUE HMAC-MD5 context copy succeeded.
980 @retval FALSE HMAC-MD5 context copy failed.
981 @retval FALSE This interface is not supported.
982
983 **/
984 BOOLEAN
985 EFIAPI
986 HmacMd5Duplicate (
987 IN CONST VOID *HmacMd5Context,
988 OUT VOID *NewHmacMd5Context
989 );
990
991 /**
992 Digests the input data and updates HMAC-MD5 context.
993
994 This function performs HMAC-MD5 digest on a data buffer of the specified size.
995 It can be called multiple times to compute the digest of long or discontinuous data streams.
996 HMAC-MD5 context should be already correctly initialized by HmacMd5Init(), and should not be
997 finalized by HmacMd5Final(). Behavior with invalid context is undefined.
998
999 If HmacMd5Context is NULL, then return FALSE.
1000 If this interface is not supported, then return FALSE.
1001
1002 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
1003 @param[in] Data Pointer to the buffer containing the data to be digested.
1004 @param[in] DataSize Size of Data buffer in bytes.
1005
1006 @retval TRUE HMAC-MD5 data digest succeeded.
1007 @retval FALSE HMAC-MD5 data digest failed.
1008 @retval FALSE This interface is not supported.
1009
1010 **/
1011 BOOLEAN
1012 EFIAPI
1013 HmacMd5Update (
1014 IN OUT VOID *HmacMd5Context,
1015 IN CONST VOID *Data,
1016 IN UINTN DataSize
1017 );
1018
1019 /**
1020 Completes computation of the HMAC-MD5 digest value.
1021
1022 This function completes HMAC-MD5 hash computation and retrieves the digest value into
1023 the specified memory. After this function has been called, the HMAC-MD5 context cannot
1024 be used again.
1025 HMAC-MD5 context should be already correctly initialized by HmacMd5Init(), and should not be
1026 finalized by HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined.
1027
1028 If HmacMd5Context is NULL, then return FALSE.
1029 If HmacValue is NULL, then return FALSE.
1030 If this interface is not supported, then return FALSE.
1031
1032 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
1033 @param[out] HmacValue Pointer to a buffer that receives the HMAC-MD5 digest
1034 value (16 bytes).
1035
1036 @retval TRUE HMAC-MD5 digest computation succeeded.
1037 @retval FALSE HMAC-MD5 digest computation failed.
1038 @retval FALSE This interface is not supported.
1039
1040 **/
1041 BOOLEAN
1042 EFIAPI
1043 HmacMd5Final (
1044 IN OUT VOID *HmacMd5Context,
1045 OUT UINT8 *HmacValue
1046 );
1047
1048 /**
1049 Retrieves the size, in bytes, of the context buffer required for HMAC-SHA1 operations.
1050 (NOTE: This API is deprecated.
1051 Use HmacSha1New() / HmacSha1Free() for HMAC-SHA1 Context operations.)
1052
1053 If this interface is not supported, then return zero.
1054
1055 @return The size, in bytes, of the context buffer required for HMAC-SHA1 operations.
1056 @retval 0 This interface is not supported.
1057
1058 **/
1059 UINTN
1060 EFIAPI
1061 HmacSha1GetContextSize (
1062 VOID
1063 );
1064
1065 /**
1066 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA1 use.
1067
1068 If this interface is not supported, then return NULL.
1069
1070 @return Pointer to the HMAC_CTX context that has been initialized.
1071 If the allocations fails, HmacSha1New() returns NULL.
1072 @return NULL This interface is not supported.
1073
1074 **/
1075 VOID *
1076 EFIAPI
1077 HmacSha1New (
1078 VOID
1079 );
1080
1081 /**
1082 Release the specified HMAC_CTX context.
1083
1084 If this interface is not supported, then do nothing.
1085
1086 @param[in] HmacSha1Ctx Pointer to the HMAC_CTX context to be released.
1087
1088 **/
1089 VOID
1090 EFIAPI
1091 HmacSha1Free (
1092 IN VOID *HmacSha1Ctx
1093 );
1094
1095 /**
1096 Initializes user-supplied memory pointed by HmacSha1Context as HMAC-SHA1 context for
1097 subsequent use.
1098
1099 If HmacSha1Context is NULL, then return FALSE.
1100 If this interface is not supported, then return FALSE.
1101
1102 @param[out] HmacSha1Context Pointer to HMAC-SHA1 context being initialized.
1103 @param[in] Key Pointer to the user-supplied key.
1104 @param[in] KeySize Key size in bytes.
1105
1106 @retval TRUE HMAC-SHA1 context initialization succeeded.
1107 @retval FALSE HMAC-SHA1 context initialization failed.
1108 @retval FALSE This interface is not supported.
1109
1110 **/
1111 BOOLEAN
1112 EFIAPI
1113 HmacSha1Init (
1114 OUT VOID *HmacSha1Context,
1115 IN CONST UINT8 *Key,
1116 IN UINTN KeySize
1117 );
1118
1119 /**
1120 Makes a copy of an existing HMAC-SHA1 context.
1121
1122 If HmacSha1Context is NULL, then return FALSE.
1123 If NewHmacSha1Context is NULL, then return FALSE.
1124 If this interface is not supported, then return FALSE.
1125
1126 @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied.
1127 @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context.
1128
1129 @retval TRUE HMAC-SHA1 context copy succeeded.
1130 @retval FALSE HMAC-SHA1 context copy failed.
1131 @retval FALSE This interface is not supported.
1132
1133 **/
1134 BOOLEAN
1135 EFIAPI
1136 HmacSha1Duplicate (
1137 IN CONST VOID *HmacSha1Context,
1138 OUT VOID *NewHmacSha1Context
1139 );
1140
1141 /**
1142 Digests the input data and updates HMAC-SHA1 context.
1143
1144 This function performs HMAC-SHA1 digest on a data buffer of the specified size.
1145 It can be called multiple times to compute the digest of long or discontinuous data streams.
1146 HMAC-SHA1 context should be already correctly initialized by HmacSha1Init(), and should not
1147 be finalized by HmacSha1Final(). Behavior with invalid context is undefined.
1148
1149 If HmacSha1Context is NULL, then return FALSE.
1150 If this interface is not supported, then return FALSE.
1151
1152 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1153 @param[in] Data Pointer to the buffer containing the data to be digested.
1154 @param[in] DataSize Size of Data buffer in bytes.
1155
1156 @retval TRUE HMAC-SHA1 data digest succeeded.
1157 @retval FALSE HMAC-SHA1 data digest failed.
1158 @retval FALSE This interface is not supported.
1159
1160 **/
1161 BOOLEAN
1162 EFIAPI
1163 HmacSha1Update (
1164 IN OUT VOID *HmacSha1Context,
1165 IN CONST VOID *Data,
1166 IN UINTN DataSize
1167 );
1168
1169 /**
1170 Completes computation of the HMAC-SHA1 digest value.
1171
1172 This function completes HMAC-SHA1 hash computation and retrieves the digest value into
1173 the specified memory. After this function has been called, the HMAC-SHA1 context cannot
1174 be used again.
1175 HMAC-SHA1 context should be already correctly initialized by HmacSha1Init(), and should
1176 not be finalized by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined.
1177
1178 If HmacSha1Context is NULL, then return FALSE.
1179 If HmacValue is NULL, then return FALSE.
1180 If this interface is not supported, then return FALSE.
1181
1182 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1183 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA1 digest
1184 value (20 bytes).
1185
1186 @retval TRUE HMAC-SHA1 digest computation succeeded.
1187 @retval FALSE HMAC-SHA1 digest computation failed.
1188 @retval FALSE This interface is not supported.
1189
1190 **/
1191 BOOLEAN
1192 EFIAPI
1193 HmacSha1Final (
1194 IN OUT VOID *HmacSha1Context,
1195 OUT UINT8 *HmacValue
1196 );
1197
1198 /**
1199 Retrieves the size, in bytes, of the context buffer required for HMAC-SHA256 operations.
1200 (NOTE: This API is deprecated.
1201 Use HmacSha256New() / HmacSha256Free() for HMAC-SHA256 Context operations.)
1202
1203 If this interface is not supported, then return zero.
1204
1205 @return The size, in bytes, of the context buffer required for HMAC-SHA256 operations.
1206 @retval 0 This interface is not supported.
1207
1208 **/
1209 UINTN
1210 EFIAPI
1211 HmacSha256GetContextSize (
1212 VOID
1213 );
1214
1215 /**
1216 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
1217
1218 @return Pointer to the HMAC_CTX context that has been initialized.
1219 If the allocations fails, HmacSha256New() returns NULL.
1220
1221 **/
1222 VOID *
1223 EFIAPI
1224 HmacSha256New (
1225 VOID
1226 );
1227
1228 /**
1229 Release the specified HMAC_CTX context.
1230
1231 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.
1232
1233 **/
1234 VOID
1235 EFIAPI
1236 HmacSha256Free (
1237 IN VOID *HmacSha256Ctx
1238 );
1239
1240 /**
1241 Initializes user-supplied memory pointed by HmacSha256Context as HMAC-SHA256 context for
1242 subsequent use.
1243
1244 If HmacSha256Context is NULL, then return FALSE.
1245 If this interface is not supported, then return FALSE.
1246
1247 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context being initialized.
1248 @param[in] Key Pointer to the user-supplied key.
1249 @param[in] KeySize Key size in bytes.
1250
1251 @retval TRUE HMAC-SHA256 context initialization succeeded.
1252 @retval FALSE HMAC-SHA256 context initialization failed.
1253 @retval FALSE This interface is not supported.
1254
1255 **/
1256 BOOLEAN
1257 EFIAPI
1258 HmacSha256Init (
1259 OUT VOID *HmacSha256Context,
1260 IN CONST UINT8 *Key,
1261 IN UINTN KeySize
1262 );
1263
1264 /**
1265 Makes a copy of an existing HMAC-SHA256 context.
1266
1267 If HmacSha256Context is NULL, then return FALSE.
1268 If NewHmacSha256Context is NULL, then return FALSE.
1269 If this interface is not supported, then return FALSE.
1270
1271 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.
1272 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.
1273
1274 @retval TRUE HMAC-SHA256 context copy succeeded.
1275 @retval FALSE HMAC-SHA256 context copy failed.
1276 @retval FALSE This interface is not supported.
1277
1278 **/
1279 BOOLEAN
1280 EFIAPI
1281 HmacSha256Duplicate (
1282 IN CONST VOID *HmacSha256Context,
1283 OUT VOID *NewHmacSha256Context
1284 );
1285
1286 /**
1287 Digests the input data and updates HMAC-SHA256 context.
1288
1289 This function performs HMAC-SHA256 digest on a data buffer of the specified size.
1290 It can be called multiple times to compute the digest of long or discontinuous data streams.
1291 HMAC-SHA256 context should be already correctly initialized by HmacSha256Init(), and should not
1292 be finalized by HmacSha256Final(). Behavior with invalid context is undefined.
1293
1294 If HmacSha256Context is NULL, then return FALSE.
1295 If this interface is not supported, then return FALSE.
1296
1297 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1298 @param[in] Data Pointer to the buffer containing the data to be digested.
1299 @param[in] DataSize Size of Data buffer in bytes.
1300
1301 @retval TRUE HMAC-SHA256 data digest succeeded.
1302 @retval FALSE HMAC-SHA256 data digest failed.
1303 @retval FALSE This interface is not supported.
1304
1305 **/
1306 BOOLEAN
1307 EFIAPI
1308 HmacSha256Update (
1309 IN OUT VOID *HmacSha256Context,
1310 IN CONST VOID *Data,
1311 IN UINTN DataSize
1312 );
1313
1314 /**
1315 Completes computation of the HMAC-SHA256 digest value.
1316
1317 This function completes HMAC-SHA256 hash computation and retrieves the digest value into
1318 the specified memory. After this function has been called, the HMAC-SHA256 context cannot
1319 be used again.
1320 HMAC-SHA256 context should be already correctly initialized by HmacSha256Init(), and should
1321 not be finalized by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.
1322
1323 If HmacSha256Context is NULL, then return FALSE.
1324 If HmacValue is NULL, then return FALSE.
1325 If this interface is not supported, then return FALSE.
1326
1327 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1328 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
1329 value (32 bytes).
1330
1331 @retval TRUE HMAC-SHA256 digest computation succeeded.
1332 @retval FALSE HMAC-SHA256 digest computation failed.
1333 @retval FALSE This interface is not supported.
1334
1335 **/
1336 BOOLEAN
1337 EFIAPI
1338 HmacSha256Final (
1339 IN OUT VOID *HmacSha256Context,
1340 OUT UINT8 *HmacValue
1341 );
1342
1343 //=====================================================================================
1344 // Symmetric Cryptography Primitive
1345 //=====================================================================================
1346
1347 /**
1348 Retrieves the size, in bytes, of the context buffer required for TDES operations.
1349
1350 If this interface is not supported, then return zero.
1351
1352 @return The size, in bytes, of the context buffer required for TDES operations.
1353 @retval 0 This interface is not supported.
1354
1355 **/
1356 UINTN
1357 EFIAPI
1358 TdesGetContextSize (
1359 VOID
1360 );
1361
1362 /**
1363 Initializes user-supplied memory as TDES context for subsequent use.
1364
1365 This function initializes user-supplied memory pointed by TdesContext as TDES context.
1366 In addition, it sets up all TDES key materials for subsequent encryption and decryption
1367 operations.
1368 There are 3 key options as follows:
1369 KeyLength = 64, Keying option 1: K1 == K2 == K3 (Backward compatibility with DES)
1370 KeyLength = 128, Keying option 2: K1 != K2 and K3 = K1 (Less Security)
1371 KeyLength = 192 Keying option 3: K1 != K2 != K3 (Strongest)
1372
1373 If TdesContext is NULL, then return FALSE.
1374 If Key is NULL, then return FALSE.
1375 If KeyLength is not valid, then return FALSE.
1376 If this interface is not supported, then return FALSE.
1377
1378 @param[out] TdesContext Pointer to TDES context being initialized.
1379 @param[in] Key Pointer to the user-supplied TDES key.
1380 @param[in] KeyLength Length of TDES key in bits.
1381
1382 @retval TRUE TDES context initialization succeeded.
1383 @retval FALSE TDES context initialization failed.
1384 @retval FALSE This interface is not supported.
1385
1386 **/
1387 BOOLEAN
1388 EFIAPI
1389 TdesInit (
1390 OUT VOID *TdesContext,
1391 IN CONST UINT8 *Key,
1392 IN UINTN KeyLength
1393 );
1394
1395 /**
1396 Performs TDES encryption on a data buffer of the specified size in ECB mode.
1397
1398 This function performs TDES encryption on data buffer pointed by Input, of specified
1399 size of InputSize, in ECB mode.
1400 InputSize must be multiple of block size (8 bytes). This function does not perform
1401 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1402 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1403 invalid TDES context is undefined.
1404
1405 If TdesContext is NULL, then return FALSE.
1406 If Input is NULL, then return FALSE.
1407 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1408 If Output is NULL, then return FALSE.
1409 If this interface is not supported, then return FALSE.
1410
1411 @param[in] TdesContext Pointer to the TDES context.
1412 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1413 @param[in] InputSize Size of the Input buffer in bytes.
1414 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1415
1416 @retval TRUE TDES encryption succeeded.
1417 @retval FALSE TDES encryption failed.
1418 @retval FALSE This interface is not supported.
1419
1420 **/
1421 BOOLEAN
1422 EFIAPI
1423 TdesEcbEncrypt (
1424 IN VOID *TdesContext,
1425 IN CONST UINT8 *Input,
1426 IN UINTN InputSize,
1427 OUT UINT8 *Output
1428 );
1429
1430 /**
1431 Performs TDES decryption on a data buffer of the specified size in ECB mode.
1432
1433 This function performs TDES decryption on data buffer pointed by Input, of specified
1434 size of InputSize, in ECB mode.
1435 InputSize must be multiple of block size (8 bytes). This function does not perform
1436 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1437 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1438 invalid TDES context is undefined.
1439
1440 If TdesContext is NULL, then return FALSE.
1441 If Input is NULL, then return FALSE.
1442 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1443 If Output is NULL, then return FALSE.
1444 If this interface is not supported, then return FALSE.
1445
1446 @param[in] TdesContext Pointer to the TDES context.
1447 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1448 @param[in] InputSize Size of the Input buffer in bytes.
1449 @param[out] Output Pointer to a buffer that receives the TDES decryption output.
1450
1451 @retval TRUE TDES decryption succeeded.
1452 @retval FALSE TDES decryption failed.
1453 @retval FALSE This interface is not supported.
1454
1455 **/
1456 BOOLEAN
1457 EFIAPI
1458 TdesEcbDecrypt (
1459 IN VOID *TdesContext,
1460 IN CONST UINT8 *Input,
1461 IN UINTN InputSize,
1462 OUT UINT8 *Output
1463 );
1464
1465 /**
1466 Performs TDES encryption on a data buffer of the specified size in CBC mode.
1467
1468 This function performs TDES encryption on data buffer pointed by Input, of specified
1469 size of InputSize, in CBC mode.
1470 InputSize must be multiple of block size (8 bytes). This function does not perform
1471 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1472 Initialization vector should be one block size (8 bytes).
1473 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1474 invalid TDES context is undefined.
1475
1476 If TdesContext is NULL, then return FALSE.
1477 If Input is NULL, then return FALSE.
1478 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1479 If Ivec is NULL, then return FALSE.
1480 If Output is NULL, then return FALSE.
1481 If this interface is not supported, then return FALSE.
1482
1483 @param[in] TdesContext Pointer to the TDES context.
1484 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1485 @param[in] InputSize Size of the Input buffer in bytes.
1486 @param[in] Ivec Pointer to initialization vector.
1487 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1488
1489 @retval TRUE TDES encryption succeeded.
1490 @retval FALSE TDES encryption failed.
1491 @retval FALSE This interface is not supported.
1492
1493 **/
1494 BOOLEAN
1495 EFIAPI
1496 TdesCbcEncrypt (
1497 IN VOID *TdesContext,
1498 IN CONST UINT8 *Input,
1499 IN UINTN InputSize,
1500 IN CONST UINT8 *Ivec,
1501 OUT UINT8 *Output
1502 );
1503
1504 /**
1505 Performs TDES decryption on a data buffer of the specified size in CBC mode.
1506
1507 This function performs TDES decryption on data buffer pointed by Input, of specified
1508 size of InputSize, in CBC mode.
1509 InputSize must be multiple of block size (8 bytes). This function does not perform
1510 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1511 Initialization vector should be one block size (8 bytes).
1512 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1513 invalid TDES context is undefined.
1514
1515 If TdesContext is NULL, then return FALSE.
1516 If Input is NULL, then return FALSE.
1517 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1518 If Ivec is NULL, then return FALSE.
1519 If Output is NULL, then return FALSE.
1520 If this interface is not supported, then return FALSE.
1521
1522 @param[in] TdesContext Pointer to the TDES context.
1523 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1524 @param[in] InputSize Size of the Input buffer in bytes.
1525 @param[in] Ivec Pointer to initialization vector.
1526 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1527
1528 @retval TRUE TDES decryption succeeded.
1529 @retval FALSE TDES decryption failed.
1530 @retval FALSE This interface is not supported.
1531
1532 **/
1533 BOOLEAN
1534 EFIAPI
1535 TdesCbcDecrypt (
1536 IN VOID *TdesContext,
1537 IN CONST UINT8 *Input,
1538 IN UINTN InputSize,
1539 IN CONST UINT8 *Ivec,
1540 OUT UINT8 *Output
1541 );
1542
1543 /**
1544 Retrieves the size, in bytes, of the context buffer required for AES operations.
1545
1546 If this interface is not supported, then return zero.
1547
1548 @return The size, in bytes, of the context buffer required for AES operations.
1549 @retval 0 This interface is not supported.
1550
1551 **/
1552 UINTN
1553 EFIAPI
1554 AesGetContextSize (
1555 VOID
1556 );
1557
1558 /**
1559 Initializes user-supplied memory as AES context for subsequent use.
1560
1561 This function initializes user-supplied memory pointed by AesContext as AES context.
1562 In addition, it sets up all AES key materials for subsequent encryption and decryption
1563 operations.
1564 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1565
1566 If AesContext is NULL, then return FALSE.
1567 If Key is NULL, then return FALSE.
1568 If KeyLength is not valid, then return FALSE.
1569 If this interface is not supported, then return FALSE.
1570
1571 @param[out] AesContext Pointer to AES context being initialized.
1572 @param[in] Key Pointer to the user-supplied AES key.
1573 @param[in] KeyLength Length of AES key in bits.
1574
1575 @retval TRUE AES context initialization succeeded.
1576 @retval FALSE AES context initialization failed.
1577 @retval FALSE This interface is not supported.
1578
1579 **/
1580 BOOLEAN
1581 EFIAPI
1582 AesInit (
1583 OUT VOID *AesContext,
1584 IN CONST UINT8 *Key,
1585 IN UINTN KeyLength
1586 );
1587
1588 /**
1589 Performs AES encryption on a data buffer of the specified size in ECB mode.
1590
1591 This function performs AES encryption on data buffer pointed by Input, of specified
1592 size of InputSize, in ECB mode.
1593 InputSize must be multiple of block size (16 bytes). This function does not perform
1594 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1595 AesContext should be already correctly initialized by AesInit(). Behavior with
1596 invalid AES context is undefined.
1597
1598 If AesContext is NULL, then return FALSE.
1599 If Input is NULL, then return FALSE.
1600 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1601 If Output is NULL, then return FALSE.
1602 If this interface is not supported, then return FALSE.
1603
1604 @param[in] AesContext Pointer to the AES context.
1605 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1606 @param[in] InputSize Size of the Input buffer in bytes.
1607 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1608
1609 @retval TRUE AES encryption succeeded.
1610 @retval FALSE AES encryption failed.
1611 @retval FALSE This interface is not supported.
1612
1613 **/
1614 BOOLEAN
1615 EFIAPI
1616 AesEcbEncrypt (
1617 IN VOID *AesContext,
1618 IN CONST UINT8 *Input,
1619 IN UINTN InputSize,
1620 OUT UINT8 *Output
1621 );
1622
1623 /**
1624 Performs AES decryption on a data buffer of the specified size in ECB mode.
1625
1626 This function performs AES decryption on data buffer pointed by Input, of specified
1627 size of InputSize, in ECB mode.
1628 InputSize must be multiple of block size (16 bytes). This function does not perform
1629 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1630 AesContext should be already correctly initialized by AesInit(). Behavior with
1631 invalid AES context is undefined.
1632
1633 If AesContext is NULL, then return FALSE.
1634 If Input is NULL, then return FALSE.
1635 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1636 If Output is NULL, then return FALSE.
1637 If this interface is not supported, then return FALSE.
1638
1639 @param[in] AesContext Pointer to the AES context.
1640 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1641 @param[in] InputSize Size of the Input buffer in bytes.
1642 @param[out] Output Pointer to a buffer that receives the AES decryption output.
1643
1644 @retval TRUE AES decryption succeeded.
1645 @retval FALSE AES decryption failed.
1646 @retval FALSE This interface is not supported.
1647
1648 **/
1649 BOOLEAN
1650 EFIAPI
1651 AesEcbDecrypt (
1652 IN VOID *AesContext,
1653 IN CONST UINT8 *Input,
1654 IN UINTN InputSize,
1655 OUT UINT8 *Output
1656 );
1657
1658 /**
1659 Performs AES encryption on a data buffer of the specified size in CBC mode.
1660
1661 This function performs AES encryption on data buffer pointed by Input, of specified
1662 size of InputSize, in CBC mode.
1663 InputSize must be multiple of block size (16 bytes). This function does not perform
1664 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1665 Initialization vector should be one block size (16 bytes).
1666 AesContext should be already correctly initialized by AesInit(). Behavior with
1667 invalid AES context is undefined.
1668
1669 If AesContext is NULL, then return FALSE.
1670 If Input is NULL, then return FALSE.
1671 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1672 If Ivec is NULL, then return FALSE.
1673 If Output is NULL, then return FALSE.
1674 If this interface is not supported, then return FALSE.
1675
1676 @param[in] AesContext Pointer to the AES context.
1677 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1678 @param[in] InputSize Size of the Input buffer in bytes.
1679 @param[in] Ivec Pointer to initialization vector.
1680 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1681
1682 @retval TRUE AES encryption succeeded.
1683 @retval FALSE AES encryption failed.
1684 @retval FALSE This interface is not supported.
1685
1686 **/
1687 BOOLEAN
1688 EFIAPI
1689 AesCbcEncrypt (
1690 IN VOID *AesContext,
1691 IN CONST UINT8 *Input,
1692 IN UINTN InputSize,
1693 IN CONST UINT8 *Ivec,
1694 OUT UINT8 *Output
1695 );
1696
1697 /**
1698 Performs AES decryption on a data buffer of the specified size in CBC mode.
1699
1700 This function performs AES decryption on data buffer pointed by Input, of specified
1701 size of InputSize, in CBC mode.
1702 InputSize must be multiple of block size (16 bytes). This function does not perform
1703 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1704 Initialization vector should be one block size (16 bytes).
1705 AesContext should be already correctly initialized by AesInit(). Behavior with
1706 invalid AES context is undefined.
1707
1708 If AesContext is NULL, then return FALSE.
1709 If Input is NULL, then return FALSE.
1710 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1711 If Ivec is NULL, then return FALSE.
1712 If Output is NULL, then return FALSE.
1713 If this interface is not supported, then return FALSE.
1714
1715 @param[in] AesContext Pointer to the AES context.
1716 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1717 @param[in] InputSize Size of the Input buffer in bytes.
1718 @param[in] Ivec Pointer to initialization vector.
1719 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1720
1721 @retval TRUE AES decryption succeeded.
1722 @retval FALSE AES decryption failed.
1723 @retval FALSE This interface is not supported.
1724
1725 **/
1726 BOOLEAN
1727 EFIAPI
1728 AesCbcDecrypt (
1729 IN VOID *AesContext,
1730 IN CONST UINT8 *Input,
1731 IN UINTN InputSize,
1732 IN CONST UINT8 *Ivec,
1733 OUT UINT8 *Output
1734 );
1735
1736 /**
1737 Retrieves the size, in bytes, of the context buffer required for ARC4 operations.
1738
1739 If this interface is not supported, then return zero.
1740
1741 @return The size, in bytes, of the context buffer required for ARC4 operations.
1742 @retval 0 This interface is not supported.
1743
1744 **/
1745 UINTN
1746 EFIAPI
1747 Arc4GetContextSize (
1748 VOID
1749 );
1750
1751 /**
1752 Initializes user-supplied memory as ARC4 context for subsequent use.
1753
1754 This function initializes user-supplied memory pointed by Arc4Context as ARC4 context.
1755 In addition, it sets up all ARC4 key materials for subsequent encryption and decryption
1756 operations.
1757
1758 If Arc4Context is NULL, then return FALSE.
1759 If Key is NULL, then return FALSE.
1760 If KeySize does not in the range of [5, 256] bytes, then return FALSE.
1761 If this interface is not supported, then return FALSE.
1762
1763 @param[out] Arc4Context Pointer to ARC4 context being initialized.
1764 @param[in] Key Pointer to the user-supplied ARC4 key.
1765 @param[in] KeySize Size of ARC4 key in bytes.
1766
1767 @retval TRUE ARC4 context initialization succeeded.
1768 @retval FALSE ARC4 context initialization failed.
1769 @retval FALSE This interface is not supported.
1770
1771 **/
1772 BOOLEAN
1773 EFIAPI
1774 Arc4Init (
1775 OUT VOID *Arc4Context,
1776 IN CONST UINT8 *Key,
1777 IN UINTN KeySize
1778 );
1779
1780 /**
1781 Performs ARC4 encryption on a data buffer of the specified size.
1782
1783 This function performs ARC4 encryption on data buffer pointed by Input, of specified
1784 size of InputSize.
1785 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
1786 invalid ARC4 context is undefined.
1787
1788 If Arc4Context is NULL, then return FALSE.
1789 If Input is NULL, then return FALSE.
1790 If Output is NULL, then return FALSE.
1791 If this interface is not supported, then return FALSE.
1792
1793 @param[in, out] Arc4Context Pointer to the ARC4 context.
1794 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1795 @param[in] InputSize Size of the Input buffer in bytes.
1796 @param[out] Output Pointer to a buffer that receives the ARC4 encryption output.
1797
1798 @retval TRUE ARC4 encryption succeeded.
1799 @retval FALSE ARC4 encryption failed.
1800 @retval FALSE This interface is not supported.
1801
1802 **/
1803 BOOLEAN
1804 EFIAPI
1805 Arc4Encrypt (
1806 IN OUT VOID *Arc4Context,
1807 IN CONST UINT8 *Input,
1808 IN UINTN InputSize,
1809 OUT UINT8 *Output
1810 );
1811
1812 /**
1813 Performs ARC4 decryption on a data buffer of the specified size.
1814
1815 This function performs ARC4 decryption on data buffer pointed by Input, of specified
1816 size of InputSize.
1817 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
1818 invalid ARC4 context is undefined.
1819
1820 If Arc4Context is NULL, then return FALSE.
1821 If Input is NULL, then return FALSE.
1822 If Output is NULL, then return FALSE.
1823 If this interface is not supported, then return FALSE.
1824
1825 @param[in, out] Arc4Context Pointer to the ARC4 context.
1826 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1827 @param[in] InputSize Size of the Input buffer in bytes.
1828 @param[out] Output Pointer to a buffer that receives the ARC4 decryption output.
1829
1830 @retval TRUE ARC4 decryption succeeded.
1831 @retval FALSE ARC4 decryption failed.
1832 @retval FALSE This interface is not supported.
1833
1834 **/
1835 BOOLEAN
1836 EFIAPI
1837 Arc4Decrypt (
1838 IN OUT VOID *Arc4Context,
1839 IN UINT8 *Input,
1840 IN UINTN InputSize,
1841 OUT UINT8 *Output
1842 );
1843
1844 /**
1845 Resets the ARC4 context to the initial state.
1846
1847 The function resets the ARC4 context to the state it had immediately after the
1848 ARC4Init() function call.
1849 Contrary to ARC4Init(), Arc4Reset() requires no secret key as input, but ARC4 context
1850 should be already correctly initialized by ARC4Init().
1851
1852 If Arc4Context is NULL, then return FALSE.
1853 If this interface is not supported, then return FALSE.
1854
1855 @param[in, out] Arc4Context Pointer to the ARC4 context.
1856
1857 @retval TRUE ARC4 reset succeeded.
1858 @retval FALSE ARC4 reset failed.
1859 @retval FALSE This interface is not supported.
1860
1861 **/
1862 BOOLEAN
1863 EFIAPI
1864 Arc4Reset (
1865 IN OUT VOID *Arc4Context
1866 );
1867
1868 //=====================================================================================
1869 // Asymmetric Cryptography Primitive
1870 //=====================================================================================
1871
1872 /**
1873 Allocates and initializes one RSA context for subsequent use.
1874
1875 @return Pointer to the RSA context that has been initialized.
1876 If the allocations fails, RsaNew() returns NULL.
1877
1878 **/
1879 VOID *
1880 EFIAPI
1881 RsaNew (
1882 VOID
1883 );
1884
1885 /**
1886 Release the specified RSA context.
1887
1888 If RsaContext is NULL, then return FALSE.
1889
1890 @param[in] RsaContext Pointer to the RSA context to be released.
1891
1892 **/
1893 VOID
1894 EFIAPI
1895 RsaFree (
1896 IN VOID *RsaContext
1897 );
1898
1899 /**
1900 Sets the tag-designated key component into the established RSA context.
1901
1902 This function sets the tag-designated RSA key component into the established
1903 RSA context from the user-specified non-negative integer (octet string format
1904 represented in RSA PKCS#1).
1905 If BigNumber is NULL, then the specified key component in RSA context is cleared.
1906
1907 If RsaContext is NULL, then return FALSE.
1908
1909 @param[in, out] RsaContext Pointer to RSA context being set.
1910 @param[in] KeyTag Tag of RSA key component being set.
1911 @param[in] BigNumber Pointer to octet integer buffer.
1912 If NULL, then the specified key component in RSA
1913 context is cleared.
1914 @param[in] BnSize Size of big number buffer in bytes.
1915 If BigNumber is NULL, then it is ignored.
1916
1917 @retval TRUE RSA key component was set successfully.
1918 @retval FALSE Invalid RSA key component tag.
1919
1920 **/
1921 BOOLEAN
1922 EFIAPI
1923 RsaSetKey (
1924 IN OUT VOID *RsaContext,
1925 IN RSA_KEY_TAG KeyTag,
1926 IN CONST UINT8 *BigNumber,
1927 IN UINTN BnSize
1928 );
1929
1930 /**
1931 Gets the tag-designated RSA key component from the established RSA context.
1932
1933 This function retrieves the tag-designated RSA key component from the
1934 established RSA context as a non-negative integer (octet string format
1935 represented in RSA PKCS#1).
1936 If specified key component has not been set or has been cleared, then returned
1937 BnSize is set to 0.
1938 If the BigNumber buffer is too small to hold the contents of the key, FALSE
1939 is returned and BnSize is set to the required buffer size to obtain the key.
1940
1941 If RsaContext is NULL, then return FALSE.
1942 If BnSize is NULL, then return FALSE.
1943 If BnSize is large enough but BigNumber is NULL, then return FALSE.
1944 If this interface is not supported, then return FALSE.
1945
1946 @param[in, out] RsaContext Pointer to RSA context being set.
1947 @param[in] KeyTag Tag of RSA key component being set.
1948 @param[out] BigNumber Pointer to octet integer buffer.
1949 @param[in, out] BnSize On input, the size of big number buffer in bytes.
1950 On output, the size of data returned in big number buffer in bytes.
1951
1952 @retval TRUE RSA key component was retrieved successfully.
1953 @retval FALSE Invalid RSA key component tag.
1954 @retval FALSE BnSize is too small.
1955 @retval FALSE This interface is not supported.
1956
1957 **/
1958 BOOLEAN
1959 EFIAPI
1960 RsaGetKey (
1961 IN OUT VOID *RsaContext,
1962 IN RSA_KEY_TAG KeyTag,
1963 OUT UINT8 *BigNumber,
1964 IN OUT UINTN *BnSize
1965 );
1966
1967 /**
1968 Generates RSA key components.
1969
1970 This function generates RSA key components. It takes RSA public exponent E and
1971 length in bits of RSA modulus N as input, and generates all key components.
1972 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
1973
1974 Before this function can be invoked, pseudorandom number generator must be correctly
1975 initialized by RandomSeed().
1976
1977 If RsaContext is NULL, then return FALSE.
1978 If this interface is not supported, then return FALSE.
1979
1980 @param[in, out] RsaContext Pointer to RSA context being set.
1981 @param[in] ModulusLength Length of RSA modulus N in bits.
1982 @param[in] PublicExponent Pointer to RSA public exponent.
1983 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
1984
1985 @retval TRUE RSA key component was generated successfully.
1986 @retval FALSE Invalid RSA key component tag.
1987 @retval FALSE This interface is not supported.
1988
1989 **/
1990 BOOLEAN
1991 EFIAPI
1992 RsaGenerateKey (
1993 IN OUT VOID *RsaContext,
1994 IN UINTN ModulusLength,
1995 IN CONST UINT8 *PublicExponent,
1996 IN UINTN PublicExponentSize
1997 );
1998
1999 /**
2000 Validates key components of RSA context.
2001 NOTE: This function performs integrity checks on all the RSA key material, so
2002 the RSA key structure must contain all the private key data.
2003
2004 This function validates key components of RSA context in following aspects:
2005 - Whether p is a prime
2006 - Whether q is a prime
2007 - Whether n = p * q
2008 - Whether d*e = 1 mod lcm(p-1,q-1)
2009
2010 If RsaContext is NULL, then return FALSE.
2011 If this interface is not supported, then return FALSE.
2012
2013 @param[in] RsaContext Pointer to RSA context to check.
2014
2015 @retval TRUE RSA key components are valid.
2016 @retval FALSE RSA key components are not valid.
2017 @retval FALSE This interface is not supported.
2018
2019 **/
2020 BOOLEAN
2021 EFIAPI
2022 RsaCheckKey (
2023 IN VOID *RsaContext
2024 );
2025
2026 /**
2027 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
2028
2029 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
2030 RSA PKCS#1.
2031 If the Signature buffer is too small to hold the contents of signature, FALSE
2032 is returned and SigSize is set to the required buffer size to obtain the signature.
2033
2034 If RsaContext is NULL, then return FALSE.
2035 If MessageHash is NULL, then return FALSE.
2036 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
2037 If SigSize is large enough but Signature is NULL, then return FALSE.
2038 If this interface is not supported, then return FALSE.
2039
2040 @param[in] RsaContext Pointer to RSA context for signature generation.
2041 @param[in] MessageHash Pointer to octet message hash to be signed.
2042 @param[in] HashSize Size of the message hash in bytes.
2043 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
2044 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
2045 On output, the size of data returned in Signature buffer in bytes.
2046
2047 @retval TRUE Signature successfully generated in PKCS1-v1_5.
2048 @retval FALSE Signature generation failed.
2049 @retval FALSE SigSize is too small.
2050 @retval FALSE This interface is not supported.
2051
2052 **/
2053 BOOLEAN
2054 EFIAPI
2055 RsaPkcs1Sign (
2056 IN VOID *RsaContext,
2057 IN CONST UINT8 *MessageHash,
2058 IN UINTN HashSize,
2059 OUT UINT8 *Signature,
2060 IN OUT UINTN *SigSize
2061 );
2062
2063 /**
2064 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
2065 RSA PKCS#1.
2066
2067 If RsaContext is NULL, then return FALSE.
2068 If MessageHash is NULL, then return FALSE.
2069 If Signature is NULL, then return FALSE.
2070 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
2071
2072 @param[in] RsaContext Pointer to RSA context for signature verification.
2073 @param[in] MessageHash Pointer to octet message hash to be checked.
2074 @param[in] HashSize Size of the message hash in bytes.
2075 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
2076 @param[in] SigSize Size of signature in bytes.
2077
2078 @retval TRUE Valid signature encoded in PKCS1-v1_5.
2079 @retval FALSE Invalid signature or invalid RSA context.
2080
2081 **/
2082 BOOLEAN
2083 EFIAPI
2084 RsaPkcs1Verify (
2085 IN VOID *RsaContext,
2086 IN CONST UINT8 *MessageHash,
2087 IN UINTN HashSize,
2088 IN CONST UINT8 *Signature,
2089 IN UINTN SigSize
2090 );
2091
2092 /**
2093 Retrieve the RSA Private Key from the password-protected PEM key data.
2094
2095 If PemData is NULL, then return FALSE.
2096 If RsaContext is NULL, then return FALSE.
2097 If this interface is not supported, then return FALSE.
2098
2099 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
2100 @param[in] PemSize Size of the PEM key data in bytes.
2101 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
2102 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2103 RSA private key component. Use RsaFree() function to free the
2104 resource.
2105
2106 @retval TRUE RSA Private Key was retrieved successfully.
2107 @retval FALSE Invalid PEM key data or incorrect password.
2108 @retval FALSE This interface is not supported.
2109
2110 **/
2111 BOOLEAN
2112 EFIAPI
2113 RsaGetPrivateKeyFromPem (
2114 IN CONST UINT8 *PemData,
2115 IN UINTN PemSize,
2116 IN CONST CHAR8 *Password,
2117 OUT VOID **RsaContext
2118 );
2119
2120 /**
2121 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
2122
2123 If Cert is NULL, then return FALSE.
2124 If RsaContext is NULL, then return FALSE.
2125 If this interface is not supported, then return FALSE.
2126
2127 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2128 @param[in] CertSize Size of the X509 certificate in bytes.
2129 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2130 RSA public key component. Use RsaFree() function to free the
2131 resource.
2132
2133 @retval TRUE RSA Public Key was retrieved successfully.
2134 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
2135 @retval FALSE This interface is not supported.
2136
2137 **/
2138 BOOLEAN
2139 EFIAPI
2140 RsaGetPublicKeyFromX509 (
2141 IN CONST UINT8 *Cert,
2142 IN UINTN CertSize,
2143 OUT VOID **RsaContext
2144 );
2145
2146 /**
2147 Retrieve the subject bytes from one X.509 certificate.
2148
2149 If Cert is NULL, then return FALSE.
2150 If SubjectSize is NULL, then return FALSE.
2151 If this interface is not supported, then return FALSE.
2152
2153 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2154 @param[in] CertSize Size of the X509 certificate in bytes.
2155 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
2156 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
2157 and the size of buffer returned CertSubject on output.
2158
2159 @retval TRUE The certificate subject retrieved successfully.
2160 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
2161 The SubjectSize will be updated with the required size.
2162 @retval FALSE This interface is not supported.
2163
2164 **/
2165 BOOLEAN
2166 EFIAPI
2167 X509GetSubjectName (
2168 IN CONST UINT8 *Cert,
2169 IN UINTN CertSize,
2170 OUT UINT8 *CertSubject,
2171 IN OUT UINTN *SubjectSize
2172 );
2173
2174 /**
2175 Retrieve the common name (CN) string from one X.509 certificate.
2176
2177 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2178 @param[in] CertSize Size of the X509 certificate in bytes.
2179 @param[out] CommonName Buffer to contain the retrieved certificate common
2180 name string (UTF8). At most CommonNameSize bytes will be
2181 written and the string will be null terminated. May be
2182 NULL in order to determine the size buffer needed.
2183 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
2184 and the size of buffer returned CommonName on output.
2185 If CommonName is NULL then the amount of space needed
2186 in buffer (including the final null) is returned.
2187
2188 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
2189 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2190 If CommonNameSize is NULL.
2191 If CommonName is not NULL and *CommonNameSize is 0.
2192 If Certificate is invalid.
2193 @retval RETURN_NOT_FOUND If no CommonName entry exists.
2194 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
2195 (including the final null) is returned in the
2196 CommonNameSize parameter.
2197 @retval RETURN_UNSUPPORTED The operation is not supported.
2198
2199 **/
2200 RETURN_STATUS
2201 EFIAPI
2202 X509GetCommonName (
2203 IN CONST UINT8 *Cert,
2204 IN UINTN CertSize,
2205 OUT CHAR8 *CommonName, OPTIONAL
2206 IN OUT UINTN *CommonNameSize
2207 );
2208
2209 /**
2210 Verify one X509 certificate was issued by the trusted CA.
2211
2212 If Cert is NULL, then return FALSE.
2213 If CACert is NULL, then return FALSE.
2214 If this interface is not supported, then return FALSE.
2215
2216 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
2217 @param[in] CertSize Size of the X509 certificate in bytes.
2218 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
2219 @param[in] CACertSize Size of the CA Certificate in bytes.
2220
2221 @retval TRUE The certificate was issued by the trusted CA.
2222 @retval FALSE Invalid certificate or the certificate was not issued by the given
2223 trusted CA.
2224 @retval FALSE This interface is not supported.
2225
2226 **/
2227 BOOLEAN
2228 EFIAPI
2229 X509VerifyCert (
2230 IN CONST UINT8 *Cert,
2231 IN UINTN CertSize,
2232 IN CONST UINT8 *CACert,
2233 IN UINTN CACertSize
2234 );
2235
2236 /**
2237 Construct a X509 object from DER-encoded certificate data.
2238
2239 If Cert is NULL, then return FALSE.
2240 If SingleX509Cert is NULL, then return FALSE.
2241 If this interface is not supported, then return FALSE.
2242
2243 @param[in] Cert Pointer to the DER-encoded certificate data.
2244 @param[in] CertSize The size of certificate data in bytes.
2245 @param[out] SingleX509Cert The generated X509 object.
2246
2247 @retval TRUE The X509 object generation succeeded.
2248 @retval FALSE The operation failed.
2249 @retval FALSE This interface is not supported.
2250
2251 **/
2252 BOOLEAN
2253 EFIAPI
2254 X509ConstructCertificate (
2255 IN CONST UINT8 *Cert,
2256 IN UINTN CertSize,
2257 OUT UINT8 **SingleX509Cert
2258 );
2259
2260 /**
2261 Construct a X509 stack object from a list of DER-encoded certificate data.
2262
2263 If X509Stack is NULL, then return FALSE.
2264 If this interface is not supported, then return FALSE.
2265
2266 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2267 On output, pointer to the X509 stack object with new
2268 inserted X509 certificate.
2269 @param ... A list of DER-encoded single certificate data followed
2270 by certificate size. A NULL terminates the list. The
2271 pairs are the arguments to X509ConstructCertificate().
2272
2273 @retval TRUE The X509 stack construction succeeded.
2274 @retval FALSE The construction operation failed.
2275 @retval FALSE This interface is not supported.
2276
2277 **/
2278 BOOLEAN
2279 EFIAPI
2280 X509ConstructCertificateStack (
2281 IN OUT UINT8 **X509Stack,
2282 ...
2283 );
2284
2285 /**
2286 Release the specified X509 object.
2287
2288 If the interface is not supported, then ASSERT().
2289
2290 @param[in] X509Cert Pointer to the X509 object to be released.
2291
2292 **/
2293 VOID
2294 EFIAPI
2295 X509Free (
2296 IN VOID *X509Cert
2297 );
2298
2299 /**
2300 Release the specified X509 stack object.
2301
2302 If the interface is not supported, then ASSERT().
2303
2304 @param[in] X509Stack Pointer to the X509 stack object to be released.
2305
2306 **/
2307 VOID
2308 EFIAPI
2309 X509StackFree (
2310 IN VOID *X509Stack
2311 );
2312
2313 /**
2314 Retrieve the TBSCertificate from one given X.509 certificate.
2315
2316 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
2317 @param[in] CertSize Size of the X509 certificate in bytes.
2318 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
2319 @param[out] TBSCertSize Size of the TBS certificate in bytes.
2320
2321 If Cert is NULL, then return FALSE.
2322 If TBSCert is NULL, then return FALSE.
2323 If TBSCertSize is NULL, then return FALSE.
2324 If this interface is not supported, then return FALSE.
2325
2326 @retval TRUE The TBSCertificate was retrieved successfully.
2327 @retval FALSE Invalid X.509 certificate.
2328
2329 **/
2330 BOOLEAN
2331 EFIAPI
2332 X509GetTBSCert (
2333 IN CONST UINT8 *Cert,
2334 IN UINTN CertSize,
2335 OUT UINT8 **TBSCert,
2336 OUT UINTN *TBSCertSize
2337 );
2338
2339 /**
2340 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2341 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2342
2343 If Password or Salt or OutKey is NULL, then return FALSE.
2344 If the hash algorithm could not be determined, then return FALSE.
2345 If this interface is not supported, then return FALSE.
2346
2347 @param[in] PasswordLength Length of input password in bytes.
2348 @param[in] Password Pointer to the array for the password.
2349 @param[in] SaltLength Size of the Salt in bytes.
2350 @param[in] Salt Pointer to the Salt.
2351 @param[in] IterationCount Number of iterations to perform. Its value should be
2352 greater than or equal to 1.
2353 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2354 NOTE: DigestSize will be used to determine the hash algorithm.
2355 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2356 @param[in] KeyLength Size of the derived key buffer in bytes.
2357 @param[out] OutKey Pointer to the output derived key buffer.
2358
2359 @retval TRUE A key was derived successfully.
2360 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2361 @retval FALSE The hash algorithm could not be determined from the digest size.
2362 @retval FALSE The key derivation operation failed.
2363 @retval FALSE This interface is not supported.
2364
2365 **/
2366 BOOLEAN
2367 EFIAPI
2368 Pkcs5HashPassword (
2369 IN UINTN PasswordLength,
2370 IN CONST CHAR8 *Password,
2371 IN UINTN SaltLength,
2372 IN CONST UINT8 *Salt,
2373 IN UINTN IterationCount,
2374 IN UINTN DigestSize,
2375 IN UINTN KeyLength,
2376 OUT UINT8 *OutKey
2377 );
2378
2379 /**
2380 The 3rd parameter of Pkcs7GetSigners will return all embedded
2381 X.509 certificate in one given PKCS7 signature. The format is:
2382 //
2383 // UINT8 CertNumber;
2384 // UINT32 Cert1Length;
2385 // UINT8 Cert1[];
2386 // UINT32 Cert2Length;
2387 // UINT8 Cert2[];
2388 // ...
2389 // UINT32 CertnLength;
2390 // UINT8 Certn[];
2391 //
2392
2393 The two following C-structure are used for parsing CertStack more clearly.
2394 **/
2395 #pragma pack(1)
2396
2397 typedef struct {
2398 UINT32 CertDataLength; // The length in bytes of X.509 certificate.
2399 UINT8 CertDataBuffer[0]; // The X.509 certificate content (DER).
2400 } EFI_CERT_DATA;
2401
2402 typedef struct {
2403 UINT8 CertNumber; // Number of X.509 certificate.
2404 //EFI_CERT_DATA CertArray[]; // An array of X.509 certificate.
2405 } EFI_CERT_STACK;
2406
2407 #pragma pack()
2408
2409 /**
2410 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2411 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2412 in a ContentInfo structure.
2413
2414 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2415 return FALSE. If P7Length overflow, then return FALSE.
2416 If this interface is not supported, then return FALSE.
2417
2418 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2419 @param[in] P7Length Length of the PKCS#7 message in bytes.
2420 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2421 It's caller's responsibility to free the buffer with
2422 Pkcs7FreeSigners().
2423 This data structure is EFI_CERT_STACK type.
2424 @param[out] StackLength Length of signer's certificates in bytes.
2425 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2426 It's caller's responsibility to free the buffer with
2427 Pkcs7FreeSigners().
2428 @param[out] CertLength Length of the trusted certificate in bytes.
2429
2430 @retval TRUE The operation is finished successfully.
2431 @retval FALSE Error occurs during the operation.
2432 @retval FALSE This interface is not supported.
2433
2434 **/
2435 BOOLEAN
2436 EFIAPI
2437 Pkcs7GetSigners (
2438 IN CONST UINT8 *P7Data,
2439 IN UINTN P7Length,
2440 OUT UINT8 **CertStack,
2441 OUT UINTN *StackLength,
2442 OUT UINT8 **TrustedCert,
2443 OUT UINTN *CertLength
2444 );
2445
2446 /**
2447 Wrap function to use free() to free allocated memory for certificates.
2448
2449 If this interface is not supported, then ASSERT().
2450
2451 @param[in] Certs Pointer to the certificates to be freed.
2452
2453 **/
2454 VOID
2455 EFIAPI
2456 Pkcs7FreeSigners (
2457 IN UINT8 *Certs
2458 );
2459
2460 /**
2461 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2462 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2463 unchained to the signer's certificates.
2464 The input signed data could be wrapped in a ContentInfo structure.
2465
2466 @param[in] P7Data Pointer to the PKCS#7 message.
2467 @param[in] P7Length Length of the PKCS#7 message in bytes.
2468 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2469 certificate. It's caller's responsibility to free the buffer
2470 with Pkcs7FreeSigners().
2471 This data structure is EFI_CERT_STACK type.
2472 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2473 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2474 responsibility to free the buffer with Pkcs7FreeSigners().
2475 This data structure is EFI_CERT_STACK type.
2476 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2477
2478 @retval TRUE The operation is finished successfully.
2479 @retval FALSE Error occurs during the operation.
2480
2481 **/
2482 BOOLEAN
2483 EFIAPI
2484 Pkcs7GetCertificatesList (
2485 IN CONST UINT8 *P7Data,
2486 IN UINTN P7Length,
2487 OUT UINT8 **SignerChainCerts,
2488 OUT UINTN *ChainLength,
2489 OUT UINT8 **UnchainCerts,
2490 OUT UINTN *UnchainLength
2491 );
2492
2493 /**
2494 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2495 Syntax Standard, version 1.5". This interface is only intended to be used for
2496 application to perform PKCS#7 functionality validation.
2497
2498 If this interface is not supported, then return FALSE.
2499
2500 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2501 data signing.
2502 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2503 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2504 key data.
2505 @param[in] InData Pointer to the content to be signed.
2506 @param[in] InDataSize Size of InData in bytes.
2507 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2508 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2509 include in the PKCS#7 signedData (e.g. any intermediate
2510 CAs in the chain).
2511 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2512 responsibility to free the buffer with FreePool().
2513 @param[out] SignedDataSize Size of SignedData in bytes.
2514
2515 @retval TRUE PKCS#7 data signing succeeded.
2516 @retval FALSE PKCS#7 data signing failed.
2517 @retval FALSE This interface is not supported.
2518
2519 **/
2520 BOOLEAN
2521 EFIAPI
2522 Pkcs7Sign (
2523 IN CONST UINT8 *PrivateKey,
2524 IN UINTN PrivateKeySize,
2525 IN CONST UINT8 *KeyPassword,
2526 IN UINT8 *InData,
2527 IN UINTN InDataSize,
2528 IN UINT8 *SignCert,
2529 IN UINT8 *OtherCerts OPTIONAL,
2530 OUT UINT8 **SignedData,
2531 OUT UINTN *SignedDataSize
2532 );
2533
2534 /**
2535 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2536 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2537 in a ContentInfo structure.
2538
2539 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2540 If P7Length, CertLength or DataLength overflow, then return FALSE.
2541 If this interface is not supported, then return FALSE.
2542
2543 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2544 @param[in] P7Length Length of the PKCS#7 message in bytes.
2545 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2546 is used for certificate chain verification.
2547 @param[in] CertLength Length of the trusted certificate in bytes.
2548 @param[in] InData Pointer to the content to be verified.
2549 @param[in] DataLength Length of InData in bytes.
2550
2551 @retval TRUE The specified PKCS#7 signed data is valid.
2552 @retval FALSE Invalid PKCS#7 signed data.
2553 @retval FALSE This interface is not supported.
2554
2555 **/
2556 BOOLEAN
2557 EFIAPI
2558 Pkcs7Verify (
2559 IN CONST UINT8 *P7Data,
2560 IN UINTN P7Length,
2561 IN CONST UINT8 *TrustedCert,
2562 IN UINTN CertLength,
2563 IN CONST UINT8 *InData,
2564 IN UINTN DataLength
2565 );
2566
2567 /**
2568 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2569 data could be wrapped in a ContentInfo structure.
2570
2571 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2572 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2573
2574 Caution: This function may receive untrusted input. So this function will do
2575 basic check for PKCS#7 data structure.
2576
2577 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2578 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2579 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2580 It's caller's responsibility to free the buffer with FreePool().
2581 @param[out] ContentSize The size of the extracted content in bytes.
2582
2583 @retval TRUE The P7Data was correctly formatted for processing.
2584 @retval FALSE The P7Data was not correctly formatted for processing.
2585
2586 **/
2587 BOOLEAN
2588 EFIAPI
2589 Pkcs7GetAttachedContent (
2590 IN CONST UINT8 *P7Data,
2591 IN UINTN P7Length,
2592 OUT VOID **Content,
2593 OUT UINTN *ContentSize
2594 );
2595
2596 /**
2597 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2598 Authenticode Portable Executable Signature Format".
2599
2600 If AuthData is NULL, then return FALSE.
2601 If ImageHash is NULL, then return FALSE.
2602 If this interface is not supported, then return FALSE.
2603
2604 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2605 PE/COFF image to be verified.
2606 @param[in] DataSize Size of the Authenticode Signature in bytes.
2607 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2608 is used for certificate chain verification.
2609 @param[in] CertSize Size of the trusted certificate in bytes.
2610 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2611 for calculating the image hash value is described in Authenticode
2612 specification.
2613 @param[in] HashSize Size of Image hash value in bytes.
2614
2615 @retval TRUE The specified Authenticode Signature is valid.
2616 @retval FALSE Invalid Authenticode Signature.
2617 @retval FALSE This interface is not supported.
2618
2619 **/
2620 BOOLEAN
2621 EFIAPI
2622 AuthenticodeVerify (
2623 IN CONST UINT8 *AuthData,
2624 IN UINTN DataSize,
2625 IN CONST UINT8 *TrustedCert,
2626 IN UINTN CertSize,
2627 IN CONST UINT8 *ImageHash,
2628 IN UINTN HashSize
2629 );
2630
2631 /**
2632 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2633 signature.
2634
2635 If AuthData is NULL, then return FALSE.
2636 If this interface is not supported, then return FALSE.
2637
2638 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2639 PE/COFF image to be verified.
2640 @param[in] DataSize Size of the Authenticode Signature in bytes.
2641 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2642 is used for TSA certificate chain verification.
2643 @param[in] CertSize Size of the trusted certificate in bytes.
2644 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2645 signature is valid.
2646
2647 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2648 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2649
2650 **/
2651 BOOLEAN
2652 EFIAPI
2653 ImageTimestampVerify (
2654 IN CONST UINT8 *AuthData,
2655 IN UINTN DataSize,
2656 IN CONST UINT8 *TsaCert,
2657 IN UINTN CertSize,
2658 OUT EFI_TIME *SigningTime
2659 );
2660
2661 //=====================================================================================
2662 // DH Key Exchange Primitive
2663 //=====================================================================================
2664
2665 /**
2666 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
2667
2668 @return Pointer to the Diffie-Hellman Context that has been initialized.
2669 If the allocations fails, DhNew() returns NULL.
2670 If the interface is not supported, DhNew() returns NULL.
2671
2672 **/
2673 VOID *
2674 EFIAPI
2675 DhNew (
2676 VOID
2677 );
2678
2679 /**
2680 Release the specified DH context.
2681
2682 If the interface is not supported, then ASSERT().
2683
2684 @param[in] DhContext Pointer to the DH context to be released.
2685
2686 **/
2687 VOID
2688 EFIAPI
2689 DhFree (
2690 IN VOID *DhContext
2691 );
2692
2693 /**
2694 Generates DH parameter.
2695
2696 Given generator g, and length of prime number p in bits, this function generates p,
2697 and sets DH context according to value of g and p.
2698
2699 Before this function can be invoked, pseudorandom number generator must be correctly
2700 initialized by RandomSeed().
2701
2702 If DhContext is NULL, then return FALSE.
2703 If Prime is NULL, then return FALSE.
2704 If this interface is not supported, then return FALSE.
2705
2706 @param[in, out] DhContext Pointer to the DH context.
2707 @param[in] Generator Value of generator.
2708 @param[in] PrimeLength Length in bits of prime to be generated.
2709 @param[out] Prime Pointer to the buffer to receive the generated prime number.
2710
2711 @retval TRUE DH parameter generation succeeded.
2712 @retval FALSE Value of Generator is not supported.
2713 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
2714 @retval FALSE This interface is not supported.
2715
2716 **/
2717 BOOLEAN
2718 EFIAPI
2719 DhGenerateParameter (
2720 IN OUT VOID *DhContext,
2721 IN UINTN Generator,
2722 IN UINTN PrimeLength,
2723 OUT UINT8 *Prime
2724 );
2725
2726 /**
2727 Sets generator and prime parameters for DH.
2728
2729 Given generator g, and prime number p, this function and sets DH
2730 context accordingly.
2731
2732 If DhContext is NULL, then return FALSE.
2733 If Prime is NULL, then return FALSE.
2734 If this interface is not supported, then return FALSE.
2735
2736 @param[in, out] DhContext Pointer to the DH context.
2737 @param[in] Generator Value of generator.
2738 @param[in] PrimeLength Length in bits of prime to be generated.
2739 @param[in] Prime Pointer to the prime number.
2740
2741 @retval TRUE DH parameter setting succeeded.
2742 @retval FALSE Value of Generator is not supported.
2743 @retval FALSE Value of Generator is not suitable for the Prime.
2744 @retval FALSE Value of Prime is not a prime number.
2745 @retval FALSE Value of Prime is not a safe prime number.
2746 @retval FALSE This interface is not supported.
2747
2748 **/
2749 BOOLEAN
2750 EFIAPI
2751 DhSetParameter (
2752 IN OUT VOID *DhContext,
2753 IN UINTN Generator,
2754 IN UINTN PrimeLength,
2755 IN CONST UINT8 *Prime
2756 );
2757
2758 /**
2759 Generates DH public key.
2760
2761 This function generates random secret exponent, and computes the public key, which is
2762 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
2763 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
2764 PublicKeySize is set to the required buffer size to obtain the public key.
2765
2766 If DhContext is NULL, then return FALSE.
2767 If PublicKeySize is NULL, then return FALSE.
2768 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
2769 If this interface is not supported, then return FALSE.
2770
2771 @param[in, out] DhContext Pointer to the DH context.
2772 @param[out] PublicKey Pointer to the buffer to receive generated public key.
2773 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
2774 On output, the size of data returned in PublicKey buffer in bytes.
2775
2776 @retval TRUE DH public key generation succeeded.
2777 @retval FALSE DH public key generation failed.
2778 @retval FALSE PublicKeySize is not large enough.
2779 @retval FALSE This interface is not supported.
2780
2781 **/
2782 BOOLEAN
2783 EFIAPI
2784 DhGenerateKey (
2785 IN OUT VOID *DhContext,
2786 OUT UINT8 *PublicKey,
2787 IN OUT UINTN *PublicKeySize
2788 );
2789
2790 /**
2791 Computes exchanged common key.
2792
2793 Given peer's public key, this function computes the exchanged common key, based on its own
2794 context including value of prime modulus and random secret exponent.
2795
2796 If DhContext is NULL, then return FALSE.
2797 If PeerPublicKey is NULL, then return FALSE.
2798 If KeySize is NULL, then return FALSE.
2799 If Key is NULL, then return FALSE.
2800 If KeySize is not large enough, then return FALSE.
2801 If this interface is not supported, then return FALSE.
2802
2803 @param[in, out] DhContext Pointer to the DH context.
2804 @param[in] PeerPublicKey Pointer to the peer's public key.
2805 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
2806 @param[out] Key Pointer to the buffer to receive generated key.
2807 @param[in, out] KeySize On input, the size of Key buffer in bytes.
2808 On output, the size of data returned in Key buffer in bytes.
2809
2810 @retval TRUE DH exchanged key generation succeeded.
2811 @retval FALSE DH exchanged key generation failed.
2812 @retval FALSE KeySize is not large enough.
2813 @retval FALSE This interface is not supported.
2814
2815 **/
2816 BOOLEAN
2817 EFIAPI
2818 DhComputeKey (
2819 IN OUT VOID *DhContext,
2820 IN CONST UINT8 *PeerPublicKey,
2821 IN UINTN PeerPublicKeySize,
2822 OUT UINT8 *Key,
2823 IN OUT UINTN *KeySize
2824 );
2825
2826 //=====================================================================================
2827 // Pseudo-Random Generation Primitive
2828 //=====================================================================================
2829
2830 /**
2831 Sets up the seed value for the pseudorandom number generator.
2832
2833 This function sets up the seed value for the pseudorandom number generator.
2834 If Seed is not NULL, then the seed passed in is used.
2835 If Seed is NULL, then default seed is used.
2836 If this interface is not supported, then return FALSE.
2837
2838 @param[in] Seed Pointer to seed value.
2839 If NULL, default seed is used.
2840 @param[in] SeedSize Size of seed value.
2841 If Seed is NULL, this parameter is ignored.
2842
2843 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
2844 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
2845 @retval FALSE This interface is not supported.
2846
2847 **/
2848 BOOLEAN
2849 EFIAPI
2850 RandomSeed (
2851 IN CONST UINT8 *Seed OPTIONAL,
2852 IN UINTN SeedSize
2853 );
2854
2855 /**
2856 Generates a pseudorandom byte stream of the specified size.
2857
2858 If Output is NULL, then return FALSE.
2859 If this interface is not supported, then return FALSE.
2860
2861 @param[out] Output Pointer to buffer to receive random value.
2862 @param[in] Size Size of random bytes to generate.
2863
2864 @retval TRUE Pseudorandom byte stream generated successfully.
2865 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
2866 @retval FALSE This interface is not supported.
2867
2868 **/
2869 BOOLEAN
2870 EFIAPI
2871 RandomBytes (
2872 OUT UINT8 *Output,
2873 IN UINTN Size
2874 );
2875
2876 #endif // __BASE_CRYPT_LIB_H__