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 Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
1557 Implementation determines salt length automatically from the signature encoding.
1558 Mask generation function is the same as the message digest algorithm.
1559 Salt length should be equal to digest length.
1561 @param[in] RsaContext Pointer to RSA context for signature verification.
1562 @param[in] Message Pointer to octet message to be verified.
1563 @param[in] MsgSize Size of the message in bytes.
1564 @param[in] Signature Pointer to RSASSA-PSS signature to be verified.
1565 @param[in] SigSize Size of signature in bytes.
1566 @param[in] DigestLen Length of digest for RSA operation.
1567 @param[in] SaltLen Salt length for PSS encoding.
1569 @retval TRUE Valid signature encoded in RSASSA-PSS.
1570 @retval FALSE Invalid signature or invalid RSA context.
1576 IN VOID
*RsaContext
,
1577 IN CONST UINT8
*Message
,
1579 IN CONST UINT8
*Signature
,
1581 IN UINT16 DigestLen
,
1585 CALL_CRYPTO_SERVICE (RsaPssVerify
, (RsaContext
, Message
, MsgSize
, Signature
, SigSize
, DigestLen
, SaltLen
), FALSE
);
1589 This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in
1591 Mask generation function is the same as the message digest algorithm.
1592 If the Signature buffer is too small to hold the contents of signature, FALSE
1593 is returned and SigSize is set to the required buffer size to obtain the signature.
1595 If RsaContext is NULL, then return FALSE.
1596 If Message is NULL, then return FALSE.
1597 If MsgSize is zero or > INT_MAX, then return FALSE.
1598 If DigestLen is NOT 32, 48 or 64, return FALSE.
1599 If SaltLen is not equal to DigestLen, then return FALSE.
1600 If SigSize is large enough but Signature is NULL, then return FALSE.
1601 If this interface is not supported, then return FALSE.
1603 @param[in] RsaContext Pointer to RSA context for signature generation.
1604 @param[in] Message Pointer to octet message to be signed.
1605 @param[in] MsgSize Size of the message in bytes.
1606 @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.
1607 @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.
1608 @param[out] Signature Pointer to buffer to receive RSA PSS signature.
1609 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1610 On output, the size of data returned in Signature buffer in bytes.
1612 @retval TRUE Signature successfully generated in RSASSA-PSS.
1613 @retval FALSE Signature generation failed.
1614 @retval FALSE SigSize is too small.
1615 @retval FALSE This interface is not supported.
1621 IN VOID
*RsaContext
,
1622 IN CONST UINT8
*Message
,
1624 IN UINT16 DigestLen
,
1626 OUT UINT8
*Signature
,
1627 IN OUT UINTN
*SigSize
1630 CALL_CRYPTO_SERVICE (RsaPssSign
, (RsaContext
, Message
, MsgSize
, DigestLen
, SaltLen
, Signature
, SigSize
), FALSE
);
1634 Retrieve the RSA Private Key from the password-protected PEM key data.
1636 If PemData is NULL, then return FALSE.
1637 If RsaContext is NULL, then return FALSE.
1638 If this interface is not supported, then return FALSE.
1640 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
1641 @param[in] PemSize Size of the PEM key data in bytes.
1642 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
1643 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1644 RSA private key component. Use RsaFree() function to free the
1647 @retval TRUE RSA Private Key was retrieved successfully.
1648 @retval FALSE Invalid PEM key data or incorrect password.
1649 @retval FALSE This interface is not supported.
1654 RsaGetPrivateKeyFromPem (
1655 IN CONST UINT8
*PemData
,
1657 IN CONST CHAR8
*Password
,
1658 OUT VOID
**RsaContext
1661 CALL_CRYPTO_SERVICE (RsaGetPrivateKeyFromPem
, (PemData
, PemSize
, Password
, RsaContext
), FALSE
);
1665 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
1667 If Cert is NULL, then return FALSE.
1668 If RsaContext is NULL, then return FALSE.
1669 If this interface is not supported, then return FALSE.
1671 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1672 @param[in] CertSize Size of the X509 certificate in bytes.
1673 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1674 RSA public key component. Use RsaFree() function to free the
1677 @retval TRUE RSA Public Key was retrieved successfully.
1678 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
1679 @retval FALSE This interface is not supported.
1684 RsaGetPublicKeyFromX509 (
1685 IN CONST UINT8
*Cert
,
1687 OUT VOID
**RsaContext
1690 CALL_CRYPTO_SERVICE (RsaGetPublicKeyFromX509
, (Cert
, CertSize
, RsaContext
), FALSE
);
1694 Retrieve the subject bytes from one X.509 certificate.
1696 If Cert is NULL, then return FALSE.
1697 If SubjectSize is NULL, then return FALSE.
1698 If this interface is not supported, then return FALSE.
1700 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1701 @param[in] CertSize Size of the X509 certificate in bytes.
1702 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
1703 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
1704 and the size of buffer returned CertSubject on output.
1706 @retval TRUE The certificate subject retrieved successfully.
1707 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
1708 The SubjectSize will be updated with the required size.
1709 @retval FALSE This interface is not supported.
1714 X509GetSubjectName (
1715 IN CONST UINT8
*Cert
,
1717 OUT UINT8
*CertSubject
,
1718 IN OUT UINTN
*SubjectSize
1721 CALL_CRYPTO_SERVICE (X509GetSubjectName
, (Cert
, CertSize
, CertSubject
, SubjectSize
), FALSE
);
1725 Retrieve the common name (CN) string from one X.509 certificate.
1727 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1728 @param[in] CertSize Size of the X509 certificate in bytes.
1729 @param[out] CommonName Buffer to contain the retrieved certificate common
1730 name string (UTF8). At most CommonNameSize bytes will be
1731 written and the string will be null terminated. May be
1732 NULL in order to determine the size buffer needed.
1733 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
1734 and the size of buffer returned CommonName on output.
1735 If CommonName is NULL then the amount of space needed
1736 in buffer (including the final null) is returned.
1738 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
1739 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
1740 If CommonNameSize is NULL.
1741 If CommonName is not NULL and *CommonNameSize is 0.
1742 If Certificate is invalid.
1743 @retval RETURN_NOT_FOUND If no CommonName entry exists.
1744 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
1745 (including the final null) is returned in the
1746 CommonNameSize parameter.
1747 @retval RETURN_UNSUPPORTED The operation is not supported.
1753 IN CONST UINT8
*Cert
,
1755 OUT CHAR8
*CommonName
, OPTIONAL
1756 IN OUT UINTN
*CommonNameSize
1759 CALL_CRYPTO_SERVICE (X509GetCommonName
, (Cert
, CertSize
, CommonName
, CommonNameSize
), RETURN_UNSUPPORTED
);
1763 Retrieve the organization name (O) string from one X.509 certificate.
1765 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1766 @param[in] CertSize Size of the X509 certificate in bytes.
1767 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
1768 name string. At most NameBufferSize bytes will be
1769 written and the string will be null terminated. May be
1770 NULL in order to determine the size buffer needed.
1771 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
1772 and the size of buffer returned Name on output.
1773 If NameBuffer is NULL then the amount of space needed
1774 in buffer (including the final null) is returned.
1776 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
1777 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
1778 If NameBufferSize is NULL.
1779 If NameBuffer is not NULL and *CommonNameSize is 0.
1780 If Certificate is invalid.
1781 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
1782 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
1783 (including the final null) is returned in the
1784 CommonNameSize parameter.
1785 @retval RETURN_UNSUPPORTED The operation is not supported.
1790 X509GetOrganizationName (
1791 IN CONST UINT8
*Cert
,
1793 OUT CHAR8
*NameBuffer
, OPTIONAL
1794 IN OUT UINTN
*NameBufferSize
1797 CALL_CRYPTO_SERVICE (X509GetOrganizationName
, (Cert
, CertSize
, NameBuffer
, NameBufferSize
), RETURN_UNSUPPORTED
);
1801 Verify one X509 certificate was issued by the trusted CA.
1803 If Cert is NULL, then return FALSE.
1804 If CACert is NULL, then return FALSE.
1805 If this interface is not supported, then return FALSE.
1807 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
1808 @param[in] CertSize Size of the X509 certificate in bytes.
1809 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
1810 @param[in] CACertSize Size of the CA Certificate in bytes.
1812 @retval TRUE The certificate was issued by the trusted CA.
1813 @retval FALSE Invalid certificate or the certificate was not issued by the given
1815 @retval FALSE This interface is not supported.
1821 IN CONST UINT8
*Cert
,
1823 IN CONST UINT8
*CACert
,
1827 CALL_CRYPTO_SERVICE (X509VerifyCert
, (Cert
, CertSize
, CACert
, CACertSize
), FALSE
);
1831 Construct a X509 object from DER-encoded certificate data.
1833 If Cert is NULL, then return FALSE.
1834 If SingleX509Cert is NULL, then return FALSE.
1835 If this interface is not supported, then return FALSE.
1837 @param[in] Cert Pointer to the DER-encoded certificate data.
1838 @param[in] CertSize The size of certificate data in bytes.
1839 @param[out] SingleX509Cert The generated X509 object.
1841 @retval TRUE The X509 object generation succeeded.
1842 @retval FALSE The operation failed.
1843 @retval FALSE This interface is not supported.
1848 X509ConstructCertificate (
1849 IN CONST UINT8
*Cert
,
1851 OUT UINT8
**SingleX509Cert
1854 CALL_CRYPTO_SERVICE (X509ConstructCertificate
, (Cert
, CertSize
, SingleX509Cert
), FALSE
);
1858 Construct a X509 stack object from a list of DER-encoded certificate data.
1860 If X509Stack is NULL, then return FALSE.
1861 If this interface is not supported, then return FALSE.
1863 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
1864 On output, pointer to the X509 stack object with new
1865 inserted X509 certificate.
1866 @param[in] Args VA_LIST marker for the variable argument list.
1867 ... A list of DER-encoded single certificate data followed
1868 by certificate size. A NULL terminates the list. The
1869 pairs are the arguments to X509ConstructCertificate().
1871 @retval TRUE The X509 stack construction succeeded.
1872 @retval FALSE The construction operation failed.
1873 @retval FALSE This interface is not supported.
1878 X509ConstructCertificateStack (
1879 IN OUT UINT8
**X509Stack
,
1886 VA_START (Args
, X509Stack
);
1887 Result
= X509ConstructCertificateStackV (X509Stack
, Args
);
1893 Construct a X509 stack object from a list of DER-encoded certificate data.
1895 If X509Stack is NULL, then return FALSE.
1896 If this interface is not supported, then return FALSE.
1898 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
1899 On output, pointer to the X509 stack object with new
1900 inserted X509 certificate.
1901 @param[in] Args VA_LIST marker for the variable argument list.
1902 A list of DER-encoded single certificate data followed
1903 by certificate size. A NULL terminates the list. The
1904 pairs are the arguments to X509ConstructCertificate().
1906 @retval TRUE The X509 stack construction succeeded.
1907 @retval FALSE The construction operation failed.
1908 @retval FALSE This interface is not supported.
1913 X509ConstructCertificateStackV (
1914 IN OUT UINT8
**X509Stack
,
1918 CALL_CRYPTO_SERVICE (X509ConstructCertificateStackV
, (X509Stack
, Args
), FALSE
);
1922 Release the specified X509 object.
1924 If the interface is not supported, then ASSERT().
1926 @param[in] X509Cert Pointer to the X509 object to be released.
1935 CALL_VOID_CRYPTO_SERVICE (X509Free
, (X509Cert
));
1939 Release the specified X509 stack object.
1941 If the interface is not supported, then ASSERT().
1943 @param[in] X509Stack Pointer to the X509 stack object to be released.
1952 CALL_VOID_CRYPTO_SERVICE (X509StackFree
, (X509Stack
));
1956 Retrieve the TBSCertificate from one given X.509 certificate.
1958 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
1959 @param[in] CertSize Size of the X509 certificate in bytes.
1960 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
1961 @param[out] TBSCertSize Size of the TBS certificate in bytes.
1963 If Cert is NULL, then return FALSE.
1964 If TBSCert is NULL, then return FALSE.
1965 If TBSCertSize is NULL, then return FALSE.
1966 If this interface is not supported, then return FALSE.
1968 @retval TRUE The TBSCertificate was retrieved successfully.
1969 @retval FALSE Invalid X.509 certificate.
1975 IN CONST UINT8
*Cert
,
1977 OUT UINT8
**TBSCert
,
1978 OUT UINTN
*TBSCertSize
1981 CALL_CRYPTO_SERVICE (X509GetTBSCert
, (Cert
, CertSize
, TBSCert
, TBSCertSize
), FALSE
);
1985 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
1986 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
1988 If Password or Salt or OutKey is NULL, then return FALSE.
1989 If the hash algorithm could not be determined, then return FALSE.
1990 If this interface is not supported, then return FALSE.
1992 @param[in] PasswordLength Length of input password in bytes.
1993 @param[in] Password Pointer to the array for the password.
1994 @param[in] SaltLength Size of the Salt in bytes.
1995 @param[in] Salt Pointer to the Salt.
1996 @param[in] IterationCount Number of iterations to perform. Its value should be
1997 greater than or equal to 1.
1998 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
1999 NOTE: DigestSize will be used to determine the hash algorithm.
2000 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2001 @param[in] KeyLength Size of the derived key buffer in bytes.
2002 @param[out] OutKey Pointer to the output derived key buffer.
2004 @retval TRUE A key was derived successfully.
2005 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2006 @retval FALSE The hash algorithm could not be determined from the digest size.
2007 @retval FALSE The key derivation operation failed.
2008 @retval FALSE This interface is not supported.
2014 IN UINTN PasswordLength
,
2015 IN CONST CHAR8
*Password
,
2016 IN UINTN SaltLength
,
2017 IN CONST UINT8
*Salt
,
2018 IN UINTN IterationCount
,
2019 IN UINTN DigestSize
,
2024 CALL_CRYPTO_SERVICE (Pkcs5HashPassword
, (PasswordLength
, Password
, SaltLength
, Salt
, IterationCount
, DigestSize
, KeyLength
, OutKey
), FALSE
);
2028 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2029 encrypted message in a newly allocated buffer.
2031 Things that can cause a failure include:
2032 - X509 key size does not match any known key size.
2033 - Fail to parse X509 certificate.
2034 - Fail to allocate an intermediate buffer.
2035 - Null pointer provided for a non-optional parameter.
2036 - Data size is too large for the provided key size (max size is a function of key size
2037 and hash digest size).
2039 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2040 will be used to encrypt the data.
2041 @param[in] PublicKeySize Size of the X509 cert buffer.
2042 @param[in] InData Data to be encrypted.
2043 @param[in] InDataSize Size of the data buffer.
2044 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2045 to be used when initializing the PRNG. NULL otherwise.
2046 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2048 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2050 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2052 @retval TRUE Encryption was successful.
2053 @retval FALSE Encryption failed.
2059 IN CONST UINT8
*PublicKey
,
2060 IN UINTN PublicKeySize
,
2062 IN UINTN InDataSize
,
2063 IN CONST UINT8
*PrngSeed
, OPTIONAL
2064 IN UINTN PrngSeedSize
, OPTIONAL
2065 OUT UINT8
**EncryptedData
,
2066 OUT UINTN
*EncryptedDataSize
2069 CALL_CRYPTO_SERVICE (Pkcs1v2Encrypt
, (PublicKey
, PublicKeySize
, InData
, InDataSize
, PrngSeed
, PrngSeedSize
, EncryptedData
, EncryptedDataSize
), FALSE
);
2073 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2074 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2075 in a ContentInfo structure.
2077 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2078 return FALSE. If P7Length overflow, then return FALSE.
2079 If this interface is not supported, then return FALSE.
2081 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2082 @param[in] P7Length Length of the PKCS#7 message in bytes.
2083 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2084 It's caller's responsibility to free the buffer with
2086 This data structure is EFI_CERT_STACK type.
2087 @param[out] StackLength Length of signer's certificates in bytes.
2088 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2089 It's caller's responsibility to free the buffer with
2091 @param[out] CertLength Length of the trusted certificate in bytes.
2093 @retval TRUE The operation is finished successfully.
2094 @retval FALSE Error occurs during the operation.
2095 @retval FALSE This interface is not supported.
2101 IN CONST UINT8
*P7Data
,
2103 OUT UINT8
**CertStack
,
2104 OUT UINTN
*StackLength
,
2105 OUT UINT8
**TrustedCert
,
2106 OUT UINTN
*CertLength
2109 CALL_CRYPTO_SERVICE (Pkcs7GetSigners
, (P7Data
, P7Length
, CertStack
, StackLength
, TrustedCert
, CertLength
), FALSE
);
2113 Wrap function to use free() to free allocated memory for certificates.
2115 If this interface is not supported, then ASSERT().
2117 @param[in] Certs Pointer to the certificates to be freed.
2126 CALL_VOID_CRYPTO_SERVICE (Pkcs7FreeSigners
, (Certs
));
2130 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2131 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2132 unchained to the signer's certificates.
2133 The input signed data could be wrapped in a ContentInfo structure.
2135 @param[in] P7Data Pointer to the PKCS#7 message.
2136 @param[in] P7Length Length of the PKCS#7 message in bytes.
2137 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2138 certificate. It's caller's responsibility to free the buffer
2139 with Pkcs7FreeSigners().
2140 This data structure is EFI_CERT_STACK type.
2141 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2142 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2143 responsibility to free the buffer with Pkcs7FreeSigners().
2144 This data structure is EFI_CERT_STACK type.
2145 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2147 @retval TRUE The operation is finished successfully.
2148 @retval FALSE Error occurs during the operation.
2153 Pkcs7GetCertificatesList (
2154 IN CONST UINT8
*P7Data
,
2156 OUT UINT8
**SignerChainCerts
,
2157 OUT UINTN
*ChainLength
,
2158 OUT UINT8
**UnchainCerts
,
2159 OUT UINTN
*UnchainLength
2162 CALL_CRYPTO_SERVICE (Pkcs7GetCertificatesList
, (P7Data
, P7Length
, SignerChainCerts
, ChainLength
, UnchainCerts
, UnchainLength
), FALSE
);
2166 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2167 Syntax Standard, version 1.5". This interface is only intended to be used for
2168 application to perform PKCS#7 functionality validation.
2170 If this interface is not supported, then return FALSE.
2172 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2174 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2175 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2177 @param[in] InData Pointer to the content to be signed.
2178 @param[in] InDataSize Size of InData in bytes.
2179 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2180 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2181 include in the PKCS#7 signedData (e.g. any intermediate
2183 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2184 responsibility to free the buffer with FreePool().
2185 @param[out] SignedDataSize Size of SignedData in bytes.
2187 @retval TRUE PKCS#7 data signing succeeded.
2188 @retval FALSE PKCS#7 data signing failed.
2189 @retval FALSE This interface is not supported.
2195 IN CONST UINT8
*PrivateKey
,
2196 IN UINTN PrivateKeySize
,
2197 IN CONST UINT8
*KeyPassword
,
2199 IN UINTN InDataSize
,
2201 IN UINT8
*OtherCerts OPTIONAL
,
2202 OUT UINT8
**SignedData
,
2203 OUT UINTN
*SignedDataSize
2206 CALL_CRYPTO_SERVICE (Pkcs7Sign
, (PrivateKey
, PrivateKeySize
, KeyPassword
, InData
, InDataSize
, SignCert
, OtherCerts
, SignedData
, SignedDataSize
), FALSE
);
2210 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2211 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2212 in a ContentInfo structure.
2214 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2215 If P7Length, CertLength or DataLength overflow, then return FALSE.
2216 If this interface is not supported, then return FALSE.
2218 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2219 @param[in] P7Length Length of the PKCS#7 message in bytes.
2220 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2221 is used for certificate chain verification.
2222 @param[in] CertLength Length of the trusted certificate in bytes.
2223 @param[in] InData Pointer to the content to be verified.
2224 @param[in] DataLength Length of InData in bytes.
2226 @retval TRUE The specified PKCS#7 signed data is valid.
2227 @retval FALSE Invalid PKCS#7 signed data.
2228 @retval FALSE This interface is not supported.
2234 IN CONST UINT8
*P7Data
,
2236 IN CONST UINT8
*TrustedCert
,
2237 IN UINTN CertLength
,
2238 IN CONST UINT8
*InData
,
2242 CALL_CRYPTO_SERVICE (Pkcs7Verify
, (P7Data
, P7Length
, TrustedCert
, CertLength
, InData
, DataLength
), FALSE
);
2246 This function receives a PKCS7 formatted signature, and then verifies that
2247 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
2248 leaf signing certificate.
2249 Note that this function does not validate the certificate chain.
2251 Applications for custom EKU's are quite flexible. For example, a policy EKU
2252 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
2253 certificate issued might also contain this EKU, thus constraining the
2254 sub-ordinate certificate. Other applications might allow a certificate
2255 embedded in a device to specify that other Object Identifiers (OIDs) are
2256 present which contains binary data specifying custom capabilities that
2257 the device is able to do.
2259 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
2260 containing the content block with both the signature,
2261 the signer's certificate, and any necessary intermediate
2263 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
2264 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
2265 required EKUs that must be present in the signature.
2266 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
2267 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
2268 must be present in the leaf signer. If it is
2269 FALSE, then we will succeed if we find any
2270 of the specified EKU's.
2272 @retval EFI_SUCCESS The required EKUs were found in the signature.
2273 @retval EFI_INVALID_PARAMETER A parameter was invalid.
2274 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
2279 VerifyEKUsInPkcs7Signature (
2280 IN CONST UINT8
*Pkcs7Signature
,
2281 IN CONST UINT32 SignatureSize
,
2282 IN CONST CHAR8
*RequiredEKUs
[],
2283 IN CONST UINT32 RequiredEKUsSize
,
2284 IN BOOLEAN RequireAllPresent
2287 CALL_CRYPTO_SERVICE (VerifyEKUsInPkcs7Signature
, (Pkcs7Signature
, SignatureSize
, RequiredEKUs
, RequiredEKUsSize
, RequireAllPresent
), FALSE
);
2292 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2293 data could be wrapped in a ContentInfo structure.
2295 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2296 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2298 Caution: This function may receive untrusted input. So this function will do
2299 basic check for PKCS#7 data structure.
2301 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2302 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2303 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2304 It's caller's responsibility to free the buffer with FreePool().
2305 @param[out] ContentSize The size of the extracted content in bytes.
2307 @retval TRUE The P7Data was correctly formatted for processing.
2308 @retval FALSE The P7Data was not correctly formatted for processing.
2313 Pkcs7GetAttachedContent (
2314 IN CONST UINT8
*P7Data
,
2317 OUT UINTN
*ContentSize
2320 CALL_CRYPTO_SERVICE (Pkcs7GetAttachedContent
, (P7Data
, P7Length
, Content
, ContentSize
), FALSE
);
2324 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2325 Authenticode Portable Executable Signature Format".
2327 If AuthData is NULL, then return FALSE.
2328 If ImageHash is NULL, then return FALSE.
2329 If this interface is not supported, then return FALSE.
2331 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2332 PE/COFF image to be verified.
2333 @param[in] DataSize Size of the Authenticode Signature in bytes.
2334 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2335 is used for certificate chain verification.
2336 @param[in] CertSize Size of the trusted certificate in bytes.
2337 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2338 for calculating the image hash value is described in Authenticode
2340 @param[in] HashSize Size of Image hash value in bytes.
2342 @retval TRUE The specified Authenticode Signature is valid.
2343 @retval FALSE Invalid Authenticode Signature.
2344 @retval FALSE This interface is not supported.
2349 AuthenticodeVerify (
2350 IN CONST UINT8
*AuthData
,
2352 IN CONST UINT8
*TrustedCert
,
2354 IN CONST UINT8
*ImageHash
,
2358 CALL_CRYPTO_SERVICE (AuthenticodeVerify
, (AuthData
, DataSize
, TrustedCert
, CertSize
, ImageHash
, HashSize
), FALSE
);
2362 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2365 If AuthData is NULL, then return FALSE.
2366 If this interface is not supported, then return FALSE.
2368 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2369 PE/COFF image to be verified.
2370 @param[in] DataSize Size of the Authenticode Signature in bytes.
2371 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2372 is used for TSA certificate chain verification.
2373 @param[in] CertSize Size of the trusted certificate in bytes.
2374 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2377 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2378 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2383 ImageTimestampVerify (
2384 IN CONST UINT8
*AuthData
,
2386 IN CONST UINT8
*TsaCert
,
2388 OUT EFI_TIME
*SigningTime
2391 CALL_CRYPTO_SERVICE (ImageTimestampVerify
, (AuthData
, DataSize
, TsaCert
, CertSize
, SigningTime
), FALSE
);
2394 //=====================================================================================
2395 // DH Key Exchange Primitive
2396 //=====================================================================================
2399 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
2401 @return Pointer to the Diffie-Hellman Context that has been initialized.
2402 If the allocations fails, DhNew() returns NULL.
2403 If the interface is not supported, DhNew() returns NULL.
2412 CALL_CRYPTO_SERVICE (DhNew
, (), NULL
);
2416 Release the specified DH context.
2418 If the interface is not supported, then ASSERT().
2420 @param[in] DhContext Pointer to the DH context to be released.
2429 CALL_VOID_CRYPTO_SERVICE (DhFree
, (DhContext
));
2433 Generates DH parameter.
2435 Given generator g, and length of prime number p in bits, this function generates p,
2436 and sets DH context according to value of g and p.
2438 Before this function can be invoked, pseudorandom number generator must be correctly
2439 initialized by RandomSeed().
2441 If DhContext is NULL, then return FALSE.
2442 If Prime is NULL, then return FALSE.
2443 If this interface is not supported, then return FALSE.
2445 @param[in, out] DhContext Pointer to the DH context.
2446 @param[in] Generator Value of generator.
2447 @param[in] PrimeLength Length in bits of prime to be generated.
2448 @param[out] Prime Pointer to the buffer to receive the generated prime number.
2450 @retval TRUE DH parameter generation succeeded.
2451 @retval FALSE Value of Generator is not supported.
2452 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
2453 @retval FALSE This interface is not supported.
2458 DhGenerateParameter (
2459 IN OUT VOID
*DhContext
,
2461 IN UINTN PrimeLength
,
2465 CALL_CRYPTO_SERVICE (DhGenerateParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
2469 Sets generator and prime parameters for DH.
2471 Given generator g, and prime number p, this function and sets DH
2472 context accordingly.
2474 If DhContext is NULL, then return FALSE.
2475 If Prime is NULL, then return FALSE.
2476 If this interface is not supported, then return FALSE.
2478 @param[in, out] DhContext Pointer to the DH context.
2479 @param[in] Generator Value of generator.
2480 @param[in] PrimeLength Length in bits of prime to be generated.
2481 @param[in] Prime Pointer to the prime number.
2483 @retval TRUE DH parameter setting succeeded.
2484 @retval FALSE Value of Generator is not supported.
2485 @retval FALSE Value of Generator is not suitable for the Prime.
2486 @retval FALSE Value of Prime is not a prime number.
2487 @retval FALSE Value of Prime is not a safe prime number.
2488 @retval FALSE This interface is not supported.
2494 IN OUT VOID
*DhContext
,
2496 IN UINTN PrimeLength
,
2497 IN CONST UINT8
*Prime
2500 CALL_CRYPTO_SERVICE (DhSetParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
2504 Generates DH public key.
2506 This function generates random secret exponent, and computes the public key, which is
2507 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
2508 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
2509 PublicKeySize is set to the required buffer size to obtain the public key.
2511 If DhContext is NULL, then return FALSE.
2512 If PublicKeySize is NULL, then return FALSE.
2513 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
2514 If this interface is not supported, then return FALSE.
2516 @param[in, out] DhContext Pointer to the DH context.
2517 @param[out] PublicKey Pointer to the buffer to receive generated public key.
2518 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
2519 On output, the size of data returned in PublicKey buffer in bytes.
2521 @retval TRUE DH public key generation succeeded.
2522 @retval FALSE DH public key generation failed.
2523 @retval FALSE PublicKeySize is not large enough.
2524 @retval FALSE This interface is not supported.
2530 IN OUT VOID
*DhContext
,
2531 OUT UINT8
*PublicKey
,
2532 IN OUT UINTN
*PublicKeySize
2535 CALL_CRYPTO_SERVICE (DhGenerateKey
, (DhContext
, PublicKey
, PublicKeySize
), FALSE
);
2539 Computes exchanged common key.
2541 Given peer's public key, this function computes the exchanged common key, based on its own
2542 context including value of prime modulus and random secret exponent.
2544 If DhContext is NULL, then return FALSE.
2545 If PeerPublicKey is NULL, then return FALSE.
2546 If KeySize is NULL, then return FALSE.
2547 If Key is NULL, then return FALSE.
2548 If KeySize is not large enough, then return FALSE.
2549 If this interface is not supported, then return FALSE.
2551 @param[in, out] DhContext Pointer to the DH context.
2552 @param[in] PeerPublicKey Pointer to the peer's public key.
2553 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
2554 @param[out] Key Pointer to the buffer to receive generated key.
2555 @param[in, out] KeySize On input, the size of Key buffer in bytes.
2556 On output, the size of data returned in Key buffer in bytes.
2558 @retval TRUE DH exchanged key generation succeeded.
2559 @retval FALSE DH exchanged key generation failed.
2560 @retval FALSE KeySize is not large enough.
2561 @retval FALSE This interface is not supported.
2567 IN OUT VOID
*DhContext
,
2568 IN CONST UINT8
*PeerPublicKey
,
2569 IN UINTN PeerPublicKeySize
,
2571 IN OUT UINTN
*KeySize
2574 CALL_CRYPTO_SERVICE (DhComputeKey
, (DhContext
, PeerPublicKey
, PeerPublicKeySize
, Key
, KeySize
), FALSE
);
2577 //=====================================================================================
2578 // Pseudo-Random Generation Primitive
2579 //=====================================================================================
2582 Sets up the seed value for the pseudorandom number generator.
2584 This function sets up the seed value for the pseudorandom number generator.
2585 If Seed is not NULL, then the seed passed in is used.
2586 If Seed is NULL, then default seed is used.
2587 If this interface is not supported, then return FALSE.
2589 @param[in] Seed Pointer to seed value.
2590 If NULL, default seed is used.
2591 @param[in] SeedSize Size of seed value.
2592 If Seed is NULL, this parameter is ignored.
2594 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
2595 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
2596 @retval FALSE This interface is not supported.
2602 IN CONST UINT8
*Seed OPTIONAL
,
2606 CALL_CRYPTO_SERVICE (RandomSeed
, (Seed
, SeedSize
), FALSE
);
2610 Generates a pseudorandom byte stream of the specified size.
2612 If Output is NULL, then return FALSE.
2613 If this interface is not supported, then return FALSE.
2615 @param[out] Output Pointer to buffer to receive random value.
2616 @param[in] Size Size of random bytes to generate.
2618 @retval TRUE Pseudorandom byte stream generated successfully.
2619 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
2620 @retval FALSE This interface is not supported.
2630 CALL_CRYPTO_SERVICE (RandomBytes
, (Output
, Size
), FALSE
);
2633 //=====================================================================================
2634 // Key Derivation Function Primitive
2635 //=====================================================================================
2638 Derive key data using HMAC-SHA256 based KDF.
2640 @param[in] Key Pointer to the user-supplied key.
2641 @param[in] KeySize Key size in bytes.
2642 @param[in] Salt Pointer to the salt(non-secret) value.
2643 @param[in] SaltSize Salt size in bytes.
2644 @param[in] Info Pointer to the application specific info.
2645 @param[in] InfoSize Info size in bytes.
2646 @param[out] Out Pointer to buffer to receive hkdf value.
2647 @param[in] OutSize Size of hkdf bytes to generate.
2649 @retval TRUE Hkdf generated successfully.
2650 @retval FALSE Hkdf generation failed.
2655 HkdfSha256ExtractAndExpand (
2656 IN CONST UINT8
*Key
,
2658 IN CONST UINT8
*Salt
,
2660 IN CONST UINT8
*Info
,
2666 CALL_CRYPTO_SERVICE (HkdfSha256ExtractAndExpand
, (Key
, KeySize
, Salt
, SaltSize
, Info
, InfoSize
, Out
, OutSize
), FALSE
);
2670 Initializes the OpenSSL library.
2672 This function registers ciphers and digests used directly and indirectly
2673 by SSL/TLS, and initializes the readable error messages.
2674 This function must be called before any other action takes places.
2676 @retval TRUE The OpenSSL library has been initialized.
2677 @retval FALSE Failed to initialize the OpenSSL library.
2686 CALL_CRYPTO_SERVICE (TlsInitialize
, (), FALSE
);
2690 Free an allocated SSL_CTX object.
2692 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
2701 CALL_VOID_CRYPTO_SERVICE (TlsCtxFree
, (TlsCtx
));
2705 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
2708 @param[in] MajorVer Major Version of TLS/SSL Protocol.
2709 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
2711 @return Pointer to an allocated SSL_CTX object.
2712 If the creation failed, TlsCtxNew() returns NULL.
2722 CALL_CRYPTO_SERVICE (TlsCtxNew
, (MajorVer
, MinorVer
), NULL
);
2726 Free an allocated TLS object.
2728 This function removes the TLS object pointed to by Tls and frees up the
2729 allocated memory. If Tls is NULL, nothing is done.
2731 @param[in] Tls Pointer to the TLS object to be freed.
2740 CALL_VOID_CRYPTO_SERVICE (TlsFree
, (Tls
));
2744 Create a new TLS object for a connection.
2746 This function creates a new TLS object for a connection. The new object
2747 inherits the setting of the underlying context TlsCtx: connection method,
2748 options, verification setting.
2750 @param[in] TlsCtx Pointer to the SSL_CTX object.
2752 @return Pointer to an allocated SSL object.
2753 If the creation failed, TlsNew() returns NULL.
2762 CALL_CRYPTO_SERVICE (TlsNew
, (TlsCtx
), NULL
);
2766 Checks if the TLS handshake was done.
2768 This function will check if the specified TLS handshake was done.
2770 @param[in] Tls Pointer to the TLS object for handshake state checking.
2772 @retval TRUE The TLS handshake was done.
2773 @retval FALSE The TLS handshake was not done.
2782 CALL_CRYPTO_SERVICE (TlsInHandshake
, (Tls
), FALSE
);
2786 Perform a TLS/SSL handshake.
2788 This function will perform a TLS/SSL handshake.
2790 @param[in] Tls Pointer to the TLS object for handshake operation.
2791 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
2792 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
2794 @param[out] BufferOut Pointer to the buffer to hold the built packet.
2795 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
2796 the buffer size provided by the caller. On output, it
2797 is the buffer size in fact needed to contain the
2800 @retval EFI_SUCCESS The required TLS packet is built successfully.
2801 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2803 BufferIn is NULL but BufferInSize is NOT 0.
2804 BufferInSize is 0 but BufferIn is NOT NULL.
2805 BufferOutSize is NULL.
2806 BufferOut is NULL if *BufferOutSize is not zero.
2807 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
2808 @retval EFI_ABORTED Something wrong during handshake.
2815 IN UINT8
*BufferIn
, OPTIONAL
2816 IN UINTN BufferInSize
, OPTIONAL
2817 OUT UINT8
*BufferOut
, OPTIONAL
2818 IN OUT UINTN
*BufferOutSize
2821 CALL_CRYPTO_SERVICE (TlsDoHandshake
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
2825 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
2826 TLS session has errors and the response packet needs to be Alert message based on error type.
2828 @param[in] Tls Pointer to the TLS object for state checking.
2829 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
2830 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
2832 @param[out] BufferOut Pointer to the buffer to hold the built packet.
2833 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
2834 the buffer size provided by the caller. On output, it
2835 is the buffer size in fact needed to contain the
2838 @retval EFI_SUCCESS The required TLS packet is built successfully.
2839 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2841 BufferIn is NULL but BufferInSize is NOT 0.
2842 BufferInSize is 0 but BufferIn is NOT NULL.
2843 BufferOutSize is NULL.
2844 BufferOut is NULL if *BufferOutSize is not zero.
2845 @retval EFI_ABORTED An error occurred.
2846 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
2853 IN UINT8
*BufferIn
, OPTIONAL
2854 IN UINTN BufferInSize
, OPTIONAL
2855 OUT UINT8
*BufferOut
, OPTIONAL
2856 IN OUT UINTN
*BufferOutSize
2859 CALL_CRYPTO_SERVICE (TlsHandleAlert
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
2863 Build the CloseNotify packet.
2865 @param[in] Tls Pointer to the TLS object for state checking.
2866 @param[in, out] Buffer Pointer to the buffer to hold the built packet.
2867 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
2868 the buffer size provided by the caller. On output, it
2869 is the buffer size in fact needed to contain the
2872 @retval EFI_SUCCESS The required TLS packet is built successfully.
2873 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2876 Buffer is NULL if *BufferSize is not zero.
2877 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
2884 IN OUT UINT8
*Buffer
,
2885 IN OUT UINTN
*BufferSize
2888 CALL_CRYPTO_SERVICE (TlsCloseNotify
, (Tls
, Buffer
, BufferSize
), EFI_UNSUPPORTED
);
2892 Attempts to read bytes from one TLS object and places the data in Buffer.
2894 This function will attempt to read BufferSize bytes from the TLS object
2895 and places the data in Buffer.
2897 @param[in] Tls Pointer to the TLS object.
2898 @param[in,out] Buffer Pointer to the buffer to store the data.
2899 @param[in] BufferSize The size of Buffer in bytes.
2901 @retval >0 The amount of data successfully read from the TLS object.
2902 @retval <=0 No data was successfully read.
2909 IN OUT VOID
*Buffer
,
2913 CALL_CRYPTO_SERVICE (TlsCtrlTrafficOut
, (Tls
, Buffer
, BufferSize
), 0);
2917 Attempts to write data from the buffer to TLS object.
2919 This function will attempt to write BufferSize bytes data from the Buffer
2922 @param[in] Tls Pointer to the TLS object.
2923 @param[in] Buffer Pointer to the data buffer.
2924 @param[in] BufferSize The size of Buffer in bytes.
2926 @retval >0 The amount of data successfully written to the TLS object.
2927 @retval <=0 No data was successfully written.
2938 CALL_CRYPTO_SERVICE (TlsCtrlTrafficIn
, (Tls
, Buffer
, BufferSize
), 0);
2942 Attempts to read bytes from the specified TLS connection into the buffer.
2944 This function tries to read BufferSize bytes data from the specified TLS
2945 connection into the Buffer.
2947 @param[in] Tls Pointer to the TLS connection for data reading.
2948 @param[in,out] Buffer Pointer to the data buffer.
2949 @param[in] BufferSize The size of Buffer in bytes.
2951 @retval >0 The read operation was successful, and return value is the
2952 number of bytes actually read from the TLS connection.
2953 @retval <=0 The read operation was not successful.
2960 IN OUT VOID
*Buffer
,
2964 CALL_CRYPTO_SERVICE (TlsRead
, (Tls
, Buffer
, BufferSize
), 0);
2968 Attempts to write data to a TLS connection.
2970 This function tries to write BufferSize bytes data from the Buffer into the
2971 specified TLS connection.
2973 @param[in] Tls Pointer to the TLS connection for data writing.
2974 @param[in] Buffer Pointer to the data buffer.
2975 @param[in] BufferSize The size of Buffer in bytes.
2977 @retval >0 The write operation was successful, and return value is the
2978 number of bytes actually written to the TLS connection.
2979 @retval <=0 The write operation was not successful.
2990 CALL_CRYPTO_SERVICE (TlsWrite
, (Tls
, Buffer
, BufferSize
), 0);
2994 Set a new TLS/SSL method for a particular TLS object.
2996 This function sets a new TLS/SSL method for a particular TLS object.
2998 @param[in] Tls Pointer to a TLS object.
2999 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3000 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3002 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
3003 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3004 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
3015 CALL_CRYPTO_SERVICE (TlsSetVersion
, (Tls
, MajorVer
, MinorVer
), EFI_UNSUPPORTED
);
3019 Set TLS object to work in client or server mode.
3021 This function prepares a TLS object to work in client or server mode.
3023 @param[in] Tls Pointer to a TLS object.
3024 @param[in] IsServer Work in server mode.
3026 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
3027 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3028 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
3033 TlsSetConnectionEnd (
3038 CALL_CRYPTO_SERVICE (TlsSetConnectionEnd
, (Tls
, IsServer
), EFI_UNSUPPORTED
);
3042 Set the ciphers list to be used by the TLS object.
3044 This function sets the ciphers for use by a specified TLS object.
3046 @param[in] Tls Pointer to a TLS object.
3047 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
3048 cipher identifier comes from the TLS Cipher Suite
3049 Registry of the IANA, interpreting Byte1 and Byte2
3050 in network (big endian) byte order.
3051 @param[in] CipherNum The number of cipher in the list.
3053 @retval EFI_SUCCESS The ciphers list was set successfully.
3054 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3055 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
3056 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
3063 IN UINT16
*CipherId
,
3067 CALL_CRYPTO_SERVICE (TlsSetCipherList
, (Tls
, CipherId
, CipherNum
), EFI_UNSUPPORTED
);
3071 Set the compression method for TLS/SSL operations.
3073 This function handles TLS/SSL integrated compression methods.
3075 @param[in] CompMethod The compression method ID.
3077 @retval EFI_SUCCESS The compression method for the communication was
3079 @retval EFI_UNSUPPORTED Unsupported compression method.
3084 TlsSetCompressionMethod (
3088 CALL_CRYPTO_SERVICE (TlsSetCompressionMethod
, (CompMethod
), EFI_UNSUPPORTED
);
3092 Set peer certificate verification mode for the TLS connection.
3094 This function sets the verification mode flags for the TLS connection.
3096 @param[in] Tls Pointer to the TLS object.
3097 @param[in] VerifyMode A set of logically or'ed verification mode flags.
3104 IN UINT32 VerifyMode
3107 CALL_VOID_CRYPTO_SERVICE (TlsSetVerify
, (Tls
, VerifyMode
));
3111 Set the specified host name to be verified.
3113 @param[in] Tls Pointer to the TLS object.
3114 @param[in] Flags The setting flags during the validation.
3115 @param[in] HostName The specified host name to be verified.
3117 @retval EFI_SUCCESS The HostName setting was set successfully.
3118 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3119 @retval EFI_ABORTED Invalid HostName setting.
3130 CALL_CRYPTO_SERVICE (TlsSetVerifyHost
, (Tls
, Flags
, HostName
), EFI_UNSUPPORTED
);
3134 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
3136 This function sets a session ID to be used when the TLS/SSL connection is
3139 @param[in] Tls Pointer to the TLS object.
3140 @param[in] SessionId Session ID data used for session resumption.
3141 @param[in] SessionIdLen Length of Session ID in bytes.
3143 @retval EFI_SUCCESS Session ID was set successfully.
3144 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3145 @retval EFI_UNSUPPORTED No available session for ID setting.
3152 IN UINT8
*SessionId
,
3153 IN UINT16 SessionIdLen
3156 CALL_CRYPTO_SERVICE (TlsSetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
3160 Adds the CA to the cert store when requesting Server or Client authentication.
3162 This function adds the CA certificate to the list of CAs when requesting
3163 Server or Client authentication for the chosen TLS connection.
3165 @param[in] Tls Pointer to the TLS object.
3166 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3167 X.509 certificate or PEM-encoded X.509 certificate.
3168 @param[in] DataSize The size of data buffer in bytes.
3170 @retval EFI_SUCCESS The operation succeeded.
3171 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3172 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3173 @retval EFI_ABORTED Invalid X.509 certificate.
3178 TlsSetCaCertificate (
3184 CALL_CRYPTO_SERVICE (TlsSetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3188 Loads the local public certificate into the specified TLS object.
3190 This function loads the X.509 certificate into the specified TLS object
3191 for TLS negotiation.
3193 @param[in] Tls Pointer to the TLS object.
3194 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3195 X.509 certificate or PEM-encoded X.509 certificate.
3196 @param[in] DataSize The size of data buffer in bytes.
3198 @retval EFI_SUCCESS The operation succeeded.
3199 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3200 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3201 @retval EFI_ABORTED Invalid X.509 certificate.
3206 TlsSetHostPublicCert (
3212 CALL_CRYPTO_SERVICE (TlsSetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3216 Adds the local private key to the specified TLS object.
3218 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
3219 key) into the specified TLS object for TLS negotiation.
3221 @param[in] Tls Pointer to the TLS object.
3222 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
3223 or PKCS#8 private key.
3224 @param[in] DataSize The size of data buffer in bytes.
3226 @retval EFI_SUCCESS The operation succeeded.
3227 @retval EFI_UNSUPPORTED This function is not supported.
3228 @retval EFI_ABORTED Invalid private key data.
3233 TlsSetHostPrivateKey (
3239 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3243 Adds the CA-supplied certificate revocation list for certificate validation.
3245 This function adds the CA-supplied certificate revocation list data for
3246 certificate validity checking.
3248 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
3249 @param[in] DataSize The size of data buffer in bytes.
3251 @retval EFI_SUCCESS The operation succeeded.
3252 @retval EFI_UNSUPPORTED This function is not supported.
3253 @retval EFI_ABORTED Invalid CRL data.
3258 TlsSetCertRevocationList (
3263 CALL_CRYPTO_SERVICE (TlsSetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);
3267 Gets the protocol version used by the specified TLS connection.
3269 This function returns the protocol version used by the specified TLS
3272 If Tls is NULL, then ASSERT().
3274 @param[in] Tls Pointer to the TLS object.
3276 @return The protocol version of the specified TLS connection.
3285 CALL_CRYPTO_SERVICE (TlsGetVersion
, (Tls
), 0);
3289 Gets the connection end of the specified TLS connection.
3291 This function returns the connection end (as client or as server) used by
3292 the specified TLS connection.
3294 If Tls is NULL, then ASSERT().
3296 @param[in] Tls Pointer to the TLS object.
3298 @return The connection end used by the specified TLS connection.
3303 TlsGetConnectionEnd (
3307 CALL_CRYPTO_SERVICE (TlsGetConnectionEnd
, (Tls
), 0);
3311 Gets the cipher suite used by the specified TLS connection.
3313 This function returns current cipher suite used by the specified
3316 @param[in] Tls Pointer to the TLS object.
3317 @param[in,out] CipherId The cipher suite used by the TLS object.
3319 @retval EFI_SUCCESS The cipher suite was returned successfully.
3320 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3321 @retval EFI_UNSUPPORTED Unsupported cipher suite.
3326 TlsGetCurrentCipher (
3328 IN OUT UINT16
*CipherId
3331 CALL_CRYPTO_SERVICE (TlsGetCurrentCipher
, (Tls
, CipherId
), EFI_UNSUPPORTED
);
3335 Gets the compression methods used by the specified TLS connection.
3337 This function returns current integrated compression methods used by
3338 the specified TLS connection.
3340 @param[in] Tls Pointer to the TLS object.
3341 @param[in,out] CompressionId The current compression method used by
3344 @retval EFI_SUCCESS The compression method was returned successfully.
3345 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3346 @retval EFI_ABORTED Invalid Compression method.
3347 @retval EFI_UNSUPPORTED This function is not supported.
3352 TlsGetCurrentCompressionId (
3354 IN OUT UINT8
*CompressionId
3357 CALL_CRYPTO_SERVICE (TlsGetCurrentCompressionId
, (Tls
, CompressionId
), EFI_UNSUPPORTED
);
3361 Gets the verification mode currently set in the TLS connection.
3363 This function returns the peer verification mode currently set in the
3364 specified TLS connection.
3366 If Tls is NULL, then ASSERT().
3368 @param[in] Tls Pointer to the TLS object.
3370 @return The verification mode set in the specified TLS connection.
3379 CALL_CRYPTO_SERVICE (TlsGetVerify
, (Tls
), 0);
3383 Gets the session ID used by the specified TLS connection.
3385 This function returns the TLS/SSL session ID currently used by the
3386 specified TLS connection.
3388 @param[in] Tls Pointer to the TLS object.
3389 @param[in,out] SessionId Buffer to contain the returned session ID.
3390 @param[in,out] SessionIdLen The length of Session ID in bytes.
3392 @retval EFI_SUCCESS The Session ID was returned successfully.
3393 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3394 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
3401 IN OUT UINT8
*SessionId
,
3402 IN OUT UINT16
*SessionIdLen
3405 CALL_CRYPTO_SERVICE (TlsGetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
3409 Gets the client random data used in the specified TLS connection.
3411 This function returns the TLS/SSL client random data currently used in
3412 the specified TLS connection.
3414 @param[in] Tls Pointer to the TLS object.
3415 @param[in,out] ClientRandom Buffer to contain the returned client
3416 random data (32 bytes).
3421 TlsGetClientRandom (
3423 IN OUT UINT8
*ClientRandom
3426 CALL_VOID_CRYPTO_SERVICE (TlsGetClientRandom
, (Tls
, ClientRandom
));
3430 Gets the server random data used in the specified TLS connection.
3432 This function returns the TLS/SSL server random data currently used in
3433 the specified TLS connection.
3435 @param[in] Tls Pointer to the TLS object.
3436 @param[in,out] ServerRandom Buffer to contain the returned server
3437 random data (32 bytes).
3442 TlsGetServerRandom (
3444 IN OUT UINT8
*ServerRandom
3447 CALL_VOID_CRYPTO_SERVICE (TlsGetServerRandom
, (Tls
, ServerRandom
));
3451 Gets the master key data used in the specified TLS connection.
3453 This function returns the TLS/SSL master key material currently used in
3454 the specified TLS connection.
3456 @param[in] Tls Pointer to the TLS object.
3457 @param[in,out] KeyMaterial Buffer to contain the returned key material.
3459 @retval EFI_SUCCESS Key material was returned successfully.
3460 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3461 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
3468 IN OUT UINT8
*KeyMaterial
3471 CALL_CRYPTO_SERVICE (TlsGetKeyMaterial
, (Tls
, KeyMaterial
), EFI_UNSUPPORTED
);
3475 Gets the CA Certificate from the cert store.
3477 This function returns the CA certificate for the chosen
3480 @param[in] Tls Pointer to the TLS object.
3481 @param[out] Data Pointer to the data buffer to receive the CA
3482 certificate data sent to the client.
3483 @param[in,out] DataSize The size of data buffer in bytes.
3485 @retval EFI_SUCCESS The operation succeeded.
3486 @retval EFI_UNSUPPORTED This function is not supported.
3487 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3492 TlsGetCaCertificate (
3495 IN OUT UINTN
*DataSize
3498 CALL_CRYPTO_SERVICE (TlsGetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3502 Gets the local public Certificate set in the specified TLS object.
3504 This function returns the local public certificate which was currently set
3505 in the specified TLS object.
3507 @param[in] Tls Pointer to the TLS object.
3508 @param[out] Data Pointer to the data buffer to receive the local
3510 @param[in,out] DataSize The size of data buffer in bytes.
3512 @retval EFI_SUCCESS The operation succeeded.
3513 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3514 @retval EFI_NOT_FOUND The certificate is not found.
3515 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3520 TlsGetHostPublicCert (
3523 IN OUT UINTN
*DataSize
3526 CALL_CRYPTO_SERVICE (TlsGetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3530 Gets the local private key set in the specified TLS object.
3532 This function returns the local private key data which was currently set
3533 in the specified TLS object.
3535 @param[in] Tls Pointer to the TLS object.
3536 @param[out] Data Pointer to the data buffer to receive the local
3538 @param[in,out] DataSize The size of data buffer in bytes.
3540 @retval EFI_SUCCESS The operation succeeded.
3541 @retval EFI_UNSUPPORTED This function is not supported.
3542 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3547 TlsGetHostPrivateKey (
3550 IN OUT UINTN
*DataSize
3553 CALL_CRYPTO_SERVICE (TlsGetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3557 Gets the CA-supplied certificate revocation list data set in the specified
3560 This function returns the CA-supplied certificate revocation list data which
3561 was currently set in the specified TLS object.
3563 @param[out] Data Pointer to the data buffer to receive the CRL data.
3564 @param[in,out] DataSize The size of data buffer in bytes.
3566 @retval EFI_SUCCESS The operation succeeded.
3567 @retval EFI_UNSUPPORTED This function is not supported.
3568 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3573 TlsGetCertRevocationList (
3575 IN OUT UINTN
*DataSize
3578 CALL_CRYPTO_SERVICE (TlsGetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);