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 - 2022, 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 Parallel hash function ParallelHash256, as defined in NIST's Special Publication 800-185,
875 published December 2016.
877 @param[in] Input Pointer to the input message (X).
878 @param[in] InputByteLen The number(>0) of input bytes provided for the input data.
879 @param[in] BlockSize The size of each block (B).
880 @param[out] Output Pointer to the output buffer.
881 @param[in] OutputByteLen The desired number of output bytes (L).
882 @param[in] Customization Pointer to the customization string (S).
883 @param[in] CustomByteLen The length of the customization string in bytes.
885 @retval TRUE ParallelHash256 digest computation succeeded.
886 @retval FALSE ParallelHash256 digest computation failed.
887 @retval FALSE This interface is not supported.
892 ParallelHash256HashAll (
893 IN CONST VOID
*Input
,
894 IN UINTN InputByteLen
,
897 IN UINTN OutputByteLen
,
898 IN CONST VOID
*Customization
,
899 IN UINTN CustomByteLen
902 CALL_CRYPTO_SERVICE (ParallelHash256HashAll
, (Input
, InputByteLen
, BlockSize
, Output
, OutputByteLen
, Customization
, CustomByteLen
), FALSE
);
906 Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.
908 @return The size, in bytes, of the context buffer required for SM3 hash operations.
917 CALL_CRYPTO_SERVICE (Sm3GetContextSize
, (), 0);
921 Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for
924 If Sm3Context is NULL, then return FALSE.
926 @param[out] Sm3Context Pointer to SM3 context being initialized.
928 @retval TRUE SM3 context initialization succeeded.
929 @retval FALSE SM3 context initialization failed.
938 CALL_CRYPTO_SERVICE (Sm3Init
, (Sm3Context
), FALSE
);
942 Makes a copy of an existing SM3 context.
944 If Sm3Context is NULL, then return FALSE.
945 If NewSm3Context is NULL, then return FALSE.
946 If this interface is not supported, then return FALSE.
948 @param[in] Sm3Context Pointer to SM3 context being copied.
949 @param[out] NewSm3Context Pointer to new SM3 context.
951 @retval TRUE SM3 context copy succeeded.
952 @retval FALSE SM3 context copy failed.
953 @retval FALSE This interface is not supported.
959 IN CONST VOID
*Sm3Context
,
960 OUT VOID
*NewSm3Context
963 CALL_CRYPTO_SERVICE (Sm3Duplicate
, (Sm3Context
, NewSm3Context
), FALSE
);
967 Digests the input data and updates SM3 context.
969 This function performs SM3 digest on a data buffer of the specified size.
970 It can be called multiple times to compute the digest of long or discontinuous data streams.
971 SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized
972 by Sm3Final(). Behavior with invalid context is undefined.
974 If Sm3Context is NULL, then return FALSE.
976 @param[in, out] Sm3Context Pointer to the SM3 context.
977 @param[in] Data Pointer to the buffer containing the data to be hashed.
978 @param[in] DataSize Size of Data buffer in bytes.
980 @retval TRUE SM3 data digest succeeded.
981 @retval FALSE SM3 data digest failed.
987 IN OUT VOID
*Sm3Context
,
992 CALL_CRYPTO_SERVICE (Sm3Update
, (Sm3Context
, Data
, DataSize
), FALSE
);
996 Completes computation of the SM3 digest value.
998 This function completes SM3 hash computation and retrieves the digest value into
999 the specified memory. After this function has been called, the SM3 context cannot
1001 SM3 context should be already correctly initialized by Sm3Init(), and should not be
1002 finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.
1004 If Sm3Context is NULL, then return FALSE.
1005 If HashValue is NULL, then return FALSE.
1007 @param[in, out] Sm3Context Pointer to the SM3 context.
1008 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
1011 @retval TRUE SM3 digest computation succeeded.
1012 @retval FALSE SM3 digest computation failed.
1018 IN OUT VOID
*Sm3Context
,
1019 OUT UINT8
*HashValue
1022 CALL_CRYPTO_SERVICE (Sm3Final
, (Sm3Context
, HashValue
), FALSE
);
1026 Computes the SM3 message digest of a input data buffer.
1028 This function performs the SM3 message digest of a given data buffer, and places
1029 the digest value into the specified memory.
1031 If this interface is not supported, then return FALSE.
1033 @param[in] Data Pointer to the buffer containing the data to be hashed.
1034 @param[in] DataSize Size of Data buffer in bytes.
1035 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
1038 @retval TRUE SM3 digest computation succeeded.
1039 @retval FALSE SM3 digest computation failed.
1040 @retval FALSE This interface is not supported.
1046 IN CONST VOID
*Data
,
1048 OUT UINT8
*HashValue
1051 CALL_CRYPTO_SERVICE (Sm3HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
1054 // =====================================================================================
1055 // MAC (Message Authentication Code) Primitive
1056 // =====================================================================================
1059 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
1061 @return Pointer to the HMAC_CTX context that has been initialized.
1062 If the allocations fails, HmacSha256New() returns NULL.
1071 CALL_CRYPTO_SERVICE (HmacSha256New
, (), NULL
);
1075 Release the specified HMAC_CTX context.
1077 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.
1083 IN VOID
*HmacSha256Ctx
1086 CALL_VOID_CRYPTO_SERVICE (HmacSha256Free
, (HmacSha256Ctx
));
1090 Set user-supplied key for subsequent use. It must be done before any
1091 calling to HmacSha256Update().
1093 If HmacSha256Context is NULL, then return FALSE.
1094 If this interface is not supported, then return FALSE.
1096 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.
1097 @param[in] Key Pointer to the user-supplied key.
1098 @param[in] KeySize Key size in bytes.
1100 @retval TRUE The Key is set successfully.
1101 @retval FALSE The Key is set unsuccessfully.
1102 @retval FALSE This interface is not supported.
1108 OUT VOID
*HmacSha256Context
,
1109 IN CONST UINT8
*Key
,
1113 CALL_CRYPTO_SERVICE (HmacSha256SetKey
, (HmacSha256Context
, Key
, KeySize
), FALSE
);
1117 Makes a copy of an existing HMAC-SHA256 context.
1119 If HmacSha256Context is NULL, then return FALSE.
1120 If NewHmacSha256Context is NULL, then return FALSE.
1121 If this interface is not supported, then return FALSE.
1123 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.
1124 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.
1126 @retval TRUE HMAC-SHA256 context copy succeeded.
1127 @retval FALSE HMAC-SHA256 context copy failed.
1128 @retval FALSE This interface is not supported.
1133 HmacSha256Duplicate (
1134 IN CONST VOID
*HmacSha256Context
,
1135 OUT VOID
*NewHmacSha256Context
1138 CALL_CRYPTO_SERVICE (HmacSha256Duplicate
, (HmacSha256Context
, NewHmacSha256Context
), FALSE
);
1142 Digests the input data and updates HMAC-SHA256 context.
1144 This function performs HMAC-SHA256 digest on a data buffer of the specified size.
1145 It can be called multiple times to compute the digest of long or discontinuous data streams.
1146 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1147 by HmacSha256Final(). Behavior with invalid context is undefined.
1149 If HmacSha256Context is NULL, then return FALSE.
1150 If this interface is not supported, then return FALSE.
1152 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1153 @param[in] Data Pointer to the buffer containing the data to be digested.
1154 @param[in] DataSize Size of Data buffer in bytes.
1156 @retval TRUE HMAC-SHA256 data digest succeeded.
1157 @retval FALSE HMAC-SHA256 data digest failed.
1158 @retval FALSE This interface is not supported.
1164 IN OUT VOID
*HmacSha256Context
,
1165 IN CONST VOID
*Data
,
1169 CALL_CRYPTO_SERVICE (HmacSha256Update
, (HmacSha256Context
, Data
, DataSize
), FALSE
);
1173 Completes computation of the HMAC-SHA256 digest value.
1175 This function completes HMAC-SHA256 hash computation and retrieves the digest value into
1176 the specified memory. After this function has been called, the HMAC-SHA256 context cannot
1178 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1179 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.
1181 If HmacSha256Context is NULL, then return FALSE.
1182 If HmacValue is NULL, then return FALSE.
1183 If this interface is not supported, then return FALSE.
1185 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1186 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
1189 @retval TRUE HMAC-SHA256 digest computation succeeded.
1190 @retval FALSE HMAC-SHA256 digest computation failed.
1191 @retval FALSE This interface is not supported.
1197 IN OUT VOID
*HmacSha256Context
,
1198 OUT UINT8
*HmacValue
1201 CALL_CRYPTO_SERVICE (HmacSha256Final
, (HmacSha256Context
, HmacValue
), FALSE
);
1204 // =====================================================================================
1205 // Symmetric Cryptography Primitive
1206 // =====================================================================================
1209 Retrieves the size, in bytes, of the context buffer required for AES operations.
1211 If this interface is not supported, then return zero.
1213 @return The size, in bytes, of the context buffer required for AES operations.
1214 @retval 0 This interface is not supported.
1223 CALL_CRYPTO_SERVICE (AesGetContextSize
, (), 0);
1227 Initializes user-supplied memory as AES context for subsequent use.
1229 This function initializes user-supplied memory pointed by AesContext as AES context.
1230 In addition, it sets up all AES key materials for subsequent encryption and decryption
1232 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1234 If AesContext is NULL, then return FALSE.
1235 If Key is NULL, then return FALSE.
1236 If KeyLength is not valid, then return FALSE.
1237 If this interface is not supported, then return FALSE.
1239 @param[out] AesContext Pointer to AES context being initialized.
1240 @param[in] Key Pointer to the user-supplied AES key.
1241 @param[in] KeyLength Length of AES key in bits.
1243 @retval TRUE AES context initialization succeeded.
1244 @retval FALSE AES context initialization failed.
1245 @retval FALSE This interface is not supported.
1251 OUT VOID
*AesContext
,
1252 IN CONST UINT8
*Key
,
1256 CALL_CRYPTO_SERVICE (AesInit
, (AesContext
, Key
, KeyLength
), FALSE
);
1260 Performs AES encryption on a data buffer of the specified size in CBC mode.
1262 This function performs AES encryption on data buffer pointed by Input, of specified
1263 size of InputSize, in CBC mode.
1264 InputSize must be multiple of block size (16 bytes). This function does not perform
1265 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1266 Initialization vector should be one block size (16 bytes).
1267 AesContext should be already correctly initialized by AesInit(). Behavior with
1268 invalid AES context is undefined.
1270 If AesContext is NULL, then return FALSE.
1271 If Input is NULL, then return FALSE.
1272 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1273 If Ivec is NULL, then return FALSE.
1274 If Output is NULL, then return FALSE.
1275 If this interface is not supported, then return FALSE.
1277 @param[in] AesContext Pointer to the AES context.
1278 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1279 @param[in] InputSize Size of the Input buffer in bytes.
1280 @param[in] Ivec Pointer to initialization vector.
1281 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1283 @retval TRUE AES encryption succeeded.
1284 @retval FALSE AES encryption failed.
1285 @retval FALSE This interface is not supported.
1291 IN VOID
*AesContext
,
1292 IN CONST UINT8
*Input
,
1294 IN CONST UINT8
*Ivec
,
1298 CALL_CRYPTO_SERVICE (AesCbcEncrypt
, (AesContext
, Input
, InputSize
, Ivec
, Output
), FALSE
);
1302 Performs AES decryption on a data buffer of the specified size in CBC mode.
1304 This function performs AES decryption on data buffer pointed by Input, of specified
1305 size of InputSize, in CBC mode.
1306 InputSize must be multiple of block size (16 bytes). This function does not perform
1307 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1308 Initialization vector should be one block size (16 bytes).
1309 AesContext should be already correctly initialized by AesInit(). Behavior with
1310 invalid AES context is undefined.
1312 If AesContext is NULL, then return FALSE.
1313 If Input is NULL, then return FALSE.
1314 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1315 If Ivec is NULL, then return FALSE.
1316 If Output is NULL, then return FALSE.
1317 If this interface is not supported, then return FALSE.
1319 @param[in] AesContext Pointer to the AES context.
1320 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1321 @param[in] InputSize Size of the Input buffer in bytes.
1322 @param[in] Ivec Pointer to initialization vector.
1323 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1325 @retval TRUE AES decryption succeeded.
1326 @retval FALSE AES decryption failed.
1327 @retval FALSE This interface is not supported.
1333 IN VOID
*AesContext
,
1334 IN CONST UINT8
*Input
,
1336 IN CONST UINT8
*Ivec
,
1340 CALL_CRYPTO_SERVICE (AesCbcDecrypt
, (AesContext
, Input
, InputSize
, Ivec
, Output
), FALSE
);
1343 // =====================================================================================
1344 // Asymmetric Cryptography Primitive
1345 // =====================================================================================
1348 Allocates and initializes one RSA context for subsequent use.
1350 @return Pointer to the RSA context that has been initialized.
1351 If the allocations fails, RsaNew() returns NULL.
1360 CALL_CRYPTO_SERVICE (RsaNew
, (), NULL
);
1364 Release the specified RSA context.
1366 If RsaContext is NULL, then return FALSE.
1368 @param[in] RsaContext Pointer to the RSA context to be released.
1377 CALL_VOID_CRYPTO_SERVICE (RsaFree
, (RsaContext
));
1381 Sets the tag-designated key component into the established RSA context.
1383 This function sets the tag-designated RSA key component into the established
1384 RSA context from the user-specified non-negative integer (octet string format
1385 represented in RSA PKCS#1).
1386 If BigNumber is NULL, then the specified key component in RSA context is cleared.
1388 If RsaContext is NULL, then return FALSE.
1390 @param[in, out] RsaContext Pointer to RSA context being set.
1391 @param[in] KeyTag Tag of RSA key component being set.
1392 @param[in] BigNumber Pointer to octet integer buffer.
1393 If NULL, then the specified key component in RSA
1395 @param[in] BnSize Size of big number buffer in bytes.
1396 If BigNumber is NULL, then it is ignored.
1398 @retval TRUE RSA key component was set successfully.
1399 @retval FALSE Invalid RSA key component tag.
1405 IN OUT VOID
*RsaContext
,
1406 IN RSA_KEY_TAG KeyTag
,
1407 IN CONST UINT8
*BigNumber
,
1411 CALL_CRYPTO_SERVICE (RsaSetKey
, (RsaContext
, KeyTag
, BigNumber
, BnSize
), FALSE
);
1415 Gets the tag-designated RSA key component from the established RSA context.
1417 This function retrieves the tag-designated RSA key component from the
1418 established RSA context as a non-negative integer (octet string format
1419 represented in RSA PKCS#1).
1420 If specified key component has not been set or has been cleared, then returned
1422 If the BigNumber buffer is too small to hold the contents of the key, FALSE
1423 is returned and BnSize is set to the required buffer size to obtain the key.
1425 If RsaContext is NULL, then return FALSE.
1426 If BnSize is NULL, then return FALSE.
1427 If BnSize is large enough but BigNumber is NULL, then return FALSE.
1428 If this interface is not supported, then return FALSE.
1430 @param[in, out] RsaContext Pointer to RSA context being set.
1431 @param[in] KeyTag Tag of RSA key component being set.
1432 @param[out] BigNumber Pointer to octet integer buffer.
1433 @param[in, out] BnSize On input, the size of big number buffer in bytes.
1434 On output, the size of data returned in big number buffer in bytes.
1436 @retval TRUE RSA key component was retrieved successfully.
1437 @retval FALSE Invalid RSA key component tag.
1438 @retval FALSE BnSize is too small.
1439 @retval FALSE This interface is not supported.
1445 IN OUT VOID
*RsaContext
,
1446 IN RSA_KEY_TAG KeyTag
,
1447 OUT UINT8
*BigNumber
,
1448 IN OUT UINTN
*BnSize
1451 CALL_CRYPTO_SERVICE (RsaGetKey
, (RsaContext
, KeyTag
, BigNumber
, BnSize
), FALSE
);
1455 Generates RSA key components.
1457 This function generates RSA key components. It takes RSA public exponent E and
1458 length in bits of RSA modulus N as input, and generates all key components.
1459 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
1461 Before this function can be invoked, pseudorandom number generator must be correctly
1462 initialized by RandomSeed().
1464 If RsaContext is NULL, then return FALSE.
1465 If this interface is not supported, then return FALSE.
1467 @param[in, out] RsaContext Pointer to RSA context being set.
1468 @param[in] ModulusLength Length of RSA modulus N in bits.
1469 @param[in] PublicExponent Pointer to RSA public exponent.
1470 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
1472 @retval TRUE RSA key component was generated successfully.
1473 @retval FALSE Invalid RSA key component tag.
1474 @retval FALSE This interface is not supported.
1480 IN OUT VOID
*RsaContext
,
1481 IN UINTN ModulusLength
,
1482 IN CONST UINT8
*PublicExponent
,
1483 IN UINTN PublicExponentSize
1486 CALL_CRYPTO_SERVICE (RsaGenerateKey
, (RsaContext
, ModulusLength
, PublicExponent
, PublicExponentSize
), FALSE
);
1490 Validates key components of RSA context.
1491 NOTE: This function performs integrity checks on all the RSA key material, so
1492 the RSA key structure must contain all the private key data.
1494 This function validates key components of RSA context in following aspects:
1495 - Whether p is a prime
1496 - Whether q is a prime
1498 - Whether d*e = 1 mod lcm(p-1,q-1)
1500 If RsaContext is NULL, then return FALSE.
1501 If this interface is not supported, then return FALSE.
1503 @param[in] RsaContext Pointer to RSA context to check.
1505 @retval TRUE RSA key components are valid.
1506 @retval FALSE RSA key components are not valid.
1507 @retval FALSE This interface is not supported.
1516 CALL_CRYPTO_SERVICE (RsaCheckKey
, (RsaContext
), FALSE
);
1520 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
1522 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
1524 If the Signature buffer is too small to hold the contents of signature, FALSE
1525 is returned and SigSize is set to the required buffer size to obtain the signature.
1527 If RsaContext is NULL, then return FALSE.
1528 If MessageHash is NULL, then return FALSE.
1529 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
1530 If SigSize is large enough but Signature is NULL, then return FALSE.
1531 If this interface is not supported, then return FALSE.
1533 @param[in] RsaContext Pointer to RSA context for signature generation.
1534 @param[in] MessageHash Pointer to octet message hash to be signed.
1535 @param[in] HashSize Size of the message hash in bytes.
1536 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
1537 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1538 On output, the size of data returned in Signature buffer in bytes.
1540 @retval TRUE Signature successfully generated in PKCS1-v1_5.
1541 @retval FALSE Signature generation failed.
1542 @retval FALSE SigSize is too small.
1543 @retval FALSE This interface is not supported.
1549 IN VOID
*RsaContext
,
1550 IN CONST UINT8
*MessageHash
,
1552 OUT UINT8
*Signature
,
1553 IN OUT UINTN
*SigSize
1556 CALL_CRYPTO_SERVICE (RsaPkcs1Sign
, (RsaContext
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
1560 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
1563 If RsaContext is NULL, then return FALSE.
1564 If MessageHash is NULL, then return FALSE.
1565 If Signature is NULL, then return FALSE.
1566 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
1568 @param[in] RsaContext Pointer to RSA context for signature verification.
1569 @param[in] MessageHash Pointer to octet message hash to be checked.
1570 @param[in] HashSize Size of the message hash in bytes.
1571 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
1572 @param[in] SigSize Size of signature in bytes.
1574 @retval TRUE Valid signature encoded in PKCS1-v1_5.
1575 @retval FALSE Invalid signature or invalid RSA context.
1581 IN VOID
*RsaContext
,
1582 IN CONST UINT8
*MessageHash
,
1584 IN CONST UINT8
*Signature
,
1588 CALL_CRYPTO_SERVICE (RsaPkcs1Verify
, (RsaContext
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
1592 Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
1593 Implementation determines salt length automatically from the signature encoding.
1594 Mask generation function is the same as the message digest algorithm.
1595 Salt length should be equal to digest length.
1597 @param[in] RsaContext Pointer to RSA context for signature verification.
1598 @param[in] Message Pointer to octet message to be verified.
1599 @param[in] MsgSize Size of the message in bytes.
1600 @param[in] Signature Pointer to RSASSA-PSS signature to be verified.
1601 @param[in] SigSize Size of signature in bytes.
1602 @param[in] DigestLen Length of digest for RSA operation.
1603 @param[in] SaltLen Salt length for PSS encoding.
1605 @retval TRUE Valid signature encoded in RSASSA-PSS.
1606 @retval FALSE Invalid signature or invalid RSA context.
1612 IN VOID
*RsaContext
,
1613 IN CONST UINT8
*Message
,
1615 IN CONST UINT8
*Signature
,
1617 IN UINT16 DigestLen
,
1621 CALL_CRYPTO_SERVICE (RsaPssVerify
, (RsaContext
, Message
, MsgSize
, Signature
, SigSize
, DigestLen
, SaltLen
), FALSE
);
1625 This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in
1627 Mask generation function is the same as the message digest algorithm.
1628 If the Signature buffer is too small to hold the contents of signature, FALSE
1629 is returned and SigSize is set to the required buffer size to obtain the signature.
1631 If RsaContext is NULL, then return FALSE.
1632 If Message is NULL, then return FALSE.
1633 If MsgSize is zero or > INT_MAX, then return FALSE.
1634 If DigestLen is NOT 32, 48 or 64, return FALSE.
1635 If SaltLen is not equal to DigestLen, then return FALSE.
1636 If SigSize is large enough but Signature is NULL, then return FALSE.
1637 If this interface is not supported, then return FALSE.
1639 @param[in] RsaContext Pointer to RSA context for signature generation.
1640 @param[in] Message Pointer to octet message to be signed.
1641 @param[in] MsgSize Size of the message in bytes.
1642 @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.
1643 @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.
1644 @param[out] Signature Pointer to buffer to receive RSA PSS signature.
1645 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1646 On output, the size of data returned in Signature buffer in bytes.
1648 @retval TRUE Signature successfully generated in RSASSA-PSS.
1649 @retval FALSE Signature generation failed.
1650 @retval FALSE SigSize is too small.
1651 @retval FALSE This interface is not supported.
1657 IN VOID
*RsaContext
,
1658 IN CONST UINT8
*Message
,
1660 IN UINT16 DigestLen
,
1662 OUT UINT8
*Signature
,
1663 IN OUT UINTN
*SigSize
1666 CALL_CRYPTO_SERVICE (RsaPssSign
, (RsaContext
, Message
, MsgSize
, DigestLen
, SaltLen
, Signature
, SigSize
), FALSE
);
1670 Retrieve the RSA Private Key from the password-protected PEM key data.
1672 If PemData is NULL, then return FALSE.
1673 If RsaContext is NULL, then return FALSE.
1674 If this interface is not supported, then return FALSE.
1676 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
1677 @param[in] PemSize Size of the PEM key data in bytes.
1678 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
1679 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1680 RSA private key component. Use RsaFree() function to free the
1683 @retval TRUE RSA Private Key was retrieved successfully.
1684 @retval FALSE Invalid PEM key data or incorrect password.
1685 @retval FALSE This interface is not supported.
1690 RsaGetPrivateKeyFromPem (
1691 IN CONST UINT8
*PemData
,
1693 IN CONST CHAR8
*Password
,
1694 OUT VOID
**RsaContext
1697 CALL_CRYPTO_SERVICE (RsaGetPrivateKeyFromPem
, (PemData
, PemSize
, Password
, RsaContext
), FALSE
);
1701 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
1703 If Cert is NULL, then return FALSE.
1704 If RsaContext is NULL, then return FALSE.
1705 If this interface is not supported, then return FALSE.
1707 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1708 @param[in] CertSize Size of the X509 certificate in bytes.
1709 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1710 RSA public key component. Use RsaFree() function to free the
1713 @retval TRUE RSA Public Key was retrieved successfully.
1714 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
1715 @retval FALSE This interface is not supported.
1720 RsaGetPublicKeyFromX509 (
1721 IN CONST UINT8
*Cert
,
1723 OUT VOID
**RsaContext
1726 CALL_CRYPTO_SERVICE (RsaGetPublicKeyFromX509
, (Cert
, CertSize
, RsaContext
), FALSE
);
1730 Retrieve the subject bytes from one X.509 certificate.
1732 If Cert is NULL, then return FALSE.
1733 If SubjectSize is NULL, then return FALSE.
1734 If this interface is not supported, then return FALSE.
1736 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1737 @param[in] CertSize Size of the X509 certificate in bytes.
1738 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
1739 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
1740 and the size of buffer returned CertSubject on output.
1742 @retval TRUE The certificate subject retrieved successfully.
1743 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
1744 The SubjectSize will be updated with the required size.
1745 @retval FALSE This interface is not supported.
1750 X509GetSubjectName (
1751 IN CONST UINT8
*Cert
,
1753 OUT UINT8
*CertSubject
,
1754 IN OUT UINTN
*SubjectSize
1757 CALL_CRYPTO_SERVICE (X509GetSubjectName
, (Cert
, CertSize
, CertSubject
, SubjectSize
), FALSE
);
1761 Retrieve the common name (CN) string from one X.509 certificate.
1763 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1764 @param[in] CertSize Size of the X509 certificate in bytes.
1765 @param[out] CommonName Buffer to contain the retrieved certificate common
1766 name string (UTF8). At most CommonNameSize bytes will be
1767 written and the string will be null terminated. May be
1768 NULL in order to determine the size buffer needed.
1769 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
1770 and the size of buffer returned CommonName on output.
1771 If CommonName is NULL then the amount of space needed
1772 in buffer (including the final null) is returned.
1774 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
1775 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
1776 If CommonNameSize is NULL.
1777 If CommonName is not NULL and *CommonNameSize is 0.
1778 If Certificate is invalid.
1779 @retval RETURN_NOT_FOUND If no CommonName entry exists.
1780 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
1781 (including the final null) is returned in the
1782 CommonNameSize parameter.
1783 @retval RETURN_UNSUPPORTED The operation is not supported.
1789 IN CONST UINT8
*Cert
,
1791 OUT CHAR8
*CommonName OPTIONAL
,
1792 IN OUT UINTN
*CommonNameSize
1795 CALL_CRYPTO_SERVICE (X509GetCommonName
, (Cert
, CertSize
, CommonName
, CommonNameSize
), RETURN_UNSUPPORTED
);
1799 Retrieve the organization name (O) string from one X.509 certificate.
1801 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1802 @param[in] CertSize Size of the X509 certificate in bytes.
1803 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
1804 name string. At most NameBufferSize bytes will be
1805 written and the string will be null terminated. May be
1806 NULL in order to determine the size buffer needed.
1807 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
1808 and the size of buffer returned Name on output.
1809 If NameBuffer is NULL then the amount of space needed
1810 in buffer (including the final null) is returned.
1812 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
1813 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
1814 If NameBufferSize is NULL.
1815 If NameBuffer is not NULL and *CommonNameSize is 0.
1816 If Certificate is invalid.
1817 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
1818 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
1819 (including the final null) is returned in the
1820 CommonNameSize parameter.
1821 @retval RETURN_UNSUPPORTED The operation is not supported.
1826 X509GetOrganizationName (
1827 IN CONST UINT8
*Cert
,
1829 OUT CHAR8
*NameBuffer OPTIONAL
,
1830 IN OUT UINTN
*NameBufferSize
1833 CALL_CRYPTO_SERVICE (X509GetOrganizationName
, (Cert
, CertSize
, NameBuffer
, NameBufferSize
), RETURN_UNSUPPORTED
);
1837 Verify one X509 certificate was issued by the trusted CA.
1839 If Cert is NULL, then return FALSE.
1840 If CACert is NULL, then return FALSE.
1841 If this interface is not supported, then return FALSE.
1843 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
1844 @param[in] CertSize Size of the X509 certificate in bytes.
1845 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
1846 @param[in] CACertSize Size of the CA Certificate in bytes.
1848 @retval TRUE The certificate was issued by the trusted CA.
1849 @retval FALSE Invalid certificate or the certificate was not issued by the given
1851 @retval FALSE This interface is not supported.
1857 IN CONST UINT8
*Cert
,
1859 IN CONST UINT8
*CACert
,
1863 CALL_CRYPTO_SERVICE (X509VerifyCert
, (Cert
, CertSize
, CACert
, CACertSize
), FALSE
);
1867 Construct a X509 object from DER-encoded certificate data.
1869 If Cert is NULL, then return FALSE.
1870 If SingleX509Cert is NULL, then return FALSE.
1871 If this interface is not supported, then return FALSE.
1873 @param[in] Cert Pointer to the DER-encoded certificate data.
1874 @param[in] CertSize The size of certificate data in bytes.
1875 @param[out] SingleX509Cert The generated X509 object.
1877 @retval TRUE The X509 object generation succeeded.
1878 @retval FALSE The operation failed.
1879 @retval FALSE This interface is not supported.
1884 X509ConstructCertificate (
1885 IN CONST UINT8
*Cert
,
1887 OUT UINT8
**SingleX509Cert
1890 CALL_CRYPTO_SERVICE (X509ConstructCertificate
, (Cert
, CertSize
, SingleX509Cert
), FALSE
);
1894 Construct a X509 stack object from a list of DER-encoded certificate data.
1896 If X509Stack is NULL, then return FALSE.
1897 If this interface is not supported, then return FALSE.
1899 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
1900 On output, pointer to the X509 stack object with new
1901 inserted X509 certificate.
1902 @param[in] Args VA_LIST marker for the variable argument list.
1903 ... A list of DER-encoded single certificate data followed
1904 by certificate size. A NULL terminates the list. The
1905 pairs are the arguments to X509ConstructCertificate().
1907 @retval TRUE The X509 stack construction succeeded.
1908 @retval FALSE The construction operation failed.
1909 @retval FALSE This interface is not supported.
1914 X509ConstructCertificateStack (
1915 IN OUT UINT8
**X509Stack
,
1922 VA_START (Args
, X509Stack
);
1923 Result
= X509ConstructCertificateStackV (X509Stack
, Args
);
1929 Construct a X509 stack object from a list of DER-encoded certificate data.
1931 If X509Stack is NULL, then return FALSE.
1932 If this interface is not supported, then return FALSE.
1934 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
1935 On output, pointer to the X509 stack object with new
1936 inserted X509 certificate.
1937 @param[in] Args VA_LIST marker for the variable argument list.
1938 A list of DER-encoded single certificate data followed
1939 by certificate size. A NULL terminates the list. The
1940 pairs are the arguments to X509ConstructCertificate().
1942 @retval TRUE The X509 stack construction succeeded.
1943 @retval FALSE The construction operation failed.
1944 @retval FALSE This interface is not supported.
1949 X509ConstructCertificateStackV (
1950 IN OUT UINT8
**X509Stack
,
1954 CALL_CRYPTO_SERVICE (X509ConstructCertificateStackV
, (X509Stack
, Args
), FALSE
);
1958 Release the specified X509 object.
1960 If the interface is not supported, then ASSERT().
1962 @param[in] X509Cert Pointer to the X509 object to be released.
1971 CALL_VOID_CRYPTO_SERVICE (X509Free
, (X509Cert
));
1975 Release the specified X509 stack object.
1977 If the interface is not supported, then ASSERT().
1979 @param[in] X509Stack Pointer to the X509 stack object to be released.
1988 CALL_VOID_CRYPTO_SERVICE (X509StackFree
, (X509Stack
));
1992 Retrieve the TBSCertificate from one given X.509 certificate.
1994 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
1995 @param[in] CertSize Size of the X509 certificate in bytes.
1996 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
1997 @param[out] TBSCertSize Size of the TBS certificate in bytes.
1999 If Cert is NULL, then return FALSE.
2000 If TBSCert is NULL, then return FALSE.
2001 If TBSCertSize is NULL, then return FALSE.
2002 If this interface is not supported, then return FALSE.
2004 @retval TRUE The TBSCertificate was retrieved successfully.
2005 @retval FALSE Invalid X.509 certificate.
2011 IN CONST UINT8
*Cert
,
2013 OUT UINT8
**TBSCert
,
2014 OUT UINTN
*TBSCertSize
2017 CALL_CRYPTO_SERVICE (X509GetTBSCert
, (Cert
, CertSize
, TBSCert
, TBSCertSize
), FALSE
);
2021 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2022 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2024 If Password or Salt or OutKey is NULL, then return FALSE.
2025 If the hash algorithm could not be determined, then return FALSE.
2026 If this interface is not supported, then return FALSE.
2028 @param[in] PasswordLength Length of input password in bytes.
2029 @param[in] Password Pointer to the array for the password.
2030 @param[in] SaltLength Size of the Salt in bytes.
2031 @param[in] Salt Pointer to the Salt.
2032 @param[in] IterationCount Number of iterations to perform. Its value should be
2033 greater than or equal to 1.
2034 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2035 NOTE: DigestSize will be used to determine the hash algorithm.
2036 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2037 @param[in] KeyLength Size of the derived key buffer in bytes.
2038 @param[out] OutKey Pointer to the output derived key buffer.
2040 @retval TRUE A key was derived successfully.
2041 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2042 @retval FALSE The hash algorithm could not be determined from the digest size.
2043 @retval FALSE The key derivation operation failed.
2044 @retval FALSE This interface is not supported.
2050 IN UINTN PasswordLength
,
2051 IN CONST CHAR8
*Password
,
2052 IN UINTN SaltLength
,
2053 IN CONST UINT8
*Salt
,
2054 IN UINTN IterationCount
,
2055 IN UINTN DigestSize
,
2060 CALL_CRYPTO_SERVICE (Pkcs5HashPassword
, (PasswordLength
, Password
, SaltLength
, Salt
, IterationCount
, DigestSize
, KeyLength
, OutKey
), FALSE
);
2064 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2065 encrypted message in a newly allocated buffer.
2067 Things that can cause a failure include:
2068 - X509 key size does not match any known key size.
2069 - Fail to parse X509 certificate.
2070 - Fail to allocate an intermediate buffer.
2071 - Null pointer provided for a non-optional parameter.
2072 - Data size is too large for the provided key size (max size is a function of key size
2073 and hash digest size).
2075 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2076 will be used to encrypt the data.
2077 @param[in] PublicKeySize Size of the X509 cert buffer.
2078 @param[in] InData Data to be encrypted.
2079 @param[in] InDataSize Size of the data buffer.
2080 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2081 to be used when initializing the PRNG. NULL otherwise.
2082 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2084 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2086 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2088 @retval TRUE Encryption was successful.
2089 @retval FALSE Encryption failed.
2095 IN CONST UINT8
*PublicKey
,
2096 IN UINTN PublicKeySize
,
2098 IN UINTN InDataSize
,
2099 IN CONST UINT8
*PrngSeed OPTIONAL
,
2100 IN UINTN PrngSeedSize OPTIONAL
,
2101 OUT UINT8
**EncryptedData
,
2102 OUT UINTN
*EncryptedDataSize
2105 CALL_CRYPTO_SERVICE (Pkcs1v2Encrypt
, (PublicKey
, PublicKeySize
, InData
, InDataSize
, PrngSeed
, PrngSeedSize
, EncryptedData
, EncryptedDataSize
), FALSE
);
2109 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2110 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2111 in a ContentInfo structure.
2113 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2114 return FALSE. If P7Length overflow, then return FALSE.
2115 If this interface is not supported, then return FALSE.
2117 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2118 @param[in] P7Length Length of the PKCS#7 message in bytes.
2119 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2120 It's caller's responsibility to free the buffer with
2122 This data structure is EFI_CERT_STACK type.
2123 @param[out] StackLength Length of signer's certificates in bytes.
2124 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2125 It's caller's responsibility to free the buffer with
2127 @param[out] CertLength Length of the trusted certificate in bytes.
2129 @retval TRUE The operation is finished successfully.
2130 @retval FALSE Error occurs during the operation.
2131 @retval FALSE This interface is not supported.
2137 IN CONST UINT8
*P7Data
,
2139 OUT UINT8
**CertStack
,
2140 OUT UINTN
*StackLength
,
2141 OUT UINT8
**TrustedCert
,
2142 OUT UINTN
*CertLength
2145 CALL_CRYPTO_SERVICE (Pkcs7GetSigners
, (P7Data
, P7Length
, CertStack
, StackLength
, TrustedCert
, CertLength
), FALSE
);
2149 Wrap function to use free() to free allocated memory for certificates.
2151 If this interface is not supported, then ASSERT().
2153 @param[in] Certs Pointer to the certificates to be freed.
2162 CALL_VOID_CRYPTO_SERVICE (Pkcs7FreeSigners
, (Certs
));
2166 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2167 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2168 unchained to the signer's certificates.
2169 The input signed data could be wrapped in a ContentInfo structure.
2171 @param[in] P7Data Pointer to the PKCS#7 message.
2172 @param[in] P7Length Length of the PKCS#7 message in bytes.
2173 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2174 certificate. It's caller's responsibility to free the buffer
2175 with Pkcs7FreeSigners().
2176 This data structure is EFI_CERT_STACK type.
2177 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2178 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2179 responsibility to free the buffer with Pkcs7FreeSigners().
2180 This data structure is EFI_CERT_STACK type.
2181 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2183 @retval TRUE The operation is finished successfully.
2184 @retval FALSE Error occurs during the operation.
2189 Pkcs7GetCertificatesList (
2190 IN CONST UINT8
*P7Data
,
2192 OUT UINT8
**SignerChainCerts
,
2193 OUT UINTN
*ChainLength
,
2194 OUT UINT8
**UnchainCerts
,
2195 OUT UINTN
*UnchainLength
2198 CALL_CRYPTO_SERVICE (Pkcs7GetCertificatesList
, (P7Data
, P7Length
, SignerChainCerts
, ChainLength
, UnchainCerts
, UnchainLength
), FALSE
);
2202 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2203 Syntax Standard, version 1.5". This interface is only intended to be used for
2204 application to perform PKCS#7 functionality validation.
2206 If this interface is not supported, then return FALSE.
2208 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2210 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2211 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2213 @param[in] InData Pointer to the content to be signed.
2214 @param[in] InDataSize Size of InData in bytes.
2215 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2216 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2217 include in the PKCS#7 signedData (e.g. any intermediate
2219 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2220 responsibility to free the buffer with FreePool().
2221 @param[out] SignedDataSize Size of SignedData in bytes.
2223 @retval TRUE PKCS#7 data signing succeeded.
2224 @retval FALSE PKCS#7 data signing failed.
2225 @retval FALSE This interface is not supported.
2231 IN CONST UINT8
*PrivateKey
,
2232 IN UINTN PrivateKeySize
,
2233 IN CONST UINT8
*KeyPassword
,
2235 IN UINTN InDataSize
,
2237 IN UINT8
*OtherCerts OPTIONAL
,
2238 OUT UINT8
**SignedData
,
2239 OUT UINTN
*SignedDataSize
2242 CALL_CRYPTO_SERVICE (Pkcs7Sign
, (PrivateKey
, PrivateKeySize
, KeyPassword
, InData
, InDataSize
, SignCert
, OtherCerts
, SignedData
, SignedDataSize
), FALSE
);
2246 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2247 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2248 in a ContentInfo structure.
2250 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2251 If P7Length, CertLength or DataLength overflow, then return FALSE.
2252 If this interface is not supported, then return FALSE.
2254 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2255 @param[in] P7Length Length of the PKCS#7 message in bytes.
2256 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2257 is used for certificate chain verification.
2258 @param[in] CertLength Length of the trusted certificate in bytes.
2259 @param[in] InData Pointer to the content to be verified.
2260 @param[in] DataLength Length of InData in bytes.
2262 @retval TRUE The specified PKCS#7 signed data is valid.
2263 @retval FALSE Invalid PKCS#7 signed data.
2264 @retval FALSE This interface is not supported.
2270 IN CONST UINT8
*P7Data
,
2272 IN CONST UINT8
*TrustedCert
,
2273 IN UINTN CertLength
,
2274 IN CONST UINT8
*InData
,
2278 CALL_CRYPTO_SERVICE (Pkcs7Verify
, (P7Data
, P7Length
, TrustedCert
, CertLength
, InData
, DataLength
), FALSE
);
2282 This function receives a PKCS7 formatted signature, and then verifies that
2283 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
2284 leaf signing certificate.
2285 Note that this function does not validate the certificate chain.
2287 Applications for custom EKU's are quite flexible. For example, a policy EKU
2288 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
2289 certificate issued might also contain this EKU, thus constraining the
2290 sub-ordinate certificate. Other applications might allow a certificate
2291 embedded in a device to specify that other Object Identifiers (OIDs) are
2292 present which contains binary data specifying custom capabilities that
2293 the device is able to do.
2295 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
2296 containing the content block with both the signature,
2297 the signer's certificate, and any necessary intermediate
2299 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
2300 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
2301 required EKUs that must be present in the signature.
2302 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
2303 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
2304 must be present in the leaf signer. If it is
2305 FALSE, then we will succeed if we find any
2306 of the specified EKU's.
2308 @retval EFI_SUCCESS The required EKUs were found in the signature.
2309 @retval EFI_INVALID_PARAMETER A parameter was invalid.
2310 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
2315 VerifyEKUsInPkcs7Signature (
2316 IN CONST UINT8
*Pkcs7Signature
,
2317 IN CONST UINT32 SignatureSize
,
2318 IN CONST CHAR8
*RequiredEKUs
[],
2319 IN CONST UINT32 RequiredEKUsSize
,
2320 IN BOOLEAN RequireAllPresent
2323 CALL_CRYPTO_SERVICE (VerifyEKUsInPkcs7Signature
, (Pkcs7Signature
, SignatureSize
, RequiredEKUs
, RequiredEKUsSize
, RequireAllPresent
), FALSE
);
2327 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2328 data could be wrapped in a ContentInfo structure.
2330 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2331 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2333 Caution: This function may receive untrusted input. So this function will do
2334 basic check for PKCS#7 data structure.
2336 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2337 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2338 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2339 It's caller's responsibility to free the buffer with FreePool().
2340 @param[out] ContentSize The size of the extracted content in bytes.
2342 @retval TRUE The P7Data was correctly formatted for processing.
2343 @retval FALSE The P7Data was not correctly formatted for processing.
2348 Pkcs7GetAttachedContent (
2349 IN CONST UINT8
*P7Data
,
2352 OUT UINTN
*ContentSize
2355 CALL_CRYPTO_SERVICE (Pkcs7GetAttachedContent
, (P7Data
, P7Length
, Content
, ContentSize
), FALSE
);
2359 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2360 Authenticode Portable Executable Signature Format".
2362 If AuthData is NULL, then return FALSE.
2363 If ImageHash is NULL, then return FALSE.
2364 If this interface is not supported, then return FALSE.
2366 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2367 PE/COFF image to be verified.
2368 @param[in] DataSize Size of the Authenticode Signature in bytes.
2369 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2370 is used for certificate chain verification.
2371 @param[in] CertSize Size of the trusted certificate in bytes.
2372 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2373 for calculating the image hash value is described in Authenticode
2375 @param[in] HashSize Size of Image hash value in bytes.
2377 @retval TRUE The specified Authenticode Signature is valid.
2378 @retval FALSE Invalid Authenticode Signature.
2379 @retval FALSE This interface is not supported.
2384 AuthenticodeVerify (
2385 IN CONST UINT8
*AuthData
,
2387 IN CONST UINT8
*TrustedCert
,
2389 IN CONST UINT8
*ImageHash
,
2393 CALL_CRYPTO_SERVICE (AuthenticodeVerify
, (AuthData
, DataSize
, TrustedCert
, CertSize
, ImageHash
, HashSize
), FALSE
);
2397 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2400 If AuthData is NULL, then return FALSE.
2401 If this interface is not supported, then return FALSE.
2403 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2404 PE/COFF image to be verified.
2405 @param[in] DataSize Size of the Authenticode Signature in bytes.
2406 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2407 is used for TSA certificate chain verification.
2408 @param[in] CertSize Size of the trusted certificate in bytes.
2409 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2412 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2413 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2418 ImageTimestampVerify (
2419 IN CONST UINT8
*AuthData
,
2421 IN CONST UINT8
*TsaCert
,
2423 OUT EFI_TIME
*SigningTime
2426 CALL_CRYPTO_SERVICE (ImageTimestampVerify
, (AuthData
, DataSize
, TsaCert
, CertSize
, SigningTime
), FALSE
);
2429 // =====================================================================================
2430 // DH Key Exchange Primitive
2431 // =====================================================================================
2434 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
2436 @return Pointer to the Diffie-Hellman Context that has been initialized.
2437 If the allocations fails, DhNew() returns NULL.
2438 If the interface is not supported, DhNew() returns NULL.
2447 CALL_CRYPTO_SERVICE (DhNew
, (), NULL
);
2451 Release the specified DH context.
2453 If the interface is not supported, then ASSERT().
2455 @param[in] DhContext Pointer to the DH context to be released.
2464 CALL_VOID_CRYPTO_SERVICE (DhFree
, (DhContext
));
2468 Generates DH parameter.
2470 Given generator g, and length of prime number p in bits, this function generates p,
2471 and sets DH context according to value of g and p.
2473 Before this function can be invoked, pseudorandom number generator must be correctly
2474 initialized by RandomSeed().
2476 If DhContext is NULL, then return FALSE.
2477 If Prime is NULL, then return FALSE.
2478 If this interface is not supported, then return FALSE.
2480 @param[in, out] DhContext Pointer to the DH context.
2481 @param[in] Generator Value of generator.
2482 @param[in] PrimeLength Length in bits of prime to be generated.
2483 @param[out] Prime Pointer to the buffer to receive the generated prime number.
2485 @retval TRUE DH parameter generation succeeded.
2486 @retval FALSE Value of Generator is not supported.
2487 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
2488 @retval FALSE This interface is not supported.
2493 DhGenerateParameter (
2494 IN OUT VOID
*DhContext
,
2496 IN UINTN PrimeLength
,
2500 CALL_CRYPTO_SERVICE (DhGenerateParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
2504 Sets generator and prime parameters for DH.
2506 Given generator g, and prime number p, this function and sets DH
2507 context accordingly.
2509 If DhContext is NULL, then return FALSE.
2510 If Prime is NULL, then return FALSE.
2511 If this interface is not supported, then return FALSE.
2513 @param[in, out] DhContext Pointer to the DH context.
2514 @param[in] Generator Value of generator.
2515 @param[in] PrimeLength Length in bits of prime to be generated.
2516 @param[in] Prime Pointer to the prime number.
2518 @retval TRUE DH parameter setting succeeded.
2519 @retval FALSE Value of Generator is not supported.
2520 @retval FALSE Value of Generator is not suitable for the Prime.
2521 @retval FALSE Value of Prime is not a prime number.
2522 @retval FALSE Value of Prime is not a safe prime number.
2523 @retval FALSE This interface is not supported.
2529 IN OUT VOID
*DhContext
,
2531 IN UINTN PrimeLength
,
2532 IN CONST UINT8
*Prime
2535 CALL_CRYPTO_SERVICE (DhSetParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
2539 Generates DH public key.
2541 This function generates random secret exponent, and computes the public key, which is
2542 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
2543 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
2544 PublicKeySize is set to the required buffer size to obtain the public key.
2546 If DhContext is NULL, then return FALSE.
2547 If PublicKeySize is NULL, then return FALSE.
2548 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
2549 If this interface is not supported, then return FALSE.
2551 @param[in, out] DhContext Pointer to the DH context.
2552 @param[out] PublicKey Pointer to the buffer to receive generated public key.
2553 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
2554 On output, the size of data returned in PublicKey buffer in bytes.
2556 @retval TRUE DH public key generation succeeded.
2557 @retval FALSE DH public key generation failed.
2558 @retval FALSE PublicKeySize is not large enough.
2559 @retval FALSE This interface is not supported.
2565 IN OUT VOID
*DhContext
,
2566 OUT UINT8
*PublicKey
,
2567 IN OUT UINTN
*PublicKeySize
2570 CALL_CRYPTO_SERVICE (DhGenerateKey
, (DhContext
, PublicKey
, PublicKeySize
), FALSE
);
2574 Computes exchanged common key.
2576 Given peer's public key, this function computes the exchanged common key, based on its own
2577 context including value of prime modulus and random secret exponent.
2579 If DhContext is NULL, then return FALSE.
2580 If PeerPublicKey is NULL, then return FALSE.
2581 If KeySize is NULL, then return FALSE.
2582 If Key is NULL, then return FALSE.
2583 If KeySize is not large enough, then return FALSE.
2584 If this interface is not supported, then return FALSE.
2586 @param[in, out] DhContext Pointer to the DH context.
2587 @param[in] PeerPublicKey Pointer to the peer's public key.
2588 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
2589 @param[out] Key Pointer to the buffer to receive generated key.
2590 @param[in, out] KeySize On input, the size of Key buffer in bytes.
2591 On output, the size of data returned in Key buffer in bytes.
2593 @retval TRUE DH exchanged key generation succeeded.
2594 @retval FALSE DH exchanged key generation failed.
2595 @retval FALSE KeySize is not large enough.
2596 @retval FALSE This interface is not supported.
2602 IN OUT VOID
*DhContext
,
2603 IN CONST UINT8
*PeerPublicKey
,
2604 IN UINTN PeerPublicKeySize
,
2606 IN OUT UINTN
*KeySize
2609 CALL_CRYPTO_SERVICE (DhComputeKey
, (DhContext
, PeerPublicKey
, PeerPublicKeySize
, Key
, KeySize
), FALSE
);
2612 // =====================================================================================
2613 // Pseudo-Random Generation Primitive
2614 // =====================================================================================
2617 Sets up the seed value for the pseudorandom number generator.
2619 This function sets up the seed value for the pseudorandom number generator.
2620 If Seed is not NULL, then the seed passed in is used.
2621 If Seed is NULL, then default seed is used.
2622 If this interface is not supported, then return FALSE.
2624 @param[in] Seed Pointer to seed value.
2625 If NULL, default seed is used.
2626 @param[in] SeedSize Size of seed value.
2627 If Seed is NULL, this parameter is ignored.
2629 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
2630 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
2631 @retval FALSE This interface is not supported.
2637 IN CONST UINT8
*Seed OPTIONAL
,
2641 CALL_CRYPTO_SERVICE (RandomSeed
, (Seed
, SeedSize
), FALSE
);
2645 Generates a pseudorandom byte stream of the specified size.
2647 If Output is NULL, then return FALSE.
2648 If this interface is not supported, then return FALSE.
2650 @param[out] Output Pointer to buffer to receive random value.
2651 @param[in] Size Size of random bytes to generate.
2653 @retval TRUE Pseudorandom byte stream generated successfully.
2654 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
2655 @retval FALSE This interface is not supported.
2665 CALL_CRYPTO_SERVICE (RandomBytes
, (Output
, Size
), FALSE
);
2668 // =====================================================================================
2669 // Key Derivation Function Primitive
2670 // =====================================================================================
2673 Derive key data using HMAC-SHA256 based KDF.
2675 @param[in] Key Pointer to the user-supplied key.
2676 @param[in] KeySize Key size in bytes.
2677 @param[in] Salt Pointer to the salt(non-secret) value.
2678 @param[in] SaltSize Salt size in bytes.
2679 @param[in] Info Pointer to the application specific info.
2680 @param[in] InfoSize Info size in bytes.
2681 @param[out] Out Pointer to buffer to receive hkdf value.
2682 @param[in] OutSize Size of hkdf bytes to generate.
2684 @retval TRUE Hkdf generated successfully.
2685 @retval FALSE Hkdf generation failed.
2690 HkdfSha256ExtractAndExpand (
2691 IN CONST UINT8
*Key
,
2693 IN CONST UINT8
*Salt
,
2695 IN CONST UINT8
*Info
,
2701 CALL_CRYPTO_SERVICE (HkdfSha256ExtractAndExpand
, (Key
, KeySize
, Salt
, SaltSize
, Info
, InfoSize
, Out
, OutSize
), FALSE
);
2705 Initializes the OpenSSL library.
2707 This function registers ciphers and digests used directly and indirectly
2708 by SSL/TLS, and initializes the readable error messages.
2709 This function must be called before any other action takes places.
2711 @retval TRUE The OpenSSL library has been initialized.
2712 @retval FALSE Failed to initialize the OpenSSL library.
2721 CALL_CRYPTO_SERVICE (TlsInitialize
, (), FALSE
);
2725 Free an allocated SSL_CTX object.
2727 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
2736 CALL_VOID_CRYPTO_SERVICE (TlsCtxFree
, (TlsCtx
));
2740 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
2743 @param[in] MajorVer Major Version of TLS/SSL Protocol.
2744 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
2746 @return Pointer to an allocated SSL_CTX object.
2747 If the creation failed, TlsCtxNew() returns NULL.
2757 CALL_CRYPTO_SERVICE (TlsCtxNew
, (MajorVer
, MinorVer
), NULL
);
2761 Free an allocated TLS object.
2763 This function removes the TLS object pointed to by Tls and frees up the
2764 allocated memory. If Tls is NULL, nothing is done.
2766 @param[in] Tls Pointer to the TLS object to be freed.
2775 CALL_VOID_CRYPTO_SERVICE (TlsFree
, (Tls
));
2779 Create a new TLS object for a connection.
2781 This function creates a new TLS object for a connection. The new object
2782 inherits the setting of the underlying context TlsCtx: connection method,
2783 options, verification setting.
2785 @param[in] TlsCtx Pointer to the SSL_CTX object.
2787 @return Pointer to an allocated SSL object.
2788 If the creation failed, TlsNew() returns NULL.
2797 CALL_CRYPTO_SERVICE (TlsNew
, (TlsCtx
), NULL
);
2801 Checks if the TLS handshake was done.
2803 This function will check if the specified TLS handshake was done.
2805 @param[in] Tls Pointer to the TLS object for handshake state checking.
2807 @retval TRUE The TLS handshake was done.
2808 @retval FALSE The TLS handshake was not done.
2817 CALL_CRYPTO_SERVICE (TlsInHandshake
, (Tls
), FALSE
);
2821 Perform a TLS/SSL handshake.
2823 This function will perform a TLS/SSL handshake.
2825 @param[in] Tls Pointer to the TLS object for handshake operation.
2826 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
2827 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
2829 @param[out] BufferOut Pointer to the buffer to hold the built packet.
2830 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
2831 the buffer size provided by the caller. On output, it
2832 is the buffer size in fact needed to contain the
2835 @retval EFI_SUCCESS The required TLS packet is built successfully.
2836 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2838 BufferIn is NULL but BufferInSize is NOT 0.
2839 BufferInSize is 0 but BufferIn is NOT NULL.
2840 BufferOutSize is NULL.
2841 BufferOut is NULL if *BufferOutSize is not zero.
2842 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
2843 @retval EFI_ABORTED Something wrong during handshake.
2850 IN UINT8
*BufferIn OPTIONAL
,
2851 IN UINTN BufferInSize OPTIONAL
,
2852 OUT UINT8
*BufferOut OPTIONAL
,
2853 IN OUT UINTN
*BufferOutSize
2856 CALL_CRYPTO_SERVICE (TlsDoHandshake
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
2860 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
2861 TLS session has errors and the response packet needs to be Alert message based on error type.
2863 @param[in] Tls Pointer to the TLS object for state checking.
2864 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
2865 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
2867 @param[out] BufferOut Pointer to the buffer to hold the built packet.
2868 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
2869 the buffer size provided by the caller. On output, it
2870 is the buffer size in fact needed to contain the
2873 @retval EFI_SUCCESS The required TLS packet is built successfully.
2874 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2876 BufferIn is NULL but BufferInSize is NOT 0.
2877 BufferInSize is 0 but BufferIn is NOT NULL.
2878 BufferOutSize is NULL.
2879 BufferOut is NULL if *BufferOutSize is not zero.
2880 @retval EFI_ABORTED An error occurred.
2881 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
2888 IN UINT8
*BufferIn OPTIONAL
,
2889 IN UINTN BufferInSize OPTIONAL
,
2890 OUT UINT8
*BufferOut OPTIONAL
,
2891 IN OUT UINTN
*BufferOutSize
2894 CALL_CRYPTO_SERVICE (TlsHandleAlert
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
2898 Build the CloseNotify packet.
2900 @param[in] Tls Pointer to the TLS object for state checking.
2901 @param[in, out] Buffer Pointer to the buffer to hold the built packet.
2902 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
2903 the buffer size provided by the caller. On output, it
2904 is the buffer size in fact needed to contain the
2907 @retval EFI_SUCCESS The required TLS packet is built successfully.
2908 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2911 Buffer is NULL if *BufferSize is not zero.
2912 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
2919 IN OUT UINT8
*Buffer
,
2920 IN OUT UINTN
*BufferSize
2923 CALL_CRYPTO_SERVICE (TlsCloseNotify
, (Tls
, Buffer
, BufferSize
), EFI_UNSUPPORTED
);
2927 Attempts to read bytes from one TLS object and places the data in Buffer.
2929 This function will attempt to read BufferSize bytes from the TLS object
2930 and places the data in Buffer.
2932 @param[in] Tls Pointer to the TLS object.
2933 @param[in,out] Buffer Pointer to the buffer to store the data.
2934 @param[in] BufferSize The size of Buffer in bytes.
2936 @retval >0 The amount of data successfully read from the TLS object.
2937 @retval <=0 No data was successfully read.
2944 IN OUT VOID
*Buffer
,
2948 CALL_CRYPTO_SERVICE (TlsCtrlTrafficOut
, (Tls
, Buffer
, BufferSize
), 0);
2952 Attempts to write data from the buffer to TLS object.
2954 This function will attempt to write BufferSize bytes data from the Buffer
2957 @param[in] Tls Pointer to the TLS object.
2958 @param[in] Buffer Pointer to the data buffer.
2959 @param[in] BufferSize The size of Buffer in bytes.
2961 @retval >0 The amount of data successfully written to the TLS object.
2962 @retval <=0 No data was successfully written.
2973 CALL_CRYPTO_SERVICE (TlsCtrlTrafficIn
, (Tls
, Buffer
, BufferSize
), 0);
2977 Attempts to read bytes from the specified TLS connection into the buffer.
2979 This function tries to read BufferSize bytes data from the specified TLS
2980 connection into the Buffer.
2982 @param[in] Tls Pointer to the TLS connection for data reading.
2983 @param[in,out] Buffer Pointer to the data buffer.
2984 @param[in] BufferSize The size of Buffer in bytes.
2986 @retval >0 The read operation was successful, and return value is the
2987 number of bytes actually read from the TLS connection.
2988 @retval <=0 The read operation was not successful.
2995 IN OUT VOID
*Buffer
,
2999 CALL_CRYPTO_SERVICE (TlsRead
, (Tls
, Buffer
, BufferSize
), 0);
3003 Attempts to write data to a TLS connection.
3005 This function tries to write BufferSize bytes data from the Buffer into the
3006 specified TLS connection.
3008 @param[in] Tls Pointer to the TLS connection for data writing.
3009 @param[in] Buffer Pointer to the data buffer.
3010 @param[in] BufferSize The size of Buffer in bytes.
3012 @retval >0 The write operation was successful, and return value is the
3013 number of bytes actually written to the TLS connection.
3014 @retval <=0 The write operation was not successful.
3025 CALL_CRYPTO_SERVICE (TlsWrite
, (Tls
, Buffer
, BufferSize
), 0);
3029 Set a new TLS/SSL method for a particular TLS object.
3031 This function sets a new TLS/SSL method for a particular TLS object.
3033 @param[in] Tls Pointer to a TLS object.
3034 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3035 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3037 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
3038 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3039 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
3050 CALL_CRYPTO_SERVICE (TlsSetVersion
, (Tls
, MajorVer
, MinorVer
), EFI_UNSUPPORTED
);
3054 Set TLS object to work in client or server mode.
3056 This function prepares a TLS object to work in client or server mode.
3058 @param[in] Tls Pointer to a TLS object.
3059 @param[in] IsServer Work in server mode.
3061 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
3062 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3063 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
3068 TlsSetConnectionEnd (
3073 CALL_CRYPTO_SERVICE (TlsSetConnectionEnd
, (Tls
, IsServer
), EFI_UNSUPPORTED
);
3077 Set the ciphers list to be used by the TLS object.
3079 This function sets the ciphers for use by a specified TLS object.
3081 @param[in] Tls Pointer to a TLS object.
3082 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
3083 cipher identifier comes from the TLS Cipher Suite
3084 Registry of the IANA, interpreting Byte1 and Byte2
3085 in network (big endian) byte order.
3086 @param[in] CipherNum The number of cipher in the list.
3088 @retval EFI_SUCCESS The ciphers list was set successfully.
3089 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3090 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
3091 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
3098 IN UINT16
*CipherId
,
3102 CALL_CRYPTO_SERVICE (TlsSetCipherList
, (Tls
, CipherId
, CipherNum
), EFI_UNSUPPORTED
);
3106 Set the compression method for TLS/SSL operations.
3108 This function handles TLS/SSL integrated compression methods.
3110 @param[in] CompMethod The compression method ID.
3112 @retval EFI_SUCCESS The compression method for the communication was
3114 @retval EFI_UNSUPPORTED Unsupported compression method.
3119 TlsSetCompressionMethod (
3123 CALL_CRYPTO_SERVICE (TlsSetCompressionMethod
, (CompMethod
), EFI_UNSUPPORTED
);
3127 Set peer certificate verification mode for the TLS connection.
3129 This function sets the verification mode flags for the TLS connection.
3131 @param[in] Tls Pointer to the TLS object.
3132 @param[in] VerifyMode A set of logically or'ed verification mode flags.
3139 IN UINT32 VerifyMode
3142 CALL_VOID_CRYPTO_SERVICE (TlsSetVerify
, (Tls
, VerifyMode
));
3146 Set the specified host name to be verified.
3148 @param[in] Tls Pointer to the TLS object.
3149 @param[in] Flags The setting flags during the validation.
3150 @param[in] HostName The specified host name to be verified.
3152 @retval EFI_SUCCESS The HostName setting was set successfully.
3153 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3154 @retval EFI_ABORTED Invalid HostName setting.
3165 CALL_CRYPTO_SERVICE (TlsSetVerifyHost
, (Tls
, Flags
, HostName
), EFI_UNSUPPORTED
);
3169 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
3171 This function sets a session ID to be used when the TLS/SSL connection is
3174 @param[in] Tls Pointer to the TLS object.
3175 @param[in] SessionId Session ID data used for session resumption.
3176 @param[in] SessionIdLen Length of Session ID in bytes.
3178 @retval EFI_SUCCESS Session ID was set successfully.
3179 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3180 @retval EFI_UNSUPPORTED No available session for ID setting.
3187 IN UINT8
*SessionId
,
3188 IN UINT16 SessionIdLen
3191 CALL_CRYPTO_SERVICE (TlsSetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
3195 Adds the CA to the cert store when requesting Server or Client authentication.
3197 This function adds the CA certificate to the list of CAs when requesting
3198 Server or Client authentication for the chosen TLS connection.
3200 @param[in] Tls Pointer to the TLS object.
3201 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3202 X.509 certificate or PEM-encoded X.509 certificate.
3203 @param[in] DataSize The size of data buffer in bytes.
3205 @retval EFI_SUCCESS The operation succeeded.
3206 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3207 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3208 @retval EFI_ABORTED Invalid X.509 certificate.
3213 TlsSetCaCertificate (
3219 CALL_CRYPTO_SERVICE (TlsSetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3223 Loads the local public certificate into the specified TLS object.
3225 This function loads the X.509 certificate into the specified TLS object
3226 for TLS negotiation.
3228 @param[in] Tls Pointer to the TLS object.
3229 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3230 X.509 certificate or PEM-encoded X.509 certificate.
3231 @param[in] DataSize The size of data buffer in bytes.
3233 @retval EFI_SUCCESS The operation succeeded.
3234 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3235 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3236 @retval EFI_ABORTED Invalid X.509 certificate.
3241 TlsSetHostPublicCert (
3247 CALL_CRYPTO_SERVICE (TlsSetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3251 Adds the local private key to the specified TLS object.
3253 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
3254 key) into the specified TLS object for TLS negotiation.
3256 @param[in] Tls Pointer to the TLS object.
3257 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
3258 or PKCS#8 private key.
3259 @param[in] DataSize The size of data buffer in bytes.
3261 @retval EFI_SUCCESS The operation succeeded.
3262 @retval EFI_UNSUPPORTED This function is not supported.
3263 @retval EFI_ABORTED Invalid private key data.
3268 TlsSetHostPrivateKey (
3274 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3278 Adds the CA-supplied certificate revocation list for certificate validation.
3280 This function adds the CA-supplied certificate revocation list data for
3281 certificate validity checking.
3283 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
3284 @param[in] DataSize The size of data buffer in bytes.
3286 @retval EFI_SUCCESS The operation succeeded.
3287 @retval EFI_UNSUPPORTED This function is not supported.
3288 @retval EFI_ABORTED Invalid CRL data.
3293 TlsSetCertRevocationList (
3298 CALL_CRYPTO_SERVICE (TlsSetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);
3302 Gets the protocol version used by the specified TLS connection.
3304 This function returns the protocol version used by the specified TLS
3307 If Tls is NULL, then ASSERT().
3309 @param[in] Tls Pointer to the TLS object.
3311 @return The protocol version of the specified TLS connection.
3320 CALL_CRYPTO_SERVICE (TlsGetVersion
, (Tls
), 0);
3324 Gets the connection end of the specified TLS connection.
3326 This function returns the connection end (as client or as server) used by
3327 the specified TLS connection.
3329 If Tls is NULL, then ASSERT().
3331 @param[in] Tls Pointer to the TLS object.
3333 @return The connection end used by the specified TLS connection.
3338 TlsGetConnectionEnd (
3342 CALL_CRYPTO_SERVICE (TlsGetConnectionEnd
, (Tls
), 0);
3346 Gets the cipher suite used by the specified TLS connection.
3348 This function returns current cipher suite used by the specified
3351 @param[in] Tls Pointer to the TLS object.
3352 @param[in,out] CipherId The cipher suite used by the TLS object.
3354 @retval EFI_SUCCESS The cipher suite was returned successfully.
3355 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3356 @retval EFI_UNSUPPORTED Unsupported cipher suite.
3361 TlsGetCurrentCipher (
3363 IN OUT UINT16
*CipherId
3366 CALL_CRYPTO_SERVICE (TlsGetCurrentCipher
, (Tls
, CipherId
), EFI_UNSUPPORTED
);
3370 Gets the compression methods used by the specified TLS connection.
3372 This function returns current integrated compression methods used by
3373 the specified TLS connection.
3375 @param[in] Tls Pointer to the TLS object.
3376 @param[in,out] CompressionId The current compression method used by
3379 @retval EFI_SUCCESS The compression method was returned successfully.
3380 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3381 @retval EFI_ABORTED Invalid Compression method.
3382 @retval EFI_UNSUPPORTED This function is not supported.
3387 TlsGetCurrentCompressionId (
3389 IN OUT UINT8
*CompressionId
3392 CALL_CRYPTO_SERVICE (TlsGetCurrentCompressionId
, (Tls
, CompressionId
), EFI_UNSUPPORTED
);
3396 Gets the verification mode currently set in the TLS connection.
3398 This function returns the peer verification mode currently set in the
3399 specified TLS connection.
3401 If Tls is NULL, then ASSERT().
3403 @param[in] Tls Pointer to the TLS object.
3405 @return The verification mode set in the specified TLS connection.
3414 CALL_CRYPTO_SERVICE (TlsGetVerify
, (Tls
), 0);
3418 Gets the session ID used by the specified TLS connection.
3420 This function returns the TLS/SSL session ID currently used by the
3421 specified TLS connection.
3423 @param[in] Tls Pointer to the TLS object.
3424 @param[in,out] SessionId Buffer to contain the returned session ID.
3425 @param[in,out] SessionIdLen The length of Session ID in bytes.
3427 @retval EFI_SUCCESS The Session ID was returned successfully.
3428 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3429 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
3436 IN OUT UINT8
*SessionId
,
3437 IN OUT UINT16
*SessionIdLen
3440 CALL_CRYPTO_SERVICE (TlsGetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
3444 Gets the client random data used in the specified TLS connection.
3446 This function returns the TLS/SSL client random data currently used in
3447 the specified TLS connection.
3449 @param[in] Tls Pointer to the TLS object.
3450 @param[in,out] ClientRandom Buffer to contain the returned client
3451 random data (32 bytes).
3456 TlsGetClientRandom (
3458 IN OUT UINT8
*ClientRandom
3461 CALL_VOID_CRYPTO_SERVICE (TlsGetClientRandom
, (Tls
, ClientRandom
));
3465 Gets the server random data used in the specified TLS connection.
3467 This function returns the TLS/SSL server random data currently used in
3468 the specified TLS connection.
3470 @param[in] Tls Pointer to the TLS object.
3471 @param[in,out] ServerRandom Buffer to contain the returned server
3472 random data (32 bytes).
3477 TlsGetServerRandom (
3479 IN OUT UINT8
*ServerRandom
3482 CALL_VOID_CRYPTO_SERVICE (TlsGetServerRandom
, (Tls
, ServerRandom
));
3486 Gets the master key data used in the specified TLS connection.
3488 This function returns the TLS/SSL master key material currently used in
3489 the specified TLS connection.
3491 @param[in] Tls Pointer to the TLS object.
3492 @param[in,out] KeyMaterial Buffer to contain the returned key material.
3494 @retval EFI_SUCCESS Key material was returned successfully.
3495 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3496 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
3503 IN OUT UINT8
*KeyMaterial
3506 CALL_CRYPTO_SERVICE (TlsGetKeyMaterial
, (Tls
, KeyMaterial
), EFI_UNSUPPORTED
);
3510 Gets the CA Certificate from the cert store.
3512 This function returns the CA certificate for the chosen
3515 @param[in] Tls Pointer to the TLS object.
3516 @param[out] Data Pointer to the data buffer to receive the CA
3517 certificate data sent to the client.
3518 @param[in,out] DataSize The size of data buffer in bytes.
3520 @retval EFI_SUCCESS The operation succeeded.
3521 @retval EFI_UNSUPPORTED This function is not supported.
3522 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3527 TlsGetCaCertificate (
3530 IN OUT UINTN
*DataSize
3533 CALL_CRYPTO_SERVICE (TlsGetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3537 Gets the local public Certificate set in the specified TLS object.
3539 This function returns the local public certificate which was currently set
3540 in the specified TLS object.
3542 @param[in] Tls Pointer to the TLS object.
3543 @param[out] Data Pointer to the data buffer to receive the local
3545 @param[in,out] DataSize The size of data buffer in bytes.
3547 @retval EFI_SUCCESS The operation succeeded.
3548 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3549 @retval EFI_NOT_FOUND The certificate is not found.
3550 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3555 TlsGetHostPublicCert (
3558 IN OUT UINTN
*DataSize
3561 CALL_CRYPTO_SERVICE (TlsGetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3565 Gets the local private key set in the specified TLS object.
3567 This function returns the local private key data which was currently set
3568 in the specified TLS object.
3570 @param[in] Tls Pointer to the TLS object.
3571 @param[out] Data Pointer to the data buffer to receive the local
3573 @param[in,out] DataSize The size of data buffer in bytes.
3575 @retval EFI_SUCCESS The operation succeeded.
3576 @retval EFI_UNSUPPORTED This function is not supported.
3577 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3582 TlsGetHostPrivateKey (
3585 IN OUT UINTN
*DataSize
3588 CALL_CRYPTO_SERVICE (TlsGetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3592 Gets the CA-supplied certificate revocation list data set in the specified
3595 This function returns the CA-supplied certificate revocation list data which
3596 was currently set in the specified TLS object.
3598 @param[out] Data Pointer to the data buffer to receive the CRL data.
3599 @param[in,out] DataSize The size of data buffer in bytes.
3601 @retval EFI_SUCCESS The operation succeeded.
3602 @retval EFI_UNSUPPORTED This function is not supported.
3603 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3608 TlsGetCertRevocationList (
3610 IN OUT UINTN
*DataSize
3613 CALL_CRYPTO_SERVICE (TlsGetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);