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