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
);
1205 Computes the HMAC-SHA256 digest of a input data buffer.
1207 This function performs the HMAC-SHA256 digest of a given data buffer, and places
1208 the digest value into the specified memory.
1210 If this interface is not supported, then return FALSE.
1212 @param[in] Data Pointer to the buffer containing the data to be digested.
1213 @param[in] DataSize Size of Data buffer in bytes.
1214 @param[in] Key Pointer to the user-supplied key.
1215 @param[in] KeySize Key size in bytes.
1216 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
1219 @retval TRUE HMAC-SHA256 digest computation succeeded.
1220 @retval FALSE HMAC-SHA256 digest computation failed.
1221 @retval FALSE This interface is not supported.
1227 IN CONST VOID
*Data
,
1229 IN CONST UINT8
*Key
,
1231 OUT UINT8
*HmacValue
1234 CALL_CRYPTO_SERVICE (HmacSha256All
, (Data
, DataSize
, Key
, KeySize
, HmacValue
), FALSE
);
1238 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA384 use.
1240 @return Pointer to the HMAC_CTX context that has been initialized.
1241 If the allocations fails, HmacSha384New() returns NULL.
1250 CALL_CRYPTO_SERVICE (HmacSha384New
, (), NULL
);
1254 Release the specified HMAC_CTX context.
1256 @param[in] HmacSha384Ctx Pointer to the HMAC_CTX context to be released.
1262 IN VOID
*HmacSha384Ctx
1265 CALL_VOID_CRYPTO_SERVICE (HmacSha384Free
, (HmacSha384Ctx
));
1269 Set user-supplied key for subsequent use. It must be done before any
1270 calling to HmacSha384Update().
1272 If HmacSha384Context is NULL, then return FALSE.
1273 If this interface is not supported, then return FALSE.
1275 @param[out] HmacSha384Context Pointer to HMAC-SHA384 context.
1276 @param[in] Key Pointer to the user-supplied key.
1277 @param[in] KeySize Key size in bytes.
1279 @retval TRUE The Key is set successfully.
1280 @retval FALSE The Key is set unsuccessfully.
1281 @retval FALSE This interface is not supported.
1287 OUT VOID
*HmacSha384Context
,
1288 IN CONST UINT8
*Key
,
1292 CALL_CRYPTO_SERVICE (HmacSha384SetKey
, (HmacSha384Context
, Key
, KeySize
), FALSE
);
1296 Makes a copy of an existing HMAC-SHA384 context.
1298 If HmacSha384Context is NULL, then return FALSE.
1299 If NewHmacSha384Context is NULL, then return FALSE.
1300 If this interface is not supported, then return FALSE.
1302 @param[in] HmacSha384Context Pointer to HMAC-SHA384 context being copied.
1303 @param[out] NewHmacSha384Context Pointer to new HMAC-SHA384 context.
1305 @retval TRUE HMAC-SHA384 context copy succeeded.
1306 @retval FALSE HMAC-SHA384 context copy failed.
1307 @retval FALSE This interface is not supported.
1312 HmacSha384Duplicate (
1313 IN CONST VOID
*HmacSha384Context
,
1314 OUT VOID
*NewHmacSha384Context
1317 CALL_CRYPTO_SERVICE (HmacSha384Duplicate
, (HmacSha384Context
, NewHmacSha384Context
), FALSE
);
1321 Digests the input data and updates HMAC-SHA384 context.
1323 This function performs HMAC-SHA384 digest on a data buffer of the specified size.
1324 It can be called multiple times to compute the digest of long or discontinuous data streams.
1325 HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized
1326 by HmacSha384Final(). Behavior with invalid context is undefined.
1328 If HmacSha384Context is NULL, then return FALSE.
1329 If this interface is not supported, then return FALSE.
1331 @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.
1332 @param[in] Data Pointer to the buffer containing the data to be digested.
1333 @param[in] DataSize Size of Data buffer in bytes.
1335 @retval TRUE HMAC-SHA384 data digest succeeded.
1336 @retval FALSE HMAC-SHA384 data digest failed.
1337 @retval FALSE This interface is not supported.
1343 IN OUT VOID
*HmacSha384Context
,
1344 IN CONST VOID
*Data
,
1348 CALL_CRYPTO_SERVICE (HmacSha384Update
, (HmacSha384Context
, Data
, DataSize
), FALSE
);
1352 Completes computation of the HMAC-SHA384 digest value.
1354 This function completes HMAC-SHA384 hash computation and retrieves the digest value into
1355 the specified memory. After this function has been called, the HMAC-SHA384 context cannot
1357 HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized
1358 by HmacSha384Final(). Behavior with invalid HMAC-SHA384 context is undefined.
1360 If HmacSha384Context is NULL, then return FALSE.
1361 If HmacValue is NULL, then return FALSE.
1362 If this interface is not supported, then return FALSE.
1364 @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.
1365 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA384 digest
1368 @retval TRUE HMAC-SHA384 digest computation succeeded.
1369 @retval FALSE HMAC-SHA384 digest computation failed.
1370 @retval FALSE This interface is not supported.
1376 IN OUT VOID
*HmacSha384Context
,
1377 OUT UINT8
*HmacValue
1380 CALL_CRYPTO_SERVICE (HmacSha384Final
, (HmacSha384Context
, HmacValue
), FALSE
);
1384 Computes the HMAC-SHA384 digest of a input data buffer.
1386 This function performs the HMAC-SHA384 digest of a given data buffer, and places
1387 the digest value into the specified memory.
1389 If this interface is not supported, then return FALSE.
1391 @param[in] Data Pointer to the buffer containing the data to be digested.
1392 @param[in] DataSize Size of Data buffer in bytes.
1393 @param[in] Key Pointer to the user-supplied key.
1394 @param[in] KeySize Key size in bytes.
1395 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA384 digest
1398 @retval TRUE HMAC-SHA384 digest computation succeeded.
1399 @retval FALSE HMAC-SHA384 digest computation failed.
1400 @retval FALSE This interface is not supported.
1406 IN CONST VOID
*Data
,
1408 IN CONST UINT8
*Key
,
1410 OUT UINT8
*HmacValue
1413 CALL_CRYPTO_SERVICE (HmacSha384All
, (Data
, DataSize
, Key
, KeySize
, HmacValue
), FALSE
);
1416 // =====================================================================================
1417 // Symmetric Cryptography Primitive
1418 // =====================================================================================
1421 Retrieves the size, in bytes, of the context buffer required for AES operations.
1423 If this interface is not supported, then return zero.
1425 @return The size, in bytes, of the context buffer required for AES operations.
1426 @retval 0 This interface is not supported.
1435 CALL_CRYPTO_SERVICE (AesGetContextSize
, (), 0);
1439 Initializes user-supplied memory as AES context for subsequent use.
1441 This function initializes user-supplied memory pointed by AesContext as AES context.
1442 In addition, it sets up all AES key materials for subsequent encryption and decryption
1444 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1446 If AesContext is NULL, then return FALSE.
1447 If Key is NULL, then return FALSE.
1448 If KeyLength is not valid, then return FALSE.
1449 If this interface is not supported, then return FALSE.
1451 @param[out] AesContext Pointer to AES context being initialized.
1452 @param[in] Key Pointer to the user-supplied AES key.
1453 @param[in] KeyLength Length of AES key in bits.
1455 @retval TRUE AES context initialization succeeded.
1456 @retval FALSE AES context initialization failed.
1457 @retval FALSE This interface is not supported.
1463 OUT VOID
*AesContext
,
1464 IN CONST UINT8
*Key
,
1468 CALL_CRYPTO_SERVICE (AesInit
, (AesContext
, Key
, KeyLength
), FALSE
);
1472 Performs AES encryption on a data buffer of the specified size in CBC mode.
1474 This function performs AES encryption on data buffer pointed by Input, of specified
1475 size of InputSize, in CBC mode.
1476 InputSize must be multiple of block size (16 bytes). This function does not perform
1477 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1478 Initialization vector should be one block size (16 bytes).
1479 AesContext should be already correctly initialized by AesInit(). Behavior with
1480 invalid AES context is undefined.
1482 If AesContext is NULL, then return FALSE.
1483 If Input is NULL, then return FALSE.
1484 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1485 If Ivec is NULL, then return FALSE.
1486 If Output is NULL, then return FALSE.
1487 If this interface is not supported, then return FALSE.
1489 @param[in] AesContext Pointer to the AES context.
1490 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1491 @param[in] InputSize Size of the Input buffer in bytes.
1492 @param[in] Ivec Pointer to initialization vector.
1493 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1495 @retval TRUE AES encryption succeeded.
1496 @retval FALSE AES encryption failed.
1497 @retval FALSE This interface is not supported.
1503 IN VOID
*AesContext
,
1504 IN CONST UINT8
*Input
,
1506 IN CONST UINT8
*Ivec
,
1510 CALL_CRYPTO_SERVICE (AesCbcEncrypt
, (AesContext
, Input
, InputSize
, Ivec
, Output
), FALSE
);
1514 Performs AES decryption on a data buffer of the specified size in CBC mode.
1516 This function performs AES decryption on data buffer pointed by Input, of specified
1517 size of InputSize, in CBC mode.
1518 InputSize must be multiple of block size (16 bytes). This function does not perform
1519 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1520 Initialization vector should be one block size (16 bytes).
1521 AesContext should be already correctly initialized by AesInit(). Behavior with
1522 invalid AES context is undefined.
1524 If AesContext is NULL, then return FALSE.
1525 If Input is NULL, then return FALSE.
1526 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1527 If Ivec is NULL, then return FALSE.
1528 If Output is NULL, then return FALSE.
1529 If this interface is not supported, then return FALSE.
1531 @param[in] AesContext Pointer to the AES context.
1532 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1533 @param[in] InputSize Size of the Input buffer in bytes.
1534 @param[in] Ivec Pointer to initialization vector.
1535 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1537 @retval TRUE AES decryption succeeded.
1538 @retval FALSE AES decryption failed.
1539 @retval FALSE This interface is not supported.
1545 IN VOID
*AesContext
,
1546 IN CONST UINT8
*Input
,
1548 IN CONST UINT8
*Ivec
,
1552 CALL_CRYPTO_SERVICE (AesCbcDecrypt
, (AesContext
, Input
, InputSize
, Ivec
, Output
), FALSE
);
1555 // =====================================================================================
1556 // Asymmetric Cryptography Primitive
1557 // =====================================================================================
1560 Allocates and initializes one RSA context for subsequent use.
1562 @return Pointer to the RSA context that has been initialized.
1563 If the allocations fails, RsaNew() returns NULL.
1572 CALL_CRYPTO_SERVICE (RsaNew
, (), NULL
);
1576 Release the specified RSA context.
1578 If RsaContext is NULL, then return FALSE.
1580 @param[in] RsaContext Pointer to the RSA context to be released.
1589 CALL_VOID_CRYPTO_SERVICE (RsaFree
, (RsaContext
));
1593 Sets the tag-designated key component into the established RSA context.
1595 This function sets the tag-designated RSA key component into the established
1596 RSA context from the user-specified non-negative integer (octet string format
1597 represented in RSA PKCS#1).
1598 If BigNumber is NULL, then the specified key component in RSA context is cleared.
1600 If RsaContext is NULL, then return FALSE.
1602 @param[in, out] RsaContext Pointer to RSA context being set.
1603 @param[in] KeyTag Tag of RSA key component being set.
1604 @param[in] BigNumber Pointer to octet integer buffer.
1605 If NULL, then the specified key component in RSA
1607 @param[in] BnSize Size of big number buffer in bytes.
1608 If BigNumber is NULL, then it is ignored.
1610 @retval TRUE RSA key component was set successfully.
1611 @retval FALSE Invalid RSA key component tag.
1617 IN OUT VOID
*RsaContext
,
1618 IN RSA_KEY_TAG KeyTag
,
1619 IN CONST UINT8
*BigNumber
,
1623 CALL_CRYPTO_SERVICE (RsaSetKey
, (RsaContext
, KeyTag
, BigNumber
, BnSize
), FALSE
);
1627 Gets the tag-designated RSA key component from the established RSA context.
1629 This function retrieves the tag-designated RSA key component from the
1630 established RSA context as a non-negative integer (octet string format
1631 represented in RSA PKCS#1).
1632 If specified key component has not been set or has been cleared, then returned
1634 If the BigNumber buffer is too small to hold the contents of the key, FALSE
1635 is returned and BnSize is set to the required buffer size to obtain the key.
1637 If RsaContext is NULL, then return FALSE.
1638 If BnSize is NULL, then return FALSE.
1639 If BnSize is large enough but BigNumber is NULL, then return FALSE.
1640 If this interface is not supported, then return FALSE.
1642 @param[in, out] RsaContext Pointer to RSA context being set.
1643 @param[in] KeyTag Tag of RSA key component being set.
1644 @param[out] BigNumber Pointer to octet integer buffer.
1645 @param[in, out] BnSize On input, the size of big number buffer in bytes.
1646 On output, the size of data returned in big number buffer in bytes.
1648 @retval TRUE RSA key component was retrieved successfully.
1649 @retval FALSE Invalid RSA key component tag.
1650 @retval FALSE BnSize is too small.
1651 @retval FALSE This interface is not supported.
1657 IN OUT VOID
*RsaContext
,
1658 IN RSA_KEY_TAG KeyTag
,
1659 OUT UINT8
*BigNumber
,
1660 IN OUT UINTN
*BnSize
1663 CALL_CRYPTO_SERVICE (RsaGetKey
, (RsaContext
, KeyTag
, BigNumber
, BnSize
), FALSE
);
1667 Generates RSA key components.
1669 This function generates RSA key components. It takes RSA public exponent E and
1670 length in bits of RSA modulus N as input, and generates all key components.
1671 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
1673 Before this function can be invoked, pseudorandom number generator must be correctly
1674 initialized by RandomSeed().
1676 If RsaContext is NULL, then return FALSE.
1677 If this interface is not supported, then return FALSE.
1679 @param[in, out] RsaContext Pointer to RSA context being set.
1680 @param[in] ModulusLength Length of RSA modulus N in bits.
1681 @param[in] PublicExponent Pointer to RSA public exponent.
1682 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
1684 @retval TRUE RSA key component was generated successfully.
1685 @retval FALSE Invalid RSA key component tag.
1686 @retval FALSE This interface is not supported.
1692 IN OUT VOID
*RsaContext
,
1693 IN UINTN ModulusLength
,
1694 IN CONST UINT8
*PublicExponent
,
1695 IN UINTN PublicExponentSize
1698 CALL_CRYPTO_SERVICE (RsaGenerateKey
, (RsaContext
, ModulusLength
, PublicExponent
, PublicExponentSize
), FALSE
);
1702 Validates key components of RSA context.
1703 NOTE: This function performs integrity checks on all the RSA key material, so
1704 the RSA key structure must contain all the private key data.
1706 This function validates key components of RSA context in following aspects:
1707 - Whether p is a prime
1708 - Whether q is a prime
1710 - Whether d*e = 1 mod lcm(p-1,q-1)
1712 If RsaContext is NULL, then return FALSE.
1713 If this interface is not supported, then return FALSE.
1715 @param[in] RsaContext Pointer to RSA context to check.
1717 @retval TRUE RSA key components are valid.
1718 @retval FALSE RSA key components are not valid.
1719 @retval FALSE This interface is not supported.
1728 CALL_CRYPTO_SERVICE (RsaCheckKey
, (RsaContext
), FALSE
);
1732 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
1734 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
1736 If the Signature buffer is too small to hold the contents of signature, FALSE
1737 is returned and SigSize is set to the required buffer size to obtain the signature.
1739 If RsaContext is NULL, then return FALSE.
1740 If MessageHash is NULL, then return FALSE.
1741 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
1742 If SigSize is large enough but Signature is NULL, then return FALSE.
1743 If this interface is not supported, then return FALSE.
1745 @param[in] RsaContext Pointer to RSA context for signature generation.
1746 @param[in] MessageHash Pointer to octet message hash to be signed.
1747 @param[in] HashSize Size of the message hash in bytes.
1748 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
1749 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1750 On output, the size of data returned in Signature buffer in bytes.
1752 @retval TRUE Signature successfully generated in PKCS1-v1_5.
1753 @retval FALSE Signature generation failed.
1754 @retval FALSE SigSize is too small.
1755 @retval FALSE This interface is not supported.
1761 IN VOID
*RsaContext
,
1762 IN CONST UINT8
*MessageHash
,
1764 OUT UINT8
*Signature
,
1765 IN OUT UINTN
*SigSize
1768 CALL_CRYPTO_SERVICE (RsaPkcs1Sign
, (RsaContext
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
1772 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
1775 If RsaContext is NULL, then return FALSE.
1776 If MessageHash is NULL, then return FALSE.
1777 If Signature is NULL, then return FALSE.
1778 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
1780 @param[in] RsaContext Pointer to RSA context for signature verification.
1781 @param[in] MessageHash Pointer to octet message hash to be checked.
1782 @param[in] HashSize Size of the message hash in bytes.
1783 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
1784 @param[in] SigSize Size of signature in bytes.
1786 @retval TRUE Valid signature encoded in PKCS1-v1_5.
1787 @retval FALSE Invalid signature or invalid RSA context.
1793 IN VOID
*RsaContext
,
1794 IN CONST UINT8
*MessageHash
,
1796 IN CONST UINT8
*Signature
,
1800 CALL_CRYPTO_SERVICE (RsaPkcs1Verify
, (RsaContext
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
1804 Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
1805 Implementation determines salt length automatically from the signature encoding.
1806 Mask generation function is the same as the message digest algorithm.
1807 Salt length should be equal to digest length.
1809 @param[in] RsaContext Pointer to RSA context for signature verification.
1810 @param[in] Message Pointer to octet message to be verified.
1811 @param[in] MsgSize Size of the message in bytes.
1812 @param[in] Signature Pointer to RSASSA-PSS signature to be verified.
1813 @param[in] SigSize Size of signature in bytes.
1814 @param[in] DigestLen Length of digest for RSA operation.
1815 @param[in] SaltLen Salt length for PSS encoding.
1817 @retval TRUE Valid signature encoded in RSASSA-PSS.
1818 @retval FALSE Invalid signature or invalid RSA context.
1824 IN VOID
*RsaContext
,
1825 IN CONST UINT8
*Message
,
1827 IN CONST UINT8
*Signature
,
1829 IN UINT16 DigestLen
,
1833 CALL_CRYPTO_SERVICE (RsaPssVerify
, (RsaContext
, Message
, MsgSize
, Signature
, SigSize
, DigestLen
, SaltLen
), FALSE
);
1837 This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in
1839 Mask generation function is the same as the message digest algorithm.
1840 If the Signature buffer is too small to hold the contents of signature, FALSE
1841 is returned and SigSize is set to the required buffer size to obtain the signature.
1843 If RsaContext is NULL, then return FALSE.
1844 If Message is NULL, then return FALSE.
1845 If MsgSize is zero or > INT_MAX, then return FALSE.
1846 If DigestLen is NOT 32, 48 or 64, return FALSE.
1847 If SaltLen is not equal to DigestLen, then return FALSE.
1848 If SigSize is large enough but Signature is NULL, then return FALSE.
1849 If this interface is not supported, then return FALSE.
1851 @param[in] RsaContext Pointer to RSA context for signature generation.
1852 @param[in] Message Pointer to octet message to be signed.
1853 @param[in] MsgSize Size of the message in bytes.
1854 @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.
1855 @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.
1856 @param[out] Signature Pointer to buffer to receive RSA PSS signature.
1857 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1858 On output, the size of data returned in Signature buffer in bytes.
1860 @retval TRUE Signature successfully generated in RSASSA-PSS.
1861 @retval FALSE Signature generation failed.
1862 @retval FALSE SigSize is too small.
1863 @retval FALSE This interface is not supported.
1869 IN VOID
*RsaContext
,
1870 IN CONST UINT8
*Message
,
1872 IN UINT16 DigestLen
,
1874 OUT UINT8
*Signature
,
1875 IN OUT UINTN
*SigSize
1878 CALL_CRYPTO_SERVICE (RsaPssSign
, (RsaContext
, Message
, MsgSize
, DigestLen
, SaltLen
, Signature
, SigSize
), FALSE
);
1882 Retrieve the RSA Private Key from the password-protected PEM key data.
1884 If PemData is NULL, then return FALSE.
1885 If RsaContext is NULL, then return FALSE.
1886 If this interface is not supported, then return FALSE.
1888 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
1889 @param[in] PemSize Size of the PEM key data in bytes.
1890 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
1891 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1892 RSA private key component. Use RsaFree() function to free the
1895 @retval TRUE RSA Private Key was retrieved successfully.
1896 @retval FALSE Invalid PEM key data or incorrect password.
1897 @retval FALSE This interface is not supported.
1902 RsaGetPrivateKeyFromPem (
1903 IN CONST UINT8
*PemData
,
1905 IN CONST CHAR8
*Password
,
1906 OUT VOID
**RsaContext
1909 CALL_CRYPTO_SERVICE (RsaGetPrivateKeyFromPem
, (PemData
, PemSize
, Password
, RsaContext
), FALSE
);
1913 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
1915 If Cert is NULL, then return FALSE.
1916 If RsaContext is NULL, then return FALSE.
1917 If this interface is not supported, then return FALSE.
1919 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1920 @param[in] CertSize Size of the X509 certificate in bytes.
1921 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1922 RSA public key component. Use RsaFree() function to free the
1925 @retval TRUE RSA Public Key was retrieved successfully.
1926 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
1927 @retval FALSE This interface is not supported.
1932 RsaGetPublicKeyFromX509 (
1933 IN CONST UINT8
*Cert
,
1935 OUT VOID
**RsaContext
1938 CALL_CRYPTO_SERVICE (RsaGetPublicKeyFromX509
, (Cert
, CertSize
, RsaContext
), FALSE
);
1942 Retrieve the subject bytes from one X.509 certificate.
1944 If Cert is NULL, then return FALSE.
1945 If SubjectSize is NULL, then return FALSE.
1946 If this interface is not supported, then return FALSE.
1948 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1949 @param[in] CertSize Size of the X509 certificate in bytes.
1950 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
1951 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
1952 and the size of buffer returned CertSubject on output.
1954 @retval TRUE The certificate subject retrieved successfully.
1955 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
1956 The SubjectSize will be updated with the required size.
1957 @retval FALSE This interface is not supported.
1962 X509GetSubjectName (
1963 IN CONST UINT8
*Cert
,
1965 OUT UINT8
*CertSubject
,
1966 IN OUT UINTN
*SubjectSize
1969 CALL_CRYPTO_SERVICE (X509GetSubjectName
, (Cert
, CertSize
, CertSubject
, SubjectSize
), FALSE
);
1973 Retrieve the common name (CN) string from one X.509 certificate.
1975 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1976 @param[in] CertSize Size of the X509 certificate in bytes.
1977 @param[out] CommonName Buffer to contain the retrieved certificate common
1978 name string (UTF8). At most CommonNameSize bytes will be
1979 written and the string will be null terminated. May be
1980 NULL in order to determine the size buffer needed.
1981 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
1982 and the size of buffer returned CommonName on output.
1983 If CommonName is NULL then the amount of space needed
1984 in buffer (including the final null) is returned.
1986 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
1987 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
1988 If CommonNameSize is NULL.
1989 If CommonName is not NULL and *CommonNameSize is 0.
1990 If Certificate is invalid.
1991 @retval RETURN_NOT_FOUND If no CommonName entry exists.
1992 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
1993 (including the final null) is returned in the
1994 CommonNameSize parameter.
1995 @retval RETURN_UNSUPPORTED The operation is not supported.
2001 IN CONST UINT8
*Cert
,
2003 OUT CHAR8
*CommonName OPTIONAL
,
2004 IN OUT UINTN
*CommonNameSize
2007 CALL_CRYPTO_SERVICE (X509GetCommonName
, (Cert
, CertSize
, CommonName
, CommonNameSize
), RETURN_UNSUPPORTED
);
2011 Retrieve the organization name (O) string from one X.509 certificate.
2013 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2014 @param[in] CertSize Size of the X509 certificate in bytes.
2015 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
2016 name string. At most NameBufferSize bytes will be
2017 written and the string will be null terminated. May be
2018 NULL in order to determine the size buffer needed.
2019 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
2020 and the size of buffer returned Name on output.
2021 If NameBuffer is NULL then the amount of space needed
2022 in buffer (including the final null) is returned.
2024 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
2025 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2026 If NameBufferSize is NULL.
2027 If NameBuffer is not NULL and *CommonNameSize is 0.
2028 If Certificate is invalid.
2029 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
2030 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
2031 (including the final null) is returned in the
2032 CommonNameSize parameter.
2033 @retval RETURN_UNSUPPORTED The operation is not supported.
2038 X509GetOrganizationName (
2039 IN CONST UINT8
*Cert
,
2041 OUT CHAR8
*NameBuffer OPTIONAL
,
2042 IN OUT UINTN
*NameBufferSize
2045 CALL_CRYPTO_SERVICE (X509GetOrganizationName
, (Cert
, CertSize
, NameBuffer
, NameBufferSize
), RETURN_UNSUPPORTED
);
2049 Verify one X509 certificate was issued by the trusted CA.
2051 If Cert is NULL, then return FALSE.
2052 If CACert is NULL, then return FALSE.
2053 If this interface is not supported, then return FALSE.
2055 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
2056 @param[in] CertSize Size of the X509 certificate in bytes.
2057 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
2058 @param[in] CACertSize Size of the CA Certificate in bytes.
2060 @retval TRUE The certificate was issued by the trusted CA.
2061 @retval FALSE Invalid certificate or the certificate was not issued by the given
2063 @retval FALSE This interface is not supported.
2069 IN CONST UINT8
*Cert
,
2071 IN CONST UINT8
*CACert
,
2075 CALL_CRYPTO_SERVICE (X509VerifyCert
, (Cert
, CertSize
, CACert
, CACertSize
), FALSE
);
2079 Construct a X509 object from DER-encoded certificate data.
2081 If Cert is NULL, then return FALSE.
2082 If SingleX509Cert is NULL, then return FALSE.
2083 If this interface is not supported, then return FALSE.
2085 @param[in] Cert Pointer to the DER-encoded certificate data.
2086 @param[in] CertSize The size of certificate data in bytes.
2087 @param[out] SingleX509Cert The generated X509 object.
2089 @retval TRUE The X509 object generation succeeded.
2090 @retval FALSE The operation failed.
2091 @retval FALSE This interface is not supported.
2096 X509ConstructCertificate (
2097 IN CONST UINT8
*Cert
,
2099 OUT UINT8
**SingleX509Cert
2102 CALL_CRYPTO_SERVICE (X509ConstructCertificate
, (Cert
, CertSize
, SingleX509Cert
), FALSE
);
2106 Construct a X509 stack object from a list of DER-encoded certificate data.
2108 If X509Stack is NULL, then return FALSE.
2109 If this interface is not supported, then return FALSE.
2111 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2112 On output, pointer to the X509 stack object with new
2113 inserted X509 certificate.
2114 @param[in] Args VA_LIST marker for the variable argument list.
2115 ... A list of DER-encoded single certificate data followed
2116 by certificate size. A NULL terminates the list. The
2117 pairs are the arguments to X509ConstructCertificate().
2119 @retval TRUE The X509 stack construction succeeded.
2120 @retval FALSE The construction operation failed.
2121 @retval FALSE This interface is not supported.
2126 X509ConstructCertificateStack (
2127 IN OUT UINT8
**X509Stack
,
2134 VA_START (Args
, X509Stack
);
2135 Result
= X509ConstructCertificateStackV (X509Stack
, Args
);
2141 Construct a X509 stack object from a list of DER-encoded certificate data.
2143 If X509Stack is NULL, then return FALSE.
2144 If this interface is not supported, then return FALSE.
2146 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2147 On output, pointer to the X509 stack object with new
2148 inserted X509 certificate.
2149 @param[in] Args VA_LIST marker for the variable argument list.
2150 A list of DER-encoded single certificate data followed
2151 by certificate size. A NULL terminates the list. The
2152 pairs are the arguments to X509ConstructCertificate().
2154 @retval TRUE The X509 stack construction succeeded.
2155 @retval FALSE The construction operation failed.
2156 @retval FALSE This interface is not supported.
2161 X509ConstructCertificateStackV (
2162 IN OUT UINT8
**X509Stack
,
2166 CALL_CRYPTO_SERVICE (X509ConstructCertificateStackV
, (X509Stack
, Args
), FALSE
);
2170 Release the specified X509 object.
2172 If the interface is not supported, then ASSERT().
2174 @param[in] X509Cert Pointer to the X509 object to be released.
2183 CALL_VOID_CRYPTO_SERVICE (X509Free
, (X509Cert
));
2187 Release the specified X509 stack object.
2189 If the interface is not supported, then ASSERT().
2191 @param[in] X509Stack Pointer to the X509 stack object to be released.
2200 CALL_VOID_CRYPTO_SERVICE (X509StackFree
, (X509Stack
));
2204 Retrieve the TBSCertificate from one given X.509 certificate.
2206 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
2207 @param[in] CertSize Size of the X509 certificate in bytes.
2208 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
2209 @param[out] TBSCertSize Size of the TBS certificate in bytes.
2211 If Cert is NULL, then return FALSE.
2212 If TBSCert is NULL, then return FALSE.
2213 If TBSCertSize is NULL, then return FALSE.
2214 If this interface is not supported, then return FALSE.
2216 @retval TRUE The TBSCertificate was retrieved successfully.
2217 @retval FALSE Invalid X.509 certificate.
2223 IN CONST UINT8
*Cert
,
2225 OUT UINT8
**TBSCert
,
2226 OUT UINTN
*TBSCertSize
2229 CALL_CRYPTO_SERVICE (X509GetTBSCert
, (Cert
, CertSize
, TBSCert
, TBSCertSize
), FALSE
);
2233 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2234 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2236 If Password or Salt or OutKey is NULL, then return FALSE.
2237 If the hash algorithm could not be determined, then return FALSE.
2238 If this interface is not supported, then return FALSE.
2240 @param[in] PasswordLength Length of input password in bytes.
2241 @param[in] Password Pointer to the array for the password.
2242 @param[in] SaltLength Size of the Salt in bytes.
2243 @param[in] Salt Pointer to the Salt.
2244 @param[in] IterationCount Number of iterations to perform. Its value should be
2245 greater than or equal to 1.
2246 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2247 NOTE: DigestSize will be used to determine the hash algorithm.
2248 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2249 @param[in] KeyLength Size of the derived key buffer in bytes.
2250 @param[out] OutKey Pointer to the output derived key buffer.
2252 @retval TRUE A key was derived successfully.
2253 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2254 @retval FALSE The hash algorithm could not be determined from the digest size.
2255 @retval FALSE The key derivation operation failed.
2256 @retval FALSE This interface is not supported.
2262 IN UINTN PasswordLength
,
2263 IN CONST CHAR8
*Password
,
2264 IN UINTN SaltLength
,
2265 IN CONST UINT8
*Salt
,
2266 IN UINTN IterationCount
,
2267 IN UINTN DigestSize
,
2272 CALL_CRYPTO_SERVICE (Pkcs5HashPassword
, (PasswordLength
, Password
, SaltLength
, Salt
, IterationCount
, DigestSize
, KeyLength
, OutKey
), FALSE
);
2276 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2277 encrypted message in a newly allocated buffer.
2279 Things that can cause a failure include:
2280 - X509 key size does not match any known key size.
2281 - Fail to parse X509 certificate.
2282 - Fail to allocate an intermediate buffer.
2283 - Null pointer provided for a non-optional parameter.
2284 - Data size is too large for the provided key size (max size is a function of key size
2285 and hash digest size).
2287 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2288 will be used to encrypt the data.
2289 @param[in] PublicKeySize Size of the X509 cert buffer.
2290 @param[in] InData Data to be encrypted.
2291 @param[in] InDataSize Size of the data buffer.
2292 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2293 to be used when initializing the PRNG. NULL otherwise.
2294 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2296 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2298 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2300 @retval TRUE Encryption was successful.
2301 @retval FALSE Encryption failed.
2307 IN CONST UINT8
*PublicKey
,
2308 IN UINTN PublicKeySize
,
2310 IN UINTN InDataSize
,
2311 IN CONST UINT8
*PrngSeed OPTIONAL
,
2312 IN UINTN PrngSeedSize OPTIONAL
,
2313 OUT UINT8
**EncryptedData
,
2314 OUT UINTN
*EncryptedDataSize
2317 CALL_CRYPTO_SERVICE (Pkcs1v2Encrypt
, (PublicKey
, PublicKeySize
, InData
, InDataSize
, PrngSeed
, PrngSeedSize
, EncryptedData
, EncryptedDataSize
), FALSE
);
2321 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2322 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2323 in a ContentInfo structure.
2325 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2326 return FALSE. If P7Length overflow, then return FALSE.
2327 If this interface is not supported, then return FALSE.
2329 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2330 @param[in] P7Length Length of the PKCS#7 message in bytes.
2331 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2332 It's caller's responsibility to free the buffer with
2334 This data structure is EFI_CERT_STACK type.
2335 @param[out] StackLength Length of signer's certificates in bytes.
2336 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2337 It's caller's responsibility to free the buffer with
2339 @param[out] CertLength Length of the trusted certificate in bytes.
2341 @retval TRUE The operation is finished successfully.
2342 @retval FALSE Error occurs during the operation.
2343 @retval FALSE This interface is not supported.
2349 IN CONST UINT8
*P7Data
,
2351 OUT UINT8
**CertStack
,
2352 OUT UINTN
*StackLength
,
2353 OUT UINT8
**TrustedCert
,
2354 OUT UINTN
*CertLength
2357 CALL_CRYPTO_SERVICE (Pkcs7GetSigners
, (P7Data
, P7Length
, CertStack
, StackLength
, TrustedCert
, CertLength
), FALSE
);
2361 Wrap function to use free() to free allocated memory for certificates.
2363 If this interface is not supported, then ASSERT().
2365 @param[in] Certs Pointer to the certificates to be freed.
2374 CALL_VOID_CRYPTO_SERVICE (Pkcs7FreeSigners
, (Certs
));
2378 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2379 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2380 unchained to the signer's certificates.
2381 The input signed data could be wrapped in a ContentInfo structure.
2383 @param[in] P7Data Pointer to the PKCS#7 message.
2384 @param[in] P7Length Length of the PKCS#7 message in bytes.
2385 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2386 certificate. It's caller's responsibility to free the buffer
2387 with Pkcs7FreeSigners().
2388 This data structure is EFI_CERT_STACK type.
2389 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2390 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2391 responsibility to free the buffer with Pkcs7FreeSigners().
2392 This data structure is EFI_CERT_STACK type.
2393 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2395 @retval TRUE The operation is finished successfully.
2396 @retval FALSE Error occurs during the operation.
2401 Pkcs7GetCertificatesList (
2402 IN CONST UINT8
*P7Data
,
2404 OUT UINT8
**SignerChainCerts
,
2405 OUT UINTN
*ChainLength
,
2406 OUT UINT8
**UnchainCerts
,
2407 OUT UINTN
*UnchainLength
2410 CALL_CRYPTO_SERVICE (Pkcs7GetCertificatesList
, (P7Data
, P7Length
, SignerChainCerts
, ChainLength
, UnchainCerts
, UnchainLength
), FALSE
);
2414 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2415 Syntax Standard, version 1.5". This interface is only intended to be used for
2416 application to perform PKCS#7 functionality validation.
2418 If this interface is not supported, then return FALSE.
2420 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2422 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2423 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2425 @param[in] InData Pointer to the content to be signed.
2426 @param[in] InDataSize Size of InData in bytes.
2427 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2428 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2429 include in the PKCS#7 signedData (e.g. any intermediate
2431 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2432 responsibility to free the buffer with FreePool().
2433 @param[out] SignedDataSize Size of SignedData in bytes.
2435 @retval TRUE PKCS#7 data signing succeeded.
2436 @retval FALSE PKCS#7 data signing failed.
2437 @retval FALSE This interface is not supported.
2443 IN CONST UINT8
*PrivateKey
,
2444 IN UINTN PrivateKeySize
,
2445 IN CONST UINT8
*KeyPassword
,
2447 IN UINTN InDataSize
,
2449 IN UINT8
*OtherCerts OPTIONAL
,
2450 OUT UINT8
**SignedData
,
2451 OUT UINTN
*SignedDataSize
2454 CALL_CRYPTO_SERVICE (Pkcs7Sign
, (PrivateKey
, PrivateKeySize
, KeyPassword
, InData
, InDataSize
, SignCert
, OtherCerts
, SignedData
, SignedDataSize
), FALSE
);
2458 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2459 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2460 in a ContentInfo structure.
2462 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2463 If P7Length, CertLength or DataLength overflow, then return FALSE.
2464 If this interface is not supported, then return FALSE.
2466 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2467 @param[in] P7Length Length of the PKCS#7 message in bytes.
2468 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2469 is used for certificate chain verification.
2470 @param[in] CertLength Length of the trusted certificate in bytes.
2471 @param[in] InData Pointer to the content to be verified.
2472 @param[in] DataLength Length of InData in bytes.
2474 @retval TRUE The specified PKCS#7 signed data is valid.
2475 @retval FALSE Invalid PKCS#7 signed data.
2476 @retval FALSE This interface is not supported.
2482 IN CONST UINT8
*P7Data
,
2484 IN CONST UINT8
*TrustedCert
,
2485 IN UINTN CertLength
,
2486 IN CONST UINT8
*InData
,
2490 CALL_CRYPTO_SERVICE (Pkcs7Verify
, (P7Data
, P7Length
, TrustedCert
, CertLength
, InData
, DataLength
), FALSE
);
2494 This function receives a PKCS7 formatted signature, and then verifies that
2495 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
2496 leaf signing certificate.
2497 Note that this function does not validate the certificate chain.
2499 Applications for custom EKU's are quite flexible. For example, a policy EKU
2500 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
2501 certificate issued might also contain this EKU, thus constraining the
2502 sub-ordinate certificate. Other applications might allow a certificate
2503 embedded in a device to specify that other Object Identifiers (OIDs) are
2504 present which contains binary data specifying custom capabilities that
2505 the device is able to do.
2507 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
2508 containing the content block with both the signature,
2509 the signer's certificate, and any necessary intermediate
2511 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
2512 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
2513 required EKUs that must be present in the signature.
2514 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
2515 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
2516 must be present in the leaf signer. If it is
2517 FALSE, then we will succeed if we find any
2518 of the specified EKU's.
2520 @retval EFI_SUCCESS The required EKUs were found in the signature.
2521 @retval EFI_INVALID_PARAMETER A parameter was invalid.
2522 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
2527 VerifyEKUsInPkcs7Signature (
2528 IN CONST UINT8
*Pkcs7Signature
,
2529 IN CONST UINT32 SignatureSize
,
2530 IN CONST CHAR8
*RequiredEKUs
[],
2531 IN CONST UINT32 RequiredEKUsSize
,
2532 IN BOOLEAN RequireAllPresent
2535 CALL_CRYPTO_SERVICE (VerifyEKUsInPkcs7Signature
, (Pkcs7Signature
, SignatureSize
, RequiredEKUs
, RequiredEKUsSize
, RequireAllPresent
), FALSE
);
2539 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2540 data could be wrapped in a ContentInfo structure.
2542 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2543 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2545 Caution: This function may receive untrusted input. So this function will do
2546 basic check for PKCS#7 data structure.
2548 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2549 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2550 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2551 It's caller's responsibility to free the buffer with FreePool().
2552 @param[out] ContentSize The size of the extracted content in bytes.
2554 @retval TRUE The P7Data was correctly formatted for processing.
2555 @retval FALSE The P7Data was not correctly formatted for processing.
2560 Pkcs7GetAttachedContent (
2561 IN CONST UINT8
*P7Data
,
2564 OUT UINTN
*ContentSize
2567 CALL_CRYPTO_SERVICE (Pkcs7GetAttachedContent
, (P7Data
, P7Length
, Content
, ContentSize
), FALSE
);
2571 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2572 Authenticode Portable Executable Signature Format".
2574 If AuthData is NULL, then return FALSE.
2575 If ImageHash is NULL, then return FALSE.
2576 If this interface is not supported, then return FALSE.
2578 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2579 PE/COFF image to be verified.
2580 @param[in] DataSize Size of the Authenticode Signature in bytes.
2581 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2582 is used for certificate chain verification.
2583 @param[in] CertSize Size of the trusted certificate in bytes.
2584 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2585 for calculating the image hash value is described in Authenticode
2587 @param[in] HashSize Size of Image hash value in bytes.
2589 @retval TRUE The specified Authenticode Signature is valid.
2590 @retval FALSE Invalid Authenticode Signature.
2591 @retval FALSE This interface is not supported.
2596 AuthenticodeVerify (
2597 IN CONST UINT8
*AuthData
,
2599 IN CONST UINT8
*TrustedCert
,
2601 IN CONST UINT8
*ImageHash
,
2605 CALL_CRYPTO_SERVICE (AuthenticodeVerify
, (AuthData
, DataSize
, TrustedCert
, CertSize
, ImageHash
, HashSize
), FALSE
);
2609 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2612 If AuthData is NULL, then return FALSE.
2613 If this interface is not supported, then return FALSE.
2615 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2616 PE/COFF image to be verified.
2617 @param[in] DataSize Size of the Authenticode Signature in bytes.
2618 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2619 is used for TSA certificate chain verification.
2620 @param[in] CertSize Size of the trusted certificate in bytes.
2621 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2624 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2625 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2630 ImageTimestampVerify (
2631 IN CONST UINT8
*AuthData
,
2633 IN CONST UINT8
*TsaCert
,
2635 OUT EFI_TIME
*SigningTime
2638 CALL_CRYPTO_SERVICE (ImageTimestampVerify
, (AuthData
, DataSize
, TsaCert
, CertSize
, SigningTime
), FALSE
);
2641 // =====================================================================================
2642 // DH Key Exchange Primitive
2643 // =====================================================================================
2646 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
2648 @return Pointer to the Diffie-Hellman Context that has been initialized.
2649 If the allocations fails, DhNew() returns NULL.
2650 If the interface is not supported, DhNew() returns NULL.
2659 CALL_CRYPTO_SERVICE (DhNew
, (), NULL
);
2663 Release the specified DH context.
2665 If the interface is not supported, then ASSERT().
2667 @param[in] DhContext Pointer to the DH context to be released.
2676 CALL_VOID_CRYPTO_SERVICE (DhFree
, (DhContext
));
2680 Generates DH parameter.
2682 Given generator g, and length of prime number p in bits, this function generates p,
2683 and sets DH context according to value of g and p.
2685 Before this function can be invoked, pseudorandom number generator must be correctly
2686 initialized by RandomSeed().
2688 If DhContext is NULL, then return FALSE.
2689 If Prime is NULL, then return FALSE.
2690 If this interface is not supported, then return FALSE.
2692 @param[in, out] DhContext Pointer to the DH context.
2693 @param[in] Generator Value of generator.
2694 @param[in] PrimeLength Length in bits of prime to be generated.
2695 @param[out] Prime Pointer to the buffer to receive the generated prime number.
2697 @retval TRUE DH parameter generation succeeded.
2698 @retval FALSE Value of Generator is not supported.
2699 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
2700 @retval FALSE This interface is not supported.
2705 DhGenerateParameter (
2706 IN OUT VOID
*DhContext
,
2708 IN UINTN PrimeLength
,
2712 CALL_CRYPTO_SERVICE (DhGenerateParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
2716 Sets generator and prime parameters for DH.
2718 Given generator g, and prime number p, this function and sets DH
2719 context accordingly.
2721 If DhContext is NULL, then return FALSE.
2722 If Prime is NULL, then return FALSE.
2723 If this interface is not supported, then return FALSE.
2725 @param[in, out] DhContext Pointer to the DH context.
2726 @param[in] Generator Value of generator.
2727 @param[in] PrimeLength Length in bits of prime to be generated.
2728 @param[in] Prime Pointer to the prime number.
2730 @retval TRUE DH parameter setting succeeded.
2731 @retval FALSE Value of Generator is not supported.
2732 @retval FALSE Value of Generator is not suitable for the Prime.
2733 @retval FALSE Value of Prime is not a prime number.
2734 @retval FALSE Value of Prime is not a safe prime number.
2735 @retval FALSE This interface is not supported.
2741 IN OUT VOID
*DhContext
,
2743 IN UINTN PrimeLength
,
2744 IN CONST UINT8
*Prime
2747 CALL_CRYPTO_SERVICE (DhSetParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
2751 Generates DH public key.
2753 This function generates random secret exponent, and computes the public key, which is
2754 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
2755 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
2756 PublicKeySize is set to the required buffer size to obtain the public key.
2758 If DhContext is NULL, then return FALSE.
2759 If PublicKeySize is NULL, then return FALSE.
2760 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
2761 If this interface is not supported, then return FALSE.
2763 @param[in, out] DhContext Pointer to the DH context.
2764 @param[out] PublicKey Pointer to the buffer to receive generated public key.
2765 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
2766 On output, the size of data returned in PublicKey buffer in bytes.
2768 @retval TRUE DH public key generation succeeded.
2769 @retval FALSE DH public key generation failed.
2770 @retval FALSE PublicKeySize is not large enough.
2771 @retval FALSE This interface is not supported.
2777 IN OUT VOID
*DhContext
,
2778 OUT UINT8
*PublicKey
,
2779 IN OUT UINTN
*PublicKeySize
2782 CALL_CRYPTO_SERVICE (DhGenerateKey
, (DhContext
, PublicKey
, PublicKeySize
), FALSE
);
2786 Computes exchanged common key.
2788 Given peer's public key, this function computes the exchanged common key, based on its own
2789 context including value of prime modulus and random secret exponent.
2791 If DhContext is NULL, then return FALSE.
2792 If PeerPublicKey is NULL, then return FALSE.
2793 If KeySize is NULL, then return FALSE.
2794 If Key is NULL, then return FALSE.
2795 If KeySize is not large enough, then return FALSE.
2796 If this interface is not supported, then return FALSE.
2798 @param[in, out] DhContext Pointer to the DH context.
2799 @param[in] PeerPublicKey Pointer to the peer's public key.
2800 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
2801 @param[out] Key Pointer to the buffer to receive generated key.
2802 @param[in, out] KeySize On input, the size of Key buffer in bytes.
2803 On output, the size of data returned in Key buffer in bytes.
2805 @retval TRUE DH exchanged key generation succeeded.
2806 @retval FALSE DH exchanged key generation failed.
2807 @retval FALSE KeySize is not large enough.
2808 @retval FALSE This interface is not supported.
2814 IN OUT VOID
*DhContext
,
2815 IN CONST UINT8
*PeerPublicKey
,
2816 IN UINTN PeerPublicKeySize
,
2818 IN OUT UINTN
*KeySize
2821 CALL_CRYPTO_SERVICE (DhComputeKey
, (DhContext
, PeerPublicKey
, PeerPublicKeySize
, Key
, KeySize
), FALSE
);
2824 // =====================================================================================
2825 // Pseudo-Random Generation Primitive
2826 // =====================================================================================
2829 Sets up the seed value for the pseudorandom number generator.
2831 This function sets up the seed value for the pseudorandom number generator.
2832 If Seed is not NULL, then the seed passed in is used.
2833 If Seed is NULL, then default seed is used.
2834 If this interface is not supported, then return FALSE.
2836 @param[in] Seed Pointer to seed value.
2837 If NULL, default seed is used.
2838 @param[in] SeedSize Size of seed value.
2839 If Seed is NULL, this parameter is ignored.
2841 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
2842 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
2843 @retval FALSE This interface is not supported.
2849 IN CONST UINT8
*Seed OPTIONAL
,
2853 CALL_CRYPTO_SERVICE (RandomSeed
, (Seed
, SeedSize
), FALSE
);
2857 Generates a pseudorandom byte stream of the specified size.
2859 If Output is NULL, then return FALSE.
2860 If this interface is not supported, then return FALSE.
2862 @param[out] Output Pointer to buffer to receive random value.
2863 @param[in] Size Size of random bytes to generate.
2865 @retval TRUE Pseudorandom byte stream generated successfully.
2866 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
2867 @retval FALSE This interface is not supported.
2877 CALL_CRYPTO_SERVICE (RandomBytes
, (Output
, Size
), FALSE
);
2880 // =====================================================================================
2881 // Key Derivation Function Primitive
2882 // =====================================================================================
2885 Derive key data using HMAC-SHA256 based KDF.
2887 @param[in] Key Pointer to the user-supplied key.
2888 @param[in] KeySize Key size in bytes.
2889 @param[in] Salt Pointer to the salt(non-secret) value.
2890 @param[in] SaltSize Salt size in bytes.
2891 @param[in] Info Pointer to the application specific info.
2892 @param[in] InfoSize Info size in bytes.
2893 @param[out] Out Pointer to buffer to receive hkdf value.
2894 @param[in] OutSize Size of hkdf bytes to generate.
2896 @retval TRUE Hkdf generated successfully.
2897 @retval FALSE Hkdf generation failed.
2902 HkdfSha256ExtractAndExpand (
2903 IN CONST UINT8
*Key
,
2905 IN CONST UINT8
*Salt
,
2907 IN CONST UINT8
*Info
,
2913 CALL_CRYPTO_SERVICE (HkdfSha256ExtractAndExpand
, (Key
, KeySize
, Salt
, SaltSize
, Info
, InfoSize
, Out
, OutSize
), FALSE
);
2917 Initializes the OpenSSL library.
2919 This function registers ciphers and digests used directly and indirectly
2920 by SSL/TLS, and initializes the readable error messages.
2921 This function must be called before any other action takes places.
2923 @retval TRUE The OpenSSL library has been initialized.
2924 @retval FALSE Failed to initialize the OpenSSL library.
2933 CALL_CRYPTO_SERVICE (TlsInitialize
, (), FALSE
);
2937 Free an allocated SSL_CTX object.
2939 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
2948 CALL_VOID_CRYPTO_SERVICE (TlsCtxFree
, (TlsCtx
));
2952 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
2955 @param[in] MajorVer Major Version of TLS/SSL Protocol.
2956 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
2958 @return Pointer to an allocated SSL_CTX object.
2959 If the creation failed, TlsCtxNew() returns NULL.
2969 CALL_CRYPTO_SERVICE (TlsCtxNew
, (MajorVer
, MinorVer
), NULL
);
2973 Free an allocated TLS object.
2975 This function removes the TLS object pointed to by Tls and frees up the
2976 allocated memory. If Tls is NULL, nothing is done.
2978 @param[in] Tls Pointer to the TLS object to be freed.
2987 CALL_VOID_CRYPTO_SERVICE (TlsFree
, (Tls
));
2991 Create a new TLS object for a connection.
2993 This function creates a new TLS object for a connection. The new object
2994 inherits the setting of the underlying context TlsCtx: connection method,
2995 options, verification setting.
2997 @param[in] TlsCtx Pointer to the SSL_CTX object.
2999 @return Pointer to an allocated SSL object.
3000 If the creation failed, TlsNew() returns NULL.
3009 CALL_CRYPTO_SERVICE (TlsNew
, (TlsCtx
), NULL
);
3013 Checks if the TLS handshake was done.
3015 This function will check if the specified TLS handshake was done.
3017 @param[in] Tls Pointer to the TLS object for handshake state checking.
3019 @retval TRUE The TLS handshake was done.
3020 @retval FALSE The TLS handshake was not done.
3029 CALL_CRYPTO_SERVICE (TlsInHandshake
, (Tls
), FALSE
);
3033 Perform a TLS/SSL handshake.
3035 This function will perform a TLS/SSL handshake.
3037 @param[in] Tls Pointer to the TLS object for handshake operation.
3038 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
3039 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3041 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3042 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3043 the buffer size provided by the caller. On output, it
3044 is the buffer size in fact needed to contain the
3047 @retval EFI_SUCCESS The required TLS packet is built successfully.
3048 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3050 BufferIn is NULL but BufferInSize is NOT 0.
3051 BufferInSize is 0 but BufferIn is NOT NULL.
3052 BufferOutSize is NULL.
3053 BufferOut is NULL if *BufferOutSize is not zero.
3054 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3055 @retval EFI_ABORTED Something wrong during handshake.
3062 IN UINT8
*BufferIn OPTIONAL
,
3063 IN UINTN BufferInSize OPTIONAL
,
3064 OUT UINT8
*BufferOut OPTIONAL
,
3065 IN OUT UINTN
*BufferOutSize
3068 CALL_CRYPTO_SERVICE (TlsDoHandshake
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
3072 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
3073 TLS session has errors and the response packet needs to be Alert message based on error type.
3075 @param[in] Tls Pointer to the TLS object for state checking.
3076 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
3077 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3079 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3080 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3081 the buffer size provided by the caller. On output, it
3082 is the buffer size in fact needed to contain the
3085 @retval EFI_SUCCESS The required TLS packet is built successfully.
3086 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3088 BufferIn is NULL but BufferInSize is NOT 0.
3089 BufferInSize is 0 but BufferIn is NOT NULL.
3090 BufferOutSize is NULL.
3091 BufferOut is NULL if *BufferOutSize is not zero.
3092 @retval EFI_ABORTED An error occurred.
3093 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3100 IN UINT8
*BufferIn OPTIONAL
,
3101 IN UINTN BufferInSize OPTIONAL
,
3102 OUT UINT8
*BufferOut OPTIONAL
,
3103 IN OUT UINTN
*BufferOutSize
3106 CALL_CRYPTO_SERVICE (TlsHandleAlert
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
3110 Build the CloseNotify packet.
3112 @param[in] Tls Pointer to the TLS object for state checking.
3113 @param[in, out] Buffer Pointer to the buffer to hold the built packet.
3114 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
3115 the buffer size provided by the caller. On output, it
3116 is the buffer size in fact needed to contain the
3119 @retval EFI_SUCCESS The required TLS packet is built successfully.
3120 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3123 Buffer is NULL if *BufferSize is not zero.
3124 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
3131 IN OUT UINT8
*Buffer
,
3132 IN OUT UINTN
*BufferSize
3135 CALL_CRYPTO_SERVICE (TlsCloseNotify
, (Tls
, Buffer
, BufferSize
), EFI_UNSUPPORTED
);
3139 Attempts to read bytes from one TLS object and places the data in Buffer.
3141 This function will attempt to read BufferSize bytes from the TLS object
3142 and places the data in Buffer.
3144 @param[in] Tls Pointer to the TLS object.
3145 @param[in,out] Buffer Pointer to the buffer to store the data.
3146 @param[in] BufferSize The size of Buffer in bytes.
3148 @retval >0 The amount of data successfully read from the TLS object.
3149 @retval <=0 No data was successfully read.
3156 IN OUT VOID
*Buffer
,
3160 CALL_CRYPTO_SERVICE (TlsCtrlTrafficOut
, (Tls
, Buffer
, BufferSize
), 0);
3164 Attempts to write data from the buffer to TLS object.
3166 This function will attempt to write BufferSize bytes data from the Buffer
3169 @param[in] Tls Pointer to the TLS object.
3170 @param[in] Buffer Pointer to the data buffer.
3171 @param[in] BufferSize The size of Buffer in bytes.
3173 @retval >0 The amount of data successfully written to the TLS object.
3174 @retval <=0 No data was successfully written.
3185 CALL_CRYPTO_SERVICE (TlsCtrlTrafficIn
, (Tls
, Buffer
, BufferSize
), 0);
3189 Attempts to read bytes from the specified TLS connection into the buffer.
3191 This function tries to read BufferSize bytes data from the specified TLS
3192 connection into the Buffer.
3194 @param[in] Tls Pointer to the TLS connection for data reading.
3195 @param[in,out] Buffer Pointer to the data buffer.
3196 @param[in] BufferSize The size of Buffer in bytes.
3198 @retval >0 The read operation was successful, and return value is the
3199 number of bytes actually read from the TLS connection.
3200 @retval <=0 The read operation was not successful.
3207 IN OUT VOID
*Buffer
,
3211 CALL_CRYPTO_SERVICE (TlsRead
, (Tls
, Buffer
, BufferSize
), 0);
3215 Attempts to write data to a TLS connection.
3217 This function tries to write BufferSize bytes data from the Buffer into the
3218 specified TLS connection.
3220 @param[in] Tls Pointer to the TLS connection for data writing.
3221 @param[in] Buffer Pointer to the data buffer.
3222 @param[in] BufferSize The size of Buffer in bytes.
3224 @retval >0 The write operation was successful, and return value is the
3225 number of bytes actually written to the TLS connection.
3226 @retval <=0 The write operation was not successful.
3237 CALL_CRYPTO_SERVICE (TlsWrite
, (Tls
, Buffer
, BufferSize
), 0);
3241 Set a new TLS/SSL method for a particular TLS object.
3243 This function sets a new TLS/SSL method for a particular TLS object.
3245 @param[in] Tls Pointer to a TLS object.
3246 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3247 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3249 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
3250 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3251 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
3262 CALL_CRYPTO_SERVICE (TlsSetVersion
, (Tls
, MajorVer
, MinorVer
), EFI_UNSUPPORTED
);
3266 Set TLS object to work in client or server mode.
3268 This function prepares a TLS object to work in client or server mode.
3270 @param[in] Tls Pointer to a TLS object.
3271 @param[in] IsServer Work in server mode.
3273 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
3274 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3275 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
3280 TlsSetConnectionEnd (
3285 CALL_CRYPTO_SERVICE (TlsSetConnectionEnd
, (Tls
, IsServer
), EFI_UNSUPPORTED
);
3289 Set the ciphers list to be used by the TLS object.
3291 This function sets the ciphers for use by a specified TLS object.
3293 @param[in] Tls Pointer to a TLS object.
3294 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
3295 cipher identifier comes from the TLS Cipher Suite
3296 Registry of the IANA, interpreting Byte1 and Byte2
3297 in network (big endian) byte order.
3298 @param[in] CipherNum The number of cipher in the list.
3300 @retval EFI_SUCCESS The ciphers list was set successfully.
3301 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3302 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
3303 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
3310 IN UINT16
*CipherId
,
3314 CALL_CRYPTO_SERVICE (TlsSetCipherList
, (Tls
, CipherId
, CipherNum
), EFI_UNSUPPORTED
);
3318 Set the compression method for TLS/SSL operations.
3320 This function handles TLS/SSL integrated compression methods.
3322 @param[in] CompMethod The compression method ID.
3324 @retval EFI_SUCCESS The compression method for the communication was
3326 @retval EFI_UNSUPPORTED Unsupported compression method.
3331 TlsSetCompressionMethod (
3335 CALL_CRYPTO_SERVICE (TlsSetCompressionMethod
, (CompMethod
), EFI_UNSUPPORTED
);
3339 Set peer certificate verification mode for the TLS connection.
3341 This function sets the verification mode flags for the TLS connection.
3343 @param[in] Tls Pointer to the TLS object.
3344 @param[in] VerifyMode A set of logically or'ed verification mode flags.
3351 IN UINT32 VerifyMode
3354 CALL_VOID_CRYPTO_SERVICE (TlsSetVerify
, (Tls
, VerifyMode
));
3358 Set the specified host name to be verified.
3360 @param[in] Tls Pointer to the TLS object.
3361 @param[in] Flags The setting flags during the validation.
3362 @param[in] HostName The specified host name to be verified.
3364 @retval EFI_SUCCESS The HostName setting was set successfully.
3365 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3366 @retval EFI_ABORTED Invalid HostName setting.
3377 CALL_CRYPTO_SERVICE (TlsSetVerifyHost
, (Tls
, Flags
, HostName
), EFI_UNSUPPORTED
);
3381 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
3383 This function sets a session ID to be used when the TLS/SSL connection is
3386 @param[in] Tls Pointer to the TLS object.
3387 @param[in] SessionId Session ID data used for session resumption.
3388 @param[in] SessionIdLen Length of Session ID in bytes.
3390 @retval EFI_SUCCESS Session ID was set successfully.
3391 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3392 @retval EFI_UNSUPPORTED No available session for ID setting.
3399 IN UINT8
*SessionId
,
3400 IN UINT16 SessionIdLen
3403 CALL_CRYPTO_SERVICE (TlsSetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
3407 Adds the CA to the cert store when requesting Server or Client authentication.
3409 This function adds the CA certificate to the list of CAs when requesting
3410 Server or Client authentication for the chosen TLS connection.
3412 @param[in] Tls Pointer to the TLS object.
3413 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3414 X.509 certificate or PEM-encoded X.509 certificate.
3415 @param[in] DataSize The size of data buffer in bytes.
3417 @retval EFI_SUCCESS The operation succeeded.
3418 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3419 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3420 @retval EFI_ABORTED Invalid X.509 certificate.
3425 TlsSetCaCertificate (
3431 CALL_CRYPTO_SERVICE (TlsSetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3435 Loads the local public certificate into the specified TLS object.
3437 This function loads the X.509 certificate into the specified TLS object
3438 for TLS negotiation.
3440 @param[in] Tls Pointer to the TLS object.
3441 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3442 X.509 certificate or PEM-encoded X.509 certificate.
3443 @param[in] DataSize The size of data buffer in bytes.
3445 @retval EFI_SUCCESS The operation succeeded.
3446 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3447 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3448 @retval EFI_ABORTED Invalid X.509 certificate.
3453 TlsSetHostPublicCert (
3459 CALL_CRYPTO_SERVICE (TlsSetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3463 Adds the local private key to the specified TLS object.
3465 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
3466 key) into the specified TLS object for TLS negotiation.
3468 @param[in] Tls Pointer to the TLS object.
3469 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
3470 or PKCS#8 private key.
3471 @param[in] DataSize The size of data buffer in bytes.
3473 @retval EFI_SUCCESS The operation succeeded.
3474 @retval EFI_UNSUPPORTED This function is not supported.
3475 @retval EFI_ABORTED Invalid private key data.
3480 TlsSetHostPrivateKey (
3486 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3490 Adds the CA-supplied certificate revocation list for certificate validation.
3492 This function adds the CA-supplied certificate revocation list data for
3493 certificate validity checking.
3495 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
3496 @param[in] DataSize The size of data buffer in bytes.
3498 @retval EFI_SUCCESS The operation succeeded.
3499 @retval EFI_UNSUPPORTED This function is not supported.
3500 @retval EFI_ABORTED Invalid CRL data.
3505 TlsSetCertRevocationList (
3510 CALL_CRYPTO_SERVICE (TlsSetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);
3514 Gets the protocol version used by the specified TLS connection.
3516 This function returns the protocol version used by the specified TLS
3519 If Tls is NULL, then ASSERT().
3521 @param[in] Tls Pointer to the TLS object.
3523 @return The protocol version of the specified TLS connection.
3532 CALL_CRYPTO_SERVICE (TlsGetVersion
, (Tls
), 0);
3536 Gets the connection end of the specified TLS connection.
3538 This function returns the connection end (as client or as server) used by
3539 the specified TLS connection.
3541 If Tls is NULL, then ASSERT().
3543 @param[in] Tls Pointer to the TLS object.
3545 @return The connection end used by the specified TLS connection.
3550 TlsGetConnectionEnd (
3554 CALL_CRYPTO_SERVICE (TlsGetConnectionEnd
, (Tls
), 0);
3558 Gets the cipher suite used by the specified TLS connection.
3560 This function returns current cipher suite used by the specified
3563 @param[in] Tls Pointer to the TLS object.
3564 @param[in,out] CipherId The cipher suite used by the TLS object.
3566 @retval EFI_SUCCESS The cipher suite was returned successfully.
3567 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3568 @retval EFI_UNSUPPORTED Unsupported cipher suite.
3573 TlsGetCurrentCipher (
3575 IN OUT UINT16
*CipherId
3578 CALL_CRYPTO_SERVICE (TlsGetCurrentCipher
, (Tls
, CipherId
), EFI_UNSUPPORTED
);
3582 Gets the compression methods used by the specified TLS connection.
3584 This function returns current integrated compression methods used by
3585 the specified TLS connection.
3587 @param[in] Tls Pointer to the TLS object.
3588 @param[in,out] CompressionId The current compression method used by
3591 @retval EFI_SUCCESS The compression method was returned successfully.
3592 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3593 @retval EFI_ABORTED Invalid Compression method.
3594 @retval EFI_UNSUPPORTED This function is not supported.
3599 TlsGetCurrentCompressionId (
3601 IN OUT UINT8
*CompressionId
3604 CALL_CRYPTO_SERVICE (TlsGetCurrentCompressionId
, (Tls
, CompressionId
), EFI_UNSUPPORTED
);
3608 Gets the verification mode currently set in the TLS connection.
3610 This function returns the peer verification mode currently set in the
3611 specified TLS connection.
3613 If Tls is NULL, then ASSERT().
3615 @param[in] Tls Pointer to the TLS object.
3617 @return The verification mode set in the specified TLS connection.
3626 CALL_CRYPTO_SERVICE (TlsGetVerify
, (Tls
), 0);
3630 Gets the session ID used by the specified TLS connection.
3632 This function returns the TLS/SSL session ID currently used by the
3633 specified TLS connection.
3635 @param[in] Tls Pointer to the TLS object.
3636 @param[in,out] SessionId Buffer to contain the returned session ID.
3637 @param[in,out] SessionIdLen The length of Session ID in bytes.
3639 @retval EFI_SUCCESS The Session ID was returned successfully.
3640 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3641 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
3648 IN OUT UINT8
*SessionId
,
3649 IN OUT UINT16
*SessionIdLen
3652 CALL_CRYPTO_SERVICE (TlsGetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
3656 Gets the client random data used in the specified TLS connection.
3658 This function returns the TLS/SSL client random data currently used in
3659 the specified TLS connection.
3661 @param[in] Tls Pointer to the TLS object.
3662 @param[in,out] ClientRandom Buffer to contain the returned client
3663 random data (32 bytes).
3668 TlsGetClientRandom (
3670 IN OUT UINT8
*ClientRandom
3673 CALL_VOID_CRYPTO_SERVICE (TlsGetClientRandom
, (Tls
, ClientRandom
));
3677 Gets the server random data used in the specified TLS connection.
3679 This function returns the TLS/SSL server random data currently used in
3680 the specified TLS connection.
3682 @param[in] Tls Pointer to the TLS object.
3683 @param[in,out] ServerRandom Buffer to contain the returned server
3684 random data (32 bytes).
3689 TlsGetServerRandom (
3691 IN OUT UINT8
*ServerRandom
3694 CALL_VOID_CRYPTO_SERVICE (TlsGetServerRandom
, (Tls
, ServerRandom
));
3698 Gets the master key data used in the specified TLS connection.
3700 This function returns the TLS/SSL master key material currently used in
3701 the specified TLS connection.
3703 @param[in] Tls Pointer to the TLS object.
3704 @param[in,out] KeyMaterial Buffer to contain the returned key material.
3706 @retval EFI_SUCCESS Key material was returned successfully.
3707 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3708 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
3715 IN OUT UINT8
*KeyMaterial
3718 CALL_CRYPTO_SERVICE (TlsGetKeyMaterial
, (Tls
, KeyMaterial
), EFI_UNSUPPORTED
);
3722 Gets the CA Certificate from the cert store.
3724 This function returns the CA certificate for the chosen
3727 @param[in] Tls Pointer to the TLS object.
3728 @param[out] Data Pointer to the data buffer to receive the CA
3729 certificate data sent to the client.
3730 @param[in,out] DataSize The size of data buffer in bytes.
3732 @retval EFI_SUCCESS The operation succeeded.
3733 @retval EFI_UNSUPPORTED This function is not supported.
3734 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3739 TlsGetCaCertificate (
3742 IN OUT UINTN
*DataSize
3745 CALL_CRYPTO_SERVICE (TlsGetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3749 Gets the local public Certificate set in the specified TLS object.
3751 This function returns the local public certificate which was currently set
3752 in the specified TLS object.
3754 @param[in] Tls Pointer to the TLS object.
3755 @param[out] Data Pointer to the data buffer to receive the local
3757 @param[in,out] DataSize The size of data buffer in bytes.
3759 @retval EFI_SUCCESS The operation succeeded.
3760 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3761 @retval EFI_NOT_FOUND The certificate is not found.
3762 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3767 TlsGetHostPublicCert (
3770 IN OUT UINTN
*DataSize
3773 CALL_CRYPTO_SERVICE (TlsGetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3777 Gets the local private key set in the specified TLS object.
3779 This function returns the local private key data which was currently set
3780 in the specified TLS object.
3782 @param[in] Tls Pointer to the TLS object.
3783 @param[out] Data Pointer to the data buffer to receive the local
3785 @param[in,out] DataSize The size of data buffer in bytes.
3787 @retval EFI_SUCCESS The operation succeeded.
3788 @retval EFI_UNSUPPORTED This function is not supported.
3789 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3794 TlsGetHostPrivateKey (
3797 IN OUT UINTN
*DataSize
3800 CALL_CRYPTO_SERVICE (TlsGetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3804 Gets the CA-supplied certificate revocation list data set in the specified
3807 This function returns the CA-supplied certificate revocation list data which
3808 was currently set in the specified TLS object.
3810 @param[out] Data Pointer to the data buffer to receive the CRL data.
3811 @param[in,out] DataSize The size of data buffer in bytes.
3813 @retval EFI_SUCCESS The operation succeeded.
3814 @retval EFI_UNSUPPORTED This function is not supported.
3815 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3820 TlsGetCertRevocationList (
3822 IN OUT UINTN
*DataSize
3825 CALL_CRYPTO_SERVICE (TlsGetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);