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