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