]> git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c
CryptoPkg: Add new hmac SHA api to Crypto Service.
[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 // Asymmetric Cryptography Primitive
1557 // =====================================================================================
1558
1559 /**
1560 Allocates and initializes one RSA context for subsequent use.
1561
1562 @return Pointer to the RSA context that has been initialized.
1563 If the allocations fails, RsaNew() returns NULL.
1564
1565 **/
1566 VOID *
1567 EFIAPI
1568 RsaNew (
1569 VOID
1570 )
1571 {
1572 CALL_CRYPTO_SERVICE (RsaNew, (), NULL);
1573 }
1574
1575 /**
1576 Release the specified RSA context.
1577
1578 If RsaContext is NULL, then return FALSE.
1579
1580 @param[in] RsaContext Pointer to the RSA context to be released.
1581
1582 **/
1583 VOID
1584 EFIAPI
1585 RsaFree (
1586 IN VOID *RsaContext
1587 )
1588 {
1589 CALL_VOID_CRYPTO_SERVICE (RsaFree, (RsaContext));
1590 }
1591
1592 /**
1593 Sets the tag-designated key component into the established RSA context.
1594
1595 This function sets the tag-designated RSA key component into the established
1596 RSA context from the user-specified non-negative integer (octet string format
1597 represented in RSA PKCS#1).
1598 If BigNumber is NULL, then the specified key component in RSA context is cleared.
1599
1600 If RsaContext is NULL, then return FALSE.
1601
1602 @param[in, out] RsaContext Pointer to RSA context being set.
1603 @param[in] KeyTag Tag of RSA key component being set.
1604 @param[in] BigNumber Pointer to octet integer buffer.
1605 If NULL, then the specified key component in RSA
1606 context is cleared.
1607 @param[in] BnSize Size of big number buffer in bytes.
1608 If BigNumber is NULL, then it is ignored.
1609
1610 @retval TRUE RSA key component was set successfully.
1611 @retval FALSE Invalid RSA key component tag.
1612
1613 **/
1614 BOOLEAN
1615 EFIAPI
1616 RsaSetKey (
1617 IN OUT VOID *RsaContext,
1618 IN RSA_KEY_TAG KeyTag,
1619 IN CONST UINT8 *BigNumber,
1620 IN UINTN BnSize
1621 )
1622 {
1623 CALL_CRYPTO_SERVICE (RsaSetKey, (RsaContext, KeyTag, BigNumber, BnSize), FALSE);
1624 }
1625
1626 /**
1627 Gets the tag-designated RSA key component from the established RSA context.
1628
1629 This function retrieves the tag-designated RSA key component from the
1630 established RSA context as a non-negative integer (octet string format
1631 represented in RSA PKCS#1).
1632 If specified key component has not been set or has been cleared, then returned
1633 BnSize is set to 0.
1634 If the BigNumber buffer is too small to hold the contents of the key, FALSE
1635 is returned and BnSize is set to the required buffer size to obtain the key.
1636
1637 If RsaContext is NULL, then return FALSE.
1638 If BnSize is NULL, then return FALSE.
1639 If BnSize is large enough but BigNumber is NULL, then return FALSE.
1640 If this interface is not supported, then return FALSE.
1641
1642 @param[in, out] RsaContext Pointer to RSA context being set.
1643 @param[in] KeyTag Tag of RSA key component being set.
1644 @param[out] BigNumber Pointer to octet integer buffer.
1645 @param[in, out] BnSize On input, the size of big number buffer in bytes.
1646 On output, the size of data returned in big number buffer in bytes.
1647
1648 @retval TRUE RSA key component was retrieved successfully.
1649 @retval FALSE Invalid RSA key component tag.
1650 @retval FALSE BnSize is too small.
1651 @retval FALSE This interface is not supported.
1652
1653 **/
1654 BOOLEAN
1655 EFIAPI
1656 RsaGetKey (
1657 IN OUT VOID *RsaContext,
1658 IN RSA_KEY_TAG KeyTag,
1659 OUT UINT8 *BigNumber,
1660 IN OUT UINTN *BnSize
1661 )
1662 {
1663 CALL_CRYPTO_SERVICE (RsaGetKey, (RsaContext, KeyTag, BigNumber, BnSize), FALSE);
1664 }
1665
1666 /**
1667 Generates RSA key components.
1668
1669 This function generates RSA key components. It takes RSA public exponent E and
1670 length in bits of RSA modulus N as input, and generates all key components.
1671 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
1672
1673 Before this function can be invoked, pseudorandom number generator must be correctly
1674 initialized by RandomSeed().
1675
1676 If RsaContext is NULL, then return FALSE.
1677 If this interface is not supported, then return FALSE.
1678
1679 @param[in, out] RsaContext Pointer to RSA context being set.
1680 @param[in] ModulusLength Length of RSA modulus N in bits.
1681 @param[in] PublicExponent Pointer to RSA public exponent.
1682 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
1683
1684 @retval TRUE RSA key component was generated successfully.
1685 @retval FALSE Invalid RSA key component tag.
1686 @retval FALSE This interface is not supported.
1687
1688 **/
1689 BOOLEAN
1690 EFIAPI
1691 RsaGenerateKey (
1692 IN OUT VOID *RsaContext,
1693 IN UINTN ModulusLength,
1694 IN CONST UINT8 *PublicExponent,
1695 IN UINTN PublicExponentSize
1696 )
1697 {
1698 CALL_CRYPTO_SERVICE (RsaGenerateKey, (RsaContext, ModulusLength, PublicExponent, PublicExponentSize), FALSE);
1699 }
1700
1701 /**
1702 Validates key components of RSA context.
1703 NOTE: This function performs integrity checks on all the RSA key material, so
1704 the RSA key structure must contain all the private key data.
1705
1706 This function validates key components of RSA context in following aspects:
1707 - Whether p is a prime
1708 - Whether q is a prime
1709 - Whether n = p * q
1710 - Whether d*e = 1 mod lcm(p-1,q-1)
1711
1712 If RsaContext is NULL, then return FALSE.
1713 If this interface is not supported, then return FALSE.
1714
1715 @param[in] RsaContext Pointer to RSA context to check.
1716
1717 @retval TRUE RSA key components are valid.
1718 @retval FALSE RSA key components are not valid.
1719 @retval FALSE This interface is not supported.
1720
1721 **/
1722 BOOLEAN
1723 EFIAPI
1724 RsaCheckKey (
1725 IN VOID *RsaContext
1726 )
1727 {
1728 CALL_CRYPTO_SERVICE (RsaCheckKey, (RsaContext), FALSE);
1729 }
1730
1731 /**
1732 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
1733
1734 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
1735 RSA PKCS#1.
1736 If the Signature buffer is too small to hold the contents of signature, FALSE
1737 is returned and SigSize is set to the required buffer size to obtain the signature.
1738
1739 If RsaContext is NULL, then return FALSE.
1740 If MessageHash is NULL, then return FALSE.
1741 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
1742 If SigSize is large enough but Signature is NULL, then return FALSE.
1743 If this interface is not supported, then return FALSE.
1744
1745 @param[in] RsaContext Pointer to RSA context for signature generation.
1746 @param[in] MessageHash Pointer to octet message hash to be signed.
1747 @param[in] HashSize Size of the message hash in bytes.
1748 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
1749 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1750 On output, the size of data returned in Signature buffer in bytes.
1751
1752 @retval TRUE Signature successfully generated in PKCS1-v1_5.
1753 @retval FALSE Signature generation failed.
1754 @retval FALSE SigSize is too small.
1755 @retval FALSE This interface is not supported.
1756
1757 **/
1758 BOOLEAN
1759 EFIAPI
1760 RsaPkcs1Sign (
1761 IN VOID *RsaContext,
1762 IN CONST UINT8 *MessageHash,
1763 IN UINTN HashSize,
1764 OUT UINT8 *Signature,
1765 IN OUT UINTN *SigSize
1766 )
1767 {
1768 CALL_CRYPTO_SERVICE (RsaPkcs1Sign, (RsaContext, MessageHash, HashSize, Signature, SigSize), FALSE);
1769 }
1770
1771 /**
1772 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
1773 RSA PKCS#1.
1774
1775 If RsaContext is NULL, then return FALSE.
1776 If MessageHash is NULL, then return FALSE.
1777 If Signature is NULL, then return FALSE.
1778 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
1779
1780 @param[in] RsaContext Pointer to RSA context for signature verification.
1781 @param[in] MessageHash Pointer to octet message hash to be checked.
1782 @param[in] HashSize Size of the message hash in bytes.
1783 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
1784 @param[in] SigSize Size of signature in bytes.
1785
1786 @retval TRUE Valid signature encoded in PKCS1-v1_5.
1787 @retval FALSE Invalid signature or invalid RSA context.
1788
1789 **/
1790 BOOLEAN
1791 EFIAPI
1792 RsaPkcs1Verify (
1793 IN VOID *RsaContext,
1794 IN CONST UINT8 *MessageHash,
1795 IN UINTN HashSize,
1796 IN CONST UINT8 *Signature,
1797 IN UINTN SigSize
1798 )
1799 {
1800 CALL_CRYPTO_SERVICE (RsaPkcs1Verify, (RsaContext, MessageHash, HashSize, Signature, SigSize), FALSE);
1801 }
1802
1803 /**
1804 Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
1805 Implementation determines salt length automatically from the signature encoding.
1806 Mask generation function is the same as the message digest algorithm.
1807 Salt length should be equal to digest length.
1808
1809 @param[in] RsaContext Pointer to RSA context for signature verification.
1810 @param[in] Message Pointer to octet message to be verified.
1811 @param[in] MsgSize Size of the message in bytes.
1812 @param[in] Signature Pointer to RSASSA-PSS signature to be verified.
1813 @param[in] SigSize Size of signature in bytes.
1814 @param[in] DigestLen Length of digest for RSA operation.
1815 @param[in] SaltLen Salt length for PSS encoding.
1816
1817 @retval TRUE Valid signature encoded in RSASSA-PSS.
1818 @retval FALSE Invalid signature or invalid RSA context.
1819
1820 **/
1821 BOOLEAN
1822 EFIAPI
1823 RsaPssVerify (
1824 IN VOID *RsaContext,
1825 IN CONST UINT8 *Message,
1826 IN UINTN MsgSize,
1827 IN CONST UINT8 *Signature,
1828 IN UINTN SigSize,
1829 IN UINT16 DigestLen,
1830 IN UINT16 SaltLen
1831 )
1832 {
1833 CALL_CRYPTO_SERVICE (RsaPssVerify, (RsaContext, Message, MsgSize, Signature, SigSize, DigestLen, SaltLen), FALSE);
1834 }
1835
1836 /**
1837 This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in
1838 RFC 8017.
1839 Mask generation function is the same as the message digest algorithm.
1840 If the Signature buffer is too small to hold the contents of signature, FALSE
1841 is returned and SigSize is set to the required buffer size to obtain the signature.
1842
1843 If RsaContext is NULL, then return FALSE.
1844 If Message is NULL, then return FALSE.
1845 If MsgSize is zero or > INT_MAX, then return FALSE.
1846 If DigestLen is NOT 32, 48 or 64, return FALSE.
1847 If SaltLen is not equal to DigestLen, then return FALSE.
1848 If SigSize is large enough but Signature is NULL, then return FALSE.
1849 If this interface is not supported, then return FALSE.
1850
1851 @param[in] RsaContext Pointer to RSA context for signature generation.
1852 @param[in] Message Pointer to octet message to be signed.
1853 @param[in] MsgSize Size of the message in bytes.
1854 @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.
1855 @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.
1856 @param[out] Signature Pointer to buffer to receive RSA PSS signature.
1857 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1858 On output, the size of data returned in Signature buffer in bytes.
1859
1860 @retval TRUE Signature successfully generated in RSASSA-PSS.
1861 @retval FALSE Signature generation failed.
1862 @retval FALSE SigSize is too small.
1863 @retval FALSE This interface is not supported.
1864
1865 **/
1866 BOOLEAN
1867 EFIAPI
1868 RsaPssSign (
1869 IN VOID *RsaContext,
1870 IN CONST UINT8 *Message,
1871 IN UINTN MsgSize,
1872 IN UINT16 DigestLen,
1873 IN UINT16 SaltLen,
1874 OUT UINT8 *Signature,
1875 IN OUT UINTN *SigSize
1876 )
1877 {
1878 CALL_CRYPTO_SERVICE (RsaPssSign, (RsaContext, Message, MsgSize, DigestLen, SaltLen, Signature, SigSize), FALSE);
1879 }
1880
1881 /**
1882 Retrieve the RSA Private Key from the password-protected PEM key data.
1883
1884 If PemData is NULL, then return FALSE.
1885 If RsaContext is NULL, then return FALSE.
1886 If this interface is not supported, then return FALSE.
1887
1888 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
1889 @param[in] PemSize Size of the PEM key data in bytes.
1890 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
1891 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1892 RSA private key component. Use RsaFree() function to free the
1893 resource.
1894
1895 @retval TRUE RSA Private Key was retrieved successfully.
1896 @retval FALSE Invalid PEM key data or incorrect password.
1897 @retval FALSE This interface is not supported.
1898
1899 **/
1900 BOOLEAN
1901 EFIAPI
1902 RsaGetPrivateKeyFromPem (
1903 IN CONST UINT8 *PemData,
1904 IN UINTN PemSize,
1905 IN CONST CHAR8 *Password,
1906 OUT VOID **RsaContext
1907 )
1908 {
1909 CALL_CRYPTO_SERVICE (RsaGetPrivateKeyFromPem, (PemData, PemSize, Password, RsaContext), FALSE);
1910 }
1911
1912 /**
1913 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
1914
1915 If Cert is NULL, then return FALSE.
1916 If RsaContext is NULL, then return FALSE.
1917 If this interface is not supported, then return FALSE.
1918
1919 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1920 @param[in] CertSize Size of the X509 certificate in bytes.
1921 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1922 RSA public key component. Use RsaFree() function to free the
1923 resource.
1924
1925 @retval TRUE RSA Public Key was retrieved successfully.
1926 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
1927 @retval FALSE This interface is not supported.
1928
1929 **/
1930 BOOLEAN
1931 EFIAPI
1932 RsaGetPublicKeyFromX509 (
1933 IN CONST UINT8 *Cert,
1934 IN UINTN CertSize,
1935 OUT VOID **RsaContext
1936 )
1937 {
1938 CALL_CRYPTO_SERVICE (RsaGetPublicKeyFromX509, (Cert, CertSize, RsaContext), FALSE);
1939 }
1940
1941 /**
1942 Retrieve the subject bytes from one X.509 certificate.
1943
1944 If Cert is NULL, then return FALSE.
1945 If SubjectSize is NULL, then return FALSE.
1946 If this interface is not supported, then return FALSE.
1947
1948 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1949 @param[in] CertSize Size of the X509 certificate in bytes.
1950 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
1951 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
1952 and the size of buffer returned CertSubject on output.
1953
1954 @retval TRUE The certificate subject retrieved successfully.
1955 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
1956 The SubjectSize will be updated with the required size.
1957 @retval FALSE This interface is not supported.
1958
1959 **/
1960 BOOLEAN
1961 EFIAPI
1962 X509GetSubjectName (
1963 IN CONST UINT8 *Cert,
1964 IN UINTN CertSize,
1965 OUT UINT8 *CertSubject,
1966 IN OUT UINTN *SubjectSize
1967 )
1968 {
1969 CALL_CRYPTO_SERVICE (X509GetSubjectName, (Cert, CertSize, CertSubject, SubjectSize), FALSE);
1970 }
1971
1972 /**
1973 Retrieve the common name (CN) string from one X.509 certificate.
1974
1975 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1976 @param[in] CertSize Size of the X509 certificate in bytes.
1977 @param[out] CommonName Buffer to contain the retrieved certificate common
1978 name string (UTF8). At most CommonNameSize bytes will be
1979 written and the string will be null terminated. May be
1980 NULL in order to determine the size buffer needed.
1981 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
1982 and the size of buffer returned CommonName on output.
1983 If CommonName is NULL then the amount of space needed
1984 in buffer (including the final null) is returned.
1985
1986 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
1987 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
1988 If CommonNameSize is NULL.
1989 If CommonName is not NULL and *CommonNameSize is 0.
1990 If Certificate is invalid.
1991 @retval RETURN_NOT_FOUND If no CommonName entry exists.
1992 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
1993 (including the final null) is returned in the
1994 CommonNameSize parameter.
1995 @retval RETURN_UNSUPPORTED The operation is not supported.
1996
1997 **/
1998 RETURN_STATUS
1999 EFIAPI
2000 X509GetCommonName (
2001 IN CONST UINT8 *Cert,
2002 IN UINTN CertSize,
2003 OUT CHAR8 *CommonName OPTIONAL,
2004 IN OUT UINTN *CommonNameSize
2005 )
2006 {
2007 CALL_CRYPTO_SERVICE (X509GetCommonName, (Cert, CertSize, CommonName, CommonNameSize), RETURN_UNSUPPORTED);
2008 }
2009
2010 /**
2011 Retrieve the organization name (O) string from one X.509 certificate.
2012
2013 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2014 @param[in] CertSize Size of the X509 certificate in bytes.
2015 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
2016 name string. At most NameBufferSize bytes will be
2017 written and the string will be null terminated. May be
2018 NULL in order to determine the size buffer needed.
2019 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
2020 and the size of buffer returned Name on output.
2021 If NameBuffer is NULL then the amount of space needed
2022 in buffer (including the final null) is returned.
2023
2024 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
2025 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2026 If NameBufferSize is NULL.
2027 If NameBuffer is not NULL and *CommonNameSize is 0.
2028 If Certificate is invalid.
2029 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
2030 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
2031 (including the final null) is returned in the
2032 CommonNameSize parameter.
2033 @retval RETURN_UNSUPPORTED The operation is not supported.
2034
2035 **/
2036 RETURN_STATUS
2037 EFIAPI
2038 X509GetOrganizationName (
2039 IN CONST UINT8 *Cert,
2040 IN UINTN CertSize,
2041 OUT CHAR8 *NameBuffer OPTIONAL,
2042 IN OUT UINTN *NameBufferSize
2043 )
2044 {
2045 CALL_CRYPTO_SERVICE (X509GetOrganizationName, (Cert, CertSize, NameBuffer, NameBufferSize), RETURN_UNSUPPORTED);
2046 }
2047
2048 /**
2049 Verify one X509 certificate was issued by the trusted CA.
2050
2051 If Cert is NULL, then return FALSE.
2052 If CACert is NULL, then return FALSE.
2053 If this interface is not supported, then return FALSE.
2054
2055 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
2056 @param[in] CertSize Size of the X509 certificate in bytes.
2057 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
2058 @param[in] CACertSize Size of the CA Certificate in bytes.
2059
2060 @retval TRUE The certificate was issued by the trusted CA.
2061 @retval FALSE Invalid certificate or the certificate was not issued by the given
2062 trusted CA.
2063 @retval FALSE This interface is not supported.
2064
2065 **/
2066 BOOLEAN
2067 EFIAPI
2068 X509VerifyCert (
2069 IN CONST UINT8 *Cert,
2070 IN UINTN CertSize,
2071 IN CONST UINT8 *CACert,
2072 IN UINTN CACertSize
2073 )
2074 {
2075 CALL_CRYPTO_SERVICE (X509VerifyCert, (Cert, CertSize, CACert, CACertSize), FALSE);
2076 }
2077
2078 /**
2079 Construct a X509 object from DER-encoded certificate data.
2080
2081 If Cert is NULL, then return FALSE.
2082 If SingleX509Cert is NULL, then return FALSE.
2083 If this interface is not supported, then return FALSE.
2084
2085 @param[in] Cert Pointer to the DER-encoded certificate data.
2086 @param[in] CertSize The size of certificate data in bytes.
2087 @param[out] SingleX509Cert The generated X509 object.
2088
2089 @retval TRUE The X509 object generation succeeded.
2090 @retval FALSE The operation failed.
2091 @retval FALSE This interface is not supported.
2092
2093 **/
2094 BOOLEAN
2095 EFIAPI
2096 X509ConstructCertificate (
2097 IN CONST UINT8 *Cert,
2098 IN UINTN CertSize,
2099 OUT UINT8 **SingleX509Cert
2100 )
2101 {
2102 CALL_CRYPTO_SERVICE (X509ConstructCertificate, (Cert, CertSize, SingleX509Cert), FALSE);
2103 }
2104
2105 /**
2106 Construct a X509 stack object from a list of DER-encoded certificate data.
2107
2108 If X509Stack is NULL, then return FALSE.
2109 If this interface is not supported, then return FALSE.
2110
2111 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2112 On output, pointer to the X509 stack object with new
2113 inserted X509 certificate.
2114 @param[in] Args VA_LIST marker for the variable argument list.
2115 ... A list of DER-encoded single certificate data followed
2116 by certificate size. A NULL terminates the list. The
2117 pairs are the arguments to X509ConstructCertificate().
2118
2119 @retval TRUE The X509 stack construction succeeded.
2120 @retval FALSE The construction operation failed.
2121 @retval FALSE This interface is not supported.
2122
2123 **/
2124 BOOLEAN
2125 EFIAPI
2126 X509ConstructCertificateStack (
2127 IN OUT UINT8 **X509Stack,
2128 ...
2129 )
2130 {
2131 VA_LIST Args;
2132 BOOLEAN Result;
2133
2134 VA_START (Args, X509Stack);
2135 Result = X509ConstructCertificateStackV (X509Stack, Args);
2136 VA_END (Args);
2137 return Result;
2138 }
2139
2140 /**
2141 Construct a X509 stack object from a list of DER-encoded certificate data.
2142
2143 If X509Stack is NULL, then return FALSE.
2144 If this interface is not supported, then return FALSE.
2145
2146 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2147 On output, pointer to the X509 stack object with new
2148 inserted X509 certificate.
2149 @param[in] Args VA_LIST marker for the variable argument list.
2150 A list of DER-encoded single certificate data followed
2151 by certificate size. A NULL terminates the list. The
2152 pairs are the arguments to X509ConstructCertificate().
2153
2154 @retval TRUE The X509 stack construction succeeded.
2155 @retval FALSE The construction operation failed.
2156 @retval FALSE This interface is not supported.
2157
2158 **/
2159 BOOLEAN
2160 EFIAPI
2161 X509ConstructCertificateStackV (
2162 IN OUT UINT8 **X509Stack,
2163 IN VA_LIST Args
2164 )
2165 {
2166 CALL_CRYPTO_SERVICE (X509ConstructCertificateStackV, (X509Stack, Args), FALSE);
2167 }
2168
2169 /**
2170 Release the specified X509 object.
2171
2172 If the interface is not supported, then ASSERT().
2173
2174 @param[in] X509Cert Pointer to the X509 object to be released.
2175
2176 **/
2177 VOID
2178 EFIAPI
2179 X509Free (
2180 IN VOID *X509Cert
2181 )
2182 {
2183 CALL_VOID_CRYPTO_SERVICE (X509Free, (X509Cert));
2184 }
2185
2186 /**
2187 Release the specified X509 stack object.
2188
2189 If the interface is not supported, then ASSERT().
2190
2191 @param[in] X509Stack Pointer to the X509 stack object to be released.
2192
2193 **/
2194 VOID
2195 EFIAPI
2196 X509StackFree (
2197 IN VOID *X509Stack
2198 )
2199 {
2200 CALL_VOID_CRYPTO_SERVICE (X509StackFree, (X509Stack));
2201 }
2202
2203 /**
2204 Retrieve the TBSCertificate from one given X.509 certificate.
2205
2206 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
2207 @param[in] CertSize Size of the X509 certificate in bytes.
2208 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
2209 @param[out] TBSCertSize Size of the TBS certificate in bytes.
2210
2211 If Cert is NULL, then return FALSE.
2212 If TBSCert is NULL, then return FALSE.
2213 If TBSCertSize is NULL, then return FALSE.
2214 If this interface is not supported, then return FALSE.
2215
2216 @retval TRUE The TBSCertificate was retrieved successfully.
2217 @retval FALSE Invalid X.509 certificate.
2218
2219 **/
2220 BOOLEAN
2221 EFIAPI
2222 X509GetTBSCert (
2223 IN CONST UINT8 *Cert,
2224 IN UINTN CertSize,
2225 OUT UINT8 **TBSCert,
2226 OUT UINTN *TBSCertSize
2227 )
2228 {
2229 CALL_CRYPTO_SERVICE (X509GetTBSCert, (Cert, CertSize, TBSCert, TBSCertSize), FALSE);
2230 }
2231
2232 /**
2233 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2234 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2235
2236 If Password or Salt or OutKey is NULL, then return FALSE.
2237 If the hash algorithm could not be determined, then return FALSE.
2238 If this interface is not supported, then return FALSE.
2239
2240 @param[in] PasswordLength Length of input password in bytes.
2241 @param[in] Password Pointer to the array for the password.
2242 @param[in] SaltLength Size of the Salt in bytes.
2243 @param[in] Salt Pointer to the Salt.
2244 @param[in] IterationCount Number of iterations to perform. Its value should be
2245 greater than or equal to 1.
2246 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2247 NOTE: DigestSize will be used to determine the hash algorithm.
2248 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2249 @param[in] KeyLength Size of the derived key buffer in bytes.
2250 @param[out] OutKey Pointer to the output derived key buffer.
2251
2252 @retval TRUE A key was derived successfully.
2253 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2254 @retval FALSE The hash algorithm could not be determined from the digest size.
2255 @retval FALSE The key derivation operation failed.
2256 @retval FALSE This interface is not supported.
2257
2258 **/
2259 BOOLEAN
2260 EFIAPI
2261 Pkcs5HashPassword (
2262 IN UINTN PasswordLength,
2263 IN CONST CHAR8 *Password,
2264 IN UINTN SaltLength,
2265 IN CONST UINT8 *Salt,
2266 IN UINTN IterationCount,
2267 IN UINTN DigestSize,
2268 IN UINTN KeyLength,
2269 OUT UINT8 *OutKey
2270 )
2271 {
2272 CALL_CRYPTO_SERVICE (Pkcs5HashPassword, (PasswordLength, Password, SaltLength, Salt, IterationCount, DigestSize, KeyLength, OutKey), FALSE);
2273 }
2274
2275 /**
2276 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2277 encrypted message in a newly allocated buffer.
2278
2279 Things that can cause a failure include:
2280 - X509 key size does not match any known key size.
2281 - Fail to parse X509 certificate.
2282 - Fail to allocate an intermediate buffer.
2283 - Null pointer provided for a non-optional parameter.
2284 - Data size is too large for the provided key size (max size is a function of key size
2285 and hash digest size).
2286
2287 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2288 will be used to encrypt the data.
2289 @param[in] PublicKeySize Size of the X509 cert buffer.
2290 @param[in] InData Data to be encrypted.
2291 @param[in] InDataSize Size of the data buffer.
2292 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2293 to be used when initializing the PRNG. NULL otherwise.
2294 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2295 0 otherwise.
2296 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2297 message.
2298 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2299
2300 @retval TRUE Encryption was successful.
2301 @retval FALSE Encryption failed.
2302
2303 **/
2304 BOOLEAN
2305 EFIAPI
2306 Pkcs1v2Encrypt (
2307 IN CONST UINT8 *PublicKey,
2308 IN UINTN PublicKeySize,
2309 IN UINT8 *InData,
2310 IN UINTN InDataSize,
2311 IN CONST UINT8 *PrngSeed OPTIONAL,
2312 IN UINTN PrngSeedSize OPTIONAL,
2313 OUT UINT8 **EncryptedData,
2314 OUT UINTN *EncryptedDataSize
2315 )
2316 {
2317 CALL_CRYPTO_SERVICE (Pkcs1v2Encrypt, (PublicKey, PublicKeySize, InData, InDataSize, PrngSeed, PrngSeedSize, EncryptedData, EncryptedDataSize), FALSE);
2318 }
2319
2320 /**
2321 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2322 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2323 in a ContentInfo structure.
2324
2325 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2326 return FALSE. If P7Length overflow, then return FALSE.
2327 If this interface is not supported, then return FALSE.
2328
2329 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2330 @param[in] P7Length Length of the PKCS#7 message in bytes.
2331 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2332 It's caller's responsibility to free the buffer with
2333 Pkcs7FreeSigners().
2334 This data structure is EFI_CERT_STACK type.
2335 @param[out] StackLength Length of signer's certificates in bytes.
2336 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2337 It's caller's responsibility to free the buffer with
2338 Pkcs7FreeSigners().
2339 @param[out] CertLength Length of the trusted certificate in bytes.
2340
2341 @retval TRUE The operation is finished successfully.
2342 @retval FALSE Error occurs during the operation.
2343 @retval FALSE This interface is not supported.
2344
2345 **/
2346 BOOLEAN
2347 EFIAPI
2348 Pkcs7GetSigners (
2349 IN CONST UINT8 *P7Data,
2350 IN UINTN P7Length,
2351 OUT UINT8 **CertStack,
2352 OUT UINTN *StackLength,
2353 OUT UINT8 **TrustedCert,
2354 OUT UINTN *CertLength
2355 )
2356 {
2357 CALL_CRYPTO_SERVICE (Pkcs7GetSigners, (P7Data, P7Length, CertStack, StackLength, TrustedCert, CertLength), FALSE);
2358 }
2359
2360 /**
2361 Wrap function to use free() to free allocated memory for certificates.
2362
2363 If this interface is not supported, then ASSERT().
2364
2365 @param[in] Certs Pointer to the certificates to be freed.
2366
2367 **/
2368 VOID
2369 EFIAPI
2370 Pkcs7FreeSigners (
2371 IN UINT8 *Certs
2372 )
2373 {
2374 CALL_VOID_CRYPTO_SERVICE (Pkcs7FreeSigners, (Certs));
2375 }
2376
2377 /**
2378 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2379 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2380 unchained to the signer's certificates.
2381 The input signed data could be wrapped in a ContentInfo structure.
2382
2383 @param[in] P7Data Pointer to the PKCS#7 message.
2384 @param[in] P7Length Length of the PKCS#7 message in bytes.
2385 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2386 certificate. It's caller's responsibility to free the buffer
2387 with Pkcs7FreeSigners().
2388 This data structure is EFI_CERT_STACK type.
2389 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2390 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2391 responsibility to free the buffer with Pkcs7FreeSigners().
2392 This data structure is EFI_CERT_STACK type.
2393 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2394
2395 @retval TRUE The operation is finished successfully.
2396 @retval FALSE Error occurs during the operation.
2397
2398 **/
2399 BOOLEAN
2400 EFIAPI
2401 Pkcs7GetCertificatesList (
2402 IN CONST UINT8 *P7Data,
2403 IN UINTN P7Length,
2404 OUT UINT8 **SignerChainCerts,
2405 OUT UINTN *ChainLength,
2406 OUT UINT8 **UnchainCerts,
2407 OUT UINTN *UnchainLength
2408 )
2409 {
2410 CALL_CRYPTO_SERVICE (Pkcs7GetCertificatesList, (P7Data, P7Length, SignerChainCerts, ChainLength, UnchainCerts, UnchainLength), FALSE);
2411 }
2412
2413 /**
2414 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2415 Syntax Standard, version 1.5". This interface is only intended to be used for
2416 application to perform PKCS#7 functionality validation.
2417
2418 If this interface is not supported, then return FALSE.
2419
2420 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2421 data signing.
2422 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2423 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2424 key data.
2425 @param[in] InData Pointer to the content to be signed.
2426 @param[in] InDataSize Size of InData in bytes.
2427 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2428 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2429 include in the PKCS#7 signedData (e.g. any intermediate
2430 CAs in the chain).
2431 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2432 responsibility to free the buffer with FreePool().
2433 @param[out] SignedDataSize Size of SignedData in bytes.
2434
2435 @retval TRUE PKCS#7 data signing succeeded.
2436 @retval FALSE PKCS#7 data signing failed.
2437 @retval FALSE This interface is not supported.
2438
2439 **/
2440 BOOLEAN
2441 EFIAPI
2442 Pkcs7Sign (
2443 IN CONST UINT8 *PrivateKey,
2444 IN UINTN PrivateKeySize,
2445 IN CONST UINT8 *KeyPassword,
2446 IN UINT8 *InData,
2447 IN UINTN InDataSize,
2448 IN UINT8 *SignCert,
2449 IN UINT8 *OtherCerts OPTIONAL,
2450 OUT UINT8 **SignedData,
2451 OUT UINTN *SignedDataSize
2452 )
2453 {
2454 CALL_CRYPTO_SERVICE (Pkcs7Sign, (PrivateKey, PrivateKeySize, KeyPassword, InData, InDataSize, SignCert, OtherCerts, SignedData, SignedDataSize), FALSE);
2455 }
2456
2457 /**
2458 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2459 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2460 in a ContentInfo structure.
2461
2462 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2463 If P7Length, CertLength or DataLength overflow, then return FALSE.
2464 If this interface is not supported, then return FALSE.
2465
2466 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2467 @param[in] P7Length Length of the PKCS#7 message in bytes.
2468 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2469 is used for certificate chain verification.
2470 @param[in] CertLength Length of the trusted certificate in bytes.
2471 @param[in] InData Pointer to the content to be verified.
2472 @param[in] DataLength Length of InData in bytes.
2473
2474 @retval TRUE The specified PKCS#7 signed data is valid.
2475 @retval FALSE Invalid PKCS#7 signed data.
2476 @retval FALSE This interface is not supported.
2477
2478 **/
2479 BOOLEAN
2480 EFIAPI
2481 Pkcs7Verify (
2482 IN CONST UINT8 *P7Data,
2483 IN UINTN P7Length,
2484 IN CONST UINT8 *TrustedCert,
2485 IN UINTN CertLength,
2486 IN CONST UINT8 *InData,
2487 IN UINTN DataLength
2488 )
2489 {
2490 CALL_CRYPTO_SERVICE (Pkcs7Verify, (P7Data, P7Length, TrustedCert, CertLength, InData, DataLength), FALSE);
2491 }
2492
2493 /**
2494 This function receives a PKCS7 formatted signature, and then verifies that
2495 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
2496 leaf signing certificate.
2497 Note that this function does not validate the certificate chain.
2498
2499 Applications for custom EKU's are quite flexible. For example, a policy EKU
2500 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
2501 certificate issued might also contain this EKU, thus constraining the
2502 sub-ordinate certificate. Other applications might allow a certificate
2503 embedded in a device to specify that other Object Identifiers (OIDs) are
2504 present which contains binary data specifying custom capabilities that
2505 the device is able to do.
2506
2507 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
2508 containing the content block with both the signature,
2509 the signer's certificate, and any necessary intermediate
2510 certificates.
2511 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
2512 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
2513 required EKUs that must be present in the signature.
2514 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
2515 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
2516 must be present in the leaf signer. If it is
2517 FALSE, then we will succeed if we find any
2518 of the specified EKU's.
2519
2520 @retval EFI_SUCCESS The required EKUs were found in the signature.
2521 @retval EFI_INVALID_PARAMETER A parameter was invalid.
2522 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
2523
2524 **/
2525 RETURN_STATUS
2526 EFIAPI
2527 VerifyEKUsInPkcs7Signature (
2528 IN CONST UINT8 *Pkcs7Signature,
2529 IN CONST UINT32 SignatureSize,
2530 IN CONST CHAR8 *RequiredEKUs[],
2531 IN CONST UINT32 RequiredEKUsSize,
2532 IN BOOLEAN RequireAllPresent
2533 )
2534 {
2535 CALL_CRYPTO_SERVICE (VerifyEKUsInPkcs7Signature, (Pkcs7Signature, SignatureSize, RequiredEKUs, RequiredEKUsSize, RequireAllPresent), FALSE);
2536 }
2537
2538 /**
2539 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2540 data could be wrapped in a ContentInfo structure.
2541
2542 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2543 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2544
2545 Caution: This function may receive untrusted input. So this function will do
2546 basic check for PKCS#7 data structure.
2547
2548 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2549 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2550 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2551 It's caller's responsibility to free the buffer with FreePool().
2552 @param[out] ContentSize The size of the extracted content in bytes.
2553
2554 @retval TRUE The P7Data was correctly formatted for processing.
2555 @retval FALSE The P7Data was not correctly formatted for processing.
2556
2557 **/
2558 BOOLEAN
2559 EFIAPI
2560 Pkcs7GetAttachedContent (
2561 IN CONST UINT8 *P7Data,
2562 IN UINTN P7Length,
2563 OUT VOID **Content,
2564 OUT UINTN *ContentSize
2565 )
2566 {
2567 CALL_CRYPTO_SERVICE (Pkcs7GetAttachedContent, (P7Data, P7Length, Content, ContentSize), FALSE);
2568 }
2569
2570 /**
2571 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2572 Authenticode Portable Executable Signature Format".
2573
2574 If AuthData is NULL, then return FALSE.
2575 If ImageHash is NULL, then return FALSE.
2576 If this interface is not supported, then return FALSE.
2577
2578 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2579 PE/COFF image to be verified.
2580 @param[in] DataSize Size of the Authenticode Signature in bytes.
2581 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2582 is used for certificate chain verification.
2583 @param[in] CertSize Size of the trusted certificate in bytes.
2584 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2585 for calculating the image hash value is described in Authenticode
2586 specification.
2587 @param[in] HashSize Size of Image hash value in bytes.
2588
2589 @retval TRUE The specified Authenticode Signature is valid.
2590 @retval FALSE Invalid Authenticode Signature.
2591 @retval FALSE This interface is not supported.
2592
2593 **/
2594 BOOLEAN
2595 EFIAPI
2596 AuthenticodeVerify (
2597 IN CONST UINT8 *AuthData,
2598 IN UINTN DataSize,
2599 IN CONST UINT8 *TrustedCert,
2600 IN UINTN CertSize,
2601 IN CONST UINT8 *ImageHash,
2602 IN UINTN HashSize
2603 )
2604 {
2605 CALL_CRYPTO_SERVICE (AuthenticodeVerify, (AuthData, DataSize, TrustedCert, CertSize, ImageHash, HashSize), FALSE);
2606 }
2607
2608 /**
2609 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2610 signature.
2611
2612 If AuthData is NULL, then return FALSE.
2613 If this interface is not supported, then return FALSE.
2614
2615 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2616 PE/COFF image to be verified.
2617 @param[in] DataSize Size of the Authenticode Signature in bytes.
2618 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2619 is used for TSA certificate chain verification.
2620 @param[in] CertSize Size of the trusted certificate in bytes.
2621 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2622 signature is valid.
2623
2624 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2625 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2626
2627 **/
2628 BOOLEAN
2629 EFIAPI
2630 ImageTimestampVerify (
2631 IN CONST UINT8 *AuthData,
2632 IN UINTN DataSize,
2633 IN CONST UINT8 *TsaCert,
2634 IN UINTN CertSize,
2635 OUT EFI_TIME *SigningTime
2636 )
2637 {
2638 CALL_CRYPTO_SERVICE (ImageTimestampVerify, (AuthData, DataSize, TsaCert, CertSize, SigningTime), FALSE);
2639 }
2640
2641 // =====================================================================================
2642 // DH Key Exchange Primitive
2643 // =====================================================================================
2644
2645 /**
2646 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
2647
2648 @return Pointer to the Diffie-Hellman Context that has been initialized.
2649 If the allocations fails, DhNew() returns NULL.
2650 If the interface is not supported, DhNew() returns NULL.
2651
2652 **/
2653 VOID *
2654 EFIAPI
2655 DhNew (
2656 VOID
2657 )
2658 {
2659 CALL_CRYPTO_SERVICE (DhNew, (), NULL);
2660 }
2661
2662 /**
2663 Release the specified DH context.
2664
2665 If the interface is not supported, then ASSERT().
2666
2667 @param[in] DhContext Pointer to the DH context to be released.
2668
2669 **/
2670 VOID
2671 EFIAPI
2672 DhFree (
2673 IN VOID *DhContext
2674 )
2675 {
2676 CALL_VOID_CRYPTO_SERVICE (DhFree, (DhContext));
2677 }
2678
2679 /**
2680 Generates DH parameter.
2681
2682 Given generator g, and length of prime number p in bits, this function generates p,
2683 and sets DH context according to value of g and p.
2684
2685 Before this function can be invoked, pseudorandom number generator must be correctly
2686 initialized by RandomSeed().
2687
2688 If DhContext is NULL, then return FALSE.
2689 If Prime is NULL, then return FALSE.
2690 If this interface is not supported, then return FALSE.
2691
2692 @param[in, out] DhContext Pointer to the DH context.
2693 @param[in] Generator Value of generator.
2694 @param[in] PrimeLength Length in bits of prime to be generated.
2695 @param[out] Prime Pointer to the buffer to receive the generated prime number.
2696
2697 @retval TRUE DH parameter generation succeeded.
2698 @retval FALSE Value of Generator is not supported.
2699 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
2700 @retval FALSE This interface is not supported.
2701
2702 **/
2703 BOOLEAN
2704 EFIAPI
2705 DhGenerateParameter (
2706 IN OUT VOID *DhContext,
2707 IN UINTN Generator,
2708 IN UINTN PrimeLength,
2709 OUT UINT8 *Prime
2710 )
2711 {
2712 CALL_CRYPTO_SERVICE (DhGenerateParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);
2713 }
2714
2715 /**
2716 Sets generator and prime parameters for DH.
2717
2718 Given generator g, and prime number p, this function and sets DH
2719 context accordingly.
2720
2721 If DhContext is NULL, then return FALSE.
2722 If Prime is NULL, then return FALSE.
2723 If this interface is not supported, then return FALSE.
2724
2725 @param[in, out] DhContext Pointer to the DH context.
2726 @param[in] Generator Value of generator.
2727 @param[in] PrimeLength Length in bits of prime to be generated.
2728 @param[in] Prime Pointer to the prime number.
2729
2730 @retval TRUE DH parameter setting succeeded.
2731 @retval FALSE Value of Generator is not supported.
2732 @retval FALSE Value of Generator is not suitable for the Prime.
2733 @retval FALSE Value of Prime is not a prime number.
2734 @retval FALSE Value of Prime is not a safe prime number.
2735 @retval FALSE This interface is not supported.
2736
2737 **/
2738 BOOLEAN
2739 EFIAPI
2740 DhSetParameter (
2741 IN OUT VOID *DhContext,
2742 IN UINTN Generator,
2743 IN UINTN PrimeLength,
2744 IN CONST UINT8 *Prime
2745 )
2746 {
2747 CALL_CRYPTO_SERVICE (DhSetParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);
2748 }
2749
2750 /**
2751 Generates DH public key.
2752
2753 This function generates random secret exponent, and computes the public key, which is
2754 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
2755 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
2756 PublicKeySize is set to the required buffer size to obtain the public key.
2757
2758 If DhContext is NULL, then return FALSE.
2759 If PublicKeySize is NULL, then return FALSE.
2760 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
2761 If this interface is not supported, then return FALSE.
2762
2763 @param[in, out] DhContext Pointer to the DH context.
2764 @param[out] PublicKey Pointer to the buffer to receive generated public key.
2765 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
2766 On output, the size of data returned in PublicKey buffer in bytes.
2767
2768 @retval TRUE DH public key generation succeeded.
2769 @retval FALSE DH public key generation failed.
2770 @retval FALSE PublicKeySize is not large enough.
2771 @retval FALSE This interface is not supported.
2772
2773 **/
2774 BOOLEAN
2775 EFIAPI
2776 DhGenerateKey (
2777 IN OUT VOID *DhContext,
2778 OUT UINT8 *PublicKey,
2779 IN OUT UINTN *PublicKeySize
2780 )
2781 {
2782 CALL_CRYPTO_SERVICE (DhGenerateKey, (DhContext, PublicKey, PublicKeySize), FALSE);
2783 }
2784
2785 /**
2786 Computes exchanged common key.
2787
2788 Given peer's public key, this function computes the exchanged common key, based on its own
2789 context including value of prime modulus and random secret exponent.
2790
2791 If DhContext is NULL, then return FALSE.
2792 If PeerPublicKey is NULL, then return FALSE.
2793 If KeySize is NULL, then return FALSE.
2794 If Key is NULL, then return FALSE.
2795 If KeySize is not large enough, then return FALSE.
2796 If this interface is not supported, then return FALSE.
2797
2798 @param[in, out] DhContext Pointer to the DH context.
2799 @param[in] PeerPublicKey Pointer to the peer's public key.
2800 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
2801 @param[out] Key Pointer to the buffer to receive generated key.
2802 @param[in, out] KeySize On input, the size of Key buffer in bytes.
2803 On output, the size of data returned in Key buffer in bytes.
2804
2805 @retval TRUE DH exchanged key generation succeeded.
2806 @retval FALSE DH exchanged key generation failed.
2807 @retval FALSE KeySize is not large enough.
2808 @retval FALSE This interface is not supported.
2809
2810 **/
2811 BOOLEAN
2812 EFIAPI
2813 DhComputeKey (
2814 IN OUT VOID *DhContext,
2815 IN CONST UINT8 *PeerPublicKey,
2816 IN UINTN PeerPublicKeySize,
2817 OUT UINT8 *Key,
2818 IN OUT UINTN *KeySize
2819 )
2820 {
2821 CALL_CRYPTO_SERVICE (DhComputeKey, (DhContext, PeerPublicKey, PeerPublicKeySize, Key, KeySize), FALSE);
2822 }
2823
2824 // =====================================================================================
2825 // Pseudo-Random Generation Primitive
2826 // =====================================================================================
2827
2828 /**
2829 Sets up the seed value for the pseudorandom number generator.
2830
2831 This function sets up the seed value for the pseudorandom number generator.
2832 If Seed is not NULL, then the seed passed in is used.
2833 If Seed is NULL, then default seed is used.
2834 If this interface is not supported, then return FALSE.
2835
2836 @param[in] Seed Pointer to seed value.
2837 If NULL, default seed is used.
2838 @param[in] SeedSize Size of seed value.
2839 If Seed is NULL, this parameter is ignored.
2840
2841 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
2842 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
2843 @retval FALSE This interface is not supported.
2844
2845 **/
2846 BOOLEAN
2847 EFIAPI
2848 RandomSeed (
2849 IN CONST UINT8 *Seed OPTIONAL,
2850 IN UINTN SeedSize
2851 )
2852 {
2853 CALL_CRYPTO_SERVICE (RandomSeed, (Seed, SeedSize), FALSE);
2854 }
2855
2856 /**
2857 Generates a pseudorandom byte stream of the specified size.
2858
2859 If Output is NULL, then return FALSE.
2860 If this interface is not supported, then return FALSE.
2861
2862 @param[out] Output Pointer to buffer to receive random value.
2863 @param[in] Size Size of random bytes to generate.
2864
2865 @retval TRUE Pseudorandom byte stream generated successfully.
2866 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
2867 @retval FALSE This interface is not supported.
2868
2869 **/
2870 BOOLEAN
2871 EFIAPI
2872 RandomBytes (
2873 OUT UINT8 *Output,
2874 IN UINTN Size
2875 )
2876 {
2877 CALL_CRYPTO_SERVICE (RandomBytes, (Output, Size), FALSE);
2878 }
2879
2880 // =====================================================================================
2881 // Key Derivation Function Primitive
2882 // =====================================================================================
2883
2884 /**
2885 Derive key data using HMAC-SHA256 based KDF.
2886
2887 @param[in] Key Pointer to the user-supplied key.
2888 @param[in] KeySize Key size in bytes.
2889 @param[in] Salt Pointer to the salt(non-secret) value.
2890 @param[in] SaltSize Salt size in bytes.
2891 @param[in] Info Pointer to the application specific info.
2892 @param[in] InfoSize Info size in bytes.
2893 @param[out] Out Pointer to buffer to receive hkdf value.
2894 @param[in] OutSize Size of hkdf bytes to generate.
2895
2896 @retval TRUE Hkdf generated successfully.
2897 @retval FALSE Hkdf generation failed.
2898
2899 **/
2900 BOOLEAN
2901 EFIAPI
2902 HkdfSha256ExtractAndExpand (
2903 IN CONST UINT8 *Key,
2904 IN UINTN KeySize,
2905 IN CONST UINT8 *Salt,
2906 IN UINTN SaltSize,
2907 IN CONST UINT8 *Info,
2908 IN UINTN InfoSize,
2909 OUT UINT8 *Out,
2910 IN UINTN OutSize
2911 )
2912 {
2913 CALL_CRYPTO_SERVICE (HkdfSha256ExtractAndExpand, (Key, KeySize, Salt, SaltSize, Info, InfoSize, Out, OutSize), FALSE);
2914 }
2915
2916 /**
2917 Initializes the OpenSSL library.
2918
2919 This function registers ciphers and digests used directly and indirectly
2920 by SSL/TLS, and initializes the readable error messages.
2921 This function must be called before any other action takes places.
2922
2923 @retval TRUE The OpenSSL library has been initialized.
2924 @retval FALSE Failed to initialize the OpenSSL library.
2925
2926 **/
2927 BOOLEAN
2928 EFIAPI
2929 TlsInitialize (
2930 VOID
2931 )
2932 {
2933 CALL_CRYPTO_SERVICE (TlsInitialize, (), FALSE);
2934 }
2935
2936 /**
2937 Free an allocated SSL_CTX object.
2938
2939 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
2940
2941 **/
2942 VOID
2943 EFIAPI
2944 TlsCtxFree (
2945 IN VOID *TlsCtx
2946 )
2947 {
2948 CALL_VOID_CRYPTO_SERVICE (TlsCtxFree, (TlsCtx));
2949 }
2950
2951 /**
2952 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
2953 connections.
2954
2955 @param[in] MajorVer Major Version of TLS/SSL Protocol.
2956 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
2957
2958 @return Pointer to an allocated SSL_CTX object.
2959 If the creation failed, TlsCtxNew() returns NULL.
2960
2961 **/
2962 VOID *
2963 EFIAPI
2964 TlsCtxNew (
2965 IN UINT8 MajorVer,
2966 IN UINT8 MinorVer
2967 )
2968 {
2969 CALL_CRYPTO_SERVICE (TlsCtxNew, (MajorVer, MinorVer), NULL);
2970 }
2971
2972 /**
2973 Free an allocated TLS object.
2974
2975 This function removes the TLS object pointed to by Tls and frees up the
2976 allocated memory. If Tls is NULL, nothing is done.
2977
2978 @param[in] Tls Pointer to the TLS object to be freed.
2979
2980 **/
2981 VOID
2982 EFIAPI
2983 TlsFree (
2984 IN VOID *Tls
2985 )
2986 {
2987 CALL_VOID_CRYPTO_SERVICE (TlsFree, (Tls));
2988 }
2989
2990 /**
2991 Create a new TLS object for a connection.
2992
2993 This function creates a new TLS object for a connection. The new object
2994 inherits the setting of the underlying context TlsCtx: connection method,
2995 options, verification setting.
2996
2997 @param[in] TlsCtx Pointer to the SSL_CTX object.
2998
2999 @return Pointer to an allocated SSL object.
3000 If the creation failed, TlsNew() returns NULL.
3001
3002 **/
3003 VOID *
3004 EFIAPI
3005 TlsNew (
3006 IN VOID *TlsCtx
3007 )
3008 {
3009 CALL_CRYPTO_SERVICE (TlsNew, (TlsCtx), NULL);
3010 }
3011
3012 /**
3013 Checks if the TLS handshake was done.
3014
3015 This function will check if the specified TLS handshake was done.
3016
3017 @param[in] Tls Pointer to the TLS object for handshake state checking.
3018
3019 @retval TRUE The TLS handshake was done.
3020 @retval FALSE The TLS handshake was not done.
3021
3022 **/
3023 BOOLEAN
3024 EFIAPI
3025 TlsInHandshake (
3026 IN VOID *Tls
3027 )
3028 {
3029 CALL_CRYPTO_SERVICE (TlsInHandshake, (Tls), FALSE);
3030 }
3031
3032 /**
3033 Perform a TLS/SSL handshake.
3034
3035 This function will perform a TLS/SSL handshake.
3036
3037 @param[in] Tls Pointer to the TLS object for handshake operation.
3038 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
3039 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3040 Handshake packet.
3041 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3042 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3043 the buffer size provided by the caller. On output, it
3044 is the buffer size in fact needed to contain the
3045 packet.
3046
3047 @retval EFI_SUCCESS The required TLS packet is built successfully.
3048 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3049 Tls is NULL.
3050 BufferIn is NULL but BufferInSize is NOT 0.
3051 BufferInSize is 0 but BufferIn is NOT NULL.
3052 BufferOutSize is NULL.
3053 BufferOut is NULL if *BufferOutSize is not zero.
3054 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3055 @retval EFI_ABORTED Something wrong during handshake.
3056
3057 **/
3058 EFI_STATUS
3059 EFIAPI
3060 TlsDoHandshake (
3061 IN VOID *Tls,
3062 IN UINT8 *BufferIn OPTIONAL,
3063 IN UINTN BufferInSize OPTIONAL,
3064 OUT UINT8 *BufferOut OPTIONAL,
3065 IN OUT UINTN *BufferOutSize
3066 )
3067 {
3068 CALL_CRYPTO_SERVICE (TlsDoHandshake, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);
3069 }
3070
3071 /**
3072 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
3073 TLS session has errors and the response packet needs to be Alert message based on error type.
3074
3075 @param[in] Tls Pointer to the TLS object for state checking.
3076 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
3077 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3078 Alert packet.
3079 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3080 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3081 the buffer size provided by the caller. On output, it
3082 is the buffer size in fact needed to contain the
3083 packet.
3084
3085 @retval EFI_SUCCESS The required TLS packet is built successfully.
3086 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3087 Tls is NULL.
3088 BufferIn is NULL but BufferInSize is NOT 0.
3089 BufferInSize is 0 but BufferIn is NOT NULL.
3090 BufferOutSize is NULL.
3091 BufferOut is NULL if *BufferOutSize is not zero.
3092 @retval EFI_ABORTED An error occurred.
3093 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3094
3095 **/
3096 EFI_STATUS
3097 EFIAPI
3098 TlsHandleAlert (
3099 IN VOID *Tls,
3100 IN UINT8 *BufferIn OPTIONAL,
3101 IN UINTN BufferInSize OPTIONAL,
3102 OUT UINT8 *BufferOut OPTIONAL,
3103 IN OUT UINTN *BufferOutSize
3104 )
3105 {
3106 CALL_CRYPTO_SERVICE (TlsHandleAlert, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);
3107 }
3108
3109 /**
3110 Build the CloseNotify packet.
3111
3112 @param[in] Tls Pointer to the TLS object for state checking.
3113 @param[in, out] Buffer Pointer to the buffer to hold the built packet.
3114 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
3115 the buffer size provided by the caller. On output, it
3116 is the buffer size in fact needed to contain the
3117 packet.
3118
3119 @retval EFI_SUCCESS The required TLS packet is built successfully.
3120 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3121 Tls is NULL.
3122 BufferSize is NULL.
3123 Buffer is NULL if *BufferSize is not zero.
3124 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
3125
3126 **/
3127 EFI_STATUS
3128 EFIAPI
3129 TlsCloseNotify (
3130 IN VOID *Tls,
3131 IN OUT UINT8 *Buffer,
3132 IN OUT UINTN *BufferSize
3133 )
3134 {
3135 CALL_CRYPTO_SERVICE (TlsCloseNotify, (Tls, Buffer, BufferSize), EFI_UNSUPPORTED);
3136 }
3137
3138 /**
3139 Attempts to read bytes from one TLS object and places the data in Buffer.
3140
3141 This function will attempt to read BufferSize bytes from the TLS object
3142 and places the data in Buffer.
3143
3144 @param[in] Tls Pointer to the TLS object.
3145 @param[in,out] Buffer Pointer to the buffer to store the data.
3146 @param[in] BufferSize The size of Buffer in bytes.
3147
3148 @retval >0 The amount of data successfully read from the TLS object.
3149 @retval <=0 No data was successfully read.
3150
3151 **/
3152 INTN
3153 EFIAPI
3154 TlsCtrlTrafficOut (
3155 IN VOID *Tls,
3156 IN OUT VOID *Buffer,
3157 IN UINTN BufferSize
3158 )
3159 {
3160 CALL_CRYPTO_SERVICE (TlsCtrlTrafficOut, (Tls, Buffer, BufferSize), 0);
3161 }
3162
3163 /**
3164 Attempts to write data from the buffer to TLS object.
3165
3166 This function will attempt to write BufferSize bytes data from the Buffer
3167 to the TLS object.
3168
3169 @param[in] Tls Pointer to the TLS object.
3170 @param[in] Buffer Pointer to the data buffer.
3171 @param[in] BufferSize The size of Buffer in bytes.
3172
3173 @retval >0 The amount of data successfully written to the TLS object.
3174 @retval <=0 No data was successfully written.
3175
3176 **/
3177 INTN
3178 EFIAPI
3179 TlsCtrlTrafficIn (
3180 IN VOID *Tls,
3181 IN VOID *Buffer,
3182 IN UINTN BufferSize
3183 )
3184 {
3185 CALL_CRYPTO_SERVICE (TlsCtrlTrafficIn, (Tls, Buffer, BufferSize), 0);
3186 }
3187
3188 /**
3189 Attempts to read bytes from the specified TLS connection into the buffer.
3190
3191 This function tries to read BufferSize bytes data from the specified TLS
3192 connection into the Buffer.
3193
3194 @param[in] Tls Pointer to the TLS connection for data reading.
3195 @param[in,out] Buffer Pointer to the data buffer.
3196 @param[in] BufferSize The size of Buffer in bytes.
3197
3198 @retval >0 The read operation was successful, and return value is the
3199 number of bytes actually read from the TLS connection.
3200 @retval <=0 The read operation was not successful.
3201
3202 **/
3203 INTN
3204 EFIAPI
3205 TlsRead (
3206 IN VOID *Tls,
3207 IN OUT VOID *Buffer,
3208 IN UINTN BufferSize
3209 )
3210 {
3211 CALL_CRYPTO_SERVICE (TlsRead, (Tls, Buffer, BufferSize), 0);
3212 }
3213
3214 /**
3215 Attempts to write data to a TLS connection.
3216
3217 This function tries to write BufferSize bytes data from the Buffer into the
3218 specified TLS connection.
3219
3220 @param[in] Tls Pointer to the TLS connection for data writing.
3221 @param[in] Buffer Pointer to the data buffer.
3222 @param[in] BufferSize The size of Buffer in bytes.
3223
3224 @retval >0 The write operation was successful, and return value is the
3225 number of bytes actually written to the TLS connection.
3226 @retval <=0 The write operation was not successful.
3227
3228 **/
3229 INTN
3230 EFIAPI
3231 TlsWrite (
3232 IN VOID *Tls,
3233 IN VOID *Buffer,
3234 IN UINTN BufferSize
3235 )
3236 {
3237 CALL_CRYPTO_SERVICE (TlsWrite, (Tls, Buffer, BufferSize), 0);
3238 }
3239
3240 /**
3241 Set a new TLS/SSL method for a particular TLS object.
3242
3243 This function sets a new TLS/SSL method for a particular TLS object.
3244
3245 @param[in] Tls Pointer to a TLS object.
3246 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3247 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3248
3249 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
3250 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3251 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
3252
3253 **/
3254 EFI_STATUS
3255 EFIAPI
3256 TlsSetVersion (
3257 IN VOID *Tls,
3258 IN UINT8 MajorVer,
3259 IN UINT8 MinorVer
3260 )
3261 {
3262 CALL_CRYPTO_SERVICE (TlsSetVersion, (Tls, MajorVer, MinorVer), EFI_UNSUPPORTED);
3263 }
3264
3265 /**
3266 Set TLS object to work in client or server mode.
3267
3268 This function prepares a TLS object to work in client or server mode.
3269
3270 @param[in] Tls Pointer to a TLS object.
3271 @param[in] IsServer Work in server mode.
3272
3273 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
3274 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3275 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
3276
3277 **/
3278 EFI_STATUS
3279 EFIAPI
3280 TlsSetConnectionEnd (
3281 IN VOID *Tls,
3282 IN BOOLEAN IsServer
3283 )
3284 {
3285 CALL_CRYPTO_SERVICE (TlsSetConnectionEnd, (Tls, IsServer), EFI_UNSUPPORTED);
3286 }
3287
3288 /**
3289 Set the ciphers list to be used by the TLS object.
3290
3291 This function sets the ciphers for use by a specified TLS object.
3292
3293 @param[in] Tls Pointer to a TLS object.
3294 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
3295 cipher identifier comes from the TLS Cipher Suite
3296 Registry of the IANA, interpreting Byte1 and Byte2
3297 in network (big endian) byte order.
3298 @param[in] CipherNum The number of cipher in the list.
3299
3300 @retval EFI_SUCCESS The ciphers list was set successfully.
3301 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3302 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
3303 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
3304
3305 **/
3306 EFI_STATUS
3307 EFIAPI
3308 TlsSetCipherList (
3309 IN VOID *Tls,
3310 IN UINT16 *CipherId,
3311 IN UINTN CipherNum
3312 )
3313 {
3314 CALL_CRYPTO_SERVICE (TlsSetCipherList, (Tls, CipherId, CipherNum), EFI_UNSUPPORTED);
3315 }
3316
3317 /**
3318 Set the compression method for TLS/SSL operations.
3319
3320 This function handles TLS/SSL integrated compression methods.
3321
3322 @param[in] CompMethod The compression method ID.
3323
3324 @retval EFI_SUCCESS The compression method for the communication was
3325 set successfully.
3326 @retval EFI_UNSUPPORTED Unsupported compression method.
3327
3328 **/
3329 EFI_STATUS
3330 EFIAPI
3331 TlsSetCompressionMethod (
3332 IN UINT8 CompMethod
3333 )
3334 {
3335 CALL_CRYPTO_SERVICE (TlsSetCompressionMethod, (CompMethod), EFI_UNSUPPORTED);
3336 }
3337
3338 /**
3339 Set peer certificate verification mode for the TLS connection.
3340
3341 This function sets the verification mode flags for the TLS connection.
3342
3343 @param[in] Tls Pointer to the TLS object.
3344 @param[in] VerifyMode A set of logically or'ed verification mode flags.
3345
3346 **/
3347 VOID
3348 EFIAPI
3349 TlsSetVerify (
3350 IN VOID *Tls,
3351 IN UINT32 VerifyMode
3352 )
3353 {
3354 CALL_VOID_CRYPTO_SERVICE (TlsSetVerify, (Tls, VerifyMode));
3355 }
3356
3357 /**
3358 Set the specified host name to be verified.
3359
3360 @param[in] Tls Pointer to the TLS object.
3361 @param[in] Flags The setting flags during the validation.
3362 @param[in] HostName The specified host name to be verified.
3363
3364 @retval EFI_SUCCESS The HostName setting was set successfully.
3365 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3366 @retval EFI_ABORTED Invalid HostName setting.
3367
3368 **/
3369 EFI_STATUS
3370 EFIAPI
3371 TlsSetVerifyHost (
3372 IN VOID *Tls,
3373 IN UINT32 Flags,
3374 IN CHAR8 *HostName
3375 )
3376 {
3377 CALL_CRYPTO_SERVICE (TlsSetVerifyHost, (Tls, Flags, HostName), EFI_UNSUPPORTED);
3378 }
3379
3380 /**
3381 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
3382
3383 This function sets a session ID to be used when the TLS/SSL connection is
3384 to be established.
3385
3386 @param[in] Tls Pointer to the TLS object.
3387 @param[in] SessionId Session ID data used for session resumption.
3388 @param[in] SessionIdLen Length of Session ID in bytes.
3389
3390 @retval EFI_SUCCESS Session ID was set successfully.
3391 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3392 @retval EFI_UNSUPPORTED No available session for ID setting.
3393
3394 **/
3395 EFI_STATUS
3396 EFIAPI
3397 TlsSetSessionId (
3398 IN VOID *Tls,
3399 IN UINT8 *SessionId,
3400 IN UINT16 SessionIdLen
3401 )
3402 {
3403 CALL_CRYPTO_SERVICE (TlsSetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);
3404 }
3405
3406 /**
3407 Adds the CA to the cert store when requesting Server or Client authentication.
3408
3409 This function adds the CA certificate to the list of CAs when requesting
3410 Server or Client authentication for the chosen TLS connection.
3411
3412 @param[in] Tls Pointer to the TLS object.
3413 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3414 X.509 certificate or PEM-encoded X.509 certificate.
3415 @param[in] DataSize The size of data buffer in bytes.
3416
3417 @retval EFI_SUCCESS The operation succeeded.
3418 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3419 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3420 @retval EFI_ABORTED Invalid X.509 certificate.
3421
3422 **/
3423 EFI_STATUS
3424 EFIAPI
3425 TlsSetCaCertificate (
3426 IN VOID *Tls,
3427 IN VOID *Data,
3428 IN UINTN DataSize
3429 )
3430 {
3431 CALL_CRYPTO_SERVICE (TlsSetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);
3432 }
3433
3434 /**
3435 Loads the local public certificate into the specified TLS object.
3436
3437 This function loads the X.509 certificate into the specified TLS object
3438 for TLS negotiation.
3439
3440 @param[in] Tls Pointer to the TLS object.
3441 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3442 X.509 certificate or PEM-encoded X.509 certificate.
3443 @param[in] DataSize The size of data buffer in bytes.
3444
3445 @retval EFI_SUCCESS The operation succeeded.
3446 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3447 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3448 @retval EFI_ABORTED Invalid X.509 certificate.
3449
3450 **/
3451 EFI_STATUS
3452 EFIAPI
3453 TlsSetHostPublicCert (
3454 IN VOID *Tls,
3455 IN VOID *Data,
3456 IN UINTN DataSize
3457 )
3458 {
3459 CALL_CRYPTO_SERVICE (TlsSetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);
3460 }
3461
3462 /**
3463 Adds the local private key to the specified TLS object.
3464
3465 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
3466 key) into the specified TLS object for TLS negotiation.
3467
3468 @param[in] Tls Pointer to the TLS object.
3469 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
3470 or PKCS#8 private key.
3471 @param[in] DataSize The size of data buffer in bytes.
3472
3473 @retval EFI_SUCCESS The operation succeeded.
3474 @retval EFI_UNSUPPORTED This function is not supported.
3475 @retval EFI_ABORTED Invalid private key data.
3476
3477 **/
3478 EFI_STATUS
3479 EFIAPI
3480 TlsSetHostPrivateKey (
3481 IN VOID *Tls,
3482 IN VOID *Data,
3483 IN UINTN DataSize
3484 )
3485 {
3486 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);
3487 }
3488
3489 /**
3490 Adds the CA-supplied certificate revocation list for certificate validation.
3491
3492 This function adds the CA-supplied certificate revocation list data for
3493 certificate validity checking.
3494
3495 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
3496 @param[in] DataSize The size of data buffer in bytes.
3497
3498 @retval EFI_SUCCESS The operation succeeded.
3499 @retval EFI_UNSUPPORTED This function is not supported.
3500 @retval EFI_ABORTED Invalid CRL data.
3501
3502 **/
3503 EFI_STATUS
3504 EFIAPI
3505 TlsSetCertRevocationList (
3506 IN VOID *Data,
3507 IN UINTN DataSize
3508 )
3509 {
3510 CALL_CRYPTO_SERVICE (TlsSetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);
3511 }
3512
3513 /**
3514 Gets the protocol version used by the specified TLS connection.
3515
3516 This function returns the protocol version used by the specified TLS
3517 connection.
3518
3519 If Tls is NULL, then ASSERT().
3520
3521 @param[in] Tls Pointer to the TLS object.
3522
3523 @return The protocol version of the specified TLS connection.
3524
3525 **/
3526 UINT16
3527 EFIAPI
3528 TlsGetVersion (
3529 IN VOID *Tls
3530 )
3531 {
3532 CALL_CRYPTO_SERVICE (TlsGetVersion, (Tls), 0);
3533 }
3534
3535 /**
3536 Gets the connection end of the specified TLS connection.
3537
3538 This function returns the connection end (as client or as server) used by
3539 the specified TLS connection.
3540
3541 If Tls is NULL, then ASSERT().
3542
3543 @param[in] Tls Pointer to the TLS object.
3544
3545 @return The connection end used by the specified TLS connection.
3546
3547 **/
3548 UINT8
3549 EFIAPI
3550 TlsGetConnectionEnd (
3551 IN VOID *Tls
3552 )
3553 {
3554 CALL_CRYPTO_SERVICE (TlsGetConnectionEnd, (Tls), 0);
3555 }
3556
3557 /**
3558 Gets the cipher suite used by the specified TLS connection.
3559
3560 This function returns current cipher suite used by the specified
3561 TLS connection.
3562
3563 @param[in] Tls Pointer to the TLS object.
3564 @param[in,out] CipherId The cipher suite used by the TLS object.
3565
3566 @retval EFI_SUCCESS The cipher suite was returned successfully.
3567 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3568 @retval EFI_UNSUPPORTED Unsupported cipher suite.
3569
3570 **/
3571 EFI_STATUS
3572 EFIAPI
3573 TlsGetCurrentCipher (
3574 IN VOID *Tls,
3575 IN OUT UINT16 *CipherId
3576 )
3577 {
3578 CALL_CRYPTO_SERVICE (TlsGetCurrentCipher, (Tls, CipherId), EFI_UNSUPPORTED);
3579 }
3580
3581 /**
3582 Gets the compression methods used by the specified TLS connection.
3583
3584 This function returns current integrated compression methods used by
3585 the specified TLS connection.
3586
3587 @param[in] Tls Pointer to the TLS object.
3588 @param[in,out] CompressionId The current compression method used by
3589 the TLS object.
3590
3591 @retval EFI_SUCCESS The compression method was returned successfully.
3592 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3593 @retval EFI_ABORTED Invalid Compression method.
3594 @retval EFI_UNSUPPORTED This function is not supported.
3595
3596 **/
3597 EFI_STATUS
3598 EFIAPI
3599 TlsGetCurrentCompressionId (
3600 IN VOID *Tls,
3601 IN OUT UINT8 *CompressionId
3602 )
3603 {
3604 CALL_CRYPTO_SERVICE (TlsGetCurrentCompressionId, (Tls, CompressionId), EFI_UNSUPPORTED);
3605 }
3606
3607 /**
3608 Gets the verification mode currently set in the TLS connection.
3609
3610 This function returns the peer verification mode currently set in the
3611 specified TLS connection.
3612
3613 If Tls is NULL, then ASSERT().
3614
3615 @param[in] Tls Pointer to the TLS object.
3616
3617 @return The verification mode set in the specified TLS connection.
3618
3619 **/
3620 UINT32
3621 EFIAPI
3622 TlsGetVerify (
3623 IN VOID *Tls
3624 )
3625 {
3626 CALL_CRYPTO_SERVICE (TlsGetVerify, (Tls), 0);
3627 }
3628
3629 /**
3630 Gets the session ID used by the specified TLS connection.
3631
3632 This function returns the TLS/SSL session ID currently used by the
3633 specified TLS connection.
3634
3635 @param[in] Tls Pointer to the TLS object.
3636 @param[in,out] SessionId Buffer to contain the returned session ID.
3637 @param[in,out] SessionIdLen The length of Session ID in bytes.
3638
3639 @retval EFI_SUCCESS The Session ID was returned successfully.
3640 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3641 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
3642
3643 **/
3644 EFI_STATUS
3645 EFIAPI
3646 TlsGetSessionId (
3647 IN VOID *Tls,
3648 IN OUT UINT8 *SessionId,
3649 IN OUT UINT16 *SessionIdLen
3650 )
3651 {
3652 CALL_CRYPTO_SERVICE (TlsGetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);
3653 }
3654
3655 /**
3656 Gets the client random data used in the specified TLS connection.
3657
3658 This function returns the TLS/SSL client random data currently used in
3659 the specified TLS connection.
3660
3661 @param[in] Tls Pointer to the TLS object.
3662 @param[in,out] ClientRandom Buffer to contain the returned client
3663 random data (32 bytes).
3664
3665 **/
3666 VOID
3667 EFIAPI
3668 TlsGetClientRandom (
3669 IN VOID *Tls,
3670 IN OUT UINT8 *ClientRandom
3671 )
3672 {
3673 CALL_VOID_CRYPTO_SERVICE (TlsGetClientRandom, (Tls, ClientRandom));
3674 }
3675
3676 /**
3677 Gets the server random data used in the specified TLS connection.
3678
3679 This function returns the TLS/SSL server random data currently used in
3680 the specified TLS connection.
3681
3682 @param[in] Tls Pointer to the TLS object.
3683 @param[in,out] ServerRandom Buffer to contain the returned server
3684 random data (32 bytes).
3685
3686 **/
3687 VOID
3688 EFIAPI
3689 TlsGetServerRandom (
3690 IN VOID *Tls,
3691 IN OUT UINT8 *ServerRandom
3692 )
3693 {
3694 CALL_VOID_CRYPTO_SERVICE (TlsGetServerRandom, (Tls, ServerRandom));
3695 }
3696
3697 /**
3698 Gets the master key data used in the specified TLS connection.
3699
3700 This function returns the TLS/SSL master key material currently used in
3701 the specified TLS connection.
3702
3703 @param[in] Tls Pointer to the TLS object.
3704 @param[in,out] KeyMaterial Buffer to contain the returned key material.
3705
3706 @retval EFI_SUCCESS Key material was returned successfully.
3707 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3708 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
3709
3710 **/
3711 EFI_STATUS
3712 EFIAPI
3713 TlsGetKeyMaterial (
3714 IN VOID *Tls,
3715 IN OUT UINT8 *KeyMaterial
3716 )
3717 {
3718 CALL_CRYPTO_SERVICE (TlsGetKeyMaterial, (Tls, KeyMaterial), EFI_UNSUPPORTED);
3719 }
3720
3721 /**
3722 Gets the CA Certificate from the cert store.
3723
3724 This function returns the CA certificate for the chosen
3725 TLS connection.
3726
3727 @param[in] Tls Pointer to the TLS object.
3728 @param[out] Data Pointer to the data buffer to receive the CA
3729 certificate data sent to the client.
3730 @param[in,out] DataSize The size of data buffer in bytes.
3731
3732 @retval EFI_SUCCESS The operation succeeded.
3733 @retval EFI_UNSUPPORTED This function is not supported.
3734 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3735
3736 **/
3737 EFI_STATUS
3738 EFIAPI
3739 TlsGetCaCertificate (
3740 IN VOID *Tls,
3741 OUT VOID *Data,
3742 IN OUT UINTN *DataSize
3743 )
3744 {
3745 CALL_CRYPTO_SERVICE (TlsGetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);
3746 }
3747
3748 /**
3749 Gets the local public Certificate set in the specified TLS object.
3750
3751 This function returns the local public certificate which was currently set
3752 in the specified TLS object.
3753
3754 @param[in] Tls Pointer to the TLS object.
3755 @param[out] Data Pointer to the data buffer to receive the local
3756 public certificate.
3757 @param[in,out] DataSize The size of data buffer in bytes.
3758
3759 @retval EFI_SUCCESS The operation succeeded.
3760 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3761 @retval EFI_NOT_FOUND The certificate is not found.
3762 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3763
3764 **/
3765 EFI_STATUS
3766 EFIAPI
3767 TlsGetHostPublicCert (
3768 IN VOID *Tls,
3769 OUT VOID *Data,
3770 IN OUT UINTN *DataSize
3771 )
3772 {
3773 CALL_CRYPTO_SERVICE (TlsGetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);
3774 }
3775
3776 /**
3777 Gets the local private key set in the specified TLS object.
3778
3779 This function returns the local private key data which was currently set
3780 in the specified TLS object.
3781
3782 @param[in] Tls Pointer to the TLS object.
3783 @param[out] Data Pointer to the data buffer to receive the local
3784 private key data.
3785 @param[in,out] DataSize The size of data buffer in bytes.
3786
3787 @retval EFI_SUCCESS The operation succeeded.
3788 @retval EFI_UNSUPPORTED This function is not supported.
3789 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3790
3791 **/
3792 EFI_STATUS
3793 EFIAPI
3794 TlsGetHostPrivateKey (
3795 IN VOID *Tls,
3796 OUT VOID *Data,
3797 IN OUT UINTN *DataSize
3798 )
3799 {
3800 CALL_CRYPTO_SERVICE (TlsGetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);
3801 }
3802
3803 /**
3804 Gets the CA-supplied certificate revocation list data set in the specified
3805 TLS object.
3806
3807 This function returns the CA-supplied certificate revocation list data which
3808 was currently set in the specified TLS object.
3809
3810 @param[out] Data Pointer to the data buffer to receive the CRL data.
3811 @param[in,out] DataSize The size of data buffer in bytes.
3812
3813 @retval EFI_SUCCESS The operation succeeded.
3814 @retval EFI_UNSUPPORTED This function is not supported.
3815 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3816
3817 **/
3818 EFI_STATUS
3819 EFIAPI
3820 TlsGetCertRevocationList (
3821 OUT VOID *Data,
3822 IN OUT UINTN *DataSize
3823 )
3824 {
3825 CALL_CRYPTO_SERVICE (TlsGetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);
3826 }