2 Defines base cryptographic library APIs.
3 The Base Cryptographic Library provides implementations of basic cryptography
4 primitives (Hash Serials, HMAC, RSA, Diffie-Hellman, etc) for UEFI security
5 functionality enabling.
7 Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #ifndef __BASE_CRYPT_LIB_H__
13 #define __BASE_CRYPT_LIB_H__
15 #include <Uefi/UefiBaseType.h>
18 /// MD4 digest size in bytes
20 #define MD4_DIGEST_SIZE 16
23 /// MD5 digest size in bytes
25 #define MD5_DIGEST_SIZE 16
28 /// SHA-1 digest size in bytes.
30 #define SHA1_DIGEST_SIZE 20
33 /// SHA-256 digest size in bytes
35 #define SHA256_DIGEST_SIZE 32
38 /// SHA-384 digest size in bytes
40 #define SHA384_DIGEST_SIZE 48
43 /// SHA-512 digest size in bytes
45 #define SHA512_DIGEST_SIZE 64
48 /// SM3 digest size in bytes
50 #define SM3_256_DIGEST_SIZE 32
53 /// TDES block size in bytes
55 #define TDES_BLOCK_SIZE 8
58 /// AES block size in bytes
60 #define AES_BLOCK_SIZE 16
63 /// RSA Key Tags Definition used in RsaSetKey() function for key component identification.
66 RsaKeyN
, ///< RSA public Modulus (N)
67 RsaKeyE
, ///< RSA Public exponent (e)
68 RsaKeyD
, ///< RSA Private exponent (d)
69 RsaKeyP
, ///< RSA secret prime factor of Modulus (p)
70 RsaKeyQ
, ///< RSA secret prime factor of Modules (q)
71 RsaKeyDp
, ///< p's CRT exponent (== d mod (p - 1))
72 RsaKeyDq
, ///< q's CRT exponent (== d mod (q - 1))
73 RsaKeyQInv
///< The CRT coefficient (== 1/q mod p)
76 //=====================================================================================
77 // One-Way Cryptographic Hash Primitives
78 //=====================================================================================
81 Retrieves the size, in bytes, of the context buffer required for MD4 hash operations.
83 If this interface is not supported, then return zero.
85 @return The size, in bytes, of the context buffer required for MD4 hash operations.
86 @retval 0 This interface is not supported.
96 Initializes user-supplied memory pointed by Md4Context as MD4 hash context for
99 If Md4Context is NULL, then return FALSE.
100 If this interface is not supported, then return FALSE.
102 @param[out] Md4Context Pointer to MD4 context being initialized.
104 @retval TRUE MD4 context initialization succeeded.
105 @retval FALSE MD4 context initialization failed.
106 @retval FALSE This interface is not supported.
116 Makes a copy of an existing MD4 context.
118 If Md4Context is NULL, then return FALSE.
119 If NewMd4Context is NULL, then return FALSE.
120 If this interface is not supported, then return FALSE.
122 @param[in] Md4Context Pointer to MD4 context being copied.
123 @param[out] NewMd4Context Pointer to new MD4 context.
125 @retval TRUE MD4 context copy succeeded.
126 @retval FALSE MD4 context copy failed.
127 @retval FALSE This interface is not supported.
133 IN CONST VOID
*Md4Context
,
134 OUT VOID
*NewMd4Context
138 Digests the input data and updates MD4 context.
140 This function performs MD4 digest on a data buffer of the specified size.
141 It can be called multiple times to compute the digest of long or discontinuous data streams.
142 MD4 context should be already correctly initialized by Md4Init(), and should not be finalized
143 by Md4Final(). Behavior with invalid context is undefined.
145 If Md4Context is NULL, then return FALSE.
146 If this interface is not supported, then return FALSE.
148 @param[in, out] Md4Context Pointer to the MD4 context.
149 @param[in] Data Pointer to the buffer containing the data to be hashed.
150 @param[in] DataSize Size of Data buffer in bytes.
152 @retval TRUE MD4 data digest succeeded.
153 @retval FALSE MD4 data digest failed.
154 @retval FALSE This interface is not supported.
160 IN OUT VOID
*Md4Context
,
166 Completes computation of the MD4 digest value.
168 This function completes MD4 hash computation and retrieves the digest value into
169 the specified memory. After this function has been called, the MD4 context cannot
171 MD4 context should be already correctly initialized by Md4Init(), and should not be
172 finalized by Md4Final(). Behavior with invalid MD4 context is undefined.
174 If Md4Context is NULL, then return FALSE.
175 If HashValue is NULL, then return FALSE.
176 If this interface is not supported, then return FALSE.
178 @param[in, out] Md4Context Pointer to the MD4 context.
179 @param[out] HashValue Pointer to a buffer that receives the MD4 digest
182 @retval TRUE MD4 digest computation succeeded.
183 @retval FALSE MD4 digest computation failed.
184 @retval FALSE This interface is not supported.
190 IN OUT VOID
*Md4Context
,
195 Computes the MD4 message digest of a input data buffer.
197 This function performs the MD4 message digest of a given data buffer, and places
198 the digest value into the specified memory.
200 If this interface is not supported, then return FALSE.
202 @param[in] Data Pointer to the buffer containing the data to be hashed.
203 @param[in] DataSize Size of Data buffer in bytes.
204 @param[out] HashValue Pointer to a buffer that receives the MD4 digest
207 @retval TRUE MD4 digest computation succeeded.
208 @retval FALSE MD4 digest computation failed.
209 @retval FALSE This interface is not supported.
221 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.
223 If this interface is not supported, then return zero.
225 @return The size, in bytes, of the context buffer required for MD5 hash operations.
226 @retval 0 This interface is not supported.
236 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for
239 If Md5Context is NULL, then return FALSE.
240 If this interface is not supported, then return FALSE.
242 @param[out] Md5Context Pointer to MD5 context being initialized.
244 @retval TRUE MD5 context initialization succeeded.
245 @retval FALSE MD5 context initialization failed.
246 @retval FALSE This interface is not supported.
256 Makes a copy of an existing MD5 context.
258 If Md5Context is NULL, then return FALSE.
259 If NewMd5Context is NULL, then return FALSE.
260 If this interface is not supported, then return FALSE.
262 @param[in] Md5Context Pointer to MD5 context being copied.
263 @param[out] NewMd5Context Pointer to new MD5 context.
265 @retval TRUE MD5 context copy succeeded.
266 @retval FALSE MD5 context copy failed.
267 @retval FALSE This interface is not supported.
273 IN CONST VOID
*Md5Context
,
274 OUT VOID
*NewMd5Context
278 Digests the input data and updates MD5 context.
280 This function performs MD5 digest on a data buffer of the specified size.
281 It can be called multiple times to compute the digest of long or discontinuous data streams.
282 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized
283 by Md5Final(). Behavior with invalid context is undefined.
285 If Md5Context is NULL, then return FALSE.
286 If this interface is not supported, then return FALSE.
288 @param[in, out] Md5Context Pointer to the MD5 context.
289 @param[in] Data Pointer to the buffer containing the data to be hashed.
290 @param[in] DataSize Size of Data buffer in bytes.
292 @retval TRUE MD5 data digest succeeded.
293 @retval FALSE MD5 data digest failed.
294 @retval FALSE This interface is not supported.
300 IN OUT VOID
*Md5Context
,
306 Completes computation of the MD5 digest value.
308 This function completes MD5 hash computation and retrieves the digest value into
309 the specified memory. After this function has been called, the MD5 context cannot
311 MD5 context should be already correctly initialized by Md5Init(), and should not be
312 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.
314 If Md5Context is NULL, then return FALSE.
315 If HashValue is NULL, then return FALSE.
316 If this interface is not supported, then return FALSE.
318 @param[in, out] Md5Context Pointer to the MD5 context.
319 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
322 @retval TRUE MD5 digest computation succeeded.
323 @retval FALSE MD5 digest computation failed.
324 @retval FALSE This interface is not supported.
330 IN OUT VOID
*Md5Context
,
335 Computes the MD5 message digest of a input data buffer.
337 This function performs the MD5 message digest of a given data buffer, and places
338 the digest value into the specified memory.
340 If this interface is not supported, then return FALSE.
342 @param[in] Data Pointer to the buffer containing the data to be hashed.
343 @param[in] DataSize Size of Data buffer in bytes.
344 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
347 @retval TRUE MD5 digest computation succeeded.
348 @retval FALSE MD5 digest computation failed.
349 @retval FALSE This interface is not supported.
361 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.
363 If this interface is not supported, then return zero.
365 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.
366 @retval 0 This interface is not supported.
376 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for
379 If Sha1Context is NULL, then return FALSE.
380 If this interface is not supported, then return FALSE.
382 @param[out] Sha1Context Pointer to SHA-1 context being initialized.
384 @retval TRUE SHA-1 context initialization succeeded.
385 @retval FALSE SHA-1 context initialization failed.
386 @retval FALSE This interface is not supported.
392 OUT VOID
*Sha1Context
396 Makes a copy of an existing SHA-1 context.
398 If Sha1Context is NULL, then return FALSE.
399 If NewSha1Context is NULL, then return FALSE.
400 If this interface is not supported, then return FALSE.
402 @param[in] Sha1Context Pointer to SHA-1 context being copied.
403 @param[out] NewSha1Context Pointer to new SHA-1 context.
405 @retval TRUE SHA-1 context copy succeeded.
406 @retval FALSE SHA-1 context copy failed.
407 @retval FALSE This interface is not supported.
413 IN CONST VOID
*Sha1Context
,
414 OUT VOID
*NewSha1Context
418 Digests the input data and updates SHA-1 context.
420 This function performs SHA-1 digest on a data buffer of the specified size.
421 It can be called multiple times to compute the digest of long or discontinuous data streams.
422 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized
423 by Sha1Final(). Behavior with invalid context is undefined.
425 If Sha1Context is NULL, then return FALSE.
426 If this interface is not supported, then return FALSE.
428 @param[in, out] Sha1Context Pointer to the SHA-1 context.
429 @param[in] Data Pointer to the buffer containing the data to be hashed.
430 @param[in] DataSize Size of Data buffer in bytes.
432 @retval TRUE SHA-1 data digest succeeded.
433 @retval FALSE SHA-1 data digest failed.
434 @retval FALSE This interface is not supported.
440 IN OUT VOID
*Sha1Context
,
446 Completes computation of the SHA-1 digest value.
448 This function completes SHA-1 hash computation and retrieves the digest value into
449 the specified memory. After this function has been called, the SHA-1 context cannot
451 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be
452 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.
454 If Sha1Context is NULL, then return FALSE.
455 If HashValue is NULL, then return FALSE.
456 If this interface is not supported, then return FALSE.
458 @param[in, out] Sha1Context Pointer to the SHA-1 context.
459 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
462 @retval TRUE SHA-1 digest computation succeeded.
463 @retval FALSE SHA-1 digest computation failed.
464 @retval FALSE This interface is not supported.
470 IN OUT VOID
*Sha1Context
,
475 Computes the SHA-1 message digest of a input data buffer.
477 This function performs the SHA-1 message digest of a given data buffer, and places
478 the digest value into the specified memory.
480 If this interface is not supported, then return FALSE.
482 @param[in] Data Pointer to the buffer containing the data to be hashed.
483 @param[in] DataSize Size of Data buffer in bytes.
484 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
487 @retval TRUE SHA-1 digest computation succeeded.
488 @retval FALSE SHA-1 digest computation failed.
489 @retval FALSE This interface is not supported.
501 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.
503 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.
508 Sha256GetContextSize (
513 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for
516 If Sha256Context is NULL, then return FALSE.
518 @param[out] Sha256Context Pointer to SHA-256 context being initialized.
520 @retval TRUE SHA-256 context initialization succeeded.
521 @retval FALSE SHA-256 context initialization failed.
527 OUT VOID
*Sha256Context
531 Makes a copy of an existing SHA-256 context.
533 If Sha256Context is NULL, then return FALSE.
534 If NewSha256Context is NULL, then return FALSE.
535 If this interface is not supported, then return FALSE.
537 @param[in] Sha256Context Pointer to SHA-256 context being copied.
538 @param[out] NewSha256Context Pointer to new SHA-256 context.
540 @retval TRUE SHA-256 context copy succeeded.
541 @retval FALSE SHA-256 context copy failed.
542 @retval FALSE This interface is not supported.
548 IN CONST VOID
*Sha256Context
,
549 OUT VOID
*NewSha256Context
553 Digests the input data and updates SHA-256 context.
555 This function performs SHA-256 digest on a data buffer of the specified size.
556 It can be called multiple times to compute the digest of long or discontinuous data streams.
557 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized
558 by Sha256Final(). Behavior with invalid context is undefined.
560 If Sha256Context is NULL, then return FALSE.
562 @param[in, out] Sha256Context Pointer to the SHA-256 context.
563 @param[in] Data Pointer to the buffer containing the data to be hashed.
564 @param[in] DataSize Size of Data buffer in bytes.
566 @retval TRUE SHA-256 data digest succeeded.
567 @retval FALSE SHA-256 data digest failed.
573 IN OUT VOID
*Sha256Context
,
579 Completes computation of the SHA-256 digest value.
581 This function completes SHA-256 hash computation and retrieves the digest value into
582 the specified memory. After this function has been called, the SHA-256 context cannot
584 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be
585 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.
587 If Sha256Context is NULL, then return FALSE.
588 If HashValue is NULL, then return FALSE.
590 @param[in, out] Sha256Context Pointer to the SHA-256 context.
591 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
594 @retval TRUE SHA-256 digest computation succeeded.
595 @retval FALSE SHA-256 digest computation failed.
601 IN OUT VOID
*Sha256Context
,
606 Computes the SHA-256 message digest of a input data buffer.
608 This function performs the SHA-256 message digest of a given data buffer, and places
609 the digest value into the specified memory.
611 If this interface is not supported, then return FALSE.
613 @param[in] Data Pointer to the buffer containing the data to be hashed.
614 @param[in] DataSize Size of Data buffer in bytes.
615 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
618 @retval TRUE SHA-256 digest computation succeeded.
619 @retval FALSE SHA-256 digest computation failed.
620 @retval FALSE This interface is not supported.
632 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.
634 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.
639 Sha384GetContextSize (
644 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for
647 If Sha384Context is NULL, then return FALSE.
649 @param[out] Sha384Context Pointer to SHA-384 context being initialized.
651 @retval TRUE SHA-384 context initialization succeeded.
652 @retval FALSE SHA-384 context initialization failed.
658 OUT VOID
*Sha384Context
662 Makes a copy of an existing SHA-384 context.
664 If Sha384Context is NULL, then return FALSE.
665 If NewSha384Context is NULL, then return FALSE.
666 If this interface is not supported, then return FALSE.
668 @param[in] Sha384Context Pointer to SHA-384 context being copied.
669 @param[out] NewSha384Context Pointer to new SHA-384 context.
671 @retval TRUE SHA-384 context copy succeeded.
672 @retval FALSE SHA-384 context copy failed.
673 @retval FALSE This interface is not supported.
679 IN CONST VOID
*Sha384Context
,
680 OUT VOID
*NewSha384Context
684 Digests the input data and updates SHA-384 context.
686 This function performs SHA-384 digest on a data buffer of the specified size.
687 It can be called multiple times to compute the digest of long or discontinuous data streams.
688 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized
689 by Sha384Final(). Behavior with invalid context is undefined.
691 If Sha384Context is NULL, then return FALSE.
693 @param[in, out] Sha384Context Pointer to the SHA-384 context.
694 @param[in] Data Pointer to the buffer containing the data to be hashed.
695 @param[in] DataSize Size of Data buffer in bytes.
697 @retval TRUE SHA-384 data digest succeeded.
698 @retval FALSE SHA-384 data digest failed.
704 IN OUT VOID
*Sha384Context
,
710 Completes computation of the SHA-384 digest value.
712 This function completes SHA-384 hash computation and retrieves the digest value into
713 the specified memory. After this function has been called, the SHA-384 context cannot
715 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be
716 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.
718 If Sha384Context is NULL, then return FALSE.
719 If HashValue is NULL, then return FALSE.
721 @param[in, out] Sha384Context Pointer to the SHA-384 context.
722 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
725 @retval TRUE SHA-384 digest computation succeeded.
726 @retval FALSE SHA-384 digest computation failed.
732 IN OUT VOID
*Sha384Context
,
737 Computes the SHA-384 message digest of a input data buffer.
739 This function performs the SHA-384 message digest of a given data buffer, and places
740 the digest value into the specified memory.
742 If this interface is not supported, then return FALSE.
744 @param[in] Data Pointer to the buffer containing the data to be hashed.
745 @param[in] DataSize Size of Data buffer in bytes.
746 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
749 @retval TRUE SHA-384 digest computation succeeded.
750 @retval FALSE SHA-384 digest computation failed.
751 @retval FALSE This interface is not supported.
763 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.
765 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.
770 Sha512GetContextSize (
775 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for
778 If Sha512Context is NULL, then return FALSE.
780 @param[out] Sha512Context Pointer to SHA-512 context being initialized.
782 @retval TRUE SHA-512 context initialization succeeded.
783 @retval FALSE SHA-512 context initialization failed.
789 OUT VOID
*Sha512Context
793 Makes a copy of an existing SHA-512 context.
795 If Sha512Context is NULL, then return FALSE.
796 If NewSha512Context is NULL, then return FALSE.
797 If this interface is not supported, then return FALSE.
799 @param[in] Sha512Context Pointer to SHA-512 context being copied.
800 @param[out] NewSha512Context Pointer to new SHA-512 context.
802 @retval TRUE SHA-512 context copy succeeded.
803 @retval FALSE SHA-512 context copy failed.
804 @retval FALSE This interface is not supported.
810 IN CONST VOID
*Sha512Context
,
811 OUT VOID
*NewSha512Context
815 Digests the input data and updates SHA-512 context.
817 This function performs SHA-512 digest on a data buffer of the specified size.
818 It can be called multiple times to compute the digest of long or discontinuous data streams.
819 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized
820 by Sha512Final(). Behavior with invalid context is undefined.
822 If Sha512Context is NULL, then return FALSE.
824 @param[in, out] Sha512Context Pointer to the SHA-512 context.
825 @param[in] Data Pointer to the buffer containing the data to be hashed.
826 @param[in] DataSize Size of Data buffer in bytes.
828 @retval TRUE SHA-512 data digest succeeded.
829 @retval FALSE SHA-512 data digest failed.
835 IN OUT VOID
*Sha512Context
,
841 Completes computation of the SHA-512 digest value.
843 This function completes SHA-512 hash computation and retrieves the digest value into
844 the specified memory. After this function has been called, the SHA-512 context cannot
846 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be
847 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.
849 If Sha512Context is NULL, then return FALSE.
850 If HashValue is NULL, then return FALSE.
852 @param[in, out] Sha512Context Pointer to the SHA-512 context.
853 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
856 @retval TRUE SHA-512 digest computation succeeded.
857 @retval FALSE SHA-512 digest computation failed.
863 IN OUT VOID
*Sha512Context
,
868 Computes the SHA-512 message digest of a input data buffer.
870 This function performs the SHA-512 message digest of a given data buffer, and places
871 the digest value into the specified memory.
873 If this interface is not supported, then return FALSE.
875 @param[in] Data Pointer to the buffer containing the data to be hashed.
876 @param[in] DataSize Size of Data buffer in bytes.
877 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
880 @retval TRUE SHA-512 digest computation succeeded.
881 @retval FALSE SHA-512 digest computation failed.
882 @retval FALSE This interface is not supported.
894 Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.
896 @return The size, in bytes, of the context buffer required for SM3 hash operations.
906 Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for
909 If Sm3Context is NULL, then return FALSE.
911 @param[out] Sm3Context Pointer to SM3 context being initialized.
913 @retval TRUE SM3 context initialization succeeded.
914 @retval FALSE SM3 context initialization failed.
924 Makes a copy of an existing SM3 context.
926 If Sm3Context is NULL, then return FALSE.
927 If NewSm3Context is NULL, then return FALSE.
928 If this interface is not supported, then return FALSE.
930 @param[in] Sm3Context Pointer to SM3 context being copied.
931 @param[out] NewSm3Context Pointer to new SM3 context.
933 @retval TRUE SM3 context copy succeeded.
934 @retval FALSE SM3 context copy failed.
935 @retval FALSE This interface is not supported.
941 IN CONST VOID
*Sm3Context
,
942 OUT VOID
*NewSm3Context
946 Digests the input data and updates SM3 context.
948 This function performs SM3 digest on a data buffer of the specified size.
949 It can be called multiple times to compute the digest of long or discontinuous data streams.
950 SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized
951 by Sm3Final(). Behavior with invalid context is undefined.
953 If Sm3Context is NULL, then return FALSE.
955 @param[in, out] Sm3Context Pointer to the SM3 context.
956 @param[in] Data Pointer to the buffer containing the data to be hashed.
957 @param[in] DataSize Size of Data buffer in bytes.
959 @retval TRUE SM3 data digest succeeded.
960 @retval FALSE SM3 data digest failed.
966 IN OUT VOID
*Sm3Context
,
972 Completes computation of the SM3 digest value.
974 This function completes SM3 hash computation and retrieves the digest value into
975 the specified memory. After this function has been called, the SM3 context cannot
977 SM3 context should be already correctly initialized by Sm3Init(), and should not be
978 finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.
980 If Sm3Context is NULL, then return FALSE.
981 If HashValue is NULL, then return FALSE.
983 @param[in, out] Sm3Context Pointer to the SM3 context.
984 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
987 @retval TRUE SM3 digest computation succeeded.
988 @retval FALSE SM3 digest computation failed.
994 IN OUT VOID
*Sm3Context
,
999 Computes the SM3 message digest of a input data buffer.
1001 This function performs the SM3 message digest of a given data buffer, and places
1002 the digest value into the specified memory.
1004 If this interface is not supported, then return FALSE.
1006 @param[in] Data Pointer to the buffer containing the data to be hashed.
1007 @param[in] DataSize Size of Data buffer in bytes.
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.
1013 @retval FALSE This interface is not supported.
1019 IN CONST VOID
*Data
,
1021 OUT UINT8
*HashValue
1024 //=====================================================================================
1025 // MAC (Message Authentication Code) Primitive
1026 //=====================================================================================
1029 Retrieves the size, in bytes, of the context buffer required for HMAC-MD5 operations.
1030 (NOTE: This API is deprecated.
1031 Use HmacMd5New() / HmacMd5Free() for HMAC-MD5 Context operations.)
1033 If this interface is not supported, then return zero.
1035 @return The size, in bytes, of the context buffer required for HMAC-MD5 operations.
1036 @retval 0 This interface is not supported.
1041 HmacMd5GetContextSize (
1046 Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD5 use.
1048 If this interface is not supported, then return NULL.
1050 @return Pointer to the HMAC_CTX context that has been initialized.
1051 If the allocations fails, HmacMd5New() returns NULL.
1052 @retval NULL This interface is not supported.
1062 Release the specified HMAC_CTX context.
1064 If this interface is not supported, then do nothing.
1066 @param[in] HmacMd5Ctx Pointer to the HMAC_CTX context to be released.
1076 Initializes user-supplied memory pointed by HmacMd5Context as HMAC-MD5 context for
1079 If HmacMd5Context is NULL, then return FALSE.
1080 If this interface is not supported, then return FALSE.
1082 @param[out] HmacMd5Context Pointer to HMAC-MD5 context being initialized.
1083 @param[in] Key Pointer to the user-supplied key.
1084 @param[in] KeySize Key size in bytes.
1086 @retval TRUE HMAC-MD5 context initialization succeeded.
1087 @retval FALSE HMAC-MD5 context initialization failed.
1088 @retval FALSE This interface is not supported.
1094 OUT VOID
*HmacMd5Context
,
1095 IN CONST UINT8
*Key
,
1100 Makes a copy of an existing HMAC-MD5 context.
1102 If HmacMd5Context is NULL, then return FALSE.
1103 If NewHmacMd5Context is NULL, then return FALSE.
1104 If this interface is not supported, then return FALSE.
1106 @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied.
1107 @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context.
1109 @retval TRUE HMAC-MD5 context copy succeeded.
1110 @retval FALSE HMAC-MD5 context copy failed.
1111 @retval FALSE This interface is not supported.
1117 IN CONST VOID
*HmacMd5Context
,
1118 OUT VOID
*NewHmacMd5Context
1122 Digests the input data and updates HMAC-MD5 context.
1124 This function performs HMAC-MD5 digest on a data buffer of the specified size.
1125 It can be called multiple times to compute the digest of long or discontinuous data streams.
1126 HMAC-MD5 context should be already correctly initialized by HmacMd5Init(), and should not be
1127 finalized by HmacMd5Final(). Behavior with invalid context is undefined.
1129 If HmacMd5Context is NULL, then return FALSE.
1130 If this interface is not supported, then return FALSE.
1132 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
1133 @param[in] Data Pointer to the buffer containing the data to be digested.
1134 @param[in] DataSize Size of Data buffer in bytes.
1136 @retval TRUE HMAC-MD5 data digest succeeded.
1137 @retval FALSE HMAC-MD5 data digest failed.
1138 @retval FALSE This interface is not supported.
1144 IN OUT VOID
*HmacMd5Context
,
1145 IN CONST VOID
*Data
,
1150 Completes computation of the HMAC-MD5 digest value.
1152 This function completes HMAC-MD5 hash computation and retrieves the digest value into
1153 the specified memory. After this function has been called, the HMAC-MD5 context cannot
1155 HMAC-MD5 context should be already correctly initialized by HmacMd5Init(), and should not be
1156 finalized by HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined.
1158 If HmacMd5Context is NULL, then return FALSE.
1159 If HmacValue is NULL, then return FALSE.
1160 If this interface is not supported, then return FALSE.
1162 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
1163 @param[out] HmacValue Pointer to a buffer that receives the HMAC-MD5 digest
1166 @retval TRUE HMAC-MD5 digest computation succeeded.
1167 @retval FALSE HMAC-MD5 digest computation failed.
1168 @retval FALSE This interface is not supported.
1174 IN OUT VOID
*HmacMd5Context
,
1175 OUT UINT8
*HmacValue
1179 Retrieves the size, in bytes, of the context buffer required for HMAC-SHA1 operations.
1180 (NOTE: This API is deprecated.
1181 Use HmacSha1New() / HmacSha1Free() for HMAC-SHA1 Context operations.)
1183 If this interface is not supported, then return zero.
1185 @return The size, in bytes, of the context buffer required for HMAC-SHA1 operations.
1186 @retval 0 This interface is not supported.
1191 HmacSha1GetContextSize (
1196 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA1 use.
1198 If this interface is not supported, then return NULL.
1200 @return Pointer to the HMAC_CTX context that has been initialized.
1201 If the allocations fails, HmacSha1New() returns NULL.
1202 @return NULL This interface is not supported.
1212 Release the specified HMAC_CTX context.
1214 If this interface is not supported, then do nothing.
1216 @param[in] HmacSha1Ctx Pointer to the HMAC_CTX context to be released.
1222 IN VOID
*HmacSha1Ctx
1226 Initializes user-supplied memory pointed by HmacSha1Context as HMAC-SHA1 context for
1229 If HmacSha1Context is NULL, then return FALSE.
1230 If this interface is not supported, then return FALSE.
1232 @param[out] HmacSha1Context Pointer to HMAC-SHA1 context being initialized.
1233 @param[in] Key Pointer to the user-supplied key.
1234 @param[in] KeySize Key size in bytes.
1236 @retval TRUE HMAC-SHA1 context initialization succeeded.
1237 @retval FALSE HMAC-SHA1 context initialization failed.
1238 @retval FALSE This interface is not supported.
1244 OUT VOID
*HmacSha1Context
,
1245 IN CONST UINT8
*Key
,
1250 Makes a copy of an existing HMAC-SHA1 context.
1252 If HmacSha1Context is NULL, then return FALSE.
1253 If NewHmacSha1Context is NULL, then return FALSE.
1254 If this interface is not supported, then return FALSE.
1256 @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied.
1257 @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context.
1259 @retval TRUE HMAC-SHA1 context copy succeeded.
1260 @retval FALSE HMAC-SHA1 context copy failed.
1261 @retval FALSE This interface is not supported.
1267 IN CONST VOID
*HmacSha1Context
,
1268 OUT VOID
*NewHmacSha1Context
1272 Digests the input data and updates HMAC-SHA1 context.
1274 This function performs HMAC-SHA1 digest on a data buffer of the specified size.
1275 It can be called multiple times to compute the digest of long or discontinuous data streams.
1276 HMAC-SHA1 context should be already correctly initialized by HmacSha1Init(), and should not
1277 be finalized by HmacSha1Final(). Behavior with invalid context is undefined.
1279 If HmacSha1Context is NULL, then return FALSE.
1280 If this interface is not supported, then return FALSE.
1282 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1283 @param[in] Data Pointer to the buffer containing the data to be digested.
1284 @param[in] DataSize Size of Data buffer in bytes.
1286 @retval TRUE HMAC-SHA1 data digest succeeded.
1287 @retval FALSE HMAC-SHA1 data digest failed.
1288 @retval FALSE This interface is not supported.
1294 IN OUT VOID
*HmacSha1Context
,
1295 IN CONST VOID
*Data
,
1300 Completes computation of the HMAC-SHA1 digest value.
1302 This function completes HMAC-SHA1 hash computation and retrieves the digest value into
1303 the specified memory. After this function has been called, the HMAC-SHA1 context cannot
1305 HMAC-SHA1 context should be already correctly initialized by HmacSha1Init(), and should
1306 not be finalized by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined.
1308 If HmacSha1Context is NULL, then return FALSE.
1309 If HmacValue is NULL, then return FALSE.
1310 If this interface is not supported, then return FALSE.
1312 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1313 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA1 digest
1316 @retval TRUE HMAC-SHA1 digest computation succeeded.
1317 @retval FALSE HMAC-SHA1 digest computation failed.
1318 @retval FALSE This interface is not supported.
1324 IN OUT VOID
*HmacSha1Context
,
1325 OUT UINT8
*HmacValue
1329 Retrieves the size, in bytes, of the context buffer required for HMAC-SHA256 operations.
1330 (NOTE: This API is deprecated.
1331 Use HmacSha256New() / HmacSha256Free() for HMAC-SHA256 Context operations.)
1333 If this interface is not supported, then return zero.
1335 @return The size, in bytes, of the context buffer required for HMAC-SHA256 operations.
1336 @retval 0 This interface is not supported.
1341 HmacSha256GetContextSize (
1346 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
1348 @return Pointer to the HMAC_CTX context that has been initialized.
1349 If the allocations fails, HmacSha256New() returns NULL.
1359 Release the specified HMAC_CTX context.
1361 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.
1367 IN VOID
*HmacSha256Ctx
1371 Initializes user-supplied memory pointed by HmacSha256Context as HMAC-SHA256 context for
1374 If HmacSha256Context is NULL, then return FALSE.
1375 If this interface is not supported, then return FALSE.
1377 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context being initialized.
1378 @param[in] Key Pointer to the user-supplied key.
1379 @param[in] KeySize Key size in bytes.
1381 @retval TRUE HMAC-SHA256 context initialization succeeded.
1382 @retval FALSE HMAC-SHA256 context initialization failed.
1383 @retval FALSE This interface is not supported.
1389 OUT VOID
*HmacSha256Context
,
1390 IN CONST UINT8
*Key
,
1395 Makes a copy of an existing HMAC-SHA256 context.
1397 If HmacSha256Context is NULL, then return FALSE.
1398 If NewHmacSha256Context is NULL, then return FALSE.
1399 If this interface is not supported, then return FALSE.
1401 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.
1402 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.
1404 @retval TRUE HMAC-SHA256 context copy succeeded.
1405 @retval FALSE HMAC-SHA256 context copy failed.
1406 @retval FALSE This interface is not supported.
1411 HmacSha256Duplicate (
1412 IN CONST VOID
*HmacSha256Context
,
1413 OUT VOID
*NewHmacSha256Context
1417 Digests the input data and updates HMAC-SHA256 context.
1419 This function performs HMAC-SHA256 digest on a data buffer of the specified size.
1420 It can be called multiple times to compute the digest of long or discontinuous data streams.
1421 HMAC-SHA256 context should be already correctly initialized by HmacSha256Init(), and should not
1422 be finalized by HmacSha256Final(). Behavior with invalid context is undefined.
1424 If HmacSha256Context is NULL, then return FALSE.
1425 If this interface is not supported, then return FALSE.
1427 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1428 @param[in] Data Pointer to the buffer containing the data to be digested.
1429 @param[in] DataSize Size of Data buffer in bytes.
1431 @retval TRUE HMAC-SHA256 data digest succeeded.
1432 @retval FALSE HMAC-SHA256 data digest failed.
1433 @retval FALSE This interface is not supported.
1439 IN OUT VOID
*HmacSha256Context
,
1440 IN CONST VOID
*Data
,
1445 Completes computation of the HMAC-SHA256 digest value.
1447 This function completes HMAC-SHA256 hash computation and retrieves the digest value into
1448 the specified memory. After this function has been called, the HMAC-SHA256 context cannot
1450 HMAC-SHA256 context should be already correctly initialized by HmacSha256Init(), and should
1451 not be finalized by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.
1453 If HmacSha256Context is NULL, then return FALSE.
1454 If HmacValue is NULL, then return FALSE.
1455 If this interface is not supported, then return FALSE.
1457 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1458 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
1461 @retval TRUE HMAC-SHA256 digest computation succeeded.
1462 @retval FALSE HMAC-SHA256 digest computation failed.
1463 @retval FALSE This interface is not supported.
1469 IN OUT VOID
*HmacSha256Context
,
1470 OUT UINT8
*HmacValue
1473 //=====================================================================================
1474 // Symmetric Cryptography Primitive
1475 //=====================================================================================
1478 Retrieves the size, in bytes, of the context buffer required for TDES operations.
1480 If this interface is not supported, then return zero.
1482 @return The size, in bytes, of the context buffer required for TDES operations.
1483 @retval 0 This interface is not supported.
1488 TdesGetContextSize (
1493 Initializes user-supplied memory as TDES context for subsequent use.
1495 This function initializes user-supplied memory pointed by TdesContext as TDES context.
1496 In addition, it sets up all TDES key materials for subsequent encryption and decryption
1498 There are 3 key options as follows:
1499 KeyLength = 64, Keying option 1: K1 == K2 == K3 (Backward compatibility with DES)
1500 KeyLength = 128, Keying option 2: K1 != K2 and K3 = K1 (Less Security)
1501 KeyLength = 192 Keying option 3: K1 != K2 != K3 (Strongest)
1503 If TdesContext is NULL, then return FALSE.
1504 If Key is NULL, then return FALSE.
1505 If KeyLength is not valid, then return FALSE.
1506 If this interface is not supported, then return FALSE.
1508 @param[out] TdesContext Pointer to TDES context being initialized.
1509 @param[in] Key Pointer to the user-supplied TDES key.
1510 @param[in] KeyLength Length of TDES key in bits.
1512 @retval TRUE TDES context initialization succeeded.
1513 @retval FALSE TDES context initialization failed.
1514 @retval FALSE This interface is not supported.
1520 OUT VOID
*TdesContext
,
1521 IN CONST UINT8
*Key
,
1526 Performs TDES encryption on a data buffer of the specified size in ECB mode.
1528 This function performs TDES encryption on data buffer pointed by Input, of specified
1529 size of InputSize, in ECB mode.
1530 InputSize must be multiple of block size (8 bytes). This function does not perform
1531 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1532 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1533 invalid TDES context is undefined.
1535 If TdesContext is NULL, then return FALSE.
1536 If Input is NULL, then return FALSE.
1537 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1538 If Output is NULL, then return FALSE.
1539 If this interface is not supported, then return FALSE.
1541 @param[in] TdesContext Pointer to the TDES context.
1542 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1543 @param[in] InputSize Size of the Input buffer in bytes.
1544 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1546 @retval TRUE TDES encryption succeeded.
1547 @retval FALSE TDES encryption failed.
1548 @retval FALSE This interface is not supported.
1554 IN VOID
*TdesContext
,
1555 IN CONST UINT8
*Input
,
1561 Performs TDES decryption on a data buffer of the specified size in ECB mode.
1563 This function performs TDES decryption on data buffer pointed by Input, of specified
1564 size of InputSize, in ECB mode.
1565 InputSize must be multiple of block size (8 bytes). This function does not perform
1566 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1567 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1568 invalid TDES context is undefined.
1570 If TdesContext is NULL, then return FALSE.
1571 If Input is NULL, then return FALSE.
1572 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1573 If Output is NULL, then return FALSE.
1574 If this interface is not supported, then return FALSE.
1576 @param[in] TdesContext Pointer to the TDES context.
1577 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1578 @param[in] InputSize Size of the Input buffer in bytes.
1579 @param[out] Output Pointer to a buffer that receives the TDES decryption output.
1581 @retval TRUE TDES decryption succeeded.
1582 @retval FALSE TDES decryption failed.
1583 @retval FALSE This interface is not supported.
1589 IN VOID
*TdesContext
,
1590 IN CONST UINT8
*Input
,
1596 Performs TDES encryption on a data buffer of the specified size in CBC mode.
1598 This function performs TDES encryption on data buffer pointed by Input, of specified
1599 size of InputSize, in CBC mode.
1600 InputSize must be multiple of block size (8 bytes). This function does not perform
1601 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1602 Initialization vector should be one block size (8 bytes).
1603 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1604 invalid TDES context is undefined.
1606 If TdesContext is NULL, then return FALSE.
1607 If Input is NULL, then return FALSE.
1608 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1609 If Ivec is NULL, then return FALSE.
1610 If Output is NULL, then return FALSE.
1611 If this interface is not supported, then return FALSE.
1613 @param[in] TdesContext Pointer to the TDES context.
1614 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1615 @param[in] InputSize Size of the Input buffer in bytes.
1616 @param[in] Ivec Pointer to initialization vector.
1617 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1619 @retval TRUE TDES encryption succeeded.
1620 @retval FALSE TDES encryption failed.
1621 @retval FALSE This interface is not supported.
1627 IN VOID
*TdesContext
,
1628 IN CONST UINT8
*Input
,
1630 IN CONST UINT8
*Ivec
,
1635 Performs TDES decryption on a data buffer of the specified size in CBC mode.
1637 This function performs TDES decryption on data buffer pointed by Input, of specified
1638 size of InputSize, in CBC mode.
1639 InputSize must be multiple of block size (8 bytes). This function does not perform
1640 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1641 Initialization vector should be one block size (8 bytes).
1642 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1643 invalid TDES context is undefined.
1645 If TdesContext is NULL, then return FALSE.
1646 If Input is NULL, then return FALSE.
1647 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1648 If Ivec is NULL, then return FALSE.
1649 If Output is NULL, then return FALSE.
1650 If this interface is not supported, then return FALSE.
1652 @param[in] TdesContext Pointer to the TDES context.
1653 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1654 @param[in] InputSize Size of the Input buffer in bytes.
1655 @param[in] Ivec Pointer to initialization vector.
1656 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1658 @retval TRUE TDES decryption succeeded.
1659 @retval FALSE TDES decryption failed.
1660 @retval FALSE This interface is not supported.
1666 IN VOID
*TdesContext
,
1667 IN CONST UINT8
*Input
,
1669 IN CONST UINT8
*Ivec
,
1674 Retrieves the size, in bytes, of the context buffer required for AES operations.
1676 If this interface is not supported, then return zero.
1678 @return The size, in bytes, of the context buffer required for AES operations.
1679 @retval 0 This interface is not supported.
1689 Initializes user-supplied memory as AES context for subsequent use.
1691 This function initializes user-supplied memory pointed by AesContext as AES context.
1692 In addition, it sets up all AES key materials for subsequent encryption and decryption
1694 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1696 If AesContext is NULL, then return FALSE.
1697 If Key is NULL, then return FALSE.
1698 If KeyLength is not valid, then return FALSE.
1699 If this interface is not supported, then return FALSE.
1701 @param[out] AesContext Pointer to AES context being initialized.
1702 @param[in] Key Pointer to the user-supplied AES key.
1703 @param[in] KeyLength Length of AES key in bits.
1705 @retval TRUE AES context initialization succeeded.
1706 @retval FALSE AES context initialization failed.
1707 @retval FALSE This interface is not supported.
1713 OUT VOID
*AesContext
,
1714 IN CONST UINT8
*Key
,
1719 Performs AES encryption on a data buffer of the specified size in ECB mode.
1721 This function performs AES encryption on data buffer pointed by Input, of specified
1722 size of InputSize, in ECB mode.
1723 InputSize must be multiple of block size (16 bytes). This function does not perform
1724 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1725 AesContext should be already correctly initialized by AesInit(). Behavior with
1726 invalid AES context is undefined.
1728 If AesContext is NULL, then return FALSE.
1729 If Input is NULL, then return FALSE.
1730 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1731 If Output is NULL, then return FALSE.
1732 If this interface is not supported, then return FALSE.
1734 @param[in] AesContext Pointer to the AES context.
1735 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1736 @param[in] InputSize Size of the Input buffer in bytes.
1737 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1739 @retval TRUE AES encryption succeeded.
1740 @retval FALSE AES encryption failed.
1741 @retval FALSE This interface is not supported.
1747 IN VOID
*AesContext
,
1748 IN CONST UINT8
*Input
,
1754 Performs AES decryption on a data buffer of the specified size in ECB mode.
1756 This function performs AES decryption on data buffer pointed by Input, of specified
1757 size of InputSize, in ECB mode.
1758 InputSize must be multiple of block size (16 bytes). This function does not perform
1759 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1760 AesContext should be already correctly initialized by AesInit(). Behavior with
1761 invalid AES context is undefined.
1763 If AesContext is NULL, then return FALSE.
1764 If Input is NULL, then return FALSE.
1765 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1766 If Output is NULL, then return FALSE.
1767 If this interface is not supported, then return FALSE.
1769 @param[in] AesContext Pointer to the AES context.
1770 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1771 @param[in] InputSize Size of the Input buffer in bytes.
1772 @param[out] Output Pointer to a buffer that receives the AES decryption output.
1774 @retval TRUE AES decryption succeeded.
1775 @retval FALSE AES decryption failed.
1776 @retval FALSE This interface is not supported.
1782 IN VOID
*AesContext
,
1783 IN CONST UINT8
*Input
,
1789 Performs AES encryption on a data buffer of the specified size in CBC mode.
1791 This function performs AES encryption on data buffer pointed by Input, of specified
1792 size of InputSize, in CBC mode.
1793 InputSize must be multiple of block size (16 bytes). This function does not perform
1794 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1795 Initialization vector should be one block size (16 bytes).
1796 AesContext should be already correctly initialized by AesInit(). Behavior with
1797 invalid AES context is undefined.
1799 If AesContext is NULL, then return FALSE.
1800 If Input is NULL, then return FALSE.
1801 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1802 If Ivec is NULL, then return FALSE.
1803 If Output is NULL, then return FALSE.
1804 If this interface is not supported, then return FALSE.
1806 @param[in] AesContext Pointer to the AES context.
1807 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1808 @param[in] InputSize Size of the Input buffer in bytes.
1809 @param[in] Ivec Pointer to initialization vector.
1810 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1812 @retval TRUE AES encryption succeeded.
1813 @retval FALSE AES encryption failed.
1814 @retval FALSE This interface is not supported.
1820 IN VOID
*AesContext
,
1821 IN CONST UINT8
*Input
,
1823 IN CONST UINT8
*Ivec
,
1828 Performs AES decryption on a data buffer of the specified size in CBC mode.
1830 This function performs AES decryption on data buffer pointed by Input, of specified
1831 size of InputSize, in CBC mode.
1832 InputSize must be multiple of block size (16 bytes). This function does not perform
1833 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1834 Initialization vector should be one block size (16 bytes).
1835 AesContext should be already correctly initialized by AesInit(). Behavior with
1836 invalid AES context is undefined.
1838 If AesContext is NULL, then return FALSE.
1839 If Input is NULL, then return FALSE.
1840 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1841 If Ivec is NULL, then return FALSE.
1842 If Output is NULL, then return FALSE.
1843 If this interface is not supported, then return FALSE.
1845 @param[in] AesContext Pointer to the AES context.
1846 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1847 @param[in] InputSize Size of the Input buffer in bytes.
1848 @param[in] Ivec Pointer to initialization vector.
1849 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1851 @retval TRUE AES decryption succeeded.
1852 @retval FALSE AES decryption failed.
1853 @retval FALSE This interface is not supported.
1859 IN VOID
*AesContext
,
1860 IN CONST UINT8
*Input
,
1862 IN CONST UINT8
*Ivec
,
1867 Retrieves the size, in bytes, of the context buffer required for ARC4 operations.
1869 If this interface is not supported, then return zero.
1871 @return The size, in bytes, of the context buffer required for ARC4 operations.
1872 @retval 0 This interface is not supported.
1877 Arc4GetContextSize (
1882 Initializes user-supplied memory as ARC4 context for subsequent use.
1884 This function initializes user-supplied memory pointed by Arc4Context as ARC4 context.
1885 In addition, it sets up all ARC4 key materials for subsequent encryption and decryption
1888 If Arc4Context is NULL, then return FALSE.
1889 If Key is NULL, then return FALSE.
1890 If KeySize does not in the range of [5, 256] bytes, then return FALSE.
1891 If this interface is not supported, then return FALSE.
1893 @param[out] Arc4Context Pointer to ARC4 context being initialized.
1894 @param[in] Key Pointer to the user-supplied ARC4 key.
1895 @param[in] KeySize Size of ARC4 key in bytes.
1897 @retval TRUE ARC4 context initialization succeeded.
1898 @retval FALSE ARC4 context initialization failed.
1899 @retval FALSE This interface is not supported.
1905 OUT VOID
*Arc4Context
,
1906 IN CONST UINT8
*Key
,
1911 Performs ARC4 encryption on a data buffer of the specified size.
1913 This function performs ARC4 encryption on data buffer pointed by Input, of specified
1915 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
1916 invalid ARC4 context is undefined.
1918 If Arc4Context is NULL, then return FALSE.
1919 If Input is NULL, then return FALSE.
1920 If Output is NULL, then return FALSE.
1921 If this interface is not supported, then return FALSE.
1923 @param[in, out] Arc4Context Pointer to the ARC4 context.
1924 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1925 @param[in] InputSize Size of the Input buffer in bytes.
1926 @param[out] Output Pointer to a buffer that receives the ARC4 encryption output.
1928 @retval TRUE ARC4 encryption succeeded.
1929 @retval FALSE ARC4 encryption failed.
1930 @retval FALSE This interface is not supported.
1936 IN OUT VOID
*Arc4Context
,
1937 IN CONST UINT8
*Input
,
1943 Performs ARC4 decryption on a data buffer of the specified size.
1945 This function performs ARC4 decryption on data buffer pointed by Input, of specified
1947 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
1948 invalid ARC4 context is undefined.
1950 If Arc4Context is NULL, then return FALSE.
1951 If Input is NULL, then return FALSE.
1952 If Output is NULL, then return FALSE.
1953 If this interface is not supported, then return FALSE.
1955 @param[in, out] Arc4Context Pointer to the ARC4 context.
1956 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1957 @param[in] InputSize Size of the Input buffer in bytes.
1958 @param[out] Output Pointer to a buffer that receives the ARC4 decryption output.
1960 @retval TRUE ARC4 decryption succeeded.
1961 @retval FALSE ARC4 decryption failed.
1962 @retval FALSE This interface is not supported.
1968 IN OUT VOID
*Arc4Context
,
1975 Resets the ARC4 context to the initial state.
1977 The function resets the ARC4 context to the state it had immediately after the
1978 ARC4Init() function call.
1979 Contrary to ARC4Init(), Arc4Reset() requires no secret key as input, but ARC4 context
1980 should be already correctly initialized by ARC4Init().
1982 If Arc4Context is NULL, then return FALSE.
1983 If this interface is not supported, then return FALSE.
1985 @param[in, out] Arc4Context Pointer to the ARC4 context.
1987 @retval TRUE ARC4 reset succeeded.
1988 @retval FALSE ARC4 reset failed.
1989 @retval FALSE This interface is not supported.
1995 IN OUT VOID
*Arc4Context
1998 //=====================================================================================
1999 // Asymmetric Cryptography Primitive
2000 //=====================================================================================
2003 Allocates and initializes one RSA context for subsequent use.
2005 @return Pointer to the RSA context that has been initialized.
2006 If the allocations fails, RsaNew() returns NULL.
2016 Release the specified RSA context.
2018 If RsaContext is NULL, then return FALSE.
2020 @param[in] RsaContext Pointer to the RSA context to be released.
2030 Sets the tag-designated key component into the established RSA context.
2032 This function sets the tag-designated RSA key component into the established
2033 RSA context from the user-specified non-negative integer (octet string format
2034 represented in RSA PKCS#1).
2035 If BigNumber is NULL, then the specified key component in RSA context is cleared.
2037 If RsaContext is NULL, then return FALSE.
2039 @param[in, out] RsaContext Pointer to RSA context being set.
2040 @param[in] KeyTag Tag of RSA key component being set.
2041 @param[in] BigNumber Pointer to octet integer buffer.
2042 If NULL, then the specified key component in RSA
2044 @param[in] BnSize Size of big number buffer in bytes.
2045 If BigNumber is NULL, then it is ignored.
2047 @retval TRUE RSA key component was set successfully.
2048 @retval FALSE Invalid RSA key component tag.
2054 IN OUT VOID
*RsaContext
,
2055 IN RSA_KEY_TAG KeyTag
,
2056 IN CONST UINT8
*BigNumber
,
2061 Gets the tag-designated RSA key component from the established RSA context.
2063 This function retrieves the tag-designated RSA key component from the
2064 established RSA context as a non-negative integer (octet string format
2065 represented in RSA PKCS#1).
2066 If specified key component has not been set or has been cleared, then returned
2068 If the BigNumber buffer is too small to hold the contents of the key, FALSE
2069 is returned and BnSize is set to the required buffer size to obtain the key.
2071 If RsaContext is NULL, then return FALSE.
2072 If BnSize is NULL, then return FALSE.
2073 If BnSize is large enough but BigNumber is NULL, then return FALSE.
2074 If this interface is not supported, then return FALSE.
2076 @param[in, out] RsaContext Pointer to RSA context being set.
2077 @param[in] KeyTag Tag of RSA key component being set.
2078 @param[out] BigNumber Pointer to octet integer buffer.
2079 @param[in, out] BnSize On input, the size of big number buffer in bytes.
2080 On output, the size of data returned in big number buffer in bytes.
2082 @retval TRUE RSA key component was retrieved successfully.
2083 @retval FALSE Invalid RSA key component tag.
2084 @retval FALSE BnSize is too small.
2085 @retval FALSE This interface is not supported.
2091 IN OUT VOID
*RsaContext
,
2092 IN RSA_KEY_TAG KeyTag
,
2093 OUT UINT8
*BigNumber
,
2094 IN OUT UINTN
*BnSize
2098 Generates RSA key components.
2100 This function generates RSA key components. It takes RSA public exponent E and
2101 length in bits of RSA modulus N as input, and generates all key components.
2102 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
2104 Before this function can be invoked, pseudorandom number generator must be correctly
2105 initialized by RandomSeed().
2107 If RsaContext is NULL, then return FALSE.
2108 If this interface is not supported, then return FALSE.
2110 @param[in, out] RsaContext Pointer to RSA context being set.
2111 @param[in] ModulusLength Length of RSA modulus N in bits.
2112 @param[in] PublicExponent Pointer to RSA public exponent.
2113 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
2115 @retval TRUE RSA key component was generated successfully.
2116 @retval FALSE Invalid RSA key component tag.
2117 @retval FALSE This interface is not supported.
2123 IN OUT VOID
*RsaContext
,
2124 IN UINTN ModulusLength
,
2125 IN CONST UINT8
*PublicExponent
,
2126 IN UINTN PublicExponentSize
2130 Validates key components of RSA context.
2131 NOTE: This function performs integrity checks on all the RSA key material, so
2132 the RSA key structure must contain all the private key data.
2134 This function validates key components of RSA context in following aspects:
2135 - Whether p is a prime
2136 - Whether q is a prime
2138 - Whether d*e = 1 mod lcm(p-1,q-1)
2140 If RsaContext is NULL, then return FALSE.
2141 If this interface is not supported, then return FALSE.
2143 @param[in] RsaContext Pointer to RSA context to check.
2145 @retval TRUE RSA key components are valid.
2146 @retval FALSE RSA key components are not valid.
2147 @retval FALSE This interface is not supported.
2157 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
2159 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
2161 If the Signature buffer is too small to hold the contents of signature, FALSE
2162 is returned and SigSize is set to the required buffer size to obtain the signature.
2164 If RsaContext is NULL, then return FALSE.
2165 If MessageHash is NULL, then return FALSE.
2166 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
2167 If SigSize is large enough but Signature is NULL, then return FALSE.
2168 If this interface is not supported, then return FALSE.
2170 @param[in] RsaContext Pointer to RSA context for signature generation.
2171 @param[in] MessageHash Pointer to octet message hash to be signed.
2172 @param[in] HashSize Size of the message hash in bytes.
2173 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
2174 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
2175 On output, the size of data returned in Signature buffer in bytes.
2177 @retval TRUE Signature successfully generated in PKCS1-v1_5.
2178 @retval FALSE Signature generation failed.
2179 @retval FALSE SigSize is too small.
2180 @retval FALSE This interface is not supported.
2186 IN VOID
*RsaContext
,
2187 IN CONST UINT8
*MessageHash
,
2189 OUT UINT8
*Signature
,
2190 IN OUT UINTN
*SigSize
2194 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
2197 If RsaContext is NULL, then return FALSE.
2198 If MessageHash is NULL, then return FALSE.
2199 If Signature is NULL, then return FALSE.
2200 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
2202 @param[in] RsaContext Pointer to RSA context for signature verification.
2203 @param[in] MessageHash Pointer to octet message hash to be checked.
2204 @param[in] HashSize Size of the message hash in bytes.
2205 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
2206 @param[in] SigSize Size of signature in bytes.
2208 @retval TRUE Valid signature encoded in PKCS1-v1_5.
2209 @retval FALSE Invalid signature or invalid RSA context.
2215 IN VOID
*RsaContext
,
2216 IN CONST UINT8
*MessageHash
,
2218 IN CONST UINT8
*Signature
,
2223 Retrieve the RSA Private Key from the password-protected PEM key data.
2225 If PemData is NULL, then return FALSE.
2226 If RsaContext is NULL, then return FALSE.
2227 If this interface is not supported, then return FALSE.
2229 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
2230 @param[in] PemSize Size of the PEM key data in bytes.
2231 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
2232 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2233 RSA private key component. Use RsaFree() function to free the
2236 @retval TRUE RSA Private Key was retrieved successfully.
2237 @retval FALSE Invalid PEM key data or incorrect password.
2238 @retval FALSE This interface is not supported.
2243 RsaGetPrivateKeyFromPem (
2244 IN CONST UINT8
*PemData
,
2246 IN CONST CHAR8
*Password
,
2247 OUT VOID
**RsaContext
2251 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
2253 If Cert is NULL, then return FALSE.
2254 If RsaContext is NULL, then return FALSE.
2255 If this interface is not supported, then return FALSE.
2257 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2258 @param[in] CertSize Size of the X509 certificate in bytes.
2259 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2260 RSA public key component. Use RsaFree() function to free the
2263 @retval TRUE RSA Public Key was retrieved successfully.
2264 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
2265 @retval FALSE This interface is not supported.
2270 RsaGetPublicKeyFromX509 (
2271 IN CONST UINT8
*Cert
,
2273 OUT VOID
**RsaContext
2277 Retrieve the subject bytes from one X.509 certificate.
2279 If Cert is NULL, then return FALSE.
2280 If SubjectSize is NULL, then return FALSE.
2281 If this interface is not supported, then return FALSE.
2283 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2284 @param[in] CertSize Size of the X509 certificate in bytes.
2285 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
2286 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
2287 and the size of buffer returned CertSubject on output.
2289 @retval TRUE The certificate subject retrieved successfully.
2290 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
2291 The SubjectSize will be updated with the required size.
2292 @retval FALSE This interface is not supported.
2297 X509GetSubjectName (
2298 IN CONST UINT8
*Cert
,
2300 OUT UINT8
*CertSubject
,
2301 IN OUT UINTN
*SubjectSize
2305 Retrieve the common name (CN) string from one X.509 certificate.
2307 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2308 @param[in] CertSize Size of the X509 certificate in bytes.
2309 @param[out] CommonName Buffer to contain the retrieved certificate common
2310 name string (UTF8). At most CommonNameSize bytes will be
2311 written and the string will be null terminated. May be
2312 NULL in order to determine the size buffer needed.
2313 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
2314 and the size of buffer returned CommonName on output.
2315 If CommonName is NULL then the amount of space needed
2316 in buffer (including the final null) is returned.
2318 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
2319 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2320 If CommonNameSize is NULL.
2321 If CommonName is not NULL and *CommonNameSize is 0.
2322 If Certificate is invalid.
2323 @retval RETURN_NOT_FOUND If no CommonName entry exists.
2324 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
2325 (including the final null) is returned in the
2326 CommonNameSize parameter.
2327 @retval RETURN_UNSUPPORTED The operation is not supported.
2333 IN CONST UINT8
*Cert
,
2335 OUT CHAR8
*CommonName
, OPTIONAL
2336 IN OUT UINTN
*CommonNameSize
2340 Retrieve the organization name (O) string from one X.509 certificate.
2342 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2343 @param[in] CertSize Size of the X509 certificate in bytes.
2344 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
2345 name string. At most NameBufferSize bytes will be
2346 written and the string will be null terminated. May be
2347 NULL in order to determine the size buffer needed.
2348 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
2349 and the size of buffer returned Name on output.
2350 If NameBuffer is NULL then the amount of space needed
2351 in buffer (including the final null) is returned.
2353 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
2354 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2355 If NameBufferSize is NULL.
2356 If NameBuffer is not NULL and *CommonNameSize is 0.
2357 If Certificate is invalid.
2358 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
2359 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
2360 (including the final null) is returned in the
2361 CommonNameSize parameter.
2362 @retval RETURN_UNSUPPORTED The operation is not supported.
2367 X509GetOrganizationName (
2368 IN CONST UINT8
*Cert
,
2370 OUT CHAR8
*NameBuffer
, OPTIONAL
2371 IN OUT UINTN
*NameBufferSize
2375 Verify one X509 certificate was issued by the trusted CA.
2377 If Cert is NULL, then return FALSE.
2378 If CACert is NULL, then return FALSE.
2379 If this interface is not supported, then return FALSE.
2381 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
2382 @param[in] CertSize Size of the X509 certificate in bytes.
2383 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
2384 @param[in] CACertSize Size of the CA Certificate in bytes.
2386 @retval TRUE The certificate was issued by the trusted CA.
2387 @retval FALSE Invalid certificate or the certificate was not issued by the given
2389 @retval FALSE This interface is not supported.
2395 IN CONST UINT8
*Cert
,
2397 IN CONST UINT8
*CACert
,
2402 Construct a X509 object from DER-encoded certificate data.
2404 If Cert is NULL, then return FALSE.
2405 If SingleX509Cert is NULL, then return FALSE.
2406 If this interface is not supported, then return FALSE.
2408 @param[in] Cert Pointer to the DER-encoded certificate data.
2409 @param[in] CertSize The size of certificate data in bytes.
2410 @param[out] SingleX509Cert The generated X509 object.
2412 @retval TRUE The X509 object generation succeeded.
2413 @retval FALSE The operation failed.
2414 @retval FALSE This interface is not supported.
2419 X509ConstructCertificate (
2420 IN CONST UINT8
*Cert
,
2422 OUT UINT8
**SingleX509Cert
2426 Construct a X509 stack object from a list of DER-encoded certificate data.
2428 If X509Stack is NULL, then return FALSE.
2429 If this interface is not supported, then return FALSE.
2431 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2432 On output, pointer to the X509 stack object with new
2433 inserted X509 certificate.
2434 @param ... A list of DER-encoded single certificate data followed
2435 by certificate size. A NULL terminates the list. The
2436 pairs are the arguments to X509ConstructCertificate().
2438 @retval TRUE The X509 stack construction succeeded.
2439 @retval FALSE The construction operation failed.
2440 @retval FALSE This interface is not supported.
2445 X509ConstructCertificateStack (
2446 IN OUT UINT8
**X509Stack
,
2451 Release the specified X509 object.
2453 If the interface is not supported, then ASSERT().
2455 @param[in] X509Cert Pointer to the X509 object to be released.
2465 Release the specified X509 stack object.
2467 If the interface is not supported, then ASSERT().
2469 @param[in] X509Stack Pointer to the X509 stack object to be released.
2479 Retrieve the TBSCertificate from one given X.509 certificate.
2481 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
2482 @param[in] CertSize Size of the X509 certificate in bytes.
2483 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
2484 @param[out] TBSCertSize Size of the TBS certificate in bytes.
2486 If Cert is NULL, then return FALSE.
2487 If TBSCert is NULL, then return FALSE.
2488 If TBSCertSize is NULL, then return FALSE.
2489 If this interface is not supported, then return FALSE.
2491 @retval TRUE The TBSCertificate was retrieved successfully.
2492 @retval FALSE Invalid X.509 certificate.
2498 IN CONST UINT8
*Cert
,
2500 OUT UINT8
**TBSCert
,
2501 OUT UINTN
*TBSCertSize
2505 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2506 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2508 If Password or Salt or OutKey is NULL, then return FALSE.
2509 If the hash algorithm could not be determined, then return FALSE.
2510 If this interface is not supported, then return FALSE.
2512 @param[in] PasswordLength Length of input password in bytes.
2513 @param[in] Password Pointer to the array for the password.
2514 @param[in] SaltLength Size of the Salt in bytes.
2515 @param[in] Salt Pointer to the Salt.
2516 @param[in] IterationCount Number of iterations to perform. Its value should be
2517 greater than or equal to 1.
2518 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2519 NOTE: DigestSize will be used to determine the hash algorithm.
2520 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2521 @param[in] KeyLength Size of the derived key buffer in bytes.
2522 @param[out] OutKey Pointer to the output derived key buffer.
2524 @retval TRUE A key was derived successfully.
2525 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2526 @retval FALSE The hash algorithm could not be determined from the digest size.
2527 @retval FALSE The key derivation operation failed.
2528 @retval FALSE This interface is not supported.
2534 IN UINTN PasswordLength
,
2535 IN CONST CHAR8
*Password
,
2536 IN UINTN SaltLength
,
2537 IN CONST UINT8
*Salt
,
2538 IN UINTN IterationCount
,
2539 IN UINTN DigestSize
,
2545 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2546 encrypted message in a newly allocated buffer.
2548 Things that can cause a failure include:
2549 - X509 key size does not match any known key size.
2550 - Fail to parse X509 certificate.
2551 - Fail to allocate an intermediate buffer.
2552 - Null pointer provided for a non-optional parameter.
2553 - Data size is too large for the provided key size (max size is a function of key size
2554 and hash digest size).
2556 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2557 will be used to encrypt the data.
2558 @param[in] PublicKeySize Size of the X509 cert buffer.
2559 @param[in] InData Data to be encrypted.
2560 @param[in] InDataSize Size of the data buffer.
2561 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2562 to be used when initializing the PRNG. NULL otherwise.
2563 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2565 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2567 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2569 @retval TRUE Encryption was successful.
2570 @retval FALSE Encryption failed.
2576 IN CONST UINT8
*PublicKey
,
2577 IN UINTN PublicKeySize
,
2579 IN UINTN InDataSize
,
2580 IN CONST UINT8
*PrngSeed
, OPTIONAL
2581 IN UINTN PrngSeedSize
, OPTIONAL
2582 OUT UINT8
**EncryptedData
,
2583 OUT UINTN
*EncryptedDataSize
2587 The 3rd parameter of Pkcs7GetSigners will return all embedded
2588 X.509 certificate in one given PKCS7 signature. The format is:
2590 // UINT8 CertNumber;
2591 // UINT32 Cert1Length;
2593 // UINT32 Cert2Length;
2596 // UINT32 CertnLength;
2600 The two following C-structure are used for parsing CertStack more clearly.
2605 UINT32 CertDataLength
; // The length in bytes of X.509 certificate.
2606 UINT8 CertDataBuffer
[0]; // The X.509 certificate content (DER).
2610 UINT8 CertNumber
; // Number of X.509 certificate.
2611 //EFI_CERT_DATA CertArray[]; // An array of X.509 certificate.
2617 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2618 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2619 in a ContentInfo structure.
2621 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2622 return FALSE. If P7Length overflow, then return FALSE.
2623 If this interface is not supported, then return FALSE.
2625 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2626 @param[in] P7Length Length of the PKCS#7 message in bytes.
2627 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2628 It's caller's responsibility to free the buffer with
2630 This data structure is EFI_CERT_STACK type.
2631 @param[out] StackLength Length of signer's certificates in bytes.
2632 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2633 It's caller's responsibility to free the buffer with
2635 @param[out] CertLength Length of the trusted certificate in bytes.
2637 @retval TRUE The operation is finished successfully.
2638 @retval FALSE Error occurs during the operation.
2639 @retval FALSE This interface is not supported.
2645 IN CONST UINT8
*P7Data
,
2647 OUT UINT8
**CertStack
,
2648 OUT UINTN
*StackLength
,
2649 OUT UINT8
**TrustedCert
,
2650 OUT UINTN
*CertLength
2654 Wrap function to use free() to free allocated memory for certificates.
2656 If this interface is not supported, then ASSERT().
2658 @param[in] Certs Pointer to the certificates to be freed.
2668 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2669 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2670 unchained to the signer's certificates.
2671 The input signed data could be wrapped in a ContentInfo structure.
2673 @param[in] P7Data Pointer to the PKCS#7 message.
2674 @param[in] P7Length Length of the PKCS#7 message in bytes.
2675 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2676 certificate. It's caller's responsibility to free the buffer
2677 with Pkcs7FreeSigners().
2678 This data structure is EFI_CERT_STACK type.
2679 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2680 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2681 responsibility to free the buffer with Pkcs7FreeSigners().
2682 This data structure is EFI_CERT_STACK type.
2683 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2685 @retval TRUE The operation is finished successfully.
2686 @retval FALSE Error occurs during the operation.
2691 Pkcs7GetCertificatesList (
2692 IN CONST UINT8
*P7Data
,
2694 OUT UINT8
**SignerChainCerts
,
2695 OUT UINTN
*ChainLength
,
2696 OUT UINT8
**UnchainCerts
,
2697 OUT UINTN
*UnchainLength
2701 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2702 Syntax Standard, version 1.5". This interface is only intended to be used for
2703 application to perform PKCS#7 functionality validation.
2705 If this interface is not supported, then return FALSE.
2707 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2709 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2710 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2712 @param[in] InData Pointer to the content to be signed.
2713 @param[in] InDataSize Size of InData in bytes.
2714 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2715 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2716 include in the PKCS#7 signedData (e.g. any intermediate
2718 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2719 responsibility to free the buffer with FreePool().
2720 @param[out] SignedDataSize Size of SignedData in bytes.
2722 @retval TRUE PKCS#7 data signing succeeded.
2723 @retval FALSE PKCS#7 data signing failed.
2724 @retval FALSE This interface is not supported.
2730 IN CONST UINT8
*PrivateKey
,
2731 IN UINTN PrivateKeySize
,
2732 IN CONST UINT8
*KeyPassword
,
2734 IN UINTN InDataSize
,
2736 IN UINT8
*OtherCerts OPTIONAL
,
2737 OUT UINT8
**SignedData
,
2738 OUT UINTN
*SignedDataSize
2742 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2743 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2744 in a ContentInfo structure.
2746 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2747 If P7Length, CertLength or DataLength overflow, then return FALSE.
2748 If this interface is not supported, then return FALSE.
2750 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2751 @param[in] P7Length Length of the PKCS#7 message in bytes.
2752 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2753 is used for certificate chain verification.
2754 @param[in] CertLength Length of the trusted certificate in bytes.
2755 @param[in] InData Pointer to the content to be verified.
2756 @param[in] DataLength Length of InData in bytes.
2758 @retval TRUE The specified PKCS#7 signed data is valid.
2759 @retval FALSE Invalid PKCS#7 signed data.
2760 @retval FALSE This interface is not supported.
2766 IN CONST UINT8
*P7Data
,
2768 IN CONST UINT8
*TrustedCert
,
2769 IN UINTN CertLength
,
2770 IN CONST UINT8
*InData
,
2775 This function receives a PKCS7 formatted signature, and then verifies that
2776 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
2777 leaf signing certificate.
2778 Note that this function does not validate the certificate chain.
2780 Applications for custom EKU's are quite flexible. For example, a policy EKU
2781 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
2782 certificate issued might also contain this EKU, thus constraining the
2783 sub-ordinate certificate. Other applications might allow a certificate
2784 embedded in a device to specify that other Object Identifiers (OIDs) are
2785 present which contains binary data specifying custom capabilities that
2786 the device is able to do.
2788 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
2789 containing the content block with both the signature,
2790 the signer's certificate, and any necessary intermediate
2792 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
2793 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
2794 required EKUs that must be present in the signature.
2795 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
2796 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
2797 must be present in the leaf signer. If it is
2798 FALSE, then we will succeed if we find any
2799 of the specified EKU's.
2801 @retval EFI_SUCCESS The required EKUs were found in the signature.
2802 @retval EFI_INVALID_PARAMETER A parameter was invalid.
2803 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
2808 VerifyEKUsInPkcs7Signature (
2809 IN CONST UINT8
*Pkcs7Signature
,
2810 IN CONST UINT32 SignatureSize
,
2811 IN CONST CHAR8
*RequiredEKUs
[],
2812 IN CONST UINT32 RequiredEKUsSize
,
2813 IN BOOLEAN RequireAllPresent
2817 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2818 data could be wrapped in a ContentInfo structure.
2820 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2821 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2823 Caution: This function may receive untrusted input. So this function will do
2824 basic check for PKCS#7 data structure.
2826 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2827 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2828 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2829 It's caller's responsibility to free the buffer with FreePool().
2830 @param[out] ContentSize The size of the extracted content in bytes.
2832 @retval TRUE The P7Data was correctly formatted for processing.
2833 @retval FALSE The P7Data was not correctly formatted for processing.
2838 Pkcs7GetAttachedContent (
2839 IN CONST UINT8
*P7Data
,
2842 OUT UINTN
*ContentSize
2846 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2847 Authenticode Portable Executable Signature Format".
2849 If AuthData is NULL, then return FALSE.
2850 If ImageHash is NULL, then return FALSE.
2851 If this interface is not supported, then return FALSE.
2853 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2854 PE/COFF image to be verified.
2855 @param[in] DataSize Size of the Authenticode Signature in bytes.
2856 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2857 is used for certificate chain verification.
2858 @param[in] CertSize Size of the trusted certificate in bytes.
2859 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2860 for calculating the image hash value is described in Authenticode
2862 @param[in] HashSize Size of Image hash value in bytes.
2864 @retval TRUE The specified Authenticode Signature is valid.
2865 @retval FALSE Invalid Authenticode Signature.
2866 @retval FALSE This interface is not supported.
2871 AuthenticodeVerify (
2872 IN CONST UINT8
*AuthData
,
2874 IN CONST UINT8
*TrustedCert
,
2876 IN CONST UINT8
*ImageHash
,
2881 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2884 If AuthData is NULL, then return FALSE.
2885 If this interface is not supported, then return FALSE.
2887 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2888 PE/COFF image to be verified.
2889 @param[in] DataSize Size of the Authenticode Signature in bytes.
2890 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2891 is used for TSA certificate chain verification.
2892 @param[in] CertSize Size of the trusted certificate in bytes.
2893 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2896 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2897 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2902 ImageTimestampVerify (
2903 IN CONST UINT8
*AuthData
,
2905 IN CONST UINT8
*TsaCert
,
2907 OUT EFI_TIME
*SigningTime
2910 //=====================================================================================
2911 // DH Key Exchange Primitive
2912 //=====================================================================================
2915 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
2917 @return Pointer to the Diffie-Hellman Context that has been initialized.
2918 If the allocations fails, DhNew() returns NULL.
2919 If the interface is not supported, DhNew() returns NULL.
2929 Release the specified DH context.
2931 If the interface is not supported, then ASSERT().
2933 @param[in] DhContext Pointer to the DH context to be released.
2943 Generates DH parameter.
2945 Given generator g, and length of prime number p in bits, this function generates p,
2946 and sets DH context according to value of g and p.
2948 Before this function can be invoked, pseudorandom number generator must be correctly
2949 initialized by RandomSeed().
2951 If DhContext is NULL, then return FALSE.
2952 If Prime is NULL, then return FALSE.
2953 If this interface is not supported, then return FALSE.
2955 @param[in, out] DhContext Pointer to the DH context.
2956 @param[in] Generator Value of generator.
2957 @param[in] PrimeLength Length in bits of prime to be generated.
2958 @param[out] Prime Pointer to the buffer to receive the generated prime number.
2960 @retval TRUE DH parameter generation succeeded.
2961 @retval FALSE Value of Generator is not supported.
2962 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
2963 @retval FALSE This interface is not supported.
2968 DhGenerateParameter (
2969 IN OUT VOID
*DhContext
,
2971 IN UINTN PrimeLength
,
2976 Sets generator and prime parameters for DH.
2978 Given generator g, and prime number p, this function and sets DH
2979 context accordingly.
2981 If DhContext is NULL, then return FALSE.
2982 If Prime is NULL, then return FALSE.
2983 If this interface is not supported, then return FALSE.
2985 @param[in, out] DhContext Pointer to the DH context.
2986 @param[in] Generator Value of generator.
2987 @param[in] PrimeLength Length in bits of prime to be generated.
2988 @param[in] Prime Pointer to the prime number.
2990 @retval TRUE DH parameter setting succeeded.
2991 @retval FALSE Value of Generator is not supported.
2992 @retval FALSE Value of Generator is not suitable for the Prime.
2993 @retval FALSE Value of Prime is not a prime number.
2994 @retval FALSE Value of Prime is not a safe prime number.
2995 @retval FALSE This interface is not supported.
3001 IN OUT VOID
*DhContext
,
3003 IN UINTN PrimeLength
,
3004 IN CONST UINT8
*Prime
3008 Generates DH public key.
3010 This function generates random secret exponent, and computes the public key, which is
3011 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
3012 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
3013 PublicKeySize is set to the required buffer size to obtain the public key.
3015 If DhContext is NULL, then return FALSE.
3016 If PublicKeySize is NULL, then return FALSE.
3017 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
3018 If this interface is not supported, then return FALSE.
3020 @param[in, out] DhContext Pointer to the DH context.
3021 @param[out] PublicKey Pointer to the buffer to receive generated public key.
3022 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
3023 On output, the size of data returned in PublicKey buffer in bytes.
3025 @retval TRUE DH public key generation succeeded.
3026 @retval FALSE DH public key generation failed.
3027 @retval FALSE PublicKeySize is not large enough.
3028 @retval FALSE This interface is not supported.
3034 IN OUT VOID
*DhContext
,
3035 OUT UINT8
*PublicKey
,
3036 IN OUT UINTN
*PublicKeySize
3040 Computes exchanged common key.
3042 Given peer's public key, this function computes the exchanged common key, based on its own
3043 context including value of prime modulus and random secret exponent.
3045 If DhContext is NULL, then return FALSE.
3046 If PeerPublicKey is NULL, then return FALSE.
3047 If KeySize is NULL, then return FALSE.
3048 If Key is NULL, then return FALSE.
3049 If KeySize is not large enough, then return FALSE.
3050 If this interface is not supported, then return FALSE.
3052 @param[in, out] DhContext Pointer to the DH context.
3053 @param[in] PeerPublicKey Pointer to the peer's public key.
3054 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
3055 @param[out] Key Pointer to the buffer to receive generated key.
3056 @param[in, out] KeySize On input, the size of Key buffer in bytes.
3057 On output, the size of data returned in Key buffer in bytes.
3059 @retval TRUE DH exchanged key generation succeeded.
3060 @retval FALSE DH exchanged key generation failed.
3061 @retval FALSE KeySize is not large enough.
3062 @retval FALSE This interface is not supported.
3068 IN OUT VOID
*DhContext
,
3069 IN CONST UINT8
*PeerPublicKey
,
3070 IN UINTN PeerPublicKeySize
,
3072 IN OUT UINTN
*KeySize
3075 //=====================================================================================
3076 // Pseudo-Random Generation Primitive
3077 //=====================================================================================
3080 Sets up the seed value for the pseudorandom number generator.
3082 This function sets up the seed value for the pseudorandom number generator.
3083 If Seed is not NULL, then the seed passed in is used.
3084 If Seed is NULL, then default seed is used.
3085 If this interface is not supported, then return FALSE.
3087 @param[in] Seed Pointer to seed value.
3088 If NULL, default seed is used.
3089 @param[in] SeedSize Size of seed value.
3090 If Seed is NULL, this parameter is ignored.
3092 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
3093 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
3094 @retval FALSE This interface is not supported.
3100 IN CONST UINT8
*Seed OPTIONAL
,
3105 Generates a pseudorandom byte stream of the specified size.
3107 If Output is NULL, then return FALSE.
3108 If this interface is not supported, then return FALSE.
3110 @param[out] Output Pointer to buffer to receive random value.
3111 @param[in] Size Size of random bytes to generate.
3113 @retval TRUE Pseudorandom byte stream generated successfully.
3114 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
3115 @retval FALSE This interface is not supported.
3125 //=====================================================================================
3126 // Key Derivation Function Primitive
3127 //=====================================================================================
3130 Derive key data using HMAC-SHA256 based KDF.
3132 @param[in] Key Pointer to the user-supplied key.
3133 @param[in] KeySize Key size in bytes.
3134 @param[in] Salt Pointer to the salt(non-secret) value.
3135 @param[in] SaltSize Salt size in bytes.
3136 @param[in] Info Pointer to the application specific info.
3137 @param[in] InfoSize Info size in bytes.
3138 @param[out] Out Pointer to buffer to receive hkdf value.
3139 @param[in] OutSize Size of hkdf bytes to generate.
3141 @retval TRUE Hkdf generated successfully.
3142 @retval FALSE Hkdf generation failed.
3147 HkdfSha256ExtractAndExpand (
3148 IN CONST UINT8
*Key
,
3150 IN CONST UINT8
*Salt
,
3152 IN CONST UINT8
*Info
,
3158 #endif // __BASE_CRYPT_LIB_H__