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