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 //=====================================================================================
103 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.
105 If this interface is not supported, then return zero.
107 @return The size, in bytes, of the context buffer required for MD5 hash operations.
108 @retval 0 This interface is not supported.
117 CALL_CRYPTO_SERVICE (Md5GetContextSize
, (), 0);
121 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for
124 If Md5Context is NULL, then return FALSE.
125 If this interface is not supported, then return FALSE.
127 @param[out] Md5Context Pointer to MD5 context being initialized.
129 @retval TRUE MD5 context initialization succeeded.
130 @retval FALSE MD5 context initialization failed.
131 @retval FALSE This interface is not supported.
140 CALL_CRYPTO_SERVICE (Md5Init
, (Md5Context
), FALSE
);
144 Makes a copy of an existing MD5 context.
146 If Md5Context is NULL, then return FALSE.
147 If NewMd5Context is NULL, then return FALSE.
148 If this interface is not supported, then return FALSE.
150 @param[in] Md5Context Pointer to MD5 context being copied.
151 @param[out] NewMd5Context Pointer to new MD5 context.
153 @retval TRUE MD5 context copy succeeded.
154 @retval FALSE MD5 context copy failed.
155 @retval FALSE This interface is not supported.
161 IN CONST VOID
*Md5Context
,
162 OUT VOID
*NewMd5Context
165 CALL_CRYPTO_SERVICE (Md5Duplicate
, (Md5Context
, NewMd5Context
), FALSE
);
169 Digests the input data and updates MD5 context.
171 This function performs MD5 digest on a data buffer of the specified size.
172 It can be called multiple times to compute the digest of long or discontinuous data streams.
173 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized
174 by Md5Final(). Behavior with invalid context is undefined.
176 If Md5Context is NULL, then return FALSE.
177 If this interface is not supported, then return FALSE.
179 @param[in, out] Md5Context Pointer to the MD5 context.
180 @param[in] Data Pointer to the buffer containing the data to be hashed.
181 @param[in] DataSize Size of Data buffer in bytes.
183 @retval TRUE MD5 data digest succeeded.
184 @retval FALSE MD5 data digest failed.
185 @retval FALSE This interface is not supported.
191 IN OUT VOID
*Md5Context
,
196 CALL_CRYPTO_SERVICE (Md5Update
, (Md5Context
, Data
, DataSize
), FALSE
);
200 Completes computation of the MD5 digest value.
202 This function completes MD5 hash computation and retrieves the digest value into
203 the specified memory. After this function has been called, the MD5 context cannot
205 MD5 context should be already correctly initialized by Md5Init(), and should not be
206 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.
208 If Md5Context is NULL, then return FALSE.
209 If HashValue is NULL, then return FALSE.
210 If this interface is not supported, then return FALSE.
212 @param[in, out] Md5Context Pointer to the MD5 context.
213 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
216 @retval TRUE MD5 digest computation succeeded.
217 @retval FALSE MD5 digest computation failed.
218 @retval FALSE This interface is not supported.
224 IN OUT VOID
*Md5Context
,
228 CALL_CRYPTO_SERVICE (Md5Final
, (Md5Context
, HashValue
), FALSE
);
232 Computes the MD5 message digest of a input data buffer.
234 This function performs the MD5 message digest of a given data buffer, and places
235 the digest value into the specified memory.
237 If this interface is not supported, then return FALSE.
239 @param[in] Data Pointer to the buffer containing the data to be hashed.
240 @param[in] DataSize Size of Data buffer in bytes.
241 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
244 @retval TRUE MD5 digest computation succeeded.
245 @retval FALSE MD5 digest computation failed.
246 @retval FALSE This interface is not supported.
257 CALL_CRYPTO_SERVICE (Md5HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
261 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.
263 If this interface is not supported, then return zero.
265 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.
266 @retval 0 This interface is not supported.
275 CALL_CRYPTO_SERVICE (Sha1GetContextSize
, (), 0);
279 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for
282 If Sha1Context is NULL, then return FALSE.
283 If this interface is not supported, then return FALSE.
285 @param[out] Sha1Context Pointer to SHA-1 context being initialized.
287 @retval TRUE SHA-1 context initialization succeeded.
288 @retval FALSE SHA-1 context initialization failed.
289 @retval FALSE This interface is not supported.
295 OUT VOID
*Sha1Context
298 CALL_CRYPTO_SERVICE (Sha1Init
, (Sha1Context
), FALSE
);
302 Makes a copy of an existing SHA-1 context.
304 If Sha1Context is NULL, then return FALSE.
305 If NewSha1Context is NULL, then return FALSE.
306 If this interface is not supported, then return FALSE.
308 @param[in] Sha1Context Pointer to SHA-1 context being copied.
309 @param[out] NewSha1Context Pointer to new SHA-1 context.
311 @retval TRUE SHA-1 context copy succeeded.
312 @retval FALSE SHA-1 context copy failed.
313 @retval FALSE This interface is not supported.
319 IN CONST VOID
*Sha1Context
,
320 OUT VOID
*NewSha1Context
323 CALL_CRYPTO_SERVICE (Sha1Duplicate
, (Sha1Context
, NewSha1Context
), FALSE
);
327 Digests the input data and updates SHA-1 context.
329 This function performs SHA-1 digest on a data buffer of the specified size.
330 It can be called multiple times to compute the digest of long or discontinuous data streams.
331 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized
332 by Sha1Final(). Behavior with invalid context is undefined.
334 If Sha1Context is NULL, then return FALSE.
335 If this interface is not supported, then return FALSE.
337 @param[in, out] Sha1Context Pointer to the SHA-1 context.
338 @param[in] Data Pointer to the buffer containing the data to be hashed.
339 @param[in] DataSize Size of Data buffer in bytes.
341 @retval TRUE SHA-1 data digest succeeded.
342 @retval FALSE SHA-1 data digest failed.
343 @retval FALSE This interface is not supported.
349 IN OUT VOID
*Sha1Context
,
354 CALL_CRYPTO_SERVICE (Sha1Update
, (Sha1Context
, Data
, DataSize
), FALSE
);
358 Completes computation of the SHA-1 digest value.
360 This function completes SHA-1 hash computation and retrieves the digest value into
361 the specified memory. After this function has been called, the SHA-1 context cannot
363 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be
364 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.
366 If Sha1Context is NULL, then return FALSE.
367 If HashValue is NULL, then return FALSE.
368 If this interface is not supported, then return FALSE.
370 @param[in, out] Sha1Context Pointer to the SHA-1 context.
371 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
374 @retval TRUE SHA-1 digest computation succeeded.
375 @retval FALSE SHA-1 digest computation failed.
376 @retval FALSE This interface is not supported.
382 IN OUT VOID
*Sha1Context
,
386 CALL_CRYPTO_SERVICE (Sha1Final
, (Sha1Context
, HashValue
), FALSE
);
390 Computes the SHA-1 message digest of a input data buffer.
392 This function performs the SHA-1 message digest of a given data buffer, and places
393 the digest value into the specified memory.
395 If this interface is not supported, then return FALSE.
397 @param[in] Data Pointer to the buffer containing the data to be hashed.
398 @param[in] DataSize Size of Data buffer in bytes.
399 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
402 @retval TRUE SHA-1 digest computation succeeded.
403 @retval FALSE SHA-1 digest computation failed.
404 @retval FALSE This interface is not supported.
415 CALL_CRYPTO_SERVICE (Sha1HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
419 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.
421 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.
426 Sha256GetContextSize (
430 CALL_CRYPTO_SERVICE (Sha256GetContextSize
, (), 0);
434 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for
437 If Sha256Context is NULL, then return FALSE.
439 @param[out] Sha256Context Pointer to SHA-256 context being initialized.
441 @retval TRUE SHA-256 context initialization succeeded.
442 @retval FALSE SHA-256 context initialization failed.
448 OUT VOID
*Sha256Context
451 CALL_CRYPTO_SERVICE (Sha256Init
, (Sha256Context
), FALSE
);
455 Makes a copy of an existing SHA-256 context.
457 If Sha256Context is NULL, then return FALSE.
458 If NewSha256Context is NULL, then return FALSE.
459 If this interface is not supported, then return FALSE.
461 @param[in] Sha256Context Pointer to SHA-256 context being copied.
462 @param[out] NewSha256Context Pointer to new SHA-256 context.
464 @retval TRUE SHA-256 context copy succeeded.
465 @retval FALSE SHA-256 context copy failed.
466 @retval FALSE This interface is not supported.
472 IN CONST VOID
*Sha256Context
,
473 OUT VOID
*NewSha256Context
476 CALL_CRYPTO_SERVICE (Sha256Duplicate
, (Sha256Context
, NewSha256Context
), FALSE
);
480 Digests the input data and updates SHA-256 context.
482 This function performs SHA-256 digest on a data buffer of the specified size.
483 It can be called multiple times to compute the digest of long or discontinuous data streams.
484 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized
485 by Sha256Final(). Behavior with invalid context is undefined.
487 If Sha256Context is NULL, then return FALSE.
489 @param[in, out] Sha256Context Pointer to the SHA-256 context.
490 @param[in] Data Pointer to the buffer containing the data to be hashed.
491 @param[in] DataSize Size of Data buffer in bytes.
493 @retval TRUE SHA-256 data digest succeeded.
494 @retval FALSE SHA-256 data digest failed.
500 IN OUT VOID
*Sha256Context
,
505 CALL_CRYPTO_SERVICE (Sha256Update
, (Sha256Context
, Data
, DataSize
), FALSE
);
509 Completes computation of the SHA-256 digest value.
511 This function completes SHA-256 hash computation and retrieves the digest value into
512 the specified memory. After this function has been called, the SHA-256 context cannot
514 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be
515 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.
517 If Sha256Context is NULL, then return FALSE.
518 If HashValue is NULL, then return FALSE.
520 @param[in, out] Sha256Context Pointer to the SHA-256 context.
521 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
524 @retval TRUE SHA-256 digest computation succeeded.
525 @retval FALSE SHA-256 digest computation failed.
531 IN OUT VOID
*Sha256Context
,
535 CALL_CRYPTO_SERVICE (Sha256Final
, (Sha256Context
, HashValue
), FALSE
);
539 Computes the SHA-256 message digest of a input data buffer.
541 This function performs the SHA-256 message digest of a given data buffer, and places
542 the digest value into the specified memory.
544 If this interface is not supported, then return FALSE.
546 @param[in] Data Pointer to the buffer containing the data to be hashed.
547 @param[in] DataSize Size of Data buffer in bytes.
548 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
551 @retval TRUE SHA-256 digest computation succeeded.
552 @retval FALSE SHA-256 digest computation failed.
553 @retval FALSE This interface is not supported.
564 CALL_CRYPTO_SERVICE (Sha256HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
568 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.
570 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.
575 Sha384GetContextSize (
579 CALL_CRYPTO_SERVICE (Sha384GetContextSize
, (), 0);
583 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for
586 If Sha384Context is NULL, then return FALSE.
588 @param[out] Sha384Context Pointer to SHA-384 context being initialized.
590 @retval TRUE SHA-384 context initialization succeeded.
591 @retval FALSE SHA-384 context initialization failed.
597 OUT VOID
*Sha384Context
600 CALL_CRYPTO_SERVICE (Sha384Init
, (Sha384Context
), FALSE
);
604 Makes a copy of an existing SHA-384 context.
606 If Sha384Context is NULL, then return FALSE.
607 If NewSha384Context is NULL, then return FALSE.
608 If this interface is not supported, then return FALSE.
610 @param[in] Sha384Context Pointer to SHA-384 context being copied.
611 @param[out] NewSha384Context Pointer to new SHA-384 context.
613 @retval TRUE SHA-384 context copy succeeded.
614 @retval FALSE SHA-384 context copy failed.
615 @retval FALSE This interface is not supported.
621 IN CONST VOID
*Sha384Context
,
622 OUT VOID
*NewSha384Context
625 CALL_CRYPTO_SERVICE (Sha384Duplicate
, (Sha384Context
, NewSha384Context
), FALSE
);
629 Digests the input data and updates SHA-384 context.
631 This function performs SHA-384 digest on a data buffer of the specified size.
632 It can be called multiple times to compute the digest of long or discontinuous data streams.
633 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized
634 by Sha384Final(). Behavior with invalid context is undefined.
636 If Sha384Context is NULL, then return FALSE.
638 @param[in, out] Sha384Context Pointer to the SHA-384 context.
639 @param[in] Data Pointer to the buffer containing the data to be hashed.
640 @param[in] DataSize Size of Data buffer in bytes.
642 @retval TRUE SHA-384 data digest succeeded.
643 @retval FALSE SHA-384 data digest failed.
649 IN OUT VOID
*Sha384Context
,
654 CALL_CRYPTO_SERVICE (Sha384Update
, (Sha384Context
, Data
, DataSize
), FALSE
);
658 Completes computation of the SHA-384 digest value.
660 This function completes SHA-384 hash computation and retrieves the digest value into
661 the specified memory. After this function has been called, the SHA-384 context cannot
663 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be
664 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.
666 If Sha384Context is NULL, then return FALSE.
667 If HashValue is NULL, then return FALSE.
669 @param[in, out] Sha384Context Pointer to the SHA-384 context.
670 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
673 @retval TRUE SHA-384 digest computation succeeded.
674 @retval FALSE SHA-384 digest computation failed.
680 IN OUT VOID
*Sha384Context
,
684 CALL_CRYPTO_SERVICE (Sha384Final
, (Sha384Context
, HashValue
), FALSE
);
688 Computes the SHA-384 message digest of a input data buffer.
690 This function performs the SHA-384 message digest of a given data buffer, and places
691 the digest value into the specified memory.
693 If this interface is not supported, then return FALSE.
695 @param[in] Data Pointer to the buffer containing the data to be hashed.
696 @param[in] DataSize Size of Data buffer in bytes.
697 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
700 @retval TRUE SHA-384 digest computation succeeded.
701 @retval FALSE SHA-384 digest computation failed.
702 @retval FALSE This interface is not supported.
713 CALL_CRYPTO_SERVICE (Sha384HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
717 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.
719 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.
724 Sha512GetContextSize (
728 CALL_CRYPTO_SERVICE (Sha512GetContextSize
, (), 0);
732 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for
735 If Sha512Context is NULL, then return FALSE.
737 @param[out] Sha512Context Pointer to SHA-512 context being initialized.
739 @retval TRUE SHA-512 context initialization succeeded.
740 @retval FALSE SHA-512 context initialization failed.
746 OUT VOID
*Sha512Context
749 CALL_CRYPTO_SERVICE (Sha512Init
, (Sha512Context
), FALSE
);
753 Makes a copy of an existing SHA-512 context.
755 If Sha512Context is NULL, then return FALSE.
756 If NewSha512Context is NULL, then return FALSE.
757 If this interface is not supported, then return FALSE.
759 @param[in] Sha512Context Pointer to SHA-512 context being copied.
760 @param[out] NewSha512Context Pointer to new SHA-512 context.
762 @retval TRUE SHA-512 context copy succeeded.
763 @retval FALSE SHA-512 context copy failed.
764 @retval FALSE This interface is not supported.
770 IN CONST VOID
*Sha512Context
,
771 OUT VOID
*NewSha512Context
774 CALL_CRYPTO_SERVICE (Sha512Duplicate
, (Sha512Context
, NewSha512Context
), FALSE
);
778 Digests the input data and updates SHA-512 context.
780 This function performs SHA-512 digest on a data buffer of the specified size.
781 It can be called multiple times to compute the digest of long or discontinuous data streams.
782 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized
783 by Sha512Final(). Behavior with invalid context is undefined.
785 If Sha512Context is NULL, then return FALSE.
787 @param[in, out] Sha512Context Pointer to the SHA-512 context.
788 @param[in] Data Pointer to the buffer containing the data to be hashed.
789 @param[in] DataSize Size of Data buffer in bytes.
791 @retval TRUE SHA-512 data digest succeeded.
792 @retval FALSE SHA-512 data digest failed.
798 IN OUT VOID
*Sha512Context
,
803 CALL_CRYPTO_SERVICE (Sha512Update
, (Sha512Context
, Data
, DataSize
), FALSE
);
807 Completes computation of the SHA-512 digest value.
809 This function completes SHA-512 hash computation and retrieves the digest value into
810 the specified memory. After this function has been called, the SHA-512 context cannot
812 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be
813 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.
815 If Sha512Context is NULL, then return FALSE.
816 If HashValue is NULL, then return FALSE.
818 @param[in, out] Sha512Context Pointer to the SHA-512 context.
819 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
822 @retval TRUE SHA-512 digest computation succeeded.
823 @retval FALSE SHA-512 digest computation failed.
829 IN OUT VOID
*Sha512Context
,
833 CALL_CRYPTO_SERVICE (Sha512Final
, (Sha512Context
, HashValue
), FALSE
);
837 Computes the SHA-512 message digest of a input data buffer.
839 This function performs the SHA-512 message digest of a given data buffer, and places
840 the digest value into the specified memory.
842 If this interface is not supported, then return FALSE.
844 @param[in] Data Pointer to the buffer containing the data to be hashed.
845 @param[in] DataSize Size of Data buffer in bytes.
846 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
849 @retval TRUE SHA-512 digest computation succeeded.
850 @retval FALSE SHA-512 digest computation failed.
851 @retval FALSE This interface is not supported.
862 CALL_CRYPTO_SERVICE (Sha512HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
866 Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.
868 @return The size, in bytes, of the context buffer required for SM3 hash operations.
877 CALL_CRYPTO_SERVICE (Sm3GetContextSize
, (), 0);
881 Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for
884 If Sm3Context is NULL, then return FALSE.
886 @param[out] Sm3Context Pointer to SM3 context being initialized.
888 @retval TRUE SM3 context initialization succeeded.
889 @retval FALSE SM3 context initialization failed.
898 CALL_CRYPTO_SERVICE (Sm3Init
, (Sm3Context
), FALSE
);
902 Makes a copy of an existing SM3 context.
904 If Sm3Context is NULL, then return FALSE.
905 If NewSm3Context is NULL, then return FALSE.
906 If this interface is not supported, then return FALSE.
908 @param[in] Sm3Context Pointer to SM3 context being copied.
909 @param[out] NewSm3Context Pointer to new SM3 context.
911 @retval TRUE SM3 context copy succeeded.
912 @retval FALSE SM3 context copy failed.
913 @retval FALSE This interface is not supported.
919 IN CONST VOID
*Sm3Context
,
920 OUT VOID
*NewSm3Context
923 CALL_CRYPTO_SERVICE (Sm3Duplicate
, (Sm3Context
, NewSm3Context
), FALSE
);
927 Digests the input data and updates SM3 context.
929 This function performs SM3 digest on a data buffer of the specified size.
930 It can be called multiple times to compute the digest of long or discontinuous data streams.
931 SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized
932 by Sm3Final(). Behavior with invalid context is undefined.
934 If Sm3Context is NULL, then return FALSE.
936 @param[in, out] Sm3Context Pointer to the SM3 context.
937 @param[in] Data Pointer to the buffer containing the data to be hashed.
938 @param[in] DataSize Size of Data buffer in bytes.
940 @retval TRUE SM3 data digest succeeded.
941 @retval FALSE SM3 data digest failed.
947 IN OUT VOID
*Sm3Context
,
952 CALL_CRYPTO_SERVICE (Sm3Update
, (Sm3Context
, Data
, DataSize
), FALSE
);
956 Completes computation of the SM3 digest value.
958 This function completes SM3 hash computation and retrieves the digest value into
959 the specified memory. After this function has been called, the SM3 context cannot
961 SM3 context should be already correctly initialized by Sm3Init(), and should not be
962 finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.
964 If Sm3Context is NULL, then return FALSE.
965 If HashValue is NULL, then return FALSE.
967 @param[in, out] Sm3Context Pointer to the SM3 context.
968 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
971 @retval TRUE SM3 digest computation succeeded.
972 @retval FALSE SM3 digest computation failed.
978 IN OUT VOID
*Sm3Context
,
982 CALL_CRYPTO_SERVICE (Sm3Final
, (Sm3Context
, HashValue
), FALSE
);
986 Computes the SM3 message digest of a input data buffer.
988 This function performs the SM3 message digest of a given data buffer, and places
989 the digest value into the specified memory.
991 If this interface is not supported, then return FALSE.
993 @param[in] Data Pointer to the buffer containing the data to be hashed.
994 @param[in] DataSize Size of Data buffer in bytes.
995 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
998 @retval TRUE SM3 digest computation succeeded.
999 @retval FALSE SM3 digest computation failed.
1000 @retval FALSE This interface is not supported.
1006 IN CONST VOID
*Data
,
1008 OUT UINT8
*HashValue
1011 CALL_CRYPTO_SERVICE (Sm3HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
1014 //=====================================================================================
1015 // MAC (Message Authentication Code) Primitive
1016 //=====================================================================================
1019 Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD5 use.
1021 If this interface is not supported, then return NULL.
1023 @return Pointer to the HMAC_CTX context that has been initialized.
1024 If the allocations fails, HmacMd5New() returns NULL.
1025 @retval NULL This interface is not supported.
1034 CALL_CRYPTO_SERVICE (HmacMd5New
, (), NULL
);
1038 Release the specified HMAC_CTX context.
1040 If this interface is not supported, then do nothing.
1042 @param[in] HmacMd5Ctx Pointer to the HMAC_CTX context to be released.
1051 CALL_VOID_CRYPTO_SERVICE (HmacMd5Free
, (HmacMd5Ctx
));
1055 Set user-supplied key for subsequent use. It must be done before any
1056 calling to HmacMd5Update().
1058 If HmacMd5Context is NULL, then return FALSE.
1059 If this interface is not supported, then return FALSE.
1061 @param[out] HmacMd5Context Pointer to HMAC-MD5 context.
1062 @param[in] Key Pointer to the user-supplied key.
1063 @param[in] KeySize Key size in bytes.
1065 @retval TRUE Key is set successfully.
1066 @retval FALSE Key is set unsuccessfully.
1067 @retval FALSE This interface is not supported.
1073 OUT VOID
*HmacMd5Context
,
1074 IN CONST UINT8
*Key
,
1078 CALL_CRYPTO_SERVICE (HmacMd5SetKey
, (HmacMd5Context
, Key
, KeySize
), FALSE
);
1082 Makes a copy of an existing HMAC-MD5 context.
1084 If HmacMd5Context is NULL, then return FALSE.
1085 If NewHmacMd5Context is NULL, then return FALSE.
1086 If this interface is not supported, then return FALSE.
1088 @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied.
1089 @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context.
1091 @retval TRUE HMAC-MD5 context copy succeeded.
1092 @retval FALSE HMAC-MD5 context copy failed.
1093 @retval FALSE This interface is not supported.
1099 IN CONST VOID
*HmacMd5Context
,
1100 OUT VOID
*NewHmacMd5Context
1103 CALL_CRYPTO_SERVICE (HmacMd5Duplicate
, (HmacMd5Context
, NewHmacMd5Context
), FALSE
);
1107 Digests the input data and updates HMAC-MD5 context.
1109 This function performs HMAC-MD5 digest on a data buffer of the specified size.
1110 It can be called multiple times to compute the digest of long or discontinuous data streams.
1111 HMAC-MD5 context should be initialized by HmacMd5New(), and should not be finalized by
1112 HmacMd5Final(). Behavior with invalid context is undefined.
1114 If HmacMd5Context is NULL, then return FALSE.
1115 If this interface is not supported, then return FALSE.
1117 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
1118 @param[in] Data Pointer to the buffer containing the data to be digested.
1119 @param[in] DataSize Size of Data buffer in bytes.
1121 @retval TRUE HMAC-MD5 data digest succeeded.
1122 @retval FALSE HMAC-MD5 data digest failed.
1123 @retval FALSE This interface is not supported.
1129 IN OUT VOID
*HmacMd5Context
,
1130 IN CONST VOID
*Data
,
1134 CALL_CRYPTO_SERVICE (HmacMd5Update
, (HmacMd5Context
, Data
, DataSize
), FALSE
);
1138 Completes computation of the HMAC-MD5 digest value.
1140 This function completes HMAC-MD5 hash computation and retrieves the digest value into
1141 the specified memory. After this function has been called, the HMAC-MD5 context cannot
1143 HMAC-MD5 context should be initialized by HmacMd5New(), and should not be finalized by
1144 HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined.
1146 If HmacMd5Context is NULL, then return FALSE.
1147 If HmacValue is NULL, then return FALSE.
1148 If this interface is not supported, then return FALSE.
1150 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
1151 @param[out] HmacValue Pointer to a buffer that receives the HMAC-MD5 digest
1154 @retval TRUE HMAC-MD5 digest computation succeeded.
1155 @retval FALSE HMAC-MD5 digest computation failed.
1156 @retval FALSE This interface is not supported.
1162 IN OUT VOID
*HmacMd5Context
,
1163 OUT UINT8
*HmacValue
1166 CALL_CRYPTO_SERVICE (HmacMd5Final
, (HmacMd5Context
, HmacValue
), FALSE
);
1170 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA1 use.
1172 If this interface is not supported, then return NULL.
1174 @return Pointer to the HMAC_CTX context that has been initialized.
1175 If the allocations fails, HmacSha1New() returns NULL.
1176 @return NULL This interface is not supported.
1185 CALL_CRYPTO_SERVICE (HmacSha1New
, (), NULL
);
1189 Release the specified HMAC_CTX context.
1191 If this interface is not supported, then do nothing.
1193 @param[in] HmacSha1Ctx Pointer to the HMAC_CTX context to be released.
1199 IN VOID
*HmacSha1Ctx
1202 CALL_VOID_CRYPTO_SERVICE (HmacSha1Free
, (HmacSha1Ctx
));
1206 Set user-supplied key for subsequent use. It must be done before any
1207 calling to HmacSha1Update().
1209 If HmacSha1Context is NULL, then return FALSE.
1210 If this interface is not supported, then return FALSE.
1212 @param[out] HmacSha1Context Pointer to HMAC-SHA1 context.
1213 @param[in] Key Pointer to the user-supplied key.
1214 @param[in] KeySize Key size in bytes.
1216 @retval TRUE The Key is set successfully.
1217 @retval FALSE The Key is set unsuccessfully.
1218 @retval FALSE This interface is not supported.
1224 OUT VOID
*HmacSha1Context
,
1225 IN CONST UINT8
*Key
,
1229 CALL_CRYPTO_SERVICE (HmacSha1SetKey
, (HmacSha1Context
, Key
, KeySize
), FALSE
);
1233 Makes a copy of an existing HMAC-SHA1 context.
1235 If HmacSha1Context is NULL, then return FALSE.
1236 If NewHmacSha1Context is NULL, then return FALSE.
1237 If this interface is not supported, then return FALSE.
1239 @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied.
1240 @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context.
1242 @retval TRUE HMAC-SHA1 context copy succeeded.
1243 @retval FALSE HMAC-SHA1 context copy failed.
1244 @retval FALSE This interface is not supported.
1250 IN CONST VOID
*HmacSha1Context
,
1251 OUT VOID
*NewHmacSha1Context
1254 CALL_CRYPTO_SERVICE (HmacSha1Duplicate
, (HmacSha1Context
, NewHmacSha1Context
), FALSE
);
1258 Digests the input data and updates HMAC-SHA1 context.
1260 This function performs HMAC-SHA1 digest on a data buffer of the specified size.
1261 It can be called multiple times to compute the digest of long or discontinuous data streams.
1262 HMAC-SHA1 context should be initialized by HmacSha1New(), and should not be finalized by
1263 HmacSha1Final(). Behavior with invalid context is undefined.
1265 If HmacSha1Context is NULL, then return FALSE.
1266 If this interface is not supported, then return FALSE.
1268 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1269 @param[in] Data Pointer to the buffer containing the data to be digested.
1270 @param[in] DataSize Size of Data buffer in bytes.
1272 @retval TRUE HMAC-SHA1 data digest succeeded.
1273 @retval FALSE HMAC-SHA1 data digest failed.
1274 @retval FALSE This interface is not supported.
1280 IN OUT VOID
*HmacSha1Context
,
1281 IN CONST VOID
*Data
,
1285 CALL_CRYPTO_SERVICE (HmacSha1Update
, (HmacSha1Context
, Data
, DataSize
), FALSE
);
1289 Completes computation of the HMAC-SHA1 digest value.
1291 This function completes HMAC-SHA1 hash computation and retrieves the digest value into
1292 the specified memory. After this function has been called, the HMAC-SHA1 context cannot
1294 HMAC-SHA1 context should be initialized by HmacSha1New(), and should not be finalized
1295 by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined.
1297 If HmacSha1Context is NULL, then return FALSE.
1298 If HmacValue is NULL, then return FALSE.
1299 If this interface is not supported, then return FALSE.
1301 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1302 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA1 digest
1305 @retval TRUE HMAC-SHA1 digest computation succeeded.
1306 @retval FALSE HMAC-SHA1 digest computation failed.
1307 @retval FALSE This interface is not supported.
1313 IN OUT VOID
*HmacSha1Context
,
1314 OUT UINT8
*HmacValue
1317 CALL_CRYPTO_SERVICE (HmacSha1Final
, (HmacSha1Context
, HmacValue
), FALSE
);
1321 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
1323 @return Pointer to the HMAC_CTX context that has been initialized.
1324 If the allocations fails, HmacSha256New() returns NULL.
1333 CALL_CRYPTO_SERVICE (HmacSha256New
, (), NULL
);
1337 Release the specified HMAC_CTX context.
1339 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.
1345 IN VOID
*HmacSha256Ctx
1348 CALL_VOID_CRYPTO_SERVICE (HmacSha256Free
, (HmacSha256Ctx
));
1352 Set user-supplied key for subsequent use. It must be done before any
1353 calling to HmacSha256Update().
1355 If HmacSha256Context is NULL, then return FALSE.
1356 If this interface is not supported, then return FALSE.
1358 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.
1359 @param[in] Key Pointer to the user-supplied key.
1360 @param[in] KeySize Key size in bytes.
1362 @retval TRUE The Key is set successfully.
1363 @retval FALSE The Key is set unsuccessfully.
1364 @retval FALSE This interface is not supported.
1370 OUT VOID
*HmacSha256Context
,
1371 IN CONST UINT8
*Key
,
1375 CALL_CRYPTO_SERVICE (HmacSha256SetKey
, (HmacSha256Context
, Key
, KeySize
), FALSE
);
1379 Makes a copy of an existing HMAC-SHA256 context.
1381 If HmacSha256Context is NULL, then return FALSE.
1382 If NewHmacSha256Context is NULL, then return FALSE.
1383 If this interface is not supported, then return FALSE.
1385 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.
1386 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.
1388 @retval TRUE HMAC-SHA256 context copy succeeded.
1389 @retval FALSE HMAC-SHA256 context copy failed.
1390 @retval FALSE This interface is not supported.
1395 HmacSha256Duplicate (
1396 IN CONST VOID
*HmacSha256Context
,
1397 OUT VOID
*NewHmacSha256Context
1400 CALL_CRYPTO_SERVICE (HmacSha256Duplicate
, (HmacSha256Context
, NewHmacSha256Context
), FALSE
);
1404 Digests the input data and updates HMAC-SHA256 context.
1406 This function performs HMAC-SHA256 digest on a data buffer of the specified size.
1407 It can be called multiple times to compute the digest of long or discontinuous data streams.
1408 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1409 by HmacSha256Final(). Behavior with invalid context is undefined.
1411 If HmacSha256Context is NULL, then return FALSE.
1412 If this interface is not supported, then return FALSE.
1414 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1415 @param[in] Data Pointer to the buffer containing the data to be digested.
1416 @param[in] DataSize Size of Data buffer in bytes.
1418 @retval TRUE HMAC-SHA256 data digest succeeded.
1419 @retval FALSE HMAC-SHA256 data digest failed.
1420 @retval FALSE This interface is not supported.
1426 IN OUT VOID
*HmacSha256Context
,
1427 IN CONST VOID
*Data
,
1431 CALL_CRYPTO_SERVICE (HmacSha256Update
, (HmacSha256Context
, Data
, DataSize
), FALSE
);
1435 Completes computation of the HMAC-SHA256 digest value.
1437 This function completes HMAC-SHA256 hash computation and retrieves the digest value into
1438 the specified memory. After this function has been called, the HMAC-SHA256 context cannot
1440 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1441 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.
1443 If HmacSha256Context is NULL, then return FALSE.
1444 If HmacValue is NULL, then return FALSE.
1445 If this interface is not supported, then return FALSE.
1447 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1448 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
1451 @retval TRUE HMAC-SHA256 digest computation succeeded.
1452 @retval FALSE HMAC-SHA256 digest computation failed.
1453 @retval FALSE This interface is not supported.
1459 IN OUT VOID
*HmacSha256Context
,
1460 OUT UINT8
*HmacValue
1463 CALL_CRYPTO_SERVICE (HmacSha256Final
, (HmacSha256Context
, HmacValue
), FALSE
);
1466 //=====================================================================================
1467 // Symmetric Cryptography Primitive
1468 //=====================================================================================
1471 Retrieves the size, in bytes, of the context buffer required for TDES operations.
1473 If this interface is not supported, then return zero.
1475 @return The size, in bytes, of the context buffer required for TDES operations.
1476 @retval 0 This interface is not supported.
1481 TdesGetContextSize (
1485 CALL_CRYPTO_SERVICE (TdesGetContextSize
, (), 0);
1489 Initializes user-supplied memory as TDES context for subsequent use.
1491 This function initializes user-supplied memory pointed by TdesContext as TDES context.
1492 In addition, it sets up all TDES key materials for subsequent encryption and decryption
1494 There are 3 key options as follows:
1495 KeyLength = 64, Keying option 1: K1 == K2 == K3 (Backward compatibility with DES)
1496 KeyLength = 128, Keying option 2: K1 != K2 and K3 = K1 (Less Security)
1497 KeyLength = 192 Keying option 3: K1 != K2 != K3 (Strongest)
1499 If TdesContext is NULL, then return FALSE.
1500 If Key is NULL, then return FALSE.
1501 If KeyLength is not valid, then return FALSE.
1502 If this interface is not supported, then return FALSE.
1504 @param[out] TdesContext Pointer to TDES context being initialized.
1505 @param[in] Key Pointer to the user-supplied TDES key.
1506 @param[in] KeyLength Length of TDES key in bits.
1508 @retval TRUE TDES context initialization succeeded.
1509 @retval FALSE TDES context initialization failed.
1510 @retval FALSE This interface is not supported.
1516 OUT VOID
*TdesContext
,
1517 IN CONST UINT8
*Key
,
1521 CALL_CRYPTO_SERVICE (TdesInit
, (TdesContext
, Key
, KeyLength
), FALSE
);
1525 Performs TDES encryption on a data buffer of the specified size in ECB mode.
1527 This function performs TDES encryption on data buffer pointed by Input, of specified
1528 size of InputSize, in ECB mode.
1529 InputSize must be multiple of block size (8 bytes). This function does not perform
1530 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1531 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1532 invalid TDES context is undefined.
1534 If TdesContext is NULL, then return FALSE.
1535 If Input is NULL, then return FALSE.
1536 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1537 If Output is NULL, then return FALSE.
1538 If this interface is not supported, then return FALSE.
1540 @param[in] TdesContext Pointer to the TDES context.
1541 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1542 @param[in] InputSize Size of the Input buffer in bytes.
1543 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1545 @retval TRUE TDES encryption succeeded.
1546 @retval FALSE TDES encryption failed.
1547 @retval FALSE This interface is not supported.
1553 IN VOID
*TdesContext
,
1554 IN CONST UINT8
*Input
,
1559 CALL_CRYPTO_SERVICE (TdesEcbEncrypt
, (TdesContext
, Input
, InputSize
, Output
), FALSE
);
1563 Performs TDES decryption on a data buffer of the specified size in ECB mode.
1565 This function performs TDES decryption on data buffer pointed by Input, of specified
1566 size of InputSize, in ECB mode.
1567 InputSize must be multiple of block size (8 bytes). This function does not perform
1568 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1569 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1570 invalid TDES context is undefined.
1572 If TdesContext is NULL, then return FALSE.
1573 If Input is NULL, then return FALSE.
1574 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1575 If Output is NULL, then return FALSE.
1576 If this interface is not supported, then return FALSE.
1578 @param[in] TdesContext Pointer to the TDES context.
1579 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1580 @param[in] InputSize Size of the Input buffer in bytes.
1581 @param[out] Output Pointer to a buffer that receives the TDES decryption output.
1583 @retval TRUE TDES decryption succeeded.
1584 @retval FALSE TDES decryption failed.
1585 @retval FALSE This interface is not supported.
1591 IN VOID
*TdesContext
,
1592 IN CONST UINT8
*Input
,
1597 CALL_CRYPTO_SERVICE (TdesEcbDecrypt
, (TdesContext
, Input
, InputSize
, Output
), FALSE
);
1601 Performs TDES encryption on a data buffer of the specified size in CBC mode.
1603 This function performs TDES encryption on data buffer pointed by Input, of specified
1604 size of InputSize, in CBC mode.
1605 InputSize must be multiple of block size (8 bytes). This function does not perform
1606 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1607 Initialization vector should be one block size (8 bytes).
1608 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1609 invalid TDES context is undefined.
1611 If TdesContext is NULL, then return FALSE.
1612 If Input is NULL, then return FALSE.
1613 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1614 If Ivec is NULL, then return FALSE.
1615 If Output is NULL, then return FALSE.
1616 If this interface is not supported, then return FALSE.
1618 @param[in] TdesContext Pointer to the TDES context.
1619 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1620 @param[in] InputSize Size of the Input buffer in bytes.
1621 @param[in] Ivec Pointer to initialization vector.
1622 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1624 @retval TRUE TDES encryption succeeded.
1625 @retval FALSE TDES encryption failed.
1626 @retval FALSE This interface is not supported.
1632 IN VOID
*TdesContext
,
1633 IN CONST UINT8
*Input
,
1635 IN CONST UINT8
*Ivec
,
1639 CALL_CRYPTO_SERVICE (TdesCbcEncrypt
, (TdesContext
, Input
, InputSize
, Ivec
, Output
), FALSE
);
1643 Performs TDES decryption on a data buffer of the specified size in CBC mode.
1645 This function performs TDES decryption on data buffer pointed by Input, of specified
1646 size of InputSize, in CBC mode.
1647 InputSize must be multiple of block size (8 bytes). This function does not perform
1648 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1649 Initialization vector should be one block size (8 bytes).
1650 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1651 invalid TDES context is undefined.
1653 If TdesContext is NULL, then return FALSE.
1654 If Input is NULL, then return FALSE.
1655 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1656 If Ivec is NULL, then return FALSE.
1657 If Output is NULL, then return FALSE.
1658 If this interface is not supported, then return FALSE.
1660 @param[in] TdesContext Pointer to the TDES context.
1661 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1662 @param[in] InputSize Size of the Input buffer in bytes.
1663 @param[in] Ivec Pointer to initialization vector.
1664 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1666 @retval TRUE TDES decryption succeeded.
1667 @retval FALSE TDES decryption failed.
1668 @retval FALSE This interface is not supported.
1674 IN VOID
*TdesContext
,
1675 IN CONST UINT8
*Input
,
1677 IN CONST UINT8
*Ivec
,
1681 CALL_CRYPTO_SERVICE (TdesCbcDecrypt
, (TdesContext
, Input
, InputSize
, Ivec
, Output
), FALSE
);
1685 Retrieves the size, in bytes, of the context buffer required for AES operations.
1687 If this interface is not supported, then return zero.
1689 @return The size, in bytes, of the context buffer required for AES operations.
1690 @retval 0 This interface is not supported.
1699 CALL_CRYPTO_SERVICE (AesGetContextSize
, (), 0);
1703 Initializes user-supplied memory as AES context for subsequent use.
1705 This function initializes user-supplied memory pointed by AesContext as AES context.
1706 In addition, it sets up all AES key materials for subsequent encryption and decryption
1708 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1710 If AesContext is NULL, then return FALSE.
1711 If Key is NULL, then return FALSE.
1712 If KeyLength is not valid, then return FALSE.
1713 If this interface is not supported, then return FALSE.
1715 @param[out] AesContext Pointer to AES context being initialized.
1716 @param[in] Key Pointer to the user-supplied AES key.
1717 @param[in] KeyLength Length of AES key in bits.
1719 @retval TRUE AES context initialization succeeded.
1720 @retval FALSE AES context initialization failed.
1721 @retval FALSE This interface is not supported.
1727 OUT VOID
*AesContext
,
1728 IN CONST UINT8
*Key
,
1732 CALL_CRYPTO_SERVICE (AesInit
, (AesContext
, Key
, KeyLength
), FALSE
);
1736 Performs AES encryption on a data buffer of the specified size in ECB mode.
1738 This function performs AES encryption on data buffer pointed by Input, of specified
1739 size of InputSize, in ECB mode.
1740 InputSize must be multiple of block size (16 bytes). This function does not perform
1741 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1742 AesContext should be already correctly initialized by AesInit(). Behavior with
1743 invalid AES context is undefined.
1745 If AesContext is NULL, then return FALSE.
1746 If Input is NULL, then return FALSE.
1747 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1748 If Output is NULL, then return FALSE.
1749 If this interface is not supported, then return FALSE.
1751 @param[in] AesContext Pointer to the AES context.
1752 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1753 @param[in] InputSize Size of the Input buffer in bytes.
1754 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1756 @retval TRUE AES encryption succeeded.
1757 @retval FALSE AES encryption failed.
1758 @retval FALSE This interface is not supported.
1764 IN VOID
*AesContext
,
1765 IN CONST UINT8
*Input
,
1770 CALL_CRYPTO_SERVICE (AesEcbEncrypt
, (AesContext
, Input
, InputSize
, Output
), FALSE
);
1774 Performs AES decryption on a data buffer of the specified size in ECB mode.
1776 This function performs AES decryption on data buffer pointed by Input, of specified
1777 size of InputSize, in ECB mode.
1778 InputSize must be multiple of block size (16 bytes). This function does not perform
1779 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1780 AesContext should be already correctly initialized by AesInit(). Behavior with
1781 invalid AES context is undefined.
1783 If AesContext is NULL, then return FALSE.
1784 If Input is NULL, then return FALSE.
1785 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1786 If Output is NULL, then return FALSE.
1787 If this interface is not supported, then return FALSE.
1789 @param[in] AesContext Pointer to the AES context.
1790 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1791 @param[in] InputSize Size of the Input buffer in bytes.
1792 @param[out] Output Pointer to a buffer that receives the AES decryption output.
1794 @retval TRUE AES decryption succeeded.
1795 @retval FALSE AES decryption failed.
1796 @retval FALSE This interface is not supported.
1802 IN VOID
*AesContext
,
1803 IN CONST UINT8
*Input
,
1808 CALL_CRYPTO_SERVICE (AesEcbDecrypt
, (AesContext
, Input
, InputSize
, Output
), FALSE
);
1812 Performs AES encryption on a data buffer of the specified size in CBC mode.
1814 This function performs AES encryption on data buffer pointed by Input, of specified
1815 size of InputSize, in CBC mode.
1816 InputSize must be multiple of block size (16 bytes). This function does not perform
1817 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1818 Initialization vector should be one block size (16 bytes).
1819 AesContext should be already correctly initialized by AesInit(). Behavior with
1820 invalid AES context is undefined.
1822 If AesContext is NULL, then return FALSE.
1823 If Input is NULL, then return FALSE.
1824 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1825 If Ivec is NULL, then return FALSE.
1826 If Output is NULL, then return FALSE.
1827 If this interface is not supported, then return FALSE.
1829 @param[in] AesContext Pointer to the AES context.
1830 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1831 @param[in] InputSize Size of the Input buffer in bytes.
1832 @param[in] Ivec Pointer to initialization vector.
1833 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1835 @retval TRUE AES encryption succeeded.
1836 @retval FALSE AES encryption failed.
1837 @retval FALSE This interface is not supported.
1843 IN VOID
*AesContext
,
1844 IN CONST UINT8
*Input
,
1846 IN CONST UINT8
*Ivec
,
1850 CALL_CRYPTO_SERVICE (AesCbcEncrypt
, (AesContext
, Input
, InputSize
, Ivec
, Output
), FALSE
);
1854 Performs AES decryption on a data buffer of the specified size in CBC mode.
1856 This function performs AES decryption on data buffer pointed by Input, of specified
1857 size of InputSize, in CBC mode.
1858 InputSize must be multiple of block size (16 bytes). This function does not perform
1859 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1860 Initialization vector should be one block size (16 bytes).
1861 AesContext should be already correctly initialized by AesInit(). Behavior with
1862 invalid AES context is undefined.
1864 If AesContext is NULL, then return FALSE.
1865 If Input is NULL, then return FALSE.
1866 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1867 If Ivec is NULL, then return FALSE.
1868 If Output is NULL, then return FALSE.
1869 If this interface is not supported, then return FALSE.
1871 @param[in] AesContext Pointer to the AES context.
1872 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1873 @param[in] InputSize Size of the Input buffer in bytes.
1874 @param[in] Ivec Pointer to initialization vector.
1875 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1877 @retval TRUE AES decryption succeeded.
1878 @retval FALSE AES decryption failed.
1879 @retval FALSE This interface is not supported.
1885 IN VOID
*AesContext
,
1886 IN CONST UINT8
*Input
,
1888 IN CONST UINT8
*Ivec
,
1892 CALL_CRYPTO_SERVICE (AesCbcDecrypt
, (AesContext
, Input
, InputSize
, Ivec
, Output
), FALSE
);
1896 Retrieves the size, in bytes, of the context buffer required for ARC4 operations.
1898 If this interface is not supported, then return zero.
1900 @return The size, in bytes, of the context buffer required for ARC4 operations.
1901 @retval 0 This interface is not supported.
1906 Arc4GetContextSize (
1910 CALL_CRYPTO_SERVICE (Arc4GetContextSize
, (), 0);
1914 Initializes user-supplied memory as ARC4 context for subsequent use.
1916 This function initializes user-supplied memory pointed by Arc4Context as ARC4 context.
1917 In addition, it sets up all ARC4 key materials for subsequent encryption and decryption
1920 If Arc4Context is NULL, then return FALSE.
1921 If Key is NULL, then return FALSE.
1922 If KeySize does not in the range of [5, 256] bytes, then return FALSE.
1923 If this interface is not supported, then return FALSE.
1925 @param[out] Arc4Context Pointer to ARC4 context being initialized.
1926 @param[in] Key Pointer to the user-supplied ARC4 key.
1927 @param[in] KeySize Size of ARC4 key in bytes.
1929 @retval TRUE ARC4 context initialization succeeded.
1930 @retval FALSE ARC4 context initialization failed.
1931 @retval FALSE This interface is not supported.
1937 OUT VOID
*Arc4Context
,
1938 IN CONST UINT8
*Key
,
1942 CALL_CRYPTO_SERVICE (Arc4Init
, (Arc4Context
, Key
, KeySize
), FALSE
);
1946 Performs ARC4 encryption on a data buffer of the specified size.
1948 This function performs ARC4 encryption on data buffer pointed by Input, of specified
1950 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
1951 invalid ARC4 context is undefined.
1953 If Arc4Context is NULL, then return FALSE.
1954 If Input is NULL, then return FALSE.
1955 If Output is NULL, then return FALSE.
1956 If this interface is not supported, then return FALSE.
1958 @param[in, out] Arc4Context Pointer to the ARC4 context.
1959 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1960 @param[in] InputSize Size of the Input buffer in bytes.
1961 @param[out] Output Pointer to a buffer that receives the ARC4 encryption output.
1963 @retval TRUE ARC4 encryption succeeded.
1964 @retval FALSE ARC4 encryption failed.
1965 @retval FALSE This interface is not supported.
1971 IN OUT VOID
*Arc4Context
,
1972 IN CONST UINT8
*Input
,
1977 CALL_CRYPTO_SERVICE (Arc4Encrypt
, (Arc4Context
, Input
, InputSize
, Output
), FALSE
);
1981 Performs ARC4 decryption on a data buffer of the specified size.
1983 This function performs ARC4 decryption on data buffer pointed by Input, of specified
1985 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
1986 invalid ARC4 context is undefined.
1988 If Arc4Context is NULL, then return FALSE.
1989 If Input is NULL, then return FALSE.
1990 If Output is NULL, then return FALSE.
1991 If this interface is not supported, then return FALSE.
1993 @param[in, out] Arc4Context Pointer to the ARC4 context.
1994 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1995 @param[in] InputSize Size of the Input buffer in bytes.
1996 @param[out] Output Pointer to a buffer that receives the ARC4 decryption output.
1998 @retval TRUE ARC4 decryption succeeded.
1999 @retval FALSE ARC4 decryption failed.
2000 @retval FALSE This interface is not supported.
2006 IN OUT VOID
*Arc4Context
,
2012 CALL_CRYPTO_SERVICE (Arc4Decrypt
, (Arc4Context
, Input
, InputSize
, Output
), FALSE
);
2016 Resets the ARC4 context to the initial state.
2018 The function resets the ARC4 context to the state it had immediately after the
2019 ARC4Init() function call.
2020 Contrary to ARC4Init(), Arc4Reset() requires no secret key as input, but ARC4 context
2021 should be already correctly initialized by ARC4Init().
2023 If Arc4Context is NULL, then return FALSE.
2024 If this interface is not supported, then return FALSE.
2026 @param[in, out] Arc4Context Pointer to the ARC4 context.
2028 @retval TRUE ARC4 reset succeeded.
2029 @retval FALSE ARC4 reset failed.
2030 @retval FALSE This interface is not supported.
2036 IN OUT VOID
*Arc4Context
2039 CALL_CRYPTO_SERVICE (Arc4Reset
, (Arc4Context
), FALSE
);
2042 //=====================================================================================
2043 // Asymmetric Cryptography Primitive
2044 //=====================================================================================
2047 Allocates and initializes one RSA context for subsequent use.
2049 @return Pointer to the RSA context that has been initialized.
2050 If the allocations fails, RsaNew() returns NULL.
2059 CALL_CRYPTO_SERVICE (RsaNew
, (), NULL
);
2063 Release the specified RSA context.
2065 If RsaContext is NULL, then return FALSE.
2067 @param[in] RsaContext Pointer to the RSA context to be released.
2076 CALL_VOID_CRYPTO_SERVICE (RsaFree
, (RsaContext
));
2080 Sets the tag-designated key component into the established RSA context.
2082 This function sets the tag-designated RSA key component into the established
2083 RSA context from the user-specified non-negative integer (octet string format
2084 represented in RSA PKCS#1).
2085 If BigNumber is NULL, then the specified key component in RSA context is cleared.
2087 If RsaContext is NULL, then return FALSE.
2089 @param[in, out] RsaContext Pointer to RSA context being set.
2090 @param[in] KeyTag Tag of RSA key component being set.
2091 @param[in] BigNumber Pointer to octet integer buffer.
2092 If NULL, then the specified key component in RSA
2094 @param[in] BnSize Size of big number buffer in bytes.
2095 If BigNumber is NULL, then it is ignored.
2097 @retval TRUE RSA key component was set successfully.
2098 @retval FALSE Invalid RSA key component tag.
2104 IN OUT VOID
*RsaContext
,
2105 IN RSA_KEY_TAG KeyTag
,
2106 IN CONST UINT8
*BigNumber
,
2110 CALL_CRYPTO_SERVICE (RsaSetKey
, (RsaContext
, KeyTag
, BigNumber
, BnSize
), FALSE
);
2114 Gets the tag-designated RSA key component from the established RSA context.
2116 This function retrieves the tag-designated RSA key component from the
2117 established RSA context as a non-negative integer (octet string format
2118 represented in RSA PKCS#1).
2119 If specified key component has not been set or has been cleared, then returned
2121 If the BigNumber buffer is too small to hold the contents of the key, FALSE
2122 is returned and BnSize is set to the required buffer size to obtain the key.
2124 If RsaContext is NULL, then return FALSE.
2125 If BnSize is NULL, then return FALSE.
2126 If BnSize is large enough but BigNumber is NULL, then return FALSE.
2127 If this interface is not supported, then return FALSE.
2129 @param[in, out] RsaContext Pointer to RSA context being set.
2130 @param[in] KeyTag Tag of RSA key component being set.
2131 @param[out] BigNumber Pointer to octet integer buffer.
2132 @param[in, out] BnSize On input, the size of big number buffer in bytes.
2133 On output, the size of data returned in big number buffer in bytes.
2135 @retval TRUE RSA key component was retrieved successfully.
2136 @retval FALSE Invalid RSA key component tag.
2137 @retval FALSE BnSize is too small.
2138 @retval FALSE This interface is not supported.
2144 IN OUT VOID
*RsaContext
,
2145 IN RSA_KEY_TAG KeyTag
,
2146 OUT UINT8
*BigNumber
,
2147 IN OUT UINTN
*BnSize
2150 CALL_CRYPTO_SERVICE (RsaGetKey
, (RsaContext
, KeyTag
, BigNumber
, BnSize
), FALSE
);
2154 Generates RSA key components.
2156 This function generates RSA key components. It takes RSA public exponent E and
2157 length in bits of RSA modulus N as input, and generates all key components.
2158 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
2160 Before this function can be invoked, pseudorandom number generator must be correctly
2161 initialized by RandomSeed().
2163 If RsaContext is NULL, then return FALSE.
2164 If this interface is not supported, then return FALSE.
2166 @param[in, out] RsaContext Pointer to RSA context being set.
2167 @param[in] ModulusLength Length of RSA modulus N in bits.
2168 @param[in] PublicExponent Pointer to RSA public exponent.
2169 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
2171 @retval TRUE RSA key component was generated successfully.
2172 @retval FALSE Invalid RSA key component tag.
2173 @retval FALSE This interface is not supported.
2179 IN OUT VOID
*RsaContext
,
2180 IN UINTN ModulusLength
,
2181 IN CONST UINT8
*PublicExponent
,
2182 IN UINTN PublicExponentSize
2185 CALL_CRYPTO_SERVICE (RsaGenerateKey
, (RsaContext
, ModulusLength
, PublicExponent
, PublicExponentSize
), FALSE
);
2189 Validates key components of RSA context.
2190 NOTE: This function performs integrity checks on all the RSA key material, so
2191 the RSA key structure must contain all the private key data.
2193 This function validates key components of RSA context in following aspects:
2194 - Whether p is a prime
2195 - Whether q is a prime
2197 - Whether d*e = 1 mod lcm(p-1,q-1)
2199 If RsaContext is NULL, then return FALSE.
2200 If this interface is not supported, then return FALSE.
2202 @param[in] RsaContext Pointer to RSA context to check.
2204 @retval TRUE RSA key components are valid.
2205 @retval FALSE RSA key components are not valid.
2206 @retval FALSE This interface is not supported.
2215 CALL_CRYPTO_SERVICE (RsaCheckKey
, (RsaContext
), FALSE
);
2219 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
2221 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
2223 If the Signature buffer is too small to hold the contents of signature, FALSE
2224 is returned and SigSize is set to the required buffer size to obtain the signature.
2226 If RsaContext is NULL, then return FALSE.
2227 If MessageHash is NULL, then return FALSE.
2228 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
2229 If SigSize is large enough but Signature is NULL, then return FALSE.
2230 If this interface is not supported, then return FALSE.
2232 @param[in] RsaContext Pointer to RSA context for signature generation.
2233 @param[in] MessageHash Pointer to octet message hash to be signed.
2234 @param[in] HashSize Size of the message hash in bytes.
2235 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
2236 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
2237 On output, the size of data returned in Signature buffer in bytes.
2239 @retval TRUE Signature successfully generated in PKCS1-v1_5.
2240 @retval FALSE Signature generation failed.
2241 @retval FALSE SigSize is too small.
2242 @retval FALSE This interface is not supported.
2248 IN VOID
*RsaContext
,
2249 IN CONST UINT8
*MessageHash
,
2251 OUT UINT8
*Signature
,
2252 IN OUT UINTN
*SigSize
2255 CALL_CRYPTO_SERVICE (RsaPkcs1Sign
, (RsaContext
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
2259 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
2262 If RsaContext is NULL, then return FALSE.
2263 If MessageHash is NULL, then return FALSE.
2264 If Signature is NULL, then return FALSE.
2265 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
2267 @param[in] RsaContext Pointer to RSA context for signature verification.
2268 @param[in] MessageHash Pointer to octet message hash to be checked.
2269 @param[in] HashSize Size of the message hash in bytes.
2270 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
2271 @param[in] SigSize Size of signature in bytes.
2273 @retval TRUE Valid signature encoded in PKCS1-v1_5.
2274 @retval FALSE Invalid signature or invalid RSA context.
2280 IN VOID
*RsaContext
,
2281 IN CONST UINT8
*MessageHash
,
2283 IN CONST UINT8
*Signature
,
2287 CALL_CRYPTO_SERVICE (RsaPkcs1Verify
, (RsaContext
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
2291 Retrieve the RSA Private Key from the password-protected PEM key data.
2293 If PemData is NULL, then return FALSE.
2294 If RsaContext is NULL, then return FALSE.
2295 If this interface is not supported, then return FALSE.
2297 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
2298 @param[in] PemSize Size of the PEM key data in bytes.
2299 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
2300 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2301 RSA private key component. Use RsaFree() function to free the
2304 @retval TRUE RSA Private Key was retrieved successfully.
2305 @retval FALSE Invalid PEM key data or incorrect password.
2306 @retval FALSE This interface is not supported.
2311 RsaGetPrivateKeyFromPem (
2312 IN CONST UINT8
*PemData
,
2314 IN CONST CHAR8
*Password
,
2315 OUT VOID
**RsaContext
2318 CALL_CRYPTO_SERVICE (RsaGetPrivateKeyFromPem
, (PemData
, PemSize
, Password
, RsaContext
), FALSE
);
2322 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
2324 If Cert is NULL, then return FALSE.
2325 If RsaContext is NULL, then return FALSE.
2326 If this interface is not supported, then return FALSE.
2328 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2329 @param[in] CertSize Size of the X509 certificate in bytes.
2330 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2331 RSA public key component. Use RsaFree() function to free the
2334 @retval TRUE RSA Public Key was retrieved successfully.
2335 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
2336 @retval FALSE This interface is not supported.
2341 RsaGetPublicKeyFromX509 (
2342 IN CONST UINT8
*Cert
,
2344 OUT VOID
**RsaContext
2347 CALL_CRYPTO_SERVICE (RsaGetPublicKeyFromX509
, (Cert
, CertSize
, RsaContext
), FALSE
);
2351 Retrieve the subject bytes from one X.509 certificate.
2353 If Cert is NULL, then return FALSE.
2354 If SubjectSize is NULL, then return FALSE.
2355 If this interface is not supported, then return FALSE.
2357 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2358 @param[in] CertSize Size of the X509 certificate in bytes.
2359 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
2360 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
2361 and the size of buffer returned CertSubject on output.
2363 @retval TRUE The certificate subject retrieved successfully.
2364 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
2365 The SubjectSize will be updated with the required size.
2366 @retval FALSE This interface is not supported.
2371 X509GetSubjectName (
2372 IN CONST UINT8
*Cert
,
2374 OUT UINT8
*CertSubject
,
2375 IN OUT UINTN
*SubjectSize
2378 CALL_CRYPTO_SERVICE (X509GetSubjectName
, (Cert
, CertSize
, CertSubject
, SubjectSize
), FALSE
);
2382 Retrieve the common name (CN) string from one X.509 certificate.
2384 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2385 @param[in] CertSize Size of the X509 certificate in bytes.
2386 @param[out] CommonName Buffer to contain the retrieved certificate common
2387 name string (UTF8). At most CommonNameSize bytes will be
2388 written and the string will be null terminated. May be
2389 NULL in order to determine the size buffer needed.
2390 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
2391 and the size of buffer returned CommonName on output.
2392 If CommonName is NULL then the amount of space needed
2393 in buffer (including the final null) is returned.
2395 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
2396 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2397 If CommonNameSize is NULL.
2398 If CommonName is not NULL and *CommonNameSize is 0.
2399 If Certificate is invalid.
2400 @retval RETURN_NOT_FOUND If no CommonName entry exists.
2401 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
2402 (including the final null) is returned in the
2403 CommonNameSize parameter.
2404 @retval RETURN_UNSUPPORTED The operation is not supported.
2410 IN CONST UINT8
*Cert
,
2412 OUT CHAR8
*CommonName
, OPTIONAL
2413 IN OUT UINTN
*CommonNameSize
2416 CALL_CRYPTO_SERVICE (X509GetCommonName
, (Cert
, CertSize
, CommonName
, CommonNameSize
), RETURN_UNSUPPORTED
);
2420 Retrieve the organization name (O) string from one X.509 certificate.
2422 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2423 @param[in] CertSize Size of the X509 certificate in bytes.
2424 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
2425 name string. At most NameBufferSize bytes will be
2426 written and the string will be null terminated. May be
2427 NULL in order to determine the size buffer needed.
2428 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
2429 and the size of buffer returned Name on output.
2430 If NameBuffer is NULL then the amount of space needed
2431 in buffer (including the final null) is returned.
2433 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
2434 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2435 If NameBufferSize is NULL.
2436 If NameBuffer is not NULL and *CommonNameSize is 0.
2437 If Certificate is invalid.
2438 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
2439 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
2440 (including the final null) is returned in the
2441 CommonNameSize parameter.
2442 @retval RETURN_UNSUPPORTED The operation is not supported.
2447 X509GetOrganizationName (
2448 IN CONST UINT8
*Cert
,
2450 OUT CHAR8
*NameBuffer
, OPTIONAL
2451 IN OUT UINTN
*NameBufferSize
2454 CALL_CRYPTO_SERVICE (X509GetOrganizationName
, (Cert
, CertSize
, NameBuffer
, NameBufferSize
), RETURN_UNSUPPORTED
);
2458 Verify one X509 certificate was issued by the trusted CA.
2460 If Cert is NULL, then return FALSE.
2461 If CACert is NULL, then return FALSE.
2462 If this interface is not supported, then return FALSE.
2464 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
2465 @param[in] CertSize Size of the X509 certificate in bytes.
2466 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
2467 @param[in] CACertSize Size of the CA Certificate in bytes.
2469 @retval TRUE The certificate was issued by the trusted CA.
2470 @retval FALSE Invalid certificate or the certificate was not issued by the given
2472 @retval FALSE This interface is not supported.
2478 IN CONST UINT8
*Cert
,
2480 IN CONST UINT8
*CACert
,
2484 CALL_CRYPTO_SERVICE (X509VerifyCert
, (Cert
, CertSize
, CACert
, CACertSize
), FALSE
);
2488 Construct a X509 object from DER-encoded certificate data.
2490 If Cert is NULL, then return FALSE.
2491 If SingleX509Cert is NULL, then return FALSE.
2492 If this interface is not supported, then return FALSE.
2494 @param[in] Cert Pointer to the DER-encoded certificate data.
2495 @param[in] CertSize The size of certificate data in bytes.
2496 @param[out] SingleX509Cert The generated X509 object.
2498 @retval TRUE The X509 object generation succeeded.
2499 @retval FALSE The operation failed.
2500 @retval FALSE This interface is not supported.
2505 X509ConstructCertificate (
2506 IN CONST UINT8
*Cert
,
2508 OUT UINT8
**SingleX509Cert
2511 CALL_CRYPTO_SERVICE (X509ConstructCertificate
, (Cert
, CertSize
, SingleX509Cert
), FALSE
);
2515 Construct a X509 stack object from a list of DER-encoded certificate data.
2517 If X509Stack is NULL, then return FALSE.
2518 If this interface is not supported, then return FALSE.
2520 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2521 On output, pointer to the X509 stack object with new
2522 inserted X509 certificate.
2523 @param[in] Args VA_LIST marker for the variable argument list.
2524 ... A list of DER-encoded single certificate data followed
2525 by certificate size. A NULL terminates the list. The
2526 pairs are the arguments to X509ConstructCertificate().
2528 @retval TRUE The X509 stack construction succeeded.
2529 @retval FALSE The construction operation failed.
2530 @retval FALSE This interface is not supported.
2535 X509ConstructCertificateStack (
2536 IN OUT UINT8
**X509Stack
,
2543 VA_START (Args
, X509Stack
);
2544 Result
= X509ConstructCertificateStackV (X509Stack
, Args
);
2550 Construct a X509 stack object from a list of DER-encoded certificate data.
2552 If X509Stack is NULL, then return FALSE.
2553 If this interface is not supported, then return FALSE.
2555 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2556 On output, pointer to the X509 stack object with new
2557 inserted X509 certificate.
2558 @param[in] Args VA_LIST marker for the variable argument list.
2559 A list of DER-encoded single certificate data followed
2560 by certificate size. A NULL terminates the list. The
2561 pairs are the arguments to X509ConstructCertificate().
2563 @retval TRUE The X509 stack construction succeeded.
2564 @retval FALSE The construction operation failed.
2565 @retval FALSE This interface is not supported.
2570 X509ConstructCertificateStackV (
2571 IN OUT UINT8
**X509Stack
,
2575 CALL_CRYPTO_SERVICE (X509ConstructCertificateStackV
, (X509Stack
, Args
), FALSE
);
2579 Release the specified X509 object.
2581 If the interface is not supported, then ASSERT().
2583 @param[in] X509Cert Pointer to the X509 object to be released.
2592 CALL_VOID_CRYPTO_SERVICE (X509Free
, (X509Cert
));
2596 Release the specified X509 stack object.
2598 If the interface is not supported, then ASSERT().
2600 @param[in] X509Stack Pointer to the X509 stack object to be released.
2609 CALL_VOID_CRYPTO_SERVICE (X509StackFree
, (X509Stack
));
2613 Retrieve the TBSCertificate from one given X.509 certificate.
2615 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
2616 @param[in] CertSize Size of the X509 certificate in bytes.
2617 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
2618 @param[out] TBSCertSize Size of the TBS certificate in bytes.
2620 If Cert is NULL, then return FALSE.
2621 If TBSCert is NULL, then return FALSE.
2622 If TBSCertSize is NULL, then return FALSE.
2623 If this interface is not supported, then return FALSE.
2625 @retval TRUE The TBSCertificate was retrieved successfully.
2626 @retval FALSE Invalid X.509 certificate.
2632 IN CONST UINT8
*Cert
,
2634 OUT UINT8
**TBSCert
,
2635 OUT UINTN
*TBSCertSize
2638 CALL_CRYPTO_SERVICE (X509GetTBSCert
, (Cert
, CertSize
, TBSCert
, TBSCertSize
), FALSE
);
2642 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2643 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2645 If Password or Salt or OutKey is NULL, then return FALSE.
2646 If the hash algorithm could not be determined, then return FALSE.
2647 If this interface is not supported, then return FALSE.
2649 @param[in] PasswordLength Length of input password in bytes.
2650 @param[in] Password Pointer to the array for the password.
2651 @param[in] SaltLength Size of the Salt in bytes.
2652 @param[in] Salt Pointer to the Salt.
2653 @param[in] IterationCount Number of iterations to perform. Its value should be
2654 greater than or equal to 1.
2655 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2656 NOTE: DigestSize will be used to determine the hash algorithm.
2657 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2658 @param[in] KeyLength Size of the derived key buffer in bytes.
2659 @param[out] OutKey Pointer to the output derived key buffer.
2661 @retval TRUE A key was derived successfully.
2662 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2663 @retval FALSE The hash algorithm could not be determined from the digest size.
2664 @retval FALSE The key derivation operation failed.
2665 @retval FALSE This interface is not supported.
2671 IN UINTN PasswordLength
,
2672 IN CONST CHAR8
*Password
,
2673 IN UINTN SaltLength
,
2674 IN CONST UINT8
*Salt
,
2675 IN UINTN IterationCount
,
2676 IN UINTN DigestSize
,
2681 CALL_CRYPTO_SERVICE (Pkcs5HashPassword
, (PasswordLength
, Password
, SaltLength
, Salt
, IterationCount
, DigestSize
, KeyLength
, OutKey
), FALSE
);
2685 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2686 encrypted message in a newly allocated buffer.
2688 Things that can cause a failure include:
2689 - X509 key size does not match any known key size.
2690 - Fail to parse X509 certificate.
2691 - Fail to allocate an intermediate buffer.
2692 - Null pointer provided for a non-optional parameter.
2693 - Data size is too large for the provided key size (max size is a function of key size
2694 and hash digest size).
2696 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2697 will be used to encrypt the data.
2698 @param[in] PublicKeySize Size of the X509 cert buffer.
2699 @param[in] InData Data to be encrypted.
2700 @param[in] InDataSize Size of the data buffer.
2701 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2702 to be used when initializing the PRNG. NULL otherwise.
2703 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2705 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2707 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2709 @retval TRUE Encryption was successful.
2710 @retval FALSE Encryption failed.
2716 IN CONST UINT8
*PublicKey
,
2717 IN UINTN PublicKeySize
,
2719 IN UINTN InDataSize
,
2720 IN CONST UINT8
*PrngSeed
, OPTIONAL
2721 IN UINTN PrngSeedSize
, OPTIONAL
2722 OUT UINT8
**EncryptedData
,
2723 OUT UINTN
*EncryptedDataSize
2726 CALL_CRYPTO_SERVICE (Pkcs1v2Encrypt
, (PublicKey
, PublicKeySize
, InData
, InDataSize
, PrngSeed
, PrngSeedSize
, EncryptedData
, EncryptedDataSize
), FALSE
);
2730 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2731 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2732 in a ContentInfo structure.
2734 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2735 return FALSE. If P7Length overflow, then return FALSE.
2736 If this interface is not supported, then return FALSE.
2738 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2739 @param[in] P7Length Length of the PKCS#7 message in bytes.
2740 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2741 It's caller's responsibility to free the buffer with
2743 This data structure is EFI_CERT_STACK type.
2744 @param[out] StackLength Length of signer's certificates in bytes.
2745 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2746 It's caller's responsibility to free the buffer with
2748 @param[out] CertLength Length of the trusted certificate in bytes.
2750 @retval TRUE The operation is finished successfully.
2751 @retval FALSE Error occurs during the operation.
2752 @retval FALSE This interface is not supported.
2758 IN CONST UINT8
*P7Data
,
2760 OUT UINT8
**CertStack
,
2761 OUT UINTN
*StackLength
,
2762 OUT UINT8
**TrustedCert
,
2763 OUT UINTN
*CertLength
2766 CALL_CRYPTO_SERVICE (Pkcs7GetSigners
, (P7Data
, P7Length
, CertStack
, StackLength
, TrustedCert
, CertLength
), FALSE
);
2770 Wrap function to use free() to free allocated memory for certificates.
2772 If this interface is not supported, then ASSERT().
2774 @param[in] Certs Pointer to the certificates to be freed.
2783 CALL_VOID_CRYPTO_SERVICE (Pkcs7FreeSigners
, (Certs
));
2787 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2788 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2789 unchained to the signer's certificates.
2790 The input signed data could be wrapped in a ContentInfo structure.
2792 @param[in] P7Data Pointer to the PKCS#7 message.
2793 @param[in] P7Length Length of the PKCS#7 message in bytes.
2794 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2795 certificate. It's caller's responsibility to free the buffer
2796 with Pkcs7FreeSigners().
2797 This data structure is EFI_CERT_STACK type.
2798 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2799 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2800 responsibility to free the buffer with Pkcs7FreeSigners().
2801 This data structure is EFI_CERT_STACK type.
2802 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2804 @retval TRUE The operation is finished successfully.
2805 @retval FALSE Error occurs during the operation.
2810 Pkcs7GetCertificatesList (
2811 IN CONST UINT8
*P7Data
,
2813 OUT UINT8
**SignerChainCerts
,
2814 OUT UINTN
*ChainLength
,
2815 OUT UINT8
**UnchainCerts
,
2816 OUT UINTN
*UnchainLength
2819 CALL_CRYPTO_SERVICE (Pkcs7GetCertificatesList
, (P7Data
, P7Length
, SignerChainCerts
, ChainLength
, UnchainCerts
, UnchainLength
), FALSE
);
2823 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2824 Syntax Standard, version 1.5". This interface is only intended to be used for
2825 application to perform PKCS#7 functionality validation.
2827 If this interface is not supported, then return FALSE.
2829 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2831 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2832 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2834 @param[in] InData Pointer to the content to be signed.
2835 @param[in] InDataSize Size of InData in bytes.
2836 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2837 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2838 include in the PKCS#7 signedData (e.g. any intermediate
2840 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2841 responsibility to free the buffer with FreePool().
2842 @param[out] SignedDataSize Size of SignedData in bytes.
2844 @retval TRUE PKCS#7 data signing succeeded.
2845 @retval FALSE PKCS#7 data signing failed.
2846 @retval FALSE This interface is not supported.
2852 IN CONST UINT8
*PrivateKey
,
2853 IN UINTN PrivateKeySize
,
2854 IN CONST UINT8
*KeyPassword
,
2856 IN UINTN InDataSize
,
2858 IN UINT8
*OtherCerts OPTIONAL
,
2859 OUT UINT8
**SignedData
,
2860 OUT UINTN
*SignedDataSize
2863 CALL_CRYPTO_SERVICE (Pkcs7Sign
, (PrivateKey
, PrivateKeySize
, KeyPassword
, InData
, InDataSize
, SignCert
, OtherCerts
, SignedData
, SignedDataSize
), FALSE
);
2867 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2868 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2869 in a ContentInfo structure.
2871 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2872 If P7Length, CertLength or DataLength overflow, then return FALSE.
2873 If this interface is not supported, then return FALSE.
2875 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2876 @param[in] P7Length Length of the PKCS#7 message in bytes.
2877 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2878 is used for certificate chain verification.
2879 @param[in] CertLength Length of the trusted certificate in bytes.
2880 @param[in] InData Pointer to the content to be verified.
2881 @param[in] DataLength Length of InData in bytes.
2883 @retval TRUE The specified PKCS#7 signed data is valid.
2884 @retval FALSE Invalid PKCS#7 signed data.
2885 @retval FALSE This interface is not supported.
2891 IN CONST UINT8
*P7Data
,
2893 IN CONST UINT8
*TrustedCert
,
2894 IN UINTN CertLength
,
2895 IN CONST UINT8
*InData
,
2899 CALL_CRYPTO_SERVICE (Pkcs7Verify
, (P7Data
, P7Length
, TrustedCert
, CertLength
, InData
, DataLength
), FALSE
);
2903 This function receives a PKCS7 formatted signature, and then verifies that
2904 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
2905 leaf signing certificate.
2906 Note that this function does not validate the certificate chain.
2908 Applications for custom EKU's are quite flexible. For example, a policy EKU
2909 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
2910 certificate issued might also contain this EKU, thus constraining the
2911 sub-ordinate certificate. Other applications might allow a certificate
2912 embedded in a device to specify that other Object Identifiers (OIDs) are
2913 present which contains binary data specifying custom capabilities that
2914 the device is able to do.
2916 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
2917 containing the content block with both the signature,
2918 the signer's certificate, and any necessary intermediate
2920 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
2921 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
2922 required EKUs that must be present in the signature.
2923 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
2924 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
2925 must be present in the leaf signer. If it is
2926 FALSE, then we will succeed if we find any
2927 of the specified EKU's.
2929 @retval EFI_SUCCESS The required EKUs were found in the signature.
2930 @retval EFI_INVALID_PARAMETER A parameter was invalid.
2931 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
2936 VerifyEKUsInPkcs7Signature (
2937 IN CONST UINT8
*Pkcs7Signature
,
2938 IN CONST UINT32 SignatureSize
,
2939 IN CONST CHAR8
*RequiredEKUs
[],
2940 IN CONST UINT32 RequiredEKUsSize
,
2941 IN BOOLEAN RequireAllPresent
2944 CALL_CRYPTO_SERVICE (VerifyEKUsInPkcs7Signature
, (Pkcs7Signature
, SignatureSize
, RequiredEKUs
, RequiredEKUsSize
, RequireAllPresent
), FALSE
);
2949 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2950 data could be wrapped in a ContentInfo structure.
2952 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2953 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2955 Caution: This function may receive untrusted input. So this function will do
2956 basic check for PKCS#7 data structure.
2958 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2959 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2960 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2961 It's caller's responsibility to free the buffer with FreePool().
2962 @param[out] ContentSize The size of the extracted content in bytes.
2964 @retval TRUE The P7Data was correctly formatted for processing.
2965 @retval FALSE The P7Data was not correctly formatted for processing.
2970 Pkcs7GetAttachedContent (
2971 IN CONST UINT8
*P7Data
,
2974 OUT UINTN
*ContentSize
2977 CALL_CRYPTO_SERVICE (Pkcs7GetAttachedContent
, (P7Data
, P7Length
, Content
, ContentSize
), FALSE
);
2981 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2982 Authenticode Portable Executable Signature Format".
2984 If AuthData is NULL, then return FALSE.
2985 If ImageHash is NULL, then return FALSE.
2986 If this interface is not supported, then return FALSE.
2988 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2989 PE/COFF image to be verified.
2990 @param[in] DataSize Size of the Authenticode Signature in bytes.
2991 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2992 is used for certificate chain verification.
2993 @param[in] CertSize Size of the trusted certificate in bytes.
2994 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2995 for calculating the image hash value is described in Authenticode
2997 @param[in] HashSize Size of Image hash value in bytes.
2999 @retval TRUE The specified Authenticode Signature is valid.
3000 @retval FALSE Invalid Authenticode Signature.
3001 @retval FALSE This interface is not supported.
3006 AuthenticodeVerify (
3007 IN CONST UINT8
*AuthData
,
3009 IN CONST UINT8
*TrustedCert
,
3011 IN CONST UINT8
*ImageHash
,
3015 CALL_CRYPTO_SERVICE (AuthenticodeVerify
, (AuthData
, DataSize
, TrustedCert
, CertSize
, ImageHash
, HashSize
), FALSE
);
3019 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
3022 If AuthData is NULL, then return FALSE.
3023 If this interface is not supported, then return FALSE.
3025 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
3026 PE/COFF image to be verified.
3027 @param[in] DataSize Size of the Authenticode Signature in bytes.
3028 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
3029 is used for TSA certificate chain verification.
3030 @param[in] CertSize Size of the trusted certificate in bytes.
3031 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
3034 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
3035 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
3040 ImageTimestampVerify (
3041 IN CONST UINT8
*AuthData
,
3043 IN CONST UINT8
*TsaCert
,
3045 OUT EFI_TIME
*SigningTime
3048 CALL_CRYPTO_SERVICE (ImageTimestampVerify
, (AuthData
, DataSize
, TsaCert
, CertSize
, SigningTime
), FALSE
);
3051 //=====================================================================================
3052 // DH Key Exchange Primitive
3053 //=====================================================================================
3056 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
3058 @return Pointer to the Diffie-Hellman Context that has been initialized.
3059 If the allocations fails, DhNew() returns NULL.
3060 If the interface is not supported, DhNew() returns NULL.
3069 CALL_CRYPTO_SERVICE (DhNew
, (), NULL
);
3073 Release the specified DH context.
3075 If the interface is not supported, then ASSERT().
3077 @param[in] DhContext Pointer to the DH context to be released.
3086 CALL_VOID_CRYPTO_SERVICE (DhFree
, (DhContext
));
3090 Generates DH parameter.
3092 Given generator g, and length of prime number p in bits, this function generates p,
3093 and sets DH context according to value of g and p.
3095 Before this function can be invoked, pseudorandom number generator must be correctly
3096 initialized by RandomSeed().
3098 If DhContext is NULL, then return FALSE.
3099 If Prime is NULL, then return FALSE.
3100 If this interface is not supported, then return FALSE.
3102 @param[in, out] DhContext Pointer to the DH context.
3103 @param[in] Generator Value of generator.
3104 @param[in] PrimeLength Length in bits of prime to be generated.
3105 @param[out] Prime Pointer to the buffer to receive the generated prime number.
3107 @retval TRUE DH parameter generation succeeded.
3108 @retval FALSE Value of Generator is not supported.
3109 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
3110 @retval FALSE This interface is not supported.
3115 DhGenerateParameter (
3116 IN OUT VOID
*DhContext
,
3118 IN UINTN PrimeLength
,
3122 CALL_CRYPTO_SERVICE (DhGenerateParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
3126 Sets generator and prime parameters for DH.
3128 Given generator g, and prime number p, this function and sets DH
3129 context accordingly.
3131 If DhContext is NULL, then return FALSE.
3132 If Prime is NULL, then return FALSE.
3133 If this interface is not supported, then return FALSE.
3135 @param[in, out] DhContext Pointer to the DH context.
3136 @param[in] Generator Value of generator.
3137 @param[in] PrimeLength Length in bits of prime to be generated.
3138 @param[in] Prime Pointer to the prime number.
3140 @retval TRUE DH parameter setting succeeded.
3141 @retval FALSE Value of Generator is not supported.
3142 @retval FALSE Value of Generator is not suitable for the Prime.
3143 @retval FALSE Value of Prime is not a prime number.
3144 @retval FALSE Value of Prime is not a safe prime number.
3145 @retval FALSE This interface is not supported.
3151 IN OUT VOID
*DhContext
,
3153 IN UINTN PrimeLength
,
3154 IN CONST UINT8
*Prime
3157 CALL_CRYPTO_SERVICE (DhSetParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
3161 Generates DH public key.
3163 This function generates random secret exponent, and computes the public key, which is
3164 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
3165 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
3166 PublicKeySize is set to the required buffer size to obtain the public key.
3168 If DhContext is NULL, then return FALSE.
3169 If PublicKeySize is NULL, then return FALSE.
3170 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
3171 If this interface is not supported, then return FALSE.
3173 @param[in, out] DhContext Pointer to the DH context.
3174 @param[out] PublicKey Pointer to the buffer to receive generated public key.
3175 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
3176 On output, the size of data returned in PublicKey buffer in bytes.
3178 @retval TRUE DH public key generation succeeded.
3179 @retval FALSE DH public key generation failed.
3180 @retval FALSE PublicKeySize is not large enough.
3181 @retval FALSE This interface is not supported.
3187 IN OUT VOID
*DhContext
,
3188 OUT UINT8
*PublicKey
,
3189 IN OUT UINTN
*PublicKeySize
3192 CALL_CRYPTO_SERVICE (DhGenerateKey
, (DhContext
, PublicKey
, PublicKeySize
), FALSE
);
3196 Computes exchanged common key.
3198 Given peer's public key, this function computes the exchanged common key, based on its own
3199 context including value of prime modulus and random secret exponent.
3201 If DhContext is NULL, then return FALSE.
3202 If PeerPublicKey is NULL, then return FALSE.
3203 If KeySize is NULL, then return FALSE.
3204 If Key is NULL, then return FALSE.
3205 If KeySize is not large enough, then return FALSE.
3206 If this interface is not supported, then return FALSE.
3208 @param[in, out] DhContext Pointer to the DH context.
3209 @param[in] PeerPublicKey Pointer to the peer's public key.
3210 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
3211 @param[out] Key Pointer to the buffer to receive generated key.
3212 @param[in, out] KeySize On input, the size of Key buffer in bytes.
3213 On output, the size of data returned in Key buffer in bytes.
3215 @retval TRUE DH exchanged key generation succeeded.
3216 @retval FALSE DH exchanged key generation failed.
3217 @retval FALSE KeySize is not large enough.
3218 @retval FALSE This interface is not supported.
3224 IN OUT VOID
*DhContext
,
3225 IN CONST UINT8
*PeerPublicKey
,
3226 IN UINTN PeerPublicKeySize
,
3228 IN OUT UINTN
*KeySize
3231 CALL_CRYPTO_SERVICE (DhComputeKey
, (DhContext
, PeerPublicKey
, PeerPublicKeySize
, Key
, KeySize
), FALSE
);
3234 //=====================================================================================
3235 // Pseudo-Random Generation Primitive
3236 //=====================================================================================
3239 Sets up the seed value for the pseudorandom number generator.
3241 This function sets up the seed value for the pseudorandom number generator.
3242 If Seed is not NULL, then the seed passed in is used.
3243 If Seed is NULL, then default seed is used.
3244 If this interface is not supported, then return FALSE.
3246 @param[in] Seed Pointer to seed value.
3247 If NULL, default seed is used.
3248 @param[in] SeedSize Size of seed value.
3249 If Seed is NULL, this parameter is ignored.
3251 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
3252 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
3253 @retval FALSE This interface is not supported.
3259 IN CONST UINT8
*Seed OPTIONAL
,
3263 CALL_CRYPTO_SERVICE (RandomSeed
, (Seed
, SeedSize
), FALSE
);
3267 Generates a pseudorandom byte stream of the specified size.
3269 If Output is NULL, then return FALSE.
3270 If this interface is not supported, then return FALSE.
3272 @param[out] Output Pointer to buffer to receive random value.
3273 @param[in] Size Size of random bytes to generate.
3275 @retval TRUE Pseudorandom byte stream generated successfully.
3276 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
3277 @retval FALSE This interface is not supported.
3287 CALL_CRYPTO_SERVICE (RandomBytes
, (Output
, Size
), FALSE
);
3290 //=====================================================================================
3291 // Key Derivation Function Primitive
3292 //=====================================================================================
3295 Derive key data using HMAC-SHA256 based KDF.
3297 @param[in] Key Pointer to the user-supplied key.
3298 @param[in] KeySize Key size in bytes.
3299 @param[in] Salt Pointer to the salt(non-secret) value.
3300 @param[in] SaltSize Salt size in bytes.
3301 @param[in] Info Pointer to the application specific info.
3302 @param[in] InfoSize Info size in bytes.
3303 @param[out] Out Pointer to buffer to receive hkdf value.
3304 @param[in] OutSize Size of hkdf bytes to generate.
3306 @retval TRUE Hkdf generated successfully.
3307 @retval FALSE Hkdf generation failed.
3312 HkdfSha256ExtractAndExpand (
3313 IN CONST UINT8
*Key
,
3315 IN CONST UINT8
*Salt
,
3317 IN CONST UINT8
*Info
,
3323 CALL_CRYPTO_SERVICE (HkdfSha256ExtractAndExpand
, (Key
, KeySize
, Salt
, SaltSize
, Info
, InfoSize
, Out
, OutSize
), FALSE
);
3327 Initializes the OpenSSL library.
3329 This function registers ciphers and digests used directly and indirectly
3330 by SSL/TLS, and initializes the readable error messages.
3331 This function must be called before any other action takes places.
3333 @retval TRUE The OpenSSL library has been initialized.
3334 @retval FALSE Failed to initialize the OpenSSL library.
3343 CALL_CRYPTO_SERVICE (TlsInitialize
, (), FALSE
);
3347 Free an allocated SSL_CTX object.
3349 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
3358 CALL_VOID_CRYPTO_SERVICE (TlsCtxFree
, (TlsCtx
));
3362 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
3365 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3366 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3368 @return Pointer to an allocated SSL_CTX object.
3369 If the creation failed, TlsCtxNew() returns NULL.
3379 CALL_CRYPTO_SERVICE (TlsCtxNew
, (MajorVer
, MinorVer
), NULL
);
3383 Free an allocated TLS object.
3385 This function removes the TLS object pointed to by Tls and frees up the
3386 allocated memory. If Tls is NULL, nothing is done.
3388 @param[in] Tls Pointer to the TLS object to be freed.
3397 CALL_VOID_CRYPTO_SERVICE (TlsFree
, (Tls
));
3401 Create a new TLS object for a connection.
3403 This function creates a new TLS object for a connection. The new object
3404 inherits the setting of the underlying context TlsCtx: connection method,
3405 options, verification setting.
3407 @param[in] TlsCtx Pointer to the SSL_CTX object.
3409 @return Pointer to an allocated SSL object.
3410 If the creation failed, TlsNew() returns NULL.
3419 CALL_CRYPTO_SERVICE (TlsNew
, (TlsCtx
), NULL
);
3423 Checks if the TLS handshake was done.
3425 This function will check if the specified TLS handshake was done.
3427 @param[in] Tls Pointer to the TLS object for handshake state checking.
3429 @retval TRUE The TLS handshake was done.
3430 @retval FALSE The TLS handshake was not done.
3439 CALL_CRYPTO_SERVICE (TlsInHandshake
, (Tls
), FALSE
);
3443 Perform a TLS/SSL handshake.
3445 This function will perform a TLS/SSL handshake.
3447 @param[in] Tls Pointer to the TLS object for handshake operation.
3448 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
3449 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3451 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3452 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3453 the buffer size provided by the caller. On output, it
3454 is the buffer size in fact needed to contain the
3457 @retval EFI_SUCCESS The required TLS packet is built successfully.
3458 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3460 BufferIn is NULL but BufferInSize is NOT 0.
3461 BufferInSize is 0 but BufferIn is NOT NULL.
3462 BufferOutSize is NULL.
3463 BufferOut is NULL if *BufferOutSize is not zero.
3464 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3465 @retval EFI_ABORTED Something wrong during handshake.
3472 IN UINT8
*BufferIn
, OPTIONAL
3473 IN UINTN BufferInSize
, OPTIONAL
3474 OUT UINT8
*BufferOut
, OPTIONAL
3475 IN OUT UINTN
*BufferOutSize
3478 CALL_CRYPTO_SERVICE (TlsDoHandshake
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
3482 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
3483 TLS session has errors and the response packet needs to be Alert message based on error type.
3485 @param[in] Tls Pointer to the TLS object for state checking.
3486 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
3487 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3489 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3490 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3491 the buffer size provided by the caller. On output, it
3492 is the buffer size in fact needed to contain the
3495 @retval EFI_SUCCESS The required TLS packet is built successfully.
3496 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3498 BufferIn is NULL but BufferInSize is NOT 0.
3499 BufferInSize is 0 but BufferIn is NOT NULL.
3500 BufferOutSize is NULL.
3501 BufferOut is NULL if *BufferOutSize is not zero.
3502 @retval EFI_ABORTED An error occurred.
3503 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3510 IN UINT8
*BufferIn
, OPTIONAL
3511 IN UINTN BufferInSize
, OPTIONAL
3512 OUT UINT8
*BufferOut
, OPTIONAL
3513 IN OUT UINTN
*BufferOutSize
3516 CALL_CRYPTO_SERVICE (TlsHandleAlert
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
3520 Build the CloseNotify packet.
3522 @param[in] Tls Pointer to the TLS object for state checking.
3523 @param[in, out] Buffer Pointer to the buffer to hold the built packet.
3524 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
3525 the buffer size provided by the caller. On output, it
3526 is the buffer size in fact needed to contain the
3529 @retval EFI_SUCCESS The required TLS packet is built successfully.
3530 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3533 Buffer is NULL if *BufferSize is not zero.
3534 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
3541 IN OUT UINT8
*Buffer
,
3542 IN OUT UINTN
*BufferSize
3545 CALL_CRYPTO_SERVICE (TlsCloseNotify
, (Tls
, Buffer
, BufferSize
), EFI_UNSUPPORTED
);
3549 Attempts to read bytes from one TLS object and places the data in Buffer.
3551 This function will attempt to read BufferSize bytes from the TLS object
3552 and places the data in Buffer.
3554 @param[in] Tls Pointer to the TLS object.
3555 @param[in,out] Buffer Pointer to the buffer to store the data.
3556 @param[in] BufferSize The size of Buffer in bytes.
3558 @retval >0 The amount of data successfully read from the TLS object.
3559 @retval <=0 No data was successfully read.
3566 IN OUT VOID
*Buffer
,
3570 CALL_CRYPTO_SERVICE (TlsCtrlTrafficOut
, (Tls
, Buffer
, BufferSize
), 0);
3574 Attempts to write data from the buffer to TLS object.
3576 This function will attempt to write BufferSize bytes data from the Buffer
3579 @param[in] Tls Pointer to the TLS object.
3580 @param[in] Buffer Pointer to the data buffer.
3581 @param[in] BufferSize The size of Buffer in bytes.
3583 @retval >0 The amount of data successfully written to the TLS object.
3584 @retval <=0 No data was successfully written.
3595 CALL_CRYPTO_SERVICE (TlsCtrlTrafficIn
, (Tls
, Buffer
, BufferSize
), 0);
3599 Attempts to read bytes from the specified TLS connection into the buffer.
3601 This function tries to read BufferSize bytes data from the specified TLS
3602 connection into the Buffer.
3604 @param[in] Tls Pointer to the TLS connection for data reading.
3605 @param[in,out] Buffer Pointer to the data buffer.
3606 @param[in] BufferSize The size of Buffer in bytes.
3608 @retval >0 The read operation was successful, and return value is the
3609 number of bytes actually read from the TLS connection.
3610 @retval <=0 The read operation was not successful.
3617 IN OUT VOID
*Buffer
,
3621 CALL_CRYPTO_SERVICE (TlsRead
, (Tls
, Buffer
, BufferSize
), 0);
3625 Attempts to write data to a TLS connection.
3627 This function tries to write BufferSize bytes data from the Buffer into the
3628 specified TLS connection.
3630 @param[in] Tls Pointer to the TLS connection for data writing.
3631 @param[in] Buffer Pointer to the data buffer.
3632 @param[in] BufferSize The size of Buffer in bytes.
3634 @retval >0 The write operation was successful, and return value is the
3635 number of bytes actually written to the TLS connection.
3636 @retval <=0 The write operation was not successful.
3647 CALL_CRYPTO_SERVICE (TlsWrite
, (Tls
, Buffer
, BufferSize
), 0);
3651 Set a new TLS/SSL method for a particular TLS object.
3653 This function sets a new TLS/SSL method for a particular TLS object.
3655 @param[in] Tls Pointer to a TLS object.
3656 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3657 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3659 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
3660 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3661 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
3672 CALL_CRYPTO_SERVICE (TlsSetVersion
, (Tls
, MajorVer
, MinorVer
), EFI_UNSUPPORTED
);
3676 Set TLS object to work in client or server mode.
3678 This function prepares a TLS object to work in client or server mode.
3680 @param[in] Tls Pointer to a TLS object.
3681 @param[in] IsServer Work in server mode.
3683 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
3684 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3685 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
3690 TlsSetConnectionEnd (
3695 CALL_CRYPTO_SERVICE (TlsSetConnectionEnd
, (Tls
, IsServer
), EFI_UNSUPPORTED
);
3699 Set the ciphers list to be used by the TLS object.
3701 This function sets the ciphers for use by a specified TLS object.
3703 @param[in] Tls Pointer to a TLS object.
3704 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
3705 cipher identifier comes from the TLS Cipher Suite
3706 Registry of the IANA, interpreting Byte1 and Byte2
3707 in network (big endian) byte order.
3708 @param[in] CipherNum The number of cipher in the list.
3710 @retval EFI_SUCCESS The ciphers list was set successfully.
3711 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3712 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
3713 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
3720 IN UINT16
*CipherId
,
3724 CALL_CRYPTO_SERVICE (TlsSetCipherList
, (Tls
, CipherId
, CipherNum
), EFI_UNSUPPORTED
);
3728 Set the compression method for TLS/SSL operations.
3730 This function handles TLS/SSL integrated compression methods.
3732 @param[in] CompMethod The compression method ID.
3734 @retval EFI_SUCCESS The compression method for the communication was
3736 @retval EFI_UNSUPPORTED Unsupported compression method.
3741 TlsSetCompressionMethod (
3745 CALL_CRYPTO_SERVICE (TlsSetCompressionMethod
, (CompMethod
), EFI_UNSUPPORTED
);
3749 Set peer certificate verification mode for the TLS connection.
3751 This function sets the verification mode flags for the TLS connection.
3753 @param[in] Tls Pointer to the TLS object.
3754 @param[in] VerifyMode A set of logically or'ed verification mode flags.
3761 IN UINT32 VerifyMode
3764 CALL_VOID_CRYPTO_SERVICE (TlsSetVerify
, (Tls
, VerifyMode
));
3768 Set the specified host name to be verified.
3770 @param[in] Tls Pointer to the TLS object.
3771 @param[in] Flags The setting flags during the validation.
3772 @param[in] HostName The specified host name to be verified.
3774 @retval EFI_SUCCESS The HostName setting was set successfully.
3775 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3776 @retval EFI_ABORTED Invalid HostName setting.
3787 CALL_CRYPTO_SERVICE (TlsSetVerifyHost
, (Tls
, Flags
, HostName
), EFI_UNSUPPORTED
);
3791 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
3793 This function sets a session ID to be used when the TLS/SSL connection is
3796 @param[in] Tls Pointer to the TLS object.
3797 @param[in] SessionId Session ID data used for session resumption.
3798 @param[in] SessionIdLen Length of Session ID in bytes.
3800 @retval EFI_SUCCESS Session ID was set successfully.
3801 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3802 @retval EFI_UNSUPPORTED No available session for ID setting.
3809 IN UINT8
*SessionId
,
3810 IN UINT16 SessionIdLen
3813 CALL_CRYPTO_SERVICE (TlsSetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
3817 Adds the CA to the cert store when requesting Server or Client authentication.
3819 This function adds the CA certificate to the list of CAs when requesting
3820 Server or Client authentication for the chosen TLS connection.
3822 @param[in] Tls Pointer to the TLS object.
3823 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3824 X.509 certificate or PEM-encoded X.509 certificate.
3825 @param[in] DataSize The size of data buffer in bytes.
3827 @retval EFI_SUCCESS The operation succeeded.
3828 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3829 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3830 @retval EFI_ABORTED Invalid X.509 certificate.
3835 TlsSetCaCertificate (
3841 CALL_CRYPTO_SERVICE (TlsSetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3845 Loads the local public certificate into the specified TLS object.
3847 This function loads the X.509 certificate into the specified TLS object
3848 for TLS negotiation.
3850 @param[in] Tls Pointer to the TLS object.
3851 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3852 X.509 certificate or PEM-encoded X.509 certificate.
3853 @param[in] DataSize The size of data buffer in bytes.
3855 @retval EFI_SUCCESS The operation succeeded.
3856 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3857 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3858 @retval EFI_ABORTED Invalid X.509 certificate.
3863 TlsSetHostPublicCert (
3869 CALL_CRYPTO_SERVICE (TlsSetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3873 Adds the local private key to the specified TLS object.
3875 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
3876 key) into the specified TLS object for TLS negotiation.
3878 @param[in] Tls Pointer to the TLS object.
3879 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
3880 or PKCS#8 private key.
3881 @param[in] DataSize The size of data buffer in bytes.
3883 @retval EFI_SUCCESS The operation succeeded.
3884 @retval EFI_UNSUPPORTED This function is not supported.
3885 @retval EFI_ABORTED Invalid private key data.
3890 TlsSetHostPrivateKey (
3896 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3900 Adds the CA-supplied certificate revocation list for certificate validation.
3902 This function adds the CA-supplied certificate revocation list data for
3903 certificate validity checking.
3905 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
3906 @param[in] DataSize The size of data buffer in bytes.
3908 @retval EFI_SUCCESS The operation succeeded.
3909 @retval EFI_UNSUPPORTED This function is not supported.
3910 @retval EFI_ABORTED Invalid CRL data.
3915 TlsSetCertRevocationList (
3920 CALL_CRYPTO_SERVICE (TlsSetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);
3924 Gets the protocol version used by the specified TLS connection.
3926 This function returns the protocol version used by the specified TLS
3929 If Tls is NULL, then ASSERT().
3931 @param[in] Tls Pointer to the TLS object.
3933 @return The protocol version of the specified TLS connection.
3942 CALL_CRYPTO_SERVICE (TlsGetVersion
, (Tls
), 0);
3946 Gets the connection end of the specified TLS connection.
3948 This function returns the connection end (as client or as server) used by
3949 the specified TLS connection.
3951 If Tls is NULL, then ASSERT().
3953 @param[in] Tls Pointer to the TLS object.
3955 @return The connection end used by the specified TLS connection.
3960 TlsGetConnectionEnd (
3964 CALL_CRYPTO_SERVICE (TlsGetConnectionEnd
, (Tls
), 0);
3968 Gets the cipher suite used by the specified TLS connection.
3970 This function returns current cipher suite used by the specified
3973 @param[in] Tls Pointer to the TLS object.
3974 @param[in,out] CipherId The cipher suite used by the TLS object.
3976 @retval EFI_SUCCESS The cipher suite was returned successfully.
3977 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3978 @retval EFI_UNSUPPORTED Unsupported cipher suite.
3983 TlsGetCurrentCipher (
3985 IN OUT UINT16
*CipherId
3988 CALL_CRYPTO_SERVICE (TlsGetCurrentCipher
, (Tls
, CipherId
), EFI_UNSUPPORTED
);
3992 Gets the compression methods used by the specified TLS connection.
3994 This function returns current integrated compression methods used by
3995 the specified TLS connection.
3997 @param[in] Tls Pointer to the TLS object.
3998 @param[in,out] CompressionId The current compression method used by
4001 @retval EFI_SUCCESS The compression method was returned successfully.
4002 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4003 @retval EFI_ABORTED Invalid Compression method.
4004 @retval EFI_UNSUPPORTED This function is not supported.
4009 TlsGetCurrentCompressionId (
4011 IN OUT UINT8
*CompressionId
4014 CALL_CRYPTO_SERVICE (TlsGetCurrentCompressionId
, (Tls
, CompressionId
), EFI_UNSUPPORTED
);
4018 Gets the verification mode currently set in the TLS connection.
4020 This function returns the peer verification mode currently set in the
4021 specified TLS connection.
4023 If Tls is NULL, then ASSERT().
4025 @param[in] Tls Pointer to the TLS object.
4027 @return The verification mode set in the specified TLS connection.
4036 CALL_CRYPTO_SERVICE (TlsGetVerify
, (Tls
), 0);
4040 Gets the session ID used by the specified TLS connection.
4042 This function returns the TLS/SSL session ID currently used by the
4043 specified TLS connection.
4045 @param[in] Tls Pointer to the TLS object.
4046 @param[in,out] SessionId Buffer to contain the returned session ID.
4047 @param[in,out] SessionIdLen The length of Session ID in bytes.
4049 @retval EFI_SUCCESS The Session ID was returned successfully.
4050 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4051 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
4058 IN OUT UINT8
*SessionId
,
4059 IN OUT UINT16
*SessionIdLen
4062 CALL_CRYPTO_SERVICE (TlsGetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
4066 Gets the client random data used in the specified TLS connection.
4068 This function returns the TLS/SSL client random data currently used in
4069 the specified TLS connection.
4071 @param[in] Tls Pointer to the TLS object.
4072 @param[in,out] ClientRandom Buffer to contain the returned client
4073 random data (32 bytes).
4078 TlsGetClientRandom (
4080 IN OUT UINT8
*ClientRandom
4083 CALL_VOID_CRYPTO_SERVICE (TlsGetClientRandom
, (Tls
, ClientRandom
));
4087 Gets the server random data used in the specified TLS connection.
4089 This function returns the TLS/SSL server random data currently used in
4090 the specified TLS connection.
4092 @param[in] Tls Pointer to the TLS object.
4093 @param[in,out] ServerRandom Buffer to contain the returned server
4094 random data (32 bytes).
4099 TlsGetServerRandom (
4101 IN OUT UINT8
*ServerRandom
4104 CALL_VOID_CRYPTO_SERVICE (TlsGetServerRandom
, (Tls
, ServerRandom
));
4108 Gets the master key data used in the specified TLS connection.
4110 This function returns the TLS/SSL master key material currently used in
4111 the specified TLS connection.
4113 @param[in] Tls Pointer to the TLS object.
4114 @param[in,out] KeyMaterial Buffer to contain the returned key material.
4116 @retval EFI_SUCCESS Key material was returned successfully.
4117 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4118 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
4125 IN OUT UINT8
*KeyMaterial
4128 CALL_CRYPTO_SERVICE (TlsGetKeyMaterial
, (Tls
, KeyMaterial
), EFI_UNSUPPORTED
);
4132 Gets the CA Certificate from the cert store.
4134 This function returns the CA certificate for the chosen
4137 @param[in] Tls Pointer to the TLS object.
4138 @param[out] Data Pointer to the data buffer to receive the CA
4139 certificate data sent to the client.
4140 @param[in,out] DataSize The size of data buffer in bytes.
4142 @retval EFI_SUCCESS The operation succeeded.
4143 @retval EFI_UNSUPPORTED This function is not supported.
4144 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4149 TlsGetCaCertificate (
4152 IN OUT UINTN
*DataSize
4155 CALL_CRYPTO_SERVICE (TlsGetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4159 Gets the local public Certificate set in the specified TLS object.
4161 This function returns the local public certificate which was currently set
4162 in the specified TLS object.
4164 @param[in] Tls Pointer to the TLS object.
4165 @param[out] Data Pointer to the data buffer to receive the local
4167 @param[in,out] DataSize The size of data buffer in bytes.
4169 @retval EFI_SUCCESS The operation succeeded.
4170 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4171 @retval EFI_NOT_FOUND The certificate is not found.
4172 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4177 TlsGetHostPublicCert (
4180 IN OUT UINTN
*DataSize
4183 CALL_CRYPTO_SERVICE (TlsGetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4187 Gets the local private key set in the specified TLS object.
4189 This function returns the local private key data which was currently set
4190 in the specified TLS object.
4192 @param[in] Tls Pointer to the TLS object.
4193 @param[out] Data Pointer to the data buffer to receive the local
4195 @param[in,out] DataSize The size of data buffer in bytes.
4197 @retval EFI_SUCCESS The operation succeeded.
4198 @retval EFI_UNSUPPORTED This function is not supported.
4199 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4204 TlsGetHostPrivateKey (
4207 IN OUT UINTN
*DataSize
4210 CALL_CRYPTO_SERVICE (TlsGetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4214 Gets the CA-supplied certificate revocation list data set in the specified
4217 This function returns the CA-supplied certificate revocation list data which
4218 was currently set in the specified TLS object.
4220 @param[out] Data Pointer to the data buffer to receive the CRL data.
4221 @param[in,out] DataSize The size of data buffer in bytes.
4223 @retval EFI_SUCCESS The operation succeeded.
4224 @retval EFI_UNSUPPORTED This function is not supported.
4225 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4230 TlsGetCertRevocationList (
4232 IN OUT UINTN
*DataSize
4235 CALL_CRYPTO_SERVICE (TlsGetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);