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