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 Retrieve the version from one X.509 certificate.
2328 If Cert is NULL, then return FALSE.
2329 If CertSize is 0, then return FALSE.
2330 If this interface is not supported, then return FALSE.
2332 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2333 @param[in] CertSize Size of the X509 certificate in bytes.
2334 @param[out] Version Pointer to the retrieved version integer.
2336 @retval TRUE The certificate version retrieved successfully.
2337 @retval FALSE If Cert is NULL or CertSize is Zero.
2338 @retval FALSE The operation is not supported.
2344 IN CONST UINT8
*Cert
,
2349 CALL_CRYPTO_SERVICE (X509GetVersion
, (Cert
, CertSize
, Version
), FALSE
);
2353 Retrieve the serialNumber from one X.509 certificate.
2355 If Cert is NULL, then return FALSE.
2356 If CertSize is 0, then return FALSE.
2357 If this interface is not supported, then return FALSE.
2359 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2360 @param[in] CertSize Size of the X509 certificate in bytes.
2361 @param[out] SerialNumber Pointer to the retrieved certificate SerialNumber bytes.
2362 @param[in, out] SerialNumberSize The size in bytes of the SerialNumber buffer on input,
2363 and the size of buffer returned SerialNumber on output.
2365 @retval TRUE The certificate serialNumber retrieved successfully.
2366 @retval FALSE If Cert is NULL or CertSize is Zero.
2367 If SerialNumberSize is NULL.
2368 If Certificate is invalid.
2369 @retval FALSE If no SerialNumber exists.
2370 @retval FALSE If the SerialNumber is NULL. The required buffer size
2371 (including the final null) is returned in the
2372 SerialNumberSize parameter.
2373 @retval FALSE The operation is not supported.
2377 X509GetSerialNumber (
2378 IN CONST UINT8
*Cert
,
2380 OUT UINT8
*SerialNumber
, OPTIONAL
2381 IN OUT UINTN
*SerialNumberSize
2384 CALL_CRYPTO_SERVICE (X509GetSerialNumber
, (Cert
, CertSize
, SerialNumber
, SerialNumberSize
), FALSE
);
2388 Retrieve the issuer bytes from one X.509 certificate.
2390 If Cert is NULL, then return FALSE.
2391 If CertIssuerSize is NULL, then return FALSE.
2392 If this interface is not supported, then return FALSE.
2394 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2395 @param[in] CertSize Size of the X509 certificate in bytes.
2396 @param[out] CertIssuer Pointer to the retrieved certificate subject bytes.
2397 @param[in, out] CertIssuerSize The size in bytes of the CertIssuer buffer on input,
2398 and the size of buffer returned CertSubject on output.
2400 @retval TRUE The certificate issuer retrieved successfully.
2401 @retval FALSE Invalid certificate, or the CertIssuerSize is too small for the result.
2402 The CertIssuerSize will be updated with the required size.
2403 @retval FALSE This interface is not supported.
2409 IN CONST UINT8
*Cert
,
2411 OUT UINT8
*CertIssuer
,
2412 IN OUT UINTN
*CertIssuerSize
2415 CALL_CRYPTO_SERVICE (X509GetIssuerName
, (Cert
, CertSize
, CertIssuer
, CertIssuerSize
), FALSE
);
2419 Retrieve the Signature Algorithm from one X.509 certificate.
2421 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2422 @param[in] CertSize Size of the X509 certificate in bytes.
2423 @param[out] Oid Signature Algorithm Object identifier buffer.
2424 @param[in,out] OidSize Signature Algorithm Object identifier buffer size
2426 @retval TRUE The certificate Extension data retrieved successfully.
2427 @retval FALSE If Cert is NULL.
2429 If Oid is not NULL and *OidSize is 0.
2430 If Certificate is invalid.
2431 @retval FALSE If no SignatureType.
2432 @retval FALSE If the Oid is NULL. The required buffer size
2433 is returned in the OidSize.
2434 @retval FALSE The operation is not supported.
2438 X509GetSignatureAlgorithm (
2439 IN CONST UINT8
*Cert
,
2441 OUT UINT8
*Oid
, OPTIONAL
2442 IN OUT UINTN
*OidSize
2445 CALL_CRYPTO_SERVICE (X509GetSignatureAlgorithm
, (Cert
, CertSize
, Oid
, OidSize
), FALSE
);
2449 Retrieve Extension data from one X.509 certificate.
2451 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2452 @param[in] CertSize Size of the X509 certificate in bytes.
2453 @param[in] Oid Object identifier buffer
2454 @param[in] OidSize Object identifier buffer size
2455 @param[out] ExtensionData Extension bytes.
2456 @param[in, out] ExtensionDataSize Extension bytes size.
2458 @retval TRUE The certificate Extension data retrieved successfully.
2459 @retval FALSE If Cert is NULL.
2460 If ExtensionDataSize is NULL.
2461 If ExtensionData is not NULL and *ExtensionDataSize is 0.
2462 If Certificate is invalid.
2463 @retval FALSE If no Extension entry match Oid.
2464 @retval FALSE If the ExtensionData is NULL. The required buffer size
2465 is returned in the ExtensionDataSize parameter.
2466 @retval FALSE The operation is not supported.
2470 X509GetExtensionData (
2471 IN CONST UINT8
*Cert
,
2473 IN CONST UINT8
*Oid
,
2475 OUT UINT8
*ExtensionData
,
2476 IN OUT UINTN
*ExtensionDataSize
2479 CALL_CRYPTO_SERVICE (X509GetExtensionData
, (Cert
, CertSize
, Oid
, OidSize
, ExtensionData
, ExtensionDataSize
), FALSE
);
2483 Retrieve the Extended Key Usage from one X.509 certificate.
2485 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2486 @param[in] CertSize Size of the X509 certificate in bytes.
2487 @param[out] Usage Key Usage bytes.
2488 @param[in, out] UsageSize Key Usage buffer sizs in bytes.
2490 @retval TRUE The Usage bytes retrieve successfully.
2491 @retval FALSE If Cert is NULL.
2492 If CertSize is NULL.
2493 If Usage is not NULL and *UsageSize is 0.
2495 @retval FALSE If the Usage is NULL. The required buffer size
2496 is returned in the UsageSize parameter.
2497 @retval FALSE The operation is not supported.
2501 X509GetExtendedKeyUsage (
2502 IN CONST UINT8
*Cert
,
2505 IN OUT UINTN
*UsageSize
2508 CALL_CRYPTO_SERVICE (X509GetExtendedKeyUsage
, (Cert
, CertSize
, Usage
, UsageSize
), FALSE
);
2512 Retrieve the Validity from one X.509 certificate
2514 If Cert is NULL, then return FALSE.
2515 If CertIssuerSize is NULL, then return FALSE.
2516 If this interface is not supported, then return FALSE.
2518 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2519 @param[in] CertSize Size of the X509 certificate in bytes.
2520 @param[in] From notBefore Pointer to DateTime object.
2521 @param[in,out] FromSize notBefore DateTime object size.
2522 @param[in] To notAfter Pointer to DateTime object.
2523 @param[in,out] ToSize notAfter DateTime object size.
2525 Note: X509CompareDateTime to compare DateTime oject
2526 x509SetDateTime to get a DateTime object from a DateTimeStr
2528 @retval TRUE The certificate Validity retrieved successfully.
2529 @retval FALSE Invalid certificate, or Validity retrieve failed.
2530 @retval FALSE This interface is not supported.
2535 IN CONST UINT8
*Cert
,
2538 IN OUT UINTN
*FromSize
,
2540 IN OUT UINTN
*ToSize
2543 CALL_CRYPTO_SERVICE (X509GetValidity
, (Cert
, CertSize
, From
, FromSize
, To
, ToSize
), FALSE
);
2547 Format a DateTimeStr to DataTime object in DataTime Buffer
2549 If DateTimeStr is NULL, then return FALSE.
2550 If DateTimeSize is NULL, then return FALSE.
2551 If this interface is not supported, then return FALSE.
2553 @param[in] DateTimeStr DateTime string like YYYYMMDDhhmmssZ
2554 Ref: https://www.w3.org/TR/NOTE-datetime
2555 Z stand for UTC time
2556 @param[out] DateTime Pointer to a DateTime object.
2557 @param[in,out] DateTimeSize DateTime object buffer size.
2559 @retval TRUE The DateTime object create successfully.
2560 @retval FALSE If DateTimeStr is NULL.
2561 If DateTimeSize is NULL.
2562 If DateTime is not NULL and *DateTimeSize is 0.
2563 If Year Month Day Hour Minute Second combination is invalid datetime.
2564 @retval FALSE If the DateTime is NULL. The required buffer size
2565 (including the final null) is returned in the
2566 DateTimeSize parameter.
2567 @retval FALSE The operation is not supported.
2571 X509FormatDateTime (
2572 IN CONST CHAR8
*DateTimeStr
,
2574 IN OUT UINTN
*DateTimeSize
2577 CALL_CRYPTO_SERVICE (X509FormatDateTime
, (DateTimeStr
, DateTime
, DateTimeSize
), FALSE
);
2581 Compare DateTime1 object and DateTime2 object.
2583 If DateTime1 is NULL, then return -2.
2584 If DateTime2 is NULL, then return -2.
2585 If DateTime1 == DateTime2, then return 0
2586 If DateTime1 > DateTime2, then return 1
2587 If DateTime1 < DateTime2, then return -1
2589 @param[in] DateTime1 Pointer to a DateTime Ojbect
2590 @param[in] DateTime2 Pointer to a DateTime Object
2592 @retval 0 If DateTime1 == DateTime2
2593 @retval 1 If DateTime1 > DateTime2
2594 @retval -1 If DateTime1 < DateTime2
2598 X509CompareDateTime (
2599 IN CONST VOID
*DateTime1
,
2600 IN CONST VOID
*DateTime2
2603 CALL_CRYPTO_SERVICE (X509CompareDateTime
, (DateTime1
, DateTime2
), FALSE
);
2607 Retrieve the Key Usage from one X.509 certificate.
2609 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2610 @param[in] CertSize Size of the X509 certificate in bytes.
2611 @param[out] Usage Key Usage (CRYPTO_X509_KU_*)
2613 @retval TRUE The certificate Key Usage retrieved successfully.
2614 @retval FALSE Invalid certificate, or Usage is NULL
2615 @retval FALSE This interface is not supported.
2620 IN CONST UINT8
*Cert
,
2625 CALL_CRYPTO_SERVICE (X509GetKeyUsage
, (Cert
, CertSize
, Usage
), FALSE
);
2629 Verify one X509 certificate was issued by the trusted CA.
2630 @param[in] RootCert Trusted Root Certificate buffer
2632 @param[in] RootCertLength Trusted Root Certificate buffer length
2633 @param[in] CertChain One or more ASN.1 DER-encoded X.509 certificates
2634 where the first certificate is signed by the Root
2635 Certificate or is the Root Cerificate itself. and
2636 subsequent cerificate is signed by the preceding
2638 @param[in] CertChainLength Total length of the certificate chain, in bytes.
2640 @retval TRUE All cerificates was issued by the first certificate in X509Certchain.
2641 @retval FALSE Invalid certificate or the certificate was not issued by the given
2646 X509VerifyCertChain (
2647 IN CONST UINT8
*RootCert
,
2648 IN UINTN RootCertLength
,
2649 IN CONST UINT8
*CertChain
,
2650 IN UINTN CertChainLength
2653 CALL_CRYPTO_SERVICE (X509VerifyCertChain
, (RootCert
, RootCertLength
, CertChain
, CertChainLength
), FALSE
);
2657 Get one X509 certificate from CertChain.
2659 @param[in] CertChain One or more ASN.1 DER-encoded X.509 certificates
2660 where the first certificate is signed by the Root
2661 Certificate or is the Root Cerificate itself. and
2662 subsequent cerificate is signed by the preceding
2664 @param[in] CertChainLength Total length of the certificate chain, in bytes.
2666 @param[in] CertIndex Index of certificate.
2668 @param[out] Cert The certificate at the index of CertChain.
2669 @param[out] CertLength The length certificate at the index of CertChain.
2671 @retval TRUE Success.
2672 @retval FALSE Failed to get certificate from certificate chain.
2676 X509GetCertFromCertChain (
2677 IN CONST UINT8
*CertChain
,
2678 IN UINTN CertChainLength
,
2679 IN CONST INT32 CertIndex
,
2680 OUT CONST UINT8
**Cert
,
2681 OUT UINTN
*CertLength
2684 CALL_CRYPTO_SERVICE (X509GetCertFromCertChain
, (CertChain
, CertChainLength
, CertIndex
, Cert
, CertLength
), FALSE
);
2688 Retrieve the tag and length of the tag.
2690 @param Ptr The position in the ASN.1 data
2691 @param End End of data
2692 @param Length The variable that will receive the length
2693 @param Tag The expected tag
2695 @retval TRUE Get tag successful
2696 @retval FALSe Failed to get tag or tag not match
2702 IN CONST UINT8
*End
,
2707 CALL_CRYPTO_SERVICE (Asn1GetTag
, (Ptr
, End
, Length
, Tag
), FALSE
);
2711 Retrieve the basic constraints from one X.509 certificate.
2713 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2714 @param[in] CertSize size of the X509 certificate in bytes.
2715 @param[out] BasicConstraints basic constraints bytes.
2716 @param[in, out] BasicConstraintsSize basic constraints buffer sizs in bytes.
2718 @retval TRUE The basic constraints retrieve successfully.
2719 @retval FALSE If cert is NULL.
2720 If cert_size is NULL.
2721 If basic_constraints is not NULL and *basic_constraints_size is 0.
2723 @retval FALSE The required buffer size is small.
2724 The return buffer size is basic_constraints_size parameter.
2725 @retval FALSE If no Extension entry match oid.
2726 @retval FALSE The operation is not supported.
2730 X509GetExtendedBasicConstraints (
2733 UINT8
*BasicConstraints
,
2734 UINTN
*BasicConstraintsSize
2737 CALL_CRYPTO_SERVICE (X509GetExtendedBasicConstraints
, (Cert
, CertSize
, BasicConstraints
, BasicConstraintsSize
), FALSE
);
2741 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2742 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2744 If Password or Salt or OutKey is NULL, then return FALSE.
2745 If the hash algorithm could not be determined, then return FALSE.
2746 If this interface is not supported, then return FALSE.
2748 @param[in] PasswordLength Length of input password in bytes.
2749 @param[in] Password Pointer to the array for the password.
2750 @param[in] SaltLength Size of the Salt in bytes.
2751 @param[in] Salt Pointer to the Salt.
2752 @param[in] IterationCount Number of iterations to perform. Its value should be
2753 greater than or equal to 1.
2754 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2755 NOTE: DigestSize will be used to determine the hash algorithm.
2756 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2757 @param[in] KeyLength Size of the derived key buffer in bytes.
2758 @param[out] OutKey Pointer to the output derived key buffer.
2760 @retval TRUE A key was derived successfully.
2761 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2762 @retval FALSE The hash algorithm could not be determined from the digest size.
2763 @retval FALSE The key derivation operation failed.
2764 @retval FALSE This interface is not supported.
2770 IN UINTN PasswordLength
,
2771 IN CONST CHAR8
*Password
,
2772 IN UINTN SaltLength
,
2773 IN CONST UINT8
*Salt
,
2774 IN UINTN IterationCount
,
2775 IN UINTN DigestSize
,
2780 CALL_CRYPTO_SERVICE (Pkcs5HashPassword
, (PasswordLength
, Password
, SaltLength
, Salt
, IterationCount
, DigestSize
, KeyLength
, OutKey
), FALSE
);
2784 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2785 encrypted message in a newly allocated buffer.
2787 Things that can cause a failure include:
2788 - X509 key size does not match any known key size.
2789 - Fail to parse X509 certificate.
2790 - Fail to allocate an intermediate buffer.
2791 - Null pointer provided for a non-optional parameter.
2792 - Data size is too large for the provided key size (max size is a function of key size
2793 and hash digest size).
2795 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2796 will be used to encrypt the data.
2797 @param[in] PublicKeySize Size of the X509 cert buffer.
2798 @param[in] InData Data to be encrypted.
2799 @param[in] InDataSize Size of the data buffer.
2800 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2801 to be used when initializing the PRNG. NULL otherwise.
2802 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2804 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2806 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2808 @retval TRUE Encryption was successful.
2809 @retval FALSE Encryption failed.
2815 IN CONST UINT8
*PublicKey
,
2816 IN UINTN PublicKeySize
,
2818 IN UINTN InDataSize
,
2819 IN CONST UINT8
*PrngSeed OPTIONAL
,
2820 IN UINTN PrngSeedSize OPTIONAL
,
2821 OUT UINT8
**EncryptedData
,
2822 OUT UINTN
*EncryptedDataSize
2825 CALL_CRYPTO_SERVICE (Pkcs1v2Encrypt
, (PublicKey
, PublicKeySize
, InData
, InDataSize
, PrngSeed
, PrngSeedSize
, EncryptedData
, EncryptedDataSize
), FALSE
);
2829 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2830 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2831 in a ContentInfo structure.
2833 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2834 return FALSE. If P7Length overflow, then return FALSE.
2835 If this interface is not supported, then return FALSE.
2837 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2838 @param[in] P7Length Length of the PKCS#7 message in bytes.
2839 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2840 It's caller's responsibility to free the buffer with
2842 This data structure is EFI_CERT_STACK type.
2843 @param[out] StackLength Length of signer's certificates in bytes.
2844 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2845 It's caller's responsibility to free the buffer with
2847 @param[out] CertLength Length of the trusted certificate in bytes.
2849 @retval TRUE The operation is finished successfully.
2850 @retval FALSE Error occurs during the operation.
2851 @retval FALSE This interface is not supported.
2857 IN CONST UINT8
*P7Data
,
2859 OUT UINT8
**CertStack
,
2860 OUT UINTN
*StackLength
,
2861 OUT UINT8
**TrustedCert
,
2862 OUT UINTN
*CertLength
2865 CALL_CRYPTO_SERVICE (Pkcs7GetSigners
, (P7Data
, P7Length
, CertStack
, StackLength
, TrustedCert
, CertLength
), FALSE
);
2869 Wrap function to use free() to free allocated memory for certificates.
2871 If this interface is not supported, then ASSERT().
2873 @param[in] Certs Pointer to the certificates to be freed.
2882 CALL_VOID_CRYPTO_SERVICE (Pkcs7FreeSigners
, (Certs
));
2886 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2887 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2888 unchained to the signer's certificates.
2889 The input signed data could be wrapped in a ContentInfo structure.
2891 @param[in] P7Data Pointer to the PKCS#7 message.
2892 @param[in] P7Length Length of the PKCS#7 message in bytes.
2893 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2894 certificate. It's caller's responsibility to free the buffer
2895 with Pkcs7FreeSigners().
2896 This data structure is EFI_CERT_STACK type.
2897 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2898 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2899 responsibility to free the buffer with Pkcs7FreeSigners().
2900 This data structure is EFI_CERT_STACK type.
2901 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2903 @retval TRUE The operation is finished successfully.
2904 @retval FALSE Error occurs during the operation.
2909 Pkcs7GetCertificatesList (
2910 IN CONST UINT8
*P7Data
,
2912 OUT UINT8
**SignerChainCerts
,
2913 OUT UINTN
*ChainLength
,
2914 OUT UINT8
**UnchainCerts
,
2915 OUT UINTN
*UnchainLength
2918 CALL_CRYPTO_SERVICE (Pkcs7GetCertificatesList
, (P7Data
, P7Length
, SignerChainCerts
, ChainLength
, UnchainCerts
, UnchainLength
), FALSE
);
2922 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2923 Syntax Standard, version 1.5". This interface is only intended to be used for
2924 application to perform PKCS#7 functionality validation.
2926 If this interface is not supported, then return FALSE.
2928 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2930 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2931 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2933 @param[in] InData Pointer to the content to be signed.
2934 @param[in] InDataSize Size of InData in bytes.
2935 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2936 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2937 include in the PKCS#7 signedData (e.g. any intermediate
2939 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2940 responsibility to free the buffer with FreePool().
2941 @param[out] SignedDataSize Size of SignedData in bytes.
2943 @retval TRUE PKCS#7 data signing succeeded.
2944 @retval FALSE PKCS#7 data signing failed.
2945 @retval FALSE This interface is not supported.
2951 IN CONST UINT8
*PrivateKey
,
2952 IN UINTN PrivateKeySize
,
2953 IN CONST UINT8
*KeyPassword
,
2955 IN UINTN InDataSize
,
2957 IN UINT8
*OtherCerts OPTIONAL
,
2958 OUT UINT8
**SignedData
,
2959 OUT UINTN
*SignedDataSize
2962 CALL_CRYPTO_SERVICE (Pkcs7Sign
, (PrivateKey
, PrivateKeySize
, KeyPassword
, InData
, InDataSize
, SignCert
, OtherCerts
, SignedData
, SignedDataSize
), FALSE
);
2966 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2967 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2968 in a ContentInfo structure.
2970 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2971 If P7Length, CertLength or DataLength overflow, then return FALSE.
2972 If this interface is not supported, then return FALSE.
2974 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2975 @param[in] P7Length Length of the PKCS#7 message in bytes.
2976 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2977 is used for certificate chain verification.
2978 @param[in] CertLength Length of the trusted certificate in bytes.
2979 @param[in] InData Pointer to the content to be verified.
2980 @param[in] DataLength Length of InData in bytes.
2982 @retval TRUE The specified PKCS#7 signed data is valid.
2983 @retval FALSE Invalid PKCS#7 signed data.
2984 @retval FALSE This interface is not supported.
2990 IN CONST UINT8
*P7Data
,
2992 IN CONST UINT8
*TrustedCert
,
2993 IN UINTN CertLength
,
2994 IN CONST UINT8
*InData
,
2998 CALL_CRYPTO_SERVICE (Pkcs7Verify
, (P7Data
, P7Length
, TrustedCert
, CertLength
, InData
, DataLength
), FALSE
);
3002 This function receives a PKCS7 formatted signature, and then verifies that
3003 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
3004 leaf signing certificate.
3005 Note that this function does not validate the certificate chain.
3007 Applications for custom EKU's are quite flexible. For example, a policy EKU
3008 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
3009 certificate issued might also contain this EKU, thus constraining the
3010 sub-ordinate certificate. Other applications might allow a certificate
3011 embedded in a device to specify that other Object Identifiers (OIDs) are
3012 present which contains binary data specifying custom capabilities that
3013 the device is able to do.
3015 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
3016 containing the content block with both the signature,
3017 the signer's certificate, and any necessary intermediate
3019 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
3020 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
3021 required EKUs that must be present in the signature.
3022 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
3023 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
3024 must be present in the leaf signer. If it is
3025 FALSE, then we will succeed if we find any
3026 of the specified EKU's.
3028 @retval EFI_SUCCESS The required EKUs were found in the signature.
3029 @retval EFI_INVALID_PARAMETER A parameter was invalid.
3030 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
3035 VerifyEKUsInPkcs7Signature (
3036 IN CONST UINT8
*Pkcs7Signature
,
3037 IN CONST UINT32 SignatureSize
,
3038 IN CONST CHAR8
*RequiredEKUs
[],
3039 IN CONST UINT32 RequiredEKUsSize
,
3040 IN BOOLEAN RequireAllPresent
3043 CALL_CRYPTO_SERVICE (VerifyEKUsInPkcs7Signature
, (Pkcs7Signature
, SignatureSize
, RequiredEKUs
, RequiredEKUsSize
, RequireAllPresent
), FALSE
);
3047 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
3048 data could be wrapped in a ContentInfo structure.
3050 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
3051 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
3053 Caution: This function may receive untrusted input. So this function will do
3054 basic check for PKCS#7 data structure.
3056 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
3057 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
3058 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
3059 It's caller's responsibility to free the buffer with FreePool().
3060 @param[out] ContentSize The size of the extracted content in bytes.
3062 @retval TRUE The P7Data was correctly formatted for processing.
3063 @retval FALSE The P7Data was not correctly formatted for processing.
3068 Pkcs7GetAttachedContent (
3069 IN CONST UINT8
*P7Data
,
3072 OUT UINTN
*ContentSize
3075 CALL_CRYPTO_SERVICE (Pkcs7GetAttachedContent
, (P7Data
, P7Length
, Content
, ContentSize
), FALSE
);
3079 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
3080 Authenticode Portable Executable Signature Format".
3082 If AuthData is NULL, then return FALSE.
3083 If ImageHash is NULL, then return FALSE.
3084 If this interface is not supported, then return FALSE.
3086 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
3087 PE/COFF image to be verified.
3088 @param[in] DataSize Size of the Authenticode Signature in bytes.
3089 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
3090 is used for certificate chain verification.
3091 @param[in] CertSize Size of the trusted certificate in bytes.
3092 @param[in] ImageHash Pointer to the original image file hash value. The procedure
3093 for calculating the image hash value is described in Authenticode
3095 @param[in] HashSize Size of Image hash value in bytes.
3097 @retval TRUE The specified Authenticode Signature is valid.
3098 @retval FALSE Invalid Authenticode Signature.
3099 @retval FALSE This interface is not supported.
3104 AuthenticodeVerify (
3105 IN CONST UINT8
*AuthData
,
3107 IN CONST UINT8
*TrustedCert
,
3109 IN CONST UINT8
*ImageHash
,
3113 CALL_CRYPTO_SERVICE (AuthenticodeVerify
, (AuthData
, DataSize
, TrustedCert
, CertSize
, ImageHash
, HashSize
), FALSE
);
3117 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
3120 If AuthData is NULL, then return FALSE.
3121 If this interface is not supported, then return FALSE.
3123 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
3124 PE/COFF image to be verified.
3125 @param[in] DataSize Size of the Authenticode Signature in bytes.
3126 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
3127 is used for TSA certificate chain verification.
3128 @param[in] CertSize Size of the trusted certificate in bytes.
3129 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
3132 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
3133 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
3138 ImageTimestampVerify (
3139 IN CONST UINT8
*AuthData
,
3141 IN CONST UINT8
*TsaCert
,
3143 OUT EFI_TIME
*SigningTime
3146 CALL_CRYPTO_SERVICE (ImageTimestampVerify
, (AuthData
, DataSize
, TsaCert
, CertSize
, SigningTime
), FALSE
);
3149 // =====================================================================================
3150 // DH Key Exchange Primitive
3151 // =====================================================================================
3154 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
3156 @return Pointer to the Diffie-Hellman Context that has been initialized.
3157 If the allocations fails, DhNew() returns NULL.
3158 If the interface is not supported, DhNew() returns NULL.
3167 CALL_CRYPTO_SERVICE (DhNew
, (), NULL
);
3171 Release the specified DH context.
3173 If the interface is not supported, then ASSERT().
3175 @param[in] DhContext Pointer to the DH context to be released.
3184 CALL_VOID_CRYPTO_SERVICE (DhFree
, (DhContext
));
3188 Generates DH parameter.
3190 Given generator g, and length of prime number p in bits, this function generates p,
3191 and sets DH context according to value of g and p.
3193 Before this function can be invoked, pseudorandom number generator must be correctly
3194 initialized by RandomSeed().
3196 If DhContext is NULL, then return FALSE.
3197 If Prime is NULL, then return FALSE.
3198 If this interface is not supported, then return FALSE.
3200 @param[in, out] DhContext Pointer to the DH context.
3201 @param[in] Generator Value of generator.
3202 @param[in] PrimeLength Length in bits of prime to be generated.
3203 @param[out] Prime Pointer to the buffer to receive the generated prime number.
3205 @retval TRUE DH parameter generation succeeded.
3206 @retval FALSE Value of Generator is not supported.
3207 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
3208 @retval FALSE This interface is not supported.
3213 DhGenerateParameter (
3214 IN OUT VOID
*DhContext
,
3216 IN UINTN PrimeLength
,
3220 CALL_CRYPTO_SERVICE (DhGenerateParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
3224 Sets generator and prime parameters for DH.
3226 Given generator g, and prime number p, this function and sets DH
3227 context accordingly.
3229 If DhContext is NULL, then return FALSE.
3230 If Prime is NULL, then return FALSE.
3231 If this interface is not supported, then return FALSE.
3233 @param[in, out] DhContext Pointer to the DH context.
3234 @param[in] Generator Value of generator.
3235 @param[in] PrimeLength Length in bits of prime to be generated.
3236 @param[in] Prime Pointer to the prime number.
3238 @retval TRUE DH parameter setting succeeded.
3239 @retval FALSE Value of Generator is not supported.
3240 @retval FALSE Value of Generator is not suitable for the Prime.
3241 @retval FALSE Value of Prime is not a prime number.
3242 @retval FALSE Value of Prime is not a safe prime number.
3243 @retval FALSE This interface is not supported.
3249 IN OUT VOID
*DhContext
,
3251 IN UINTN PrimeLength
,
3252 IN CONST UINT8
*Prime
3255 CALL_CRYPTO_SERVICE (DhSetParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
3259 Generates DH public key.
3261 This function generates random secret exponent, and computes the public key, which is
3262 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
3263 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
3264 PublicKeySize is set to the required buffer size to obtain the public key.
3266 If DhContext is NULL, then return FALSE.
3267 If PublicKeySize is NULL, then return FALSE.
3268 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
3269 If this interface is not supported, then return FALSE.
3271 @param[in, out] DhContext Pointer to the DH context.
3272 @param[out] PublicKey Pointer to the buffer to receive generated public key.
3273 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
3274 On output, the size of data returned in PublicKey buffer in bytes.
3276 @retval TRUE DH public key generation succeeded.
3277 @retval FALSE DH public key generation failed.
3278 @retval FALSE PublicKeySize is not large enough.
3279 @retval FALSE This interface is not supported.
3285 IN OUT VOID
*DhContext
,
3286 OUT UINT8
*PublicKey
,
3287 IN OUT UINTN
*PublicKeySize
3290 CALL_CRYPTO_SERVICE (DhGenerateKey
, (DhContext
, PublicKey
, PublicKeySize
), FALSE
);
3294 Computes exchanged common key.
3296 Given peer's public key, this function computes the exchanged common key, based on its own
3297 context including value of prime modulus and random secret exponent.
3299 If DhContext is NULL, then return FALSE.
3300 If PeerPublicKey is NULL, then return FALSE.
3301 If KeySize is NULL, then return FALSE.
3302 If Key is NULL, then return FALSE.
3303 If KeySize is not large enough, then return FALSE.
3304 If this interface is not supported, then return FALSE.
3306 @param[in, out] DhContext Pointer to the DH context.
3307 @param[in] PeerPublicKey Pointer to the peer's public key.
3308 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
3309 @param[out] Key Pointer to the buffer to receive generated key.
3310 @param[in, out] KeySize On input, the size of Key buffer in bytes.
3311 On output, the size of data returned in Key buffer in bytes.
3313 @retval TRUE DH exchanged key generation succeeded.
3314 @retval FALSE DH exchanged key generation failed.
3315 @retval FALSE KeySize is not large enough.
3316 @retval FALSE This interface is not supported.
3322 IN OUT VOID
*DhContext
,
3323 IN CONST UINT8
*PeerPublicKey
,
3324 IN UINTN PeerPublicKeySize
,
3326 IN OUT UINTN
*KeySize
3329 CALL_CRYPTO_SERVICE (DhComputeKey
, (DhContext
, PeerPublicKey
, PeerPublicKeySize
, Key
, KeySize
), FALSE
);
3332 // =====================================================================================
3333 // Pseudo-Random Generation Primitive
3334 // =====================================================================================
3337 Sets up the seed value for the pseudorandom number generator.
3339 This function sets up the seed value for the pseudorandom number generator.
3340 If Seed is not NULL, then the seed passed in is used.
3341 If Seed is NULL, then default seed is used.
3342 If this interface is not supported, then return FALSE.
3344 @param[in] Seed Pointer to seed value.
3345 If NULL, default seed is used.
3346 @param[in] SeedSize Size of seed value.
3347 If Seed is NULL, this parameter is ignored.
3349 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
3350 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
3351 @retval FALSE This interface is not supported.
3357 IN CONST UINT8
*Seed OPTIONAL
,
3361 CALL_CRYPTO_SERVICE (RandomSeed
, (Seed
, SeedSize
), FALSE
);
3365 Generates a pseudorandom byte stream of the specified size.
3367 If Output is NULL, then return FALSE.
3368 If this interface is not supported, then return FALSE.
3370 @param[out] Output Pointer to buffer to receive random value.
3371 @param[in] Size Size of random bytes to generate.
3373 @retval TRUE Pseudorandom byte stream generated successfully.
3374 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
3375 @retval FALSE This interface is not supported.
3385 CALL_CRYPTO_SERVICE (RandomBytes
, (Output
, Size
), FALSE
);
3388 // =====================================================================================
3389 // Key Derivation Function Primitive
3390 // =====================================================================================
3393 Derive key data using HMAC-SHA256 based KDF.
3395 @param[in] Key Pointer to the user-supplied key.
3396 @param[in] KeySize Key size in bytes.
3397 @param[in] Salt Pointer to the salt(non-secret) value.
3398 @param[in] SaltSize Salt size in bytes.
3399 @param[in] Info Pointer to the application specific info.
3400 @param[in] InfoSize Info size in bytes.
3401 @param[out] Out Pointer to buffer to receive hkdf value.
3402 @param[in] OutSize Size of hkdf bytes to generate.
3404 @retval TRUE Hkdf generated successfully.
3405 @retval FALSE Hkdf generation failed.
3410 HkdfSha256ExtractAndExpand (
3411 IN CONST UINT8
*Key
,
3413 IN CONST UINT8
*Salt
,
3415 IN CONST UINT8
*Info
,
3421 CALL_CRYPTO_SERVICE (HkdfSha256ExtractAndExpand
, (Key
, KeySize
, Salt
, SaltSize
, Info
, InfoSize
, Out
, OutSize
), FALSE
);
3425 Derive SHA256 HMAC-based Extract key Derivation Function (HKDF).
3427 @param[in] Key Pointer to the user-supplied key.
3428 @param[in] KeySize key size in bytes.
3429 @param[in] Salt Pointer to the salt(non-secret) value.
3430 @param[in] SaltSize salt size in bytes.
3431 @param[out] PrkOut Pointer to buffer to receive hkdf value.
3432 @param[in] PrkOutSize size of hkdf bytes to generate.
3434 @retval true Hkdf generated successfully.
3435 @retval false Hkdf generation failed.
3441 IN CONST UINT8
*Key
,
3443 IN CONST UINT8
*Salt
,
3449 CALL_CRYPTO_SERVICE (HkdfSha256Extract
, (Key
, KeySize
, Salt
, SaltSize
, PrkOut
, PrkOutSize
), FALSE
);
3453 Derive SHA256 HMAC-based Expand Key Derivation Function (HKDF).
3455 @param[in] Prk Pointer to the user-supplied key.
3456 @param[in] PrkSize Key size in bytes.
3457 @param[in] Info Pointer to the application specific info.
3458 @param[in] InfoSize Info size in bytes.
3459 @param[out] Out Pointer to buffer to receive hkdf value.
3460 @param[in] OutSize Size of hkdf bytes to generate.
3462 @retval TRUE Hkdf generated successfully.
3463 @retval FALSE Hkdf generation failed.
3469 IN CONST UINT8
*Prk
,
3471 IN CONST UINT8
*Info
,
3477 CALL_CRYPTO_SERVICE (HkdfSha256Expand
, (Prk
, PrkSize
, Info
, InfoSize
, Out
, OutSize
), FALSE
);
3481 Derive SHA384 HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
3483 @param[in] Key Pointer to the user-supplied key.
3484 @param[in] KeySize Key size in bytes.
3485 @param[in] Salt Pointer to the salt(non-secret) value.
3486 @param[in] SaltSize Salt size in bytes.
3487 @param[in] Info Pointer to the application specific info.
3488 @param[in] InfoSize Info size in bytes.
3489 @param[out] Out Pointer to buffer to receive hkdf value.
3490 @param[in] OutSize Size of hkdf bytes to generate.
3492 @retval TRUE Hkdf generated successfully.
3493 @retval FALSE Hkdf generation failed.
3498 HkdfSha384ExtractAndExpand (
3499 IN CONST UINT8
*Key
,
3501 IN CONST UINT8
*Salt
,
3503 IN CONST UINT8
*Info
,
3509 CALL_CRYPTO_SERVICE (HkdfSha384ExtractAndExpand
, (Key
, KeySize
, Salt
, SaltSize
, Info
, InfoSize
, Out
, OutSize
), FALSE
);
3513 Derive SHA384 HMAC-based Extract key Derivation Function (HKDF).
3515 @param[in] Key Pointer to the user-supplied key.
3516 @param[in] KeySize key size in bytes.
3517 @param[in] Salt Pointer to the salt(non-secret) value.
3518 @param[in] SaltSize salt size in bytes.
3519 @param[out] PrkOut Pointer to buffer to receive hkdf value.
3520 @param[in] PrkOutSize size of hkdf bytes to generate.
3522 @retval true Hkdf generated successfully.
3523 @retval false Hkdf generation failed.
3529 IN CONST UINT8
*Key
,
3531 IN CONST UINT8
*Salt
,
3537 CALL_CRYPTO_SERVICE (HkdfSha384Extract
, (Key
, KeySize
, Salt
, SaltSize
, PrkOut
, PrkOutSize
), FALSE
);
3541 Derive SHA384 HMAC-based Expand Key Derivation Function (HKDF).
3543 @param[in] Prk Pointer to the user-supplied key.
3544 @param[in] PrkSize Key size in bytes.
3545 @param[in] Info Pointer to the application specific info.
3546 @param[in] InfoSize Info size in bytes.
3547 @param[out] Out Pointer to buffer to receive hkdf value.
3548 @param[in] OutSize Size of hkdf bytes to generate.
3550 @retval TRUE Hkdf generated successfully.
3551 @retval FALSE Hkdf generation failed.
3557 IN CONST UINT8
*Prk
,
3559 IN CONST UINT8
*Info
,
3565 CALL_CRYPTO_SERVICE (HkdfSha384Expand
, (Prk
, PrkSize
, Info
, InfoSize
, Out
, OutSize
), FALSE
);
3569 Initializes the OpenSSL library.
3571 This function registers ciphers and digests used directly and indirectly
3572 by SSL/TLS, and initializes the readable error messages.
3573 This function must be called before any other action takes places.
3575 @retval TRUE The OpenSSL library has been initialized.
3576 @retval FALSE Failed to initialize the OpenSSL library.
3585 CALL_CRYPTO_SERVICE (TlsInitialize
, (), FALSE
);
3589 Free an allocated SSL_CTX object.
3591 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
3600 CALL_VOID_CRYPTO_SERVICE (TlsCtxFree
, (TlsCtx
));
3604 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
3607 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3608 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3610 @return Pointer to an allocated SSL_CTX object.
3611 If the creation failed, TlsCtxNew() returns NULL.
3621 CALL_CRYPTO_SERVICE (TlsCtxNew
, (MajorVer
, MinorVer
), NULL
);
3625 Free an allocated TLS object.
3627 This function removes the TLS object pointed to by Tls and frees up the
3628 allocated memory. If Tls is NULL, nothing is done.
3630 @param[in] Tls Pointer to the TLS object to be freed.
3639 CALL_VOID_CRYPTO_SERVICE (TlsFree
, (Tls
));
3643 Create a new TLS object for a connection.
3645 This function creates a new TLS object for a connection. The new object
3646 inherits the setting of the underlying context TlsCtx: connection method,
3647 options, verification setting.
3649 @param[in] TlsCtx Pointer to the SSL_CTX object.
3651 @return Pointer to an allocated SSL object.
3652 If the creation failed, TlsNew() returns NULL.
3661 CALL_CRYPTO_SERVICE (TlsNew
, (TlsCtx
), NULL
);
3665 Checks if the TLS handshake was done.
3667 This function will check if the specified TLS handshake was done.
3669 @param[in] Tls Pointer to the TLS object for handshake state checking.
3671 @retval TRUE The TLS handshake was done.
3672 @retval FALSE The TLS handshake was not done.
3681 CALL_CRYPTO_SERVICE (TlsInHandshake
, (Tls
), FALSE
);
3685 Perform a TLS/SSL handshake.
3687 This function will perform a TLS/SSL handshake.
3689 @param[in] Tls Pointer to the TLS object for handshake operation.
3690 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
3691 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3693 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3694 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3695 the buffer size provided by the caller. On output, it
3696 is the buffer size in fact needed to contain the
3699 @retval EFI_SUCCESS The required TLS packet is built successfully.
3700 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3702 BufferIn is NULL but BufferInSize is NOT 0.
3703 BufferInSize is 0 but BufferIn is NOT NULL.
3704 BufferOutSize is NULL.
3705 BufferOut is NULL if *BufferOutSize is not zero.
3706 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3707 @retval EFI_ABORTED Something wrong during handshake.
3714 IN UINT8
*BufferIn OPTIONAL
,
3715 IN UINTN BufferInSize OPTIONAL
,
3716 OUT UINT8
*BufferOut OPTIONAL
,
3717 IN OUT UINTN
*BufferOutSize
3720 CALL_CRYPTO_SERVICE (TlsDoHandshake
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
3724 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
3725 TLS session has errors and the response packet needs to be Alert message based on error type.
3727 @param[in] Tls Pointer to the TLS object for state checking.
3728 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
3729 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3731 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3732 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3733 the buffer size provided by the caller. On output, it
3734 is the buffer size in fact needed to contain the
3737 @retval EFI_SUCCESS The required TLS packet is built successfully.
3738 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3740 BufferIn is NULL but BufferInSize is NOT 0.
3741 BufferInSize is 0 but BufferIn is NOT NULL.
3742 BufferOutSize is NULL.
3743 BufferOut is NULL if *BufferOutSize is not zero.
3744 @retval EFI_ABORTED An error occurred.
3745 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3752 IN UINT8
*BufferIn OPTIONAL
,
3753 IN UINTN BufferInSize OPTIONAL
,
3754 OUT UINT8
*BufferOut OPTIONAL
,
3755 IN OUT UINTN
*BufferOutSize
3758 CALL_CRYPTO_SERVICE (TlsHandleAlert
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
3762 Build the CloseNotify packet.
3764 @param[in] Tls Pointer to the TLS object for state checking.
3765 @param[in, out] Buffer Pointer to the buffer to hold the built packet.
3766 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
3767 the buffer size provided by the caller. On output, it
3768 is the buffer size in fact needed to contain the
3771 @retval EFI_SUCCESS The required TLS packet is built successfully.
3772 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3775 Buffer is NULL if *BufferSize is not zero.
3776 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
3783 IN OUT UINT8
*Buffer
,
3784 IN OUT UINTN
*BufferSize
3787 CALL_CRYPTO_SERVICE (TlsCloseNotify
, (Tls
, Buffer
, BufferSize
), EFI_UNSUPPORTED
);
3791 Attempts to read bytes from one TLS object and places the data in Buffer.
3793 This function will attempt to read BufferSize bytes from the TLS object
3794 and places the data in Buffer.
3796 @param[in] Tls Pointer to the TLS object.
3797 @param[in,out] Buffer Pointer to the buffer to store the data.
3798 @param[in] BufferSize The size of Buffer in bytes.
3800 @retval >0 The amount of data successfully read from the TLS object.
3801 @retval <=0 No data was successfully read.
3808 IN OUT VOID
*Buffer
,
3812 CALL_CRYPTO_SERVICE (TlsCtrlTrafficOut
, (Tls
, Buffer
, BufferSize
), 0);
3816 Attempts to write data from the buffer to TLS object.
3818 This function will attempt to write BufferSize bytes data from the Buffer
3821 @param[in] Tls Pointer to the TLS object.
3822 @param[in] Buffer Pointer to the data buffer.
3823 @param[in] BufferSize The size of Buffer in bytes.
3825 @retval >0 The amount of data successfully written to the TLS object.
3826 @retval <=0 No data was successfully written.
3837 CALL_CRYPTO_SERVICE (TlsCtrlTrafficIn
, (Tls
, Buffer
, BufferSize
), 0);
3841 Attempts to read bytes from the specified TLS connection into the buffer.
3843 This function tries to read BufferSize bytes data from the specified TLS
3844 connection into the Buffer.
3846 @param[in] Tls Pointer to the TLS connection for data reading.
3847 @param[in,out] Buffer Pointer to the data buffer.
3848 @param[in] BufferSize The size of Buffer in bytes.
3850 @retval >0 The read operation was successful, and return value is the
3851 number of bytes actually read from the TLS connection.
3852 @retval <=0 The read operation was not successful.
3859 IN OUT VOID
*Buffer
,
3863 CALL_CRYPTO_SERVICE (TlsRead
, (Tls
, Buffer
, BufferSize
), 0);
3867 Attempts to write data to a TLS connection.
3869 This function tries to write BufferSize bytes data from the Buffer into the
3870 specified TLS connection.
3872 @param[in] Tls Pointer to the TLS connection for data writing.
3873 @param[in] Buffer Pointer to the data buffer.
3874 @param[in] BufferSize The size of Buffer in bytes.
3876 @retval >0 The write operation was successful, and return value is the
3877 number of bytes actually written to the TLS connection.
3878 @retval <=0 The write operation was not successful.
3889 CALL_CRYPTO_SERVICE (TlsWrite
, (Tls
, Buffer
, BufferSize
), 0);
3893 Shutdown a TLS connection.
3895 Shutdown the TLS connection without releasing the resources, meaning a new
3896 connection can be started without calling TlsNew() and without setting
3899 @param[in] Tls Pointer to the TLS object to shutdown.
3901 @retval EFI_SUCCESS The TLS is shutdown successfully.
3902 @retval EFI_INVALID_PARAMETER Tls is NULL.
3903 @retval EFI_PROTOCOL_ERROR Some other error occurred.
3911 CALL_CRYPTO_SERVICE (TlsShutdown
, (Tls
), EFI_UNSUPPORTED
);
3915 Set a new TLS/SSL method for a particular TLS object.
3917 This function sets a new TLS/SSL method for a particular TLS object.
3919 @param[in] Tls Pointer to a TLS object.
3920 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3921 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3923 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
3924 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3925 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
3936 CALL_CRYPTO_SERVICE (TlsSetVersion
, (Tls
, MajorVer
, MinorVer
), EFI_UNSUPPORTED
);
3940 Set TLS object to work in client or server mode.
3942 This function prepares a TLS object to work in client or server mode.
3944 @param[in] Tls Pointer to a TLS object.
3945 @param[in] IsServer Work in server mode.
3947 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
3948 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3949 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
3954 TlsSetConnectionEnd (
3959 CALL_CRYPTO_SERVICE (TlsSetConnectionEnd
, (Tls
, IsServer
), EFI_UNSUPPORTED
);
3963 Set the ciphers list to be used by the TLS object.
3965 This function sets the ciphers for use by a specified TLS object.
3967 @param[in] Tls Pointer to a TLS object.
3968 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
3969 cipher identifier comes from the TLS Cipher Suite
3970 Registry of the IANA, interpreting Byte1 and Byte2
3971 in network (big endian) byte order.
3972 @param[in] CipherNum The number of cipher in the list.
3974 @retval EFI_SUCCESS The ciphers list was set successfully.
3975 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3976 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
3977 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
3984 IN UINT16
*CipherId
,
3988 CALL_CRYPTO_SERVICE (TlsSetCipherList
, (Tls
, CipherId
, CipherNum
), EFI_UNSUPPORTED
);
3992 Set the compression method for TLS/SSL operations.
3994 This function handles TLS/SSL integrated compression methods.
3996 @param[in] CompMethod The compression method ID.
3998 @retval EFI_SUCCESS The compression method for the communication was
4000 @retval EFI_UNSUPPORTED Unsupported compression method.
4005 TlsSetCompressionMethod (
4009 CALL_CRYPTO_SERVICE (TlsSetCompressionMethod
, (CompMethod
), EFI_UNSUPPORTED
);
4013 Set peer certificate verification mode for the TLS connection.
4015 This function sets the verification mode flags for the TLS connection.
4017 @param[in] Tls Pointer to the TLS object.
4018 @param[in] VerifyMode A set of logically or'ed verification mode flags.
4025 IN UINT32 VerifyMode
4028 CALL_VOID_CRYPTO_SERVICE (TlsSetVerify
, (Tls
, VerifyMode
));
4032 Set the specified host name to be verified.
4034 @param[in] Tls Pointer to the TLS object.
4035 @param[in] Flags The setting flags during the validation.
4036 @param[in] HostName The specified host name to be verified.
4038 @retval EFI_SUCCESS The HostName setting was set successfully.
4039 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4040 @retval EFI_ABORTED Invalid HostName setting.
4051 CALL_CRYPTO_SERVICE (TlsSetVerifyHost
, (Tls
, Flags
, HostName
), EFI_UNSUPPORTED
);
4055 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
4057 This function sets a session ID to be used when the TLS/SSL connection is
4060 @param[in] Tls Pointer to the TLS object.
4061 @param[in] SessionId Session ID data used for session resumption.
4062 @param[in] SessionIdLen Length of Session ID in bytes.
4064 @retval EFI_SUCCESS Session ID was set successfully.
4065 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4066 @retval EFI_UNSUPPORTED No available session for ID setting.
4073 IN UINT8
*SessionId
,
4074 IN UINT16 SessionIdLen
4077 CALL_CRYPTO_SERVICE (TlsSetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
4081 Adds the CA to the cert store when requesting Server or Client authentication.
4083 This function adds the CA certificate to the list of CAs when requesting
4084 Server or Client authentication for the chosen TLS connection.
4086 @param[in] Tls Pointer to the TLS object.
4087 @param[in] Data Pointer to the data buffer of a DER-encoded binary
4088 X.509 certificate or PEM-encoded X.509 certificate.
4089 @param[in] DataSize The size of data buffer in bytes.
4091 @retval EFI_SUCCESS The operation succeeded.
4092 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4093 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
4094 @retval EFI_ABORTED Invalid X.509 certificate.
4099 TlsSetCaCertificate (
4105 CALL_CRYPTO_SERVICE (TlsSetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4109 Loads the local public certificate into the specified TLS object.
4111 This function loads the X.509 certificate into the specified TLS object
4112 for TLS negotiation.
4114 @param[in] Tls Pointer to the TLS object.
4115 @param[in] Data Pointer to the data buffer of a DER-encoded binary
4116 X.509 certificate or PEM-encoded X.509 certificate.
4117 @param[in] DataSize The size of data buffer in bytes.
4119 @retval EFI_SUCCESS The operation succeeded.
4120 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4121 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
4122 @retval EFI_ABORTED Invalid X.509 certificate.
4127 TlsSetHostPublicCert (
4133 CALL_CRYPTO_SERVICE (TlsSetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4137 Adds the local private key to the specified TLS object.
4139 This function adds the local private key (DER-encoded or PEM-encoded or PKCS#8 private
4140 key) into the specified TLS object for TLS negotiation.
4142 @param[in] Tls Pointer to the TLS object.
4143 @param[in] Data Pointer to the data buffer of a DER-encoded or PEM-encoded
4144 or PKCS#8 private key.
4145 @param[in] DataSize The size of data buffer in bytes.
4146 @param[in] Password Pointer to NULL-terminated private key password, set it to NULL
4147 if private key not encrypted.
4149 @retval EFI_SUCCESS The operation succeeded.
4150 @retval EFI_UNSUPPORTED This function is not supported.
4151 @retval EFI_ABORTED Invalid private key data.
4156 TlsSetHostPrivateKeyEx (
4160 IN VOID
*Password OPTIONAL
4163 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKeyEx
, (Tls
, Data
, DataSize
, Password
), EFI_UNSUPPORTED
);
4167 Adds the local private key to the specified TLS object.
4169 This function adds the local private key (DER-encoded or PEM-encoded or PKCS#8 private
4170 key) into the specified TLS object for TLS negotiation.
4172 @param[in] Tls Pointer to the TLS object.
4173 @param[in] Data Pointer to the data buffer of a DER-encoded or PEM-encoded
4174 or PKCS#8 private key.
4175 @param[in] DataSize The size of data buffer in bytes.
4177 @retval EFI_SUCCESS The operation succeeded.
4178 @retval EFI_UNSUPPORTED This function is not supported.
4179 @retval EFI_ABORTED Invalid private key data.
4184 TlsSetHostPrivateKey (
4190 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4194 Adds the CA-supplied certificate revocation list for certificate validation.
4196 This function adds the CA-supplied certificate revocation list data for
4197 certificate validity checking.
4199 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
4200 @param[in] DataSize The size of data buffer in bytes.
4202 @retval EFI_SUCCESS The operation succeeded.
4203 @retval EFI_UNSUPPORTED This function is not supported.
4204 @retval EFI_ABORTED Invalid CRL data.
4209 TlsSetCertRevocationList (
4214 CALL_CRYPTO_SERVICE (TlsSetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);
4218 Set the signature algorithm list to used by the TLS object.
4220 This function sets the signature algorithms for use by a specified TLS object.
4222 @param[in] Tls Pointer to a TLS object.
4223 @param[in] Data Array of UINT8 of signature algorithms. The array consists of
4224 pairs of the hash algorithm and the signature algorithm as defined
4226 @param[in] DataSize The length the SignatureAlgoList. Must be divisible by 2.
4228 @retval EFI_SUCCESS The signature algorithm list was set successfully.
4229 @retval EFI_INVALID_PARAMETER The parameters are invalid.
4230 @retval EFI_UNSUPPORTED No supported TLS signature algorithm was found in SignatureAlgoList
4231 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
4236 TlsSetSignatureAlgoList (
4242 CALL_CRYPTO_SERVICE (TlsSetSignatureAlgoList
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4246 Set the EC curve to be used for TLS flows
4248 This function sets the EC curve to be used for TLS flows.
4250 @param[in] Tls Pointer to a TLS object.
4251 @param[in] Data An EC named curve as defined in section 5.1.1 of RFC 4492.
4252 @param[in] DataSize Size of Data, it should be sizeof (UINT32)
4254 @retval EFI_SUCCESS The EC curve was set successfully.
4255 @retval EFI_INVALID_PARAMETER The parameters are invalid.
4256 @retval EFI_UNSUPPORTED The requested TLS EC curve is not supported
4267 CALL_CRYPTO_SERVICE (TlsSetSignatureAlgoList
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4271 Gets the protocol version used by the specified TLS connection.
4273 This function returns the protocol version used by the specified TLS
4276 If Tls is NULL, then ASSERT().
4278 @param[in] Tls Pointer to the TLS object.
4280 @return The protocol version of the specified TLS connection.
4289 CALL_CRYPTO_SERVICE (TlsGetVersion
, (Tls
), 0);
4293 Gets the connection end of the specified TLS connection.
4295 This function returns the connection end (as client or as server) used by
4296 the specified TLS connection.
4298 If Tls is NULL, then ASSERT().
4300 @param[in] Tls Pointer to the TLS object.
4302 @return The connection end used by the specified TLS connection.
4307 TlsGetConnectionEnd (
4311 CALL_CRYPTO_SERVICE (TlsGetConnectionEnd
, (Tls
), 0);
4315 Gets the cipher suite used by the specified TLS connection.
4317 This function returns current cipher suite used by the specified
4320 @param[in] Tls Pointer to the TLS object.
4321 @param[in,out] CipherId The cipher suite used by the TLS object.
4323 @retval EFI_SUCCESS The cipher suite was returned successfully.
4324 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4325 @retval EFI_UNSUPPORTED Unsupported cipher suite.
4330 TlsGetCurrentCipher (
4332 IN OUT UINT16
*CipherId
4335 CALL_CRYPTO_SERVICE (TlsGetCurrentCipher
, (Tls
, CipherId
), EFI_UNSUPPORTED
);
4339 Gets the compression methods used by the specified TLS connection.
4341 This function returns current integrated compression methods used by
4342 the specified TLS connection.
4344 @param[in] Tls Pointer to the TLS object.
4345 @param[in,out] CompressionId The current compression method used by
4348 @retval EFI_SUCCESS The compression method was returned successfully.
4349 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4350 @retval EFI_ABORTED Invalid Compression method.
4351 @retval EFI_UNSUPPORTED This function is not supported.
4356 TlsGetCurrentCompressionId (
4358 IN OUT UINT8
*CompressionId
4361 CALL_CRYPTO_SERVICE (TlsGetCurrentCompressionId
, (Tls
, CompressionId
), EFI_UNSUPPORTED
);
4365 Gets the verification mode currently set in the TLS connection.
4367 This function returns the peer verification mode currently set in the
4368 specified TLS connection.
4370 If Tls is NULL, then ASSERT().
4372 @param[in] Tls Pointer to the TLS object.
4374 @return The verification mode set in the specified TLS connection.
4383 CALL_CRYPTO_SERVICE (TlsGetVerify
, (Tls
), 0);
4387 Gets the session ID used by the specified TLS connection.
4389 This function returns the TLS/SSL session ID currently used by the
4390 specified TLS connection.
4392 @param[in] Tls Pointer to the TLS object.
4393 @param[in,out] SessionId Buffer to contain the returned session ID.
4394 @param[in,out] SessionIdLen The length of Session ID in bytes.
4396 @retval EFI_SUCCESS The Session ID was returned successfully.
4397 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4398 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
4405 IN OUT UINT8
*SessionId
,
4406 IN OUT UINT16
*SessionIdLen
4409 CALL_CRYPTO_SERVICE (TlsGetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
4413 Gets the client random data used in the specified TLS connection.
4415 This function returns the TLS/SSL client random data currently used in
4416 the specified TLS connection.
4418 @param[in] Tls Pointer to the TLS object.
4419 @param[in,out] ClientRandom Buffer to contain the returned client
4420 random data (32 bytes).
4425 TlsGetClientRandom (
4427 IN OUT UINT8
*ClientRandom
4430 CALL_VOID_CRYPTO_SERVICE (TlsGetClientRandom
, (Tls
, ClientRandom
));
4434 Gets the server random data used in the specified TLS connection.
4436 This function returns the TLS/SSL server random data currently used in
4437 the specified TLS connection.
4439 @param[in] Tls Pointer to the TLS object.
4440 @param[in,out] ServerRandom Buffer to contain the returned server
4441 random data (32 bytes).
4446 TlsGetServerRandom (
4448 IN OUT UINT8
*ServerRandom
4451 CALL_VOID_CRYPTO_SERVICE (TlsGetServerRandom
, (Tls
, ServerRandom
));
4455 Gets the master key data used in the specified TLS connection.
4457 This function returns the TLS/SSL master key material currently used in
4458 the specified TLS connection.
4460 @param[in] Tls Pointer to the TLS object.
4461 @param[in,out] KeyMaterial Buffer to contain the returned key material.
4463 @retval EFI_SUCCESS Key material was returned successfully.
4464 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4465 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
4472 IN OUT UINT8
*KeyMaterial
4475 CALL_CRYPTO_SERVICE (TlsGetKeyMaterial
, (Tls
, KeyMaterial
), EFI_UNSUPPORTED
);
4479 Gets the CA Certificate from the cert store.
4481 This function returns the CA certificate for the chosen
4484 @param[in] Tls Pointer to the TLS object.
4485 @param[out] Data Pointer to the data buffer to receive the CA
4486 certificate data sent to the client.
4487 @param[in,out] DataSize The size of data buffer in bytes.
4489 @retval EFI_SUCCESS The operation succeeded.
4490 @retval EFI_UNSUPPORTED This function is not supported.
4491 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4496 TlsGetCaCertificate (
4499 IN OUT UINTN
*DataSize
4502 CALL_CRYPTO_SERVICE (TlsGetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4506 Gets the local public Certificate set in the specified TLS object.
4508 This function returns the local public certificate which was currently set
4509 in the specified TLS object.
4511 @param[in] Tls Pointer to the TLS object.
4512 @param[out] Data Pointer to the data buffer to receive the local
4514 @param[in,out] DataSize The size of data buffer in bytes.
4516 @retval EFI_SUCCESS The operation succeeded.
4517 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4518 @retval EFI_NOT_FOUND The certificate is not found.
4519 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4524 TlsGetHostPublicCert (
4527 IN OUT UINTN
*DataSize
4530 CALL_CRYPTO_SERVICE (TlsGetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4534 Gets the local private key set in the specified TLS object.
4536 This function returns the local private key data which was currently set
4537 in the specified TLS object.
4539 @param[in] Tls Pointer to the TLS object.
4540 @param[out] Data Pointer to the data buffer to receive the local
4542 @param[in,out] DataSize The size of data buffer in bytes.
4544 @retval EFI_SUCCESS The operation succeeded.
4545 @retval EFI_UNSUPPORTED This function is not supported.
4546 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4551 TlsGetHostPrivateKey (
4554 IN OUT UINTN
*DataSize
4557 CALL_CRYPTO_SERVICE (TlsGetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4561 Gets the CA-supplied certificate revocation list data set in the specified
4564 This function returns the CA-supplied certificate revocation list data which
4565 was currently set in the specified TLS object.
4567 @param[out] Data Pointer to the data buffer to receive the CRL data.
4568 @param[in,out] DataSize The size of data buffer in bytes.
4570 @retval EFI_SUCCESS The operation succeeded.
4571 @retval EFI_UNSUPPORTED This function is not supported.
4572 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4577 TlsGetCertRevocationList (
4579 IN OUT UINTN
*DataSize
4582 CALL_CRYPTO_SERVICE (TlsGetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);
4586 Derive keying material from a TLS connection.
4588 This function exports keying material using the mechanism described in RFC
4591 @param[in] Tls Pointer to the TLS object
4592 @param[in] Label Description of the key for the PRF function
4593 @param[in] Context Optional context
4594 @param[in] ContextLen The length of the context value in bytes
4595 @param[out] KeyBuffer Buffer to hold the output of the TLS-PRF
4596 @param[in] KeyBufferLen The length of the KeyBuffer
4598 @retval EFI_SUCCESS The operation succeeded.
4599 @retval EFI_INVALID_PARAMETER The TLS object is invalid.
4600 @retval EFI_PROTOCOL_ERROR Some other error occurred.
4607 IN CONST VOID
*Label
,
4608 IN CONST VOID
*Context
,
4609 IN UINTN ContextLen
,
4610 OUT VOID
*KeyBuffer
,
4611 IN UINTN KeyBufferLen
4614 CALL_CRYPTO_SERVICE (
4616 (Tls
, Label
, Context
, ContextLen
,
4617 KeyBuffer
, KeyBufferLen
),
4622 // =====================================================================================
4623 // Big number primitive
4624 // =====================================================================================
4627 Allocate new Big Number.
4629 @retval New BigNum opaque structure or NULL on failure.
4637 CALL_CRYPTO_SERVICE (BigNumInit
, (), NULL
);
4641 Allocate new Big Number and assign the provided value to it.
4643 @param[in] Buf Big endian encoded buffer.
4644 @param[in] Len Buffer length.
4646 @retval New BigNum opaque structure or NULL on failure.
4651 IN CONST UINT8
*Buf
,
4655 CALL_CRYPTO_SERVICE (BigNumFromBin
, (Buf
, Len
), NULL
);
4659 Convert the absolute value of Bn into big-endian form and store it at Buf.
4660 The Buf array should have at least BigNumBytes() in it.
4662 @param[in] Bn Big number to convert.
4663 @param[out] Buf Output buffer.
4665 @retval The length of the big-endian number placed at Buf or -1 on error.
4674 CALL_CRYPTO_SERVICE (BigNumToBin
, (Bn
, Buf
), -1);
4678 Free the Big Number.
4680 @param[in] Bn Big number to free.
4681 @param[in] Clear TRUE if the buffer should be cleared.
4690 CALL_VOID_CRYPTO_SERVICE (BigNumFree
, (Bn
, Clear
));
4694 Calculate the sum of two Big Numbers.
4695 Please note, all "out" Big number arguments should be properly initialized
4696 by calling to BigNumInit() or BigNumFromBin() functions.
4698 @param[in] BnA Big number.
4699 @param[in] BnB Big number.
4700 @param[out] BnRes The result of BnA + BnB.
4702 @retval TRUE On success.
4703 @retval FALSE Otherwise.
4713 CALL_CRYPTO_SERVICE (BigNumAdd
, (BnA
, BnB
, BnRes
), FALSE
);
4717 Subtract two Big Numbers.
4718 Please note, all "out" Big number arguments should be properly initialized
4719 by calling to BigNumInit() or BigNumFromBin() functions.
4721 @param[in] BnA Big number.
4722 @param[in] BnB Big number.
4723 @param[out] BnRes The result of BnA - BnB.
4725 @retval TRUE On success.
4726 @retval FALSE Otherwise.
4736 CALL_CRYPTO_SERVICE (BigNumSub
, (BnA
, BnB
, BnRes
), FALSE
);
4740 Calculate remainder: BnRes = BnA % BnB
4741 Please note, all "out" Big number arguments should be properly initialized
4742 by calling to BigNumInit() or BigNumFromBin() functions.
4744 @param[in] BnA Big number.
4745 @param[in] BnB Big number.
4746 @param[out] BnRes The result of BnA % BnB.
4748 @retval TRUE On success.
4749 @retval FALSE Otherwise.
4759 CALL_CRYPTO_SERVICE (BigNumMod
, (BnA
, BnB
, BnRes
), FALSE
);
4763 Compute BnA to the BnP-th power modulo BnM.
4764 Please note, all "out" Big number arguments should be properly initialized
4765 by calling to BigNumInit() or BigNumFromBin() functions.
4767 @param[in] BnA Big number.
4768 @param[in] BnP Big number (power).
4769 @param[in] BnM Big number (modulo).
4770 @param[out] BnRes The result of (BnA ^ BnP) % BnM.
4772 @retval TRUE On success.
4773 @retval FALSE Otherwise.
4784 CALL_CRYPTO_SERVICE (BigNumExpMod
, (BnA
, BnP
, BnM
, BnRes
), FALSE
);
4788 Compute BnA inverse modulo BnM.
4789 Please note, all "out" Big number arguments should be properly initialized
4790 by calling to BigNumInit() or BigNumFromBin() functions.
4792 @param[in] BnA Big number.
4793 @param[in] BnM Big number (modulo).
4794 @param[out] BnRes The result, such that (BnA * BnRes) % BnM == 1.
4796 @retval TRUE On success.
4797 @retval FALSE Otherwise.
4807 CALL_CRYPTO_SERVICE (BigNumInverseMod
, (BnA
, BnM
, BnRes
), FALSE
);
4811 Divide two Big Numbers.
4812 Please note, all "out" Big number arguments should be properly initialized
4813 by calling to BigNumInit() or BigNumFromBin() functions.
4815 @param[in] BnA Big number.
4816 @param[in] BnB Big number.
4817 @param[out] BnRes The result, such that BnA / BnB.
4819 @retval TRUE On success.
4820 @retval FALSE Otherwise.
4830 CALL_CRYPTO_SERVICE (BigNumDiv
, (BnA
, BnB
, BnRes
), FALSE
);
4834 Multiply two Big Numbers modulo BnM.
4835 Please note, all "out" Big number arguments should be properly initialized
4836 by calling to BigNumInit() or BigNumFromBin() functions.
4838 @param[in] BnA Big number.
4839 @param[in] BnB Big number.
4840 @param[in] BnM Big number (modulo).
4841 @param[out] BnRes The result, such that (BnA * BnB) % BnM.
4843 @retval TRUE On success.
4844 @retval FALSE Otherwise.
4855 CALL_CRYPTO_SERVICE (BigNumMulMod
, (BnA
, BnB
, BnM
, BnRes
), FALSE
);
4859 Compare two Big Numbers.
4861 @param[in] BnA Big number.
4862 @param[in] BnB Big number.
4864 @retval 0 BnA == BnB.
4865 @retval 1 BnA > BnB.
4866 @retval -1 BnA < BnB.
4875 CALL_CRYPTO_SERVICE (BigNumCmp
, (BnA
, BnB
), 0);
4879 Get number of bits in Bn.
4881 @param[in] Bn Big number.
4883 @retval Number of bits.
4891 CALL_CRYPTO_SERVICE (BigNumBits
, (Bn
), 0);
4895 Get number of bytes in Bn.
4897 @param[in] Bn Big number.
4899 @retval Number of bytes.
4907 CALL_CRYPTO_SERVICE (BigNumBytes
, (Bn
), 0);
4911 Checks if Big Number equals to the given Num.
4913 @param[in] Bn Big number.
4914 @param[in] Num Number.
4916 @retval TRUE iff Bn == Num.
4917 @retval FALSE otherwise.
4926 CALL_CRYPTO_SERVICE (BigNumIsWord
, (Bn
, Num
), FALSE
);
4930 Checks if Big Number is odd.
4932 @param[in] Bn Big number.
4934 @retval TRUE Bn is odd (Bn % 2 == 1).
4935 @retval FALSE otherwise.
4943 CALL_CRYPTO_SERVICE (BigNumIsOdd
, (Bn
), FALSE
);
4949 @param[out] BnDst Destination.
4950 @param[in] BnSrc Source.
4952 @retval BnDst on success.
4953 @retval NULL otherwise.
4959 IN CONST VOID
*BnSrc
4962 CALL_CRYPTO_SERVICE (BigNumCopy
, (BnDst
, BnSrc
), NULL
);
4966 Get constant Big number with value of "1".
4967 This may be used to save expensive allocations.
4969 @retval Big Number with value of 1.
4977 CALL_CRYPTO_SERVICE (BigNumValueOne
, (), NULL
);
4981 Shift right Big Number.
4982 Please note, all "out" Big number arguments should be properly initialized
4983 by calling to BigNumInit() or BigNumFromBin() functions.
4985 @param[in] Bn Big number.
4986 @param[in] N Number of bits to shift.
4987 @param[out] BnRes The result.
4989 @retval TRUE On success.
4990 @retval FALSE Otherwise.
5000 CALL_CRYPTO_SERVICE (BigNumRShift
, (Bn
, N
, BnRes
), FALSE
);
5004 Mark Big Number for constant time computations.
5005 This function should be called before any constant time computations are
5006 performed on the given Big number.
5008 @param[in] Bn Big number.
5016 CALL_VOID_CRYPTO_SERVICE (BigNumConstTime
, (Bn
));
5020 Calculate square modulo.
5021 Please note, all "out" Big number arguments should be properly initialized
5022 by calling to BigNumInit() or BigNumFromBin() functions.
5024 @param[in] BnA Big number.
5025 @param[in] BnM Big number (modulo).
5026 @param[out] BnRes The result, such that (BnA ^ 2) % BnM.
5028 @retval TRUE On success.
5029 @retval FALSE Otherwise.
5039 CALL_CRYPTO_SERVICE (BigNumSqrMod
, (BnA
, BnM
, BnRes
), FALSE
);
5043 Create new Big Number computation context. This is an opaque structure
5044 which should be passed to any function that requires it. The BN context is
5045 needed to optimize calculations and expensive allocations.
5047 @retval Big Number context struct or NULL on failure.
5055 CALL_CRYPTO_SERVICE (BigNumNewContext
, (), NULL
);
5059 Free Big Number context that was allocated with BigNumNewContext().
5061 @param[in] BnCtx Big number context to free.
5069 CALL_VOID_CRYPTO_SERVICE (BigNumContextFree
, (BnCtx
));
5073 Set Big Number to a given value.
5075 @param[in] Bn Big number to set.
5076 @param[in] Val Value to set.
5078 @retval TRUE On success.
5079 @retval FALSE Otherwise.
5088 CALL_CRYPTO_SERVICE (BigNumSetUint
, (Bn
, Val
), FALSE
);
5092 Add two Big Numbers modulo BnM.
5094 @param[in] BnA Big number.
5095 @param[in] BnB Big number.
5096 @param[in] BnM Big number (modulo).
5097 @param[out] BnRes The result, such that (BnA + BnB) % BnM.
5099 @retval TRUE On success.
5100 @retval FALSE Otherwise.
5111 CALL_CRYPTO_SERVICE (BigNumAddMod
, (BnA
, BnB
, BnM
, BnRes
), FALSE
);
5115 Initialize new opaque EcGroup object. This object represents an EC curve and
5116 and is used for calculation within this group. This object should be freed
5117 using EcGroupFree() function.
5119 @param[in] CryptoNid Identifying number for the ECC curve (Defined in
5122 @retval EcGroup object On success.
5123 @retval NULL On failure.
5131 CALL_CRYPTO_SERVICE (EcGroupInit
, (CryptoNid
), NULL
);
5135 Get EC curve parameters. While elliptic curve equation is Y^2 mod P = (X^3 + AX + B) Mod P.
5136 This function will set the provided Big Number objects to the corresponding
5137 values. The caller needs to make sure all the "out" BigNumber parameters
5138 are properly initialized.
5140 @param[in] EcGroup EC group object.
5141 @param[out] BnPrime Group prime number.
5142 @param[out] BnA A coefficient.
5143 @param[out] BnB B coefficient.
5144 @param[in] BnCtx BN context.
5146 @retval TRUE On success.
5147 @retval FALSE Otherwise.
5152 IN CONST VOID
*EcGroup
,
5159 CALL_CRYPTO_SERVICE (EcGroupGetCurve
, (EcGroup
, BnPrime
, BnA
, BnB
, BnCtx
), FALSE
);
5164 This function will set the provided Big Number object to the corresponding
5165 value. The caller needs to make sure that the "out" BigNumber parameter
5166 is properly initialized.
5168 @param[in] EcGroup EC group object.
5169 @param[out] BnOrder Group prime number.
5171 @retval TRUE On success.
5172 @retval FALSE Otherwise.
5181 CALL_CRYPTO_SERVICE (EcGroupGetOrder
, (EcGroup
, BnOrder
), FALSE
);
5185 Free previously allocated EC group object using EcGroupInit().
5187 @param[in] EcGroup EC group object to free.
5195 CALL_VOID_CRYPTO_SERVICE (EcGroupFree
, (EcGroup
));
5199 Initialize new opaque EC Point object. This object represents an EC point
5200 within the given EC group (curve).
5202 @param[in] EC Group, properly initialized using EcGroupInit().
5204 @retval EC Point object On success.
5205 @retval NULL On failure.
5210 IN CONST VOID
*EcGroup
5213 CALL_CRYPTO_SERVICE (EcPointInit
, (EcGroup
), NULL
);
5217 Free previously allocated EC Point object using EcPointInit().
5219 @param[in] EcPoint EC Point to free.
5220 @param[in] Clear TRUE iff the memory should be cleared.
5229 CALL_VOID_CRYPTO_SERVICE (EcPointDeInit
, (EcPoint
, Clear
));
5233 Get EC point affine (x,y) coordinates.
5234 This function will set the provided Big Number objects to the corresponding
5235 values. The caller needs to make sure all the "out" BigNumber parameters
5236 are properly initialized.
5238 @param[in] EcGroup EC group object.
5239 @param[in] EcPoint EC point object.
5240 @param[out] BnX X coordinate.
5241 @param[out] BnY Y coordinate.
5242 @param[in] BnCtx BN context, created with BigNumNewContext().
5244 @retval TRUE On success.
5245 @retval FALSE Otherwise.
5249 EcPointGetAffineCoordinates (
5250 IN CONST VOID
*EcGroup
,
5251 IN CONST VOID
*EcPoint
,
5257 CALL_CRYPTO_SERVICE (EcPointGetAffineCoordinates
, (EcGroup
, EcPoint
, BnX
, BnY
, BnCtx
), FALSE
);
5261 Set EC point affine (x,y) coordinates.
5263 @param[in] EcGroup EC group object.
5264 @param[in] EcPoint EC point object.
5265 @param[in] BnX X coordinate.
5266 @param[in] BnY Y coordinate.
5267 @param[in] BnCtx BN context, created with BigNumNewContext().
5269 @retval TRUE On success.
5270 @retval FALSE Otherwise.
5274 EcPointSetAffineCoordinates (
5275 IN CONST VOID
*EcGroup
,
5282 CALL_CRYPTO_SERVICE (EcPointSetAffineCoordinates
, (EcGroup
, EcPoint
, BnX
, BnY
, BnCtx
), FALSE
);
5286 EC Point addition. EcPointResult = EcPointA + EcPointB.
5288 @param[in] EcGroup EC group object.
5289 @param[out] EcPointResult EC point to hold the result. The point should
5290 be properly initialized.
5291 @param[in] EcPointA EC Point.
5292 @param[in] EcPointB EC Point.
5293 @param[in] BnCtx BN context, created with BigNumNewContext().
5295 @retval TRUE On success.
5296 @retval FALSE Otherwise.
5301 IN CONST VOID
*EcGroup
,
5302 OUT VOID
*EcPointResult
,
5303 IN CONST VOID
*EcPointA
,
5304 IN CONST VOID
*EcPointB
,
5308 CALL_CRYPTO_SERVICE (EcPointAdd
, (EcGroup
, EcPointResult
, EcPointA
, EcPointB
, BnCtx
), FALSE
);
5312 Variable EC point multiplication. EcPointResult = EcPoint * BnPScalar.
5314 @param[in] EcGroup EC group object.
5315 @param[out] EcPointResult EC point to hold the result. The point should
5316 be properly initialized.
5317 @param[in] EcPoint EC Point.
5318 @param[in] BnPScalar P Scalar.
5319 @param[in] BnCtx BN context, created with BigNumNewContext().
5321 @retval TRUE On success.
5322 @retval FALSE Otherwise.
5327 IN CONST VOID
*EcGroup
,
5328 OUT VOID
*EcPointResult
,
5329 IN CONST VOID
*EcPoint
,
5330 IN CONST VOID
*BnPScalar
,
5334 CALL_CRYPTO_SERVICE (EcPointMul
, (EcGroup
, EcPointResult
, EcPoint
, BnPScalar
, BnCtx
), FALSE
);
5338 Calculate the inverse of the supplied EC point.
5340 @param[in] EcGroup EC group object.
5341 @param[in,out] EcPoint EC point to invert.
5342 @param[in] BnCtx BN context, created with BigNumNewContext().
5344 @retval TRUE On success.
5345 @retval FALSE Otherwise.
5350 IN CONST VOID
*EcGroup
,
5351 IN OUT VOID
*EcPoint
,
5355 CALL_CRYPTO_SERVICE (EcPointInvert
, (EcGroup
, EcPoint
, BnCtx
), FALSE
);
5359 Check if the supplied point is on EC curve.
5361 @param[in] EcGroup EC group object.
5362 @param[in] EcPoint EC point to check.
5363 @param[in] BnCtx BN context, created with BigNumNewContext().
5365 @retval TRUE On curve.
5366 @retval FALSE Otherwise.
5371 IN CONST VOID
*EcGroup
,
5372 IN CONST VOID
*EcPoint
,
5376 CALL_CRYPTO_SERVICE (EcPointIsOnCurve
, (EcGroup
, EcPoint
, BnCtx
), FALSE
);
5380 Check if the supplied point is at infinity.
5382 @param[in] EcGroup EC group object.
5383 @param[in] EcPoint EC point to check.
5385 @retval TRUE At infinity.
5386 @retval FALSE Otherwise.
5390 EcPointIsAtInfinity (
5391 IN CONST VOID
*EcGroup
,
5392 IN CONST VOID
*EcPoint
5395 CALL_CRYPTO_SERVICE (EcPointIsAtInfinity
, (EcGroup
, EcPoint
), FALSE
);
5399 Check if EC points are equal.
5401 @param[in] EcGroup EC group object.
5402 @param[in] EcPointA EC point A.
5403 @param[in] EcPointB EC point B.
5404 @param[in] BnCtx BN context, created with BigNumNewContext().
5406 @retval TRUE A == B.
5407 @retval FALSE Otherwise.
5412 IN CONST VOID
*EcGroup
,
5413 IN CONST VOID
*EcPointA
,
5414 IN CONST VOID
*EcPointB
,
5418 CALL_CRYPTO_SERVICE (EcPointEqual
, (EcGroup
, EcPointA
, EcPointB
, BnCtx
), FALSE
);
5422 Set EC point compressed coordinates. Points can be described in terms of
5423 their compressed coordinates. For a point (x, y), for any given value for x
5424 such that the point is on the curve there will only ever be two possible
5425 values for y. Therefore, a point can be set using this function where BnX is
5426 the x coordinate and YBit is a value 0 or 1 to identify which of the two
5427 possible values for y should be used.
5429 @param[in] EcGroup EC group object.
5430 @param[in] EcPoint EC Point.
5431 @param[in] BnX X coordinate.
5432 @param[in] YBit 0 or 1 to identify which Y value is used.
5433 @param[in] BnCtx BN context, created with BigNumNewContext().
5435 @retval TRUE On success.
5436 @retval FALSE Otherwise.
5440 EcPointSetCompressedCoordinates (
5441 IN CONST VOID
*EcGroup
,
5448 CALL_CRYPTO_SERVICE (EcPointSetCompressedCoordinates
, (EcGroup
, EcPoint
, BnX
, YBit
, BnCtx
), FALSE
);
5452 Allocates and Initializes one Elliptic Curve Context for subsequent use
5455 @param[in] Nid cipher NID
5456 @return Pointer to the Elliptic Curve Context that has been initialized.
5457 If the allocations fails, EcNewByNid() returns NULL.
5465 CALL_CRYPTO_SERVICE (EcNewByNid
, (Nid
), NULL
);
5469 Release the specified EC context.
5471 @param[in] EcContext Pointer to the EC context to be released.
5479 CALL_VOID_CRYPTO_SERVICE (EcFree
, (EcContext
));
5483 Generates EC key and returns EC public key (X, Y), Please note, this function uses
5484 pseudo random number generator. The caller must make sure RandomSeed()
5485 function was properly called before.
5486 The Ec context should be correctly initialized by EcNewByNid.
5487 This function generates random secret, and computes the public key (X, Y), which is
5488 returned via parameter Public, PublicSize.
5489 X is the first half of Public with size being PublicSize / 2,
5490 Y is the second half of Public with size being PublicSize / 2.
5491 EC context is updated accordingly.
5492 If the Public buffer is too small to hold the public X, Y, FALSE is returned and
5493 PublicSize is set to the required buffer size to obtain the public X, Y.
5494 For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.
5495 For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.
5496 For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.
5497 If EcContext is NULL, then return FALSE.
5498 If PublicSize is NULL, then return FALSE.
5499 If PublicSize is large enough but Public is NULL, then return FALSE.
5500 @param[in, out] EcContext Pointer to the EC context.
5501 @param[out] PublicKey Pointer to the buffer to receive generated public X,Y.
5502 @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.
5503 On output, the size of data returned in Public buffer in bytes.
5504 @retval TRUE EC public X,Y generation succeeded.
5505 @retval FALSE EC public X,Y generation failed.
5506 @retval FALSE PublicKeySize is not large enough.
5511 IN OUT VOID
*EcContext
,
5512 OUT UINT8
*PublicKey
,
5513 IN OUT UINTN
*PublicKeySize
5516 CALL_CRYPTO_SERVICE (EcGenerateKey
, (EcContext
, PublicKey
, PublicKeySize
), FALSE
);
5520 Gets the public key component from the established EC context.
5521 The Ec context should be correctly initialized by EcNewByNid, and successfully
5522 generate key pair from EcGenerateKey().
5523 For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.
5524 For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.
5525 For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.
5526 @param[in, out] EcContext Pointer to EC context being set.
5527 @param[out] PublicKey Pointer to t buffer to receive generated public X,Y.
5528 @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.
5529 On output, the size of data returned in Public buffer in bytes.
5530 @retval TRUE EC key component was retrieved successfully.
5531 @retval FALSE Invalid EC key component.
5536 IN OUT VOID
*EcContext
,
5537 OUT UINT8
*PublicKey
,
5538 IN OUT UINTN
*PublicKeySize
5541 CALL_CRYPTO_SERVICE (EcGetPubKey
, (EcContext
, PublicKey
, PublicKeySize
), FALSE
);
5545 Computes exchanged common key.
5546 Given peer's public key (X, Y), this function computes the exchanged common key,
5547 based on its own context including value of curve parameter and random secret.
5548 X is the first half of PeerPublic with size being PeerPublicSize / 2,
5549 Y is the second half of PeerPublic with size being PeerPublicSize / 2.
5550 If EcContext is NULL, then return FALSE.
5551 If PeerPublic is NULL, then return FALSE.
5552 If PeerPublicSize is 0, then return FALSE.
5553 If Key is NULL, then return FALSE.
5554 If KeySize is not large enough, then return FALSE.
5555 For P-256, the PeerPublicSize is 64. First 32-byte is X, Second 32-byte is Y.
5556 For P-384, the PeerPublicSize is 96. First 48-byte is X, Second 48-byte is Y.
5557 For P-521, the PeerPublicSize is 132. First 66-byte is X, Second 66-byte is Y.
5558 @param[in, out] EcContext Pointer to the EC context.
5559 @param[in] PeerPublic Pointer to the peer's public X,Y.
5560 @param[in] PeerPublicSize Size of peer's public X,Y in bytes.
5561 @param[in] CompressFlag Flag of PeerPublic is compressed or not.
5562 @param[out] Key Pointer to the buffer to receive generated key.
5563 @param[in, out] KeySize On input, the size of Key buffer in bytes.
5564 On output, the size of data returned in Key buffer in bytes.
5565 @retval TRUE EC exchanged key generation succeeded.
5566 @retval FALSE EC exchanged key generation failed.
5567 @retval FALSE KeySize is not large enough.
5572 IN OUT VOID
*EcContext
,
5573 IN CONST UINT8
*PeerPublic
,
5574 IN UINTN PeerPublicSize
,
5575 IN CONST INT32
*CompressFlag
,
5577 IN OUT UINTN
*KeySize
5580 CALL_CRYPTO_SERVICE (EcDhComputeKey
, (EcContext
, PeerPublic
, PeerPublicSize
, CompressFlag
, Key
, KeySize
), FALSE
);
5584 Retrieve the EC Public Key from one DER-encoded X509 certificate.
5586 @param[in] Cert Pointer to the DER-encoded X509 certificate.
5587 @param[in] CertSize Size of the X509 certificate in bytes.
5588 @param[out] EcContext Pointer to new-generated EC DSA context which contain the retrieved
5589 EC public key component. Use EcFree() function to free the
5592 If Cert is NULL, then return FALSE.
5593 If EcContext is NULL, then return FALSE.
5595 @retval TRUE EC Public Key was retrieved successfully.
5596 @retval FALSE Fail to retrieve EC public key from X509 certificate.
5601 EcGetPublicKeyFromX509 (
5602 IN CONST UINT8
*Cert
,
5604 OUT VOID
**EcContext
5607 CALL_CRYPTO_SERVICE (EcGetPublicKeyFromX509
, (Cert
, CertSize
, EcContext
), FALSE
);
5611 Retrieve the EC Private Key from the password-protected PEM key data.
5613 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
5614 @param[in] PemSize Size of the PEM key data in bytes.
5615 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
5616 @param[out] EcContext Pointer to new-generated EC DSA context which contain the retrieved
5617 EC private key component. Use EcFree() function to free the
5620 If PemData is NULL, then return FALSE.
5621 If EcContext is NULL, then return FALSE.
5623 @retval TRUE EC Private Key was retrieved successfully.
5624 @retval FALSE Invalid PEM key data or incorrect password.
5629 EcGetPrivateKeyFromPem (
5630 IN CONST UINT8
*PemData
,
5632 IN CONST CHAR8
*Password
,
5633 OUT VOID
**EcContext
5636 CALL_CRYPTO_SERVICE (EcGetPrivateKeyFromPem
, (PemData
, PemSize
, Password
, EcContext
), FALSE
);
5640 Carries out the EC-DSA signature.
5642 This function carries out the EC-DSA signature.
5643 If the Signature buffer is too small to hold the contents of signature, FALSE
5644 is returned and SigSize is set to the required buffer size to obtain the signature.
5646 If EcContext is NULL, then return FALSE.
5647 If MessageHash is NULL, then return FALSE.
5648 If HashSize need match the HashNid. HashNid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
5649 If SigSize is large enough but Signature is NULL, then return FALSE.
5651 For P-256, the SigSize is 64. First 32-byte is R, Second 32-byte is S.
5652 For P-384, the SigSize is 96. First 48-byte is R, Second 48-byte is S.
5653 For P-521, the SigSize is 132. First 66-byte is R, Second 66-byte is S.
5655 @param[in] EcContext Pointer to EC context for signature generation.
5656 @param[in] HashNid hash NID
5657 @param[in] MessageHash Pointer to octet message hash to be signed.
5658 @param[in] HashSize Size of the message hash in bytes.
5659 @param[out] Signature Pointer to buffer to receive EC-DSA signature.
5660 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
5661 On output, the size of data returned in Signature buffer in bytes.
5663 @retval TRUE Signature successfully generated in EC-DSA.
5664 @retval FALSE Signature generation failed.
5665 @retval FALSE SigSize is too small.
5673 IN CONST UINT8
*MessageHash
,
5675 OUT UINT8
*Signature
,
5676 IN OUT UINTN
*SigSize
5679 CALL_CRYPTO_SERVICE (EcDsaSign
, (EcContext
, HashNid
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
5683 Verifies the EC-DSA signature.
5685 If EcContext is NULL, then return FALSE.
5686 If MessageHash is NULL, then return FALSE.
5687 If Signature is NULL, then return FALSE.
5688 If HashSize need match the HashNid. HashNid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
5690 For P-256, the SigSize is 64. First 32-byte is R, Second 32-byte is S.
5691 For P-384, the SigSize is 96. First 48-byte is R, Second 48-byte is S.
5692 For P-521, the SigSize is 132. First 66-byte is R, Second 66-byte is S.
5694 @param[in] EcContext Pointer to EC context for signature verification.
5695 @param[in] HashNid hash NID
5696 @param[in] MessageHash Pointer to octet message hash to be checked.
5697 @param[in] HashSize Size of the message hash in bytes.
5698 @param[in] Signature Pointer to EC-DSA signature to be verified.
5699 @param[in] SigSize Size of signature in bytes.
5701 @retval TRUE Valid signature encoded in EC-DSA.
5702 @retval FALSE Invalid signature or invalid EC context.
5710 IN CONST UINT8
*MessageHash
,
5712 IN CONST UINT8
*Signature
,
5716 CALL_CRYPTO_SERVICE (EcDsaVerify
, (EcContext
, HashNid
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);