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 // Authenticated Encryption with Associated Data (AEAD) Cryptography Primitive
1557 // =====================================================================================
1560 Performs AEAD AES-GCM authenticated encryption on a data buffer and additional authenticated data (AAD).
1562 IvSize must be 12, otherwise FALSE is returned.
1563 KeySize must be 16, 24 or 32, otherwise FALSE is returned.
1564 TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.
1566 @param[in] Key Pointer to the encryption key.
1567 @param[in] KeySize Size of the encryption key in bytes.
1568 @param[in] Iv Pointer to the IV value.
1569 @param[in] IvSize Size of the IV value in bytes.
1570 @param[in] AData Pointer to the additional authenticated data (AAD).
1571 @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.
1572 @param[in] DataIn Pointer to the input data buffer to be encrypted.
1573 @param[in] DataInSize Size of the input data buffer in bytes.
1574 @param[out] TagOut Pointer to a buffer that receives the authentication tag output.
1575 @param[in] TagSize Size of the authentication tag in bytes.
1576 @param[out] DataOut Pointer to a buffer that receives the encryption output.
1577 @param[out] DataOutSize Size of the output data buffer in bytes.
1579 @retval TRUE AEAD AES-GCM authenticated encryption succeeded.
1580 @retval FALSE AEAD AES-GCM authenticated encryption failed.
1586 IN CONST UINT8
*Key
,
1590 IN CONST UINT8
*AData
,
1592 IN CONST UINT8
*DataIn
,
1593 IN UINTN DataInSize
,
1597 OUT UINTN
*DataOutSize
1600 CALL_CRYPTO_SERVICE (AeadAesGcmEncrypt
, (Key
, KeySize
, Iv
, IvSize
, AData
, ADataSize
, DataIn
, DataInSize
, TagOut
, TagSize
, DataOut
, DataOutSize
), FALSE
);
1604 Performs AEAD AES-GCM authenticated decryption on a data buffer and additional authenticated data (AAD).
1606 IvSize must be 12, otherwise FALSE is returned.
1607 KeySize must be 16, 24 or 32, otherwise FALSE is returned.
1608 TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.
1609 If additional authenticated data verification fails, FALSE is returned.
1611 @param[in] Key Pointer to the encryption key.
1612 @param[in] KeySize Size of the encryption key in bytes.
1613 @param[in] Iv Pointer to the IV value.
1614 @param[in] IvSize Size of the IV value in bytes.
1615 @param[in] AData Pointer to the additional authenticated data (AAD).
1616 @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.
1617 @param[in] DataIn Pointer to the input data buffer to be decrypted.
1618 @param[in] DataInSize Size of the input data buffer in bytes.
1619 @param[in] Tag Pointer to a buffer that contains the authentication tag.
1620 @param[in] TagSize Size of the authentication tag in bytes.
1621 @param[out] DataOut Pointer to a buffer that receives the decryption output.
1622 @param[out] DataOutSize Size of the output data buffer in bytes.
1624 @retval TRUE AEAD AES-GCM authenticated decryption succeeded.
1625 @retval FALSE AEAD AES-GCM authenticated decryption failed.
1631 IN CONST UINT8
*Key
,
1635 IN CONST UINT8
*AData
,
1637 IN CONST UINT8
*DataIn
,
1638 IN UINTN DataInSize
,
1639 IN CONST UINT8
*Tag
,
1642 OUT UINTN
*DataOutSize
1645 CALL_CRYPTO_SERVICE (AeadAesGcmDecrypt
, (Key
, KeySize
, Iv
, IvSize
, AData
, ADataSize
, DataIn
, DataInSize
, Tag
, TagSize
, DataOut
, DataOutSize
), FALSE
);
1648 // =====================================================================================
1649 // Asymmetric Cryptography Primitive
1650 // =====================================================================================
1653 Allocates and initializes one RSA context for subsequent use.
1655 @return Pointer to the RSA context that has been initialized.
1656 If the allocations fails, RsaNew() returns NULL.
1665 CALL_CRYPTO_SERVICE (RsaNew
, (), NULL
);
1669 Release the specified RSA context.
1671 If RsaContext is NULL, then return FALSE.
1673 @param[in] RsaContext Pointer to the RSA context to be released.
1682 CALL_VOID_CRYPTO_SERVICE (RsaFree
, (RsaContext
));
1686 Sets the tag-designated key component into the established RSA context.
1688 This function sets the tag-designated RSA key component into the established
1689 RSA context from the user-specified non-negative integer (octet string format
1690 represented in RSA PKCS#1).
1691 If BigNumber is NULL, then the specified key component in RSA context is cleared.
1693 If RsaContext is NULL, then return FALSE.
1695 @param[in, out] RsaContext Pointer to RSA context being set.
1696 @param[in] KeyTag Tag of RSA key component being set.
1697 @param[in] BigNumber Pointer to octet integer buffer.
1698 If NULL, then the specified key component in RSA
1700 @param[in] BnSize Size of big number buffer in bytes.
1701 If BigNumber is NULL, then it is ignored.
1703 @retval TRUE RSA key component was set successfully.
1704 @retval FALSE Invalid RSA key component tag.
1710 IN OUT VOID
*RsaContext
,
1711 IN RSA_KEY_TAG KeyTag
,
1712 IN CONST UINT8
*BigNumber
,
1716 CALL_CRYPTO_SERVICE (RsaSetKey
, (RsaContext
, KeyTag
, BigNumber
, BnSize
), FALSE
);
1720 Gets the tag-designated RSA key component from the established RSA context.
1722 This function retrieves the tag-designated RSA key component from the
1723 established RSA context as a non-negative integer (octet string format
1724 represented in RSA PKCS#1).
1725 If specified key component has not been set or has been cleared, then returned
1727 If the BigNumber buffer is too small to hold the contents of the key, FALSE
1728 is returned and BnSize is set to the required buffer size to obtain the key.
1730 If RsaContext is NULL, then return FALSE.
1731 If BnSize is NULL, then return FALSE.
1732 If BnSize is large enough but BigNumber is NULL, then return FALSE.
1733 If this interface is not supported, then return FALSE.
1735 @param[in, out] RsaContext Pointer to RSA context being set.
1736 @param[in] KeyTag Tag of RSA key component being set.
1737 @param[out] BigNumber Pointer to octet integer buffer.
1738 @param[in, out] BnSize On input, the size of big number buffer in bytes.
1739 On output, the size of data returned in big number buffer in bytes.
1741 @retval TRUE RSA key component was retrieved successfully.
1742 @retval FALSE Invalid RSA key component tag.
1743 @retval FALSE BnSize is too small.
1744 @retval FALSE This interface is not supported.
1750 IN OUT VOID
*RsaContext
,
1751 IN RSA_KEY_TAG KeyTag
,
1752 OUT UINT8
*BigNumber
,
1753 IN OUT UINTN
*BnSize
1756 CALL_CRYPTO_SERVICE (RsaGetKey
, (RsaContext
, KeyTag
, BigNumber
, BnSize
), FALSE
);
1760 Generates RSA key components.
1762 This function generates RSA key components. It takes RSA public exponent E and
1763 length in bits of RSA modulus N as input, and generates all key components.
1764 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
1766 Before this function can be invoked, pseudorandom number generator must be correctly
1767 initialized by RandomSeed().
1769 If RsaContext is NULL, then return FALSE.
1770 If this interface is not supported, then return FALSE.
1772 @param[in, out] RsaContext Pointer to RSA context being set.
1773 @param[in] ModulusLength Length of RSA modulus N in bits.
1774 @param[in] PublicExponent Pointer to RSA public exponent.
1775 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
1777 @retval TRUE RSA key component was generated successfully.
1778 @retval FALSE Invalid RSA key component tag.
1779 @retval FALSE This interface is not supported.
1785 IN OUT VOID
*RsaContext
,
1786 IN UINTN ModulusLength
,
1787 IN CONST UINT8
*PublicExponent
,
1788 IN UINTN PublicExponentSize
1791 CALL_CRYPTO_SERVICE (RsaGenerateKey
, (RsaContext
, ModulusLength
, PublicExponent
, PublicExponentSize
), FALSE
);
1795 Validates key components of RSA context.
1796 NOTE: This function performs integrity checks on all the RSA key material, so
1797 the RSA key structure must contain all the private key data.
1799 This function validates key components of RSA context in following aspects:
1800 - Whether p is a prime
1801 - Whether q is a prime
1803 - Whether d*e = 1 mod lcm(p-1,q-1)
1805 If RsaContext is NULL, then return FALSE.
1806 If this interface is not supported, then return FALSE.
1808 @param[in] RsaContext Pointer to RSA context to check.
1810 @retval TRUE RSA key components are valid.
1811 @retval FALSE RSA key components are not valid.
1812 @retval FALSE This interface is not supported.
1821 CALL_CRYPTO_SERVICE (RsaCheckKey
, (RsaContext
), FALSE
);
1825 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
1827 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
1829 If the Signature buffer is too small to hold the contents of signature, FALSE
1830 is returned and SigSize is set to the required buffer size to obtain the signature.
1832 If RsaContext is NULL, then return FALSE.
1833 If MessageHash is NULL, then return FALSE.
1834 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
1835 If SigSize is large enough but Signature is NULL, then return FALSE.
1836 If this interface is not supported, then return FALSE.
1838 @param[in] RsaContext Pointer to RSA context for signature generation.
1839 @param[in] MessageHash Pointer to octet message hash to be signed.
1840 @param[in] HashSize Size of the message hash in bytes.
1841 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
1842 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1843 On output, the size of data returned in Signature buffer in bytes.
1845 @retval TRUE Signature successfully generated in PKCS1-v1_5.
1846 @retval FALSE Signature generation failed.
1847 @retval FALSE SigSize is too small.
1848 @retval FALSE This interface is not supported.
1854 IN VOID
*RsaContext
,
1855 IN CONST UINT8
*MessageHash
,
1857 OUT UINT8
*Signature
,
1858 IN OUT UINTN
*SigSize
1861 CALL_CRYPTO_SERVICE (RsaPkcs1Sign
, (RsaContext
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
1865 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
1868 If RsaContext is NULL, then return FALSE.
1869 If MessageHash is NULL, then return FALSE.
1870 If Signature is NULL, then return FALSE.
1871 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
1873 @param[in] RsaContext Pointer to RSA context for signature verification.
1874 @param[in] MessageHash Pointer to octet message hash to be checked.
1875 @param[in] HashSize Size of the message hash in bytes.
1876 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
1877 @param[in] SigSize Size of signature in bytes.
1879 @retval TRUE Valid signature encoded in PKCS1-v1_5.
1880 @retval FALSE Invalid signature or invalid RSA context.
1886 IN VOID
*RsaContext
,
1887 IN CONST UINT8
*MessageHash
,
1889 IN CONST UINT8
*Signature
,
1893 CALL_CRYPTO_SERVICE (RsaPkcs1Verify
, (RsaContext
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
1897 Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
1898 Implementation determines salt length automatically from the signature encoding.
1899 Mask generation function is the same as the message digest algorithm.
1900 Salt length should be equal to digest length.
1902 @param[in] RsaContext Pointer to RSA context for signature verification.
1903 @param[in] Message Pointer to octet message to be verified.
1904 @param[in] MsgSize Size of the message in bytes.
1905 @param[in] Signature Pointer to RSASSA-PSS signature to be verified.
1906 @param[in] SigSize Size of signature in bytes.
1907 @param[in] DigestLen Length of digest for RSA operation.
1908 @param[in] SaltLen Salt length for PSS encoding.
1910 @retval TRUE Valid signature encoded in RSASSA-PSS.
1911 @retval FALSE Invalid signature or invalid RSA context.
1917 IN VOID
*RsaContext
,
1918 IN CONST UINT8
*Message
,
1920 IN CONST UINT8
*Signature
,
1922 IN UINT16 DigestLen
,
1926 CALL_CRYPTO_SERVICE (RsaPssVerify
, (RsaContext
, Message
, MsgSize
, Signature
, SigSize
, DigestLen
, SaltLen
), FALSE
);
1930 This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in
1932 Mask generation function is the same as the message digest algorithm.
1933 If the Signature buffer is too small to hold the contents of signature, FALSE
1934 is returned and SigSize is set to the required buffer size to obtain the signature.
1936 If RsaContext is NULL, then return FALSE.
1937 If Message is NULL, then return FALSE.
1938 If MsgSize is zero or > INT_MAX, then return FALSE.
1939 If DigestLen is NOT 32, 48 or 64, return FALSE.
1940 If SaltLen is not equal to DigestLen, then return FALSE.
1941 If SigSize is large enough but Signature is NULL, then return FALSE.
1942 If this interface is not supported, then return FALSE.
1944 @param[in] RsaContext Pointer to RSA context for signature generation.
1945 @param[in] Message Pointer to octet message to be signed.
1946 @param[in] MsgSize Size of the message in bytes.
1947 @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.
1948 @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.
1949 @param[out] Signature Pointer to buffer to receive RSA PSS signature.
1950 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1951 On output, the size of data returned in Signature buffer in bytes.
1953 @retval TRUE Signature successfully generated in RSASSA-PSS.
1954 @retval FALSE Signature generation failed.
1955 @retval FALSE SigSize is too small.
1956 @retval FALSE This interface is not supported.
1962 IN VOID
*RsaContext
,
1963 IN CONST UINT8
*Message
,
1965 IN UINT16 DigestLen
,
1967 OUT UINT8
*Signature
,
1968 IN OUT UINTN
*SigSize
1971 CALL_CRYPTO_SERVICE (RsaPssSign
, (RsaContext
, Message
, MsgSize
, DigestLen
, SaltLen
, Signature
, SigSize
), FALSE
);
1975 Retrieve the RSA Private Key from the password-protected PEM key data.
1977 If PemData is NULL, then return FALSE.
1978 If RsaContext is NULL, then return FALSE.
1979 If this interface is not supported, then return FALSE.
1981 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
1982 @param[in] PemSize Size of the PEM key data in bytes.
1983 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
1984 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1985 RSA private key component. Use RsaFree() function to free the
1988 @retval TRUE RSA Private Key was retrieved successfully.
1989 @retval FALSE Invalid PEM key data or incorrect password.
1990 @retval FALSE This interface is not supported.
1995 RsaGetPrivateKeyFromPem (
1996 IN CONST UINT8
*PemData
,
1998 IN CONST CHAR8
*Password
,
1999 OUT VOID
**RsaContext
2002 CALL_CRYPTO_SERVICE (RsaGetPrivateKeyFromPem
, (PemData
, PemSize
, Password
, RsaContext
), FALSE
);
2006 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
2008 If Cert is NULL, then return FALSE.
2009 If RsaContext is NULL, then return FALSE.
2010 If this interface is not supported, then return FALSE.
2012 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2013 @param[in] CertSize Size of the X509 certificate in bytes.
2014 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2015 RSA public key component. Use RsaFree() function to free the
2018 @retval TRUE RSA Public Key was retrieved successfully.
2019 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
2020 @retval FALSE This interface is not supported.
2025 RsaGetPublicKeyFromX509 (
2026 IN CONST UINT8
*Cert
,
2028 OUT VOID
**RsaContext
2031 CALL_CRYPTO_SERVICE (RsaGetPublicKeyFromX509
, (Cert
, CertSize
, RsaContext
), FALSE
);
2035 Retrieve the subject bytes from one X.509 certificate.
2037 If Cert is NULL, then return FALSE.
2038 If SubjectSize is NULL, then return FALSE.
2039 If this interface is not supported, then return FALSE.
2041 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2042 @param[in] CertSize Size of the X509 certificate in bytes.
2043 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
2044 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
2045 and the size of buffer returned CertSubject on output.
2047 @retval TRUE The certificate subject retrieved successfully.
2048 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
2049 The SubjectSize will be updated with the required size.
2050 @retval FALSE This interface is not supported.
2055 X509GetSubjectName (
2056 IN CONST UINT8
*Cert
,
2058 OUT UINT8
*CertSubject
,
2059 IN OUT UINTN
*SubjectSize
2062 CALL_CRYPTO_SERVICE (X509GetSubjectName
, (Cert
, CertSize
, CertSubject
, SubjectSize
), FALSE
);
2066 Retrieve the common name (CN) string from one X.509 certificate.
2068 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2069 @param[in] CertSize Size of the X509 certificate in bytes.
2070 @param[out] CommonName Buffer to contain the retrieved certificate common
2071 name string (UTF8). At most CommonNameSize bytes will be
2072 written and the string will be null terminated. May be
2073 NULL in order to determine the size buffer needed.
2074 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
2075 and the size of buffer returned CommonName on output.
2076 If CommonName is NULL then the amount of space needed
2077 in buffer (including the final null) is returned.
2079 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
2080 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2081 If CommonNameSize is NULL.
2082 If CommonName is not NULL and *CommonNameSize is 0.
2083 If Certificate is invalid.
2084 @retval RETURN_NOT_FOUND If no CommonName entry exists.
2085 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
2086 (including the final null) is returned in the
2087 CommonNameSize parameter.
2088 @retval RETURN_UNSUPPORTED The operation is not supported.
2094 IN CONST UINT8
*Cert
,
2096 OUT CHAR8
*CommonName OPTIONAL
,
2097 IN OUT UINTN
*CommonNameSize
2100 CALL_CRYPTO_SERVICE (X509GetCommonName
, (Cert
, CertSize
, CommonName
, CommonNameSize
), RETURN_UNSUPPORTED
);
2104 Retrieve the organization name (O) string from one X.509 certificate.
2106 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2107 @param[in] CertSize Size of the X509 certificate in bytes.
2108 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
2109 name string. At most NameBufferSize bytes will be
2110 written and the string will be null terminated. May be
2111 NULL in order to determine the size buffer needed.
2112 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
2113 and the size of buffer returned Name on output.
2114 If NameBuffer is NULL then the amount of space needed
2115 in buffer (including the final null) is returned.
2117 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
2118 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2119 If NameBufferSize is NULL.
2120 If NameBuffer is not NULL and *CommonNameSize is 0.
2121 If Certificate is invalid.
2122 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
2123 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
2124 (including the final null) is returned in the
2125 CommonNameSize parameter.
2126 @retval RETURN_UNSUPPORTED The operation is not supported.
2131 X509GetOrganizationName (
2132 IN CONST UINT8
*Cert
,
2134 OUT CHAR8
*NameBuffer OPTIONAL
,
2135 IN OUT UINTN
*NameBufferSize
2138 CALL_CRYPTO_SERVICE (X509GetOrganizationName
, (Cert
, CertSize
, NameBuffer
, NameBufferSize
), RETURN_UNSUPPORTED
);
2142 Verify one X509 certificate was issued by the trusted CA.
2144 If Cert is NULL, then return FALSE.
2145 If CACert is NULL, then return FALSE.
2146 If this interface is not supported, then return FALSE.
2148 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
2149 @param[in] CertSize Size of the X509 certificate in bytes.
2150 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
2151 @param[in] CACertSize Size of the CA Certificate in bytes.
2153 @retval TRUE The certificate was issued by the trusted CA.
2154 @retval FALSE Invalid certificate or the certificate was not issued by the given
2156 @retval FALSE This interface is not supported.
2162 IN CONST UINT8
*Cert
,
2164 IN CONST UINT8
*CACert
,
2168 CALL_CRYPTO_SERVICE (X509VerifyCert
, (Cert
, CertSize
, CACert
, CACertSize
), FALSE
);
2172 Construct a X509 object from DER-encoded certificate data.
2174 If Cert is NULL, then return FALSE.
2175 If SingleX509Cert is NULL, then return FALSE.
2176 If this interface is not supported, then return FALSE.
2178 @param[in] Cert Pointer to the DER-encoded certificate data.
2179 @param[in] CertSize The size of certificate data in bytes.
2180 @param[out] SingleX509Cert The generated X509 object.
2182 @retval TRUE The X509 object generation succeeded.
2183 @retval FALSE The operation failed.
2184 @retval FALSE This interface is not supported.
2189 X509ConstructCertificate (
2190 IN CONST UINT8
*Cert
,
2192 OUT UINT8
**SingleX509Cert
2195 CALL_CRYPTO_SERVICE (X509ConstructCertificate
, (Cert
, CertSize
, SingleX509Cert
), FALSE
);
2199 Construct a X509 stack object from a list of DER-encoded certificate data.
2201 If X509Stack is NULL, then return FALSE.
2202 If this interface is not supported, then return FALSE.
2204 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2205 On output, pointer to the X509 stack object with new
2206 inserted X509 certificate.
2207 @param[in] Args VA_LIST marker for the variable argument list.
2208 ... A list of DER-encoded single certificate data followed
2209 by certificate size. A NULL terminates the list. The
2210 pairs are the arguments to X509ConstructCertificate().
2212 @retval TRUE The X509 stack construction succeeded.
2213 @retval FALSE The construction operation failed.
2214 @retval FALSE This interface is not supported.
2219 X509ConstructCertificateStack (
2220 IN OUT UINT8
**X509Stack
,
2227 VA_START (Args
, X509Stack
);
2228 Result
= X509ConstructCertificateStackV (X509Stack
, Args
);
2234 Construct a X509 stack object from a list of DER-encoded certificate data.
2236 If X509Stack is NULL, then return FALSE.
2237 If this interface is not supported, then return FALSE.
2239 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2240 On output, pointer to the X509 stack object with new
2241 inserted X509 certificate.
2242 @param[in] Args VA_LIST marker for the variable argument list.
2243 A list of DER-encoded single certificate data followed
2244 by certificate size. A NULL terminates the list. The
2245 pairs are the arguments to X509ConstructCertificate().
2247 @retval TRUE The X509 stack construction succeeded.
2248 @retval FALSE The construction operation failed.
2249 @retval FALSE This interface is not supported.
2254 X509ConstructCertificateStackV (
2255 IN OUT UINT8
**X509Stack
,
2259 CALL_CRYPTO_SERVICE (X509ConstructCertificateStackV
, (X509Stack
, Args
), FALSE
);
2263 Release the specified X509 object.
2265 If the interface is not supported, then ASSERT().
2267 @param[in] X509Cert Pointer to the X509 object to be released.
2276 CALL_VOID_CRYPTO_SERVICE (X509Free
, (X509Cert
));
2280 Release the specified X509 stack object.
2282 If the interface is not supported, then ASSERT().
2284 @param[in] X509Stack Pointer to the X509 stack object to be released.
2293 CALL_VOID_CRYPTO_SERVICE (X509StackFree
, (X509Stack
));
2297 Retrieve the TBSCertificate from one given X.509 certificate.
2299 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
2300 @param[in] CertSize Size of the X509 certificate in bytes.
2301 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
2302 @param[out] TBSCertSize Size of the TBS certificate in bytes.
2304 If Cert is NULL, then return FALSE.
2305 If TBSCert is NULL, then return FALSE.
2306 If TBSCertSize is NULL, then return FALSE.
2307 If this interface is not supported, then return FALSE.
2309 @retval TRUE The TBSCertificate was retrieved successfully.
2310 @retval FALSE Invalid X.509 certificate.
2316 IN CONST UINT8
*Cert
,
2318 OUT UINT8
**TBSCert
,
2319 OUT UINTN
*TBSCertSize
2322 CALL_CRYPTO_SERVICE (X509GetTBSCert
, (Cert
, CertSize
, TBSCert
, TBSCertSize
), FALSE
);
2326 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2327 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2329 If Password or Salt or OutKey is NULL, then return FALSE.
2330 If the hash algorithm could not be determined, then return FALSE.
2331 If this interface is not supported, then return FALSE.
2333 @param[in] PasswordLength Length of input password in bytes.
2334 @param[in] Password Pointer to the array for the password.
2335 @param[in] SaltLength Size of the Salt in bytes.
2336 @param[in] Salt Pointer to the Salt.
2337 @param[in] IterationCount Number of iterations to perform. Its value should be
2338 greater than or equal to 1.
2339 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2340 NOTE: DigestSize will be used to determine the hash algorithm.
2341 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2342 @param[in] KeyLength Size of the derived key buffer in bytes.
2343 @param[out] OutKey Pointer to the output derived key buffer.
2345 @retval TRUE A key was derived successfully.
2346 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2347 @retval FALSE The hash algorithm could not be determined from the digest size.
2348 @retval FALSE The key derivation operation failed.
2349 @retval FALSE This interface is not supported.
2355 IN UINTN PasswordLength
,
2356 IN CONST CHAR8
*Password
,
2357 IN UINTN SaltLength
,
2358 IN CONST UINT8
*Salt
,
2359 IN UINTN IterationCount
,
2360 IN UINTN DigestSize
,
2365 CALL_CRYPTO_SERVICE (Pkcs5HashPassword
, (PasswordLength
, Password
, SaltLength
, Salt
, IterationCount
, DigestSize
, KeyLength
, OutKey
), FALSE
);
2369 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2370 encrypted message in a newly allocated buffer.
2372 Things that can cause a failure include:
2373 - X509 key size does not match any known key size.
2374 - Fail to parse X509 certificate.
2375 - Fail to allocate an intermediate buffer.
2376 - Null pointer provided for a non-optional parameter.
2377 - Data size is too large for the provided key size (max size is a function of key size
2378 and hash digest size).
2380 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2381 will be used to encrypt the data.
2382 @param[in] PublicKeySize Size of the X509 cert buffer.
2383 @param[in] InData Data to be encrypted.
2384 @param[in] InDataSize Size of the data buffer.
2385 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2386 to be used when initializing the PRNG. NULL otherwise.
2387 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2389 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2391 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2393 @retval TRUE Encryption was successful.
2394 @retval FALSE Encryption failed.
2400 IN CONST UINT8
*PublicKey
,
2401 IN UINTN PublicKeySize
,
2403 IN UINTN InDataSize
,
2404 IN CONST UINT8
*PrngSeed OPTIONAL
,
2405 IN UINTN PrngSeedSize OPTIONAL
,
2406 OUT UINT8
**EncryptedData
,
2407 OUT UINTN
*EncryptedDataSize
2410 CALL_CRYPTO_SERVICE (Pkcs1v2Encrypt
, (PublicKey
, PublicKeySize
, InData
, InDataSize
, PrngSeed
, PrngSeedSize
, EncryptedData
, EncryptedDataSize
), FALSE
);
2414 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2415 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2416 in a ContentInfo structure.
2418 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2419 return FALSE. If P7Length overflow, then return FALSE.
2420 If this interface is not supported, then return FALSE.
2422 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2423 @param[in] P7Length Length of the PKCS#7 message in bytes.
2424 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2425 It's caller's responsibility to free the buffer with
2427 This data structure is EFI_CERT_STACK type.
2428 @param[out] StackLength Length of signer's certificates in bytes.
2429 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2430 It's caller's responsibility to free the buffer with
2432 @param[out] CertLength Length of the trusted certificate in bytes.
2434 @retval TRUE The operation is finished successfully.
2435 @retval FALSE Error occurs during the operation.
2436 @retval FALSE This interface is not supported.
2442 IN CONST UINT8
*P7Data
,
2444 OUT UINT8
**CertStack
,
2445 OUT UINTN
*StackLength
,
2446 OUT UINT8
**TrustedCert
,
2447 OUT UINTN
*CertLength
2450 CALL_CRYPTO_SERVICE (Pkcs7GetSigners
, (P7Data
, P7Length
, CertStack
, StackLength
, TrustedCert
, CertLength
), FALSE
);
2454 Wrap function to use free() to free allocated memory for certificates.
2456 If this interface is not supported, then ASSERT().
2458 @param[in] Certs Pointer to the certificates to be freed.
2467 CALL_VOID_CRYPTO_SERVICE (Pkcs7FreeSigners
, (Certs
));
2471 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2472 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2473 unchained to the signer's certificates.
2474 The input signed data could be wrapped in a ContentInfo structure.
2476 @param[in] P7Data Pointer to the PKCS#7 message.
2477 @param[in] P7Length Length of the PKCS#7 message in bytes.
2478 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2479 certificate. It's caller's responsibility to free the buffer
2480 with Pkcs7FreeSigners().
2481 This data structure is EFI_CERT_STACK type.
2482 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2483 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2484 responsibility to free the buffer with Pkcs7FreeSigners().
2485 This data structure is EFI_CERT_STACK type.
2486 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2488 @retval TRUE The operation is finished successfully.
2489 @retval FALSE Error occurs during the operation.
2494 Pkcs7GetCertificatesList (
2495 IN CONST UINT8
*P7Data
,
2497 OUT UINT8
**SignerChainCerts
,
2498 OUT UINTN
*ChainLength
,
2499 OUT UINT8
**UnchainCerts
,
2500 OUT UINTN
*UnchainLength
2503 CALL_CRYPTO_SERVICE (Pkcs7GetCertificatesList
, (P7Data
, P7Length
, SignerChainCerts
, ChainLength
, UnchainCerts
, UnchainLength
), FALSE
);
2507 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2508 Syntax Standard, version 1.5". This interface is only intended to be used for
2509 application to perform PKCS#7 functionality validation.
2511 If this interface is not supported, then return FALSE.
2513 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2515 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2516 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2518 @param[in] InData Pointer to the content to be signed.
2519 @param[in] InDataSize Size of InData in bytes.
2520 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2521 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2522 include in the PKCS#7 signedData (e.g. any intermediate
2524 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2525 responsibility to free the buffer with FreePool().
2526 @param[out] SignedDataSize Size of SignedData in bytes.
2528 @retval TRUE PKCS#7 data signing succeeded.
2529 @retval FALSE PKCS#7 data signing failed.
2530 @retval FALSE This interface is not supported.
2536 IN CONST UINT8
*PrivateKey
,
2537 IN UINTN PrivateKeySize
,
2538 IN CONST UINT8
*KeyPassword
,
2540 IN UINTN InDataSize
,
2542 IN UINT8
*OtherCerts OPTIONAL
,
2543 OUT UINT8
**SignedData
,
2544 OUT UINTN
*SignedDataSize
2547 CALL_CRYPTO_SERVICE (Pkcs7Sign
, (PrivateKey
, PrivateKeySize
, KeyPassword
, InData
, InDataSize
, SignCert
, OtherCerts
, SignedData
, SignedDataSize
), FALSE
);
2551 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2552 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2553 in a ContentInfo structure.
2555 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2556 If P7Length, CertLength or DataLength overflow, then return FALSE.
2557 If this interface is not supported, then return FALSE.
2559 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2560 @param[in] P7Length Length of the PKCS#7 message in bytes.
2561 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2562 is used for certificate chain verification.
2563 @param[in] CertLength Length of the trusted certificate in bytes.
2564 @param[in] InData Pointer to the content to be verified.
2565 @param[in] DataLength Length of InData in bytes.
2567 @retval TRUE The specified PKCS#7 signed data is valid.
2568 @retval FALSE Invalid PKCS#7 signed data.
2569 @retval FALSE This interface is not supported.
2575 IN CONST UINT8
*P7Data
,
2577 IN CONST UINT8
*TrustedCert
,
2578 IN UINTN CertLength
,
2579 IN CONST UINT8
*InData
,
2583 CALL_CRYPTO_SERVICE (Pkcs7Verify
, (P7Data
, P7Length
, TrustedCert
, CertLength
, InData
, DataLength
), FALSE
);
2587 This function receives a PKCS7 formatted signature, and then verifies that
2588 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
2589 leaf signing certificate.
2590 Note that this function does not validate the certificate chain.
2592 Applications for custom EKU's are quite flexible. For example, a policy EKU
2593 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
2594 certificate issued might also contain this EKU, thus constraining the
2595 sub-ordinate certificate. Other applications might allow a certificate
2596 embedded in a device to specify that other Object Identifiers (OIDs) are
2597 present which contains binary data specifying custom capabilities that
2598 the device is able to do.
2600 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
2601 containing the content block with both the signature,
2602 the signer's certificate, and any necessary intermediate
2604 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
2605 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
2606 required EKUs that must be present in the signature.
2607 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
2608 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
2609 must be present in the leaf signer. If it is
2610 FALSE, then we will succeed if we find any
2611 of the specified EKU's.
2613 @retval EFI_SUCCESS The required EKUs were found in the signature.
2614 @retval EFI_INVALID_PARAMETER A parameter was invalid.
2615 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
2620 VerifyEKUsInPkcs7Signature (
2621 IN CONST UINT8
*Pkcs7Signature
,
2622 IN CONST UINT32 SignatureSize
,
2623 IN CONST CHAR8
*RequiredEKUs
[],
2624 IN CONST UINT32 RequiredEKUsSize
,
2625 IN BOOLEAN RequireAllPresent
2628 CALL_CRYPTO_SERVICE (VerifyEKUsInPkcs7Signature
, (Pkcs7Signature
, SignatureSize
, RequiredEKUs
, RequiredEKUsSize
, RequireAllPresent
), FALSE
);
2632 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2633 data could be wrapped in a ContentInfo structure.
2635 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2636 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2638 Caution: This function may receive untrusted input. So this function will do
2639 basic check for PKCS#7 data structure.
2641 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2642 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2643 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2644 It's caller's responsibility to free the buffer with FreePool().
2645 @param[out] ContentSize The size of the extracted content in bytes.
2647 @retval TRUE The P7Data was correctly formatted for processing.
2648 @retval FALSE The P7Data was not correctly formatted for processing.
2653 Pkcs7GetAttachedContent (
2654 IN CONST UINT8
*P7Data
,
2657 OUT UINTN
*ContentSize
2660 CALL_CRYPTO_SERVICE (Pkcs7GetAttachedContent
, (P7Data
, P7Length
, Content
, ContentSize
), FALSE
);
2664 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2665 Authenticode Portable Executable Signature Format".
2667 If AuthData is NULL, then return FALSE.
2668 If ImageHash is NULL, then return FALSE.
2669 If this interface is not supported, then return FALSE.
2671 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2672 PE/COFF image to be verified.
2673 @param[in] DataSize Size of the Authenticode Signature in bytes.
2674 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2675 is used for certificate chain verification.
2676 @param[in] CertSize Size of the trusted certificate in bytes.
2677 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2678 for calculating the image hash value is described in Authenticode
2680 @param[in] HashSize Size of Image hash value in bytes.
2682 @retval TRUE The specified Authenticode Signature is valid.
2683 @retval FALSE Invalid Authenticode Signature.
2684 @retval FALSE This interface is not supported.
2689 AuthenticodeVerify (
2690 IN CONST UINT8
*AuthData
,
2692 IN CONST UINT8
*TrustedCert
,
2694 IN CONST UINT8
*ImageHash
,
2698 CALL_CRYPTO_SERVICE (AuthenticodeVerify
, (AuthData
, DataSize
, TrustedCert
, CertSize
, ImageHash
, HashSize
), FALSE
);
2702 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2705 If AuthData is NULL, then return FALSE.
2706 If this interface is not supported, then return FALSE.
2708 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2709 PE/COFF image to be verified.
2710 @param[in] DataSize Size of the Authenticode Signature in bytes.
2711 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2712 is used for TSA certificate chain verification.
2713 @param[in] CertSize Size of the trusted certificate in bytes.
2714 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2717 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2718 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2723 ImageTimestampVerify (
2724 IN CONST UINT8
*AuthData
,
2726 IN CONST UINT8
*TsaCert
,
2728 OUT EFI_TIME
*SigningTime
2731 CALL_CRYPTO_SERVICE (ImageTimestampVerify
, (AuthData
, DataSize
, TsaCert
, CertSize
, SigningTime
), FALSE
);
2734 // =====================================================================================
2735 // DH Key Exchange Primitive
2736 // =====================================================================================
2739 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
2741 @return Pointer to the Diffie-Hellman Context that has been initialized.
2742 If the allocations fails, DhNew() returns NULL.
2743 If the interface is not supported, DhNew() returns NULL.
2752 CALL_CRYPTO_SERVICE (DhNew
, (), NULL
);
2756 Release the specified DH context.
2758 If the interface is not supported, then ASSERT().
2760 @param[in] DhContext Pointer to the DH context to be released.
2769 CALL_VOID_CRYPTO_SERVICE (DhFree
, (DhContext
));
2773 Generates DH parameter.
2775 Given generator g, and length of prime number p in bits, this function generates p,
2776 and sets DH context according to value of g and p.
2778 Before this function can be invoked, pseudorandom number generator must be correctly
2779 initialized by RandomSeed().
2781 If DhContext is NULL, then return FALSE.
2782 If Prime is NULL, then return FALSE.
2783 If this interface is not supported, then return FALSE.
2785 @param[in, out] DhContext Pointer to the DH context.
2786 @param[in] Generator Value of generator.
2787 @param[in] PrimeLength Length in bits of prime to be generated.
2788 @param[out] Prime Pointer to the buffer to receive the generated prime number.
2790 @retval TRUE DH parameter generation succeeded.
2791 @retval FALSE Value of Generator is not supported.
2792 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
2793 @retval FALSE This interface is not supported.
2798 DhGenerateParameter (
2799 IN OUT VOID
*DhContext
,
2801 IN UINTN PrimeLength
,
2805 CALL_CRYPTO_SERVICE (DhGenerateParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
2809 Sets generator and prime parameters for DH.
2811 Given generator g, and prime number p, this function and sets DH
2812 context accordingly.
2814 If DhContext is NULL, then return FALSE.
2815 If Prime is NULL, then return FALSE.
2816 If this interface is not supported, then return FALSE.
2818 @param[in, out] DhContext Pointer to the DH context.
2819 @param[in] Generator Value of generator.
2820 @param[in] PrimeLength Length in bits of prime to be generated.
2821 @param[in] Prime Pointer to the prime number.
2823 @retval TRUE DH parameter setting succeeded.
2824 @retval FALSE Value of Generator is not supported.
2825 @retval FALSE Value of Generator is not suitable for the Prime.
2826 @retval FALSE Value of Prime is not a prime number.
2827 @retval FALSE Value of Prime is not a safe prime number.
2828 @retval FALSE This interface is not supported.
2834 IN OUT VOID
*DhContext
,
2836 IN UINTN PrimeLength
,
2837 IN CONST UINT8
*Prime
2840 CALL_CRYPTO_SERVICE (DhSetParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
2844 Generates DH public key.
2846 This function generates random secret exponent, and computes the public key, which is
2847 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
2848 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
2849 PublicKeySize is set to the required buffer size to obtain the public key.
2851 If DhContext is NULL, then return FALSE.
2852 If PublicKeySize is NULL, then return FALSE.
2853 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
2854 If this interface is not supported, then return FALSE.
2856 @param[in, out] DhContext Pointer to the DH context.
2857 @param[out] PublicKey Pointer to the buffer to receive generated public key.
2858 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
2859 On output, the size of data returned in PublicKey buffer in bytes.
2861 @retval TRUE DH public key generation succeeded.
2862 @retval FALSE DH public key generation failed.
2863 @retval FALSE PublicKeySize is not large enough.
2864 @retval FALSE This interface is not supported.
2870 IN OUT VOID
*DhContext
,
2871 OUT UINT8
*PublicKey
,
2872 IN OUT UINTN
*PublicKeySize
2875 CALL_CRYPTO_SERVICE (DhGenerateKey
, (DhContext
, PublicKey
, PublicKeySize
), FALSE
);
2879 Computes exchanged common key.
2881 Given peer's public key, this function computes the exchanged common key, based on its own
2882 context including value of prime modulus and random secret exponent.
2884 If DhContext is NULL, then return FALSE.
2885 If PeerPublicKey is NULL, then return FALSE.
2886 If KeySize is NULL, then return FALSE.
2887 If Key is NULL, then return FALSE.
2888 If KeySize is not large enough, then return FALSE.
2889 If this interface is not supported, then return FALSE.
2891 @param[in, out] DhContext Pointer to the DH context.
2892 @param[in] PeerPublicKey Pointer to the peer's public key.
2893 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
2894 @param[out] Key Pointer to the buffer to receive generated key.
2895 @param[in, out] KeySize On input, the size of Key buffer in bytes.
2896 On output, the size of data returned in Key buffer in bytes.
2898 @retval TRUE DH exchanged key generation succeeded.
2899 @retval FALSE DH exchanged key generation failed.
2900 @retval FALSE KeySize is not large enough.
2901 @retval FALSE This interface is not supported.
2907 IN OUT VOID
*DhContext
,
2908 IN CONST UINT8
*PeerPublicKey
,
2909 IN UINTN PeerPublicKeySize
,
2911 IN OUT UINTN
*KeySize
2914 CALL_CRYPTO_SERVICE (DhComputeKey
, (DhContext
, PeerPublicKey
, PeerPublicKeySize
, Key
, KeySize
), FALSE
);
2917 // =====================================================================================
2918 // Pseudo-Random Generation Primitive
2919 // =====================================================================================
2922 Sets up the seed value for the pseudorandom number generator.
2924 This function sets up the seed value for the pseudorandom number generator.
2925 If Seed is not NULL, then the seed passed in is used.
2926 If Seed is NULL, then default seed is used.
2927 If this interface is not supported, then return FALSE.
2929 @param[in] Seed Pointer to seed value.
2930 If NULL, default seed is used.
2931 @param[in] SeedSize Size of seed value.
2932 If Seed is NULL, this parameter is ignored.
2934 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
2935 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
2936 @retval FALSE This interface is not supported.
2942 IN CONST UINT8
*Seed OPTIONAL
,
2946 CALL_CRYPTO_SERVICE (RandomSeed
, (Seed
, SeedSize
), FALSE
);
2950 Generates a pseudorandom byte stream of the specified size.
2952 If Output is NULL, then return FALSE.
2953 If this interface is not supported, then return FALSE.
2955 @param[out] Output Pointer to buffer to receive random value.
2956 @param[in] Size Size of random bytes to generate.
2958 @retval TRUE Pseudorandom byte stream generated successfully.
2959 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
2960 @retval FALSE This interface is not supported.
2970 CALL_CRYPTO_SERVICE (RandomBytes
, (Output
, Size
), FALSE
);
2973 // =====================================================================================
2974 // Key Derivation Function Primitive
2975 // =====================================================================================
2978 Derive key data using HMAC-SHA256 based KDF.
2980 @param[in] Key Pointer to the user-supplied key.
2981 @param[in] KeySize Key size in bytes.
2982 @param[in] Salt Pointer to the salt(non-secret) value.
2983 @param[in] SaltSize Salt size in bytes.
2984 @param[in] Info Pointer to the application specific info.
2985 @param[in] InfoSize Info size in bytes.
2986 @param[out] Out Pointer to buffer to receive hkdf value.
2987 @param[in] OutSize Size of hkdf bytes to generate.
2989 @retval TRUE Hkdf generated successfully.
2990 @retval FALSE Hkdf generation failed.
2995 HkdfSha256ExtractAndExpand (
2996 IN CONST UINT8
*Key
,
2998 IN CONST UINT8
*Salt
,
3000 IN CONST UINT8
*Info
,
3006 CALL_CRYPTO_SERVICE (HkdfSha256ExtractAndExpand
, (Key
, KeySize
, Salt
, SaltSize
, Info
, InfoSize
, Out
, OutSize
), FALSE
);
3010 Derive SHA256 HMAC-based Extract key Derivation Function (HKDF).
3012 @param[in] Key Pointer to the user-supplied key.
3013 @param[in] KeySize key size in bytes.
3014 @param[in] Salt Pointer to the salt(non-secret) value.
3015 @param[in] SaltSize salt size in bytes.
3016 @param[out] PrkOut Pointer to buffer to receive hkdf value.
3017 @param[in] PrkOutSize size of hkdf bytes to generate.
3019 @retval true Hkdf generated successfully.
3020 @retval false Hkdf generation failed.
3026 IN CONST UINT8
*Key
,
3028 IN CONST UINT8
*Salt
,
3034 CALL_CRYPTO_SERVICE (HkdfSha256Extract
, (Key
, KeySize
, Salt
, SaltSize
, PrkOut
, PrkOutSize
), FALSE
);
3038 Derive SHA256 HMAC-based Expand Key Derivation Function (HKDF).
3040 @param[in] Prk Pointer to the user-supplied key.
3041 @param[in] PrkSize Key size in bytes.
3042 @param[in] Info Pointer to the application specific info.
3043 @param[in] InfoSize Info size in bytes.
3044 @param[out] Out Pointer to buffer to receive hkdf value.
3045 @param[in] OutSize Size of hkdf bytes to generate.
3047 @retval TRUE Hkdf generated successfully.
3048 @retval FALSE Hkdf generation failed.
3054 IN CONST UINT8
*Prk
,
3056 IN CONST UINT8
*Info
,
3062 CALL_CRYPTO_SERVICE (HkdfSha256Expand
, (Prk
, PrkSize
, Info
, InfoSize
, Out
, OutSize
), FALSE
);
3066 Derive SHA384 HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
3068 @param[in] Key Pointer to the user-supplied key.
3069 @param[in] KeySize Key size in bytes.
3070 @param[in] Salt Pointer to the salt(non-secret) value.
3071 @param[in] SaltSize Salt size in bytes.
3072 @param[in] Info Pointer to the application specific info.
3073 @param[in] InfoSize Info size in bytes.
3074 @param[out] Out Pointer to buffer to receive hkdf value.
3075 @param[in] OutSize Size of hkdf bytes to generate.
3077 @retval TRUE Hkdf generated successfully.
3078 @retval FALSE Hkdf generation failed.
3083 HkdfSha384ExtractAndExpand (
3084 IN CONST UINT8
*Key
,
3086 IN CONST UINT8
*Salt
,
3088 IN CONST UINT8
*Info
,
3094 CALL_CRYPTO_SERVICE (HkdfSha384ExtractAndExpand
, (Key
, KeySize
, Salt
, SaltSize
, Info
, InfoSize
, Out
, OutSize
), FALSE
);
3098 Derive SHA384 HMAC-based Extract key Derivation Function (HKDF).
3100 @param[in] Key Pointer to the user-supplied key.
3101 @param[in] KeySize key size in bytes.
3102 @param[in] Salt Pointer to the salt(non-secret) value.
3103 @param[in] SaltSize salt size in bytes.
3104 @param[out] PrkOut Pointer to buffer to receive hkdf value.
3105 @param[in] PrkOutSize size of hkdf bytes to generate.
3107 @retval true Hkdf generated successfully.
3108 @retval false Hkdf generation failed.
3114 IN CONST UINT8
*Key
,
3116 IN CONST UINT8
*Salt
,
3122 CALL_CRYPTO_SERVICE (HkdfSha384Extract
, (Key
, KeySize
, Salt
, SaltSize
, PrkOut
, PrkOutSize
), FALSE
);
3126 Derive SHA384 HMAC-based Expand Key Derivation Function (HKDF).
3128 @param[in] Prk Pointer to the user-supplied key.
3129 @param[in] PrkSize Key size in bytes.
3130 @param[in] Info Pointer to the application specific info.
3131 @param[in] InfoSize Info size in bytes.
3132 @param[out] Out Pointer to buffer to receive hkdf value.
3133 @param[in] OutSize Size of hkdf bytes to generate.
3135 @retval TRUE Hkdf generated successfully.
3136 @retval FALSE Hkdf generation failed.
3142 IN CONST UINT8
*Prk
,
3144 IN CONST UINT8
*Info
,
3150 CALL_CRYPTO_SERVICE (HkdfSha384Expand
, (Prk
, PrkSize
, Info
, InfoSize
, Out
, OutSize
), FALSE
);
3154 Initializes the OpenSSL library.
3156 This function registers ciphers and digests used directly and indirectly
3157 by SSL/TLS, and initializes the readable error messages.
3158 This function must be called before any other action takes places.
3160 @retval TRUE The OpenSSL library has been initialized.
3161 @retval FALSE Failed to initialize the OpenSSL library.
3170 CALL_CRYPTO_SERVICE (TlsInitialize
, (), FALSE
);
3174 Free an allocated SSL_CTX object.
3176 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
3185 CALL_VOID_CRYPTO_SERVICE (TlsCtxFree
, (TlsCtx
));
3189 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
3192 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3193 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3195 @return Pointer to an allocated SSL_CTX object.
3196 If the creation failed, TlsCtxNew() returns NULL.
3206 CALL_CRYPTO_SERVICE (TlsCtxNew
, (MajorVer
, MinorVer
), NULL
);
3210 Free an allocated TLS object.
3212 This function removes the TLS object pointed to by Tls and frees up the
3213 allocated memory. If Tls is NULL, nothing is done.
3215 @param[in] Tls Pointer to the TLS object to be freed.
3224 CALL_VOID_CRYPTO_SERVICE (TlsFree
, (Tls
));
3228 Create a new TLS object for a connection.
3230 This function creates a new TLS object for a connection. The new object
3231 inherits the setting of the underlying context TlsCtx: connection method,
3232 options, verification setting.
3234 @param[in] TlsCtx Pointer to the SSL_CTX object.
3236 @return Pointer to an allocated SSL object.
3237 If the creation failed, TlsNew() returns NULL.
3246 CALL_CRYPTO_SERVICE (TlsNew
, (TlsCtx
), NULL
);
3250 Checks if the TLS handshake was done.
3252 This function will check if the specified TLS handshake was done.
3254 @param[in] Tls Pointer to the TLS object for handshake state checking.
3256 @retval TRUE The TLS handshake was done.
3257 @retval FALSE The TLS handshake was not done.
3266 CALL_CRYPTO_SERVICE (TlsInHandshake
, (Tls
), FALSE
);
3270 Perform a TLS/SSL handshake.
3272 This function will perform a TLS/SSL handshake.
3274 @param[in] Tls Pointer to the TLS object for handshake operation.
3275 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
3276 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3278 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3279 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3280 the buffer size provided by the caller. On output, it
3281 is the buffer size in fact needed to contain the
3284 @retval EFI_SUCCESS The required TLS packet is built successfully.
3285 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3287 BufferIn is NULL but BufferInSize is NOT 0.
3288 BufferInSize is 0 but BufferIn is NOT NULL.
3289 BufferOutSize is NULL.
3290 BufferOut is NULL if *BufferOutSize is not zero.
3291 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3292 @retval EFI_ABORTED Something wrong during handshake.
3299 IN UINT8
*BufferIn OPTIONAL
,
3300 IN UINTN BufferInSize OPTIONAL
,
3301 OUT UINT8
*BufferOut OPTIONAL
,
3302 IN OUT UINTN
*BufferOutSize
3305 CALL_CRYPTO_SERVICE (TlsDoHandshake
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
3309 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
3310 TLS session has errors and the response packet needs to be Alert message based on error type.
3312 @param[in] Tls Pointer to the TLS object for state checking.
3313 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
3314 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3316 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3317 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3318 the buffer size provided by the caller. On output, it
3319 is the buffer size in fact needed to contain the
3322 @retval EFI_SUCCESS The required TLS packet is built successfully.
3323 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3325 BufferIn is NULL but BufferInSize is NOT 0.
3326 BufferInSize is 0 but BufferIn is NOT NULL.
3327 BufferOutSize is NULL.
3328 BufferOut is NULL if *BufferOutSize is not zero.
3329 @retval EFI_ABORTED An error occurred.
3330 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3337 IN UINT8
*BufferIn OPTIONAL
,
3338 IN UINTN BufferInSize OPTIONAL
,
3339 OUT UINT8
*BufferOut OPTIONAL
,
3340 IN OUT UINTN
*BufferOutSize
3343 CALL_CRYPTO_SERVICE (TlsHandleAlert
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
3347 Build the CloseNotify packet.
3349 @param[in] Tls Pointer to the TLS object for state checking.
3350 @param[in, out] Buffer Pointer to the buffer to hold the built packet.
3351 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
3352 the buffer size provided by the caller. On output, it
3353 is the buffer size in fact needed to contain the
3356 @retval EFI_SUCCESS The required TLS packet is built successfully.
3357 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3360 Buffer is NULL if *BufferSize is not zero.
3361 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
3368 IN OUT UINT8
*Buffer
,
3369 IN OUT UINTN
*BufferSize
3372 CALL_CRYPTO_SERVICE (TlsCloseNotify
, (Tls
, Buffer
, BufferSize
), EFI_UNSUPPORTED
);
3376 Attempts to read bytes from one TLS object and places the data in Buffer.
3378 This function will attempt to read BufferSize bytes from the TLS object
3379 and places the data in Buffer.
3381 @param[in] Tls Pointer to the TLS object.
3382 @param[in,out] Buffer Pointer to the buffer to store the data.
3383 @param[in] BufferSize The size of Buffer in bytes.
3385 @retval >0 The amount of data successfully read from the TLS object.
3386 @retval <=0 No data was successfully read.
3393 IN OUT VOID
*Buffer
,
3397 CALL_CRYPTO_SERVICE (TlsCtrlTrafficOut
, (Tls
, Buffer
, BufferSize
), 0);
3401 Attempts to write data from the buffer to TLS object.
3403 This function will attempt to write BufferSize bytes data from the Buffer
3406 @param[in] Tls Pointer to the TLS object.
3407 @param[in] Buffer Pointer to the data buffer.
3408 @param[in] BufferSize The size of Buffer in bytes.
3410 @retval >0 The amount of data successfully written to the TLS object.
3411 @retval <=0 No data was successfully written.
3422 CALL_CRYPTO_SERVICE (TlsCtrlTrafficIn
, (Tls
, Buffer
, BufferSize
), 0);
3426 Attempts to read bytes from the specified TLS connection into the buffer.
3428 This function tries to read BufferSize bytes data from the specified TLS
3429 connection into the Buffer.
3431 @param[in] Tls Pointer to the TLS connection for data reading.
3432 @param[in,out] Buffer Pointer to the data buffer.
3433 @param[in] BufferSize The size of Buffer in bytes.
3435 @retval >0 The read operation was successful, and return value is the
3436 number of bytes actually read from the TLS connection.
3437 @retval <=0 The read operation was not successful.
3444 IN OUT VOID
*Buffer
,
3448 CALL_CRYPTO_SERVICE (TlsRead
, (Tls
, Buffer
, BufferSize
), 0);
3452 Attempts to write data to a TLS connection.
3454 This function tries to write BufferSize bytes data from the Buffer into the
3455 specified TLS connection.
3457 @param[in] Tls Pointer to the TLS connection for data writing.
3458 @param[in] Buffer Pointer to the data buffer.
3459 @param[in] BufferSize The size of Buffer in bytes.
3461 @retval >0 The write operation was successful, and return value is the
3462 number of bytes actually written to the TLS connection.
3463 @retval <=0 The write operation was not successful.
3474 CALL_CRYPTO_SERVICE (TlsWrite
, (Tls
, Buffer
, BufferSize
), 0);
3478 Set a new TLS/SSL method for a particular TLS object.
3480 This function sets a new TLS/SSL method for a particular TLS object.
3482 @param[in] Tls Pointer to a TLS object.
3483 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3484 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3486 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
3487 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3488 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
3499 CALL_CRYPTO_SERVICE (TlsSetVersion
, (Tls
, MajorVer
, MinorVer
), EFI_UNSUPPORTED
);
3503 Set TLS object to work in client or server mode.
3505 This function prepares a TLS object to work in client or server mode.
3507 @param[in] Tls Pointer to a TLS object.
3508 @param[in] IsServer Work in server mode.
3510 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
3511 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3512 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
3517 TlsSetConnectionEnd (
3522 CALL_CRYPTO_SERVICE (TlsSetConnectionEnd
, (Tls
, IsServer
), EFI_UNSUPPORTED
);
3526 Set the ciphers list to be used by the TLS object.
3528 This function sets the ciphers for use by a specified TLS object.
3530 @param[in] Tls Pointer to a TLS object.
3531 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
3532 cipher identifier comes from the TLS Cipher Suite
3533 Registry of the IANA, interpreting Byte1 and Byte2
3534 in network (big endian) byte order.
3535 @param[in] CipherNum The number of cipher in the list.
3537 @retval EFI_SUCCESS The ciphers list was set successfully.
3538 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3539 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
3540 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
3547 IN UINT16
*CipherId
,
3551 CALL_CRYPTO_SERVICE (TlsSetCipherList
, (Tls
, CipherId
, CipherNum
), EFI_UNSUPPORTED
);
3555 Set the compression method for TLS/SSL operations.
3557 This function handles TLS/SSL integrated compression methods.
3559 @param[in] CompMethod The compression method ID.
3561 @retval EFI_SUCCESS The compression method for the communication was
3563 @retval EFI_UNSUPPORTED Unsupported compression method.
3568 TlsSetCompressionMethod (
3572 CALL_CRYPTO_SERVICE (TlsSetCompressionMethod
, (CompMethod
), EFI_UNSUPPORTED
);
3576 Set peer certificate verification mode for the TLS connection.
3578 This function sets the verification mode flags for the TLS connection.
3580 @param[in] Tls Pointer to the TLS object.
3581 @param[in] VerifyMode A set of logically or'ed verification mode flags.
3588 IN UINT32 VerifyMode
3591 CALL_VOID_CRYPTO_SERVICE (TlsSetVerify
, (Tls
, VerifyMode
));
3595 Set the specified host name to be verified.
3597 @param[in] Tls Pointer to the TLS object.
3598 @param[in] Flags The setting flags during the validation.
3599 @param[in] HostName The specified host name to be verified.
3601 @retval EFI_SUCCESS The HostName setting was set successfully.
3602 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3603 @retval EFI_ABORTED Invalid HostName setting.
3614 CALL_CRYPTO_SERVICE (TlsSetVerifyHost
, (Tls
, Flags
, HostName
), EFI_UNSUPPORTED
);
3618 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
3620 This function sets a session ID to be used when the TLS/SSL connection is
3623 @param[in] Tls Pointer to the TLS object.
3624 @param[in] SessionId Session ID data used for session resumption.
3625 @param[in] SessionIdLen Length of Session ID in bytes.
3627 @retval EFI_SUCCESS Session ID was set successfully.
3628 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3629 @retval EFI_UNSUPPORTED No available session for ID setting.
3636 IN UINT8
*SessionId
,
3637 IN UINT16 SessionIdLen
3640 CALL_CRYPTO_SERVICE (TlsSetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
3644 Adds the CA to the cert store when requesting Server or Client authentication.
3646 This function adds the CA certificate to the list of CAs when requesting
3647 Server or Client authentication for the chosen TLS connection.
3649 @param[in] Tls Pointer to the TLS object.
3650 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3651 X.509 certificate or PEM-encoded X.509 certificate.
3652 @param[in] DataSize The size of data buffer in bytes.
3654 @retval EFI_SUCCESS The operation succeeded.
3655 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3656 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3657 @retval EFI_ABORTED Invalid X.509 certificate.
3662 TlsSetCaCertificate (
3668 CALL_CRYPTO_SERVICE (TlsSetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3672 Loads the local public certificate into the specified TLS object.
3674 This function loads the X.509 certificate into the specified TLS object
3675 for TLS negotiation.
3677 @param[in] Tls Pointer to the TLS object.
3678 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3679 X.509 certificate or PEM-encoded X.509 certificate.
3680 @param[in] DataSize The size of data buffer in bytes.
3682 @retval EFI_SUCCESS The operation succeeded.
3683 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3684 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3685 @retval EFI_ABORTED Invalid X.509 certificate.
3690 TlsSetHostPublicCert (
3696 CALL_CRYPTO_SERVICE (TlsSetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3700 Adds the local private key to the specified TLS object.
3702 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
3703 key) into the specified TLS object for TLS negotiation.
3705 @param[in] Tls Pointer to the TLS object.
3706 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
3707 or PKCS#8 private key.
3708 @param[in] DataSize The size of data buffer in bytes.
3710 @retval EFI_SUCCESS The operation succeeded.
3711 @retval EFI_UNSUPPORTED This function is not supported.
3712 @retval EFI_ABORTED Invalid private key data.
3717 TlsSetHostPrivateKey (
3723 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3727 Adds the CA-supplied certificate revocation list for certificate validation.
3729 This function adds the CA-supplied certificate revocation list data for
3730 certificate validity checking.
3732 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
3733 @param[in] DataSize The size of data buffer in bytes.
3735 @retval EFI_SUCCESS The operation succeeded.
3736 @retval EFI_UNSUPPORTED This function is not supported.
3737 @retval EFI_ABORTED Invalid CRL data.
3742 TlsSetCertRevocationList (
3747 CALL_CRYPTO_SERVICE (TlsSetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);
3751 Gets the protocol version used by the specified TLS connection.
3753 This function returns the protocol version used by the specified TLS
3756 If Tls is NULL, then ASSERT().
3758 @param[in] Tls Pointer to the TLS object.
3760 @return The protocol version of the specified TLS connection.
3769 CALL_CRYPTO_SERVICE (TlsGetVersion
, (Tls
), 0);
3773 Gets the connection end of the specified TLS connection.
3775 This function returns the connection end (as client or as server) used by
3776 the specified TLS connection.
3778 If Tls is NULL, then ASSERT().
3780 @param[in] Tls Pointer to the TLS object.
3782 @return The connection end used by the specified TLS connection.
3787 TlsGetConnectionEnd (
3791 CALL_CRYPTO_SERVICE (TlsGetConnectionEnd
, (Tls
), 0);
3795 Gets the cipher suite used by the specified TLS connection.
3797 This function returns current cipher suite used by the specified
3800 @param[in] Tls Pointer to the TLS object.
3801 @param[in,out] CipherId The cipher suite used by the TLS object.
3803 @retval EFI_SUCCESS The cipher suite was returned successfully.
3804 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3805 @retval EFI_UNSUPPORTED Unsupported cipher suite.
3810 TlsGetCurrentCipher (
3812 IN OUT UINT16
*CipherId
3815 CALL_CRYPTO_SERVICE (TlsGetCurrentCipher
, (Tls
, CipherId
), EFI_UNSUPPORTED
);
3819 Gets the compression methods used by the specified TLS connection.
3821 This function returns current integrated compression methods used by
3822 the specified TLS connection.
3824 @param[in] Tls Pointer to the TLS object.
3825 @param[in,out] CompressionId The current compression method used by
3828 @retval EFI_SUCCESS The compression method was returned successfully.
3829 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3830 @retval EFI_ABORTED Invalid Compression method.
3831 @retval EFI_UNSUPPORTED This function is not supported.
3836 TlsGetCurrentCompressionId (
3838 IN OUT UINT8
*CompressionId
3841 CALL_CRYPTO_SERVICE (TlsGetCurrentCompressionId
, (Tls
, CompressionId
), EFI_UNSUPPORTED
);
3845 Gets the verification mode currently set in the TLS connection.
3847 This function returns the peer verification mode currently set in the
3848 specified TLS connection.
3850 If Tls is NULL, then ASSERT().
3852 @param[in] Tls Pointer to the TLS object.
3854 @return The verification mode set in the specified TLS connection.
3863 CALL_CRYPTO_SERVICE (TlsGetVerify
, (Tls
), 0);
3867 Gets the session ID used by the specified TLS connection.
3869 This function returns the TLS/SSL session ID currently used by the
3870 specified TLS connection.
3872 @param[in] Tls Pointer to the TLS object.
3873 @param[in,out] SessionId Buffer to contain the returned session ID.
3874 @param[in,out] SessionIdLen The length of Session ID in bytes.
3876 @retval EFI_SUCCESS The Session ID was returned successfully.
3877 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3878 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
3885 IN OUT UINT8
*SessionId
,
3886 IN OUT UINT16
*SessionIdLen
3889 CALL_CRYPTO_SERVICE (TlsGetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
3893 Gets the client random data used in the specified TLS connection.
3895 This function returns the TLS/SSL client random data currently used in
3896 the specified TLS connection.
3898 @param[in] Tls Pointer to the TLS object.
3899 @param[in,out] ClientRandom Buffer to contain the returned client
3900 random data (32 bytes).
3905 TlsGetClientRandom (
3907 IN OUT UINT8
*ClientRandom
3910 CALL_VOID_CRYPTO_SERVICE (TlsGetClientRandom
, (Tls
, ClientRandom
));
3914 Gets the server random data used in the specified TLS connection.
3916 This function returns the TLS/SSL server random data currently used in
3917 the specified TLS connection.
3919 @param[in] Tls Pointer to the TLS object.
3920 @param[in,out] ServerRandom Buffer to contain the returned server
3921 random data (32 bytes).
3926 TlsGetServerRandom (
3928 IN OUT UINT8
*ServerRandom
3931 CALL_VOID_CRYPTO_SERVICE (TlsGetServerRandom
, (Tls
, ServerRandom
));
3935 Gets the master key data used in the specified TLS connection.
3937 This function returns the TLS/SSL master key material currently used in
3938 the specified TLS connection.
3940 @param[in] Tls Pointer to the TLS object.
3941 @param[in,out] KeyMaterial Buffer to contain the returned key material.
3943 @retval EFI_SUCCESS Key material was returned successfully.
3944 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3945 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
3952 IN OUT UINT8
*KeyMaterial
3955 CALL_CRYPTO_SERVICE (TlsGetKeyMaterial
, (Tls
, KeyMaterial
), EFI_UNSUPPORTED
);
3959 Gets the CA Certificate from the cert store.
3961 This function returns the CA certificate for the chosen
3964 @param[in] Tls Pointer to the TLS object.
3965 @param[out] Data Pointer to the data buffer to receive the CA
3966 certificate data sent to the client.
3967 @param[in,out] DataSize The size of data buffer in bytes.
3969 @retval EFI_SUCCESS The operation succeeded.
3970 @retval EFI_UNSUPPORTED This function is not supported.
3971 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
3976 TlsGetCaCertificate (
3979 IN OUT UINTN
*DataSize
3982 CALL_CRYPTO_SERVICE (TlsGetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3986 Gets the local public Certificate set in the specified TLS object.
3988 This function returns the local public certificate which was currently set
3989 in the specified TLS object.
3991 @param[in] Tls Pointer to the TLS object.
3992 @param[out] Data Pointer to the data buffer to receive the local
3994 @param[in,out] DataSize The size of data buffer in bytes.
3996 @retval EFI_SUCCESS The operation succeeded.
3997 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3998 @retval EFI_NOT_FOUND The certificate is not found.
3999 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4004 TlsGetHostPublicCert (
4007 IN OUT UINTN
*DataSize
4010 CALL_CRYPTO_SERVICE (TlsGetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4014 Gets the local private key set in the specified TLS object.
4016 This function returns the local private key data which was currently set
4017 in the specified TLS object.
4019 @param[in] Tls Pointer to the TLS object.
4020 @param[out] Data Pointer to the data buffer to receive the local
4022 @param[in,out] DataSize The size of data buffer in bytes.
4024 @retval EFI_SUCCESS The operation succeeded.
4025 @retval EFI_UNSUPPORTED This function is not supported.
4026 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4031 TlsGetHostPrivateKey (
4034 IN OUT UINTN
*DataSize
4037 CALL_CRYPTO_SERVICE (TlsGetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4041 Gets the CA-supplied certificate revocation list data set in the specified
4044 This function returns the CA-supplied certificate revocation list data which
4045 was currently set in the specified TLS object.
4047 @param[out] Data Pointer to the data buffer to receive the CRL data.
4048 @param[in,out] DataSize The size of data buffer in bytes.
4050 @retval EFI_SUCCESS The operation succeeded.
4051 @retval EFI_UNSUPPORTED This function is not supported.
4052 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4057 TlsGetCertRevocationList (
4059 IN OUT UINTN
*DataSize
4062 CALL_CRYPTO_SERVICE (TlsGetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);
4065 // =====================================================================================
4066 // Big number primitive
4067 // =====================================================================================
4070 Allocate new Big Number.
4072 @retval New BigNum opaque structure or NULL on failure.
4080 CALL_CRYPTO_SERVICE (BigNumInit
, (), NULL
);
4084 Allocate new Big Number and assign the provided value to it.
4086 @param[in] Buf Big endian encoded buffer.
4087 @param[in] Len Buffer length.
4089 @retval New BigNum opaque structure or NULL on failure.
4094 IN CONST UINT8
*Buf
,
4098 CALL_CRYPTO_SERVICE (BigNumFromBin
, (Buf
, Len
), NULL
);
4102 Convert the absolute value of Bn into big-endian form and store it at Buf.
4103 The Buf array should have at least BigNumBytes() in it.
4105 @param[in] Bn Big number to convert.
4106 @param[out] Buf Output buffer.
4108 @retval The length of the big-endian number placed at Buf or -1 on error.
4117 CALL_CRYPTO_SERVICE (BigNumToBin
, (Bn
, Buf
), -1);
4121 Free the Big Number.
4123 @param[in] Bn Big number to free.
4124 @param[in] Clear TRUE if the buffer should be cleared.
4133 CALL_VOID_CRYPTO_SERVICE (BigNumFree
, (Bn
, Clear
));
4137 Calculate the sum of two Big Numbers.
4138 Please note, all "out" Big number arguments should be properly initialized
4139 by calling to BigNumInit() or BigNumFromBin() functions.
4141 @param[in] BnA Big number.
4142 @param[in] BnB Big number.
4143 @param[out] BnRes The result of BnA + BnB.
4145 @retval TRUE On success.
4146 @retval FALSE Otherwise.
4156 CALL_CRYPTO_SERVICE (BigNumAdd
, (BnA
, BnB
, BnRes
), FALSE
);
4160 Subtract two Big Numbers.
4161 Please note, all "out" Big number arguments should be properly initialized
4162 by calling to BigNumInit() or BigNumFromBin() functions.
4164 @param[in] BnA Big number.
4165 @param[in] BnB Big number.
4166 @param[out] BnRes The result of BnA - BnB.
4168 @retval TRUE On success.
4169 @retval FALSE Otherwise.
4179 CALL_CRYPTO_SERVICE (BigNumSub
, (BnA
, BnB
, BnRes
), FALSE
);
4183 Calculate remainder: BnRes = BnA % BnB
4184 Please note, all "out" Big number arguments should be properly initialized
4185 by calling to BigNumInit() or BigNumFromBin() functions.
4187 @param[in] BnA Big number.
4188 @param[in] BnB Big number.
4189 @param[out] BnRes The result of BnA % BnB.
4191 @retval TRUE On success.
4192 @retval FALSE Otherwise.
4202 CALL_CRYPTO_SERVICE (BigNumMod
, (BnA
, BnB
, BnRes
), FALSE
);
4206 Compute BnA to the BnP-th power modulo BnM.
4207 Please note, all "out" Big number arguments should be properly initialized
4208 by calling to BigNumInit() or BigNumFromBin() functions.
4210 @param[in] BnA Big number.
4211 @param[in] BnP Big number (power).
4212 @param[in] BnM Big number (modulo).
4213 @param[out] BnRes The result of (BnA ^ BnP) % BnM.
4215 @retval TRUE On success.
4216 @retval FALSE Otherwise.
4227 CALL_CRYPTO_SERVICE (BigNumExpMod
, (BnA
, BnP
, BnM
, BnRes
), FALSE
);
4231 Compute BnA inverse modulo BnM.
4232 Please note, all "out" Big number arguments should be properly initialized
4233 by calling to BigNumInit() or BigNumFromBin() functions.
4235 @param[in] BnA Big number.
4236 @param[in] BnM Big number (modulo).
4237 @param[out] BnRes The result, such that (BnA * BnRes) % BnM == 1.
4239 @retval TRUE On success.
4240 @retval FALSE Otherwise.
4250 CALL_CRYPTO_SERVICE (BigNumInverseMod
, (BnA
, BnM
, BnRes
), FALSE
);
4254 Divide two Big Numbers.
4255 Please note, all "out" Big number arguments should be properly initialized
4256 by calling to BigNumInit() or BigNumFromBin() functions.
4258 @param[in] BnA Big number.
4259 @param[in] BnB Big number.
4260 @param[out] BnRes The result, such that BnA / BnB.
4262 @retval TRUE On success.
4263 @retval FALSE Otherwise.
4273 CALL_CRYPTO_SERVICE (BigNumDiv
, (BnA
, BnB
, BnRes
), FALSE
);
4277 Multiply two Big Numbers modulo BnM.
4278 Please note, all "out" Big number arguments should be properly initialized
4279 by calling to BigNumInit() or BigNumFromBin() functions.
4281 @param[in] BnA Big number.
4282 @param[in] BnB Big number.
4283 @param[in] BnM Big number (modulo).
4284 @param[out] BnRes The result, such that (BnA * BnB) % BnM.
4286 @retval TRUE On success.
4287 @retval FALSE Otherwise.
4298 CALL_CRYPTO_SERVICE (BigNumMulMod
, (BnA
, BnB
, BnM
, BnRes
), FALSE
);
4302 Compare two Big Numbers.
4304 @param[in] BnA Big number.
4305 @param[in] BnB Big number.
4307 @retval 0 BnA == BnB.
4308 @retval 1 BnA > BnB.
4309 @retval -1 BnA < BnB.
4318 CALL_CRYPTO_SERVICE (BigNumCmp
, (BnA
, BnB
), 0);
4322 Get number of bits in Bn.
4324 @param[in] Bn Big number.
4326 @retval Number of bits.
4334 CALL_CRYPTO_SERVICE (BigNumBits
, (Bn
), 0);
4338 Get number of bytes in Bn.
4340 @param[in] Bn Big number.
4342 @retval Number of bytes.
4350 CALL_CRYPTO_SERVICE (BigNumBytes
, (Bn
), 0);
4354 Checks if Big Number equals to the given Num.
4356 @param[in] Bn Big number.
4357 @param[in] Num Number.
4359 @retval TRUE iff Bn == Num.
4360 @retval FALSE otherwise.
4369 CALL_CRYPTO_SERVICE (BigNumIsWord
, (Bn
, Num
), FALSE
);
4373 Checks if Big Number is odd.
4375 @param[in] Bn Big number.
4377 @retval TRUE Bn is odd (Bn % 2 == 1).
4378 @retval FALSE otherwise.
4386 CALL_CRYPTO_SERVICE (BigNumIsOdd
, (Bn
), FALSE
);
4392 @param[out] BnDst Destination.
4393 @param[in] BnSrc Source.
4395 @retval BnDst on success.
4396 @retval NULL otherwise.
4402 IN CONST VOID
*BnSrc
4405 CALL_CRYPTO_SERVICE (BigNumCopy
, (BnDst
, BnSrc
), NULL
);
4409 Get constant Big number with value of "1".
4410 This may be used to save expensive allocations.
4412 @retval Big Number with value of 1.
4420 CALL_CRYPTO_SERVICE (BigNumValueOne
, (), NULL
);
4424 Shift right Big Number.
4425 Please note, all "out" Big number arguments should be properly initialized
4426 by calling to BigNumInit() or BigNumFromBin() functions.
4428 @param[in] Bn Big number.
4429 @param[in] N Number of bits to shift.
4430 @param[out] BnRes The result.
4432 @retval TRUE On success.
4433 @retval FALSE Otherwise.
4443 CALL_CRYPTO_SERVICE (BigNumRShift
, (Bn
, N
, BnRes
), FALSE
);
4447 Mark Big Number for constant time computations.
4448 This function should be called before any constant time computations are
4449 performed on the given Big number.
4451 @param[in] Bn Big number.
4459 CALL_VOID_CRYPTO_SERVICE (BigNumConstTime
, (Bn
));
4463 Calculate square modulo.
4464 Please note, all "out" Big number arguments should be properly initialized
4465 by calling to BigNumInit() or BigNumFromBin() functions.
4467 @param[in] BnA Big number.
4468 @param[in] BnM Big number (modulo).
4469 @param[out] BnRes The result, such that (BnA ^ 2) % BnM.
4471 @retval TRUE On success.
4472 @retval FALSE Otherwise.
4482 CALL_CRYPTO_SERVICE (BigNumSqrMod
, (BnA
, BnM
, BnRes
), FALSE
);
4486 Create new Big Number computation context. This is an opaque structure
4487 which should be passed to any function that requires it. The BN context is
4488 needed to optimize calculations and expensive allocations.
4490 @retval Big Number context struct or NULL on failure.
4498 CALL_CRYPTO_SERVICE (BigNumNewContext
, (), NULL
);
4502 Free Big Number context that was allocated with BigNumNewContext().
4504 @param[in] BnCtx Big number context to free.
4512 CALL_VOID_CRYPTO_SERVICE (BigNumContextFree
, (BnCtx
));
4516 Set Big Number to a given value.
4518 @param[in] Bn Big number to set.
4519 @param[in] Val Value to set.
4521 @retval TRUE On success.
4522 @retval FALSE Otherwise.
4531 CALL_CRYPTO_SERVICE (BigNumSetUint
, (Bn
, Val
), FALSE
);
4535 Add two Big Numbers modulo BnM.
4537 @param[in] BnA Big number.
4538 @param[in] BnB Big number.
4539 @param[in] BnM Big number (modulo).
4540 @param[out] BnRes The result, such that (BnA + BnB) % BnM.
4542 @retval TRUE On success.
4543 @retval FALSE Otherwise.
4554 CALL_CRYPTO_SERVICE (BigNumAddMod
, (BnA
, BnB
, BnM
, BnRes
), FALSE
);
4558 Initialize new opaque EcGroup object. This object represents an EC curve and
4559 and is used for calculation within this group. This object should be freed
4560 using EcGroupFree() function.
4562 @param[in] CryptoNid Identifying number for the ECC curve (Defined in
4565 @retval EcGroup object On success.
4566 @retval NULL On failure.
4574 CALL_CRYPTO_SERVICE (EcGroupInit
, (CryptoNid
), NULL
);
4578 Get EC curve parameters. While elliptic curve equation is Y^2 mod P = (X^3 + AX + B) Mod P.
4579 This function will set the provided Big Number objects to the corresponding
4580 values. The caller needs to make sure all the "out" BigNumber parameters
4581 are properly initialized.
4583 @param[in] EcGroup EC group object.
4584 @param[out] BnPrime Group prime number.
4585 @param[out] BnA A coefficient.
4586 @param[out] BnB B coefficient.
4587 @param[in] BnCtx BN context.
4589 @retval TRUE On success.
4590 @retval FALSE Otherwise.
4595 IN CONST VOID
*EcGroup
,
4602 CALL_CRYPTO_SERVICE (EcGroupGetCurve
, (EcGroup
, BnPrime
, BnA
, BnB
, BnCtx
), FALSE
);
4607 This function will set the provided Big Number object to the corresponding
4608 value. The caller needs to make sure that the "out" BigNumber parameter
4609 is properly initialized.
4611 @param[in] EcGroup EC group object.
4612 @param[out] BnOrder Group prime number.
4614 @retval TRUE On success.
4615 @retval FALSE Otherwise.
4624 CALL_CRYPTO_SERVICE (EcGroupGetOrder
, (EcGroup
, BnOrder
), FALSE
);
4628 Free previously allocated EC group object using EcGroupInit().
4630 @param[in] EcGroup EC group object to free.
4638 CALL_VOID_CRYPTO_SERVICE (EcGroupFree
, (EcGroup
));
4642 Initialize new opaque EC Point object. This object represents an EC point
4643 within the given EC group (curve).
4645 @param[in] EC Group, properly initialized using EcGroupInit().
4647 @retval EC Point object On success.
4648 @retval NULL On failure.
4653 IN CONST VOID
*EcGroup
4656 CALL_CRYPTO_SERVICE (EcPointInit
, (EcGroup
), NULL
);
4660 Free previously allocated EC Point object using EcPointInit().
4662 @param[in] EcPoint EC Point to free.
4663 @param[in] Clear TRUE iff the memory should be cleared.
4672 CALL_VOID_CRYPTO_SERVICE (EcPointDeInit
, (EcPoint
, Clear
));
4676 Get EC point affine (x,y) coordinates.
4677 This function will set the provided Big Number objects to the corresponding
4678 values. The caller needs to make sure all the "out" BigNumber parameters
4679 are properly initialized.
4681 @param[in] EcGroup EC group object.
4682 @param[in] EcPoint EC point object.
4683 @param[out] BnX X coordinate.
4684 @param[out] BnY Y coordinate.
4685 @param[in] BnCtx BN context, created with BigNumNewContext().
4687 @retval TRUE On success.
4688 @retval FALSE Otherwise.
4692 EcPointGetAffineCoordinates (
4693 IN CONST VOID
*EcGroup
,
4694 IN CONST VOID
*EcPoint
,
4700 CALL_CRYPTO_SERVICE (EcPointGetAffineCoordinates
, (EcGroup
, EcPoint
, BnX
, BnY
, BnCtx
), FALSE
);
4704 Set EC point affine (x,y) coordinates.
4706 @param[in] EcGroup EC group object.
4707 @param[in] EcPoint EC point object.
4708 @param[in] BnX X coordinate.
4709 @param[in] BnY Y coordinate.
4710 @param[in] BnCtx BN context, created with BigNumNewContext().
4712 @retval TRUE On success.
4713 @retval FALSE Otherwise.
4717 EcPointSetAffineCoordinates (
4718 IN CONST VOID
*EcGroup
,
4725 CALL_CRYPTO_SERVICE (EcPointSetAffineCoordinates
, (EcGroup
, EcPoint
, BnX
, BnY
, BnCtx
), FALSE
);
4729 EC Point addition. EcPointResult = EcPointA + EcPointB.
4731 @param[in] EcGroup EC group object.
4732 @param[out] EcPointResult EC point to hold the result. The point should
4733 be properly initialized.
4734 @param[in] EcPointA EC Point.
4735 @param[in] EcPointB EC Point.
4736 @param[in] BnCtx BN context, created with BigNumNewContext().
4738 @retval TRUE On success.
4739 @retval FALSE Otherwise.
4744 IN CONST VOID
*EcGroup
,
4745 OUT VOID
*EcPointResult
,
4746 IN CONST VOID
*EcPointA
,
4747 IN CONST VOID
*EcPointB
,
4751 CALL_CRYPTO_SERVICE (EcPointAdd
, (EcGroup
, EcPointResult
, EcPointA
, EcPointB
, BnCtx
), FALSE
);
4755 Variable EC point multiplication. EcPointResult = EcPoint * BnPScalar.
4757 @param[in] EcGroup EC group object.
4758 @param[out] EcPointResult EC point to hold the result. The point should
4759 be properly initialized.
4760 @param[in] EcPoint EC Point.
4761 @param[in] BnPScalar P Scalar.
4762 @param[in] BnCtx BN context, created with BigNumNewContext().
4764 @retval TRUE On success.
4765 @retval FALSE Otherwise.
4770 IN CONST VOID
*EcGroup
,
4771 OUT VOID
*EcPointResult
,
4772 IN CONST VOID
*EcPoint
,
4773 IN CONST VOID
*BnPScalar
,
4777 CALL_CRYPTO_SERVICE (EcPointMul
, (EcGroup
, EcPointResult
, EcPoint
, BnPScalar
, BnCtx
), FALSE
);
4781 Calculate the inverse of the supplied EC point.
4783 @param[in] EcGroup EC group object.
4784 @param[in,out] EcPoint EC point to invert.
4785 @param[in] BnCtx BN context, created with BigNumNewContext().
4787 @retval TRUE On success.
4788 @retval FALSE Otherwise.
4793 IN CONST VOID
*EcGroup
,
4794 IN OUT VOID
*EcPoint
,
4798 CALL_CRYPTO_SERVICE (EcPointInvert
, (EcGroup
, EcPoint
, BnCtx
), FALSE
);
4802 Check if the supplied point is on EC curve.
4804 @param[in] EcGroup EC group object.
4805 @param[in] EcPoint EC point to check.
4806 @param[in] BnCtx BN context, created with BigNumNewContext().
4808 @retval TRUE On curve.
4809 @retval FALSE Otherwise.
4814 IN CONST VOID
*EcGroup
,
4815 IN CONST VOID
*EcPoint
,
4819 CALL_CRYPTO_SERVICE (EcPointIsOnCurve
, (EcGroup
, EcPoint
, BnCtx
), FALSE
);
4823 Check if the supplied point is at infinity.
4825 @param[in] EcGroup EC group object.
4826 @param[in] EcPoint EC point to check.
4828 @retval TRUE At infinity.
4829 @retval FALSE Otherwise.
4833 EcPointIsAtInfinity (
4834 IN CONST VOID
*EcGroup
,
4835 IN CONST VOID
*EcPoint
4838 CALL_CRYPTO_SERVICE (EcPointIsAtInfinity
, (EcGroup
, EcPoint
), FALSE
);
4842 Check if EC points are equal.
4844 @param[in] EcGroup EC group object.
4845 @param[in] EcPointA EC point A.
4846 @param[in] EcPointB EC point B.
4847 @param[in] BnCtx BN context, created with BigNumNewContext().
4849 @retval TRUE A == B.
4850 @retval FALSE Otherwise.
4855 IN CONST VOID
*EcGroup
,
4856 IN CONST VOID
*EcPointA
,
4857 IN CONST VOID
*EcPointB
,
4861 CALL_CRYPTO_SERVICE (EcPointEqual
, (EcGroup
, EcPointA
, EcPointB
, BnCtx
), FALSE
);
4865 Set EC point compressed coordinates. Points can be described in terms of
4866 their compressed coordinates. For a point (x, y), for any given value for x
4867 such that the point is on the curve there will only ever be two possible
4868 values for y. Therefore, a point can be set using this function where BnX is
4869 the x coordinate and YBit is a value 0 or 1 to identify which of the two
4870 possible values for y should be used.
4872 @param[in] EcGroup EC group object.
4873 @param[in] EcPoint EC Point.
4874 @param[in] BnX X coordinate.
4875 @param[in] YBit 0 or 1 to identify which Y value is used.
4876 @param[in] BnCtx BN context, created with BigNumNewContext().
4878 @retval TRUE On success.
4879 @retval FALSE Otherwise.
4883 EcPointSetCompressedCoordinates (
4884 IN CONST VOID
*EcGroup
,
4891 CALL_CRYPTO_SERVICE (EcPointSetCompressedCoordinates
, (EcGroup
, EcPoint
, BnX
, YBit
, BnCtx
), FALSE
);
4895 Allocates and Initializes one Elliptic Curve Context for subsequent use
4898 @param[in] Nid cipher NID
4899 @return Pointer to the Elliptic Curve Context that has been initialized.
4900 If the allocations fails, EcNewByNid() returns NULL.
4908 CALL_CRYPTO_SERVICE (EcNewByNid
, (Nid
), NULL
);
4912 Release the specified EC context.
4914 @param[in] EcContext Pointer to the EC context to be released.
4922 CALL_VOID_CRYPTO_SERVICE (EcFree
, (EcContext
));
4926 Generates EC key and returns EC public key (X, Y), Please note, this function uses
4927 pseudo random number generator. The caller must make sure RandomSeed()
4928 function was properly called before.
4929 The Ec context should be correctly initialized by EcNewByNid.
4930 This function generates random secret, and computes the public key (X, Y), which is
4931 returned via parameter Public, PublicSize.
4932 X is the first half of Public with size being PublicSize / 2,
4933 Y is the second half of Public with size being PublicSize / 2.
4934 EC context is updated accordingly.
4935 If the Public buffer is too small to hold the public X, Y, FALSE is returned and
4936 PublicSize is set to the required buffer size to obtain the public X, Y.
4937 For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.
4938 For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.
4939 For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.
4940 If EcContext is NULL, then return FALSE.
4941 If PublicSize is NULL, then return FALSE.
4942 If PublicSize is large enough but Public is NULL, then return FALSE.
4943 @param[in, out] EcContext Pointer to the EC context.
4944 @param[out] PublicKey Pointer to the buffer to receive generated public X,Y.
4945 @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.
4946 On output, the size of data returned in Public buffer in bytes.
4947 @retval TRUE EC public X,Y generation succeeded.
4948 @retval FALSE EC public X,Y generation failed.
4949 @retval FALSE PublicKeySize is not large enough.
4954 IN OUT VOID
*EcContext
,
4955 OUT UINT8
*PublicKey
,
4956 IN OUT UINTN
*PublicKeySize
4959 CALL_CRYPTO_SERVICE (EcGenerateKey
, (EcContext
, PublicKey
, PublicKeySize
), FALSE
);
4963 Gets the public key component from the established EC context.
4964 The Ec context should be correctly initialized by EcNewByNid, and successfully
4965 generate key pair from EcGenerateKey().
4966 For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.
4967 For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.
4968 For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.
4969 @param[in, out] EcContext Pointer to EC context being set.
4970 @param[out] PublicKey Pointer to t buffer to receive generated public X,Y.
4971 @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.
4972 On output, the size of data returned in Public buffer in bytes.
4973 @retval TRUE EC key component was retrieved successfully.
4974 @retval FALSE Invalid EC key component.
4979 IN OUT VOID
*EcContext
,
4980 OUT UINT8
*PublicKey
,
4981 IN OUT UINTN
*PublicKeySize
4984 CALL_CRYPTO_SERVICE (EcGetPubKey
, (EcContext
, PublicKey
, PublicKeySize
), FALSE
);
4988 Computes exchanged common key.
4989 Given peer's public key (X, Y), this function computes the exchanged common key,
4990 based on its own context including value of curve parameter and random secret.
4991 X is the first half of PeerPublic with size being PeerPublicSize / 2,
4992 Y is the second half of PeerPublic with size being PeerPublicSize / 2.
4993 If EcContext is NULL, then return FALSE.
4994 If PeerPublic is NULL, then return FALSE.
4995 If PeerPublicSize is 0, then return FALSE.
4996 If Key is NULL, then return FALSE.
4997 If KeySize is not large enough, then return FALSE.
4998 For P-256, the PeerPublicSize is 64. First 32-byte is X, Second 32-byte is Y.
4999 For P-384, the PeerPublicSize is 96. First 48-byte is X, Second 48-byte is Y.
5000 For P-521, the PeerPublicSize is 132. First 66-byte is X, Second 66-byte is Y.
5001 @param[in, out] EcContext Pointer to the EC context.
5002 @param[in] PeerPublic Pointer to the peer's public X,Y.
5003 @param[in] PeerPublicSize Size of peer's public X,Y in bytes.
5004 @param[in] CompressFlag Flag of PeerPublic is compressed or not.
5005 @param[out] Key Pointer to the buffer to receive generated key.
5006 @param[in, out] KeySize On input, the size of Key buffer in bytes.
5007 On output, the size of data returned in Key buffer in bytes.
5008 @retval TRUE EC exchanged key generation succeeded.
5009 @retval FALSE EC exchanged key generation failed.
5010 @retval FALSE KeySize is not large enough.
5015 IN OUT VOID
*EcContext
,
5016 IN CONST UINT8
*PeerPublic
,
5017 IN UINTN PeerPublicSize
,
5018 IN CONST INT32
*CompressFlag
,
5020 IN OUT UINTN
*KeySize
5023 CALL_CRYPTO_SERVICE (EcDhComputeKey
, (EcContext
, PeerPublic
, PeerPublicSize
, CompressFlag
, Key
, KeySize
), FALSE
);