2 Implements the BaseCryptLib and TlsLib using the services of the EDK II Crypto
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
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>
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.
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.
29 #define CALL_CRYPTO_SERVICE(Function, Args, ErrorReturnValue) \
31 EDKII_CRYPTO_PROTOCOL *CryptoServices; \
33 CryptoServices = (EDKII_CRYPTO_PROTOCOL *)GetCryptoServices (); \
34 if (CryptoServices != NULL && CryptoServices->Function != NULL) { \
35 return (CryptoServices->Function) Args; \
37 CryptoServiceNotAvailable (#Function); \
38 return ErrorReturnValue; \
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.
46 @param Function Name of the EDK II Crypto Protocol service to call.
47 @param Args The argument list to pass to Function.
50 #define CALL_VOID_CRYPTO_SERVICE(Function, Args) \
52 EDKII_CRYPTO_PROTOCOL *CryptoServices; \
54 CryptoServices = (EDKII_CRYPTO_PROTOCOL *)GetCryptoServices (); \
55 if (CryptoServices != NULL && CryptoServices->Function != NULL) { \
56 (CryptoServices->Function) Args; \
59 CryptoServiceNotAvailable (#Function); \
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
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.
84 @param[in] FunctionName Null-terminated ASCII string that is the name of an
85 EDK II Crypto service.
90 CryptoServiceNotAvailable (
91 IN CONST CHAR8
*FunctionName
94 DEBUG ((DEBUG_ERROR
, "[%a] Function %a is not available\n", gEfiCallerBaseName
, FunctionName
));
95 ASSERT_EFI_ERROR (EFI_UNSUPPORTED
);
98 //=====================================================================================
99 // One-Way Cryptographic Hash Primitives
100 //=====================================================================================
102 #ifdef ENABLE_MD5_DEPRECATED_INTERFACES
104 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.
106 If this interface is not supported, then return zero.
108 @return The size, in bytes, of the context buffer required for MD5 hash operations.
109 @retval 0 This interface is not supported.
118 CALL_CRYPTO_SERVICE (Md5GetContextSize
, (), 0);
122 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for
125 If Md5Context is NULL, then return FALSE.
126 If this interface is not supported, then return FALSE.
128 @param[out] Md5Context Pointer to MD5 context being initialized.
130 @retval TRUE MD5 context initialization succeeded.
131 @retval FALSE MD5 context initialization failed.
132 @retval FALSE This interface is not supported.
141 CALL_CRYPTO_SERVICE (Md5Init
, (Md5Context
), FALSE
);
145 Makes a copy of an existing MD5 context.
147 If Md5Context is NULL, then return FALSE.
148 If NewMd5Context is NULL, then return FALSE.
149 If this interface is not supported, then return FALSE.
151 @param[in] Md5Context Pointer to MD5 context being copied.
152 @param[out] NewMd5Context Pointer to new MD5 context.
154 @retval TRUE MD5 context copy succeeded.
155 @retval FALSE MD5 context copy failed.
156 @retval FALSE This interface is not supported.
162 IN CONST VOID
*Md5Context
,
163 OUT VOID
*NewMd5Context
166 CALL_CRYPTO_SERVICE (Md5Duplicate
, (Md5Context
, NewMd5Context
), FALSE
);
170 Digests the input data and updates MD5 context.
172 This function performs MD5 digest on a data buffer of the specified size.
173 It can be called multiple times to compute the digest of long or discontinuous data streams.
174 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized
175 by Md5Final(). Behavior with invalid context is undefined.
177 If Md5Context is NULL, then return FALSE.
178 If this interface is not supported, then return FALSE.
180 @param[in, out] Md5Context Pointer to the MD5 context.
181 @param[in] Data Pointer to the buffer containing the data to be hashed.
182 @param[in] DataSize Size of Data buffer in bytes.
184 @retval TRUE MD5 data digest succeeded.
185 @retval FALSE MD5 data digest failed.
186 @retval FALSE This interface is not supported.
192 IN OUT VOID
*Md5Context
,
197 CALL_CRYPTO_SERVICE (Md5Update
, (Md5Context
, Data
, DataSize
), FALSE
);
201 Completes computation of the MD5 digest value.
203 This function completes MD5 hash computation and retrieves the digest value into
204 the specified memory. After this function has been called, the MD5 context cannot
206 MD5 context should be already correctly initialized by Md5Init(), and should not be
207 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.
209 If Md5Context is NULL, then return FALSE.
210 If HashValue is NULL, then return FALSE.
211 If this interface is not supported, then return FALSE.
213 @param[in, out] Md5Context Pointer to the MD5 context.
214 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
217 @retval TRUE MD5 digest computation succeeded.
218 @retval FALSE MD5 digest computation failed.
219 @retval FALSE This interface is not supported.
225 IN OUT VOID
*Md5Context
,
229 CALL_CRYPTO_SERVICE (Md5Final
, (Md5Context
, HashValue
), FALSE
);
233 Computes the MD5 message digest of a input data buffer.
235 This function performs the MD5 message digest of a given data buffer, and places
236 the digest value into the specified memory.
238 If this interface is not supported, then return FALSE.
240 @param[in] Data Pointer to the buffer containing the data to be hashed.
241 @param[in] DataSize Size of Data buffer in bytes.
242 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
245 @retval TRUE MD5 digest computation succeeded.
246 @retval FALSE MD5 digest computation failed.
247 @retval FALSE This interface is not supported.
258 CALL_CRYPTO_SERVICE (Md5HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
262 #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
264 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.
266 If this interface is not supported, then return zero.
268 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.
269 @retval 0 This interface is not supported.
278 CALL_CRYPTO_SERVICE (Sha1GetContextSize
, (), 0);
282 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for
285 If Sha1Context is NULL, then return FALSE.
286 If this interface is not supported, then return FALSE.
288 @param[out] Sha1Context Pointer to SHA-1 context being initialized.
290 @retval TRUE SHA-1 context initialization succeeded.
291 @retval FALSE SHA-1 context initialization failed.
292 @retval FALSE This interface is not supported.
298 OUT VOID
*Sha1Context
301 CALL_CRYPTO_SERVICE (Sha1Init
, (Sha1Context
), FALSE
);
305 Makes a copy of an existing SHA-1 context.
307 If Sha1Context is NULL, then return FALSE.
308 If NewSha1Context is NULL, then return FALSE.
309 If this interface is not supported, then return FALSE.
311 @param[in] Sha1Context Pointer to SHA-1 context being copied.
312 @param[out] NewSha1Context Pointer to new SHA-1 context.
314 @retval TRUE SHA-1 context copy succeeded.
315 @retval FALSE SHA-1 context copy failed.
316 @retval FALSE This interface is not supported.
322 IN CONST VOID
*Sha1Context
,
323 OUT VOID
*NewSha1Context
326 CALL_CRYPTO_SERVICE (Sha1Duplicate
, (Sha1Context
, NewSha1Context
), FALSE
);
330 Digests the input data and updates SHA-1 context.
332 This function performs SHA-1 digest on a data buffer of the specified size.
333 It can be called multiple times to compute the digest of long or discontinuous data streams.
334 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized
335 by Sha1Final(). Behavior with invalid context is undefined.
337 If Sha1Context is NULL, then return FALSE.
338 If this interface is not supported, then return FALSE.
340 @param[in, out] Sha1Context Pointer to the SHA-1 context.
341 @param[in] Data Pointer to the buffer containing the data to be hashed.
342 @param[in] DataSize Size of Data buffer in bytes.
344 @retval TRUE SHA-1 data digest succeeded.
345 @retval FALSE SHA-1 data digest failed.
346 @retval FALSE This interface is not supported.
352 IN OUT VOID
*Sha1Context
,
357 CALL_CRYPTO_SERVICE (Sha1Update
, (Sha1Context
, Data
, DataSize
), FALSE
);
361 Completes computation of the SHA-1 digest value.
363 This function completes SHA-1 hash computation and retrieves the digest value into
364 the specified memory. After this function has been called, the SHA-1 context cannot
366 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be
367 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.
369 If Sha1Context is NULL, then return FALSE.
370 If HashValue is NULL, then return FALSE.
371 If this interface is not supported, then return FALSE.
373 @param[in, out] Sha1Context Pointer to the SHA-1 context.
374 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
377 @retval TRUE SHA-1 digest computation succeeded.
378 @retval FALSE SHA-1 digest computation failed.
379 @retval FALSE This interface is not supported.
385 IN OUT VOID
*Sha1Context
,
389 CALL_CRYPTO_SERVICE (Sha1Final
, (Sha1Context
, HashValue
), FALSE
);
393 Computes the SHA-1 message digest of a input data buffer.
395 This function performs the SHA-1 message digest of a given data buffer, and places
396 the digest value into the specified memory.
398 If this interface is not supported, then return FALSE.
400 @param[in] Data Pointer to the buffer containing the data to be hashed.
401 @param[in] DataSize Size of Data buffer in bytes.
402 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
405 @retval TRUE SHA-1 digest computation succeeded.
406 @retval FALSE SHA-1 digest computation failed.
407 @retval FALSE This interface is not supported.
418 CALL_CRYPTO_SERVICE (Sha1HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
423 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.
425 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.
430 Sha256GetContextSize (
434 CALL_CRYPTO_SERVICE (Sha256GetContextSize
, (), 0);
438 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for
441 If Sha256Context is NULL, then return FALSE.
443 @param[out] Sha256Context Pointer to SHA-256 context being initialized.
445 @retval TRUE SHA-256 context initialization succeeded.
446 @retval FALSE SHA-256 context initialization failed.
452 OUT VOID
*Sha256Context
455 CALL_CRYPTO_SERVICE (Sha256Init
, (Sha256Context
), FALSE
);
459 Makes a copy of an existing SHA-256 context.
461 If Sha256Context is NULL, then return FALSE.
462 If NewSha256Context is NULL, then return FALSE.
463 If this interface is not supported, then return FALSE.
465 @param[in] Sha256Context Pointer to SHA-256 context being copied.
466 @param[out] NewSha256Context Pointer to new SHA-256 context.
468 @retval TRUE SHA-256 context copy succeeded.
469 @retval FALSE SHA-256 context copy failed.
470 @retval FALSE This interface is not supported.
476 IN CONST VOID
*Sha256Context
,
477 OUT VOID
*NewSha256Context
480 CALL_CRYPTO_SERVICE (Sha256Duplicate
, (Sha256Context
, NewSha256Context
), FALSE
);
484 Digests the input data and updates SHA-256 context.
486 This function performs SHA-256 digest on a data buffer of the specified size.
487 It can be called multiple times to compute the digest of long or discontinuous data streams.
488 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized
489 by Sha256Final(). Behavior with invalid context is undefined.
491 If Sha256Context is NULL, then return FALSE.
493 @param[in, out] Sha256Context Pointer to the SHA-256 context.
494 @param[in] Data Pointer to the buffer containing the data to be hashed.
495 @param[in] DataSize Size of Data buffer in bytes.
497 @retval TRUE SHA-256 data digest succeeded.
498 @retval FALSE SHA-256 data digest failed.
504 IN OUT VOID
*Sha256Context
,
509 CALL_CRYPTO_SERVICE (Sha256Update
, (Sha256Context
, Data
, DataSize
), FALSE
);
513 Completes computation of the SHA-256 digest value.
515 This function completes SHA-256 hash computation and retrieves the digest value into
516 the specified memory. After this function has been called, the SHA-256 context cannot
518 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be
519 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.
521 If Sha256Context is NULL, then return FALSE.
522 If HashValue is NULL, then return FALSE.
524 @param[in, out] Sha256Context Pointer to the SHA-256 context.
525 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
528 @retval TRUE SHA-256 digest computation succeeded.
529 @retval FALSE SHA-256 digest computation failed.
535 IN OUT VOID
*Sha256Context
,
539 CALL_CRYPTO_SERVICE (Sha256Final
, (Sha256Context
, HashValue
), FALSE
);
543 Computes the SHA-256 message digest of a input data buffer.
545 This function performs the SHA-256 message digest of a given data buffer, and places
546 the digest value into the specified memory.
548 If this interface is not supported, then return FALSE.
550 @param[in] Data Pointer to the buffer containing the data to be hashed.
551 @param[in] DataSize Size of Data buffer in bytes.
552 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
555 @retval TRUE SHA-256 digest computation succeeded.
556 @retval FALSE SHA-256 digest computation failed.
557 @retval FALSE This interface is not supported.
568 CALL_CRYPTO_SERVICE (Sha256HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
572 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.
574 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.
579 Sha384GetContextSize (
583 CALL_CRYPTO_SERVICE (Sha384GetContextSize
, (), 0);
587 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for
590 If Sha384Context is NULL, then return FALSE.
592 @param[out] Sha384Context Pointer to SHA-384 context being initialized.
594 @retval TRUE SHA-384 context initialization succeeded.
595 @retval FALSE SHA-384 context initialization failed.
601 OUT VOID
*Sha384Context
604 CALL_CRYPTO_SERVICE (Sha384Init
, (Sha384Context
), FALSE
);
608 Makes a copy of an existing SHA-384 context.
610 If Sha384Context is NULL, then return FALSE.
611 If NewSha384Context is NULL, then return FALSE.
612 If this interface is not supported, then return FALSE.
614 @param[in] Sha384Context Pointer to SHA-384 context being copied.
615 @param[out] NewSha384Context Pointer to new SHA-384 context.
617 @retval TRUE SHA-384 context copy succeeded.
618 @retval FALSE SHA-384 context copy failed.
619 @retval FALSE This interface is not supported.
625 IN CONST VOID
*Sha384Context
,
626 OUT VOID
*NewSha384Context
629 CALL_CRYPTO_SERVICE (Sha384Duplicate
, (Sha384Context
, NewSha384Context
), FALSE
);
633 Digests the input data and updates SHA-384 context.
635 This function performs SHA-384 digest on a data buffer of the specified size.
636 It can be called multiple times to compute the digest of long or discontinuous data streams.
637 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized
638 by Sha384Final(). Behavior with invalid context is undefined.
640 If Sha384Context is NULL, then return FALSE.
642 @param[in, out] Sha384Context Pointer to the SHA-384 context.
643 @param[in] Data Pointer to the buffer containing the data to be hashed.
644 @param[in] DataSize Size of Data buffer in bytes.
646 @retval TRUE SHA-384 data digest succeeded.
647 @retval FALSE SHA-384 data digest failed.
653 IN OUT VOID
*Sha384Context
,
658 CALL_CRYPTO_SERVICE (Sha384Update
, (Sha384Context
, Data
, DataSize
), FALSE
);
662 Completes computation of the SHA-384 digest value.
664 This function completes SHA-384 hash computation and retrieves the digest value into
665 the specified memory. After this function has been called, the SHA-384 context cannot
667 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be
668 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.
670 If Sha384Context is NULL, then return FALSE.
671 If HashValue is NULL, then return FALSE.
673 @param[in, out] Sha384Context Pointer to the SHA-384 context.
674 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
677 @retval TRUE SHA-384 digest computation succeeded.
678 @retval FALSE SHA-384 digest computation failed.
684 IN OUT VOID
*Sha384Context
,
688 CALL_CRYPTO_SERVICE (Sha384Final
, (Sha384Context
, HashValue
), FALSE
);
692 Computes the SHA-384 message digest of a input data buffer.
694 This function performs the SHA-384 message digest of a given data buffer, and places
695 the digest value into the specified memory.
697 If this interface is not supported, then return FALSE.
699 @param[in] Data Pointer to the buffer containing the data to be hashed.
700 @param[in] DataSize Size of Data buffer in bytes.
701 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
704 @retval TRUE SHA-384 digest computation succeeded.
705 @retval FALSE SHA-384 digest computation failed.
706 @retval FALSE This interface is not supported.
717 CALL_CRYPTO_SERVICE (Sha384HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
721 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.
723 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.
728 Sha512GetContextSize (
732 CALL_CRYPTO_SERVICE (Sha512GetContextSize
, (), 0);
736 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for
739 If Sha512Context is NULL, then return FALSE.
741 @param[out] Sha512Context Pointer to SHA-512 context being initialized.
743 @retval TRUE SHA-512 context initialization succeeded.
744 @retval FALSE SHA-512 context initialization failed.
750 OUT VOID
*Sha512Context
753 CALL_CRYPTO_SERVICE (Sha512Init
, (Sha512Context
), FALSE
);
757 Makes a copy of an existing SHA-512 context.
759 If Sha512Context is NULL, then return FALSE.
760 If NewSha512Context is NULL, then return FALSE.
761 If this interface is not supported, then return FALSE.
763 @param[in] Sha512Context Pointer to SHA-512 context being copied.
764 @param[out] NewSha512Context Pointer to new SHA-512 context.
766 @retval TRUE SHA-512 context copy succeeded.
767 @retval FALSE SHA-512 context copy failed.
768 @retval FALSE This interface is not supported.
774 IN CONST VOID
*Sha512Context
,
775 OUT VOID
*NewSha512Context
778 CALL_CRYPTO_SERVICE (Sha512Duplicate
, (Sha512Context
, NewSha512Context
), FALSE
);
782 Digests the input data and updates SHA-512 context.
784 This function performs SHA-512 digest on a data buffer of the specified size.
785 It can be called multiple times to compute the digest of long or discontinuous data streams.
786 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized
787 by Sha512Final(). Behavior with invalid context is undefined.
789 If Sha512Context is NULL, then return FALSE.
791 @param[in, out] Sha512Context Pointer to the SHA-512 context.
792 @param[in] Data Pointer to the buffer containing the data to be hashed.
793 @param[in] DataSize Size of Data buffer in bytes.
795 @retval TRUE SHA-512 data digest succeeded.
796 @retval FALSE SHA-512 data digest failed.
802 IN OUT VOID
*Sha512Context
,
807 CALL_CRYPTO_SERVICE (Sha512Update
, (Sha512Context
, Data
, DataSize
), FALSE
);
811 Completes computation of the SHA-512 digest value.
813 This function completes SHA-512 hash computation and retrieves the digest value into
814 the specified memory. After this function has been called, the SHA-512 context cannot
816 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be
817 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.
819 If Sha512Context is NULL, then return FALSE.
820 If HashValue is NULL, then return FALSE.
822 @param[in, out] Sha512Context Pointer to the SHA-512 context.
823 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
826 @retval TRUE SHA-512 digest computation succeeded.
827 @retval FALSE SHA-512 digest computation failed.
833 IN OUT VOID
*Sha512Context
,
837 CALL_CRYPTO_SERVICE (Sha512Final
, (Sha512Context
, HashValue
), FALSE
);
841 Computes the SHA-512 message digest of a input data buffer.
843 This function performs the SHA-512 message digest of a given data buffer, and places
844 the digest value into the specified memory.
846 If this interface is not supported, then return FALSE.
848 @param[in] Data Pointer to the buffer containing the data to be hashed.
849 @param[in] DataSize Size of Data buffer in bytes.
850 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
853 @retval TRUE SHA-512 digest computation succeeded.
854 @retval FALSE SHA-512 digest computation failed.
855 @retval FALSE This interface is not supported.
866 CALL_CRYPTO_SERVICE (Sha512HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
870 Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.
872 @return The size, in bytes, of the context buffer required for SM3 hash operations.
881 CALL_CRYPTO_SERVICE (Sm3GetContextSize
, (), 0);
885 Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for
888 If Sm3Context is NULL, then return FALSE.
890 @param[out] Sm3Context Pointer to SM3 context being initialized.
892 @retval TRUE SM3 context initialization succeeded.
893 @retval FALSE SM3 context initialization failed.
902 CALL_CRYPTO_SERVICE (Sm3Init
, (Sm3Context
), FALSE
);
906 Makes a copy of an existing SM3 context.
908 If Sm3Context is NULL, then return FALSE.
909 If NewSm3Context is NULL, then return FALSE.
910 If this interface is not supported, then return FALSE.
912 @param[in] Sm3Context Pointer to SM3 context being copied.
913 @param[out] NewSm3Context Pointer to new SM3 context.
915 @retval TRUE SM3 context copy succeeded.
916 @retval FALSE SM3 context copy failed.
917 @retval FALSE This interface is not supported.
923 IN CONST VOID
*Sm3Context
,
924 OUT VOID
*NewSm3Context
927 CALL_CRYPTO_SERVICE (Sm3Duplicate
, (Sm3Context
, NewSm3Context
), FALSE
);
931 Digests the input data and updates SM3 context.
933 This function performs SM3 digest on a data buffer of the specified size.
934 It can be called multiple times to compute the digest of long or discontinuous data streams.
935 SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized
936 by Sm3Final(). Behavior with invalid context is undefined.
938 If Sm3Context is NULL, then return FALSE.
940 @param[in, out] Sm3Context Pointer to the SM3 context.
941 @param[in] Data Pointer to the buffer containing the data to be hashed.
942 @param[in] DataSize Size of Data buffer in bytes.
944 @retval TRUE SM3 data digest succeeded.
945 @retval FALSE SM3 data digest failed.
951 IN OUT VOID
*Sm3Context
,
956 CALL_CRYPTO_SERVICE (Sm3Update
, (Sm3Context
, Data
, DataSize
), FALSE
);
960 Completes computation of the SM3 digest value.
962 This function completes SM3 hash computation and retrieves the digest value into
963 the specified memory. After this function has been called, the SM3 context cannot
965 SM3 context should be already correctly initialized by Sm3Init(), and should not be
966 finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.
968 If Sm3Context is NULL, then return FALSE.
969 If HashValue is NULL, then return FALSE.
971 @param[in, out] Sm3Context Pointer to the SM3 context.
972 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
975 @retval TRUE SM3 digest computation succeeded.
976 @retval FALSE SM3 digest computation failed.
982 IN OUT VOID
*Sm3Context
,
986 CALL_CRYPTO_SERVICE (Sm3Final
, (Sm3Context
, HashValue
), FALSE
);
990 Computes the SM3 message digest of a input data buffer.
992 This function performs the SM3 message digest of a given data buffer, and places
993 the digest value into the specified memory.
995 If this interface is not supported, then return FALSE.
997 @param[in] Data Pointer to the buffer containing the data to be hashed.
998 @param[in] DataSize Size of Data buffer in bytes.
999 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
1002 @retval TRUE SM3 digest computation succeeded.
1003 @retval FALSE SM3 digest computation failed.
1004 @retval FALSE This interface is not supported.
1010 IN CONST VOID
*Data
,
1012 OUT UINT8
*HashValue
1015 CALL_CRYPTO_SERVICE (Sm3HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
1018 //=====================================================================================
1019 // MAC (Message Authentication Code) Primitive
1020 //=====================================================================================
1023 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
1025 @return Pointer to the HMAC_CTX context that has been initialized.
1026 If the allocations fails, HmacSha256New() returns NULL.
1035 CALL_CRYPTO_SERVICE (HmacSha256New
, (), NULL
);
1039 Release the specified HMAC_CTX context.
1041 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.
1047 IN VOID
*HmacSha256Ctx
1050 CALL_VOID_CRYPTO_SERVICE (HmacSha256Free
, (HmacSha256Ctx
));
1054 Set user-supplied key for subsequent use. It must be done before any
1055 calling to HmacSha256Update().
1057 If HmacSha256Context is NULL, then return FALSE.
1058 If this interface is not supported, then return FALSE.
1060 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.
1061 @param[in] Key Pointer to the user-supplied key.
1062 @param[in] KeySize Key size in bytes.
1064 @retval TRUE The Key is set successfully.
1065 @retval FALSE The Key is set unsuccessfully.
1066 @retval FALSE This interface is not supported.
1072 OUT VOID
*HmacSha256Context
,
1073 IN CONST UINT8
*Key
,
1077 CALL_CRYPTO_SERVICE (HmacSha256SetKey
, (HmacSha256Context
, Key
, KeySize
), FALSE
);
1081 Makes a copy of an existing HMAC-SHA256 context.
1083 If HmacSha256Context is NULL, then return FALSE.
1084 If NewHmacSha256Context is NULL, then return FALSE.
1085 If this interface is not supported, then return FALSE.
1087 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.
1088 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.
1090 @retval TRUE HMAC-SHA256 context copy succeeded.
1091 @retval FALSE HMAC-SHA256 context copy failed.
1092 @retval FALSE This interface is not supported.
1097 HmacSha256Duplicate (
1098 IN CONST VOID
*HmacSha256Context
,
1099 OUT VOID
*NewHmacSha256Context
1102 CALL_CRYPTO_SERVICE (HmacSha256Duplicate
, (HmacSha256Context
, NewHmacSha256Context
), FALSE
);
1106 Digests the input data and updates HMAC-SHA256 context.
1108 This function performs HMAC-SHA256 digest on a data buffer of the specified size.
1109 It can be called multiple times to compute the digest of long or discontinuous data streams.
1110 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1111 by HmacSha256Final(). Behavior with invalid context is undefined.
1113 If HmacSha256Context is NULL, then return FALSE.
1114 If this interface is not supported, then return FALSE.
1116 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1117 @param[in] Data Pointer to the buffer containing the data to be digested.
1118 @param[in] DataSize Size of Data buffer in bytes.
1120 @retval TRUE HMAC-SHA256 data digest succeeded.
1121 @retval FALSE HMAC-SHA256 data digest failed.
1122 @retval FALSE This interface is not supported.
1128 IN OUT VOID
*HmacSha256Context
,
1129 IN CONST VOID
*Data
,
1133 CALL_CRYPTO_SERVICE (HmacSha256Update
, (HmacSha256Context
, Data
, DataSize
), FALSE
);
1137 Completes computation of the HMAC-SHA256 digest value.
1139 This function completes HMAC-SHA256 hash computation and retrieves the digest value into
1140 the specified memory. After this function has been called, the HMAC-SHA256 context cannot
1142 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1143 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.
1145 If HmacSha256Context is NULL, then return FALSE.
1146 If HmacValue is NULL, then return FALSE.
1147 If this interface is not supported, then return FALSE.
1149 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1150 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
1153 @retval TRUE HMAC-SHA256 digest computation succeeded.
1154 @retval FALSE HMAC-SHA256 digest computation failed.
1155 @retval FALSE This interface is not supported.
1161 IN OUT VOID
*HmacSha256Context
,
1162 OUT UINT8
*HmacValue
1165 CALL_CRYPTO_SERVICE (HmacSha256Final
, (HmacSha256Context
, HmacValue
), FALSE
);
1168 //=====================================================================================
1169 // Symmetric Cryptography Primitive
1170 //=====================================================================================
1173 Retrieves the size, in bytes, of the context buffer required for AES operations.
1175 If this interface is not supported, then return zero.
1177 @return The size, in bytes, of the context buffer required for AES operations.
1178 @retval 0 This interface is not supported.
1187 CALL_CRYPTO_SERVICE (AesGetContextSize
, (), 0);
1191 Initializes user-supplied memory as AES context for subsequent use.
1193 This function initializes user-supplied memory pointed by AesContext as AES context.
1194 In addition, it sets up all AES key materials for subsequent encryption and decryption
1196 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1198 If AesContext is NULL, then return FALSE.
1199 If Key is NULL, then return FALSE.
1200 If KeyLength is not valid, then return FALSE.
1201 If this interface is not supported, then return FALSE.
1203 @param[out] AesContext Pointer to AES context being initialized.
1204 @param[in] Key Pointer to the user-supplied AES key.
1205 @param[in] KeyLength Length of AES key in bits.
1207 @retval TRUE AES context initialization succeeded.
1208 @retval FALSE AES context initialization failed.
1209 @retval FALSE This interface is not supported.
1215 OUT VOID
*AesContext
,
1216 IN CONST UINT8
*Key
,
1220 CALL_CRYPTO_SERVICE (AesInit
, (AesContext
, Key
, KeyLength
), FALSE
);
1224 Performs AES encryption on a data buffer of the specified size in CBC mode.
1226 This function performs AES encryption on data buffer pointed by Input, of specified
1227 size of InputSize, in CBC mode.
1228 InputSize must be multiple of block size (16 bytes). This function does not perform
1229 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1230 Initialization vector should be one block size (16 bytes).
1231 AesContext should be already correctly initialized by AesInit(). Behavior with
1232 invalid AES context is undefined.
1234 If AesContext is NULL, then return FALSE.
1235 If Input is NULL, then return FALSE.
1236 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1237 If Ivec is NULL, then return FALSE.
1238 If Output is NULL, then return FALSE.
1239 If this interface is not supported, then return FALSE.
1241 @param[in] AesContext Pointer to the AES context.
1242 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1243 @param[in] InputSize Size of the Input buffer in bytes.
1244 @param[in] Ivec Pointer to initialization vector.
1245 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1247 @retval TRUE AES encryption succeeded.
1248 @retval FALSE AES encryption failed.
1249 @retval FALSE This interface is not supported.
1255 IN VOID
*AesContext
,
1256 IN CONST UINT8
*Input
,
1258 IN CONST UINT8
*Ivec
,
1262 CALL_CRYPTO_SERVICE (AesCbcEncrypt
, (AesContext
, Input
, InputSize
, Ivec
, Output
), FALSE
);
1266 Performs AES decryption on a data buffer of the specified size in CBC mode.
1268 This function performs AES decryption on data buffer pointed by Input, of specified
1269 size of InputSize, in CBC mode.
1270 InputSize must be multiple of block size (16 bytes). This function does not perform
1271 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1272 Initialization vector should be one block size (16 bytes).
1273 AesContext should be already correctly initialized by AesInit(). Behavior with
1274 invalid AES context is undefined.
1276 If AesContext is NULL, then return FALSE.
1277 If Input is NULL, then return FALSE.
1278 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1279 If Ivec is NULL, then return FALSE.
1280 If Output is NULL, then return FALSE.
1281 If this interface is not supported, then return FALSE.
1283 @param[in] AesContext Pointer to the AES context.
1284 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1285 @param[in] InputSize Size of the Input buffer in bytes.
1286 @param[in] Ivec Pointer to initialization vector.
1287 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1289 @retval TRUE AES decryption succeeded.
1290 @retval FALSE AES decryption failed.
1291 @retval FALSE This interface is not supported.
1297 IN VOID
*AesContext
,
1298 IN CONST UINT8
*Input
,
1300 IN CONST UINT8
*Ivec
,
1304 CALL_CRYPTO_SERVICE (AesCbcDecrypt
, (AesContext
, Input
, InputSize
, Ivec
, Output
), FALSE
);
1307 //=====================================================================================
1308 // Asymmetric Cryptography Primitive
1309 //=====================================================================================
1312 Allocates and initializes one RSA context for subsequent use.
1314 @return Pointer to the RSA context that has been initialized.
1315 If the allocations fails, RsaNew() returns NULL.
1324 CALL_CRYPTO_SERVICE (RsaNew
, (), NULL
);
1328 Release the specified RSA context.
1330 If RsaContext is NULL, then return FALSE.
1332 @param[in] RsaContext Pointer to the RSA context to be released.
1341 CALL_VOID_CRYPTO_SERVICE (RsaFree
, (RsaContext
));
1345 Sets the tag-designated key component into the established RSA context.
1347 This function sets the tag-designated RSA key component into the established
1348 RSA context from the user-specified non-negative integer (octet string format
1349 represented in RSA PKCS#1).
1350 If BigNumber is NULL, then the specified key component in RSA context is cleared.
1352 If RsaContext is NULL, then return FALSE.
1354 @param[in, out] RsaContext Pointer to RSA context being set.
1355 @param[in] KeyTag Tag of RSA key component being set.
1356 @param[in] BigNumber Pointer to octet integer buffer.
1357 If NULL, then the specified key component in RSA
1359 @param[in] BnSize Size of big number buffer in bytes.
1360 If BigNumber is NULL, then it is ignored.
1362 @retval TRUE RSA key component was set successfully.
1363 @retval FALSE Invalid RSA key component tag.
1369 IN OUT VOID
*RsaContext
,
1370 IN RSA_KEY_TAG KeyTag
,
1371 IN CONST UINT8
*BigNumber
,
1375 CALL_CRYPTO_SERVICE (RsaSetKey
, (RsaContext
, KeyTag
, BigNumber
, BnSize
), FALSE
);
1379 Gets the tag-designated RSA key component from the established RSA context.
1381 This function retrieves the tag-designated RSA key component from the
1382 established RSA context as a non-negative integer (octet string format
1383 represented in RSA PKCS#1).
1384 If specified key component has not been set or has been cleared, then returned
1386 If the BigNumber buffer is too small to hold the contents of the key, FALSE
1387 is returned and BnSize is set to the required buffer size to obtain the key.
1389 If RsaContext is NULL, then return FALSE.
1390 If BnSize is NULL, then return FALSE.
1391 If BnSize is large enough but BigNumber is NULL, then return FALSE.
1392 If this interface is not supported, then return FALSE.
1394 @param[in, out] RsaContext Pointer to RSA context being set.
1395 @param[in] KeyTag Tag of RSA key component being set.
1396 @param[out] BigNumber Pointer to octet integer buffer.
1397 @param[in, out] BnSize On input, the size of big number buffer in bytes.
1398 On output, the size of data returned in big number buffer in bytes.
1400 @retval TRUE RSA key component was retrieved successfully.
1401 @retval FALSE Invalid RSA key component tag.
1402 @retval FALSE BnSize is too small.
1403 @retval FALSE This interface is not supported.
1409 IN OUT VOID
*RsaContext
,
1410 IN RSA_KEY_TAG KeyTag
,
1411 OUT UINT8
*BigNumber
,
1412 IN OUT UINTN
*BnSize
1415 CALL_CRYPTO_SERVICE (RsaGetKey
, (RsaContext
, KeyTag
, BigNumber
, BnSize
), FALSE
);
1419 Generates RSA key components.
1421 This function generates RSA key components. It takes RSA public exponent E and
1422 length in bits of RSA modulus N as input, and generates all key components.
1423 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
1425 Before this function can be invoked, pseudorandom number generator must be correctly
1426 initialized by RandomSeed().
1428 If RsaContext is NULL, then return FALSE.
1429 If this interface is not supported, then return FALSE.
1431 @param[in, out] RsaContext Pointer to RSA context being set.
1432 @param[in] ModulusLength Length of RSA modulus N in bits.
1433 @param[in] PublicExponent Pointer to RSA public exponent.
1434 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
1436 @retval TRUE RSA key component was generated successfully.
1437 @retval FALSE Invalid RSA key component tag.
1438 @retval FALSE This interface is not supported.
1444 IN OUT VOID
*RsaContext
,
1445 IN UINTN ModulusLength
,
1446 IN CONST UINT8
*PublicExponent
,
1447 IN UINTN PublicExponentSize
1450 CALL_CRYPTO_SERVICE (RsaGenerateKey
, (RsaContext
, ModulusLength
, PublicExponent
, PublicExponentSize
), FALSE
);
1454 Validates key components of RSA context.
1455 NOTE: This function performs integrity checks on all the RSA key material, so
1456 the RSA key structure must contain all the private key data.
1458 This function validates key components of RSA context in following aspects:
1459 - Whether p is a prime
1460 - Whether q is a prime
1462 - Whether d*e = 1 mod lcm(p-1,q-1)
1464 If RsaContext is NULL, then return FALSE.
1465 If this interface is not supported, then return FALSE.
1467 @param[in] RsaContext Pointer to RSA context to check.
1469 @retval TRUE RSA key components are valid.
1470 @retval FALSE RSA key components are not valid.
1471 @retval FALSE This interface is not supported.
1480 CALL_CRYPTO_SERVICE (RsaCheckKey
, (RsaContext
), FALSE
);
1484 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
1486 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
1488 If the Signature buffer is too small to hold the contents of signature, FALSE
1489 is returned and SigSize is set to the required buffer size to obtain the signature.
1491 If RsaContext is NULL, then return FALSE.
1492 If MessageHash is NULL, then return FALSE.
1493 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
1494 If SigSize is large enough but Signature is NULL, then return FALSE.
1495 If this interface is not supported, then return FALSE.
1497 @param[in] RsaContext Pointer to RSA context for signature generation.
1498 @param[in] MessageHash Pointer to octet message hash to be signed.
1499 @param[in] HashSize Size of the message hash in bytes.
1500 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
1501 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1502 On output, the size of data returned in Signature buffer in bytes.
1504 @retval TRUE Signature successfully generated in PKCS1-v1_5.
1505 @retval FALSE Signature generation failed.
1506 @retval FALSE SigSize is too small.
1507 @retval FALSE This interface is not supported.
1513 IN VOID
*RsaContext
,
1514 IN CONST UINT8
*MessageHash
,
1516 OUT UINT8
*Signature
,
1517 IN OUT UINTN
*SigSize
1520 CALL_CRYPTO_SERVICE (RsaPkcs1Sign
, (RsaContext
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
1524 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
1527 If RsaContext is NULL, then return FALSE.
1528 If MessageHash is NULL, then return FALSE.
1529 If Signature is NULL, then return FALSE.
1530 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
1532 @param[in] RsaContext Pointer to RSA context for signature verification.
1533 @param[in] MessageHash Pointer to octet message hash to be checked.
1534 @param[in] HashSize Size of the message hash in bytes.
1535 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
1536 @param[in] SigSize Size of signature in bytes.
1538 @retval TRUE Valid signature encoded in PKCS1-v1_5.
1539 @retval FALSE Invalid signature or invalid RSA context.
1545 IN VOID
*RsaContext
,
1546 IN CONST UINT8
*MessageHash
,
1548 IN CONST UINT8
*Signature
,
1552 CALL_CRYPTO_SERVICE (RsaPkcs1Verify
, (RsaContext
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
1556 Retrieve the RSA Private Key from the password-protected PEM key data.
1558 If PemData is NULL, then return FALSE.
1559 If RsaContext is NULL, then return FALSE.
1560 If this interface is not supported, then return FALSE.
1562 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
1563 @param[in] PemSize Size of the PEM key data in bytes.
1564 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
1565 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1566 RSA private key component. Use RsaFree() function to free the
1569 @retval TRUE RSA Private Key was retrieved successfully.
1570 @retval FALSE Invalid PEM key data or incorrect password.
1571 @retval FALSE This interface is not supported.
1576 RsaGetPrivateKeyFromPem (
1577 IN CONST UINT8
*PemData
,
1579 IN CONST CHAR8
*Password
,
1580 OUT VOID
**RsaContext
1583 CALL_CRYPTO_SERVICE (RsaGetPrivateKeyFromPem
, (PemData
, PemSize
, Password
, RsaContext
), FALSE
);
1587 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
1589 If Cert is NULL, then return FALSE.
1590 If RsaContext is NULL, then return FALSE.
1591 If this interface is not supported, then return FALSE.
1593 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1594 @param[in] CertSize Size of the X509 certificate in bytes.
1595 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1596 RSA public key component. Use RsaFree() function to free the
1599 @retval TRUE RSA Public Key was retrieved successfully.
1600 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
1601 @retval FALSE This interface is not supported.
1606 RsaGetPublicKeyFromX509 (
1607 IN CONST UINT8
*Cert
,
1609 OUT VOID
**RsaContext
1612 CALL_CRYPTO_SERVICE (RsaGetPublicKeyFromX509
, (Cert
, CertSize
, RsaContext
), FALSE
);
1616 Retrieve the subject bytes from one X.509 certificate.
1618 If Cert is NULL, then return FALSE.
1619 If SubjectSize is NULL, then return FALSE.
1620 If this interface is not supported, then return FALSE.
1622 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1623 @param[in] CertSize Size of the X509 certificate in bytes.
1624 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
1625 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
1626 and the size of buffer returned CertSubject on output.
1628 @retval TRUE The certificate subject retrieved successfully.
1629 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
1630 The SubjectSize will be updated with the required size.
1631 @retval FALSE This interface is not supported.
1636 X509GetSubjectName (
1637 IN CONST UINT8
*Cert
,
1639 OUT UINT8
*CertSubject
,
1640 IN OUT UINTN
*SubjectSize
1643 CALL_CRYPTO_SERVICE (X509GetSubjectName
, (Cert
, CertSize
, CertSubject
, SubjectSize
), FALSE
);
1647 Retrieve the common name (CN) string from one X.509 certificate.
1649 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1650 @param[in] CertSize Size of the X509 certificate in bytes.
1651 @param[out] CommonName Buffer to contain the retrieved certificate common
1652 name string (UTF8). At most CommonNameSize bytes will be
1653 written and the string will be null terminated. May be
1654 NULL in order to determine the size buffer needed.
1655 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
1656 and the size of buffer returned CommonName on output.
1657 If CommonName is NULL then the amount of space needed
1658 in buffer (including the final null) is returned.
1660 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
1661 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
1662 If CommonNameSize is NULL.
1663 If CommonName is not NULL and *CommonNameSize is 0.
1664 If Certificate is invalid.
1665 @retval RETURN_NOT_FOUND If no CommonName entry exists.
1666 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
1667 (including the final null) is returned in the
1668 CommonNameSize parameter.
1669 @retval RETURN_UNSUPPORTED The operation is not supported.
1675 IN CONST UINT8
*Cert
,
1677 OUT CHAR8
*CommonName
, OPTIONAL
1678 IN OUT UINTN
*CommonNameSize
1681 CALL_CRYPTO_SERVICE (X509GetCommonName
, (Cert
, CertSize
, CommonName
, CommonNameSize
), RETURN_UNSUPPORTED
);
1685 Retrieve the organization name (O) string from one X.509 certificate.
1687 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1688 @param[in] CertSize Size of the X509 certificate in bytes.
1689 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
1690 name string. At most NameBufferSize bytes will be
1691 written and the string will be null terminated. May be
1692 NULL in order to determine the size buffer needed.
1693 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
1694 and the size of buffer returned Name on output.
1695 If NameBuffer is NULL then the amount of space needed
1696 in buffer (including the final null) is returned.
1698 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
1699 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
1700 If NameBufferSize is NULL.
1701 If NameBuffer is not NULL and *CommonNameSize is 0.
1702 If Certificate is invalid.
1703 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
1704 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
1705 (including the final null) is returned in the
1706 CommonNameSize parameter.
1707 @retval RETURN_UNSUPPORTED The operation is not supported.
1712 X509GetOrganizationName (
1713 IN CONST UINT8
*Cert
,
1715 OUT CHAR8
*NameBuffer
, OPTIONAL
1716 IN OUT UINTN
*NameBufferSize
1719 CALL_CRYPTO_SERVICE (X509GetOrganizationName
, (Cert
, CertSize
, NameBuffer
, NameBufferSize
), RETURN_UNSUPPORTED
);
1723 Verify one X509 certificate was issued by the trusted CA.
1725 If Cert is NULL, then return FALSE.
1726 If CACert is NULL, then return FALSE.
1727 If this interface is not supported, then return FALSE.
1729 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
1730 @param[in] CertSize Size of the X509 certificate in bytes.
1731 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
1732 @param[in] CACertSize Size of the CA Certificate in bytes.
1734 @retval TRUE The certificate was issued by the trusted CA.
1735 @retval FALSE Invalid certificate or the certificate was not issued by the given
1737 @retval FALSE This interface is not supported.
1743 IN CONST UINT8
*Cert
,
1745 IN CONST UINT8
*CACert
,
1749 CALL_CRYPTO_SERVICE (X509VerifyCert
, (Cert
, CertSize
, CACert
, CACertSize
), FALSE
);
1753 Construct a X509 object from DER-encoded certificate data.
1755 If Cert is NULL, then return FALSE.
1756 If SingleX509Cert is NULL, then return FALSE.
1757 If this interface is not supported, then return FALSE.
1759 @param[in] Cert Pointer to the DER-encoded certificate data.
1760 @param[in] CertSize The size of certificate data in bytes.
1761 @param[out] SingleX509Cert The generated X509 object.
1763 @retval TRUE The X509 object generation succeeded.
1764 @retval FALSE The operation failed.
1765 @retval FALSE This interface is not supported.
1770 X509ConstructCertificate (
1771 IN CONST UINT8
*Cert
,
1773 OUT UINT8
**SingleX509Cert
1776 CALL_CRYPTO_SERVICE (X509ConstructCertificate
, (Cert
, CertSize
, SingleX509Cert
), FALSE
);
1780 Construct a X509 stack object from a list of DER-encoded certificate data.
1782 If X509Stack is NULL, then return FALSE.
1783 If this interface is not supported, then return FALSE.
1785 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
1786 On output, pointer to the X509 stack object with new
1787 inserted X509 certificate.
1788 @param[in] Args VA_LIST marker for the variable argument list.
1789 ... A list of DER-encoded single certificate data followed
1790 by certificate size. A NULL terminates the list. The
1791 pairs are the arguments to X509ConstructCertificate().
1793 @retval TRUE The X509 stack construction succeeded.
1794 @retval FALSE The construction operation failed.
1795 @retval FALSE This interface is not supported.
1800 X509ConstructCertificateStack (
1801 IN OUT UINT8
**X509Stack
,
1808 VA_START (Args
, X509Stack
);
1809 Result
= X509ConstructCertificateStackV (X509Stack
, Args
);
1815 Construct a X509 stack object from a list of DER-encoded certificate data.
1817 If X509Stack is NULL, then return FALSE.
1818 If this interface is not supported, then return FALSE.
1820 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
1821 On output, pointer to the X509 stack object with new
1822 inserted X509 certificate.
1823 @param[in] Args VA_LIST marker for the variable argument list.
1824 A list of DER-encoded single certificate data followed
1825 by certificate size. A NULL terminates the list. The
1826 pairs are the arguments to X509ConstructCertificate().
1828 @retval TRUE The X509 stack construction succeeded.
1829 @retval FALSE The construction operation failed.
1830 @retval FALSE This interface is not supported.
1835 X509ConstructCertificateStackV (
1836 IN OUT UINT8
**X509Stack
,
1840 CALL_CRYPTO_SERVICE (X509ConstructCertificateStackV
, (X509Stack
, Args
), FALSE
);
1844 Release the specified X509 object.
1846 If the interface is not supported, then ASSERT().
1848 @param[in] X509Cert Pointer to the X509 object to be released.
1857 CALL_VOID_CRYPTO_SERVICE (X509Free
, (X509Cert
));
1861 Release the specified X509 stack object.
1863 If the interface is not supported, then ASSERT().
1865 @param[in] X509Stack Pointer to the X509 stack object to be released.
1874 CALL_VOID_CRYPTO_SERVICE (X509StackFree
, (X509Stack
));
1878 Retrieve the TBSCertificate from one given X.509 certificate.
1880 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
1881 @param[in] CertSize Size of the X509 certificate in bytes.
1882 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
1883 @param[out] TBSCertSize Size of the TBS certificate in bytes.
1885 If Cert is NULL, then return FALSE.
1886 If TBSCert is NULL, then return FALSE.
1887 If TBSCertSize is NULL, then return FALSE.
1888 If this interface is not supported, then return FALSE.
1890 @retval TRUE The TBSCertificate was retrieved successfully.
1891 @retval FALSE Invalid X.509 certificate.
1897 IN CONST UINT8
*Cert
,
1899 OUT UINT8
**TBSCert
,
1900 OUT UINTN
*TBSCertSize
1903 CALL_CRYPTO_SERVICE (X509GetTBSCert
, (Cert
, CertSize
, TBSCert
, TBSCertSize
), FALSE
);
1907 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
1908 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
1910 If Password or Salt or OutKey is NULL, then return FALSE.
1911 If the hash algorithm could not be determined, then return FALSE.
1912 If this interface is not supported, then return FALSE.
1914 @param[in] PasswordLength Length of input password in bytes.
1915 @param[in] Password Pointer to the array for the password.
1916 @param[in] SaltLength Size of the Salt in bytes.
1917 @param[in] Salt Pointer to the Salt.
1918 @param[in] IterationCount Number of iterations to perform. Its value should be
1919 greater than or equal to 1.
1920 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
1921 NOTE: DigestSize will be used to determine the hash algorithm.
1922 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
1923 @param[in] KeyLength Size of the derived key buffer in bytes.
1924 @param[out] OutKey Pointer to the output derived key buffer.
1926 @retval TRUE A key was derived successfully.
1927 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
1928 @retval FALSE The hash algorithm could not be determined from the digest size.
1929 @retval FALSE The key derivation operation failed.
1930 @retval FALSE This interface is not supported.
1936 IN UINTN PasswordLength
,
1937 IN CONST CHAR8
*Password
,
1938 IN UINTN SaltLength
,
1939 IN CONST UINT8
*Salt
,
1940 IN UINTN IterationCount
,
1941 IN UINTN DigestSize
,
1946 CALL_CRYPTO_SERVICE (Pkcs5HashPassword
, (PasswordLength
, Password
, SaltLength
, Salt
, IterationCount
, DigestSize
, KeyLength
, OutKey
), FALSE
);
1950 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
1951 encrypted message in a newly allocated buffer.
1953 Things that can cause a failure include:
1954 - X509 key size does not match any known key size.
1955 - Fail to parse X509 certificate.
1956 - Fail to allocate an intermediate buffer.
1957 - Null pointer provided for a non-optional parameter.
1958 - Data size is too large for the provided key size (max size is a function of key size
1959 and hash digest size).
1961 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
1962 will be used to encrypt the data.
1963 @param[in] PublicKeySize Size of the X509 cert buffer.
1964 @param[in] InData Data to be encrypted.
1965 @param[in] InDataSize Size of the data buffer.
1966 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
1967 to be used when initializing the PRNG. NULL otherwise.
1968 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
1970 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
1972 @param[out] EncryptedDataSize Size of the encrypted message buffer.
1974 @retval TRUE Encryption was successful.
1975 @retval FALSE Encryption failed.
1981 IN CONST UINT8
*PublicKey
,
1982 IN UINTN PublicKeySize
,
1984 IN UINTN InDataSize
,
1985 IN CONST UINT8
*PrngSeed
, OPTIONAL
1986 IN UINTN PrngSeedSize
, OPTIONAL
1987 OUT UINT8
**EncryptedData
,
1988 OUT UINTN
*EncryptedDataSize
1991 CALL_CRYPTO_SERVICE (Pkcs1v2Encrypt
, (PublicKey
, PublicKeySize
, InData
, InDataSize
, PrngSeed
, PrngSeedSize
, EncryptedData
, EncryptedDataSize
), FALSE
);
1995 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
1996 Cryptographic Message Syntax Standard". The input signed data could be wrapped
1997 in a ContentInfo structure.
1999 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2000 return FALSE. If P7Length overflow, then return FALSE.
2001 If this interface is not supported, then return FALSE.
2003 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2004 @param[in] P7Length Length of the PKCS#7 message in bytes.
2005 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2006 It's caller's responsibility to free the buffer with
2008 This data structure is EFI_CERT_STACK type.
2009 @param[out] StackLength Length of signer's certificates in bytes.
2010 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2011 It's caller's responsibility to free the buffer with
2013 @param[out] CertLength Length of the trusted certificate in bytes.
2015 @retval TRUE The operation is finished successfully.
2016 @retval FALSE Error occurs during the operation.
2017 @retval FALSE This interface is not supported.
2023 IN CONST UINT8
*P7Data
,
2025 OUT UINT8
**CertStack
,
2026 OUT UINTN
*StackLength
,
2027 OUT UINT8
**TrustedCert
,
2028 OUT UINTN
*CertLength
2031 CALL_CRYPTO_SERVICE (Pkcs7GetSigners
, (P7Data
, P7Length
, CertStack
, StackLength
, TrustedCert
, CertLength
), FALSE
);
2035 Wrap function to use free() to free allocated memory for certificates.
2037 If this interface is not supported, then ASSERT().
2039 @param[in] Certs Pointer to the certificates to be freed.
2048 CALL_VOID_CRYPTO_SERVICE (Pkcs7FreeSigners
, (Certs
));
2052 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2053 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2054 unchained to the signer's certificates.
2055 The input signed data could be wrapped in a ContentInfo structure.
2057 @param[in] P7Data Pointer to the PKCS#7 message.
2058 @param[in] P7Length Length of the PKCS#7 message in bytes.
2059 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2060 certificate. It's caller's responsibility to free the buffer
2061 with Pkcs7FreeSigners().
2062 This data structure is EFI_CERT_STACK type.
2063 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2064 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2065 responsibility to free the buffer with Pkcs7FreeSigners().
2066 This data structure is EFI_CERT_STACK type.
2067 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2069 @retval TRUE The operation is finished successfully.
2070 @retval FALSE Error occurs during the operation.
2075 Pkcs7GetCertificatesList (
2076 IN CONST UINT8
*P7Data
,
2078 OUT UINT8
**SignerChainCerts
,
2079 OUT UINTN
*ChainLength
,
2080 OUT UINT8
**UnchainCerts
,
2081 OUT UINTN
*UnchainLength
2084 CALL_CRYPTO_SERVICE (Pkcs7GetCertificatesList
, (P7Data
, P7Length
, SignerChainCerts
, ChainLength
, UnchainCerts
, UnchainLength
), FALSE
);
2088 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2089 Syntax Standard, version 1.5". This interface is only intended to be used for
2090 application to perform PKCS#7 functionality validation.
2092 If this interface is not supported, then return FALSE.
2094 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2096 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2097 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2099 @param[in] InData Pointer to the content to be signed.
2100 @param[in] InDataSize Size of InData in bytes.
2101 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2102 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2103 include in the PKCS#7 signedData (e.g. any intermediate
2105 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2106 responsibility to free the buffer with FreePool().
2107 @param[out] SignedDataSize Size of SignedData in bytes.
2109 @retval TRUE PKCS#7 data signing succeeded.
2110 @retval FALSE PKCS#7 data signing failed.
2111 @retval FALSE This interface is not supported.
2117 IN CONST UINT8
*PrivateKey
,
2118 IN UINTN PrivateKeySize
,
2119 IN CONST UINT8
*KeyPassword
,
2121 IN UINTN InDataSize
,
2123 IN UINT8
*OtherCerts OPTIONAL
,
2124 OUT UINT8
**SignedData
,
2125 OUT UINTN
*SignedDataSize
2128 CALL_CRYPTO_SERVICE (Pkcs7Sign
, (PrivateKey
, PrivateKeySize
, KeyPassword
, InData
, InDataSize
, SignCert
, OtherCerts
, SignedData
, SignedDataSize
), FALSE
);
2132 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2133 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2134 in a ContentInfo structure.
2136 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2137 If P7Length, CertLength or DataLength overflow, then return FALSE.
2138 If this interface is not supported, then return FALSE.
2140 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2141 @param[in] P7Length Length of the PKCS#7 message in bytes.
2142 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2143 is used for certificate chain verification.
2144 @param[in] CertLength Length of the trusted certificate in bytes.
2145 @param[in] InData Pointer to the content to be verified.
2146 @param[in] DataLength Length of InData in bytes.
2148 @retval TRUE The specified PKCS#7 signed data is valid.
2149 @retval FALSE Invalid PKCS#7 signed data.
2150 @retval FALSE This interface is not supported.
2156 IN CONST UINT8
*P7Data
,
2158 IN CONST UINT8
*TrustedCert
,
2159 IN UINTN CertLength
,
2160 IN CONST UINT8
*InData
,
2164 CALL_CRYPTO_SERVICE (Pkcs7Verify
, (P7Data
, P7Length
, TrustedCert
, CertLength
, InData
, DataLength
), FALSE
);
2168 This function receives a PKCS7 formatted signature, and then verifies that
2169 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
2170 leaf signing certificate.
2171 Note that this function does not validate the certificate chain.
2173 Applications for custom EKU's are quite flexible. For example, a policy EKU
2174 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
2175 certificate issued might also contain this EKU, thus constraining the
2176 sub-ordinate certificate. Other applications might allow a certificate
2177 embedded in a device to specify that other Object Identifiers (OIDs) are
2178 present which contains binary data specifying custom capabilities that
2179 the device is able to do.
2181 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
2182 containing the content block with both the signature,
2183 the signer's certificate, and any necessary intermediate
2185 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
2186 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
2187 required EKUs that must be present in the signature.
2188 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
2189 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
2190 must be present in the leaf signer. If it is
2191 FALSE, then we will succeed if we find any
2192 of the specified EKU's.
2194 @retval EFI_SUCCESS The required EKUs were found in the signature.
2195 @retval EFI_INVALID_PARAMETER A parameter was invalid.
2196 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
2201 VerifyEKUsInPkcs7Signature (
2202 IN CONST UINT8
*Pkcs7Signature
,
2203 IN CONST UINT32 SignatureSize
,
2204 IN CONST CHAR8
*RequiredEKUs
[],
2205 IN CONST UINT32 RequiredEKUsSize
,
2206 IN BOOLEAN RequireAllPresent
2209 CALL_CRYPTO_SERVICE (VerifyEKUsInPkcs7Signature
, (Pkcs7Signature
, SignatureSize
, RequiredEKUs
, RequiredEKUsSize
, RequireAllPresent
), FALSE
);
2214 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2215 data could be wrapped in a ContentInfo structure.
2217 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2218 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2220 Caution: This function may receive untrusted input. So this function will do
2221 basic check for PKCS#7 data structure.
2223 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2224 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2225 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2226 It's caller's responsibility to free the buffer with FreePool().
2227 @param[out] ContentSize The size of the extracted content in bytes.
2229 @retval TRUE The P7Data was correctly formatted for processing.
2230 @retval FALSE The P7Data was not correctly formatted for processing.
2235 Pkcs7GetAttachedContent (
2236 IN CONST UINT8
*P7Data
,
2239 OUT UINTN
*ContentSize
2242 CALL_CRYPTO_SERVICE (Pkcs7GetAttachedContent
, (P7Data
, P7Length
, Content
, ContentSize
), FALSE
);
2246 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2247 Authenticode Portable Executable Signature Format".
2249 If AuthData is NULL, then return FALSE.
2250 If ImageHash is NULL, then return FALSE.
2251 If this interface is not supported, then return FALSE.
2253 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2254 PE/COFF image to be verified.
2255 @param[in] DataSize Size of the Authenticode Signature in bytes.
2256 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2257 is used for certificate chain verification.
2258 @param[in] CertSize Size of the trusted certificate in bytes.
2259 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2260 for calculating the image hash value is described in Authenticode
2262 @param[in] HashSize Size of Image hash value in bytes.
2264 @retval TRUE The specified Authenticode Signature is valid.
2265 @retval FALSE Invalid Authenticode Signature.
2266 @retval FALSE This interface is not supported.
2271 AuthenticodeVerify (
2272 IN CONST UINT8
*AuthData
,
2274 IN CONST UINT8
*TrustedCert
,
2276 IN CONST UINT8
*ImageHash
,
2280 CALL_CRYPTO_SERVICE (AuthenticodeVerify
, (AuthData
, DataSize
, TrustedCert
, CertSize
, ImageHash
, HashSize
), FALSE
);
2284 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2287 If AuthData is NULL, then return FALSE.
2288 If this interface is not supported, then return FALSE.
2290 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2291 PE/COFF image to be verified.
2292 @param[in] DataSize Size of the Authenticode Signature in bytes.
2293 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2294 is used for TSA certificate chain verification.
2295 @param[in] CertSize Size of the trusted certificate in bytes.
2296 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2299 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2300 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2305 ImageTimestampVerify (
2306 IN CONST UINT8
*AuthData
,
2308 IN CONST UINT8
*TsaCert
,
2310 OUT EFI_TIME
*SigningTime
2313 CALL_CRYPTO_SERVICE (ImageTimestampVerify
, (AuthData
, DataSize
, TsaCert
, CertSize
, SigningTime
), FALSE
);
2316 //=====================================================================================
2317 // DH Key Exchange Primitive
2318 //=====================================================================================
2321 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
2323 @return Pointer to the Diffie-Hellman Context that has been initialized.
2324 If the allocations fails, DhNew() returns NULL.
2325 If the interface is not supported, DhNew() returns NULL.
2334 CALL_CRYPTO_SERVICE (DhNew
, (), NULL
);
2338 Release the specified DH context.
2340 If the interface is not supported, then ASSERT().
2342 @param[in] DhContext Pointer to the DH context to be released.
2351 CALL_VOID_CRYPTO_SERVICE (DhFree
, (DhContext
));
2355 Generates DH parameter.
2357 Given generator g, and length of prime number p in bits, this function generates p,
2358 and sets DH context according to value of g and p.
2360 Before this function can be invoked, pseudorandom number generator must be correctly
2361 initialized by RandomSeed().
2363 If DhContext is NULL, then return FALSE.
2364 If Prime is NULL, then return FALSE.
2365 If this interface is not supported, then return FALSE.
2367 @param[in, out] DhContext Pointer to the DH context.
2368 @param[in] Generator Value of generator.
2369 @param[in] PrimeLength Length in bits of prime to be generated.
2370 @param[out] Prime Pointer to the buffer to receive the generated prime number.
2372 @retval TRUE DH parameter generation succeeded.
2373 @retval FALSE Value of Generator is not supported.
2374 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
2375 @retval FALSE This interface is not supported.
2380 DhGenerateParameter (
2381 IN OUT VOID
*DhContext
,
2383 IN UINTN PrimeLength
,
2387 CALL_CRYPTO_SERVICE (DhGenerateParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
2391 Sets generator and prime parameters for DH.
2393 Given generator g, and prime number p, this function and sets DH
2394 context accordingly.
2396 If DhContext is NULL, then return FALSE.
2397 If Prime is NULL, then return FALSE.
2398 If this interface is not supported, then return FALSE.
2400 @param[in, out] DhContext Pointer to the DH context.
2401 @param[in] Generator Value of generator.
2402 @param[in] PrimeLength Length in bits of prime to be generated.
2403 @param[in] Prime Pointer to the prime number.
2405 @retval TRUE DH parameter setting succeeded.
2406 @retval FALSE Value of Generator is not supported.
2407 @retval FALSE Value of Generator is not suitable for the Prime.
2408 @retval FALSE Value of Prime is not a prime number.
2409 @retval FALSE Value of Prime is not a safe prime number.
2410 @retval FALSE This interface is not supported.
2416 IN OUT VOID
*DhContext
,
2418 IN UINTN PrimeLength
,
2419 IN CONST UINT8
*Prime
2422 CALL_CRYPTO_SERVICE (DhSetParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
2426 Generates DH public key.
2428 This function generates random secret exponent, and computes the public key, which is
2429 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
2430 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
2431 PublicKeySize is set to the required buffer size to obtain the public key.
2433 If DhContext is NULL, then return FALSE.
2434 If PublicKeySize is NULL, then return FALSE.
2435 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
2436 If this interface is not supported, then return FALSE.
2438 @param[in, out] DhContext Pointer to the DH context.
2439 @param[out] PublicKey Pointer to the buffer to receive generated public key.
2440 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
2441 On output, the size of data returned in PublicKey buffer in bytes.
2443 @retval TRUE DH public key generation succeeded.
2444 @retval FALSE DH public key generation failed.
2445 @retval FALSE PublicKeySize is not large enough.
2446 @retval FALSE This interface is not supported.
2452 IN OUT VOID
*DhContext
,
2453 OUT UINT8
*PublicKey
,
2454 IN OUT UINTN
*PublicKeySize
2457 CALL_CRYPTO_SERVICE (DhGenerateKey
, (DhContext
, PublicKey
, PublicKeySize
), FALSE
);
2461 Computes exchanged common key.
2463 Given peer's public key, this function computes the exchanged common key, based on its own
2464 context including value of prime modulus and random secret exponent.
2466 If DhContext is NULL, then return FALSE.
2467 If PeerPublicKey is NULL, then return FALSE.
2468 If KeySize is NULL, then return FALSE.
2469 If Key is NULL, then return FALSE.
2470 If KeySize is not large enough, then return FALSE.
2471 If this interface is not supported, then return FALSE.
2473 @param[in, out] DhContext Pointer to the DH context.
2474 @param[in] PeerPublicKey Pointer to the peer's public key.
2475 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
2476 @param[out] Key Pointer to the buffer to receive generated key.
2477 @param[in, out] KeySize On input, the size of Key buffer in bytes.
2478 On output, the size of data returned in Key buffer in bytes.
2480 @retval TRUE DH exchanged key generation succeeded.
2481 @retval FALSE DH exchanged key generation failed.
2482 @retval FALSE KeySize is not large enough.
2483 @retval FALSE This interface is not supported.
2489 IN OUT VOID
*DhContext
,
2490 IN CONST UINT8
*PeerPublicKey
,
2491 IN UINTN PeerPublicKeySize
,
2493 IN OUT UINTN
*KeySize
2496 CALL_CRYPTO_SERVICE (DhComputeKey
, (DhContext
, PeerPublicKey
, PeerPublicKeySize
, Key
, KeySize
), FALSE
);
2499 //=====================================================================================
2500 // Pseudo-Random Generation Primitive
2501 //=====================================================================================
2504 Sets up the seed value for the pseudorandom number generator.
2506 This function sets up the seed value for the pseudorandom number generator.
2507 If Seed is not NULL, then the seed passed in is used.
2508 If Seed is NULL, then default seed is used.
2509 If this interface is not supported, then return FALSE.
2511 @param[in] Seed Pointer to seed value.
2512 If NULL, default seed is used.
2513 @param[in] SeedSize Size of seed value.
2514 If Seed is NULL, this parameter is ignored.
2516 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
2517 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
2518 @retval FALSE This interface is not supported.
2524 IN CONST UINT8
*Seed OPTIONAL
,
2528 CALL_CRYPTO_SERVICE (RandomSeed
, (Seed
, SeedSize
), FALSE
);
2532 Generates a pseudorandom byte stream of the specified size.
2534 If Output is NULL, then return FALSE.
2535 If this interface is not supported, then return FALSE.
2537 @param[out] Output Pointer to buffer to receive random value.
2538 @param[in] Size Size of random bytes to generate.
2540 @retval TRUE Pseudorandom byte stream generated successfully.
2541 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
2542 @retval FALSE This interface is not supported.
2552 CALL_CRYPTO_SERVICE (RandomBytes
, (Output
, Size
), FALSE
);
2555 //=====================================================================================
2556 // Key Derivation Function Primitive
2557 //=====================================================================================
2560 Derive key data using HMAC-SHA256 based KDF.
2562 @param[in] Key Pointer to the user-supplied key.
2563 @param[in] KeySize Key size in bytes.
2564 @param[in] Salt Pointer to the salt(non-secret) value.
2565 @param[in] SaltSize Salt size in bytes.
2566 @param[in] Info Pointer to the application specific info.
2567 @param[in] InfoSize Info size in bytes.
2568 @param[out] Out Pointer to buffer to receive hkdf value.
2569 @param[in] OutSize Size of hkdf bytes to generate.
2571 @retval TRUE Hkdf generated successfully.
2572 @retval FALSE Hkdf generation failed.
2577 HkdfSha256ExtractAndExpand (
2578 IN CONST UINT8
*Key
,
2580 IN CONST UINT8
*Salt
,
2582 IN CONST UINT8
*Info
,
2588 CALL_CRYPTO_SERVICE (HkdfSha256ExtractAndExpand
, (Key
, KeySize
, Salt
, SaltSize
, Info
, InfoSize
, Out
, OutSize
), FALSE
);
2592 Initializes the OpenSSL library.
2594 This function registers ciphers and digests used directly and indirectly
2595 by SSL/TLS, and initializes the readable error messages.
2596 This function must be called before any other action takes places.
2598 @retval TRUE The OpenSSL library has been initialized.
2599 @retval FALSE Failed to initialize the OpenSSL library.
2608 CALL_CRYPTO_SERVICE (TlsInitialize
, (), FALSE
);
2612 Free an allocated SSL_CTX object.
2614 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
2623 CALL_VOID_CRYPTO_SERVICE (TlsCtxFree
, (TlsCtx
));
2627 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
2630 @param[in] MajorVer Major Version of TLS/SSL Protocol.
2631 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
2633 @return Pointer to an allocated SSL_CTX object.
2634 If the creation failed, TlsCtxNew() returns NULL.
2644 CALL_CRYPTO_SERVICE (TlsCtxNew
, (MajorVer
, MinorVer
), NULL
);
2648 Free an allocated TLS object.
2650 This function removes the TLS object pointed to by Tls and frees up the
2651 allocated memory. If Tls is NULL, nothing is done.
2653 @param[in] Tls Pointer to the TLS object to be freed.
2662 CALL_VOID_CRYPTO_SERVICE (TlsFree
, (Tls
));
2666 Create a new TLS object for a connection.
2668 This function creates a new TLS object for a connection. The new object
2669 inherits the setting of the underlying context TlsCtx: connection method,
2670 options, verification setting.
2672 @param[in] TlsCtx Pointer to the SSL_CTX object.
2674 @return Pointer to an allocated SSL object.
2675 If the creation failed, TlsNew() returns NULL.
2684 CALL_CRYPTO_SERVICE (TlsNew
, (TlsCtx
), NULL
);
2688 Checks if the TLS handshake was done.
2690 This function will check if the specified TLS handshake was done.
2692 @param[in] Tls Pointer to the TLS object for handshake state checking.
2694 @retval TRUE The TLS handshake was done.
2695 @retval FALSE The TLS handshake was not done.
2704 CALL_CRYPTO_SERVICE (TlsInHandshake
, (Tls
), FALSE
);
2708 Perform a TLS/SSL handshake.
2710 This function will perform a TLS/SSL handshake.
2712 @param[in] Tls Pointer to the TLS object for handshake operation.
2713 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
2714 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
2716 @param[out] BufferOut Pointer to the buffer to hold the built packet.
2717 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
2718 the buffer size provided by the caller. On output, it
2719 is the buffer size in fact needed to contain the
2722 @retval EFI_SUCCESS The required TLS packet is built successfully.
2723 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2725 BufferIn is NULL but BufferInSize is NOT 0.
2726 BufferInSize is 0 but BufferIn is NOT NULL.
2727 BufferOutSize is NULL.
2728 BufferOut is NULL if *BufferOutSize is not zero.
2729 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
2730 @retval EFI_ABORTED Something wrong during handshake.
2737 IN UINT8
*BufferIn
, OPTIONAL
2738 IN UINTN BufferInSize
, OPTIONAL
2739 OUT UINT8
*BufferOut
, OPTIONAL
2740 IN OUT UINTN
*BufferOutSize
2743 CALL_CRYPTO_SERVICE (TlsDoHandshake
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
2747 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
2748 TLS session has errors and the response packet needs to be Alert message based on error type.
2750 @param[in] Tls Pointer to the TLS object for state checking.
2751 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
2752 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
2754 @param[out] BufferOut Pointer to the buffer to hold the built packet.
2755 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
2756 the buffer size provided by the caller. On output, it
2757 is the buffer size in fact needed to contain the
2760 @retval EFI_SUCCESS The required TLS packet is built successfully.
2761 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2763 BufferIn is NULL but BufferInSize is NOT 0.
2764 BufferInSize is 0 but BufferIn is NOT NULL.
2765 BufferOutSize is NULL.
2766 BufferOut is NULL if *BufferOutSize is not zero.
2767 @retval EFI_ABORTED An error occurred.
2768 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
2775 IN UINT8
*BufferIn
, OPTIONAL
2776 IN UINTN BufferInSize
, OPTIONAL
2777 OUT UINT8
*BufferOut
, OPTIONAL
2778 IN OUT UINTN
*BufferOutSize
2781 CALL_CRYPTO_SERVICE (TlsHandleAlert
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
2785 Build the CloseNotify packet.
2787 @param[in] Tls Pointer to the TLS object for state checking.
2788 @param[in, out] Buffer Pointer to the buffer to hold the built packet.
2789 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
2790 the buffer size provided by the caller. On output, it
2791 is the buffer size in fact needed to contain the
2794 @retval EFI_SUCCESS The required TLS packet is built successfully.
2795 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2798 Buffer is NULL if *BufferSize is not zero.
2799 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
2806 IN OUT UINT8
*Buffer
,
2807 IN OUT UINTN
*BufferSize
2810 CALL_CRYPTO_SERVICE (TlsCloseNotify
, (Tls
, Buffer
, BufferSize
), EFI_UNSUPPORTED
);
2814 Attempts to read bytes from one TLS object and places the data in Buffer.
2816 This function will attempt to read BufferSize bytes from the TLS object
2817 and places the data in Buffer.
2819 @param[in] Tls Pointer to the TLS object.
2820 @param[in,out] Buffer Pointer to the buffer to store the data.
2821 @param[in] BufferSize The size of Buffer in bytes.
2823 @retval >0 The amount of data successfully read from the TLS object.
2824 @retval <=0 No data was successfully read.
2831 IN OUT VOID
*Buffer
,
2835 CALL_CRYPTO_SERVICE (TlsCtrlTrafficOut
, (Tls
, Buffer
, BufferSize
), 0);
2839 Attempts to write data from the buffer to TLS object.
2841 This function will attempt to write BufferSize bytes data from the Buffer
2844 @param[in] Tls Pointer to the TLS object.
2845 @param[in] Buffer Pointer to the data buffer.
2846 @param[in] BufferSize The size of Buffer in bytes.
2848 @retval >0 The amount of data successfully written to the TLS object.
2849 @retval <=0 No data was successfully written.
2860 CALL_CRYPTO_SERVICE (TlsCtrlTrafficIn
, (Tls
, Buffer
, BufferSize
), 0);
2864 Attempts to read bytes from the specified TLS connection into the buffer.
2866 This function tries to read BufferSize bytes data from the specified TLS
2867 connection into the Buffer.
2869 @param[in] Tls Pointer to the TLS connection for data reading.
2870 @param[in,out] Buffer Pointer to the data buffer.
2871 @param[in] BufferSize The size of Buffer in bytes.
2873 @retval >0 The read operation was successful, and return value is the
2874 number of bytes actually read from the TLS connection.
2875 @retval <=0 The read operation was not successful.
2882 IN OUT VOID
*Buffer
,
2886 CALL_CRYPTO_SERVICE (TlsRead
, (Tls
, Buffer
, BufferSize
), 0);
2890 Attempts to write data to a TLS connection.
2892 This function tries to write BufferSize bytes data from the Buffer into the
2893 specified TLS connection.
2895 @param[in] Tls Pointer to the TLS connection for data writing.
2896 @param[in] Buffer Pointer to the data buffer.
2897 @param[in] BufferSize The size of Buffer in bytes.
2899 @retval >0 The write operation was successful, and return value is the
2900 number of bytes actually written to the TLS connection.
2901 @retval <=0 The write operation was not successful.
2912 CALL_CRYPTO_SERVICE (TlsWrite
, (Tls
, Buffer
, BufferSize
), 0);
2916 Set a new TLS/SSL method for a particular TLS object.
2918 This function sets a new TLS/SSL method for a particular TLS object.
2920 @param[in] Tls Pointer to a TLS object.
2921 @param[in] MajorVer Major Version of TLS/SSL Protocol.
2922 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
2924 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
2925 @retval EFI_INVALID_PARAMETER The parameter is invalid.
2926 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
2937 CALL_CRYPTO_SERVICE (TlsSetVersion
, (Tls
, MajorVer
, MinorVer
), EFI_UNSUPPORTED
);
2941 Set TLS object to work in client or server mode.
2943 This function prepares a TLS object to work in client or server mode.
2945 @param[in] Tls Pointer to a TLS object.
2946 @param[in] IsServer Work in server mode.
2948 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
2949 @retval EFI_INVALID_PARAMETER The parameter is invalid.
2950 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
2955 TlsSetConnectionEnd (
2960 CALL_CRYPTO_SERVICE (TlsSetConnectionEnd
, (Tls
, IsServer
), EFI_UNSUPPORTED
);
2964 Set the ciphers list to be used by the TLS object.
2966 This function sets the ciphers for use by a specified TLS object.
2968 @param[in] Tls Pointer to a TLS object.
2969 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
2970 cipher identifier comes from the TLS Cipher Suite
2971 Registry of the IANA, interpreting Byte1 and Byte2
2972 in network (big endian) byte order.
2973 @param[in] CipherNum The number of cipher in the list.
2975 @retval EFI_SUCCESS The ciphers list was set successfully.
2976 @retval EFI_INVALID_PARAMETER The parameter is invalid.
2977 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
2978 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
2985 IN UINT16
*CipherId
,
2989 CALL_CRYPTO_SERVICE (TlsSetCipherList
, (Tls
, CipherId
, CipherNum
), EFI_UNSUPPORTED
);
2993 Set the compression method for TLS/SSL operations.
2995 This function handles TLS/SSL integrated compression methods.
2997 @param[in] CompMethod The compression method ID.
2999 @retval EFI_SUCCESS The compression method for the communication was
3001 @retval EFI_UNSUPPORTED Unsupported compression method.
3006 TlsSetCompressionMethod (
3010 CALL_CRYPTO_SERVICE (TlsSetCompressionMethod
, (CompMethod
), EFI_UNSUPPORTED
);
3014 Set peer certificate verification mode for the TLS connection.
3016 This function sets the verification mode flags for the TLS connection.
3018 @param[in] Tls Pointer to the TLS object.
3019 @param[in] VerifyMode A set of logically or'ed verification mode flags.
3026 IN UINT32 VerifyMode
3029 CALL_VOID_CRYPTO_SERVICE (TlsSetVerify
, (Tls
, VerifyMode
));
3033 Set the specified host name to be verified.
3035 @param[in] Tls Pointer to the TLS object.
3036 @param[in] Flags The setting flags during the validation.
3037 @param[in] HostName The specified host name to be verified.
3039 @retval EFI_SUCCESS The HostName setting was set successfully.
3040 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3041 @retval EFI_ABORTED Invalid HostName setting.
3052 CALL_CRYPTO_SERVICE (TlsSetVerifyHost
, (Tls
, Flags
, HostName
), EFI_UNSUPPORTED
);
3056 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
3058 This function sets a session ID to be used when the TLS/SSL connection is
3061 @param[in] Tls Pointer to the TLS object.
3062 @param[in] SessionId Session ID data used for session resumption.
3063 @param[in] SessionIdLen Length of Session ID in bytes.
3065 @retval EFI_SUCCESS Session ID was set successfully.
3066 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3067 @retval EFI_UNSUPPORTED No available session for ID setting.
3074 IN UINT8
*SessionId
,
3075 IN UINT16 SessionIdLen
3078 CALL_CRYPTO_SERVICE (TlsSetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
3082 Adds the CA to the cert store when requesting Server or Client authentication.
3084 This function adds the CA certificate to the list of CAs when requesting
3085 Server or Client authentication for the chosen TLS connection.
3087 @param[in] Tls Pointer to the TLS object.
3088 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3089 X.509 certificate or PEM-encoded X.509 certificate.
3090 @param[in] DataSize The size of data buffer in bytes.
3092 @retval EFI_SUCCESS The operation succeeded.
3093 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3094 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3095 @retval EFI_ABORTED Invalid X.509 certificate.
3100 TlsSetCaCertificate (
3106 CALL_CRYPTO_SERVICE (TlsSetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3110 Loads the local public certificate into the specified TLS object.
3112 This function loads the X.509 certificate into the specified TLS object
3113 for TLS negotiation.
3115 @param[in] Tls Pointer to the TLS object.
3116 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3117 X.509 certificate or PEM-encoded X.509 certificate.
3118 @param[in] DataSize The size of data buffer in bytes.
3120 @retval EFI_SUCCESS The operation succeeded.
3121 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3122 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3123 @retval EFI_ABORTED Invalid X.509 certificate.
3128 TlsSetHostPublicCert (
3134 CALL_CRYPTO_SERVICE (TlsSetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3138 Adds the local private key to the specified TLS object.
3140 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
3141 key) into the specified TLS object for TLS negotiation.
3143 @param[in] Tls Pointer to the TLS object.
3144 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
3145 or PKCS#8 private key.
3146 @param[in] DataSize The size of data buffer in bytes.
3148 @retval EFI_SUCCESS The operation succeeded.
3149 @retval EFI_UNSUPPORTED This function is not supported.
3150 @retval EFI_ABORTED Invalid private key data.
3155 TlsSetHostPrivateKey (
3161 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3165 Adds the CA-supplied certificate revocation list for certificate validation.
3167 This function adds the CA-supplied certificate revocation list data for
3168 certificate validity checking.
3170 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
3171 @param[in] DataSize The size of data buffer in bytes.
3173 @retval EFI_SUCCESS The operation succeeded.
3174 @retval EFI_UNSUPPORTED This function is not supported.
3175 @retval EFI_ABORTED Invalid CRL data.
3180 TlsSetCertRevocationList (
3185 CALL_CRYPTO_SERVICE (TlsSetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);
3189 Gets the protocol version used by the specified TLS connection.
3191 This function returns the protocol version used by the specified TLS
3194 If Tls is NULL, then ASSERT().
3196 @param[in] Tls Pointer to the TLS object.
3198 @return The protocol version of the specified TLS connection.
3207 CALL_CRYPTO_SERVICE (TlsGetVersion
, (Tls
), 0);
3211 Gets the connection end of the specified TLS connection.
3213 This function returns the connection end (as client or as server) used by
3214 the specified TLS connection.
3216 If Tls is NULL, then ASSERT().
3218 @param[in] Tls Pointer to the TLS object.
3220 @return The connection end used by the specified TLS connection.
3225 TlsGetConnectionEnd (
3229 CALL_CRYPTO_SERVICE (TlsGetConnectionEnd
, (Tls
), 0);
3233 Gets the cipher suite used by the specified TLS connection.
3235 This function returns current cipher suite used by the specified
3238 @param[in] Tls Pointer to the TLS object.
3239 @param[in,out] CipherId The cipher suite used by the TLS object.
3241 @retval EFI_SUCCESS The cipher suite was returned successfully.
3242 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3243 @retval EFI_UNSUPPORTED Unsupported cipher suite.
3248 TlsGetCurrentCipher (
3250 IN OUT UINT16
*CipherId
3253 CALL_CRYPTO_SERVICE (TlsGetCurrentCipher
, (Tls
, CipherId
), EFI_UNSUPPORTED
);
3257 Gets the compression methods used by the specified TLS connection.
3259 This function returns current integrated compression methods used by
3260 the specified TLS connection.
3262 @param[in] Tls Pointer to the TLS object.
3263 @param[in,out] CompressionId The current compression method used by
3266 @retval EFI_SUCCESS The compression method was returned successfully.
3267 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3268 @retval EFI_ABORTED Invalid Compression method.
3269 @retval EFI_UNSUPPORTED This function is not supported.
3274 TlsGetCurrentCompressionId (
3276 IN OUT UINT8
*CompressionId
3279 CALL_CRYPTO_SERVICE (TlsGetCurrentCompressionId
, (Tls
, CompressionId
), EFI_UNSUPPORTED
);
3283 Gets the verification mode currently set in the TLS connection.
3285 This function returns the peer verification mode currently set in the
3286 specified TLS connection.
3288 If Tls is NULL, then ASSERT().
3290 @param[in] Tls Pointer to the TLS object.
3292 @return The verification mode set in the specified TLS connection.
3301 CALL_CRYPTO_SERVICE (TlsGetVerify
, (Tls
), 0);
3305 Gets the session ID used by the specified TLS connection.
3307 This function returns the TLS/SSL session ID currently used by the
3308 specified TLS connection.
3310 @param[in] Tls Pointer to the TLS object.
3311 @param[in,out] SessionId Buffer to contain the returned session ID.
3312 @param[in,out] SessionIdLen The length of Session ID in bytes.
3314 @retval EFI_SUCCESS The Session ID was returned successfully.
3315 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3316 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
3323 IN OUT UINT8
*SessionId
,
3324 IN OUT UINT16
*SessionIdLen
3327 CALL_CRYPTO_SERVICE (TlsGetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
3331 Gets the client random data used in the specified TLS connection.
3333 This function returns the TLS/SSL client random data currently used in
3334 the specified TLS connection.
3336 @param[in] Tls Pointer to the TLS object.
3337 @param[in,out] ClientRandom Buffer to contain the returned client
3338 random data (32 bytes).
3343 TlsGetClientRandom (
3345 IN OUT UINT8
*ClientRandom
3348 CALL_VOID_CRYPTO_SERVICE (TlsGetClientRandom
, (Tls
, ClientRandom
));
3352 Gets the server random data used in the specified TLS connection.
3354 This function returns the TLS/SSL server random data currently used in
3355 the specified TLS connection.
3357 @param[in] Tls Pointer to the TLS object.
3358 @param[in,out] ServerRandom Buffer to contain the returned server
3359 random data (32 bytes).
3364 TlsGetServerRandom (
3366 IN OUT UINT8
*ServerRandom
3369 CALL_VOID_CRYPTO_SERVICE (TlsGetServerRandom
, (Tls
, ServerRandom
));
3373 Gets the master key data used in the specified TLS connection.
3375 This function returns the TLS/SSL master key material currently used in
3376 the specified TLS connection.
3378 @param[in] Tls Pointer to the TLS object.
3379 @param[in,out] KeyMaterial Buffer to contain the returned key material.
3381 @retval EFI_SUCCESS Key material was returned successfully.
3382 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3383 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
3390 IN OUT UINT8
*KeyMaterial
3393 CALL_CRYPTO_SERVICE (TlsGetKeyMaterial
, (Tls
, KeyMaterial
), EFI_UNSUPPORTED
);
3397 Gets the CA Certificate from the cert store.
3399 This function returns the CA certificate for the chosen
3402 @param[in] Tls Pointer to the TLS object.
3403 @param[out] Data Pointer to the data buffer to receive the CA
3404 certificate data sent to the client.
3405 @param[in,out] DataSize The size of data buffer in bytes.
3407 @retval EFI_SUCCESS The operation succeeded.
3408 @retval EFI_UNSUPPORTED This function is not supported.
3409 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3414 TlsGetCaCertificate (
3417 IN OUT UINTN
*DataSize
3420 CALL_CRYPTO_SERVICE (TlsGetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3424 Gets the local public Certificate set in the specified TLS object.
3426 This function returns the local public certificate which was currently set
3427 in the specified TLS object.
3429 @param[in] Tls Pointer to the TLS object.
3430 @param[out] Data Pointer to the data buffer to receive the local
3432 @param[in,out] DataSize The size of data buffer in bytes.
3434 @retval EFI_SUCCESS The operation succeeded.
3435 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3436 @retval EFI_NOT_FOUND The certificate is not found.
3437 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3442 TlsGetHostPublicCert (
3445 IN OUT UINTN
*DataSize
3448 CALL_CRYPTO_SERVICE (TlsGetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3452 Gets the local private key set in the specified TLS object.
3454 This function returns the local private key data which was currently set
3455 in the specified TLS object.
3457 @param[in] Tls Pointer to the TLS object.
3458 @param[out] Data Pointer to the data buffer to receive the local
3460 @param[in,out] DataSize The size of data buffer in bytes.
3462 @retval EFI_SUCCESS The operation succeeded.
3463 @retval EFI_UNSUPPORTED This function is not supported.
3464 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3469 TlsGetHostPrivateKey (
3472 IN OUT UINTN
*DataSize
3475 CALL_CRYPTO_SERVICE (TlsGetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3479 Gets the CA-supplied certificate revocation list data set in the specified
3482 This function returns the CA-supplied certificate revocation list data which
3483 was currently set in the specified TLS object.
3485 @param[out] Data Pointer to the data buffer to receive the CRL data.
3486 @param[in,out] DataSize The size of data buffer in bytes.
3488 @retval EFI_SUCCESS The operation succeeded.
3489 @retval EFI_UNSUPPORTED This function is not supported.
3490 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3495 TlsGetCertRevocationList (
3497 IN OUT UINTN
*DataSize
3500 CALL_CRYPTO_SERVICE (TlsGetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);