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