2 Implements the BaseCryptLib and TlsLib using the services of the EDK II Crypto
5 Copyright (C) Microsoft Corporation. All rights reserved.
6 Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Library/BaseLib.h>
13 #include <Library/DebugLib.h>
14 #include <Library/BaseCryptLib.h>
15 #include <Library/TlsLib.h>
16 #include <Protocol/Crypto.h>
19 A macro used to call a non-void service in an EDK II Crypto Protocol.
20 If the protocol is NULL or the service in the protocol is NULL, then a debug
21 message and assert is generated and an appropriate return value is returned.
23 @param Function Name of the EDK II Crypto Protocol service to call.
24 @param Args The argument list to pass to Function.
25 @param ErrorReturnValue The value to return if the protocol is NULL or the
26 service in the protocol is NULL.
29 #define CALL_CRYPTO_SERVICE(Function, Args, ErrorReturnValue) \
31 EDKII_CRYPTO_PROTOCOL *CryptoServices; \
33 CryptoServices = (EDKII_CRYPTO_PROTOCOL *)GetCryptoServices (); \
34 if (CryptoServices != NULL && CryptoServices->Function != NULL) { \
35 return (CryptoServices->Function) Args; \
37 CryptoServiceNotAvailable (#Function); \
38 return ErrorReturnValue; \
42 A macro used to call a void service in an EDK II Crypto Protocol.
43 If the protocol is NULL or the service in the protocol is NULL, then a debug
44 message and assert is generated.
46 @param Function Name of the EDK II Crypto Protocol service to call.
47 @param Args The argument list to pass to Function.
50 #define CALL_VOID_CRYPTO_SERVICE(Function, Args) \
52 EDKII_CRYPTO_PROTOCOL *CryptoServices; \
54 CryptoServices = (EDKII_CRYPTO_PROTOCOL *)GetCryptoServices (); \
55 if (CryptoServices != NULL && CryptoServices->Function != NULL) { \
56 (CryptoServices->Function) Args; \
59 CryptoServiceNotAvailable (#Function); \
64 Internal worker function that returns the pointer to an EDK II Crypto
65 Protocol/PPI. The layout of the PPI, DXE Protocol, and SMM Protocol are
66 identical which allows the implementation of the BaseCryptLib functions that
67 call through a Protocol/PPI to be shared for the PEI, DXE, and SMM
76 Internal worker function that prints a debug message and asserts if a crypto
77 service is not available. This should never occur because library instances
78 have a dependency expression for the for the EDK II Crypto Protocol/PPI so
79 a module that uses these library instances are not dispatched until the EDK II
80 Crypto Protocol/PPI is available. The only case that this function handles is
81 if the EDK II Crypto Protocol/PPI installed is NULL or a function pointer in
82 the EDK II Protocol/PPI is NULL.
84 @param[in] FunctionName Null-terminated ASCII string that is the name of an
85 EDK II Crypto service.
90 CryptoServiceNotAvailable (
91 IN CONST CHAR8
*FunctionName
94 DEBUG ((DEBUG_ERROR
, "[%a] Function %a is not available\n", gEfiCallerBaseName
, FunctionName
));
95 ASSERT_EFI_ERROR (EFI_UNSUPPORTED
);
98 // =====================================================================================
99 // One-Way Cryptographic Hash Primitives
100 // =====================================================================================
102 #ifdef ENABLE_MD5_DEPRECATED_INTERFACES
105 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.
107 If this interface is not supported, then return zero.
109 @return The size, in bytes, of the context buffer required for MD5 hash operations.
110 @retval 0 This interface is not supported.
119 CALL_CRYPTO_SERVICE (Md5GetContextSize
, (), 0);
123 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for
126 If Md5Context is NULL, then return FALSE.
127 If this interface is not supported, then return FALSE.
129 @param[out] Md5Context Pointer to MD5 context being initialized.
131 @retval TRUE MD5 context initialization succeeded.
132 @retval FALSE MD5 context initialization failed.
133 @retval FALSE This interface is not supported.
142 CALL_CRYPTO_SERVICE (Md5Init
, (Md5Context
), FALSE
);
146 Makes a copy of an existing MD5 context.
148 If Md5Context is NULL, then return FALSE.
149 If NewMd5Context is NULL, then return FALSE.
150 If this interface is not supported, then return FALSE.
152 @param[in] Md5Context Pointer to MD5 context being copied.
153 @param[out] NewMd5Context Pointer to new MD5 context.
155 @retval TRUE MD5 context copy succeeded.
156 @retval FALSE MD5 context copy failed.
157 @retval FALSE This interface is not supported.
163 IN CONST VOID
*Md5Context
,
164 OUT VOID
*NewMd5Context
167 CALL_CRYPTO_SERVICE (Md5Duplicate
, (Md5Context
, NewMd5Context
), FALSE
);
171 Digests the input data and updates MD5 context.
173 This function performs MD5 digest on a data buffer of the specified size.
174 It can be called multiple times to compute the digest of long or discontinuous data streams.
175 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized
176 by Md5Final(). Behavior with invalid context is undefined.
178 If Md5Context is NULL, then return FALSE.
179 If this interface is not supported, then return FALSE.
181 @param[in, out] Md5Context Pointer to the MD5 context.
182 @param[in] Data Pointer to the buffer containing the data to be hashed.
183 @param[in] DataSize Size of Data buffer in bytes.
185 @retval TRUE MD5 data digest succeeded.
186 @retval FALSE MD5 data digest failed.
187 @retval FALSE This interface is not supported.
193 IN OUT VOID
*Md5Context
,
198 CALL_CRYPTO_SERVICE (Md5Update
, (Md5Context
, Data
, DataSize
), FALSE
);
202 Completes computation of the MD5 digest value.
204 This function completes MD5 hash computation and retrieves the digest value into
205 the specified memory. After this function has been called, the MD5 context cannot
207 MD5 context should be already correctly initialized by Md5Init(), and should not be
208 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.
210 If Md5Context is NULL, then return FALSE.
211 If HashValue is NULL, then return FALSE.
212 If this interface is not supported, then return FALSE.
214 @param[in, out] Md5Context Pointer to the MD5 context.
215 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
218 @retval TRUE MD5 digest computation succeeded.
219 @retval FALSE MD5 digest computation failed.
220 @retval FALSE This interface is not supported.
226 IN OUT VOID
*Md5Context
,
230 CALL_CRYPTO_SERVICE (Md5Final
, (Md5Context
, HashValue
), FALSE
);
234 Computes the MD5 message digest of a input data buffer.
236 This function performs the MD5 message digest of a given data buffer, and places
237 the digest value into the specified memory.
239 If this interface is not supported, then return FALSE.
241 @param[in] Data Pointer to the buffer containing the data to be hashed.
242 @param[in] DataSize Size of Data buffer in bytes.
243 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
246 @retval TRUE MD5 digest computation succeeded.
247 @retval FALSE MD5 digest computation failed.
248 @retval FALSE This interface is not supported.
259 CALL_CRYPTO_SERVICE (Md5HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
264 #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
267 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.
269 If this interface is not supported, then return zero.
271 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.
272 @retval 0 This interface is not supported.
281 CALL_CRYPTO_SERVICE (Sha1GetContextSize
, (), 0);
285 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for
288 If Sha1Context is NULL, then return FALSE.
289 If this interface is not supported, then return FALSE.
291 @param[out] Sha1Context Pointer to SHA-1 context being initialized.
293 @retval TRUE SHA-1 context initialization succeeded.
294 @retval FALSE SHA-1 context initialization failed.
295 @retval FALSE This interface is not supported.
301 OUT VOID
*Sha1Context
304 CALL_CRYPTO_SERVICE (Sha1Init
, (Sha1Context
), FALSE
);
308 Makes a copy of an existing SHA-1 context.
310 If Sha1Context is NULL, then return FALSE.
311 If NewSha1Context is NULL, then return FALSE.
312 If this interface is not supported, then return FALSE.
314 @param[in] Sha1Context Pointer to SHA-1 context being copied.
315 @param[out] NewSha1Context Pointer to new SHA-1 context.
317 @retval TRUE SHA-1 context copy succeeded.
318 @retval FALSE SHA-1 context copy failed.
319 @retval FALSE This interface is not supported.
325 IN CONST VOID
*Sha1Context
,
326 OUT VOID
*NewSha1Context
329 CALL_CRYPTO_SERVICE (Sha1Duplicate
, (Sha1Context
, NewSha1Context
), FALSE
);
333 Digests the input data and updates SHA-1 context.
335 This function performs SHA-1 digest on a data buffer of the specified size.
336 It can be called multiple times to compute the digest of long or discontinuous data streams.
337 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized
338 by Sha1Final(). Behavior with invalid context is undefined.
340 If Sha1Context is NULL, then return FALSE.
341 If this interface is not supported, then return FALSE.
343 @param[in, out] Sha1Context Pointer to the SHA-1 context.
344 @param[in] Data Pointer to the buffer containing the data to be hashed.
345 @param[in] DataSize Size of Data buffer in bytes.
347 @retval TRUE SHA-1 data digest succeeded.
348 @retval FALSE SHA-1 data digest failed.
349 @retval FALSE This interface is not supported.
355 IN OUT VOID
*Sha1Context
,
360 CALL_CRYPTO_SERVICE (Sha1Update
, (Sha1Context
, Data
, DataSize
), FALSE
);
364 Completes computation of the SHA-1 digest value.
366 This function completes SHA-1 hash computation and retrieves the digest value into
367 the specified memory. After this function has been called, the SHA-1 context cannot
369 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be
370 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.
372 If Sha1Context is NULL, then return FALSE.
373 If HashValue is NULL, then return FALSE.
374 If this interface is not supported, then return FALSE.
376 @param[in, out] Sha1Context Pointer to the SHA-1 context.
377 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
380 @retval TRUE SHA-1 digest computation succeeded.
381 @retval FALSE SHA-1 digest computation failed.
382 @retval FALSE This interface is not supported.
388 IN OUT VOID
*Sha1Context
,
392 CALL_CRYPTO_SERVICE (Sha1Final
, (Sha1Context
, HashValue
), FALSE
);
396 Computes the SHA-1 message digest of a input data buffer.
398 This function performs the SHA-1 message digest of a given data buffer, and places
399 the digest value into the specified memory.
401 If this interface is not supported, then return FALSE.
403 @param[in] Data Pointer to the buffer containing the data to be hashed.
404 @param[in] DataSize Size of Data buffer in bytes.
405 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
408 @retval TRUE SHA-1 digest computation succeeded.
409 @retval FALSE SHA-1 digest computation failed.
410 @retval FALSE This interface is not supported.
421 CALL_CRYPTO_SERVICE (Sha1HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
427 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.
429 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.
434 Sha256GetContextSize (
438 CALL_CRYPTO_SERVICE (Sha256GetContextSize
, (), 0);
442 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for
445 If Sha256Context is NULL, then return FALSE.
447 @param[out] Sha256Context Pointer to SHA-256 context being initialized.
449 @retval TRUE SHA-256 context initialization succeeded.
450 @retval FALSE SHA-256 context initialization failed.
456 OUT VOID
*Sha256Context
459 CALL_CRYPTO_SERVICE (Sha256Init
, (Sha256Context
), FALSE
);
463 Makes a copy of an existing SHA-256 context.
465 If Sha256Context is NULL, then return FALSE.
466 If NewSha256Context is NULL, then return FALSE.
467 If this interface is not supported, then return FALSE.
469 @param[in] Sha256Context Pointer to SHA-256 context being copied.
470 @param[out] NewSha256Context Pointer to new SHA-256 context.
472 @retval TRUE SHA-256 context copy succeeded.
473 @retval FALSE SHA-256 context copy failed.
474 @retval FALSE This interface is not supported.
480 IN CONST VOID
*Sha256Context
,
481 OUT VOID
*NewSha256Context
484 CALL_CRYPTO_SERVICE (Sha256Duplicate
, (Sha256Context
, NewSha256Context
), FALSE
);
488 Digests the input data and updates SHA-256 context.
490 This function performs SHA-256 digest on a data buffer of the specified size.
491 It can be called multiple times to compute the digest of long or discontinuous data streams.
492 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized
493 by Sha256Final(). Behavior with invalid context is undefined.
495 If Sha256Context is NULL, then return FALSE.
497 @param[in, out] Sha256Context Pointer to the SHA-256 context.
498 @param[in] Data Pointer to the buffer containing the data to be hashed.
499 @param[in] DataSize Size of Data buffer in bytes.
501 @retval TRUE SHA-256 data digest succeeded.
502 @retval FALSE SHA-256 data digest failed.
508 IN OUT VOID
*Sha256Context
,
513 CALL_CRYPTO_SERVICE (Sha256Update
, (Sha256Context
, Data
, DataSize
), FALSE
);
517 Completes computation of the SHA-256 digest value.
519 This function completes SHA-256 hash computation and retrieves the digest value into
520 the specified memory. After this function has been called, the SHA-256 context cannot
522 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be
523 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.
525 If Sha256Context is NULL, then return FALSE.
526 If HashValue is NULL, then return FALSE.
528 @param[in, out] Sha256Context Pointer to the SHA-256 context.
529 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
532 @retval TRUE SHA-256 digest computation succeeded.
533 @retval FALSE SHA-256 digest computation failed.
539 IN OUT VOID
*Sha256Context
,
543 CALL_CRYPTO_SERVICE (Sha256Final
, (Sha256Context
, HashValue
), FALSE
);
547 Computes the SHA-256 message digest of a input data buffer.
549 This function performs the SHA-256 message digest of a given data buffer, and places
550 the digest value into the specified memory.
552 If this interface is not supported, then return FALSE.
554 @param[in] Data Pointer to the buffer containing the data to be hashed.
555 @param[in] DataSize Size of Data buffer in bytes.
556 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
559 @retval TRUE SHA-256 digest computation succeeded.
560 @retval FALSE SHA-256 digest computation failed.
561 @retval FALSE This interface is not supported.
572 CALL_CRYPTO_SERVICE (Sha256HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
576 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.
578 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.
583 Sha384GetContextSize (
587 CALL_CRYPTO_SERVICE (Sha384GetContextSize
, (), 0);
591 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for
594 If Sha384Context is NULL, then return FALSE.
596 @param[out] Sha384Context Pointer to SHA-384 context being initialized.
598 @retval TRUE SHA-384 context initialization succeeded.
599 @retval FALSE SHA-384 context initialization failed.
605 OUT VOID
*Sha384Context
608 CALL_CRYPTO_SERVICE (Sha384Init
, (Sha384Context
), FALSE
);
612 Makes a copy of an existing SHA-384 context.
614 If Sha384Context is NULL, then return FALSE.
615 If NewSha384Context is NULL, then return FALSE.
616 If this interface is not supported, then return FALSE.
618 @param[in] Sha384Context Pointer to SHA-384 context being copied.
619 @param[out] NewSha384Context Pointer to new SHA-384 context.
621 @retval TRUE SHA-384 context copy succeeded.
622 @retval FALSE SHA-384 context copy failed.
623 @retval FALSE This interface is not supported.
629 IN CONST VOID
*Sha384Context
,
630 OUT VOID
*NewSha384Context
633 CALL_CRYPTO_SERVICE (Sha384Duplicate
, (Sha384Context
, NewSha384Context
), FALSE
);
637 Digests the input data and updates SHA-384 context.
639 This function performs SHA-384 digest on a data buffer of the specified size.
640 It can be called multiple times to compute the digest of long or discontinuous data streams.
641 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized
642 by Sha384Final(). Behavior with invalid context is undefined.
644 If Sha384Context is NULL, then return FALSE.
646 @param[in, out] Sha384Context Pointer to the SHA-384 context.
647 @param[in] Data Pointer to the buffer containing the data to be hashed.
648 @param[in] DataSize Size of Data buffer in bytes.
650 @retval TRUE SHA-384 data digest succeeded.
651 @retval FALSE SHA-384 data digest failed.
657 IN OUT VOID
*Sha384Context
,
662 CALL_CRYPTO_SERVICE (Sha384Update
, (Sha384Context
, Data
, DataSize
), FALSE
);
666 Completes computation of the SHA-384 digest value.
668 This function completes SHA-384 hash computation and retrieves the digest value into
669 the specified memory. After this function has been called, the SHA-384 context cannot
671 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be
672 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.
674 If Sha384Context is NULL, then return FALSE.
675 If HashValue is NULL, then return FALSE.
677 @param[in, out] Sha384Context Pointer to the SHA-384 context.
678 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
681 @retval TRUE SHA-384 digest computation succeeded.
682 @retval FALSE SHA-384 digest computation failed.
688 IN OUT VOID
*Sha384Context
,
692 CALL_CRYPTO_SERVICE (Sha384Final
, (Sha384Context
, HashValue
), FALSE
);
696 Computes the SHA-384 message digest of a input data buffer.
698 This function performs the SHA-384 message digest of a given data buffer, and places
699 the digest value into the specified memory.
701 If this interface is not supported, then return FALSE.
703 @param[in] Data Pointer to the buffer containing the data to be hashed.
704 @param[in] DataSize Size of Data buffer in bytes.
705 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
708 @retval TRUE SHA-384 digest computation succeeded.
709 @retval FALSE SHA-384 digest computation failed.
710 @retval FALSE This interface is not supported.
721 CALL_CRYPTO_SERVICE (Sha384HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
725 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.
727 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.
732 Sha512GetContextSize (
736 CALL_CRYPTO_SERVICE (Sha512GetContextSize
, (), 0);
740 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for
743 If Sha512Context is NULL, then return FALSE.
745 @param[out] Sha512Context Pointer to SHA-512 context being initialized.
747 @retval TRUE SHA-512 context initialization succeeded.
748 @retval FALSE SHA-512 context initialization failed.
754 OUT VOID
*Sha512Context
757 CALL_CRYPTO_SERVICE (Sha512Init
, (Sha512Context
), FALSE
);
761 Makes a copy of an existing SHA-512 context.
763 If Sha512Context is NULL, then return FALSE.
764 If NewSha512Context is NULL, then return FALSE.
765 If this interface is not supported, then return FALSE.
767 @param[in] Sha512Context Pointer to SHA-512 context being copied.
768 @param[out] NewSha512Context Pointer to new SHA-512 context.
770 @retval TRUE SHA-512 context copy succeeded.
771 @retval FALSE SHA-512 context copy failed.
772 @retval FALSE This interface is not supported.
778 IN CONST VOID
*Sha512Context
,
779 OUT VOID
*NewSha512Context
782 CALL_CRYPTO_SERVICE (Sha512Duplicate
, (Sha512Context
, NewSha512Context
), FALSE
);
786 Digests the input data and updates SHA-512 context.
788 This function performs SHA-512 digest on a data buffer of the specified size.
789 It can be called multiple times to compute the digest of long or discontinuous data streams.
790 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized
791 by Sha512Final(). Behavior with invalid context is undefined.
793 If Sha512Context is NULL, then return FALSE.
795 @param[in, out] Sha512Context Pointer to the SHA-512 context.
796 @param[in] Data Pointer to the buffer containing the data to be hashed.
797 @param[in] DataSize Size of Data buffer in bytes.
799 @retval TRUE SHA-512 data digest succeeded.
800 @retval FALSE SHA-512 data digest failed.
806 IN OUT VOID
*Sha512Context
,
811 CALL_CRYPTO_SERVICE (Sha512Update
, (Sha512Context
, Data
, DataSize
), FALSE
);
815 Completes computation of the SHA-512 digest value.
817 This function completes SHA-512 hash computation and retrieves the digest value into
818 the specified memory. After this function has been called, the SHA-512 context cannot
820 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be
821 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.
823 If Sha512Context is NULL, then return FALSE.
824 If HashValue is NULL, then return FALSE.
826 @param[in, out] Sha512Context Pointer to the SHA-512 context.
827 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
830 @retval TRUE SHA-512 digest computation succeeded.
831 @retval FALSE SHA-512 digest computation failed.
837 IN OUT VOID
*Sha512Context
,
841 CALL_CRYPTO_SERVICE (Sha512Final
, (Sha512Context
, HashValue
), FALSE
);
845 Computes the SHA-512 message digest of a input data buffer.
847 This function performs the SHA-512 message digest of a given data buffer, and places
848 the digest value into the specified memory.
850 If this interface is not supported, then return FALSE.
852 @param[in] Data Pointer to the buffer containing the data to be hashed.
853 @param[in] DataSize Size of Data buffer in bytes.
854 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
857 @retval TRUE SHA-512 digest computation succeeded.
858 @retval FALSE SHA-512 digest computation failed.
859 @retval FALSE This interface is not supported.
870 CALL_CRYPTO_SERVICE (Sha512HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
874 Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.
876 @return The size, in bytes, of the context buffer required for SM3 hash operations.
885 CALL_CRYPTO_SERVICE (Sm3GetContextSize
, (), 0);
889 Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for
892 If Sm3Context is NULL, then return FALSE.
894 @param[out] Sm3Context Pointer to SM3 context being initialized.
896 @retval TRUE SM3 context initialization succeeded.
897 @retval FALSE SM3 context initialization failed.
906 CALL_CRYPTO_SERVICE (Sm3Init
, (Sm3Context
), FALSE
);
910 Makes a copy of an existing SM3 context.
912 If Sm3Context is NULL, then return FALSE.
913 If NewSm3Context is NULL, then return FALSE.
914 If this interface is not supported, then return FALSE.
916 @param[in] Sm3Context Pointer to SM3 context being copied.
917 @param[out] NewSm3Context Pointer to new SM3 context.
919 @retval TRUE SM3 context copy succeeded.
920 @retval FALSE SM3 context copy failed.
921 @retval FALSE This interface is not supported.
927 IN CONST VOID
*Sm3Context
,
928 OUT VOID
*NewSm3Context
931 CALL_CRYPTO_SERVICE (Sm3Duplicate
, (Sm3Context
, NewSm3Context
), FALSE
);
935 Digests the input data and updates SM3 context.
937 This function performs SM3 digest on a data buffer of the specified size.
938 It can be called multiple times to compute the digest of long or discontinuous data streams.
939 SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized
940 by Sm3Final(). Behavior with invalid context is undefined.
942 If Sm3Context is NULL, then return FALSE.
944 @param[in, out] Sm3Context Pointer to the SM3 context.
945 @param[in] Data Pointer to the buffer containing the data to be hashed.
946 @param[in] DataSize Size of Data buffer in bytes.
948 @retval TRUE SM3 data digest succeeded.
949 @retval FALSE SM3 data digest failed.
955 IN OUT VOID
*Sm3Context
,
960 CALL_CRYPTO_SERVICE (Sm3Update
, (Sm3Context
, Data
, DataSize
), FALSE
);
964 Completes computation of the SM3 digest value.
966 This function completes SM3 hash computation and retrieves the digest value into
967 the specified memory. After this function has been called, the SM3 context cannot
969 SM3 context should be already correctly initialized by Sm3Init(), and should not be
970 finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.
972 If Sm3Context is NULL, then return FALSE.
973 If HashValue is NULL, then return FALSE.
975 @param[in, out] Sm3Context Pointer to the SM3 context.
976 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
979 @retval TRUE SM3 digest computation succeeded.
980 @retval FALSE SM3 digest computation failed.
986 IN OUT VOID
*Sm3Context
,
990 CALL_CRYPTO_SERVICE (Sm3Final
, (Sm3Context
, HashValue
), FALSE
);
994 Computes the SM3 message digest of a input data buffer.
996 This function performs the SM3 message digest of a given data buffer, and places
997 the digest value into the specified memory.
999 If this interface is not supported, then return FALSE.
1001 @param[in] Data Pointer to the buffer containing the data to be hashed.
1002 @param[in] DataSize Size of Data buffer in bytes.
1003 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
1006 @retval TRUE SM3 digest computation succeeded.
1007 @retval FALSE SM3 digest computation failed.
1008 @retval FALSE This interface is not supported.
1014 IN CONST VOID
*Data
,
1016 OUT UINT8
*HashValue
1019 CALL_CRYPTO_SERVICE (Sm3HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
1022 // =====================================================================================
1023 // MAC (Message Authentication Code) Primitive
1024 // =====================================================================================
1027 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
1029 @return Pointer to the HMAC_CTX context that has been initialized.
1030 If the allocations fails, HmacSha256New() returns NULL.
1039 CALL_CRYPTO_SERVICE (HmacSha256New
, (), NULL
);
1043 Release the specified HMAC_CTX context.
1045 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.
1051 IN VOID
*HmacSha256Ctx
1054 CALL_VOID_CRYPTO_SERVICE (HmacSha256Free
, (HmacSha256Ctx
));
1058 Set user-supplied key for subsequent use. It must be done before any
1059 calling to HmacSha256Update().
1061 If HmacSha256Context is NULL, then return FALSE.
1062 If this interface is not supported, then return FALSE.
1064 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.
1065 @param[in] Key Pointer to the user-supplied key.
1066 @param[in] KeySize Key size in bytes.
1068 @retval TRUE The Key is set successfully.
1069 @retval FALSE The Key is set unsuccessfully.
1070 @retval FALSE This interface is not supported.
1076 OUT VOID
*HmacSha256Context
,
1077 IN CONST UINT8
*Key
,
1081 CALL_CRYPTO_SERVICE (HmacSha256SetKey
, (HmacSha256Context
, Key
, KeySize
), FALSE
);
1085 Makes a copy of an existing HMAC-SHA256 context.
1087 If HmacSha256Context is NULL, then return FALSE.
1088 If NewHmacSha256Context is NULL, then return FALSE.
1089 If this interface is not supported, then return FALSE.
1091 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.
1092 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.
1094 @retval TRUE HMAC-SHA256 context copy succeeded.
1095 @retval FALSE HMAC-SHA256 context copy failed.
1096 @retval FALSE This interface is not supported.
1101 HmacSha256Duplicate (
1102 IN CONST VOID
*HmacSha256Context
,
1103 OUT VOID
*NewHmacSha256Context
1106 CALL_CRYPTO_SERVICE (HmacSha256Duplicate
, (HmacSha256Context
, NewHmacSha256Context
), FALSE
);
1110 Digests the input data and updates HMAC-SHA256 context.
1112 This function performs HMAC-SHA256 digest on a data buffer of the specified size.
1113 It can be called multiple times to compute the digest of long or discontinuous data streams.
1114 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1115 by HmacSha256Final(). Behavior with invalid context is undefined.
1117 If HmacSha256Context is NULL, then return FALSE.
1118 If this interface is not supported, then return FALSE.
1120 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1121 @param[in] Data Pointer to the buffer containing the data to be digested.
1122 @param[in] DataSize Size of Data buffer in bytes.
1124 @retval TRUE HMAC-SHA256 data digest succeeded.
1125 @retval FALSE HMAC-SHA256 data digest failed.
1126 @retval FALSE This interface is not supported.
1132 IN OUT VOID
*HmacSha256Context
,
1133 IN CONST VOID
*Data
,
1137 CALL_CRYPTO_SERVICE (HmacSha256Update
, (HmacSha256Context
, Data
, DataSize
), FALSE
);
1141 Completes computation of the HMAC-SHA256 digest value.
1143 This function completes HMAC-SHA256 hash computation and retrieves the digest value into
1144 the specified memory. After this function has been called, the HMAC-SHA256 context cannot
1146 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1147 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.
1149 If HmacSha256Context is NULL, then return FALSE.
1150 If HmacValue is NULL, then return FALSE.
1151 If this interface is not supported, then return FALSE.
1153 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1154 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
1157 @retval TRUE HMAC-SHA256 digest computation succeeded.
1158 @retval FALSE HMAC-SHA256 digest computation failed.
1159 @retval FALSE This interface is not supported.
1165 IN OUT VOID
*HmacSha256Context
,
1166 OUT UINT8
*HmacValue
1169 CALL_CRYPTO_SERVICE (HmacSha256Final
, (HmacSha256Context
, HmacValue
), FALSE
);
1172 // =====================================================================================
1173 // Symmetric Cryptography Primitive
1174 // =====================================================================================
1177 Retrieves the size, in bytes, of the context buffer required for AES operations.
1179 If this interface is not supported, then return zero.
1181 @return The size, in bytes, of the context buffer required for AES operations.
1182 @retval 0 This interface is not supported.
1191 CALL_CRYPTO_SERVICE (AesGetContextSize
, (), 0);
1195 Initializes user-supplied memory as AES context for subsequent use.
1197 This function initializes user-supplied memory pointed by AesContext as AES context.
1198 In addition, it sets up all AES key materials for subsequent encryption and decryption
1200 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1202 If AesContext is NULL, then return FALSE.
1203 If Key is NULL, then return FALSE.
1204 If KeyLength is not valid, then return FALSE.
1205 If this interface is not supported, then return FALSE.
1207 @param[out] AesContext Pointer to AES context being initialized.
1208 @param[in] Key Pointer to the user-supplied AES key.
1209 @param[in] KeyLength Length of AES key in bits.
1211 @retval TRUE AES context initialization succeeded.
1212 @retval FALSE AES context initialization failed.
1213 @retval FALSE This interface is not supported.
1219 OUT VOID
*AesContext
,
1220 IN CONST UINT8
*Key
,
1224 CALL_CRYPTO_SERVICE (AesInit
, (AesContext
, Key
, KeyLength
), FALSE
);
1228 Performs AES encryption on a data buffer of the specified size in CBC mode.
1230 This function performs AES encryption on data buffer pointed by Input, of specified
1231 size of InputSize, in CBC mode.
1232 InputSize must be multiple of block size (16 bytes). This function does not perform
1233 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1234 Initialization vector should be one block size (16 bytes).
1235 AesContext should be already correctly initialized by AesInit(). Behavior with
1236 invalid AES context is undefined.
1238 If AesContext is NULL, then return FALSE.
1239 If Input is NULL, then return FALSE.
1240 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1241 If Ivec is NULL, then return FALSE.
1242 If Output is NULL, then return FALSE.
1243 If this interface is not supported, then return FALSE.
1245 @param[in] AesContext Pointer to the AES context.
1246 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1247 @param[in] InputSize Size of the Input buffer in bytes.
1248 @param[in] Ivec Pointer to initialization vector.
1249 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1251 @retval TRUE AES encryption succeeded.
1252 @retval FALSE AES encryption failed.
1253 @retval FALSE This interface is not supported.
1259 IN VOID
*AesContext
,
1260 IN CONST UINT8
*Input
,
1262 IN CONST UINT8
*Ivec
,
1266 CALL_CRYPTO_SERVICE (AesCbcEncrypt
, (AesContext
, Input
, InputSize
, Ivec
, Output
), FALSE
);
1270 Performs AES decryption on a data buffer of the specified size in CBC mode.
1272 This function performs AES decryption on data buffer pointed by Input, of specified
1273 size of InputSize, in CBC mode.
1274 InputSize must be multiple of block size (16 bytes). This function does not perform
1275 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1276 Initialization vector should be one block size (16 bytes).
1277 AesContext should be already correctly initialized by AesInit(). Behavior with
1278 invalid AES context is undefined.
1280 If AesContext is NULL, then return FALSE.
1281 If Input is NULL, then return FALSE.
1282 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1283 If Ivec is NULL, then return FALSE.
1284 If Output is NULL, then return FALSE.
1285 If this interface is not supported, then return FALSE.
1287 @param[in] AesContext Pointer to the AES context.
1288 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1289 @param[in] InputSize Size of the Input buffer in bytes.
1290 @param[in] Ivec Pointer to initialization vector.
1291 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1293 @retval TRUE AES decryption succeeded.
1294 @retval FALSE AES decryption failed.
1295 @retval FALSE This interface is not supported.
1301 IN VOID
*AesContext
,
1302 IN CONST UINT8
*Input
,
1304 IN CONST UINT8
*Ivec
,
1308 CALL_CRYPTO_SERVICE (AesCbcDecrypt
, (AesContext
, Input
, InputSize
, Ivec
, Output
), FALSE
);
1311 // =====================================================================================
1312 // Asymmetric Cryptography Primitive
1313 // =====================================================================================
1316 Allocates and initializes one RSA context for subsequent use.
1318 @return Pointer to the RSA context that has been initialized.
1319 If the allocations fails, RsaNew() returns NULL.
1328 CALL_CRYPTO_SERVICE (RsaNew
, (), NULL
);
1332 Release the specified RSA context.
1334 If RsaContext is NULL, then return FALSE.
1336 @param[in] RsaContext Pointer to the RSA context to be released.
1345 CALL_VOID_CRYPTO_SERVICE (RsaFree
, (RsaContext
));
1349 Sets the tag-designated key component into the established RSA context.
1351 This function sets the tag-designated RSA key component into the established
1352 RSA context from the user-specified non-negative integer (octet string format
1353 represented in RSA PKCS#1).
1354 If BigNumber is NULL, then the specified key component in RSA context is cleared.
1356 If RsaContext is NULL, then return FALSE.
1358 @param[in, out] RsaContext Pointer to RSA context being set.
1359 @param[in] KeyTag Tag of RSA key component being set.
1360 @param[in] BigNumber Pointer to octet integer buffer.
1361 If NULL, then the specified key component in RSA
1363 @param[in] BnSize Size of big number buffer in bytes.
1364 If BigNumber is NULL, then it is ignored.
1366 @retval TRUE RSA key component was set successfully.
1367 @retval FALSE Invalid RSA key component tag.
1373 IN OUT VOID
*RsaContext
,
1374 IN RSA_KEY_TAG KeyTag
,
1375 IN CONST UINT8
*BigNumber
,
1379 CALL_CRYPTO_SERVICE (RsaSetKey
, (RsaContext
, KeyTag
, BigNumber
, BnSize
), FALSE
);
1383 Gets the tag-designated RSA key component from the established RSA context.
1385 This function retrieves the tag-designated RSA key component from the
1386 established RSA context as a non-negative integer (octet string format
1387 represented in RSA PKCS#1).
1388 If specified key component has not been set or has been cleared, then returned
1390 If the BigNumber buffer is too small to hold the contents of the key, FALSE
1391 is returned and BnSize is set to the required buffer size to obtain the key.
1393 If RsaContext is NULL, then return FALSE.
1394 If BnSize is NULL, then return FALSE.
1395 If BnSize is large enough but BigNumber is NULL, then return FALSE.
1396 If this interface is not supported, then return FALSE.
1398 @param[in, out] RsaContext Pointer to RSA context being set.
1399 @param[in] KeyTag Tag of RSA key component being set.
1400 @param[out] BigNumber Pointer to octet integer buffer.
1401 @param[in, out] BnSize On input, the size of big number buffer in bytes.
1402 On output, the size of data returned in big number buffer in bytes.
1404 @retval TRUE RSA key component was retrieved successfully.
1405 @retval FALSE Invalid RSA key component tag.
1406 @retval FALSE BnSize is too small.
1407 @retval FALSE This interface is not supported.
1413 IN OUT VOID
*RsaContext
,
1414 IN RSA_KEY_TAG KeyTag
,
1415 OUT UINT8
*BigNumber
,
1416 IN OUT UINTN
*BnSize
1419 CALL_CRYPTO_SERVICE (RsaGetKey
, (RsaContext
, KeyTag
, BigNumber
, BnSize
), FALSE
);
1423 Generates RSA key components.
1425 This function generates RSA key components. It takes RSA public exponent E and
1426 length in bits of RSA modulus N as input, and generates all key components.
1427 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
1429 Before this function can be invoked, pseudorandom number generator must be correctly
1430 initialized by RandomSeed().
1432 If RsaContext is NULL, then return FALSE.
1433 If this interface is not supported, then return FALSE.
1435 @param[in, out] RsaContext Pointer to RSA context being set.
1436 @param[in] ModulusLength Length of RSA modulus N in bits.
1437 @param[in] PublicExponent Pointer to RSA public exponent.
1438 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
1440 @retval TRUE RSA key component was generated successfully.
1441 @retval FALSE Invalid RSA key component tag.
1442 @retval FALSE This interface is not supported.
1448 IN OUT VOID
*RsaContext
,
1449 IN UINTN ModulusLength
,
1450 IN CONST UINT8
*PublicExponent
,
1451 IN UINTN PublicExponentSize
1454 CALL_CRYPTO_SERVICE (RsaGenerateKey
, (RsaContext
, ModulusLength
, PublicExponent
, PublicExponentSize
), FALSE
);
1458 Validates key components of RSA context.
1459 NOTE: This function performs integrity checks on all the RSA key material, so
1460 the RSA key structure must contain all the private key data.
1462 This function validates key components of RSA context in following aspects:
1463 - Whether p is a prime
1464 - Whether q is a prime
1466 - Whether d*e = 1 mod lcm(p-1,q-1)
1468 If RsaContext is NULL, then return FALSE.
1469 If this interface is not supported, then return FALSE.
1471 @param[in] RsaContext Pointer to RSA context to check.
1473 @retval TRUE RSA key components are valid.
1474 @retval FALSE RSA key components are not valid.
1475 @retval FALSE This interface is not supported.
1484 CALL_CRYPTO_SERVICE (RsaCheckKey
, (RsaContext
), FALSE
);
1488 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
1490 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
1492 If the Signature buffer is too small to hold the contents of signature, FALSE
1493 is returned and SigSize is set to the required buffer size to obtain the signature.
1495 If RsaContext is NULL, then return FALSE.
1496 If MessageHash is NULL, then return FALSE.
1497 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
1498 If SigSize is large enough but Signature is NULL, then return FALSE.
1499 If this interface is not supported, then return FALSE.
1501 @param[in] RsaContext Pointer to RSA context for signature generation.
1502 @param[in] MessageHash Pointer to octet message hash to be signed.
1503 @param[in] HashSize Size of the message hash in bytes.
1504 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
1505 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1506 On output, the size of data returned in Signature buffer in bytes.
1508 @retval TRUE Signature successfully generated in PKCS1-v1_5.
1509 @retval FALSE Signature generation failed.
1510 @retval FALSE SigSize is too small.
1511 @retval FALSE This interface is not supported.
1517 IN VOID
*RsaContext
,
1518 IN CONST UINT8
*MessageHash
,
1520 OUT UINT8
*Signature
,
1521 IN OUT UINTN
*SigSize
1524 CALL_CRYPTO_SERVICE (RsaPkcs1Sign
, (RsaContext
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
1528 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
1531 If RsaContext is NULL, then return FALSE.
1532 If MessageHash is NULL, then return FALSE.
1533 If Signature is NULL, then return FALSE.
1534 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
1536 @param[in] RsaContext Pointer to RSA context for signature verification.
1537 @param[in] MessageHash Pointer to octet message hash to be checked.
1538 @param[in] HashSize Size of the message hash in bytes.
1539 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
1540 @param[in] SigSize Size of signature in bytes.
1542 @retval TRUE Valid signature encoded in PKCS1-v1_5.
1543 @retval FALSE Invalid signature or invalid RSA context.
1549 IN VOID
*RsaContext
,
1550 IN CONST UINT8
*MessageHash
,
1552 IN CONST UINT8
*Signature
,
1556 CALL_CRYPTO_SERVICE (RsaPkcs1Verify
, (RsaContext
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
1560 Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
1561 Implementation determines salt length automatically from the signature encoding.
1562 Mask generation function is the same as the message digest algorithm.
1563 Salt length should be equal to digest length.
1565 @param[in] RsaContext Pointer to RSA context for signature verification.
1566 @param[in] Message Pointer to octet message to be verified.
1567 @param[in] MsgSize Size of the message in bytes.
1568 @param[in] Signature Pointer to RSASSA-PSS signature to be verified.
1569 @param[in] SigSize Size of signature in bytes.
1570 @param[in] DigestLen Length of digest for RSA operation.
1571 @param[in] SaltLen Salt length for PSS encoding.
1573 @retval TRUE Valid signature encoded in RSASSA-PSS.
1574 @retval FALSE Invalid signature or invalid RSA context.
1580 IN VOID
*RsaContext
,
1581 IN CONST UINT8
*Message
,
1583 IN CONST UINT8
*Signature
,
1585 IN UINT16 DigestLen
,
1589 CALL_CRYPTO_SERVICE (RsaPssVerify
, (RsaContext
, Message
, MsgSize
, Signature
, SigSize
, DigestLen
, SaltLen
), FALSE
);
1593 This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in
1595 Mask generation function is the same as the message digest algorithm.
1596 If the Signature buffer is too small to hold the contents of signature, FALSE
1597 is returned and SigSize is set to the required buffer size to obtain the signature.
1599 If RsaContext is NULL, then return FALSE.
1600 If Message is NULL, then return FALSE.
1601 If MsgSize is zero or > INT_MAX, then return FALSE.
1602 If DigestLen is NOT 32, 48 or 64, return FALSE.
1603 If SaltLen is not equal to DigestLen, then return FALSE.
1604 If SigSize is large enough but Signature is NULL, then return FALSE.
1605 If this interface is not supported, then return FALSE.
1607 @param[in] RsaContext Pointer to RSA context for signature generation.
1608 @param[in] Message Pointer to octet message to be signed.
1609 @param[in] MsgSize Size of the message in bytes.
1610 @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.
1611 @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.
1612 @param[out] Signature Pointer to buffer to receive RSA PSS signature.
1613 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1614 On output, the size of data returned in Signature buffer in bytes.
1616 @retval TRUE Signature successfully generated in RSASSA-PSS.
1617 @retval FALSE Signature generation failed.
1618 @retval FALSE SigSize is too small.
1619 @retval FALSE This interface is not supported.
1625 IN VOID
*RsaContext
,
1626 IN CONST UINT8
*Message
,
1628 IN UINT16 DigestLen
,
1630 OUT UINT8
*Signature
,
1631 IN OUT UINTN
*SigSize
1634 CALL_CRYPTO_SERVICE (RsaPssSign
, (RsaContext
, Message
, MsgSize
, DigestLen
, SaltLen
, Signature
, SigSize
), FALSE
);
1638 Retrieve the RSA Private Key from the password-protected PEM key data.
1640 If PemData is NULL, then return FALSE.
1641 If RsaContext is NULL, then return FALSE.
1642 If this interface is not supported, then return FALSE.
1644 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
1645 @param[in] PemSize Size of the PEM key data in bytes.
1646 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
1647 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1648 RSA private key component. Use RsaFree() function to free the
1651 @retval TRUE RSA Private Key was retrieved successfully.
1652 @retval FALSE Invalid PEM key data or incorrect password.
1653 @retval FALSE This interface is not supported.
1658 RsaGetPrivateKeyFromPem (
1659 IN CONST UINT8
*PemData
,
1661 IN CONST CHAR8
*Password
,
1662 OUT VOID
**RsaContext
1665 CALL_CRYPTO_SERVICE (RsaGetPrivateKeyFromPem
, (PemData
, PemSize
, Password
, RsaContext
), FALSE
);
1669 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
1671 If Cert is NULL, then return FALSE.
1672 If RsaContext is NULL, then return FALSE.
1673 If this interface is not supported, then return FALSE.
1675 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1676 @param[in] CertSize Size of the X509 certificate in bytes.
1677 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1678 RSA public key component. Use RsaFree() function to free the
1681 @retval TRUE RSA Public Key was retrieved successfully.
1682 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
1683 @retval FALSE This interface is not supported.
1688 RsaGetPublicKeyFromX509 (
1689 IN CONST UINT8
*Cert
,
1691 OUT VOID
**RsaContext
1694 CALL_CRYPTO_SERVICE (RsaGetPublicKeyFromX509
, (Cert
, CertSize
, RsaContext
), FALSE
);
1698 Retrieve the subject bytes from one X.509 certificate.
1700 If Cert is NULL, then return FALSE.
1701 If SubjectSize is NULL, then return FALSE.
1702 If this interface is not supported, then return FALSE.
1704 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1705 @param[in] CertSize Size of the X509 certificate in bytes.
1706 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
1707 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
1708 and the size of buffer returned CertSubject on output.
1710 @retval TRUE The certificate subject retrieved successfully.
1711 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
1712 The SubjectSize will be updated with the required size.
1713 @retval FALSE This interface is not supported.
1718 X509GetSubjectName (
1719 IN CONST UINT8
*Cert
,
1721 OUT UINT8
*CertSubject
,
1722 IN OUT UINTN
*SubjectSize
1725 CALL_CRYPTO_SERVICE (X509GetSubjectName
, (Cert
, CertSize
, CertSubject
, SubjectSize
), FALSE
);
1729 Retrieve the common name (CN) string from one X.509 certificate.
1731 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1732 @param[in] CertSize Size of the X509 certificate in bytes.
1733 @param[out] CommonName Buffer to contain the retrieved certificate common
1734 name string (UTF8). At most CommonNameSize bytes will be
1735 written and the string will be null terminated. May be
1736 NULL in order to determine the size buffer needed.
1737 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
1738 and the size of buffer returned CommonName on output.
1739 If CommonName is NULL then the amount of space needed
1740 in buffer (including the final null) is returned.
1742 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
1743 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
1744 If CommonNameSize is NULL.
1745 If CommonName is not NULL and *CommonNameSize is 0.
1746 If Certificate is invalid.
1747 @retval RETURN_NOT_FOUND If no CommonName entry exists.
1748 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
1749 (including the final null) is returned in the
1750 CommonNameSize parameter.
1751 @retval RETURN_UNSUPPORTED The operation is not supported.
1757 IN CONST UINT8
*Cert
,
1759 OUT CHAR8
*CommonName OPTIONAL
,
1760 IN OUT UINTN
*CommonNameSize
1763 CALL_CRYPTO_SERVICE (X509GetCommonName
, (Cert
, CertSize
, CommonName
, CommonNameSize
), RETURN_UNSUPPORTED
);
1767 Retrieve the organization name (O) string from one X.509 certificate.
1769 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1770 @param[in] CertSize Size of the X509 certificate in bytes.
1771 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
1772 name string. At most NameBufferSize bytes will be
1773 written and the string will be null terminated. May be
1774 NULL in order to determine the size buffer needed.
1775 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
1776 and the size of buffer returned Name on output.
1777 If NameBuffer is NULL then the amount of space needed
1778 in buffer (including the final null) is returned.
1780 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
1781 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
1782 If NameBufferSize is NULL.
1783 If NameBuffer is not NULL and *CommonNameSize is 0.
1784 If Certificate is invalid.
1785 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
1786 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
1787 (including the final null) is returned in the
1788 CommonNameSize parameter.
1789 @retval RETURN_UNSUPPORTED The operation is not supported.
1794 X509GetOrganizationName (
1795 IN CONST UINT8
*Cert
,
1797 OUT CHAR8
*NameBuffer OPTIONAL
,
1798 IN OUT UINTN
*NameBufferSize
1801 CALL_CRYPTO_SERVICE (X509GetOrganizationName
, (Cert
, CertSize
, NameBuffer
, NameBufferSize
), RETURN_UNSUPPORTED
);
1805 Verify one X509 certificate was issued by the trusted CA.
1807 If Cert is NULL, then return FALSE.
1808 If CACert is NULL, then return FALSE.
1809 If this interface is not supported, then return FALSE.
1811 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
1812 @param[in] CertSize Size of the X509 certificate in bytes.
1813 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
1814 @param[in] CACertSize Size of the CA Certificate in bytes.
1816 @retval TRUE The certificate was issued by the trusted CA.
1817 @retval FALSE Invalid certificate or the certificate was not issued by the given
1819 @retval FALSE This interface is not supported.
1825 IN CONST UINT8
*Cert
,
1827 IN CONST UINT8
*CACert
,
1831 CALL_CRYPTO_SERVICE (X509VerifyCert
, (Cert
, CertSize
, CACert
, CACertSize
), FALSE
);
1835 Construct a X509 object from DER-encoded certificate data.
1837 If Cert is NULL, then return FALSE.
1838 If SingleX509Cert is NULL, then return FALSE.
1839 If this interface is not supported, then return FALSE.
1841 @param[in] Cert Pointer to the DER-encoded certificate data.
1842 @param[in] CertSize The size of certificate data in bytes.
1843 @param[out] SingleX509Cert The generated X509 object.
1845 @retval TRUE The X509 object generation succeeded.
1846 @retval FALSE The operation failed.
1847 @retval FALSE This interface is not supported.
1852 X509ConstructCertificate (
1853 IN CONST UINT8
*Cert
,
1855 OUT UINT8
**SingleX509Cert
1858 CALL_CRYPTO_SERVICE (X509ConstructCertificate
, (Cert
, CertSize
, SingleX509Cert
), FALSE
);
1862 Construct a X509 stack object from a list of DER-encoded certificate data.
1864 If X509Stack is NULL, then return FALSE.
1865 If this interface is not supported, then return FALSE.
1867 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
1868 On output, pointer to the X509 stack object with new
1869 inserted X509 certificate.
1870 @param[in] Args VA_LIST marker for the variable argument list.
1871 ... A list of DER-encoded single certificate data followed
1872 by certificate size. A NULL terminates the list. The
1873 pairs are the arguments to X509ConstructCertificate().
1875 @retval TRUE The X509 stack construction succeeded.
1876 @retval FALSE The construction operation failed.
1877 @retval FALSE This interface is not supported.
1882 X509ConstructCertificateStack (
1883 IN OUT UINT8
**X509Stack
,
1890 VA_START (Args
, X509Stack
);
1891 Result
= X509ConstructCertificateStackV (X509Stack
, Args
);
1897 Construct a X509 stack object from a list of DER-encoded certificate data.
1899 If X509Stack is NULL, then return FALSE.
1900 If this interface is not supported, then return FALSE.
1902 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
1903 On output, pointer to the X509 stack object with new
1904 inserted X509 certificate.
1905 @param[in] Args VA_LIST marker for the variable argument list.
1906 A list of DER-encoded single certificate data followed
1907 by certificate size. A NULL terminates the list. The
1908 pairs are the arguments to X509ConstructCertificate().
1910 @retval TRUE The X509 stack construction succeeded.
1911 @retval FALSE The construction operation failed.
1912 @retval FALSE This interface is not supported.
1917 X509ConstructCertificateStackV (
1918 IN OUT UINT8
**X509Stack
,
1922 CALL_CRYPTO_SERVICE (X509ConstructCertificateStackV
, (X509Stack
, Args
), FALSE
);
1926 Release the specified X509 object.
1928 If the interface is not supported, then ASSERT().
1930 @param[in] X509Cert Pointer to the X509 object to be released.
1939 CALL_VOID_CRYPTO_SERVICE (X509Free
, (X509Cert
));
1943 Release the specified X509 stack object.
1945 If the interface is not supported, then ASSERT().
1947 @param[in] X509Stack Pointer to the X509 stack object to be released.
1956 CALL_VOID_CRYPTO_SERVICE (X509StackFree
, (X509Stack
));
1960 Retrieve the TBSCertificate from one given X.509 certificate.
1962 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
1963 @param[in] CertSize Size of the X509 certificate in bytes.
1964 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
1965 @param[out] TBSCertSize Size of the TBS certificate in bytes.
1967 If Cert is NULL, then return FALSE.
1968 If TBSCert is NULL, then return FALSE.
1969 If TBSCertSize is NULL, then return FALSE.
1970 If this interface is not supported, then return FALSE.
1972 @retval TRUE The TBSCertificate was retrieved successfully.
1973 @retval FALSE Invalid X.509 certificate.
1979 IN CONST UINT8
*Cert
,
1981 OUT UINT8
**TBSCert
,
1982 OUT UINTN
*TBSCertSize
1985 CALL_CRYPTO_SERVICE (X509GetTBSCert
, (Cert
, CertSize
, TBSCert
, TBSCertSize
), FALSE
);
1989 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
1990 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
1992 If Password or Salt or OutKey is NULL, then return FALSE.
1993 If the hash algorithm could not be determined, then return FALSE.
1994 If this interface is not supported, then return FALSE.
1996 @param[in] PasswordLength Length of input password in bytes.
1997 @param[in] Password Pointer to the array for the password.
1998 @param[in] SaltLength Size of the Salt in bytes.
1999 @param[in] Salt Pointer to the Salt.
2000 @param[in] IterationCount Number of iterations to perform. Its value should be
2001 greater than or equal to 1.
2002 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2003 NOTE: DigestSize will be used to determine the hash algorithm.
2004 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2005 @param[in] KeyLength Size of the derived key buffer in bytes.
2006 @param[out] OutKey Pointer to the output derived key buffer.
2008 @retval TRUE A key was derived successfully.
2009 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2010 @retval FALSE The hash algorithm could not be determined from the digest size.
2011 @retval FALSE The key derivation operation failed.
2012 @retval FALSE This interface is not supported.
2018 IN UINTN PasswordLength
,
2019 IN CONST CHAR8
*Password
,
2020 IN UINTN SaltLength
,
2021 IN CONST UINT8
*Salt
,
2022 IN UINTN IterationCount
,
2023 IN UINTN DigestSize
,
2028 CALL_CRYPTO_SERVICE (Pkcs5HashPassword
, (PasswordLength
, Password
, SaltLength
, Salt
, IterationCount
, DigestSize
, KeyLength
, OutKey
), FALSE
);
2032 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2033 encrypted message in a newly allocated buffer.
2035 Things that can cause a failure include:
2036 - X509 key size does not match any known key size.
2037 - Fail to parse X509 certificate.
2038 - Fail to allocate an intermediate buffer.
2039 - Null pointer provided for a non-optional parameter.
2040 - Data size is too large for the provided key size (max size is a function of key size
2041 and hash digest size).
2043 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2044 will be used to encrypt the data.
2045 @param[in] PublicKeySize Size of the X509 cert buffer.
2046 @param[in] InData Data to be encrypted.
2047 @param[in] InDataSize Size of the data buffer.
2048 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2049 to be used when initializing the PRNG. NULL otherwise.
2050 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2052 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2054 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2056 @retval TRUE Encryption was successful.
2057 @retval FALSE Encryption failed.
2063 IN CONST UINT8
*PublicKey
,
2064 IN UINTN PublicKeySize
,
2066 IN UINTN InDataSize
,
2067 IN CONST UINT8
*PrngSeed OPTIONAL
,
2068 IN UINTN PrngSeedSize OPTIONAL
,
2069 OUT UINT8
**EncryptedData
,
2070 OUT UINTN
*EncryptedDataSize
2073 CALL_CRYPTO_SERVICE (Pkcs1v2Encrypt
, (PublicKey
, PublicKeySize
, InData
, InDataSize
, PrngSeed
, PrngSeedSize
, EncryptedData
, EncryptedDataSize
), FALSE
);
2077 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2078 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2079 in a ContentInfo structure.
2081 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2082 return FALSE. If P7Length overflow, then return FALSE.
2083 If this interface is not supported, then return FALSE.
2085 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2086 @param[in] P7Length Length of the PKCS#7 message in bytes.
2087 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2088 It's caller's responsibility to free the buffer with
2090 This data structure is EFI_CERT_STACK type.
2091 @param[out] StackLength Length of signer's certificates in bytes.
2092 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2093 It's caller's responsibility to free the buffer with
2095 @param[out] CertLength Length of the trusted certificate in bytes.
2097 @retval TRUE The operation is finished successfully.
2098 @retval FALSE Error occurs during the operation.
2099 @retval FALSE This interface is not supported.
2105 IN CONST UINT8
*P7Data
,
2107 OUT UINT8
**CertStack
,
2108 OUT UINTN
*StackLength
,
2109 OUT UINT8
**TrustedCert
,
2110 OUT UINTN
*CertLength
2113 CALL_CRYPTO_SERVICE (Pkcs7GetSigners
, (P7Data
, P7Length
, CertStack
, StackLength
, TrustedCert
, CertLength
), FALSE
);
2117 Wrap function to use free() to free allocated memory for certificates.
2119 If this interface is not supported, then ASSERT().
2121 @param[in] Certs Pointer to the certificates to be freed.
2130 CALL_VOID_CRYPTO_SERVICE (Pkcs7FreeSigners
, (Certs
));
2134 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2135 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2136 unchained to the signer's certificates.
2137 The input signed data could be wrapped in a ContentInfo structure.
2139 @param[in] P7Data Pointer to the PKCS#7 message.
2140 @param[in] P7Length Length of the PKCS#7 message in bytes.
2141 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2142 certificate. It's caller's responsibility to free the buffer
2143 with Pkcs7FreeSigners().
2144 This data structure is EFI_CERT_STACK type.
2145 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2146 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2147 responsibility to free the buffer with Pkcs7FreeSigners().
2148 This data structure is EFI_CERT_STACK type.
2149 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2151 @retval TRUE The operation is finished successfully.
2152 @retval FALSE Error occurs during the operation.
2157 Pkcs7GetCertificatesList (
2158 IN CONST UINT8
*P7Data
,
2160 OUT UINT8
**SignerChainCerts
,
2161 OUT UINTN
*ChainLength
,
2162 OUT UINT8
**UnchainCerts
,
2163 OUT UINTN
*UnchainLength
2166 CALL_CRYPTO_SERVICE (Pkcs7GetCertificatesList
, (P7Data
, P7Length
, SignerChainCerts
, ChainLength
, UnchainCerts
, UnchainLength
), FALSE
);
2170 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2171 Syntax Standard, version 1.5". This interface is only intended to be used for
2172 application to perform PKCS#7 functionality validation.
2174 If this interface is not supported, then return FALSE.
2176 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2178 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2179 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2181 @param[in] InData Pointer to the content to be signed.
2182 @param[in] InDataSize Size of InData in bytes.
2183 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2184 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2185 include in the PKCS#7 signedData (e.g. any intermediate
2187 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2188 responsibility to free the buffer with FreePool().
2189 @param[out] SignedDataSize Size of SignedData in bytes.
2191 @retval TRUE PKCS#7 data signing succeeded.
2192 @retval FALSE PKCS#7 data signing failed.
2193 @retval FALSE This interface is not supported.
2199 IN CONST UINT8
*PrivateKey
,
2200 IN UINTN PrivateKeySize
,
2201 IN CONST UINT8
*KeyPassword
,
2203 IN UINTN InDataSize
,
2205 IN UINT8
*OtherCerts OPTIONAL
,
2206 OUT UINT8
**SignedData
,
2207 OUT UINTN
*SignedDataSize
2210 CALL_CRYPTO_SERVICE (Pkcs7Sign
, (PrivateKey
, PrivateKeySize
, KeyPassword
, InData
, InDataSize
, SignCert
, OtherCerts
, SignedData
, SignedDataSize
), FALSE
);
2214 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2215 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2216 in a ContentInfo structure.
2218 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2219 If P7Length, CertLength or DataLength overflow, then return FALSE.
2220 If this interface is not supported, then return FALSE.
2222 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2223 @param[in] P7Length Length of the PKCS#7 message in bytes.
2224 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2225 is used for certificate chain verification.
2226 @param[in] CertLength Length of the trusted certificate in bytes.
2227 @param[in] InData Pointer to the content to be verified.
2228 @param[in] DataLength Length of InData in bytes.
2230 @retval TRUE The specified PKCS#7 signed data is valid.
2231 @retval FALSE Invalid PKCS#7 signed data.
2232 @retval FALSE This interface is not supported.
2238 IN CONST UINT8
*P7Data
,
2240 IN CONST UINT8
*TrustedCert
,
2241 IN UINTN CertLength
,
2242 IN CONST UINT8
*InData
,
2246 CALL_CRYPTO_SERVICE (Pkcs7Verify
, (P7Data
, P7Length
, TrustedCert
, CertLength
, InData
, DataLength
), FALSE
);
2250 This function receives a PKCS7 formatted signature, and then verifies that
2251 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
2252 leaf signing certificate.
2253 Note that this function does not validate the certificate chain.
2255 Applications for custom EKU's are quite flexible. For example, a policy EKU
2256 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
2257 certificate issued might also contain this EKU, thus constraining the
2258 sub-ordinate certificate. Other applications might allow a certificate
2259 embedded in a device to specify that other Object Identifiers (OIDs) are
2260 present which contains binary data specifying custom capabilities that
2261 the device is able to do.
2263 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
2264 containing the content block with both the signature,
2265 the signer's certificate, and any necessary intermediate
2267 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
2268 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
2269 required EKUs that must be present in the signature.
2270 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
2271 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
2272 must be present in the leaf signer. If it is
2273 FALSE, then we will succeed if we find any
2274 of the specified EKU's.
2276 @retval EFI_SUCCESS The required EKUs were found in the signature.
2277 @retval EFI_INVALID_PARAMETER A parameter was invalid.
2278 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
2283 VerifyEKUsInPkcs7Signature (
2284 IN CONST UINT8
*Pkcs7Signature
,
2285 IN CONST UINT32 SignatureSize
,
2286 IN CONST CHAR8
*RequiredEKUs
[],
2287 IN CONST UINT32 RequiredEKUsSize
,
2288 IN BOOLEAN RequireAllPresent
2291 CALL_CRYPTO_SERVICE (VerifyEKUsInPkcs7Signature
, (Pkcs7Signature
, SignatureSize
, RequiredEKUs
, RequiredEKUsSize
, RequireAllPresent
), FALSE
);
2295 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2296 data could be wrapped in a ContentInfo structure.
2298 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2299 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2301 Caution: This function may receive untrusted input. So this function will do
2302 basic check for PKCS#7 data structure.
2304 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2305 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2306 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2307 It's caller's responsibility to free the buffer with FreePool().
2308 @param[out] ContentSize The size of the extracted content in bytes.
2310 @retval TRUE The P7Data was correctly formatted for processing.
2311 @retval FALSE The P7Data was not correctly formatted for processing.
2316 Pkcs7GetAttachedContent (
2317 IN CONST UINT8
*P7Data
,
2320 OUT UINTN
*ContentSize
2323 CALL_CRYPTO_SERVICE (Pkcs7GetAttachedContent
, (P7Data
, P7Length
, Content
, ContentSize
), FALSE
);
2327 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2328 Authenticode Portable Executable Signature Format".
2330 If AuthData is NULL, then return FALSE.
2331 If ImageHash is NULL, then return FALSE.
2332 If this interface is not supported, then return FALSE.
2334 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2335 PE/COFF image to be verified.
2336 @param[in] DataSize Size of the Authenticode Signature in bytes.
2337 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2338 is used for certificate chain verification.
2339 @param[in] CertSize Size of the trusted certificate in bytes.
2340 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2341 for calculating the image hash value is described in Authenticode
2343 @param[in] HashSize Size of Image hash value in bytes.
2345 @retval TRUE The specified Authenticode Signature is valid.
2346 @retval FALSE Invalid Authenticode Signature.
2347 @retval FALSE This interface is not supported.
2352 AuthenticodeVerify (
2353 IN CONST UINT8
*AuthData
,
2355 IN CONST UINT8
*TrustedCert
,
2357 IN CONST UINT8
*ImageHash
,
2361 CALL_CRYPTO_SERVICE (AuthenticodeVerify
, (AuthData
, DataSize
, TrustedCert
, CertSize
, ImageHash
, HashSize
), FALSE
);
2365 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2368 If AuthData is NULL, then return FALSE.
2369 If this interface is not supported, then return FALSE.
2371 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2372 PE/COFF image to be verified.
2373 @param[in] DataSize Size of the Authenticode Signature in bytes.
2374 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2375 is used for TSA certificate chain verification.
2376 @param[in] CertSize Size of the trusted certificate in bytes.
2377 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2380 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2381 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2386 ImageTimestampVerify (
2387 IN CONST UINT8
*AuthData
,
2389 IN CONST UINT8
*TsaCert
,
2391 OUT EFI_TIME
*SigningTime
2394 CALL_CRYPTO_SERVICE (ImageTimestampVerify
, (AuthData
, DataSize
, TsaCert
, CertSize
, SigningTime
), FALSE
);
2397 // =====================================================================================
2398 // DH Key Exchange Primitive
2399 // =====================================================================================
2402 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
2404 @return Pointer to the Diffie-Hellman Context that has been initialized.
2405 If the allocations fails, DhNew() returns NULL.
2406 If the interface is not supported, DhNew() returns NULL.
2415 CALL_CRYPTO_SERVICE (DhNew
, (), NULL
);
2419 Release the specified DH context.
2421 If the interface is not supported, then ASSERT().
2423 @param[in] DhContext Pointer to the DH context to be released.
2432 CALL_VOID_CRYPTO_SERVICE (DhFree
, (DhContext
));
2436 Generates DH parameter.
2438 Given generator g, and length of prime number p in bits, this function generates p,
2439 and sets DH context according to value of g and p.
2441 Before this function can be invoked, pseudorandom number generator must be correctly
2442 initialized by RandomSeed().
2444 If DhContext is NULL, then return FALSE.
2445 If Prime is NULL, then return FALSE.
2446 If this interface is not supported, then return FALSE.
2448 @param[in, out] DhContext Pointer to the DH context.
2449 @param[in] Generator Value of generator.
2450 @param[in] PrimeLength Length in bits of prime to be generated.
2451 @param[out] Prime Pointer to the buffer to receive the generated prime number.
2453 @retval TRUE DH parameter generation succeeded.
2454 @retval FALSE Value of Generator is not supported.
2455 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
2456 @retval FALSE This interface is not supported.
2461 DhGenerateParameter (
2462 IN OUT VOID
*DhContext
,
2464 IN UINTN PrimeLength
,
2468 CALL_CRYPTO_SERVICE (DhGenerateParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
2472 Sets generator and prime parameters for DH.
2474 Given generator g, and prime number p, this function and sets DH
2475 context accordingly.
2477 If DhContext is NULL, then return FALSE.
2478 If Prime is NULL, then return FALSE.
2479 If this interface is not supported, then return FALSE.
2481 @param[in, out] DhContext Pointer to the DH context.
2482 @param[in] Generator Value of generator.
2483 @param[in] PrimeLength Length in bits of prime to be generated.
2484 @param[in] Prime Pointer to the prime number.
2486 @retval TRUE DH parameter setting succeeded.
2487 @retval FALSE Value of Generator is not supported.
2488 @retval FALSE Value of Generator is not suitable for the Prime.
2489 @retval FALSE Value of Prime is not a prime number.
2490 @retval FALSE Value of Prime is not a safe prime number.
2491 @retval FALSE This interface is not supported.
2497 IN OUT VOID
*DhContext
,
2499 IN UINTN PrimeLength
,
2500 IN CONST UINT8
*Prime
2503 CALL_CRYPTO_SERVICE (DhSetParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
2507 Generates DH public key.
2509 This function generates random secret exponent, and computes the public key, which is
2510 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
2511 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
2512 PublicKeySize is set to the required buffer size to obtain the public key.
2514 If DhContext is NULL, then return FALSE.
2515 If PublicKeySize is NULL, then return FALSE.
2516 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
2517 If this interface is not supported, then return FALSE.
2519 @param[in, out] DhContext Pointer to the DH context.
2520 @param[out] PublicKey Pointer to the buffer to receive generated public key.
2521 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
2522 On output, the size of data returned in PublicKey buffer in bytes.
2524 @retval TRUE DH public key generation succeeded.
2525 @retval FALSE DH public key generation failed.
2526 @retval FALSE PublicKeySize is not large enough.
2527 @retval FALSE This interface is not supported.
2533 IN OUT VOID
*DhContext
,
2534 OUT UINT8
*PublicKey
,
2535 IN OUT UINTN
*PublicKeySize
2538 CALL_CRYPTO_SERVICE (DhGenerateKey
, (DhContext
, PublicKey
, PublicKeySize
), FALSE
);
2542 Computes exchanged common key.
2544 Given peer's public key, this function computes the exchanged common key, based on its own
2545 context including value of prime modulus and random secret exponent.
2547 If DhContext is NULL, then return FALSE.
2548 If PeerPublicKey is NULL, then return FALSE.
2549 If KeySize is NULL, then return FALSE.
2550 If Key is NULL, then return FALSE.
2551 If KeySize is not large enough, then return FALSE.
2552 If this interface is not supported, then return FALSE.
2554 @param[in, out] DhContext Pointer to the DH context.
2555 @param[in] PeerPublicKey Pointer to the peer's public key.
2556 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
2557 @param[out] Key Pointer to the buffer to receive generated key.
2558 @param[in, out] KeySize On input, the size of Key buffer in bytes.
2559 On output, the size of data returned in Key buffer in bytes.
2561 @retval TRUE DH exchanged key generation succeeded.
2562 @retval FALSE DH exchanged key generation failed.
2563 @retval FALSE KeySize is not large enough.
2564 @retval FALSE This interface is not supported.
2570 IN OUT VOID
*DhContext
,
2571 IN CONST UINT8
*PeerPublicKey
,
2572 IN UINTN PeerPublicKeySize
,
2574 IN OUT UINTN
*KeySize
2577 CALL_CRYPTO_SERVICE (DhComputeKey
, (DhContext
, PeerPublicKey
, PeerPublicKeySize
, Key
, KeySize
), FALSE
);
2580 // =====================================================================================
2581 // Pseudo-Random Generation Primitive
2582 // =====================================================================================
2585 Sets up the seed value for the pseudorandom number generator.
2587 This function sets up the seed value for the pseudorandom number generator.
2588 If Seed is not NULL, then the seed passed in is used.
2589 If Seed is NULL, then default seed is used.
2590 If this interface is not supported, then return FALSE.
2592 @param[in] Seed Pointer to seed value.
2593 If NULL, default seed is used.
2594 @param[in] SeedSize Size of seed value.
2595 If Seed is NULL, this parameter is ignored.
2597 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
2598 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
2599 @retval FALSE This interface is not supported.
2605 IN CONST UINT8
*Seed OPTIONAL
,
2609 CALL_CRYPTO_SERVICE (RandomSeed
, (Seed
, SeedSize
), FALSE
);
2613 Generates a pseudorandom byte stream of the specified size.
2615 If Output is NULL, then return FALSE.
2616 If this interface is not supported, then return FALSE.
2618 @param[out] Output Pointer to buffer to receive random value.
2619 @param[in] Size Size of random bytes to generate.
2621 @retval TRUE Pseudorandom byte stream generated successfully.
2622 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
2623 @retval FALSE This interface is not supported.
2633 CALL_CRYPTO_SERVICE (RandomBytes
, (Output
, Size
), FALSE
);
2636 // =====================================================================================
2637 // Key Derivation Function Primitive
2638 // =====================================================================================
2641 Derive key data using HMAC-SHA256 based KDF.
2643 @param[in] Key Pointer to the user-supplied key.
2644 @param[in] KeySize Key size in bytes.
2645 @param[in] Salt Pointer to the salt(non-secret) value.
2646 @param[in] SaltSize Salt size in bytes.
2647 @param[in] Info Pointer to the application specific info.
2648 @param[in] InfoSize Info size in bytes.
2649 @param[out] Out Pointer to buffer to receive hkdf value.
2650 @param[in] OutSize Size of hkdf bytes to generate.
2652 @retval TRUE Hkdf generated successfully.
2653 @retval FALSE Hkdf generation failed.
2658 HkdfSha256ExtractAndExpand (
2659 IN CONST UINT8
*Key
,
2661 IN CONST UINT8
*Salt
,
2663 IN CONST UINT8
*Info
,
2669 CALL_CRYPTO_SERVICE (HkdfSha256ExtractAndExpand
, (Key
, KeySize
, Salt
, SaltSize
, Info
, InfoSize
, Out
, OutSize
), FALSE
);
2673 Initializes the OpenSSL library.
2675 This function registers ciphers and digests used directly and indirectly
2676 by SSL/TLS, and initializes the readable error messages.
2677 This function must be called before any other action takes places.
2679 @retval TRUE The OpenSSL library has been initialized.
2680 @retval FALSE Failed to initialize the OpenSSL library.
2689 CALL_CRYPTO_SERVICE (TlsInitialize
, (), FALSE
);
2693 Free an allocated SSL_CTX object.
2695 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
2704 CALL_VOID_CRYPTO_SERVICE (TlsCtxFree
, (TlsCtx
));
2708 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
2711 @param[in] MajorVer Major Version of TLS/SSL Protocol.
2712 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
2714 @return Pointer to an allocated SSL_CTX object.
2715 If the creation failed, TlsCtxNew() returns NULL.
2725 CALL_CRYPTO_SERVICE (TlsCtxNew
, (MajorVer
, MinorVer
), NULL
);
2729 Free an allocated TLS object.
2731 This function removes the TLS object pointed to by Tls and frees up the
2732 allocated memory. If Tls is NULL, nothing is done.
2734 @param[in] Tls Pointer to the TLS object to be freed.
2743 CALL_VOID_CRYPTO_SERVICE (TlsFree
, (Tls
));
2747 Create a new TLS object for a connection.
2749 This function creates a new TLS object for a connection. The new object
2750 inherits the setting of the underlying context TlsCtx: connection method,
2751 options, verification setting.
2753 @param[in] TlsCtx Pointer to the SSL_CTX object.
2755 @return Pointer to an allocated SSL object.
2756 If the creation failed, TlsNew() returns NULL.
2765 CALL_CRYPTO_SERVICE (TlsNew
, (TlsCtx
), NULL
);
2769 Checks if the TLS handshake was done.
2771 This function will check if the specified TLS handshake was done.
2773 @param[in] Tls Pointer to the TLS object for handshake state checking.
2775 @retval TRUE The TLS handshake was done.
2776 @retval FALSE The TLS handshake was not done.
2785 CALL_CRYPTO_SERVICE (TlsInHandshake
, (Tls
), FALSE
);
2789 Perform a TLS/SSL handshake.
2791 This function will perform a TLS/SSL handshake.
2793 @param[in] Tls Pointer to the TLS object for handshake operation.
2794 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
2795 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
2797 @param[out] BufferOut Pointer to the buffer to hold the built packet.
2798 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
2799 the buffer size provided by the caller. On output, it
2800 is the buffer size in fact needed to contain the
2803 @retval EFI_SUCCESS The required TLS packet is built successfully.
2804 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2806 BufferIn is NULL but BufferInSize is NOT 0.
2807 BufferInSize is 0 but BufferIn is NOT NULL.
2808 BufferOutSize is NULL.
2809 BufferOut is NULL if *BufferOutSize is not zero.
2810 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
2811 @retval EFI_ABORTED Something wrong during handshake.
2818 IN UINT8
*BufferIn OPTIONAL
,
2819 IN UINTN BufferInSize OPTIONAL
,
2820 OUT UINT8
*BufferOut OPTIONAL
,
2821 IN OUT UINTN
*BufferOutSize
2824 CALL_CRYPTO_SERVICE (TlsDoHandshake
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
2828 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
2829 TLS session has errors and the response packet needs to be Alert message based on error type.
2831 @param[in] Tls Pointer to the TLS object for state checking.
2832 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
2833 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
2835 @param[out] BufferOut Pointer to the buffer to hold the built packet.
2836 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
2837 the buffer size provided by the caller. On output, it
2838 is the buffer size in fact needed to contain the
2841 @retval EFI_SUCCESS The required TLS packet is built successfully.
2842 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2844 BufferIn is NULL but BufferInSize is NOT 0.
2845 BufferInSize is 0 but BufferIn is NOT NULL.
2846 BufferOutSize is NULL.
2847 BufferOut is NULL if *BufferOutSize is not zero.
2848 @retval EFI_ABORTED An error occurred.
2849 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
2856 IN UINT8
*BufferIn OPTIONAL
,
2857 IN UINTN BufferInSize OPTIONAL
,
2858 OUT UINT8
*BufferOut OPTIONAL
,
2859 IN OUT UINTN
*BufferOutSize
2862 CALL_CRYPTO_SERVICE (TlsHandleAlert
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
2866 Build the CloseNotify packet.
2868 @param[in] Tls Pointer to the TLS object for state checking.
2869 @param[in, out] Buffer Pointer to the buffer to hold the built packet.
2870 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
2871 the buffer size provided by the caller. On output, it
2872 is the buffer size in fact needed to contain the
2875 @retval EFI_SUCCESS The required TLS packet is built successfully.
2876 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2879 Buffer is NULL if *BufferSize is not zero.
2880 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
2887 IN OUT UINT8
*Buffer
,
2888 IN OUT UINTN
*BufferSize
2891 CALL_CRYPTO_SERVICE (TlsCloseNotify
, (Tls
, Buffer
, BufferSize
), EFI_UNSUPPORTED
);
2895 Attempts to read bytes from one TLS object and places the data in Buffer.
2897 This function will attempt to read BufferSize bytes from the TLS object
2898 and places the data in Buffer.
2900 @param[in] Tls Pointer to the TLS object.
2901 @param[in,out] Buffer Pointer to the buffer to store the data.
2902 @param[in] BufferSize The size of Buffer in bytes.
2904 @retval >0 The amount of data successfully read from the TLS object.
2905 @retval <=0 No data was successfully read.
2912 IN OUT VOID
*Buffer
,
2916 CALL_CRYPTO_SERVICE (TlsCtrlTrafficOut
, (Tls
, Buffer
, BufferSize
), 0);
2920 Attempts to write data from the buffer to TLS object.
2922 This function will attempt to write BufferSize bytes data from the Buffer
2925 @param[in] Tls Pointer to the TLS object.
2926 @param[in] Buffer Pointer to the data buffer.
2927 @param[in] BufferSize The size of Buffer in bytes.
2929 @retval >0 The amount of data successfully written to the TLS object.
2930 @retval <=0 No data was successfully written.
2941 CALL_CRYPTO_SERVICE (TlsCtrlTrafficIn
, (Tls
, Buffer
, BufferSize
), 0);
2945 Attempts to read bytes from the specified TLS connection into the buffer.
2947 This function tries to read BufferSize bytes data from the specified TLS
2948 connection into the Buffer.
2950 @param[in] Tls Pointer to the TLS connection for data reading.
2951 @param[in,out] Buffer Pointer to the data buffer.
2952 @param[in] BufferSize The size of Buffer in bytes.
2954 @retval >0 The read operation was successful, and return value is the
2955 number of bytes actually read from the TLS connection.
2956 @retval <=0 The read operation was not successful.
2963 IN OUT VOID
*Buffer
,
2967 CALL_CRYPTO_SERVICE (TlsRead
, (Tls
, Buffer
, BufferSize
), 0);
2971 Attempts to write data to a TLS connection.
2973 This function tries to write BufferSize bytes data from the Buffer into the
2974 specified TLS connection.
2976 @param[in] Tls Pointer to the TLS connection for data writing.
2977 @param[in] Buffer Pointer to the data buffer.
2978 @param[in] BufferSize The size of Buffer in bytes.
2980 @retval >0 The write operation was successful, and return value is the
2981 number of bytes actually written to the TLS connection.
2982 @retval <=0 The write operation was not successful.
2993 CALL_CRYPTO_SERVICE (TlsWrite
, (Tls
, Buffer
, BufferSize
), 0);
2997 Set a new TLS/SSL method for a particular TLS object.
2999 This function sets a new TLS/SSL method for a particular TLS object.
3001 @param[in] Tls Pointer to a TLS object.
3002 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3003 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3005 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
3006 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3007 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
3018 CALL_CRYPTO_SERVICE (TlsSetVersion
, (Tls
, MajorVer
, MinorVer
), EFI_UNSUPPORTED
);
3022 Set TLS object to work in client or server mode.
3024 This function prepares a TLS object to work in client or server mode.
3026 @param[in] Tls Pointer to a TLS object.
3027 @param[in] IsServer Work in server mode.
3029 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
3030 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3031 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
3036 TlsSetConnectionEnd (
3041 CALL_CRYPTO_SERVICE (TlsSetConnectionEnd
, (Tls
, IsServer
), EFI_UNSUPPORTED
);
3045 Set the ciphers list to be used by the TLS object.
3047 This function sets the ciphers for use by a specified TLS object.
3049 @param[in] Tls Pointer to a TLS object.
3050 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
3051 cipher identifier comes from the TLS Cipher Suite
3052 Registry of the IANA, interpreting Byte1 and Byte2
3053 in network (big endian) byte order.
3054 @param[in] CipherNum The number of cipher in the list.
3056 @retval EFI_SUCCESS The ciphers list was set successfully.
3057 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3058 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
3059 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
3066 IN UINT16
*CipherId
,
3070 CALL_CRYPTO_SERVICE (TlsSetCipherList
, (Tls
, CipherId
, CipherNum
), EFI_UNSUPPORTED
);
3074 Set the compression method for TLS/SSL operations.
3076 This function handles TLS/SSL integrated compression methods.
3078 @param[in] CompMethod The compression method ID.
3080 @retval EFI_SUCCESS The compression method for the communication was
3082 @retval EFI_UNSUPPORTED Unsupported compression method.
3087 TlsSetCompressionMethod (
3091 CALL_CRYPTO_SERVICE (TlsSetCompressionMethod
, (CompMethod
), EFI_UNSUPPORTED
);
3095 Set peer certificate verification mode for the TLS connection.
3097 This function sets the verification mode flags for the TLS connection.
3099 @param[in] Tls Pointer to the TLS object.
3100 @param[in] VerifyMode A set of logically or'ed verification mode flags.
3107 IN UINT32 VerifyMode
3110 CALL_VOID_CRYPTO_SERVICE (TlsSetVerify
, (Tls
, VerifyMode
));
3114 Set the specified host name to be verified.
3116 @param[in] Tls Pointer to the TLS object.
3117 @param[in] Flags The setting flags during the validation.
3118 @param[in] HostName The specified host name to be verified.
3120 @retval EFI_SUCCESS The HostName setting was set successfully.
3121 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3122 @retval EFI_ABORTED Invalid HostName setting.
3133 CALL_CRYPTO_SERVICE (TlsSetVerifyHost
, (Tls
, Flags
, HostName
), EFI_UNSUPPORTED
);
3137 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
3139 This function sets a session ID to be used when the TLS/SSL connection is
3142 @param[in] Tls Pointer to the TLS object.
3143 @param[in] SessionId Session ID data used for session resumption.
3144 @param[in] SessionIdLen Length of Session ID in bytes.
3146 @retval EFI_SUCCESS Session ID was set successfully.
3147 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3148 @retval EFI_UNSUPPORTED No available session for ID setting.
3155 IN UINT8
*SessionId
,
3156 IN UINT16 SessionIdLen
3159 CALL_CRYPTO_SERVICE (TlsSetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
3163 Adds the CA to the cert store when requesting Server or Client authentication.
3165 This function adds the CA certificate to the list of CAs when requesting
3166 Server or Client authentication for the chosen TLS connection.
3168 @param[in] Tls Pointer to the TLS object.
3169 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3170 X.509 certificate or PEM-encoded X.509 certificate.
3171 @param[in] DataSize The size of data buffer in bytes.
3173 @retval EFI_SUCCESS The operation succeeded.
3174 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3175 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3176 @retval EFI_ABORTED Invalid X.509 certificate.
3181 TlsSetCaCertificate (
3187 CALL_CRYPTO_SERVICE (TlsSetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3191 Loads the local public certificate into the specified TLS object.
3193 This function loads the X.509 certificate into the specified TLS object
3194 for TLS negotiation.
3196 @param[in] Tls Pointer to the TLS object.
3197 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3198 X.509 certificate or PEM-encoded X.509 certificate.
3199 @param[in] DataSize The size of data buffer in bytes.
3201 @retval EFI_SUCCESS The operation succeeded.
3202 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3203 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3204 @retval EFI_ABORTED Invalid X.509 certificate.
3209 TlsSetHostPublicCert (
3215 CALL_CRYPTO_SERVICE (TlsSetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3219 Adds the local private key to the specified TLS object.
3221 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
3222 key) into the specified TLS object for TLS negotiation.
3224 @param[in] Tls Pointer to the TLS object.
3225 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
3226 or PKCS#8 private key.
3227 @param[in] DataSize The size of data buffer in bytes.
3229 @retval EFI_SUCCESS The operation succeeded.
3230 @retval EFI_UNSUPPORTED This function is not supported.
3231 @retval EFI_ABORTED Invalid private key data.
3236 TlsSetHostPrivateKey (
3242 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3246 Adds the CA-supplied certificate revocation list for certificate validation.
3248 This function adds the CA-supplied certificate revocation list data for
3249 certificate validity checking.
3251 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
3252 @param[in] DataSize The size of data buffer in bytes.
3254 @retval EFI_SUCCESS The operation succeeded.
3255 @retval EFI_UNSUPPORTED This function is not supported.
3256 @retval EFI_ABORTED Invalid CRL data.
3261 TlsSetCertRevocationList (
3266 CALL_CRYPTO_SERVICE (TlsSetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);
3270 Gets the protocol version used by the specified TLS connection.
3272 This function returns the protocol version used by the specified TLS
3275 If Tls is NULL, then ASSERT().
3277 @param[in] Tls Pointer to the TLS object.
3279 @return The protocol version of the specified TLS connection.
3288 CALL_CRYPTO_SERVICE (TlsGetVersion
, (Tls
), 0);
3292 Gets the connection end of the specified TLS connection.
3294 This function returns the connection end (as client or as server) used by
3295 the specified TLS connection.
3297 If Tls is NULL, then ASSERT().
3299 @param[in] Tls Pointer to the TLS object.
3301 @return The connection end used by the specified TLS connection.
3306 TlsGetConnectionEnd (
3310 CALL_CRYPTO_SERVICE (TlsGetConnectionEnd
, (Tls
), 0);
3314 Gets the cipher suite used by the specified TLS connection.
3316 This function returns current cipher suite used by the specified
3319 @param[in] Tls Pointer to the TLS object.
3320 @param[in,out] CipherId The cipher suite used by the TLS object.
3322 @retval EFI_SUCCESS The cipher suite was returned successfully.
3323 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3324 @retval EFI_UNSUPPORTED Unsupported cipher suite.
3329 TlsGetCurrentCipher (
3331 IN OUT UINT16
*CipherId
3334 CALL_CRYPTO_SERVICE (TlsGetCurrentCipher
, (Tls
, CipherId
), EFI_UNSUPPORTED
);
3338 Gets the compression methods used by the specified TLS connection.
3340 This function returns current integrated compression methods used by
3341 the specified TLS connection.
3343 @param[in] Tls Pointer to the TLS object.
3344 @param[in,out] CompressionId The current compression method used by
3347 @retval EFI_SUCCESS The compression method was returned successfully.
3348 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3349 @retval EFI_ABORTED Invalid Compression method.
3350 @retval EFI_UNSUPPORTED This function is not supported.
3355 TlsGetCurrentCompressionId (
3357 IN OUT UINT8
*CompressionId
3360 CALL_CRYPTO_SERVICE (TlsGetCurrentCompressionId
, (Tls
, CompressionId
), EFI_UNSUPPORTED
);
3364 Gets the verification mode currently set in the TLS connection.
3366 This function returns the peer verification mode currently set in the
3367 specified TLS connection.
3369 If Tls is NULL, then ASSERT().
3371 @param[in] Tls Pointer to the TLS object.
3373 @return The verification mode set in the specified TLS connection.
3382 CALL_CRYPTO_SERVICE (TlsGetVerify
, (Tls
), 0);
3386 Gets the session ID used by the specified TLS connection.
3388 This function returns the TLS/SSL session ID currently used by the
3389 specified TLS connection.
3391 @param[in] Tls Pointer to the TLS object.
3392 @param[in,out] SessionId Buffer to contain the returned session ID.
3393 @param[in,out] SessionIdLen The length of Session ID in bytes.
3395 @retval EFI_SUCCESS The Session ID was returned successfully.
3396 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3397 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
3404 IN OUT UINT8
*SessionId
,
3405 IN OUT UINT16
*SessionIdLen
3408 CALL_CRYPTO_SERVICE (TlsGetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
3412 Gets the client random data used in the specified TLS connection.
3414 This function returns the TLS/SSL client random data currently used in
3415 the specified TLS connection.
3417 @param[in] Tls Pointer to the TLS object.
3418 @param[in,out] ClientRandom Buffer to contain the returned client
3419 random data (32 bytes).
3424 TlsGetClientRandom (
3426 IN OUT UINT8
*ClientRandom
3429 CALL_VOID_CRYPTO_SERVICE (TlsGetClientRandom
, (Tls
, ClientRandom
));
3433 Gets the server random data used in the specified TLS connection.
3435 This function returns the TLS/SSL server random data currently used in
3436 the specified TLS connection.
3438 @param[in] Tls Pointer to the TLS object.
3439 @param[in,out] ServerRandom Buffer to contain the returned server
3440 random data (32 bytes).
3445 TlsGetServerRandom (
3447 IN OUT UINT8
*ServerRandom
3450 CALL_VOID_CRYPTO_SERVICE (TlsGetServerRandom
, (Tls
, ServerRandom
));
3454 Gets the master key data used in the specified TLS connection.
3456 This function returns the TLS/SSL master key material currently used in
3457 the specified TLS connection.
3459 @param[in] Tls Pointer to the TLS object.
3460 @param[in,out] KeyMaterial Buffer to contain the returned key material.
3462 @retval EFI_SUCCESS Key material was returned successfully.
3463 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3464 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
3471 IN OUT UINT8
*KeyMaterial
3474 CALL_CRYPTO_SERVICE (TlsGetKeyMaterial
, (Tls
, KeyMaterial
), EFI_UNSUPPORTED
);
3478 Gets the CA Certificate from the cert store.
3480 This function returns the CA certificate for the chosen
3483 @param[in] Tls Pointer to the TLS object.
3484 @param[out] Data Pointer to the data buffer to receive the CA
3485 certificate data sent to the client.
3486 @param[in,out] DataSize The size of data buffer in bytes.
3488 @retval EFI_SUCCESS The operation succeeded.
3489 @retval EFI_UNSUPPORTED This function is not supported.
3490 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3495 TlsGetCaCertificate (
3498 IN OUT UINTN
*DataSize
3501 CALL_CRYPTO_SERVICE (TlsGetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3505 Gets the local public Certificate set in the specified TLS object.
3507 This function returns the local public certificate which was currently set
3508 in the specified TLS object.
3510 @param[in] Tls Pointer to the TLS object.
3511 @param[out] Data Pointer to the data buffer to receive the local
3513 @param[in,out] DataSize The size of data buffer in bytes.
3515 @retval EFI_SUCCESS The operation succeeded.
3516 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3517 @retval EFI_NOT_FOUND The certificate is not found.
3518 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3523 TlsGetHostPublicCert (
3526 IN OUT UINTN
*DataSize
3529 CALL_CRYPTO_SERVICE (TlsGetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3533 Gets the local private key set in the specified TLS object.
3535 This function returns the local private key data which was currently set
3536 in the specified TLS object.
3538 @param[in] Tls Pointer to the TLS object.
3539 @param[out] Data Pointer to the data buffer to receive the local
3541 @param[in,out] DataSize The size of data buffer in bytes.
3543 @retval EFI_SUCCESS The operation succeeded.
3544 @retval EFI_UNSUPPORTED This function is not supported.
3545 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3550 TlsGetHostPrivateKey (
3553 IN OUT UINTN
*DataSize
3556 CALL_CRYPTO_SERVICE (TlsGetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3560 Gets the CA-supplied certificate revocation list data set in the specified
3563 This function returns the CA-supplied certificate revocation list data which
3564 was currently set in the specified TLS object.
3566 @param[out] Data Pointer to the data buffer to receive the CRL data.
3567 @param[in,out] DataSize The size of data buffer in bytes.
3569 @retval EFI_SUCCESS The operation succeeded.
3570 @retval EFI_UNSUPPORTED This function is not supported.
3571 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3576 TlsGetCertRevocationList (
3578 IN OUT UINTN
*DataSize
3581 CALL_CRYPTO_SERVICE (TlsGetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);