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