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