]> git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c
CryptoPkg: add new X509 function 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 // Authenticated Encryption with Associated Data (AEAD) Cryptography Primitive
1557 // =====================================================================================
1558
1559 /**
1560 Performs AEAD AES-GCM authenticated encryption on a data buffer and additional authenticated data (AAD).
1561
1562 IvSize must be 12, otherwise FALSE is returned.
1563 KeySize must be 16, 24 or 32, otherwise FALSE is returned.
1564 TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.
1565
1566 @param[in] Key Pointer to the encryption key.
1567 @param[in] KeySize Size of the encryption key in bytes.
1568 @param[in] Iv Pointer to the IV value.
1569 @param[in] IvSize Size of the IV value in bytes.
1570 @param[in] AData Pointer to the additional authenticated data (AAD).
1571 @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.
1572 @param[in] DataIn Pointer to the input data buffer to be encrypted.
1573 @param[in] DataInSize Size of the input data buffer in bytes.
1574 @param[out] TagOut Pointer to a buffer that receives the authentication tag output.
1575 @param[in] TagSize Size of the authentication tag in bytes.
1576 @param[out] DataOut Pointer to a buffer that receives the encryption output.
1577 @param[out] DataOutSize Size of the output data buffer in bytes.
1578
1579 @retval TRUE AEAD AES-GCM authenticated encryption succeeded.
1580 @retval FALSE AEAD AES-GCM authenticated encryption failed.
1581
1582 **/
1583 BOOLEAN
1584 EFIAPI
1585 AeadAesGcmEncrypt (
1586 IN CONST UINT8 *Key,
1587 IN UINTN KeySize,
1588 IN CONST UINT8 *Iv,
1589 IN UINTN IvSize,
1590 IN CONST UINT8 *AData,
1591 IN UINTN ADataSize,
1592 IN CONST UINT8 *DataIn,
1593 IN UINTN DataInSize,
1594 OUT UINT8 *TagOut,
1595 IN UINTN TagSize,
1596 OUT UINT8 *DataOut,
1597 OUT UINTN *DataOutSize
1598 )
1599 {
1600 CALL_CRYPTO_SERVICE (AeadAesGcmEncrypt, (Key, KeySize, Iv, IvSize, AData, ADataSize, DataIn, DataInSize, TagOut, TagSize, DataOut, DataOutSize), FALSE);
1601 }
1602
1603 /**
1604 Performs AEAD AES-GCM authenticated decryption on a data buffer and additional authenticated data (AAD).
1605
1606 IvSize must be 12, otherwise FALSE is returned.
1607 KeySize must be 16, 24 or 32, otherwise FALSE is returned.
1608 TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.
1609 If additional authenticated data verification fails, FALSE is returned.
1610
1611 @param[in] Key Pointer to the encryption key.
1612 @param[in] KeySize Size of the encryption key in bytes.
1613 @param[in] Iv Pointer to the IV value.
1614 @param[in] IvSize Size of the IV value in bytes.
1615 @param[in] AData Pointer to the additional authenticated data (AAD).
1616 @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.
1617 @param[in] DataIn Pointer to the input data buffer to be decrypted.
1618 @param[in] DataInSize Size of the input data buffer in bytes.
1619 @param[in] Tag Pointer to a buffer that contains the authentication tag.
1620 @param[in] TagSize Size of the authentication tag in bytes.
1621 @param[out] DataOut Pointer to a buffer that receives the decryption output.
1622 @param[out] DataOutSize Size of the output data buffer in bytes.
1623
1624 @retval TRUE AEAD AES-GCM authenticated decryption succeeded.
1625 @retval FALSE AEAD AES-GCM authenticated decryption failed.
1626
1627 **/
1628 BOOLEAN
1629 EFIAPI
1630 AeadAesGcmDecrypt (
1631 IN CONST UINT8 *Key,
1632 IN UINTN KeySize,
1633 IN CONST UINT8 *Iv,
1634 IN UINTN IvSize,
1635 IN CONST UINT8 *AData,
1636 IN UINTN ADataSize,
1637 IN CONST UINT8 *DataIn,
1638 IN UINTN DataInSize,
1639 IN CONST UINT8 *Tag,
1640 IN UINTN TagSize,
1641 OUT UINT8 *DataOut,
1642 OUT UINTN *DataOutSize
1643 )
1644 {
1645 CALL_CRYPTO_SERVICE (AeadAesGcmDecrypt, (Key, KeySize, Iv, IvSize, AData, ADataSize, DataIn, DataInSize, Tag, TagSize, DataOut, DataOutSize), FALSE);
1646 }
1647
1648 // =====================================================================================
1649 // Asymmetric Cryptography Primitive
1650 // =====================================================================================
1651
1652 /**
1653 Allocates and initializes one RSA context for subsequent use.
1654
1655 @return Pointer to the RSA context that has been initialized.
1656 If the allocations fails, RsaNew() returns NULL.
1657
1658 **/
1659 VOID *
1660 EFIAPI
1661 RsaNew (
1662 VOID
1663 )
1664 {
1665 CALL_CRYPTO_SERVICE (RsaNew, (), NULL);
1666 }
1667
1668 /**
1669 Release the specified RSA context.
1670
1671 If RsaContext is NULL, then return FALSE.
1672
1673 @param[in] RsaContext Pointer to the RSA context to be released.
1674
1675 **/
1676 VOID
1677 EFIAPI
1678 RsaFree (
1679 IN VOID *RsaContext
1680 )
1681 {
1682 CALL_VOID_CRYPTO_SERVICE (RsaFree, (RsaContext));
1683 }
1684
1685 /**
1686 Sets the tag-designated key component into the established RSA context.
1687
1688 This function sets the tag-designated RSA key component into the established
1689 RSA context from the user-specified non-negative integer (octet string format
1690 represented in RSA PKCS#1).
1691 If BigNumber is NULL, then the specified key component in RSA context is cleared.
1692
1693 If RsaContext is NULL, then return FALSE.
1694
1695 @param[in, out] RsaContext Pointer to RSA context being set.
1696 @param[in] KeyTag Tag of RSA key component being set.
1697 @param[in] BigNumber Pointer to octet integer buffer.
1698 If NULL, then the specified key component in RSA
1699 context is cleared.
1700 @param[in] BnSize Size of big number buffer in bytes.
1701 If BigNumber is NULL, then it is ignored.
1702
1703 @retval TRUE RSA key component was set successfully.
1704 @retval FALSE Invalid RSA key component tag.
1705
1706 **/
1707 BOOLEAN
1708 EFIAPI
1709 RsaSetKey (
1710 IN OUT VOID *RsaContext,
1711 IN RSA_KEY_TAG KeyTag,
1712 IN CONST UINT8 *BigNumber,
1713 IN UINTN BnSize
1714 )
1715 {
1716 CALL_CRYPTO_SERVICE (RsaSetKey, (RsaContext, KeyTag, BigNumber, BnSize), FALSE);
1717 }
1718
1719 /**
1720 Gets the tag-designated RSA key component from the established RSA context.
1721
1722 This function retrieves the tag-designated RSA key component from the
1723 established RSA context as a non-negative integer (octet string format
1724 represented in RSA PKCS#1).
1725 If specified key component has not been set or has been cleared, then returned
1726 BnSize is set to 0.
1727 If the BigNumber buffer is too small to hold the contents of the key, FALSE
1728 is returned and BnSize is set to the required buffer size to obtain the key.
1729
1730 If RsaContext is NULL, then return FALSE.
1731 If BnSize is NULL, then return FALSE.
1732 If BnSize is large enough but BigNumber is NULL, then return FALSE.
1733 If this interface is not supported, then return FALSE.
1734
1735 @param[in, out] RsaContext Pointer to RSA context being set.
1736 @param[in] KeyTag Tag of RSA key component being set.
1737 @param[out] BigNumber Pointer to octet integer buffer.
1738 @param[in, out] BnSize On input, the size of big number buffer in bytes.
1739 On output, the size of data returned in big number buffer in bytes.
1740
1741 @retval TRUE RSA key component was retrieved successfully.
1742 @retval FALSE Invalid RSA key component tag.
1743 @retval FALSE BnSize is too small.
1744 @retval FALSE This interface is not supported.
1745
1746 **/
1747 BOOLEAN
1748 EFIAPI
1749 RsaGetKey (
1750 IN OUT VOID *RsaContext,
1751 IN RSA_KEY_TAG KeyTag,
1752 OUT UINT8 *BigNumber,
1753 IN OUT UINTN *BnSize
1754 )
1755 {
1756 CALL_CRYPTO_SERVICE (RsaGetKey, (RsaContext, KeyTag, BigNumber, BnSize), FALSE);
1757 }
1758
1759 /**
1760 Generates RSA key components.
1761
1762 This function generates RSA key components. It takes RSA public exponent E and
1763 length in bits of RSA modulus N as input, and generates all key components.
1764 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
1765
1766 Before this function can be invoked, pseudorandom number generator must be correctly
1767 initialized by RandomSeed().
1768
1769 If RsaContext is NULL, then return FALSE.
1770 If this interface is not supported, then return FALSE.
1771
1772 @param[in, out] RsaContext Pointer to RSA context being set.
1773 @param[in] ModulusLength Length of RSA modulus N in bits.
1774 @param[in] PublicExponent Pointer to RSA public exponent.
1775 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
1776
1777 @retval TRUE RSA key component was generated successfully.
1778 @retval FALSE Invalid RSA key component tag.
1779 @retval FALSE This interface is not supported.
1780
1781 **/
1782 BOOLEAN
1783 EFIAPI
1784 RsaGenerateKey (
1785 IN OUT VOID *RsaContext,
1786 IN UINTN ModulusLength,
1787 IN CONST UINT8 *PublicExponent,
1788 IN UINTN PublicExponentSize
1789 )
1790 {
1791 CALL_CRYPTO_SERVICE (RsaGenerateKey, (RsaContext, ModulusLength, PublicExponent, PublicExponentSize), FALSE);
1792 }
1793
1794 /**
1795 Validates key components of RSA context.
1796 NOTE: This function performs integrity checks on all the RSA key material, so
1797 the RSA key structure must contain all the private key data.
1798
1799 This function validates key components of RSA context in following aspects:
1800 - Whether p is a prime
1801 - Whether q is a prime
1802 - Whether n = p * q
1803 - Whether d*e = 1 mod lcm(p-1,q-1)
1804
1805 If RsaContext is NULL, then return FALSE.
1806 If this interface is not supported, then return FALSE.
1807
1808 @param[in] RsaContext Pointer to RSA context to check.
1809
1810 @retval TRUE RSA key components are valid.
1811 @retval FALSE RSA key components are not valid.
1812 @retval FALSE This interface is not supported.
1813
1814 **/
1815 BOOLEAN
1816 EFIAPI
1817 RsaCheckKey (
1818 IN VOID *RsaContext
1819 )
1820 {
1821 CALL_CRYPTO_SERVICE (RsaCheckKey, (RsaContext), FALSE);
1822 }
1823
1824 /**
1825 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
1826
1827 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
1828 RSA PKCS#1.
1829 If the Signature buffer is too small to hold the contents of signature, FALSE
1830 is returned and SigSize is set to the required buffer size to obtain the signature.
1831
1832 If RsaContext is NULL, then return FALSE.
1833 If MessageHash is NULL, then return FALSE.
1834 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
1835 If SigSize is large enough but Signature is NULL, then return FALSE.
1836 If this interface is not supported, then return FALSE.
1837
1838 @param[in] RsaContext Pointer to RSA context for signature generation.
1839 @param[in] MessageHash Pointer to octet message hash to be signed.
1840 @param[in] HashSize Size of the message hash in bytes.
1841 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
1842 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1843 On output, the size of data returned in Signature buffer in bytes.
1844
1845 @retval TRUE Signature successfully generated in PKCS1-v1_5.
1846 @retval FALSE Signature generation failed.
1847 @retval FALSE SigSize is too small.
1848 @retval FALSE This interface is not supported.
1849
1850 **/
1851 BOOLEAN
1852 EFIAPI
1853 RsaPkcs1Sign (
1854 IN VOID *RsaContext,
1855 IN CONST UINT8 *MessageHash,
1856 IN UINTN HashSize,
1857 OUT UINT8 *Signature,
1858 IN OUT UINTN *SigSize
1859 )
1860 {
1861 CALL_CRYPTO_SERVICE (RsaPkcs1Sign, (RsaContext, MessageHash, HashSize, Signature, SigSize), FALSE);
1862 }
1863
1864 /**
1865 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
1866 RSA PKCS#1.
1867
1868 If RsaContext is NULL, then return FALSE.
1869 If MessageHash is NULL, then return FALSE.
1870 If Signature is NULL, then return FALSE.
1871 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
1872
1873 @param[in] RsaContext Pointer to RSA context for signature verification.
1874 @param[in] MessageHash Pointer to octet message hash to be checked.
1875 @param[in] HashSize Size of the message hash in bytes.
1876 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
1877 @param[in] SigSize Size of signature in bytes.
1878
1879 @retval TRUE Valid signature encoded in PKCS1-v1_5.
1880 @retval FALSE Invalid signature or invalid RSA context.
1881
1882 **/
1883 BOOLEAN
1884 EFIAPI
1885 RsaPkcs1Verify (
1886 IN VOID *RsaContext,
1887 IN CONST UINT8 *MessageHash,
1888 IN UINTN HashSize,
1889 IN CONST UINT8 *Signature,
1890 IN UINTN SigSize
1891 )
1892 {
1893 CALL_CRYPTO_SERVICE (RsaPkcs1Verify, (RsaContext, MessageHash, HashSize, Signature, SigSize), FALSE);
1894 }
1895
1896 /**
1897 Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
1898 Implementation determines salt length automatically from the signature encoding.
1899 Mask generation function is the same as the message digest algorithm.
1900 Salt length should be equal to digest length.
1901
1902 @param[in] RsaContext Pointer to RSA context for signature verification.
1903 @param[in] Message Pointer to octet message to be verified.
1904 @param[in] MsgSize Size of the message in bytes.
1905 @param[in] Signature Pointer to RSASSA-PSS signature to be verified.
1906 @param[in] SigSize Size of signature in bytes.
1907 @param[in] DigestLen Length of digest for RSA operation.
1908 @param[in] SaltLen Salt length for PSS encoding.
1909
1910 @retval TRUE Valid signature encoded in RSASSA-PSS.
1911 @retval FALSE Invalid signature or invalid RSA context.
1912
1913 **/
1914 BOOLEAN
1915 EFIAPI
1916 RsaPssVerify (
1917 IN VOID *RsaContext,
1918 IN CONST UINT8 *Message,
1919 IN UINTN MsgSize,
1920 IN CONST UINT8 *Signature,
1921 IN UINTN SigSize,
1922 IN UINT16 DigestLen,
1923 IN UINT16 SaltLen
1924 )
1925 {
1926 CALL_CRYPTO_SERVICE (RsaPssVerify, (RsaContext, Message, MsgSize, Signature, SigSize, DigestLen, SaltLen), FALSE);
1927 }
1928
1929 /**
1930 This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in
1931 RFC 8017.
1932 Mask generation function is the same as the message digest algorithm.
1933 If the Signature buffer is too small to hold the contents of signature, FALSE
1934 is returned and SigSize is set to the required buffer size to obtain the signature.
1935
1936 If RsaContext is NULL, then return FALSE.
1937 If Message is NULL, then return FALSE.
1938 If MsgSize is zero or > INT_MAX, then return FALSE.
1939 If DigestLen is NOT 32, 48 or 64, return FALSE.
1940 If SaltLen is not equal to DigestLen, then return FALSE.
1941 If SigSize is large enough but Signature is NULL, then return FALSE.
1942 If this interface is not supported, then return FALSE.
1943
1944 @param[in] RsaContext Pointer to RSA context for signature generation.
1945 @param[in] Message Pointer to octet message to be signed.
1946 @param[in] MsgSize Size of the message in bytes.
1947 @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.
1948 @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.
1949 @param[out] Signature Pointer to buffer to receive RSA PSS signature.
1950 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1951 On output, the size of data returned in Signature buffer in bytes.
1952
1953 @retval TRUE Signature successfully generated in RSASSA-PSS.
1954 @retval FALSE Signature generation failed.
1955 @retval FALSE SigSize is too small.
1956 @retval FALSE This interface is not supported.
1957
1958 **/
1959 BOOLEAN
1960 EFIAPI
1961 RsaPssSign (
1962 IN VOID *RsaContext,
1963 IN CONST UINT8 *Message,
1964 IN UINTN MsgSize,
1965 IN UINT16 DigestLen,
1966 IN UINT16 SaltLen,
1967 OUT UINT8 *Signature,
1968 IN OUT UINTN *SigSize
1969 )
1970 {
1971 CALL_CRYPTO_SERVICE (RsaPssSign, (RsaContext, Message, MsgSize, DigestLen, SaltLen, Signature, SigSize), FALSE);
1972 }
1973
1974 /**
1975 Retrieve the RSA Private Key from the password-protected PEM key data.
1976
1977 If PemData is NULL, then return FALSE.
1978 If RsaContext is NULL, then return FALSE.
1979 If this interface is not supported, then return FALSE.
1980
1981 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
1982 @param[in] PemSize Size of the PEM key data in bytes.
1983 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
1984 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1985 RSA private key component. Use RsaFree() function to free the
1986 resource.
1987
1988 @retval TRUE RSA Private Key was retrieved successfully.
1989 @retval FALSE Invalid PEM key data or incorrect password.
1990 @retval FALSE This interface is not supported.
1991
1992 **/
1993 BOOLEAN
1994 EFIAPI
1995 RsaGetPrivateKeyFromPem (
1996 IN CONST UINT8 *PemData,
1997 IN UINTN PemSize,
1998 IN CONST CHAR8 *Password,
1999 OUT VOID **RsaContext
2000 )
2001 {
2002 CALL_CRYPTO_SERVICE (RsaGetPrivateKeyFromPem, (PemData, PemSize, Password, RsaContext), FALSE);
2003 }
2004
2005 /**
2006 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
2007
2008 If Cert is NULL, then return FALSE.
2009 If RsaContext is NULL, then return FALSE.
2010 If this interface is not supported, then return FALSE.
2011
2012 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2013 @param[in] CertSize Size of the X509 certificate in bytes.
2014 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2015 RSA public key component. Use RsaFree() function to free the
2016 resource.
2017
2018 @retval TRUE RSA Public Key was retrieved successfully.
2019 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
2020 @retval FALSE This interface is not supported.
2021
2022 **/
2023 BOOLEAN
2024 EFIAPI
2025 RsaGetPublicKeyFromX509 (
2026 IN CONST UINT8 *Cert,
2027 IN UINTN CertSize,
2028 OUT VOID **RsaContext
2029 )
2030 {
2031 CALL_CRYPTO_SERVICE (RsaGetPublicKeyFromX509, (Cert, CertSize, RsaContext), FALSE);
2032 }
2033
2034 /**
2035 Retrieve the subject bytes from one X.509 certificate.
2036
2037 If Cert is NULL, then return FALSE.
2038 If SubjectSize is NULL, then return FALSE.
2039 If this interface is not supported, then return FALSE.
2040
2041 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2042 @param[in] CertSize Size of the X509 certificate in bytes.
2043 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
2044 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
2045 and the size of buffer returned CertSubject on output.
2046
2047 @retval TRUE The certificate subject retrieved successfully.
2048 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
2049 The SubjectSize will be updated with the required size.
2050 @retval FALSE This interface is not supported.
2051
2052 **/
2053 BOOLEAN
2054 EFIAPI
2055 X509GetSubjectName (
2056 IN CONST UINT8 *Cert,
2057 IN UINTN CertSize,
2058 OUT UINT8 *CertSubject,
2059 IN OUT UINTN *SubjectSize
2060 )
2061 {
2062 CALL_CRYPTO_SERVICE (X509GetSubjectName, (Cert, CertSize, CertSubject, SubjectSize), FALSE);
2063 }
2064
2065 /**
2066 Retrieve the common name (CN) string from one X.509 certificate.
2067
2068 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2069 @param[in] CertSize Size of the X509 certificate in bytes.
2070 @param[out] CommonName Buffer to contain the retrieved certificate common
2071 name string (UTF8). At most CommonNameSize bytes will be
2072 written and the string will be null terminated. May be
2073 NULL in order to determine the size buffer needed.
2074 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
2075 and the size of buffer returned CommonName on output.
2076 If CommonName is NULL then the amount of space needed
2077 in buffer (including the final null) is returned.
2078
2079 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
2080 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2081 If CommonNameSize is NULL.
2082 If CommonName is not NULL and *CommonNameSize is 0.
2083 If Certificate is invalid.
2084 @retval RETURN_NOT_FOUND If no CommonName entry exists.
2085 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
2086 (including the final null) is returned in the
2087 CommonNameSize parameter.
2088 @retval RETURN_UNSUPPORTED The operation is not supported.
2089
2090 **/
2091 RETURN_STATUS
2092 EFIAPI
2093 X509GetCommonName (
2094 IN CONST UINT8 *Cert,
2095 IN UINTN CertSize,
2096 OUT CHAR8 *CommonName OPTIONAL,
2097 IN OUT UINTN *CommonNameSize
2098 )
2099 {
2100 CALL_CRYPTO_SERVICE (X509GetCommonName, (Cert, CertSize, CommonName, CommonNameSize), RETURN_UNSUPPORTED);
2101 }
2102
2103 /**
2104 Retrieve the organization name (O) string from one X.509 certificate.
2105
2106 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2107 @param[in] CertSize Size of the X509 certificate in bytes.
2108 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
2109 name string. At most NameBufferSize bytes will be
2110 written and the string will be null terminated. May be
2111 NULL in order to determine the size buffer needed.
2112 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
2113 and the size of buffer returned Name on output.
2114 If NameBuffer is NULL then the amount of space needed
2115 in buffer (including the final null) is returned.
2116
2117 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
2118 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2119 If NameBufferSize is NULL.
2120 If NameBuffer is not NULL and *CommonNameSize is 0.
2121 If Certificate is invalid.
2122 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
2123 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
2124 (including the final null) is returned in the
2125 CommonNameSize parameter.
2126 @retval RETURN_UNSUPPORTED The operation is not supported.
2127
2128 **/
2129 RETURN_STATUS
2130 EFIAPI
2131 X509GetOrganizationName (
2132 IN CONST UINT8 *Cert,
2133 IN UINTN CertSize,
2134 OUT CHAR8 *NameBuffer OPTIONAL,
2135 IN OUT UINTN *NameBufferSize
2136 )
2137 {
2138 CALL_CRYPTO_SERVICE (X509GetOrganizationName, (Cert, CertSize, NameBuffer, NameBufferSize), RETURN_UNSUPPORTED);
2139 }
2140
2141 /**
2142 Verify one X509 certificate was issued by the trusted CA.
2143
2144 If Cert is NULL, then return FALSE.
2145 If CACert is NULL, then return FALSE.
2146 If this interface is not supported, then return FALSE.
2147
2148 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
2149 @param[in] CertSize Size of the X509 certificate in bytes.
2150 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
2151 @param[in] CACertSize Size of the CA Certificate in bytes.
2152
2153 @retval TRUE The certificate was issued by the trusted CA.
2154 @retval FALSE Invalid certificate or the certificate was not issued by the given
2155 trusted CA.
2156 @retval FALSE This interface is not supported.
2157
2158 **/
2159 BOOLEAN
2160 EFIAPI
2161 X509VerifyCert (
2162 IN CONST UINT8 *Cert,
2163 IN UINTN CertSize,
2164 IN CONST UINT8 *CACert,
2165 IN UINTN CACertSize
2166 )
2167 {
2168 CALL_CRYPTO_SERVICE (X509VerifyCert, (Cert, CertSize, CACert, CACertSize), FALSE);
2169 }
2170
2171 /**
2172 Construct a X509 object from DER-encoded certificate data.
2173
2174 If Cert is NULL, then return FALSE.
2175 If SingleX509Cert is NULL, then return FALSE.
2176 If this interface is not supported, then return FALSE.
2177
2178 @param[in] Cert Pointer to the DER-encoded certificate data.
2179 @param[in] CertSize The size of certificate data in bytes.
2180 @param[out] SingleX509Cert The generated X509 object.
2181
2182 @retval TRUE The X509 object generation succeeded.
2183 @retval FALSE The operation failed.
2184 @retval FALSE This interface is not supported.
2185
2186 **/
2187 BOOLEAN
2188 EFIAPI
2189 X509ConstructCertificate (
2190 IN CONST UINT8 *Cert,
2191 IN UINTN CertSize,
2192 OUT UINT8 **SingleX509Cert
2193 )
2194 {
2195 CALL_CRYPTO_SERVICE (X509ConstructCertificate, (Cert, CertSize, SingleX509Cert), FALSE);
2196 }
2197
2198 /**
2199 Construct a X509 stack object from a list of DER-encoded certificate data.
2200
2201 If X509Stack is NULL, then return FALSE.
2202 If this interface is not supported, then return FALSE.
2203
2204 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2205 On output, pointer to the X509 stack object with new
2206 inserted X509 certificate.
2207 @param[in] Args VA_LIST marker for the variable argument list.
2208 ... A list of DER-encoded single certificate data followed
2209 by certificate size. A NULL terminates the list. The
2210 pairs are the arguments to X509ConstructCertificate().
2211
2212 @retval TRUE The X509 stack construction succeeded.
2213 @retval FALSE The construction operation failed.
2214 @retval FALSE This interface is not supported.
2215
2216 **/
2217 BOOLEAN
2218 EFIAPI
2219 X509ConstructCertificateStack (
2220 IN OUT UINT8 **X509Stack,
2221 ...
2222 )
2223 {
2224 VA_LIST Args;
2225 BOOLEAN Result;
2226
2227 VA_START (Args, X509Stack);
2228 Result = X509ConstructCertificateStackV (X509Stack, Args);
2229 VA_END (Args);
2230 return Result;
2231 }
2232
2233 /**
2234 Construct a X509 stack object from a list of DER-encoded certificate data.
2235
2236 If X509Stack is NULL, then return FALSE.
2237 If this interface is not supported, then return FALSE.
2238
2239 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2240 On output, pointer to the X509 stack object with new
2241 inserted X509 certificate.
2242 @param[in] Args VA_LIST marker for the variable argument list.
2243 A list of DER-encoded single certificate data followed
2244 by certificate size. A NULL terminates the list. The
2245 pairs are the arguments to X509ConstructCertificate().
2246
2247 @retval TRUE The X509 stack construction succeeded.
2248 @retval FALSE The construction operation failed.
2249 @retval FALSE This interface is not supported.
2250
2251 **/
2252 BOOLEAN
2253 EFIAPI
2254 X509ConstructCertificateStackV (
2255 IN OUT UINT8 **X509Stack,
2256 IN VA_LIST Args
2257 )
2258 {
2259 CALL_CRYPTO_SERVICE (X509ConstructCertificateStackV, (X509Stack, Args), FALSE);
2260 }
2261
2262 /**
2263 Release the specified X509 object.
2264
2265 If the interface is not supported, then ASSERT().
2266
2267 @param[in] X509Cert Pointer to the X509 object to be released.
2268
2269 **/
2270 VOID
2271 EFIAPI
2272 X509Free (
2273 IN VOID *X509Cert
2274 )
2275 {
2276 CALL_VOID_CRYPTO_SERVICE (X509Free, (X509Cert));
2277 }
2278
2279 /**
2280 Release the specified X509 stack object.
2281
2282 If the interface is not supported, then ASSERT().
2283
2284 @param[in] X509Stack Pointer to the X509 stack object to be released.
2285
2286 **/
2287 VOID
2288 EFIAPI
2289 X509StackFree (
2290 IN VOID *X509Stack
2291 )
2292 {
2293 CALL_VOID_CRYPTO_SERVICE (X509StackFree, (X509Stack));
2294 }
2295
2296 /**
2297 Retrieve the TBSCertificate from one given X.509 certificate.
2298
2299 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
2300 @param[in] CertSize Size of the X509 certificate in bytes.
2301 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
2302 @param[out] TBSCertSize Size of the TBS certificate in bytes.
2303
2304 If Cert is NULL, then return FALSE.
2305 If TBSCert is NULL, then return FALSE.
2306 If TBSCertSize is NULL, then return FALSE.
2307 If this interface is not supported, then return FALSE.
2308
2309 @retval TRUE The TBSCertificate was retrieved successfully.
2310 @retval FALSE Invalid X.509 certificate.
2311
2312 **/
2313 BOOLEAN
2314 EFIAPI
2315 X509GetTBSCert (
2316 IN CONST UINT8 *Cert,
2317 IN UINTN CertSize,
2318 OUT UINT8 **TBSCert,
2319 OUT UINTN *TBSCertSize
2320 )
2321 {
2322 CALL_CRYPTO_SERVICE (X509GetTBSCert, (Cert, CertSize, TBSCert, TBSCertSize), FALSE);
2323 }
2324
2325 /**
2326 Retrieve the version from one X.509 certificate.
2327
2328 If Cert is NULL, then return FALSE.
2329 If CertSize is 0, then return FALSE.
2330 If this interface is not supported, then return FALSE.
2331
2332 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2333 @param[in] CertSize Size of the X509 certificate in bytes.
2334 @param[out] Version Pointer to the retrieved version integer.
2335
2336 @retval TRUE The certificate version retrieved successfully.
2337 @retval FALSE If Cert is NULL or CertSize is Zero.
2338 @retval FALSE The operation is not supported.
2339
2340 **/
2341 BOOLEAN
2342 EFIAPI
2343 X509GetVersion (
2344 IN CONST UINT8 *Cert,
2345 IN UINTN CertSize,
2346 OUT UINTN *Version
2347 )
2348 {
2349 CALL_CRYPTO_SERVICE (X509GetVersion, (Cert, CertSize, Version), FALSE);
2350 }
2351
2352 /**
2353 Retrieve the serialNumber from one X.509 certificate.
2354
2355 If Cert is NULL, then return FALSE.
2356 If CertSize is 0, then return FALSE.
2357 If this interface is not supported, then return FALSE.
2358
2359 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2360 @param[in] CertSize Size of the X509 certificate in bytes.
2361 @param[out] SerialNumber Pointer to the retrieved certificate SerialNumber bytes.
2362 @param[in, out] SerialNumberSize The size in bytes of the SerialNumber buffer on input,
2363 and the size of buffer returned SerialNumber on output.
2364
2365 @retval TRUE The certificate serialNumber retrieved successfully.
2366 @retval FALSE If Cert is NULL or CertSize is Zero.
2367 If SerialNumberSize is NULL.
2368 If Certificate is invalid.
2369 @retval FALSE If no SerialNumber exists.
2370 @retval FALSE If the SerialNumber is NULL. The required buffer size
2371 (including the final null) is returned in the
2372 SerialNumberSize parameter.
2373 @retval FALSE The operation is not supported.
2374 **/
2375 BOOLEAN
2376 EFIAPI
2377 X509GetSerialNumber (
2378 IN CONST UINT8 *Cert,
2379 IN UINTN CertSize,
2380 OUT UINT8 *SerialNumber, OPTIONAL
2381 IN OUT UINTN *SerialNumberSize
2382 )
2383 {
2384 CALL_CRYPTO_SERVICE (X509GetSerialNumber, (Cert, CertSize, SerialNumber, SerialNumberSize), FALSE);
2385 }
2386
2387 /**
2388 Retrieve the issuer bytes from one X.509 certificate.
2389
2390 If Cert is NULL, then return FALSE.
2391 If CertIssuerSize is NULL, then return FALSE.
2392 If this interface is not supported, then return FALSE.
2393
2394 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2395 @param[in] CertSize Size of the X509 certificate in bytes.
2396 @param[out] CertIssuer Pointer to the retrieved certificate subject bytes.
2397 @param[in, out] CertIssuerSize The size in bytes of the CertIssuer buffer on input,
2398 and the size of buffer returned CertSubject on output.
2399
2400 @retval TRUE The certificate issuer retrieved successfully.
2401 @retval FALSE Invalid certificate, or the CertIssuerSize is too small for the result.
2402 The CertIssuerSize will be updated with the required size.
2403 @retval FALSE This interface is not supported.
2404
2405 **/
2406 BOOLEAN
2407 EFIAPI
2408 X509GetIssuerName (
2409 IN CONST UINT8 *Cert,
2410 IN UINTN CertSize,
2411 OUT UINT8 *CertIssuer,
2412 IN OUT UINTN *CertIssuerSize
2413 )
2414 {
2415 CALL_CRYPTO_SERVICE (X509GetIssuerName, (Cert, CertSize, CertIssuer, CertIssuerSize), FALSE);
2416 }
2417
2418 /**
2419 Retrieve the Signature Algorithm from one X.509 certificate.
2420
2421 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2422 @param[in] CertSize Size of the X509 certificate in bytes.
2423 @param[out] Oid Signature Algorithm Object identifier buffer.
2424 @param[in,out] OidSize Signature Algorithm Object identifier buffer size
2425
2426 @retval TRUE The certificate Extension data retrieved successfully.
2427 @retval FALSE If Cert is NULL.
2428 If OidSize is NULL.
2429 If Oid is not NULL and *OidSize is 0.
2430 If Certificate is invalid.
2431 @retval FALSE If no SignatureType.
2432 @retval FALSE If the Oid is NULL. The required buffer size
2433 is returned in the OidSize.
2434 @retval FALSE The operation is not supported.
2435 **/
2436 BOOLEAN
2437 EFIAPI
2438 X509GetSignatureAlgorithm (
2439 IN CONST UINT8 *Cert,
2440 IN UINTN CertSize,
2441 OUT UINT8 *Oid, OPTIONAL
2442 IN OUT UINTN *OidSize
2443 )
2444 {
2445 CALL_CRYPTO_SERVICE (X509GetSignatureAlgorithm, (Cert, CertSize, Oid, OidSize), FALSE);
2446 }
2447
2448 /**
2449 Retrieve Extension data from one X.509 certificate.
2450
2451 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2452 @param[in] CertSize Size of the X509 certificate in bytes.
2453 @param[in] Oid Object identifier buffer
2454 @param[in] OidSize Object identifier buffer size
2455 @param[out] ExtensionData Extension bytes.
2456 @param[in, out] ExtensionDataSize Extension bytes size.
2457
2458 @retval TRUE The certificate Extension data retrieved successfully.
2459 @retval FALSE If Cert is NULL.
2460 If ExtensionDataSize is NULL.
2461 If ExtensionData is not NULL and *ExtensionDataSize is 0.
2462 If Certificate is invalid.
2463 @retval FALSE If no Extension entry match Oid.
2464 @retval FALSE If the ExtensionData is NULL. The required buffer size
2465 is returned in the ExtensionDataSize parameter.
2466 @retval FALSE The operation is not supported.
2467 **/
2468 BOOLEAN
2469 EFIAPI
2470 X509GetExtensionData (
2471 IN CONST UINT8 *Cert,
2472 IN UINTN CertSize,
2473 IN CONST UINT8 *Oid,
2474 IN UINTN OidSize,
2475 OUT UINT8 *ExtensionData,
2476 IN OUT UINTN *ExtensionDataSize
2477 )
2478 {
2479 CALL_CRYPTO_SERVICE (X509GetExtensionData, (Cert, CertSize, Oid, OidSize, ExtensionData, ExtensionDataSize), FALSE);
2480 }
2481
2482 /**
2483 Retrieve the Extended Key Usage from one X.509 certificate.
2484
2485 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2486 @param[in] CertSize Size of the X509 certificate in bytes.
2487 @param[out] Usage Key Usage bytes.
2488 @param[in, out] UsageSize Key Usage buffer sizs in bytes.
2489
2490 @retval TRUE The Usage bytes retrieve successfully.
2491 @retval FALSE If Cert is NULL.
2492 If CertSize is NULL.
2493 If Usage is not NULL and *UsageSize is 0.
2494 If Cert is invalid.
2495 @retval FALSE If the Usage is NULL. The required buffer size
2496 is returned in the UsageSize parameter.
2497 @retval FALSE The operation is not supported.
2498 **/
2499 BOOLEAN
2500 EFIAPI
2501 X509GetExtendedKeyUsage (
2502 IN CONST UINT8 *Cert,
2503 IN UINTN CertSize,
2504 OUT UINT8 *Usage,
2505 IN OUT UINTN *UsageSize
2506 )
2507 {
2508 CALL_CRYPTO_SERVICE (X509GetExtendedKeyUsage, (Cert, CertSize, Usage, UsageSize), FALSE);
2509 }
2510
2511 /**
2512 Retrieve the Validity from one X.509 certificate
2513
2514 If Cert is NULL, then return FALSE.
2515 If CertIssuerSize is NULL, then return FALSE.
2516 If this interface is not supported, then return FALSE.
2517
2518 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2519 @param[in] CertSize Size of the X509 certificate in bytes.
2520 @param[in] From notBefore Pointer to DateTime object.
2521 @param[in,out] FromSize notBefore DateTime object size.
2522 @param[in] To notAfter Pointer to DateTime object.
2523 @param[in,out] ToSize notAfter DateTime object size.
2524
2525 Note: X509CompareDateTime to compare DateTime oject
2526 x509SetDateTime to get a DateTime object from a DateTimeStr
2527
2528 @retval TRUE The certificate Validity retrieved successfully.
2529 @retval FALSE Invalid certificate, or Validity retrieve failed.
2530 @retval FALSE This interface is not supported.
2531 **/
2532 BOOLEAN
2533 EFIAPI
2534 X509GetValidity (
2535 IN CONST UINT8 *Cert,
2536 IN UINTN CertSize,
2537 IN UINT8 *From,
2538 IN OUT UINTN *FromSize,
2539 IN UINT8 *To,
2540 IN OUT UINTN *ToSize
2541 )
2542 {
2543 CALL_CRYPTO_SERVICE (X509GetValidity, (Cert, CertSize, From, FromSize, To, ToSize), FALSE);
2544 }
2545
2546 /**
2547 Format a DateTimeStr to DataTime object in DataTime Buffer
2548
2549 If DateTimeStr is NULL, then return FALSE.
2550 If DateTimeSize is NULL, then return FALSE.
2551 If this interface is not supported, then return FALSE.
2552
2553 @param[in] DateTimeStr DateTime string like YYYYMMDDhhmmssZ
2554 Ref: https://www.w3.org/TR/NOTE-datetime
2555 Z stand for UTC time
2556 @param[out] DateTime Pointer to a DateTime object.
2557 @param[in,out] DateTimeSize DateTime object buffer size.
2558
2559 @retval TRUE The DateTime object create successfully.
2560 @retval FALSE If DateTimeStr is NULL.
2561 If DateTimeSize is NULL.
2562 If DateTime is not NULL and *DateTimeSize is 0.
2563 If Year Month Day Hour Minute Second combination is invalid datetime.
2564 @retval FALSE If the DateTime is NULL. The required buffer size
2565 (including the final null) is returned in the
2566 DateTimeSize parameter.
2567 @retval FALSE The operation is not supported.
2568 **/
2569 BOOLEAN
2570 EFIAPI
2571 X509FormatDateTime (
2572 IN CONST CHAR8 *DateTimeStr,
2573 OUT VOID *DateTime,
2574 IN OUT UINTN *DateTimeSize
2575 )
2576 {
2577 CALL_CRYPTO_SERVICE (X509FormatDateTime, (DateTimeStr, DateTime, DateTimeSize), FALSE);
2578 }
2579
2580 /**
2581 Compare DateTime1 object and DateTime2 object.
2582
2583 If DateTime1 is NULL, then return -2.
2584 If DateTime2 is NULL, then return -2.
2585 If DateTime1 == DateTime2, then return 0
2586 If DateTime1 > DateTime2, then return 1
2587 If DateTime1 < DateTime2, then return -1
2588
2589 @param[in] DateTime1 Pointer to a DateTime Ojbect
2590 @param[in] DateTime2 Pointer to a DateTime Object
2591
2592 @retval 0 If DateTime1 == DateTime2
2593 @retval 1 If DateTime1 > DateTime2
2594 @retval -1 If DateTime1 < DateTime2
2595 **/
2596 INT32
2597 EFIAPI
2598 X509CompareDateTime (
2599 IN CONST VOID *DateTime1,
2600 IN CONST VOID *DateTime2
2601 )
2602 {
2603 CALL_CRYPTO_SERVICE (X509CompareDateTime, (DateTime1, DateTime2), FALSE);
2604 }
2605
2606 /**
2607 Retrieve the Key Usage from one X.509 certificate.
2608
2609 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2610 @param[in] CertSize Size of the X509 certificate in bytes.
2611 @param[out] Usage Key Usage (CRYPTO_X509_KU_*)
2612
2613 @retval TRUE The certificate Key Usage retrieved successfully.
2614 @retval FALSE Invalid certificate, or Usage is NULL
2615 @retval FALSE This interface is not supported.
2616 **/
2617 BOOLEAN
2618 EFIAPI
2619 X509GetKeyUsage (
2620 IN CONST UINT8 *Cert,
2621 IN UINTN CertSize,
2622 OUT UINTN *Usage
2623 )
2624 {
2625 CALL_CRYPTO_SERVICE (X509GetKeyUsage, (Cert, CertSize, Usage), FALSE);
2626 }
2627
2628 /**
2629 Verify one X509 certificate was issued by the trusted CA.
2630 @param[in] RootCert Trusted Root Certificate buffer
2631
2632 @param[in] RootCertLength Trusted Root Certificate buffer length
2633 @param[in] CertChain One or more ASN.1 DER-encoded X.509 certificates
2634 where the first certificate is signed by the Root
2635 Certificate or is the Root Cerificate itself. and
2636 subsequent cerificate is signed by the preceding
2637 cerificate.
2638 @param[in] CertChainLength Total length of the certificate chain, in bytes.
2639
2640 @retval TRUE All cerificates was issued by the first certificate in X509Certchain.
2641 @retval FALSE Invalid certificate or the certificate was not issued by the given
2642 trusted CA.
2643 **/
2644 BOOLEAN
2645 EFIAPI
2646 X509VerifyCertChain (
2647 IN CONST UINT8 *RootCert,
2648 IN UINTN RootCertLength,
2649 IN CONST UINT8 *CertChain,
2650 IN UINTN CertChainLength
2651 )
2652 {
2653 CALL_CRYPTO_SERVICE (X509VerifyCertChain, (RootCert, RootCertLength, CertChain, CertChainLength), FALSE);
2654 }
2655
2656 /**
2657 Get one X509 certificate from CertChain.
2658
2659 @param[in] CertChain One or more ASN.1 DER-encoded X.509 certificates
2660 where the first certificate is signed by the Root
2661 Certificate or is the Root Cerificate itself. and
2662 subsequent cerificate is signed by the preceding
2663 cerificate.
2664 @param[in] CertChainLength Total length of the certificate chain, in bytes.
2665
2666 @param[in] CertIndex Index of certificate.
2667
2668 @param[out] Cert The certificate at the index of CertChain.
2669 @param[out] CertLength The length certificate at the index of CertChain.
2670
2671 @retval TRUE Success.
2672 @retval FALSE Failed to get certificate from certificate chain.
2673 **/
2674 BOOLEAN
2675 EFIAPI
2676 X509GetCertFromCertChain (
2677 IN CONST UINT8 *CertChain,
2678 IN UINTN CertChainLength,
2679 IN CONST INT32 CertIndex,
2680 OUT CONST UINT8 **Cert,
2681 OUT UINTN *CertLength
2682 )
2683 {
2684 CALL_CRYPTO_SERVICE (X509GetCertFromCertChain, (CertChain, CertChainLength, CertIndex, Cert, CertLength), FALSE);
2685 }
2686
2687 /**
2688 Retrieve the tag and length of the tag.
2689
2690 @param Ptr The position in the ASN.1 data
2691 @param End End of data
2692 @param Length The variable that will receive the length
2693 @param Tag The expected tag
2694
2695 @retval TRUE Get tag successful
2696 @retval FALSe Failed to get tag or tag not match
2697 **/
2698 BOOLEAN
2699 EFIAPI
2700 Asn1GetTag (
2701 IN OUT UINT8 **Ptr,
2702 IN CONST UINT8 *End,
2703 OUT UINTN *Length,
2704 IN UINT32 Tag
2705 )
2706 {
2707 CALL_CRYPTO_SERVICE (Asn1GetTag, (Ptr, End, Length, Tag), FALSE);
2708 }
2709
2710 /**
2711 Retrieve the basic constraints from one X.509 certificate.
2712
2713 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2714 @param[in] CertSize size of the X509 certificate in bytes.
2715 @param[out] BasicConstraints basic constraints bytes.
2716 @param[in, out] BasicConstraintsSize basic constraints buffer sizs in bytes.
2717
2718 @retval TRUE The basic constraints retrieve successfully.
2719 @retval FALSE If cert is NULL.
2720 If cert_size is NULL.
2721 If basic_constraints is not NULL and *basic_constraints_size is 0.
2722 If cert is invalid.
2723 @retval FALSE The required buffer size is small.
2724 The return buffer size is basic_constraints_size parameter.
2725 @retval FALSE If no Extension entry match oid.
2726 @retval FALSE The operation is not supported.
2727 **/
2728 BOOLEAN
2729 EFIAPI
2730 X509GetExtendedBasicConstraints (
2731 CONST UINT8 *Cert,
2732 UINTN CertSize,
2733 UINT8 *BasicConstraints,
2734 UINTN *BasicConstraintsSize
2735 )
2736 {
2737 CALL_CRYPTO_SERVICE (X509GetExtendedBasicConstraints, (Cert, CertSize, BasicConstraints, BasicConstraintsSize), FALSE);
2738 }
2739
2740 /**
2741 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2742 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2743
2744 If Password or Salt or OutKey is NULL, then return FALSE.
2745 If the hash algorithm could not be determined, then return FALSE.
2746 If this interface is not supported, then return FALSE.
2747
2748 @param[in] PasswordLength Length of input password in bytes.
2749 @param[in] Password Pointer to the array for the password.
2750 @param[in] SaltLength Size of the Salt in bytes.
2751 @param[in] Salt Pointer to the Salt.
2752 @param[in] IterationCount Number of iterations to perform. Its value should be
2753 greater than or equal to 1.
2754 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2755 NOTE: DigestSize will be used to determine the hash algorithm.
2756 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2757 @param[in] KeyLength Size of the derived key buffer in bytes.
2758 @param[out] OutKey Pointer to the output derived key buffer.
2759
2760 @retval TRUE A key was derived successfully.
2761 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2762 @retval FALSE The hash algorithm could not be determined from the digest size.
2763 @retval FALSE The key derivation operation failed.
2764 @retval FALSE This interface is not supported.
2765
2766 **/
2767 BOOLEAN
2768 EFIAPI
2769 Pkcs5HashPassword (
2770 IN UINTN PasswordLength,
2771 IN CONST CHAR8 *Password,
2772 IN UINTN SaltLength,
2773 IN CONST UINT8 *Salt,
2774 IN UINTN IterationCount,
2775 IN UINTN DigestSize,
2776 IN UINTN KeyLength,
2777 OUT UINT8 *OutKey
2778 )
2779 {
2780 CALL_CRYPTO_SERVICE (Pkcs5HashPassword, (PasswordLength, Password, SaltLength, Salt, IterationCount, DigestSize, KeyLength, OutKey), FALSE);
2781 }
2782
2783 /**
2784 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2785 encrypted message in a newly allocated buffer.
2786
2787 Things that can cause a failure include:
2788 - X509 key size does not match any known key size.
2789 - Fail to parse X509 certificate.
2790 - Fail to allocate an intermediate buffer.
2791 - Null pointer provided for a non-optional parameter.
2792 - Data size is too large for the provided key size (max size is a function of key size
2793 and hash digest size).
2794
2795 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2796 will be used to encrypt the data.
2797 @param[in] PublicKeySize Size of the X509 cert buffer.
2798 @param[in] InData Data to be encrypted.
2799 @param[in] InDataSize Size of the data buffer.
2800 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2801 to be used when initializing the PRNG. NULL otherwise.
2802 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2803 0 otherwise.
2804 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2805 message.
2806 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2807
2808 @retval TRUE Encryption was successful.
2809 @retval FALSE Encryption failed.
2810
2811 **/
2812 BOOLEAN
2813 EFIAPI
2814 Pkcs1v2Encrypt (
2815 IN CONST UINT8 *PublicKey,
2816 IN UINTN PublicKeySize,
2817 IN UINT8 *InData,
2818 IN UINTN InDataSize,
2819 IN CONST UINT8 *PrngSeed OPTIONAL,
2820 IN UINTN PrngSeedSize OPTIONAL,
2821 OUT UINT8 **EncryptedData,
2822 OUT UINTN *EncryptedDataSize
2823 )
2824 {
2825 CALL_CRYPTO_SERVICE (Pkcs1v2Encrypt, (PublicKey, PublicKeySize, InData, InDataSize, PrngSeed, PrngSeedSize, EncryptedData, EncryptedDataSize), FALSE);
2826 }
2827
2828 /**
2829 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2830 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2831 in a ContentInfo structure.
2832
2833 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2834 return FALSE. If P7Length overflow, then return FALSE.
2835 If this interface is not supported, then return FALSE.
2836
2837 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2838 @param[in] P7Length Length of the PKCS#7 message in bytes.
2839 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2840 It's caller's responsibility to free the buffer with
2841 Pkcs7FreeSigners().
2842 This data structure is EFI_CERT_STACK type.
2843 @param[out] StackLength Length of signer's certificates in bytes.
2844 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2845 It's caller's responsibility to free the buffer with
2846 Pkcs7FreeSigners().
2847 @param[out] CertLength Length of the trusted certificate in bytes.
2848
2849 @retval TRUE The operation is finished successfully.
2850 @retval FALSE Error occurs during the operation.
2851 @retval FALSE This interface is not supported.
2852
2853 **/
2854 BOOLEAN
2855 EFIAPI
2856 Pkcs7GetSigners (
2857 IN CONST UINT8 *P7Data,
2858 IN UINTN P7Length,
2859 OUT UINT8 **CertStack,
2860 OUT UINTN *StackLength,
2861 OUT UINT8 **TrustedCert,
2862 OUT UINTN *CertLength
2863 )
2864 {
2865 CALL_CRYPTO_SERVICE (Pkcs7GetSigners, (P7Data, P7Length, CertStack, StackLength, TrustedCert, CertLength), FALSE);
2866 }
2867
2868 /**
2869 Wrap function to use free() to free allocated memory for certificates.
2870
2871 If this interface is not supported, then ASSERT().
2872
2873 @param[in] Certs Pointer to the certificates to be freed.
2874
2875 **/
2876 VOID
2877 EFIAPI
2878 Pkcs7FreeSigners (
2879 IN UINT8 *Certs
2880 )
2881 {
2882 CALL_VOID_CRYPTO_SERVICE (Pkcs7FreeSigners, (Certs));
2883 }
2884
2885 /**
2886 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2887 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2888 unchained to the signer's certificates.
2889 The input signed data could be wrapped in a ContentInfo structure.
2890
2891 @param[in] P7Data Pointer to the PKCS#7 message.
2892 @param[in] P7Length Length of the PKCS#7 message in bytes.
2893 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2894 certificate. It's caller's responsibility to free the buffer
2895 with Pkcs7FreeSigners().
2896 This data structure is EFI_CERT_STACK type.
2897 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2898 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2899 responsibility to free the buffer with Pkcs7FreeSigners().
2900 This data structure is EFI_CERT_STACK type.
2901 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2902
2903 @retval TRUE The operation is finished successfully.
2904 @retval FALSE Error occurs during the operation.
2905
2906 **/
2907 BOOLEAN
2908 EFIAPI
2909 Pkcs7GetCertificatesList (
2910 IN CONST UINT8 *P7Data,
2911 IN UINTN P7Length,
2912 OUT UINT8 **SignerChainCerts,
2913 OUT UINTN *ChainLength,
2914 OUT UINT8 **UnchainCerts,
2915 OUT UINTN *UnchainLength
2916 )
2917 {
2918 CALL_CRYPTO_SERVICE (Pkcs7GetCertificatesList, (P7Data, P7Length, SignerChainCerts, ChainLength, UnchainCerts, UnchainLength), FALSE);
2919 }
2920
2921 /**
2922 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2923 Syntax Standard, version 1.5". This interface is only intended to be used for
2924 application to perform PKCS#7 functionality validation.
2925
2926 If this interface is not supported, then return FALSE.
2927
2928 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2929 data signing.
2930 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2931 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2932 key data.
2933 @param[in] InData Pointer to the content to be signed.
2934 @param[in] InDataSize Size of InData in bytes.
2935 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2936 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2937 include in the PKCS#7 signedData (e.g. any intermediate
2938 CAs in the chain).
2939 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2940 responsibility to free the buffer with FreePool().
2941 @param[out] SignedDataSize Size of SignedData in bytes.
2942
2943 @retval TRUE PKCS#7 data signing succeeded.
2944 @retval FALSE PKCS#7 data signing failed.
2945 @retval FALSE This interface is not supported.
2946
2947 **/
2948 BOOLEAN
2949 EFIAPI
2950 Pkcs7Sign (
2951 IN CONST UINT8 *PrivateKey,
2952 IN UINTN PrivateKeySize,
2953 IN CONST UINT8 *KeyPassword,
2954 IN UINT8 *InData,
2955 IN UINTN InDataSize,
2956 IN UINT8 *SignCert,
2957 IN UINT8 *OtherCerts OPTIONAL,
2958 OUT UINT8 **SignedData,
2959 OUT UINTN *SignedDataSize
2960 )
2961 {
2962 CALL_CRYPTO_SERVICE (Pkcs7Sign, (PrivateKey, PrivateKeySize, KeyPassword, InData, InDataSize, SignCert, OtherCerts, SignedData, SignedDataSize), FALSE);
2963 }
2964
2965 /**
2966 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2967 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2968 in a ContentInfo structure.
2969
2970 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2971 If P7Length, CertLength or DataLength overflow, then return FALSE.
2972 If this interface is not supported, then return FALSE.
2973
2974 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2975 @param[in] P7Length Length of the PKCS#7 message in bytes.
2976 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2977 is used for certificate chain verification.
2978 @param[in] CertLength Length of the trusted certificate in bytes.
2979 @param[in] InData Pointer to the content to be verified.
2980 @param[in] DataLength Length of InData in bytes.
2981
2982 @retval TRUE The specified PKCS#7 signed data is valid.
2983 @retval FALSE Invalid PKCS#7 signed data.
2984 @retval FALSE This interface is not supported.
2985
2986 **/
2987 BOOLEAN
2988 EFIAPI
2989 Pkcs7Verify (
2990 IN CONST UINT8 *P7Data,
2991 IN UINTN P7Length,
2992 IN CONST UINT8 *TrustedCert,
2993 IN UINTN CertLength,
2994 IN CONST UINT8 *InData,
2995 IN UINTN DataLength
2996 )
2997 {
2998 CALL_CRYPTO_SERVICE (Pkcs7Verify, (P7Data, P7Length, TrustedCert, CertLength, InData, DataLength), FALSE);
2999 }
3000
3001 /**
3002 This function receives a PKCS7 formatted signature, and then verifies that
3003 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
3004 leaf signing certificate.
3005 Note that this function does not validate the certificate chain.
3006
3007 Applications for custom EKU's are quite flexible. For example, a policy EKU
3008 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
3009 certificate issued might also contain this EKU, thus constraining the
3010 sub-ordinate certificate. Other applications might allow a certificate
3011 embedded in a device to specify that other Object Identifiers (OIDs) are
3012 present which contains binary data specifying custom capabilities that
3013 the device is able to do.
3014
3015 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
3016 containing the content block with both the signature,
3017 the signer's certificate, and any necessary intermediate
3018 certificates.
3019 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
3020 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
3021 required EKUs that must be present in the signature.
3022 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
3023 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
3024 must be present in the leaf signer. If it is
3025 FALSE, then we will succeed if we find any
3026 of the specified EKU's.
3027
3028 @retval EFI_SUCCESS The required EKUs were found in the signature.
3029 @retval EFI_INVALID_PARAMETER A parameter was invalid.
3030 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
3031
3032 **/
3033 RETURN_STATUS
3034 EFIAPI
3035 VerifyEKUsInPkcs7Signature (
3036 IN CONST UINT8 *Pkcs7Signature,
3037 IN CONST UINT32 SignatureSize,
3038 IN CONST CHAR8 *RequiredEKUs[],
3039 IN CONST UINT32 RequiredEKUsSize,
3040 IN BOOLEAN RequireAllPresent
3041 )
3042 {
3043 CALL_CRYPTO_SERVICE (VerifyEKUsInPkcs7Signature, (Pkcs7Signature, SignatureSize, RequiredEKUs, RequiredEKUsSize, RequireAllPresent), FALSE);
3044 }
3045
3046 /**
3047 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
3048 data could be wrapped in a ContentInfo structure.
3049
3050 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
3051 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
3052
3053 Caution: This function may receive untrusted input. So this function will do
3054 basic check for PKCS#7 data structure.
3055
3056 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
3057 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
3058 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
3059 It's caller's responsibility to free the buffer with FreePool().
3060 @param[out] ContentSize The size of the extracted content in bytes.
3061
3062 @retval TRUE The P7Data was correctly formatted for processing.
3063 @retval FALSE The P7Data was not correctly formatted for processing.
3064
3065 **/
3066 BOOLEAN
3067 EFIAPI
3068 Pkcs7GetAttachedContent (
3069 IN CONST UINT8 *P7Data,
3070 IN UINTN P7Length,
3071 OUT VOID **Content,
3072 OUT UINTN *ContentSize
3073 )
3074 {
3075 CALL_CRYPTO_SERVICE (Pkcs7GetAttachedContent, (P7Data, P7Length, Content, ContentSize), FALSE);
3076 }
3077
3078 /**
3079 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
3080 Authenticode Portable Executable Signature Format".
3081
3082 If AuthData is NULL, then return FALSE.
3083 If ImageHash is NULL, then return FALSE.
3084 If this interface is not supported, then return FALSE.
3085
3086 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
3087 PE/COFF image to be verified.
3088 @param[in] DataSize Size of the Authenticode Signature in bytes.
3089 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
3090 is used for certificate chain verification.
3091 @param[in] CertSize Size of the trusted certificate in bytes.
3092 @param[in] ImageHash Pointer to the original image file hash value. The procedure
3093 for calculating the image hash value is described in Authenticode
3094 specification.
3095 @param[in] HashSize Size of Image hash value in bytes.
3096
3097 @retval TRUE The specified Authenticode Signature is valid.
3098 @retval FALSE Invalid Authenticode Signature.
3099 @retval FALSE This interface is not supported.
3100
3101 **/
3102 BOOLEAN
3103 EFIAPI
3104 AuthenticodeVerify (
3105 IN CONST UINT8 *AuthData,
3106 IN UINTN DataSize,
3107 IN CONST UINT8 *TrustedCert,
3108 IN UINTN CertSize,
3109 IN CONST UINT8 *ImageHash,
3110 IN UINTN HashSize
3111 )
3112 {
3113 CALL_CRYPTO_SERVICE (AuthenticodeVerify, (AuthData, DataSize, TrustedCert, CertSize, ImageHash, HashSize), FALSE);
3114 }
3115
3116 /**
3117 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
3118 signature.
3119
3120 If AuthData is NULL, then return FALSE.
3121 If this interface is not supported, then return FALSE.
3122
3123 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
3124 PE/COFF image to be verified.
3125 @param[in] DataSize Size of the Authenticode Signature in bytes.
3126 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
3127 is used for TSA certificate chain verification.
3128 @param[in] CertSize Size of the trusted certificate in bytes.
3129 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
3130 signature is valid.
3131
3132 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
3133 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
3134
3135 **/
3136 BOOLEAN
3137 EFIAPI
3138 ImageTimestampVerify (
3139 IN CONST UINT8 *AuthData,
3140 IN UINTN DataSize,
3141 IN CONST UINT8 *TsaCert,
3142 IN UINTN CertSize,
3143 OUT EFI_TIME *SigningTime
3144 )
3145 {
3146 CALL_CRYPTO_SERVICE (ImageTimestampVerify, (AuthData, DataSize, TsaCert, CertSize, SigningTime), FALSE);
3147 }
3148
3149 // =====================================================================================
3150 // DH Key Exchange Primitive
3151 // =====================================================================================
3152
3153 /**
3154 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
3155
3156 @return Pointer to the Diffie-Hellman Context that has been initialized.
3157 If the allocations fails, DhNew() returns NULL.
3158 If the interface is not supported, DhNew() returns NULL.
3159
3160 **/
3161 VOID *
3162 EFIAPI
3163 DhNew (
3164 VOID
3165 )
3166 {
3167 CALL_CRYPTO_SERVICE (DhNew, (), NULL);
3168 }
3169
3170 /**
3171 Release the specified DH context.
3172
3173 If the interface is not supported, then ASSERT().
3174
3175 @param[in] DhContext Pointer to the DH context to be released.
3176
3177 **/
3178 VOID
3179 EFIAPI
3180 DhFree (
3181 IN VOID *DhContext
3182 )
3183 {
3184 CALL_VOID_CRYPTO_SERVICE (DhFree, (DhContext));
3185 }
3186
3187 /**
3188 Generates DH parameter.
3189
3190 Given generator g, and length of prime number p in bits, this function generates p,
3191 and sets DH context according to value of g and p.
3192
3193 Before this function can be invoked, pseudorandom number generator must be correctly
3194 initialized by RandomSeed().
3195
3196 If DhContext is NULL, then return FALSE.
3197 If Prime is NULL, then return FALSE.
3198 If this interface is not supported, then return FALSE.
3199
3200 @param[in, out] DhContext Pointer to the DH context.
3201 @param[in] Generator Value of generator.
3202 @param[in] PrimeLength Length in bits of prime to be generated.
3203 @param[out] Prime Pointer to the buffer to receive the generated prime number.
3204
3205 @retval TRUE DH parameter generation succeeded.
3206 @retval FALSE Value of Generator is not supported.
3207 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
3208 @retval FALSE This interface is not supported.
3209
3210 **/
3211 BOOLEAN
3212 EFIAPI
3213 DhGenerateParameter (
3214 IN OUT VOID *DhContext,
3215 IN UINTN Generator,
3216 IN UINTN PrimeLength,
3217 OUT UINT8 *Prime
3218 )
3219 {
3220 CALL_CRYPTO_SERVICE (DhGenerateParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);
3221 }
3222
3223 /**
3224 Sets generator and prime parameters for DH.
3225
3226 Given generator g, and prime number p, this function and sets DH
3227 context accordingly.
3228
3229 If DhContext is NULL, then return FALSE.
3230 If Prime is NULL, then return FALSE.
3231 If this interface is not supported, then return FALSE.
3232
3233 @param[in, out] DhContext Pointer to the DH context.
3234 @param[in] Generator Value of generator.
3235 @param[in] PrimeLength Length in bits of prime to be generated.
3236 @param[in] Prime Pointer to the prime number.
3237
3238 @retval TRUE DH parameter setting succeeded.
3239 @retval FALSE Value of Generator is not supported.
3240 @retval FALSE Value of Generator is not suitable for the Prime.
3241 @retval FALSE Value of Prime is not a prime number.
3242 @retval FALSE Value of Prime is not a safe prime number.
3243 @retval FALSE This interface is not supported.
3244
3245 **/
3246 BOOLEAN
3247 EFIAPI
3248 DhSetParameter (
3249 IN OUT VOID *DhContext,
3250 IN UINTN Generator,
3251 IN UINTN PrimeLength,
3252 IN CONST UINT8 *Prime
3253 )
3254 {
3255 CALL_CRYPTO_SERVICE (DhSetParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);
3256 }
3257
3258 /**
3259 Generates DH public key.
3260
3261 This function generates random secret exponent, and computes the public key, which is
3262 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
3263 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
3264 PublicKeySize is set to the required buffer size to obtain the public key.
3265
3266 If DhContext is NULL, then return FALSE.
3267 If PublicKeySize is NULL, then return FALSE.
3268 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
3269 If this interface is not supported, then return FALSE.
3270
3271 @param[in, out] DhContext Pointer to the DH context.
3272 @param[out] PublicKey Pointer to the buffer to receive generated public key.
3273 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
3274 On output, the size of data returned in PublicKey buffer in bytes.
3275
3276 @retval TRUE DH public key generation succeeded.
3277 @retval FALSE DH public key generation failed.
3278 @retval FALSE PublicKeySize is not large enough.
3279 @retval FALSE This interface is not supported.
3280
3281 **/
3282 BOOLEAN
3283 EFIAPI
3284 DhGenerateKey (
3285 IN OUT VOID *DhContext,
3286 OUT UINT8 *PublicKey,
3287 IN OUT UINTN *PublicKeySize
3288 )
3289 {
3290 CALL_CRYPTO_SERVICE (DhGenerateKey, (DhContext, PublicKey, PublicKeySize), FALSE);
3291 }
3292
3293 /**
3294 Computes exchanged common key.
3295
3296 Given peer's public key, this function computes the exchanged common key, based on its own
3297 context including value of prime modulus and random secret exponent.
3298
3299 If DhContext is NULL, then return FALSE.
3300 If PeerPublicKey is NULL, then return FALSE.
3301 If KeySize is NULL, then return FALSE.
3302 If Key is NULL, then return FALSE.
3303 If KeySize is not large enough, then return FALSE.
3304 If this interface is not supported, then return FALSE.
3305
3306 @param[in, out] DhContext Pointer to the DH context.
3307 @param[in] PeerPublicKey Pointer to the peer's public key.
3308 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
3309 @param[out] Key Pointer to the buffer to receive generated key.
3310 @param[in, out] KeySize On input, the size of Key buffer in bytes.
3311 On output, the size of data returned in Key buffer in bytes.
3312
3313 @retval TRUE DH exchanged key generation succeeded.
3314 @retval FALSE DH exchanged key generation failed.
3315 @retval FALSE KeySize is not large enough.
3316 @retval FALSE This interface is not supported.
3317
3318 **/
3319 BOOLEAN
3320 EFIAPI
3321 DhComputeKey (
3322 IN OUT VOID *DhContext,
3323 IN CONST UINT8 *PeerPublicKey,
3324 IN UINTN PeerPublicKeySize,
3325 OUT UINT8 *Key,
3326 IN OUT UINTN *KeySize
3327 )
3328 {
3329 CALL_CRYPTO_SERVICE (DhComputeKey, (DhContext, PeerPublicKey, PeerPublicKeySize, Key, KeySize), FALSE);
3330 }
3331
3332 // =====================================================================================
3333 // Pseudo-Random Generation Primitive
3334 // =====================================================================================
3335
3336 /**
3337 Sets up the seed value for the pseudorandom number generator.
3338
3339 This function sets up the seed value for the pseudorandom number generator.
3340 If Seed is not NULL, then the seed passed in is used.
3341 If Seed is NULL, then default seed is used.
3342 If this interface is not supported, then return FALSE.
3343
3344 @param[in] Seed Pointer to seed value.
3345 If NULL, default seed is used.
3346 @param[in] SeedSize Size of seed value.
3347 If Seed is NULL, this parameter is ignored.
3348
3349 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
3350 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
3351 @retval FALSE This interface is not supported.
3352
3353 **/
3354 BOOLEAN
3355 EFIAPI
3356 RandomSeed (
3357 IN CONST UINT8 *Seed OPTIONAL,
3358 IN UINTN SeedSize
3359 )
3360 {
3361 CALL_CRYPTO_SERVICE (RandomSeed, (Seed, SeedSize), FALSE);
3362 }
3363
3364 /**
3365 Generates a pseudorandom byte stream of the specified size.
3366
3367 If Output is NULL, then return FALSE.
3368 If this interface is not supported, then return FALSE.
3369
3370 @param[out] Output Pointer to buffer to receive random value.
3371 @param[in] Size Size of random bytes to generate.
3372
3373 @retval TRUE Pseudorandom byte stream generated successfully.
3374 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
3375 @retval FALSE This interface is not supported.
3376
3377 **/
3378 BOOLEAN
3379 EFIAPI
3380 RandomBytes (
3381 OUT UINT8 *Output,
3382 IN UINTN Size
3383 )
3384 {
3385 CALL_CRYPTO_SERVICE (RandomBytes, (Output, Size), FALSE);
3386 }
3387
3388 // =====================================================================================
3389 // Key Derivation Function Primitive
3390 // =====================================================================================
3391
3392 /**
3393 Derive key data using HMAC-SHA256 based KDF.
3394
3395 @param[in] Key Pointer to the user-supplied key.
3396 @param[in] KeySize Key size in bytes.
3397 @param[in] Salt Pointer to the salt(non-secret) value.
3398 @param[in] SaltSize Salt size in bytes.
3399 @param[in] Info Pointer to the application specific info.
3400 @param[in] InfoSize Info size in bytes.
3401 @param[out] Out Pointer to buffer to receive hkdf value.
3402 @param[in] OutSize Size of hkdf bytes to generate.
3403
3404 @retval TRUE Hkdf generated successfully.
3405 @retval FALSE Hkdf generation failed.
3406
3407 **/
3408 BOOLEAN
3409 EFIAPI
3410 HkdfSha256ExtractAndExpand (
3411 IN CONST UINT8 *Key,
3412 IN UINTN KeySize,
3413 IN CONST UINT8 *Salt,
3414 IN UINTN SaltSize,
3415 IN CONST UINT8 *Info,
3416 IN UINTN InfoSize,
3417 OUT UINT8 *Out,
3418 IN UINTN OutSize
3419 )
3420 {
3421 CALL_CRYPTO_SERVICE (HkdfSha256ExtractAndExpand, (Key, KeySize, Salt, SaltSize, Info, InfoSize, Out, OutSize), FALSE);
3422 }
3423
3424 /**
3425 Derive SHA256 HMAC-based Extract key Derivation Function (HKDF).
3426
3427 @param[in] Key Pointer to the user-supplied key.
3428 @param[in] KeySize key size in bytes.
3429 @param[in] Salt Pointer to the salt(non-secret) value.
3430 @param[in] SaltSize salt size in bytes.
3431 @param[out] PrkOut Pointer to buffer to receive hkdf value.
3432 @param[in] PrkOutSize size of hkdf bytes to generate.
3433
3434 @retval true Hkdf generated successfully.
3435 @retval false Hkdf generation failed.
3436
3437 **/
3438 BOOLEAN
3439 EFIAPI
3440 HkdfSha256Extract (
3441 IN CONST UINT8 *Key,
3442 IN UINTN KeySize,
3443 IN CONST UINT8 *Salt,
3444 IN UINTN SaltSize,
3445 OUT UINT8 *PrkOut,
3446 UINTN PrkOutSize
3447 )
3448 {
3449 CALL_CRYPTO_SERVICE (HkdfSha256Extract, (Key, KeySize, Salt, SaltSize, PrkOut, PrkOutSize), FALSE);
3450 }
3451
3452 /**
3453 Derive SHA256 HMAC-based Expand Key Derivation Function (HKDF).
3454
3455 @param[in] Prk Pointer to the user-supplied key.
3456 @param[in] PrkSize Key size in bytes.
3457 @param[in] Info Pointer to the application specific info.
3458 @param[in] InfoSize Info size in bytes.
3459 @param[out] Out Pointer to buffer to receive hkdf value.
3460 @param[in] OutSize Size of hkdf bytes to generate.
3461
3462 @retval TRUE Hkdf generated successfully.
3463 @retval FALSE Hkdf generation failed.
3464
3465 **/
3466 BOOLEAN
3467 EFIAPI
3468 HkdfSha256Expand (
3469 IN CONST UINT8 *Prk,
3470 IN UINTN PrkSize,
3471 IN CONST UINT8 *Info,
3472 IN UINTN InfoSize,
3473 OUT UINT8 *Out,
3474 IN UINTN OutSize
3475 )
3476 {
3477 CALL_CRYPTO_SERVICE (HkdfSha256Expand, (Prk, PrkSize, Info, InfoSize, Out, OutSize), FALSE);
3478 }
3479
3480 /**
3481 Derive SHA384 HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
3482
3483 @param[in] Key Pointer to the user-supplied key.
3484 @param[in] KeySize Key size in bytes.
3485 @param[in] Salt Pointer to the salt(non-secret) value.
3486 @param[in] SaltSize Salt size in bytes.
3487 @param[in] Info Pointer to the application specific info.
3488 @param[in] InfoSize Info size in bytes.
3489 @param[out] Out Pointer to buffer to receive hkdf value.
3490 @param[in] OutSize Size of hkdf bytes to generate.
3491
3492 @retval TRUE Hkdf generated successfully.
3493 @retval FALSE Hkdf generation failed.
3494
3495 **/
3496 BOOLEAN
3497 EFIAPI
3498 HkdfSha384ExtractAndExpand (
3499 IN CONST UINT8 *Key,
3500 IN UINTN KeySize,
3501 IN CONST UINT8 *Salt,
3502 IN UINTN SaltSize,
3503 IN CONST UINT8 *Info,
3504 IN UINTN InfoSize,
3505 OUT UINT8 *Out,
3506 IN UINTN OutSize
3507 )
3508 {
3509 CALL_CRYPTO_SERVICE (HkdfSha384ExtractAndExpand, (Key, KeySize, Salt, SaltSize, Info, InfoSize, Out, OutSize), FALSE);
3510 }
3511
3512 /**
3513 Derive SHA384 HMAC-based Extract key Derivation Function (HKDF).
3514
3515 @param[in] Key Pointer to the user-supplied key.
3516 @param[in] KeySize key size in bytes.
3517 @param[in] Salt Pointer to the salt(non-secret) value.
3518 @param[in] SaltSize salt size in bytes.
3519 @param[out] PrkOut Pointer to buffer to receive hkdf value.
3520 @param[in] PrkOutSize size of hkdf bytes to generate.
3521
3522 @retval true Hkdf generated successfully.
3523 @retval false Hkdf generation failed.
3524
3525 **/
3526 BOOLEAN
3527 EFIAPI
3528 HkdfSha384Extract (
3529 IN CONST UINT8 *Key,
3530 IN UINTN KeySize,
3531 IN CONST UINT8 *Salt,
3532 IN UINTN SaltSize,
3533 OUT UINT8 *PrkOut,
3534 UINTN PrkOutSize
3535 )
3536 {
3537 CALL_CRYPTO_SERVICE (HkdfSha384Extract, (Key, KeySize, Salt, SaltSize, PrkOut, PrkOutSize), FALSE);
3538 }
3539
3540 /**
3541 Derive SHA384 HMAC-based Expand Key Derivation Function (HKDF).
3542
3543 @param[in] Prk Pointer to the user-supplied key.
3544 @param[in] PrkSize Key size in bytes.
3545 @param[in] Info Pointer to the application specific info.
3546 @param[in] InfoSize Info size in bytes.
3547 @param[out] Out Pointer to buffer to receive hkdf value.
3548 @param[in] OutSize Size of hkdf bytes to generate.
3549
3550 @retval TRUE Hkdf generated successfully.
3551 @retval FALSE Hkdf generation failed.
3552
3553 **/
3554 BOOLEAN
3555 EFIAPI
3556 HkdfSha384Expand (
3557 IN CONST UINT8 *Prk,
3558 IN UINTN PrkSize,
3559 IN CONST UINT8 *Info,
3560 IN UINTN InfoSize,
3561 OUT UINT8 *Out,
3562 IN UINTN OutSize
3563 )
3564 {
3565 CALL_CRYPTO_SERVICE (HkdfSha384Expand, (Prk, PrkSize, Info, InfoSize, Out, OutSize), FALSE);
3566 }
3567
3568 /**
3569 Initializes the OpenSSL library.
3570
3571 This function registers ciphers and digests used directly and indirectly
3572 by SSL/TLS, and initializes the readable error messages.
3573 This function must be called before any other action takes places.
3574
3575 @retval TRUE The OpenSSL library has been initialized.
3576 @retval FALSE Failed to initialize the OpenSSL library.
3577
3578 **/
3579 BOOLEAN
3580 EFIAPI
3581 TlsInitialize (
3582 VOID
3583 )
3584 {
3585 CALL_CRYPTO_SERVICE (TlsInitialize, (), FALSE);
3586 }
3587
3588 /**
3589 Free an allocated SSL_CTX object.
3590
3591 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
3592
3593 **/
3594 VOID
3595 EFIAPI
3596 TlsCtxFree (
3597 IN VOID *TlsCtx
3598 )
3599 {
3600 CALL_VOID_CRYPTO_SERVICE (TlsCtxFree, (TlsCtx));
3601 }
3602
3603 /**
3604 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
3605 connections.
3606
3607 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3608 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3609
3610 @return Pointer to an allocated SSL_CTX object.
3611 If the creation failed, TlsCtxNew() returns NULL.
3612
3613 **/
3614 VOID *
3615 EFIAPI
3616 TlsCtxNew (
3617 IN UINT8 MajorVer,
3618 IN UINT8 MinorVer
3619 )
3620 {
3621 CALL_CRYPTO_SERVICE (TlsCtxNew, (MajorVer, MinorVer), NULL);
3622 }
3623
3624 /**
3625 Free an allocated TLS object.
3626
3627 This function removes the TLS object pointed to by Tls and frees up the
3628 allocated memory. If Tls is NULL, nothing is done.
3629
3630 @param[in] Tls Pointer to the TLS object to be freed.
3631
3632 **/
3633 VOID
3634 EFIAPI
3635 TlsFree (
3636 IN VOID *Tls
3637 )
3638 {
3639 CALL_VOID_CRYPTO_SERVICE (TlsFree, (Tls));
3640 }
3641
3642 /**
3643 Create a new TLS object for a connection.
3644
3645 This function creates a new TLS object for a connection. The new object
3646 inherits the setting of the underlying context TlsCtx: connection method,
3647 options, verification setting.
3648
3649 @param[in] TlsCtx Pointer to the SSL_CTX object.
3650
3651 @return Pointer to an allocated SSL object.
3652 If the creation failed, TlsNew() returns NULL.
3653
3654 **/
3655 VOID *
3656 EFIAPI
3657 TlsNew (
3658 IN VOID *TlsCtx
3659 )
3660 {
3661 CALL_CRYPTO_SERVICE (TlsNew, (TlsCtx), NULL);
3662 }
3663
3664 /**
3665 Checks if the TLS handshake was done.
3666
3667 This function will check if the specified TLS handshake was done.
3668
3669 @param[in] Tls Pointer to the TLS object for handshake state checking.
3670
3671 @retval TRUE The TLS handshake was done.
3672 @retval FALSE The TLS handshake was not done.
3673
3674 **/
3675 BOOLEAN
3676 EFIAPI
3677 TlsInHandshake (
3678 IN VOID *Tls
3679 )
3680 {
3681 CALL_CRYPTO_SERVICE (TlsInHandshake, (Tls), FALSE);
3682 }
3683
3684 /**
3685 Perform a TLS/SSL handshake.
3686
3687 This function will perform a TLS/SSL handshake.
3688
3689 @param[in] Tls Pointer to the TLS object for handshake operation.
3690 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
3691 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3692 Handshake packet.
3693 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3694 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3695 the buffer size provided by the caller. On output, it
3696 is the buffer size in fact needed to contain the
3697 packet.
3698
3699 @retval EFI_SUCCESS The required TLS packet is built successfully.
3700 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3701 Tls is NULL.
3702 BufferIn is NULL but BufferInSize is NOT 0.
3703 BufferInSize is 0 but BufferIn is NOT NULL.
3704 BufferOutSize is NULL.
3705 BufferOut is NULL if *BufferOutSize is not zero.
3706 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3707 @retval EFI_ABORTED Something wrong during handshake.
3708
3709 **/
3710 EFI_STATUS
3711 EFIAPI
3712 TlsDoHandshake (
3713 IN VOID *Tls,
3714 IN UINT8 *BufferIn OPTIONAL,
3715 IN UINTN BufferInSize OPTIONAL,
3716 OUT UINT8 *BufferOut OPTIONAL,
3717 IN OUT UINTN *BufferOutSize
3718 )
3719 {
3720 CALL_CRYPTO_SERVICE (TlsDoHandshake, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);
3721 }
3722
3723 /**
3724 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
3725 TLS session has errors and the response packet needs to be Alert message based on error type.
3726
3727 @param[in] Tls Pointer to the TLS object for state checking.
3728 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
3729 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3730 Alert packet.
3731 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3732 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3733 the buffer size provided by the caller. On output, it
3734 is the buffer size in fact needed to contain the
3735 packet.
3736
3737 @retval EFI_SUCCESS The required TLS packet is built successfully.
3738 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3739 Tls is NULL.
3740 BufferIn is NULL but BufferInSize is NOT 0.
3741 BufferInSize is 0 but BufferIn is NOT NULL.
3742 BufferOutSize is NULL.
3743 BufferOut is NULL if *BufferOutSize is not zero.
3744 @retval EFI_ABORTED An error occurred.
3745 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3746
3747 **/
3748 EFI_STATUS
3749 EFIAPI
3750 TlsHandleAlert (
3751 IN VOID *Tls,
3752 IN UINT8 *BufferIn OPTIONAL,
3753 IN UINTN BufferInSize OPTIONAL,
3754 OUT UINT8 *BufferOut OPTIONAL,
3755 IN OUT UINTN *BufferOutSize
3756 )
3757 {
3758 CALL_CRYPTO_SERVICE (TlsHandleAlert, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);
3759 }
3760
3761 /**
3762 Build the CloseNotify packet.
3763
3764 @param[in] Tls Pointer to the TLS object for state checking.
3765 @param[in, out] Buffer Pointer to the buffer to hold the built packet.
3766 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
3767 the buffer size provided by the caller. On output, it
3768 is the buffer size in fact needed to contain the
3769 packet.
3770
3771 @retval EFI_SUCCESS The required TLS packet is built successfully.
3772 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3773 Tls is NULL.
3774 BufferSize is NULL.
3775 Buffer is NULL if *BufferSize is not zero.
3776 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
3777
3778 **/
3779 EFI_STATUS
3780 EFIAPI
3781 TlsCloseNotify (
3782 IN VOID *Tls,
3783 IN OUT UINT8 *Buffer,
3784 IN OUT UINTN *BufferSize
3785 )
3786 {
3787 CALL_CRYPTO_SERVICE (TlsCloseNotify, (Tls, Buffer, BufferSize), EFI_UNSUPPORTED);
3788 }
3789
3790 /**
3791 Attempts to read bytes from one TLS object and places the data in Buffer.
3792
3793 This function will attempt to read BufferSize bytes from the TLS object
3794 and places the data in Buffer.
3795
3796 @param[in] Tls Pointer to the TLS object.
3797 @param[in,out] Buffer Pointer to the buffer to store the data.
3798 @param[in] BufferSize The size of Buffer in bytes.
3799
3800 @retval >0 The amount of data successfully read from the TLS object.
3801 @retval <=0 No data was successfully read.
3802
3803 **/
3804 INTN
3805 EFIAPI
3806 TlsCtrlTrafficOut (
3807 IN VOID *Tls,
3808 IN OUT VOID *Buffer,
3809 IN UINTN BufferSize
3810 )
3811 {
3812 CALL_CRYPTO_SERVICE (TlsCtrlTrafficOut, (Tls, Buffer, BufferSize), 0);
3813 }
3814
3815 /**
3816 Attempts to write data from the buffer to TLS object.
3817
3818 This function will attempt to write BufferSize bytes data from the Buffer
3819 to the TLS object.
3820
3821 @param[in] Tls Pointer to the TLS object.
3822 @param[in] Buffer Pointer to the data buffer.
3823 @param[in] BufferSize The size of Buffer in bytes.
3824
3825 @retval >0 The amount of data successfully written to the TLS object.
3826 @retval <=0 No data was successfully written.
3827
3828 **/
3829 INTN
3830 EFIAPI
3831 TlsCtrlTrafficIn (
3832 IN VOID *Tls,
3833 IN VOID *Buffer,
3834 IN UINTN BufferSize
3835 )
3836 {
3837 CALL_CRYPTO_SERVICE (TlsCtrlTrafficIn, (Tls, Buffer, BufferSize), 0);
3838 }
3839
3840 /**
3841 Attempts to read bytes from the specified TLS connection into the buffer.
3842
3843 This function tries to read BufferSize bytes data from the specified TLS
3844 connection into the Buffer.
3845
3846 @param[in] Tls Pointer to the TLS connection for data reading.
3847 @param[in,out] Buffer Pointer to the data buffer.
3848 @param[in] BufferSize The size of Buffer in bytes.
3849
3850 @retval >0 The read operation was successful, and return value is the
3851 number of bytes actually read from the TLS connection.
3852 @retval <=0 The read operation was not successful.
3853
3854 **/
3855 INTN
3856 EFIAPI
3857 TlsRead (
3858 IN VOID *Tls,
3859 IN OUT VOID *Buffer,
3860 IN UINTN BufferSize
3861 )
3862 {
3863 CALL_CRYPTO_SERVICE (TlsRead, (Tls, Buffer, BufferSize), 0);
3864 }
3865
3866 /**
3867 Attempts to write data to a TLS connection.
3868
3869 This function tries to write BufferSize bytes data from the Buffer into the
3870 specified TLS connection.
3871
3872 @param[in] Tls Pointer to the TLS connection for data writing.
3873 @param[in] Buffer Pointer to the data buffer.
3874 @param[in] BufferSize The size of Buffer in bytes.
3875
3876 @retval >0 The write operation was successful, and return value is the
3877 number of bytes actually written to the TLS connection.
3878 @retval <=0 The write operation was not successful.
3879
3880 **/
3881 INTN
3882 EFIAPI
3883 TlsWrite (
3884 IN VOID *Tls,
3885 IN VOID *Buffer,
3886 IN UINTN BufferSize
3887 )
3888 {
3889 CALL_CRYPTO_SERVICE (TlsWrite, (Tls, Buffer, BufferSize), 0);
3890 }
3891
3892 /**
3893 Shutdown a TLS connection.
3894
3895 Shutdown the TLS connection without releasing the resources, meaning a new
3896 connection can be started without calling TlsNew() and without setting
3897 certificates etc.
3898
3899 @param[in] Tls Pointer to the TLS object to shutdown.
3900
3901 @retval EFI_SUCCESS The TLS is shutdown successfully.
3902 @retval EFI_INVALID_PARAMETER Tls is NULL.
3903 @retval EFI_PROTOCOL_ERROR Some other error occurred.
3904 **/
3905 EFI_STATUS
3906 EFIAPI
3907 TlsShutdown (
3908 IN VOID *Tls
3909 )
3910 {
3911 CALL_CRYPTO_SERVICE (TlsShutdown, (Tls), EFI_UNSUPPORTED);
3912 }
3913
3914 /**
3915 Set a new TLS/SSL method for a particular TLS object.
3916
3917 This function sets a new TLS/SSL method for a particular TLS object.
3918
3919 @param[in] Tls Pointer to a TLS object.
3920 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3921 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3922
3923 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
3924 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3925 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
3926
3927 **/
3928 EFI_STATUS
3929 EFIAPI
3930 TlsSetVersion (
3931 IN VOID *Tls,
3932 IN UINT8 MajorVer,
3933 IN UINT8 MinorVer
3934 )
3935 {
3936 CALL_CRYPTO_SERVICE (TlsSetVersion, (Tls, MajorVer, MinorVer), EFI_UNSUPPORTED);
3937 }
3938
3939 /**
3940 Set TLS object to work in client or server mode.
3941
3942 This function prepares a TLS object to work in client or server mode.
3943
3944 @param[in] Tls Pointer to a TLS object.
3945 @param[in] IsServer Work in server mode.
3946
3947 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
3948 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3949 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
3950
3951 **/
3952 EFI_STATUS
3953 EFIAPI
3954 TlsSetConnectionEnd (
3955 IN VOID *Tls,
3956 IN BOOLEAN IsServer
3957 )
3958 {
3959 CALL_CRYPTO_SERVICE (TlsSetConnectionEnd, (Tls, IsServer), EFI_UNSUPPORTED);
3960 }
3961
3962 /**
3963 Set the ciphers list to be used by the TLS object.
3964
3965 This function sets the ciphers for use by a specified TLS object.
3966
3967 @param[in] Tls Pointer to a TLS object.
3968 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
3969 cipher identifier comes from the TLS Cipher Suite
3970 Registry of the IANA, interpreting Byte1 and Byte2
3971 in network (big endian) byte order.
3972 @param[in] CipherNum The number of cipher in the list.
3973
3974 @retval EFI_SUCCESS The ciphers list was set successfully.
3975 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3976 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
3977 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
3978
3979 **/
3980 EFI_STATUS
3981 EFIAPI
3982 TlsSetCipherList (
3983 IN VOID *Tls,
3984 IN UINT16 *CipherId,
3985 IN UINTN CipherNum
3986 )
3987 {
3988 CALL_CRYPTO_SERVICE (TlsSetCipherList, (Tls, CipherId, CipherNum), EFI_UNSUPPORTED);
3989 }
3990
3991 /**
3992 Set the compression method for TLS/SSL operations.
3993
3994 This function handles TLS/SSL integrated compression methods.
3995
3996 @param[in] CompMethod The compression method ID.
3997
3998 @retval EFI_SUCCESS The compression method for the communication was
3999 set successfully.
4000 @retval EFI_UNSUPPORTED Unsupported compression method.
4001
4002 **/
4003 EFI_STATUS
4004 EFIAPI
4005 TlsSetCompressionMethod (
4006 IN UINT8 CompMethod
4007 )
4008 {
4009 CALL_CRYPTO_SERVICE (TlsSetCompressionMethod, (CompMethod), EFI_UNSUPPORTED);
4010 }
4011
4012 /**
4013 Set peer certificate verification mode for the TLS connection.
4014
4015 This function sets the verification mode flags for the TLS connection.
4016
4017 @param[in] Tls Pointer to the TLS object.
4018 @param[in] VerifyMode A set of logically or'ed verification mode flags.
4019
4020 **/
4021 VOID
4022 EFIAPI
4023 TlsSetVerify (
4024 IN VOID *Tls,
4025 IN UINT32 VerifyMode
4026 )
4027 {
4028 CALL_VOID_CRYPTO_SERVICE (TlsSetVerify, (Tls, VerifyMode));
4029 }
4030
4031 /**
4032 Set the specified host name to be verified.
4033
4034 @param[in] Tls Pointer to the TLS object.
4035 @param[in] Flags The setting flags during the validation.
4036 @param[in] HostName The specified host name to be verified.
4037
4038 @retval EFI_SUCCESS The HostName setting was set successfully.
4039 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4040 @retval EFI_ABORTED Invalid HostName setting.
4041
4042 **/
4043 EFI_STATUS
4044 EFIAPI
4045 TlsSetVerifyHost (
4046 IN VOID *Tls,
4047 IN UINT32 Flags,
4048 IN CHAR8 *HostName
4049 )
4050 {
4051 CALL_CRYPTO_SERVICE (TlsSetVerifyHost, (Tls, Flags, HostName), EFI_UNSUPPORTED);
4052 }
4053
4054 /**
4055 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
4056
4057 This function sets a session ID to be used when the TLS/SSL connection is
4058 to be established.
4059
4060 @param[in] Tls Pointer to the TLS object.
4061 @param[in] SessionId Session ID data used for session resumption.
4062 @param[in] SessionIdLen Length of Session ID in bytes.
4063
4064 @retval EFI_SUCCESS Session ID was set successfully.
4065 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4066 @retval EFI_UNSUPPORTED No available session for ID setting.
4067
4068 **/
4069 EFI_STATUS
4070 EFIAPI
4071 TlsSetSessionId (
4072 IN VOID *Tls,
4073 IN UINT8 *SessionId,
4074 IN UINT16 SessionIdLen
4075 )
4076 {
4077 CALL_CRYPTO_SERVICE (TlsSetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);
4078 }
4079
4080 /**
4081 Adds the CA to the cert store when requesting Server or Client authentication.
4082
4083 This function adds the CA certificate to the list of CAs when requesting
4084 Server or Client authentication for the chosen TLS connection.
4085
4086 @param[in] Tls Pointer to the TLS object.
4087 @param[in] Data Pointer to the data buffer of a DER-encoded binary
4088 X.509 certificate or PEM-encoded X.509 certificate.
4089 @param[in] DataSize The size of data buffer in bytes.
4090
4091 @retval EFI_SUCCESS The operation succeeded.
4092 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4093 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
4094 @retval EFI_ABORTED Invalid X.509 certificate.
4095
4096 **/
4097 EFI_STATUS
4098 EFIAPI
4099 TlsSetCaCertificate (
4100 IN VOID *Tls,
4101 IN VOID *Data,
4102 IN UINTN DataSize
4103 )
4104 {
4105 CALL_CRYPTO_SERVICE (TlsSetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);
4106 }
4107
4108 /**
4109 Loads the local public certificate into the specified TLS object.
4110
4111 This function loads the X.509 certificate into the specified TLS object
4112 for TLS negotiation.
4113
4114 @param[in] Tls Pointer to the TLS object.
4115 @param[in] Data Pointer to the data buffer of a DER-encoded binary
4116 X.509 certificate or PEM-encoded X.509 certificate.
4117 @param[in] DataSize The size of data buffer in bytes.
4118
4119 @retval EFI_SUCCESS The operation succeeded.
4120 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4121 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
4122 @retval EFI_ABORTED Invalid X.509 certificate.
4123
4124 **/
4125 EFI_STATUS
4126 EFIAPI
4127 TlsSetHostPublicCert (
4128 IN VOID *Tls,
4129 IN VOID *Data,
4130 IN UINTN DataSize
4131 )
4132 {
4133 CALL_CRYPTO_SERVICE (TlsSetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);
4134 }
4135
4136 /**
4137 Adds the local private key to the specified TLS object.
4138
4139 This function adds the local private key (DER-encoded or PEM-encoded or PKCS#8 private
4140 key) into the specified TLS object for TLS negotiation.
4141
4142 @param[in] Tls Pointer to the TLS object.
4143 @param[in] Data Pointer to the data buffer of a DER-encoded or PEM-encoded
4144 or PKCS#8 private key.
4145 @param[in] DataSize The size of data buffer in bytes.
4146 @param[in] Password Pointer to NULL-terminated private key password, set it to NULL
4147 if private key not encrypted.
4148
4149 @retval EFI_SUCCESS The operation succeeded.
4150 @retval EFI_UNSUPPORTED This function is not supported.
4151 @retval EFI_ABORTED Invalid private key data.
4152
4153 **/
4154 EFI_STATUS
4155 EFIAPI
4156 TlsSetHostPrivateKeyEx (
4157 IN VOID *Tls,
4158 IN VOID *Data,
4159 IN UINTN DataSize,
4160 IN VOID *Password OPTIONAL
4161 )
4162 {
4163 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKeyEx, (Tls, Data, DataSize, Password), EFI_UNSUPPORTED);
4164 }
4165
4166 /**
4167 Adds the local private key to the specified TLS object.
4168
4169 This function adds the local private key (DER-encoded or PEM-encoded or PKCS#8 private
4170 key) into the specified TLS object for TLS negotiation.
4171
4172 @param[in] Tls Pointer to the TLS object.
4173 @param[in] Data Pointer to the data buffer of a DER-encoded or PEM-encoded
4174 or PKCS#8 private key.
4175 @param[in] DataSize The size of data buffer in bytes.
4176
4177 @retval EFI_SUCCESS The operation succeeded.
4178 @retval EFI_UNSUPPORTED This function is not supported.
4179 @retval EFI_ABORTED Invalid private key data.
4180
4181 **/
4182 EFI_STATUS
4183 EFIAPI
4184 TlsSetHostPrivateKey (
4185 IN VOID *Tls,
4186 IN VOID *Data,
4187 IN UINTN DataSize
4188 )
4189 {
4190 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);
4191 }
4192
4193 /**
4194 Adds the CA-supplied certificate revocation list for certificate validation.
4195
4196 This function adds the CA-supplied certificate revocation list data for
4197 certificate validity checking.
4198
4199 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
4200 @param[in] DataSize The size of data buffer in bytes.
4201
4202 @retval EFI_SUCCESS The operation succeeded.
4203 @retval EFI_UNSUPPORTED This function is not supported.
4204 @retval EFI_ABORTED Invalid CRL data.
4205
4206 **/
4207 EFI_STATUS
4208 EFIAPI
4209 TlsSetCertRevocationList (
4210 IN VOID *Data,
4211 IN UINTN DataSize
4212 )
4213 {
4214 CALL_CRYPTO_SERVICE (TlsSetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);
4215 }
4216
4217 /**
4218 Set the signature algorithm list to used by the TLS object.
4219
4220 This function sets the signature algorithms for use by a specified TLS object.
4221
4222 @param[in] Tls Pointer to a TLS object.
4223 @param[in] Data Array of UINT8 of signature algorithms. The array consists of
4224 pairs of the hash algorithm and the signature algorithm as defined
4225 in RFC 5246
4226 @param[in] DataSize The length the SignatureAlgoList. Must be divisible by 2.
4227
4228 @retval EFI_SUCCESS The signature algorithm list was set successfully.
4229 @retval EFI_INVALID_PARAMETER The parameters are invalid.
4230 @retval EFI_UNSUPPORTED No supported TLS signature algorithm was found in SignatureAlgoList
4231 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
4232
4233 **/
4234 EFI_STATUS
4235 EFIAPI
4236 TlsSetSignatureAlgoList (
4237 IN VOID *Tls,
4238 IN UINT8 *Data,
4239 IN UINTN DataSize
4240 )
4241 {
4242 CALL_CRYPTO_SERVICE (TlsSetSignatureAlgoList, (Tls, Data, DataSize), EFI_UNSUPPORTED);
4243 }
4244
4245 /**
4246 Set the EC curve to be used for TLS flows
4247
4248 This function sets the EC curve to be used for TLS flows.
4249
4250 @param[in] Tls Pointer to a TLS object.
4251 @param[in] Data An EC named curve as defined in section 5.1.1 of RFC 4492.
4252 @param[in] DataSize Size of Data, it should be sizeof (UINT32)
4253
4254 @retval EFI_SUCCESS The EC curve was set successfully.
4255 @retval EFI_INVALID_PARAMETER The parameters are invalid.
4256 @retval EFI_UNSUPPORTED The requested TLS EC curve is not supported
4257
4258 **/
4259 EFI_STATUS
4260 EFIAPI
4261 TlsSetEcCurve (
4262 IN VOID *Tls,
4263 IN UINT8 *Data,
4264 IN UINTN DataSize
4265 )
4266 {
4267 CALL_CRYPTO_SERVICE (TlsSetSignatureAlgoList, (Tls, Data, DataSize), EFI_UNSUPPORTED);
4268 }
4269
4270 /**
4271 Gets the protocol version used by the specified TLS connection.
4272
4273 This function returns the protocol version used by the specified TLS
4274 connection.
4275
4276 If Tls is NULL, then ASSERT().
4277
4278 @param[in] Tls Pointer to the TLS object.
4279
4280 @return The protocol version of the specified TLS connection.
4281
4282 **/
4283 UINT16
4284 EFIAPI
4285 TlsGetVersion (
4286 IN VOID *Tls
4287 )
4288 {
4289 CALL_CRYPTO_SERVICE (TlsGetVersion, (Tls), 0);
4290 }
4291
4292 /**
4293 Gets the connection end of the specified TLS connection.
4294
4295 This function returns the connection end (as client or as server) used by
4296 the specified TLS connection.
4297
4298 If Tls is NULL, then ASSERT().
4299
4300 @param[in] Tls Pointer to the TLS object.
4301
4302 @return The connection end used by the specified TLS connection.
4303
4304 **/
4305 UINT8
4306 EFIAPI
4307 TlsGetConnectionEnd (
4308 IN VOID *Tls
4309 )
4310 {
4311 CALL_CRYPTO_SERVICE (TlsGetConnectionEnd, (Tls), 0);
4312 }
4313
4314 /**
4315 Gets the cipher suite used by the specified TLS connection.
4316
4317 This function returns current cipher suite used by the specified
4318 TLS connection.
4319
4320 @param[in] Tls Pointer to the TLS object.
4321 @param[in,out] CipherId The cipher suite used by the TLS object.
4322
4323 @retval EFI_SUCCESS The cipher suite was returned successfully.
4324 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4325 @retval EFI_UNSUPPORTED Unsupported cipher suite.
4326
4327 **/
4328 EFI_STATUS
4329 EFIAPI
4330 TlsGetCurrentCipher (
4331 IN VOID *Tls,
4332 IN OUT UINT16 *CipherId
4333 )
4334 {
4335 CALL_CRYPTO_SERVICE (TlsGetCurrentCipher, (Tls, CipherId), EFI_UNSUPPORTED);
4336 }
4337
4338 /**
4339 Gets the compression methods used by the specified TLS connection.
4340
4341 This function returns current integrated compression methods used by
4342 the specified TLS connection.
4343
4344 @param[in] Tls Pointer to the TLS object.
4345 @param[in,out] CompressionId The current compression method used by
4346 the TLS object.
4347
4348 @retval EFI_SUCCESS The compression method was returned successfully.
4349 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4350 @retval EFI_ABORTED Invalid Compression method.
4351 @retval EFI_UNSUPPORTED This function is not supported.
4352
4353 **/
4354 EFI_STATUS
4355 EFIAPI
4356 TlsGetCurrentCompressionId (
4357 IN VOID *Tls,
4358 IN OUT UINT8 *CompressionId
4359 )
4360 {
4361 CALL_CRYPTO_SERVICE (TlsGetCurrentCompressionId, (Tls, CompressionId), EFI_UNSUPPORTED);
4362 }
4363
4364 /**
4365 Gets the verification mode currently set in the TLS connection.
4366
4367 This function returns the peer verification mode currently set in the
4368 specified TLS connection.
4369
4370 If Tls is NULL, then ASSERT().
4371
4372 @param[in] Tls Pointer to the TLS object.
4373
4374 @return The verification mode set in the specified TLS connection.
4375
4376 **/
4377 UINT32
4378 EFIAPI
4379 TlsGetVerify (
4380 IN VOID *Tls
4381 )
4382 {
4383 CALL_CRYPTO_SERVICE (TlsGetVerify, (Tls), 0);
4384 }
4385
4386 /**
4387 Gets the session ID used by the specified TLS connection.
4388
4389 This function returns the TLS/SSL session ID currently used by the
4390 specified TLS connection.
4391
4392 @param[in] Tls Pointer to the TLS object.
4393 @param[in,out] SessionId Buffer to contain the returned session ID.
4394 @param[in,out] SessionIdLen The length of Session ID in bytes.
4395
4396 @retval EFI_SUCCESS The Session ID was returned successfully.
4397 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4398 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
4399
4400 **/
4401 EFI_STATUS
4402 EFIAPI
4403 TlsGetSessionId (
4404 IN VOID *Tls,
4405 IN OUT UINT8 *SessionId,
4406 IN OUT UINT16 *SessionIdLen
4407 )
4408 {
4409 CALL_CRYPTO_SERVICE (TlsGetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);
4410 }
4411
4412 /**
4413 Gets the client random data used in the specified TLS connection.
4414
4415 This function returns the TLS/SSL client random data currently used in
4416 the specified TLS connection.
4417
4418 @param[in] Tls Pointer to the TLS object.
4419 @param[in,out] ClientRandom Buffer to contain the returned client
4420 random data (32 bytes).
4421
4422 **/
4423 VOID
4424 EFIAPI
4425 TlsGetClientRandom (
4426 IN VOID *Tls,
4427 IN OUT UINT8 *ClientRandom
4428 )
4429 {
4430 CALL_VOID_CRYPTO_SERVICE (TlsGetClientRandom, (Tls, ClientRandom));
4431 }
4432
4433 /**
4434 Gets the server random data used in the specified TLS connection.
4435
4436 This function returns the TLS/SSL server random data currently used in
4437 the specified TLS connection.
4438
4439 @param[in] Tls Pointer to the TLS object.
4440 @param[in,out] ServerRandom Buffer to contain the returned server
4441 random data (32 bytes).
4442
4443 **/
4444 VOID
4445 EFIAPI
4446 TlsGetServerRandom (
4447 IN VOID *Tls,
4448 IN OUT UINT8 *ServerRandom
4449 )
4450 {
4451 CALL_VOID_CRYPTO_SERVICE (TlsGetServerRandom, (Tls, ServerRandom));
4452 }
4453
4454 /**
4455 Gets the master key data used in the specified TLS connection.
4456
4457 This function returns the TLS/SSL master key material currently used in
4458 the specified TLS connection.
4459
4460 @param[in] Tls Pointer to the TLS object.
4461 @param[in,out] KeyMaterial Buffer to contain the returned key material.
4462
4463 @retval EFI_SUCCESS Key material was returned successfully.
4464 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4465 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
4466
4467 **/
4468 EFI_STATUS
4469 EFIAPI
4470 TlsGetKeyMaterial (
4471 IN VOID *Tls,
4472 IN OUT UINT8 *KeyMaterial
4473 )
4474 {
4475 CALL_CRYPTO_SERVICE (TlsGetKeyMaterial, (Tls, KeyMaterial), EFI_UNSUPPORTED);
4476 }
4477
4478 /**
4479 Gets the CA Certificate from the cert store.
4480
4481 This function returns the CA certificate for the chosen
4482 TLS connection.
4483
4484 @param[in] Tls Pointer to the TLS object.
4485 @param[out] Data Pointer to the data buffer to receive the CA
4486 certificate data sent to the client.
4487 @param[in,out] DataSize The size of data buffer in bytes.
4488
4489 @retval EFI_SUCCESS The operation succeeded.
4490 @retval EFI_UNSUPPORTED This function is not supported.
4491 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4492
4493 **/
4494 EFI_STATUS
4495 EFIAPI
4496 TlsGetCaCertificate (
4497 IN VOID *Tls,
4498 OUT VOID *Data,
4499 IN OUT UINTN *DataSize
4500 )
4501 {
4502 CALL_CRYPTO_SERVICE (TlsGetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);
4503 }
4504
4505 /**
4506 Gets the local public Certificate set in the specified TLS object.
4507
4508 This function returns the local public certificate which was currently set
4509 in the specified TLS object.
4510
4511 @param[in] Tls Pointer to the TLS object.
4512 @param[out] Data Pointer to the data buffer to receive the local
4513 public certificate.
4514 @param[in,out] DataSize The size of data buffer in bytes.
4515
4516 @retval EFI_SUCCESS The operation succeeded.
4517 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4518 @retval EFI_NOT_FOUND The certificate is not found.
4519 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4520
4521 **/
4522 EFI_STATUS
4523 EFIAPI
4524 TlsGetHostPublicCert (
4525 IN VOID *Tls,
4526 OUT VOID *Data,
4527 IN OUT UINTN *DataSize
4528 )
4529 {
4530 CALL_CRYPTO_SERVICE (TlsGetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);
4531 }
4532
4533 /**
4534 Gets the local private key set in the specified TLS object.
4535
4536 This function returns the local private key data which was currently set
4537 in the specified TLS object.
4538
4539 @param[in] Tls Pointer to the TLS object.
4540 @param[out] Data Pointer to the data buffer to receive the local
4541 private key data.
4542 @param[in,out] DataSize The size of data buffer in bytes.
4543
4544 @retval EFI_SUCCESS The operation succeeded.
4545 @retval EFI_UNSUPPORTED This function is not supported.
4546 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4547
4548 **/
4549 EFI_STATUS
4550 EFIAPI
4551 TlsGetHostPrivateKey (
4552 IN VOID *Tls,
4553 OUT VOID *Data,
4554 IN OUT UINTN *DataSize
4555 )
4556 {
4557 CALL_CRYPTO_SERVICE (TlsGetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);
4558 }
4559
4560 /**
4561 Gets the CA-supplied certificate revocation list data set in the specified
4562 TLS object.
4563
4564 This function returns the CA-supplied certificate revocation list data which
4565 was currently set in the specified TLS object.
4566
4567 @param[out] Data Pointer to the data buffer to receive the CRL data.
4568 @param[in,out] DataSize The size of data buffer in bytes.
4569
4570 @retval EFI_SUCCESS The operation succeeded.
4571 @retval EFI_UNSUPPORTED This function is not supported.
4572 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4573
4574 **/
4575 EFI_STATUS
4576 EFIAPI
4577 TlsGetCertRevocationList (
4578 OUT VOID *Data,
4579 IN OUT UINTN *DataSize
4580 )
4581 {
4582 CALL_CRYPTO_SERVICE (TlsGetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);
4583 }
4584
4585 /**
4586 Derive keying material from a TLS connection.
4587
4588 This function exports keying material using the mechanism described in RFC
4589 5705.
4590
4591 @param[in] Tls Pointer to the TLS object
4592 @param[in] Label Description of the key for the PRF function
4593 @param[in] Context Optional context
4594 @param[in] ContextLen The length of the context value in bytes
4595 @param[out] KeyBuffer Buffer to hold the output of the TLS-PRF
4596 @param[in] KeyBufferLen The length of the KeyBuffer
4597
4598 @retval EFI_SUCCESS The operation succeeded.
4599 @retval EFI_INVALID_PARAMETER The TLS object is invalid.
4600 @retval EFI_PROTOCOL_ERROR Some other error occurred.
4601
4602 **/
4603 EFI_STATUS
4604 EFIAPI
4605 TlsGetExportKey (
4606 IN VOID *Tls,
4607 IN CONST VOID *Label,
4608 IN CONST VOID *Context,
4609 IN UINTN ContextLen,
4610 OUT VOID *KeyBuffer,
4611 IN UINTN KeyBufferLen
4612 )
4613 {
4614 CALL_CRYPTO_SERVICE (
4615 TlsGetExportKey,
4616 (Tls, Label, Context, ContextLen,
4617 KeyBuffer, KeyBufferLen),
4618 EFI_UNSUPPORTED
4619 );
4620 }
4621
4622 // =====================================================================================
4623 // Big number primitive
4624 // =====================================================================================
4625
4626 /**
4627 Allocate new Big Number.
4628
4629 @retval New BigNum opaque structure or NULL on failure.
4630 **/
4631 VOID *
4632 EFIAPI
4633 BigNumInit (
4634 VOID
4635 )
4636 {
4637 CALL_CRYPTO_SERVICE (BigNumInit, (), NULL);
4638 }
4639
4640 /**
4641 Allocate new Big Number and assign the provided value to it.
4642
4643 @param[in] Buf Big endian encoded buffer.
4644 @param[in] Len Buffer length.
4645
4646 @retval New BigNum opaque structure or NULL on failure.
4647 **/
4648 VOID *
4649 EFIAPI
4650 BigNumFromBin (
4651 IN CONST UINT8 *Buf,
4652 IN UINTN Len
4653 )
4654 {
4655 CALL_CRYPTO_SERVICE (BigNumFromBin, (Buf, Len), NULL);
4656 }
4657
4658 /**
4659 Convert the absolute value of Bn into big-endian form and store it at Buf.
4660 The Buf array should have at least BigNumBytes() in it.
4661
4662 @param[in] Bn Big number to convert.
4663 @param[out] Buf Output buffer.
4664
4665 @retval The length of the big-endian number placed at Buf or -1 on error.
4666 **/
4667 INTN
4668 EFIAPI
4669 BigNumToBin (
4670 IN CONST VOID *Bn,
4671 OUT UINT8 *Buf
4672 )
4673 {
4674 CALL_CRYPTO_SERVICE (BigNumToBin, (Bn, Buf), -1);
4675 }
4676
4677 /**
4678 Free the Big Number.
4679
4680 @param[in] Bn Big number to free.
4681 @param[in] Clear TRUE if the buffer should be cleared.
4682 **/
4683 VOID
4684 EFIAPI
4685 BigNumFree (
4686 IN VOID *Bn,
4687 IN BOOLEAN Clear
4688 )
4689 {
4690 CALL_VOID_CRYPTO_SERVICE (BigNumFree, (Bn, Clear));
4691 }
4692
4693 /**
4694 Calculate the sum of two Big Numbers.
4695 Please note, all "out" Big number arguments should be properly initialized
4696 by calling to BigNumInit() or BigNumFromBin() functions.
4697
4698 @param[in] BnA Big number.
4699 @param[in] BnB Big number.
4700 @param[out] BnRes The result of BnA + BnB.
4701
4702 @retval TRUE On success.
4703 @retval FALSE Otherwise.
4704 **/
4705 BOOLEAN
4706 EFIAPI
4707 BigNumAdd (
4708 IN CONST VOID *BnA,
4709 IN CONST VOID *BnB,
4710 OUT VOID *BnRes
4711 )
4712 {
4713 CALL_CRYPTO_SERVICE (BigNumAdd, (BnA, BnB, BnRes), FALSE);
4714 }
4715
4716 /**
4717 Subtract two Big Numbers.
4718 Please note, all "out" Big number arguments should be properly initialized
4719 by calling to BigNumInit() or BigNumFromBin() functions.
4720
4721 @param[in] BnA Big number.
4722 @param[in] BnB Big number.
4723 @param[out] BnRes The result of BnA - BnB.
4724
4725 @retval TRUE On success.
4726 @retval FALSE Otherwise.
4727 **/
4728 BOOLEAN
4729 EFIAPI
4730 BigNumSub (
4731 IN CONST VOID *BnA,
4732 IN CONST VOID *BnB,
4733 OUT VOID *BnRes
4734 )
4735 {
4736 CALL_CRYPTO_SERVICE (BigNumSub, (BnA, BnB, BnRes), FALSE);
4737 }
4738
4739 /**
4740 Calculate remainder: BnRes = BnA % BnB
4741 Please note, all "out" Big number arguments should be properly initialized
4742 by calling to BigNumInit() or BigNumFromBin() functions.
4743
4744 @param[in] BnA Big number.
4745 @param[in] BnB Big number.
4746 @param[out] BnRes The result of BnA % BnB.
4747
4748 @retval TRUE On success.
4749 @retval FALSE Otherwise.
4750 **/
4751 BOOLEAN
4752 EFIAPI
4753 BigNumMod (
4754 IN CONST VOID *BnA,
4755 IN CONST VOID *BnB,
4756 OUT VOID *BnRes
4757 )
4758 {
4759 CALL_CRYPTO_SERVICE (BigNumMod, (BnA, BnB, BnRes), FALSE);
4760 }
4761
4762 /**
4763 Compute BnA to the BnP-th power modulo BnM.
4764 Please note, all "out" Big number arguments should be properly initialized
4765 by calling to BigNumInit() or BigNumFromBin() functions.
4766
4767 @param[in] BnA Big number.
4768 @param[in] BnP Big number (power).
4769 @param[in] BnM Big number (modulo).
4770 @param[out] BnRes The result of (BnA ^ BnP) % BnM.
4771
4772 @retval TRUE On success.
4773 @retval FALSE Otherwise.
4774 **/
4775 BOOLEAN
4776 EFIAPI
4777 BigNumExpMod (
4778 IN CONST VOID *BnA,
4779 IN CONST VOID *BnP,
4780 IN CONST VOID *BnM,
4781 OUT VOID *BnRes
4782 )
4783 {
4784 CALL_CRYPTO_SERVICE (BigNumExpMod, (BnA, BnP, BnM, BnRes), FALSE);
4785 }
4786
4787 /**
4788 Compute BnA inverse modulo BnM.
4789 Please note, all "out" Big number arguments should be properly initialized
4790 by calling to BigNumInit() or BigNumFromBin() functions.
4791
4792 @param[in] BnA Big number.
4793 @param[in] BnM Big number (modulo).
4794 @param[out] BnRes The result, such that (BnA * BnRes) % BnM == 1.
4795
4796 @retval TRUE On success.
4797 @retval FALSE Otherwise.
4798 **/
4799 BOOLEAN
4800 EFIAPI
4801 BigNumInverseMod (
4802 IN CONST VOID *BnA,
4803 IN CONST VOID *BnM,
4804 OUT VOID *BnRes
4805 )
4806 {
4807 CALL_CRYPTO_SERVICE (BigNumInverseMod, (BnA, BnM, BnRes), FALSE);
4808 }
4809
4810 /**
4811 Divide two Big Numbers.
4812 Please note, all "out" Big number arguments should be properly initialized
4813 by calling to BigNumInit() or BigNumFromBin() functions.
4814
4815 @param[in] BnA Big number.
4816 @param[in] BnB Big number.
4817 @param[out] BnRes The result, such that BnA / BnB.
4818
4819 @retval TRUE On success.
4820 @retval FALSE Otherwise.
4821 **/
4822 BOOLEAN
4823 EFIAPI
4824 BigNumDiv (
4825 IN CONST VOID *BnA,
4826 IN CONST VOID *BnB,
4827 OUT VOID *BnRes
4828 )
4829 {
4830 CALL_CRYPTO_SERVICE (BigNumDiv, (BnA, BnB, BnRes), FALSE);
4831 }
4832
4833 /**
4834 Multiply two Big Numbers modulo BnM.
4835 Please note, all "out" Big number arguments should be properly initialized
4836 by calling to BigNumInit() or BigNumFromBin() functions.
4837
4838 @param[in] BnA Big number.
4839 @param[in] BnB Big number.
4840 @param[in] BnM Big number (modulo).
4841 @param[out] BnRes The result, such that (BnA * BnB) % BnM.
4842
4843 @retval TRUE On success.
4844 @retval FALSE Otherwise.
4845 **/
4846 BOOLEAN
4847 EFIAPI
4848 BigNumMulMod (
4849 IN CONST VOID *BnA,
4850 IN CONST VOID *BnB,
4851 IN CONST VOID *BnM,
4852 OUT VOID *BnRes
4853 )
4854 {
4855 CALL_CRYPTO_SERVICE (BigNumMulMod, (BnA, BnB, BnM, BnRes), FALSE);
4856 }
4857
4858 /**
4859 Compare two Big Numbers.
4860
4861 @param[in] BnA Big number.
4862 @param[in] BnB Big number.
4863
4864 @retval 0 BnA == BnB.
4865 @retval 1 BnA > BnB.
4866 @retval -1 BnA < BnB.
4867 **/
4868 INTN
4869 EFIAPI
4870 BigNumCmp (
4871 IN CONST VOID *BnA,
4872 IN CONST VOID *BnB
4873 )
4874 {
4875 CALL_CRYPTO_SERVICE (BigNumCmp, (BnA, BnB), 0);
4876 }
4877
4878 /**
4879 Get number of bits in Bn.
4880
4881 @param[in] Bn Big number.
4882
4883 @retval Number of bits.
4884 **/
4885 UINTN
4886 EFIAPI
4887 BigNumBits (
4888 IN CONST VOID *Bn
4889 )
4890 {
4891 CALL_CRYPTO_SERVICE (BigNumBits, (Bn), 0);
4892 }
4893
4894 /**
4895 Get number of bytes in Bn.
4896
4897 @param[in] Bn Big number.
4898
4899 @retval Number of bytes.
4900 **/
4901 UINTN
4902 EFIAPI
4903 BigNumBytes (
4904 IN CONST VOID *Bn
4905 )
4906 {
4907 CALL_CRYPTO_SERVICE (BigNumBytes, (Bn), 0);
4908 }
4909
4910 /**
4911 Checks if Big Number equals to the given Num.
4912
4913 @param[in] Bn Big number.
4914 @param[in] Num Number.
4915
4916 @retval TRUE iff Bn == Num.
4917 @retval FALSE otherwise.
4918 **/
4919 BOOLEAN
4920 EFIAPI
4921 BigNumIsWord (
4922 IN CONST VOID *Bn,
4923 IN UINTN Num
4924 )
4925 {
4926 CALL_CRYPTO_SERVICE (BigNumIsWord, (Bn, Num), FALSE);
4927 }
4928
4929 /**
4930 Checks if Big Number is odd.
4931
4932 @param[in] Bn Big number.
4933
4934 @retval TRUE Bn is odd (Bn % 2 == 1).
4935 @retval FALSE otherwise.
4936 **/
4937 BOOLEAN
4938 EFIAPI
4939 BigNumIsOdd (
4940 IN CONST VOID *Bn
4941 )
4942 {
4943 CALL_CRYPTO_SERVICE (BigNumIsOdd, (Bn), FALSE);
4944 }
4945
4946 /**
4947 Copy Big number.
4948
4949 @param[out] BnDst Destination.
4950 @param[in] BnSrc Source.
4951
4952 @retval BnDst on success.
4953 @retval NULL otherwise.
4954 **/
4955 VOID *
4956 EFIAPI
4957 BigNumCopy (
4958 OUT VOID *BnDst,
4959 IN CONST VOID *BnSrc
4960 )
4961 {
4962 CALL_CRYPTO_SERVICE (BigNumCopy, (BnDst, BnSrc), NULL);
4963 }
4964
4965 /**
4966 Get constant Big number with value of "1".
4967 This may be used to save expensive allocations.
4968
4969 @retval Big Number with value of 1.
4970 **/
4971 CONST VOID *
4972 EFIAPI
4973 BigNumValueOne (
4974 VOID
4975 )
4976 {
4977 CALL_CRYPTO_SERVICE (BigNumValueOne, (), NULL);
4978 }
4979
4980 /**
4981 Shift right Big Number.
4982 Please note, all "out" Big number arguments should be properly initialized
4983 by calling to BigNumInit() or BigNumFromBin() functions.
4984
4985 @param[in] Bn Big number.
4986 @param[in] N Number of bits to shift.
4987 @param[out] BnRes The result.
4988
4989 @retval TRUE On success.
4990 @retval FALSE Otherwise.
4991 **/
4992 BOOLEAN
4993 EFIAPI
4994 BigNumRShift (
4995 IN CONST VOID *Bn,
4996 IN UINTN N,
4997 OUT VOID *BnRes
4998 )
4999 {
5000 CALL_CRYPTO_SERVICE (BigNumRShift, (Bn, N, BnRes), FALSE);
5001 }
5002
5003 /**
5004 Mark Big Number for constant time computations.
5005 This function should be called before any constant time computations are
5006 performed on the given Big number.
5007
5008 @param[in] Bn Big number.
5009 **/
5010 VOID
5011 EFIAPI
5012 BigNumConstTime (
5013 IN VOID *Bn
5014 )
5015 {
5016 CALL_VOID_CRYPTO_SERVICE (BigNumConstTime, (Bn));
5017 }
5018
5019 /**
5020 Calculate square modulo.
5021 Please note, all "out" Big number arguments should be properly initialized
5022 by calling to BigNumInit() or BigNumFromBin() functions.
5023
5024 @param[in] BnA Big number.
5025 @param[in] BnM Big number (modulo).
5026 @param[out] BnRes The result, such that (BnA ^ 2) % BnM.
5027
5028 @retval TRUE On success.
5029 @retval FALSE Otherwise.
5030 **/
5031 BOOLEAN
5032 EFIAPI
5033 BigNumSqrMod (
5034 IN CONST VOID *BnA,
5035 IN CONST VOID *BnM,
5036 OUT VOID *BnRes
5037 )
5038 {
5039 CALL_CRYPTO_SERVICE (BigNumSqrMod, (BnA, BnM, BnRes), FALSE);
5040 }
5041
5042 /**
5043 Create new Big Number computation context. This is an opaque structure
5044 which should be passed to any function that requires it. The BN context is
5045 needed to optimize calculations and expensive allocations.
5046
5047 @retval Big Number context struct or NULL on failure.
5048 **/
5049 VOID *
5050 EFIAPI
5051 BigNumNewContext (
5052 VOID
5053 )
5054 {
5055 CALL_CRYPTO_SERVICE (BigNumNewContext, (), NULL);
5056 }
5057
5058 /**
5059 Free Big Number context that was allocated with BigNumNewContext().
5060
5061 @param[in] BnCtx Big number context to free.
5062 **/
5063 VOID
5064 EFIAPI
5065 BigNumContextFree (
5066 IN VOID *BnCtx
5067 )
5068 {
5069 CALL_VOID_CRYPTO_SERVICE (BigNumContextFree, (BnCtx));
5070 }
5071
5072 /**
5073 Set Big Number to a given value.
5074
5075 @param[in] Bn Big number to set.
5076 @param[in] Val Value to set.
5077
5078 @retval TRUE On success.
5079 @retval FALSE Otherwise.
5080 **/
5081 BOOLEAN
5082 EFIAPI
5083 BigNumSetUint (
5084 IN VOID *Bn,
5085 IN UINTN Val
5086 )
5087 {
5088 CALL_CRYPTO_SERVICE (BigNumSetUint, (Bn, Val), FALSE);
5089 }
5090
5091 /**
5092 Add two Big Numbers modulo BnM.
5093
5094 @param[in] BnA Big number.
5095 @param[in] BnB Big number.
5096 @param[in] BnM Big number (modulo).
5097 @param[out] BnRes The result, such that (BnA + BnB) % BnM.
5098
5099 @retval TRUE On success.
5100 @retval FALSE Otherwise.
5101 **/
5102 BOOLEAN
5103 EFIAPI
5104 BigNumAddMod (
5105 IN CONST VOID *BnA,
5106 IN CONST VOID *BnB,
5107 IN CONST VOID *BnM,
5108 OUT VOID *BnRes
5109 )
5110 {
5111 CALL_CRYPTO_SERVICE (BigNumAddMod, (BnA, BnB, BnM, BnRes), FALSE);
5112 }
5113
5114 /**
5115 Initialize new opaque EcGroup object. This object represents an EC curve and
5116 and is used for calculation within this group. This object should be freed
5117 using EcGroupFree() function.
5118
5119 @param[in] CryptoNid Identifying number for the ECC curve (Defined in
5120 BaseCryptLib.h).
5121
5122 @retval EcGroup object On success.
5123 @retval NULL On failure.
5124 **/
5125 VOID *
5126 EFIAPI
5127 EcGroupInit (
5128 IN UINTN CryptoNid
5129 )
5130 {
5131 CALL_CRYPTO_SERVICE (EcGroupInit, (CryptoNid), NULL);
5132 }
5133
5134 /**
5135 Get EC curve parameters. While elliptic curve equation is Y^2 mod P = (X^3 + AX + B) Mod P.
5136 This function will set the provided Big Number objects to the corresponding
5137 values. The caller needs to make sure all the "out" BigNumber parameters
5138 are properly initialized.
5139
5140 @param[in] EcGroup EC group object.
5141 @param[out] BnPrime Group prime number.
5142 @param[out] BnA A coefficient.
5143 @param[out] BnB B coefficient.
5144 @param[in] BnCtx BN context.
5145
5146 @retval TRUE On success.
5147 @retval FALSE Otherwise.
5148 **/
5149 BOOLEAN
5150 EFIAPI
5151 EcGroupGetCurve (
5152 IN CONST VOID *EcGroup,
5153 OUT VOID *BnPrime,
5154 OUT VOID *BnA,
5155 OUT VOID *BnB,
5156 IN VOID *BnCtx
5157 )
5158 {
5159 CALL_CRYPTO_SERVICE (EcGroupGetCurve, (EcGroup, BnPrime, BnA, BnB, BnCtx), FALSE);
5160 }
5161
5162 /**
5163 Get EC group order.
5164 This function will set the provided Big Number object to the corresponding
5165 value. The caller needs to make sure that the "out" BigNumber parameter
5166 is properly initialized.
5167
5168 @param[in] EcGroup EC group object.
5169 @param[out] BnOrder Group prime number.
5170
5171 @retval TRUE On success.
5172 @retval FALSE Otherwise.
5173 **/
5174 BOOLEAN
5175 EFIAPI
5176 EcGroupGetOrder (
5177 IN VOID *EcGroup,
5178 OUT VOID *BnOrder
5179 )
5180 {
5181 CALL_CRYPTO_SERVICE (EcGroupGetOrder, (EcGroup, BnOrder), FALSE);
5182 }
5183
5184 /**
5185 Free previously allocated EC group object using EcGroupInit().
5186
5187 @param[in] EcGroup EC group object to free.
5188 **/
5189 VOID
5190 EFIAPI
5191 EcGroupFree (
5192 IN VOID *EcGroup
5193 )
5194 {
5195 CALL_VOID_CRYPTO_SERVICE (EcGroupFree, (EcGroup));
5196 }
5197
5198 /**
5199 Initialize new opaque EC Point object. This object represents an EC point
5200 within the given EC group (curve).
5201
5202 @param[in] EC Group, properly initialized using EcGroupInit().
5203
5204 @retval EC Point object On success.
5205 @retval NULL On failure.
5206 **/
5207 VOID *
5208 EFIAPI
5209 EcPointInit (
5210 IN CONST VOID *EcGroup
5211 )
5212 {
5213 CALL_CRYPTO_SERVICE (EcPointInit, (EcGroup), NULL);
5214 }
5215
5216 /**
5217 Free previously allocated EC Point object using EcPointInit().
5218
5219 @param[in] EcPoint EC Point to free.
5220 @param[in] Clear TRUE iff the memory should be cleared.
5221 **/
5222 VOID
5223 EFIAPI
5224 EcPointDeInit (
5225 IN VOID *EcPoint,
5226 IN BOOLEAN Clear
5227 )
5228 {
5229 CALL_VOID_CRYPTO_SERVICE (EcPointDeInit, (EcPoint, Clear));
5230 }
5231
5232 /**
5233 Get EC point affine (x,y) coordinates.
5234 This function will set the provided Big Number objects to the corresponding
5235 values. The caller needs to make sure all the "out" BigNumber parameters
5236 are properly initialized.
5237
5238 @param[in] EcGroup EC group object.
5239 @param[in] EcPoint EC point object.
5240 @param[out] BnX X coordinate.
5241 @param[out] BnY Y coordinate.
5242 @param[in] BnCtx BN context, created with BigNumNewContext().
5243
5244 @retval TRUE On success.
5245 @retval FALSE Otherwise.
5246 **/
5247 BOOLEAN
5248 EFIAPI
5249 EcPointGetAffineCoordinates (
5250 IN CONST VOID *EcGroup,
5251 IN CONST VOID *EcPoint,
5252 OUT VOID *BnX,
5253 OUT VOID *BnY,
5254 IN VOID *BnCtx
5255 )
5256 {
5257 CALL_CRYPTO_SERVICE (EcPointGetAffineCoordinates, (EcGroup, EcPoint, BnX, BnY, BnCtx), FALSE);
5258 }
5259
5260 /**
5261 Set EC point affine (x,y) coordinates.
5262
5263 @param[in] EcGroup EC group object.
5264 @param[in] EcPoint EC point object.
5265 @param[in] BnX X coordinate.
5266 @param[in] BnY Y coordinate.
5267 @param[in] BnCtx BN context, created with BigNumNewContext().
5268
5269 @retval TRUE On success.
5270 @retval FALSE Otherwise.
5271 **/
5272 BOOLEAN
5273 EFIAPI
5274 EcPointSetAffineCoordinates (
5275 IN CONST VOID *EcGroup,
5276 IN VOID *EcPoint,
5277 IN CONST VOID *BnX,
5278 IN CONST VOID *BnY,
5279 IN VOID *BnCtx
5280 )
5281 {
5282 CALL_CRYPTO_SERVICE (EcPointSetAffineCoordinates, (EcGroup, EcPoint, BnX, BnY, BnCtx), FALSE);
5283 }
5284
5285 /**
5286 EC Point addition. EcPointResult = EcPointA + EcPointB.
5287
5288 @param[in] EcGroup EC group object.
5289 @param[out] EcPointResult EC point to hold the result. The point should
5290 be properly initialized.
5291 @param[in] EcPointA EC Point.
5292 @param[in] EcPointB EC Point.
5293 @param[in] BnCtx BN context, created with BigNumNewContext().
5294
5295 @retval TRUE On success.
5296 @retval FALSE Otherwise.
5297 **/
5298 BOOLEAN
5299 EFIAPI
5300 EcPointAdd (
5301 IN CONST VOID *EcGroup,
5302 OUT VOID *EcPointResult,
5303 IN CONST VOID *EcPointA,
5304 IN CONST VOID *EcPointB,
5305 IN VOID *BnCtx
5306 )
5307 {
5308 CALL_CRYPTO_SERVICE (EcPointAdd, (EcGroup, EcPointResult, EcPointA, EcPointB, BnCtx), FALSE);
5309 }
5310
5311 /**
5312 Variable EC point multiplication. EcPointResult = EcPoint * BnPScalar.
5313
5314 @param[in] EcGroup EC group object.
5315 @param[out] EcPointResult EC point to hold the result. The point should
5316 be properly initialized.
5317 @param[in] EcPoint EC Point.
5318 @param[in] BnPScalar P Scalar.
5319 @param[in] BnCtx BN context, created with BigNumNewContext().
5320
5321 @retval TRUE On success.
5322 @retval FALSE Otherwise.
5323 **/
5324 BOOLEAN
5325 EFIAPI
5326 EcPointMul (
5327 IN CONST VOID *EcGroup,
5328 OUT VOID *EcPointResult,
5329 IN CONST VOID *EcPoint,
5330 IN CONST VOID *BnPScalar,
5331 IN VOID *BnCtx
5332 )
5333 {
5334 CALL_CRYPTO_SERVICE (EcPointMul, (EcGroup, EcPointResult, EcPoint, BnPScalar, BnCtx), FALSE);
5335 }
5336
5337 /**
5338 Calculate the inverse of the supplied EC point.
5339
5340 @param[in] EcGroup EC group object.
5341 @param[in,out] EcPoint EC point to invert.
5342 @param[in] BnCtx BN context, created with BigNumNewContext().
5343
5344 @retval TRUE On success.
5345 @retval FALSE Otherwise.
5346 **/
5347 BOOLEAN
5348 EFIAPI
5349 EcPointInvert (
5350 IN CONST VOID *EcGroup,
5351 IN OUT VOID *EcPoint,
5352 IN VOID *BnCtx
5353 )
5354 {
5355 CALL_CRYPTO_SERVICE (EcPointInvert, (EcGroup, EcPoint, BnCtx), FALSE);
5356 }
5357
5358 /**
5359 Check if the supplied point is on EC curve.
5360
5361 @param[in] EcGroup EC group object.
5362 @param[in] EcPoint EC point to check.
5363 @param[in] BnCtx BN context, created with BigNumNewContext().
5364
5365 @retval TRUE On curve.
5366 @retval FALSE Otherwise.
5367 **/
5368 BOOLEAN
5369 EFIAPI
5370 EcPointIsOnCurve (
5371 IN CONST VOID *EcGroup,
5372 IN CONST VOID *EcPoint,
5373 IN VOID *BnCtx
5374 )
5375 {
5376 CALL_CRYPTO_SERVICE (EcPointIsOnCurve, (EcGroup, EcPoint, BnCtx), FALSE);
5377 }
5378
5379 /**
5380 Check if the supplied point is at infinity.
5381
5382 @param[in] EcGroup EC group object.
5383 @param[in] EcPoint EC point to check.
5384
5385 @retval TRUE At infinity.
5386 @retval FALSE Otherwise.
5387 **/
5388 BOOLEAN
5389 EFIAPI
5390 EcPointIsAtInfinity (
5391 IN CONST VOID *EcGroup,
5392 IN CONST VOID *EcPoint
5393 )
5394 {
5395 CALL_CRYPTO_SERVICE (EcPointIsAtInfinity, (EcGroup, EcPoint), FALSE);
5396 }
5397
5398 /**
5399 Check if EC points are equal.
5400
5401 @param[in] EcGroup EC group object.
5402 @param[in] EcPointA EC point A.
5403 @param[in] EcPointB EC point B.
5404 @param[in] BnCtx BN context, created with BigNumNewContext().
5405
5406 @retval TRUE A == B.
5407 @retval FALSE Otherwise.
5408 **/
5409 BOOLEAN
5410 EFIAPI
5411 EcPointEqual (
5412 IN CONST VOID *EcGroup,
5413 IN CONST VOID *EcPointA,
5414 IN CONST VOID *EcPointB,
5415 IN VOID *BnCtx
5416 )
5417 {
5418 CALL_CRYPTO_SERVICE (EcPointEqual, (EcGroup, EcPointA, EcPointB, BnCtx), FALSE);
5419 }
5420
5421 /**
5422 Set EC point compressed coordinates. Points can be described in terms of
5423 their compressed coordinates. For a point (x, y), for any given value for x
5424 such that the point is on the curve there will only ever be two possible
5425 values for y. Therefore, a point can be set using this function where BnX is
5426 the x coordinate and YBit is a value 0 or 1 to identify which of the two
5427 possible values for y should be used.
5428
5429 @param[in] EcGroup EC group object.
5430 @param[in] EcPoint EC Point.
5431 @param[in] BnX X coordinate.
5432 @param[in] YBit 0 or 1 to identify which Y value is used.
5433 @param[in] BnCtx BN context, created with BigNumNewContext().
5434
5435 @retval TRUE On success.
5436 @retval FALSE Otherwise.
5437 **/
5438 BOOLEAN
5439 EFIAPI
5440 EcPointSetCompressedCoordinates (
5441 IN CONST VOID *EcGroup,
5442 IN VOID *EcPoint,
5443 IN CONST VOID *BnX,
5444 IN UINT8 YBit,
5445 IN VOID *BnCtx
5446 )
5447 {
5448 CALL_CRYPTO_SERVICE (EcPointSetCompressedCoordinates, (EcGroup, EcPoint, BnX, YBit, BnCtx), FALSE);
5449 }
5450
5451 /**
5452 Allocates and Initializes one Elliptic Curve Context for subsequent use
5453 with the NID.
5454
5455 @param[in] Nid cipher NID
5456 @return Pointer to the Elliptic Curve Context that has been initialized.
5457 If the allocations fails, EcNewByNid() returns NULL.
5458 **/
5459 VOID *
5460 EFIAPI
5461 EcNewByNid (
5462 IN UINTN Nid
5463 )
5464 {
5465 CALL_CRYPTO_SERVICE (EcNewByNid, (Nid), NULL);
5466 }
5467
5468 /**
5469 Release the specified EC context.
5470
5471 @param[in] EcContext Pointer to the EC context to be released.
5472 **/
5473 VOID
5474 EFIAPI
5475 EcFree (
5476 IN VOID *EcContext
5477 )
5478 {
5479 CALL_VOID_CRYPTO_SERVICE (EcFree, (EcContext));
5480 }
5481
5482 /**
5483 Generates EC key and returns EC public key (X, Y), Please note, this function uses
5484 pseudo random number generator. The caller must make sure RandomSeed()
5485 function was properly called before.
5486 The Ec context should be correctly initialized by EcNewByNid.
5487 This function generates random secret, and computes the public key (X, Y), which is
5488 returned via parameter Public, PublicSize.
5489 X is the first half of Public with size being PublicSize / 2,
5490 Y is the second half of Public with size being PublicSize / 2.
5491 EC context is updated accordingly.
5492 If the Public buffer is too small to hold the public X, Y, FALSE is returned and
5493 PublicSize is set to the required buffer size to obtain the public X, Y.
5494 For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.
5495 For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.
5496 For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.
5497 If EcContext is NULL, then return FALSE.
5498 If PublicSize is NULL, then return FALSE.
5499 If PublicSize is large enough but Public is NULL, then return FALSE.
5500 @param[in, out] EcContext Pointer to the EC context.
5501 @param[out] PublicKey Pointer to the buffer to receive generated public X,Y.
5502 @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.
5503 On output, the size of data returned in Public buffer in bytes.
5504 @retval TRUE EC public X,Y generation succeeded.
5505 @retval FALSE EC public X,Y generation failed.
5506 @retval FALSE PublicKeySize is not large enough.
5507 **/
5508 BOOLEAN
5509 EFIAPI
5510 EcGenerateKey (
5511 IN OUT VOID *EcContext,
5512 OUT UINT8 *PublicKey,
5513 IN OUT UINTN *PublicKeySize
5514 )
5515 {
5516 CALL_CRYPTO_SERVICE (EcGenerateKey, (EcContext, PublicKey, PublicKeySize), FALSE);
5517 }
5518
5519 /**
5520 Gets the public key component from the established EC context.
5521 The Ec context should be correctly initialized by EcNewByNid, and successfully
5522 generate key pair from EcGenerateKey().
5523 For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.
5524 For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.
5525 For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.
5526 @param[in, out] EcContext Pointer to EC context being set.
5527 @param[out] PublicKey Pointer to t buffer to receive generated public X,Y.
5528 @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.
5529 On output, the size of data returned in Public buffer in bytes.
5530 @retval TRUE EC key component was retrieved successfully.
5531 @retval FALSE Invalid EC key component.
5532 **/
5533 BOOLEAN
5534 EFIAPI
5535 EcGetPubKey (
5536 IN OUT VOID *EcContext,
5537 OUT UINT8 *PublicKey,
5538 IN OUT UINTN *PublicKeySize
5539 )
5540 {
5541 CALL_CRYPTO_SERVICE (EcGetPubKey, (EcContext, PublicKey, PublicKeySize), FALSE);
5542 }
5543
5544 /**
5545 Computes exchanged common key.
5546 Given peer's public key (X, Y), this function computes the exchanged common key,
5547 based on its own context including value of curve parameter and random secret.
5548 X is the first half of PeerPublic with size being PeerPublicSize / 2,
5549 Y is the second half of PeerPublic with size being PeerPublicSize / 2.
5550 If EcContext is NULL, then return FALSE.
5551 If PeerPublic is NULL, then return FALSE.
5552 If PeerPublicSize is 0, then return FALSE.
5553 If Key is NULL, then return FALSE.
5554 If KeySize is not large enough, then return FALSE.
5555 For P-256, the PeerPublicSize is 64. First 32-byte is X, Second 32-byte is Y.
5556 For P-384, the PeerPublicSize is 96. First 48-byte is X, Second 48-byte is Y.
5557 For P-521, the PeerPublicSize is 132. First 66-byte is X, Second 66-byte is Y.
5558 @param[in, out] EcContext Pointer to the EC context.
5559 @param[in] PeerPublic Pointer to the peer's public X,Y.
5560 @param[in] PeerPublicSize Size of peer's public X,Y in bytes.
5561 @param[in] CompressFlag Flag of PeerPublic is compressed or not.
5562 @param[out] Key Pointer to the buffer to receive generated key.
5563 @param[in, out] KeySize On input, the size of Key buffer in bytes.
5564 On output, the size of data returned in Key buffer in bytes.
5565 @retval TRUE EC exchanged key generation succeeded.
5566 @retval FALSE EC exchanged key generation failed.
5567 @retval FALSE KeySize is not large enough.
5568 **/
5569 BOOLEAN
5570 EFIAPI
5571 EcDhComputeKey (
5572 IN OUT VOID *EcContext,
5573 IN CONST UINT8 *PeerPublic,
5574 IN UINTN PeerPublicSize,
5575 IN CONST INT32 *CompressFlag,
5576 OUT UINT8 *Key,
5577 IN OUT UINTN *KeySize
5578 )
5579 {
5580 CALL_CRYPTO_SERVICE (EcDhComputeKey, (EcContext, PeerPublic, PeerPublicSize, CompressFlag, Key, KeySize), FALSE);
5581 }
5582
5583 /**
5584 Retrieve the EC Public Key from one DER-encoded X509 certificate.
5585
5586 @param[in] Cert Pointer to the DER-encoded X509 certificate.
5587 @param[in] CertSize Size of the X509 certificate in bytes.
5588 @param[out] EcContext Pointer to new-generated EC DSA context which contain the retrieved
5589 EC public key component. Use EcFree() function to free the
5590 resource.
5591
5592 If Cert is NULL, then return FALSE.
5593 If EcContext is NULL, then return FALSE.
5594
5595 @retval TRUE EC Public Key was retrieved successfully.
5596 @retval FALSE Fail to retrieve EC public key from X509 certificate.
5597
5598 **/
5599 BOOLEAN
5600 EFIAPI
5601 EcGetPublicKeyFromX509 (
5602 IN CONST UINT8 *Cert,
5603 IN UINTN CertSize,
5604 OUT VOID **EcContext
5605 )
5606 {
5607 CALL_CRYPTO_SERVICE (EcGetPublicKeyFromX509, (Cert, CertSize, EcContext), FALSE);
5608 }
5609
5610 /**
5611 Retrieve the EC Private Key from the password-protected PEM key data.
5612
5613 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
5614 @param[in] PemSize Size of the PEM key data in bytes.
5615 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
5616 @param[out] EcContext Pointer to new-generated EC DSA context which contain the retrieved
5617 EC private key component. Use EcFree() function to free the
5618 resource.
5619
5620 If PemData is NULL, then return FALSE.
5621 If EcContext is NULL, then return FALSE.
5622
5623 @retval TRUE EC Private Key was retrieved successfully.
5624 @retval FALSE Invalid PEM key data or incorrect password.
5625
5626 **/
5627 BOOLEAN
5628 EFIAPI
5629 EcGetPrivateKeyFromPem (
5630 IN CONST UINT8 *PemData,
5631 IN UINTN PemSize,
5632 IN CONST CHAR8 *Password,
5633 OUT VOID **EcContext
5634 )
5635 {
5636 CALL_CRYPTO_SERVICE (EcGetPrivateKeyFromPem, (PemData, PemSize, Password, EcContext), FALSE);
5637 }
5638
5639 /**
5640 Carries out the EC-DSA signature.
5641
5642 This function carries out the EC-DSA signature.
5643 If the Signature buffer is too small to hold the contents of signature, FALSE
5644 is returned and SigSize is set to the required buffer size to obtain the signature.
5645
5646 If EcContext is NULL, then return FALSE.
5647 If MessageHash is NULL, then return FALSE.
5648 If HashSize need match the HashNid. HashNid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
5649 If SigSize is large enough but Signature is NULL, then return FALSE.
5650
5651 For P-256, the SigSize is 64. First 32-byte is R, Second 32-byte is S.
5652 For P-384, the SigSize is 96. First 48-byte is R, Second 48-byte is S.
5653 For P-521, the SigSize is 132. First 66-byte is R, Second 66-byte is S.
5654
5655 @param[in] EcContext Pointer to EC context for signature generation.
5656 @param[in] HashNid hash NID
5657 @param[in] MessageHash Pointer to octet message hash to be signed.
5658 @param[in] HashSize Size of the message hash in bytes.
5659 @param[out] Signature Pointer to buffer to receive EC-DSA signature.
5660 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
5661 On output, the size of data returned in Signature buffer in bytes.
5662
5663 @retval TRUE Signature successfully generated in EC-DSA.
5664 @retval FALSE Signature generation failed.
5665 @retval FALSE SigSize is too small.
5666
5667 **/
5668 BOOLEAN
5669 EFIAPI
5670 EcDsaSign (
5671 IN VOID *EcContext,
5672 IN UINTN HashNid,
5673 IN CONST UINT8 *MessageHash,
5674 IN UINTN HashSize,
5675 OUT UINT8 *Signature,
5676 IN OUT UINTN *SigSize
5677 )
5678 {
5679 CALL_CRYPTO_SERVICE (EcDsaSign, (EcContext, HashNid, MessageHash, HashSize, Signature, SigSize), FALSE);
5680 }
5681
5682 /**
5683 Verifies the EC-DSA signature.
5684
5685 If EcContext is NULL, then return FALSE.
5686 If MessageHash is NULL, then return FALSE.
5687 If Signature is NULL, then return FALSE.
5688 If HashSize need match the HashNid. HashNid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
5689
5690 For P-256, the SigSize is 64. First 32-byte is R, Second 32-byte is S.
5691 For P-384, the SigSize is 96. First 48-byte is R, Second 48-byte is S.
5692 For P-521, the SigSize is 132. First 66-byte is R, Second 66-byte is S.
5693
5694 @param[in] EcContext Pointer to EC context for signature verification.
5695 @param[in] HashNid hash NID
5696 @param[in] MessageHash Pointer to octet message hash to be checked.
5697 @param[in] HashSize Size of the message hash in bytes.
5698 @param[in] Signature Pointer to EC-DSA signature to be verified.
5699 @param[in] SigSize Size of signature in bytes.
5700
5701 @retval TRUE Valid signature encoded in EC-DSA.
5702 @retval FALSE Invalid signature or invalid EC context.
5703
5704 **/
5705 BOOLEAN
5706 EFIAPI
5707 EcDsaVerify (
5708 IN VOID *EcContext,
5709 IN UINTN HashNid,
5710 IN CONST UINT8 *MessageHash,
5711 IN UINTN HashSize,
5712 IN CONST UINT8 *Signature,
5713 IN UINTN SigSize
5714 )
5715 {
5716 CALL_CRYPTO_SERVICE (EcDsaVerify, (EcContext, HashNid, MessageHash, HashSize, Signature, SigSize), FALSE);
5717 }