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 - 2020, 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 Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD5 use.
1031 If this interface is not supported, then return NULL.
1033 @return Pointer to the HMAC_CTX context that has been initialized.
1034 If the allocations fails, HmacMd5New() returns NULL.
1035 @retval NULL This interface is not supported.
1045 Release the specified HMAC_CTX context.
1047 If this interface is not supported, then do nothing.
1049 @param[in] HmacMd5Ctx Pointer to the HMAC_CTX context to be released.
1059 Set user-supplied key for subsequent use. It must be done before any
1060 calling to HmacMd5Update().
1062 If HmacMd5Context is NULL, then return FALSE.
1063 If this interface is not supported, then return FALSE.
1065 @param[out] HmacMd5Context Pointer to HMAC-MD5 context.
1066 @param[in] Key Pointer to the user-supplied key.
1067 @param[in] KeySize Key size in bytes.
1069 @retval TRUE Key is set successfully.
1070 @retval FALSE Key is set unsuccessfully.
1071 @retval FALSE This interface is not supported.
1077 OUT VOID
*HmacMd5Context
,
1078 IN CONST UINT8
*Key
,
1083 Makes a copy of an existing HMAC-MD5 context.
1085 If HmacMd5Context is NULL, then return FALSE.
1086 If NewHmacMd5Context is NULL, then return FALSE.
1087 If this interface is not supported, then return FALSE.
1089 @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied.
1090 @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context.
1092 @retval TRUE HMAC-MD5 context copy succeeded.
1093 @retval FALSE HMAC-MD5 context copy failed.
1094 @retval FALSE This interface is not supported.
1100 IN CONST VOID
*HmacMd5Context
,
1101 OUT VOID
*NewHmacMd5Context
1105 Digests the input data and updates HMAC-MD5 context.
1107 This function performs HMAC-MD5 digest on a data buffer of the specified size.
1108 It can be called multiple times to compute the digest of long or discontinuous data streams.
1109 HMAC-MD5 context should be initialized by HmacMd5New(), and should not be finalized by
1110 HmacMd5Final(). Behavior with invalid context is undefined.
1112 If HmacMd5Context is NULL, then return FALSE.
1113 If this interface is not supported, then return FALSE.
1115 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
1116 @param[in] Data Pointer to the buffer containing the data to be digested.
1117 @param[in] DataSize Size of Data buffer in bytes.
1119 @retval TRUE HMAC-MD5 data digest succeeded.
1120 @retval FALSE HMAC-MD5 data digest failed.
1121 @retval FALSE This interface is not supported.
1127 IN OUT VOID
*HmacMd5Context
,
1128 IN CONST VOID
*Data
,
1133 Completes computation of the HMAC-MD5 digest value.
1135 This function completes HMAC-MD5 hash computation and retrieves the digest value into
1136 the specified memory. After this function has been called, the HMAC-MD5 context cannot
1138 HMAC-MD5 context should be initialized by HmacMd5New(), and should not be finalized by
1139 HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined.
1141 If HmacMd5Context is NULL, then return FALSE.
1142 If HmacValue is NULL, then return FALSE.
1143 If this interface is not supported, then return FALSE.
1145 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
1146 @param[out] HmacValue Pointer to a buffer that receives the HMAC-MD5 digest
1149 @retval TRUE HMAC-MD5 digest computation succeeded.
1150 @retval FALSE HMAC-MD5 digest computation failed.
1151 @retval FALSE This interface is not supported.
1157 IN OUT VOID
*HmacMd5Context
,
1158 OUT UINT8
*HmacValue
1162 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA1 use.
1164 If this interface is not supported, then return NULL.
1166 @return Pointer to the HMAC_CTX context that has been initialized.
1167 If the allocations fails, HmacSha1New() returns NULL.
1168 @return NULL This interface is not supported.
1178 Release the specified HMAC_CTX context.
1180 If this interface is not supported, then do nothing.
1182 @param[in] HmacSha1Ctx Pointer to the HMAC_CTX context to be released.
1188 IN VOID
*HmacSha1Ctx
1192 Set user-supplied key for subsequent use. It must be done before any
1193 calling to HmacSha1Update().
1195 If HmacSha1Context is NULL, then return FALSE.
1196 If this interface is not supported, then return FALSE.
1198 @param[out] HmacSha1Context Pointer to HMAC-SHA1 context.
1199 @param[in] Key Pointer to the user-supplied key.
1200 @param[in] KeySize Key size in bytes.
1202 @retval TRUE The Key is set successfully.
1203 @retval FALSE The Key is set unsuccessfully.
1204 @retval FALSE This interface is not supported.
1210 OUT VOID
*HmacSha1Context
,
1211 IN CONST UINT8
*Key
,
1216 Makes a copy of an existing HMAC-SHA1 context.
1218 If HmacSha1Context is NULL, then return FALSE.
1219 If NewHmacSha1Context is NULL, then return FALSE.
1220 If this interface is not supported, then return FALSE.
1222 @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied.
1223 @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context.
1225 @retval TRUE HMAC-SHA1 context copy succeeded.
1226 @retval FALSE HMAC-SHA1 context copy failed.
1227 @retval FALSE This interface is not supported.
1233 IN CONST VOID
*HmacSha1Context
,
1234 OUT VOID
*NewHmacSha1Context
1238 Digests the input data and updates HMAC-SHA1 context.
1240 This function performs HMAC-SHA1 digest on a data buffer of the specified size.
1241 It can be called multiple times to compute the digest of long or discontinuous data streams.
1242 HMAC-SHA1 context should be initialized by HmacSha1New(), and should not be finalized by
1243 HmacSha1Final(). Behavior with invalid context is undefined.
1245 If HmacSha1Context is NULL, then return FALSE.
1246 If this interface is not supported, then return FALSE.
1248 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1249 @param[in] Data Pointer to the buffer containing the data to be digested.
1250 @param[in] DataSize Size of Data buffer in bytes.
1252 @retval TRUE HMAC-SHA1 data digest succeeded.
1253 @retval FALSE HMAC-SHA1 data digest failed.
1254 @retval FALSE This interface is not supported.
1260 IN OUT VOID
*HmacSha1Context
,
1261 IN CONST VOID
*Data
,
1266 Completes computation of the HMAC-SHA1 digest value.
1268 This function completes HMAC-SHA1 hash computation and retrieves the digest value into
1269 the specified memory. After this function has been called, the HMAC-SHA1 context cannot
1271 HMAC-SHA1 context should be initialized by HmacSha1New(), and should not be finalized
1272 by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined.
1274 If HmacSha1Context is NULL, then return FALSE.
1275 If HmacValue is NULL, then return FALSE.
1276 If this interface is not supported, then return FALSE.
1278 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1279 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA1 digest
1282 @retval TRUE HMAC-SHA1 digest computation succeeded.
1283 @retval FALSE HMAC-SHA1 digest computation failed.
1284 @retval FALSE This interface is not supported.
1290 IN OUT VOID
*HmacSha1Context
,
1291 OUT UINT8
*HmacValue
1295 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
1297 @return Pointer to the HMAC_CTX context that has been initialized.
1298 If the allocations fails, HmacSha256New() returns NULL.
1308 Release the specified HMAC_CTX context.
1310 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.
1316 IN VOID
*HmacSha256Ctx
1320 Set user-supplied key for subsequent use. It must be done before any
1321 calling to HmacSha256Update().
1323 If HmacSha256Context is NULL, then return FALSE.
1324 If this interface is not supported, then return FALSE.
1326 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.
1327 @param[in] Key Pointer to the user-supplied key.
1328 @param[in] KeySize Key size in bytes.
1330 @retval TRUE The Key is set successfully.
1331 @retval FALSE The Key is set unsuccessfully.
1332 @retval FALSE This interface is not supported.
1338 OUT VOID
*HmacSha256Context
,
1339 IN CONST UINT8
*Key
,
1344 Makes a copy of an existing HMAC-SHA256 context.
1346 If HmacSha256Context is NULL, then return FALSE.
1347 If NewHmacSha256Context is NULL, then return FALSE.
1348 If this interface is not supported, then return FALSE.
1350 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.
1351 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.
1353 @retval TRUE HMAC-SHA256 context copy succeeded.
1354 @retval FALSE HMAC-SHA256 context copy failed.
1355 @retval FALSE This interface is not supported.
1360 HmacSha256Duplicate (
1361 IN CONST VOID
*HmacSha256Context
,
1362 OUT VOID
*NewHmacSha256Context
1366 Digests the input data and updates HMAC-SHA256 context.
1368 This function performs HMAC-SHA256 digest on a data buffer of the specified size.
1369 It can be called multiple times to compute the digest of long or discontinuous data streams.
1370 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1371 by HmacSha256Final(). Behavior with invalid context is undefined.
1373 If HmacSha256Context is NULL, then return FALSE.
1374 If this interface is not supported, then return FALSE.
1376 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1377 @param[in] Data Pointer to the buffer containing the data to be digested.
1378 @param[in] DataSize Size of Data buffer in bytes.
1380 @retval TRUE HMAC-SHA256 data digest succeeded.
1381 @retval FALSE HMAC-SHA256 data digest failed.
1382 @retval FALSE This interface is not supported.
1388 IN OUT VOID
*HmacSha256Context
,
1389 IN CONST VOID
*Data
,
1394 Completes computation of the HMAC-SHA256 digest value.
1396 This function completes HMAC-SHA256 hash computation and retrieves the digest value into
1397 the specified memory. After this function has been called, the HMAC-SHA256 context cannot
1399 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1400 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.
1402 If HmacSha256Context is NULL, then return FALSE.
1403 If HmacValue is NULL, then return FALSE.
1404 If this interface is not supported, then return FALSE.
1406 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1407 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
1410 @retval TRUE HMAC-SHA256 digest computation succeeded.
1411 @retval FALSE HMAC-SHA256 digest computation failed.
1412 @retval FALSE This interface is not supported.
1418 IN OUT VOID
*HmacSha256Context
,
1419 OUT UINT8
*HmacValue
1422 //=====================================================================================
1423 // Symmetric Cryptography Primitive
1424 //=====================================================================================
1427 Retrieves the size, in bytes, of the context buffer required for TDES operations.
1429 If this interface is not supported, then return zero.
1431 @return The size, in bytes, of the context buffer required for TDES operations.
1432 @retval 0 This interface is not supported.
1437 TdesGetContextSize (
1442 Initializes user-supplied memory as TDES context for subsequent use.
1444 This function initializes user-supplied memory pointed by TdesContext as TDES context.
1445 In addition, it sets up all TDES key materials for subsequent encryption and decryption
1447 There are 3 key options as follows:
1448 KeyLength = 64, Keying option 1: K1 == K2 == K3 (Backward compatibility with DES)
1449 KeyLength = 128, Keying option 2: K1 != K2 and K3 = K1 (Less Security)
1450 KeyLength = 192 Keying option 3: K1 != K2 != K3 (Strongest)
1452 If TdesContext is NULL, then return FALSE.
1453 If Key is NULL, then return FALSE.
1454 If KeyLength is not valid, then return FALSE.
1455 If this interface is not supported, then return FALSE.
1457 @param[out] TdesContext Pointer to TDES context being initialized.
1458 @param[in] Key Pointer to the user-supplied TDES key.
1459 @param[in] KeyLength Length of TDES key in bits.
1461 @retval TRUE TDES context initialization succeeded.
1462 @retval FALSE TDES context initialization failed.
1463 @retval FALSE This interface is not supported.
1469 OUT VOID
*TdesContext
,
1470 IN CONST UINT8
*Key
,
1475 Performs TDES encryption on a data buffer of the specified size in ECB mode.
1477 This function performs TDES encryption on data buffer pointed by Input, of specified
1478 size of InputSize, in ECB mode.
1479 InputSize must be multiple of block size (8 bytes). This function does not perform
1480 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1481 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1482 invalid TDES context is undefined.
1484 If TdesContext is NULL, then return FALSE.
1485 If Input is NULL, then return FALSE.
1486 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1487 If Output is NULL, then return FALSE.
1488 If this interface is not supported, then return FALSE.
1490 @param[in] TdesContext Pointer to the TDES context.
1491 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1492 @param[in] InputSize Size of the Input buffer in bytes.
1493 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1495 @retval TRUE TDES encryption succeeded.
1496 @retval FALSE TDES encryption failed.
1497 @retval FALSE This interface is not supported.
1503 IN VOID
*TdesContext
,
1504 IN CONST UINT8
*Input
,
1510 Performs TDES decryption on a data buffer of the specified size in ECB mode.
1512 This function performs TDES decryption on data buffer pointed by Input, of specified
1513 size of InputSize, in ECB mode.
1514 InputSize must be multiple of block size (8 bytes). This function does not perform
1515 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1516 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1517 invalid TDES context is undefined.
1519 If TdesContext is NULL, then return FALSE.
1520 If Input is NULL, then return FALSE.
1521 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1522 If Output is NULL, then return FALSE.
1523 If this interface is not supported, then return FALSE.
1525 @param[in] TdesContext Pointer to the TDES context.
1526 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1527 @param[in] InputSize Size of the Input buffer in bytes.
1528 @param[out] Output Pointer to a buffer that receives the TDES decryption output.
1530 @retval TRUE TDES decryption succeeded.
1531 @retval FALSE TDES decryption failed.
1532 @retval FALSE This interface is not supported.
1538 IN VOID
*TdesContext
,
1539 IN CONST UINT8
*Input
,
1545 Performs TDES encryption on a data buffer of the specified size in CBC mode.
1547 This function performs TDES encryption on data buffer pointed by Input, of specified
1548 size of InputSize, in CBC mode.
1549 InputSize must be multiple of block size (8 bytes). This function does not perform
1550 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1551 Initialization vector should be one block size (8 bytes).
1552 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1553 invalid TDES context is undefined.
1555 If TdesContext is NULL, then return FALSE.
1556 If Input is NULL, then return FALSE.
1557 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1558 If Ivec is NULL, then return FALSE.
1559 If Output is NULL, then return FALSE.
1560 If this interface is not supported, then return FALSE.
1562 @param[in] TdesContext Pointer to the TDES context.
1563 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1564 @param[in] InputSize Size of the Input buffer in bytes.
1565 @param[in] Ivec Pointer to initialization vector.
1566 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1568 @retval TRUE TDES encryption succeeded.
1569 @retval FALSE TDES encryption failed.
1570 @retval FALSE This interface is not supported.
1576 IN VOID
*TdesContext
,
1577 IN CONST UINT8
*Input
,
1579 IN CONST UINT8
*Ivec
,
1584 Performs TDES decryption on a data buffer of the specified size in CBC mode.
1586 This function performs TDES decryption on data buffer pointed by Input, of specified
1587 size of InputSize, in CBC mode.
1588 InputSize must be multiple of block size (8 bytes). This function does not perform
1589 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1590 Initialization vector should be one block size (8 bytes).
1591 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1592 invalid TDES context is undefined.
1594 If TdesContext is NULL, then return FALSE.
1595 If Input is NULL, then return FALSE.
1596 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1597 If Ivec is NULL, then return FALSE.
1598 If Output is NULL, then return FALSE.
1599 If this interface is not supported, then return FALSE.
1601 @param[in] TdesContext Pointer to the TDES context.
1602 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1603 @param[in] InputSize Size of the Input buffer in bytes.
1604 @param[in] Ivec Pointer to initialization vector.
1605 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1607 @retval TRUE TDES decryption succeeded.
1608 @retval FALSE TDES decryption failed.
1609 @retval FALSE This interface is not supported.
1615 IN VOID
*TdesContext
,
1616 IN CONST UINT8
*Input
,
1618 IN CONST UINT8
*Ivec
,
1623 Retrieves the size, in bytes, of the context buffer required for AES operations.
1625 If this interface is not supported, then return zero.
1627 @return The size, in bytes, of the context buffer required for AES operations.
1628 @retval 0 This interface is not supported.
1638 Initializes user-supplied memory as AES context for subsequent use.
1640 This function initializes user-supplied memory pointed by AesContext as AES context.
1641 In addition, it sets up all AES key materials for subsequent encryption and decryption
1643 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1645 If AesContext is NULL, then return FALSE.
1646 If Key is NULL, then return FALSE.
1647 If KeyLength is not valid, then return FALSE.
1648 If this interface is not supported, then return FALSE.
1650 @param[out] AesContext Pointer to AES context being initialized.
1651 @param[in] Key Pointer to the user-supplied AES key.
1652 @param[in] KeyLength Length of AES key in bits.
1654 @retval TRUE AES context initialization succeeded.
1655 @retval FALSE AES context initialization failed.
1656 @retval FALSE This interface is not supported.
1662 OUT VOID
*AesContext
,
1663 IN CONST UINT8
*Key
,
1668 Performs AES encryption on a data buffer of the specified size in ECB mode.
1670 This function performs AES encryption on data buffer pointed by Input, of specified
1671 size of InputSize, in ECB mode.
1672 InputSize must be multiple of block size (16 bytes). This function does not perform
1673 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1674 AesContext should be already correctly initialized by AesInit(). Behavior with
1675 invalid AES context is undefined.
1677 If AesContext is NULL, then return FALSE.
1678 If Input is NULL, then return FALSE.
1679 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1680 If Output is NULL, then return FALSE.
1681 If this interface is not supported, then return FALSE.
1683 @param[in] AesContext Pointer to the AES context.
1684 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1685 @param[in] InputSize Size of the Input buffer in bytes.
1686 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1688 @retval TRUE AES encryption succeeded.
1689 @retval FALSE AES encryption failed.
1690 @retval FALSE This interface is not supported.
1696 IN VOID
*AesContext
,
1697 IN CONST UINT8
*Input
,
1703 Performs AES decryption on a data buffer of the specified size in ECB mode.
1705 This function performs AES decryption on data buffer pointed by Input, of specified
1706 size of InputSize, in ECB mode.
1707 InputSize must be multiple of block size (16 bytes). This function does not perform
1708 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1709 AesContext should be already correctly initialized by AesInit(). Behavior with
1710 invalid AES context is undefined.
1712 If AesContext is NULL, then return FALSE.
1713 If Input is NULL, then return FALSE.
1714 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1715 If Output is NULL, then return FALSE.
1716 If this interface is not supported, then return FALSE.
1718 @param[in] AesContext Pointer to the AES context.
1719 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1720 @param[in] InputSize Size of the Input buffer in bytes.
1721 @param[out] Output Pointer to a buffer that receives the AES decryption output.
1723 @retval TRUE AES decryption succeeded.
1724 @retval FALSE AES decryption failed.
1725 @retval FALSE This interface is not supported.
1731 IN VOID
*AesContext
,
1732 IN CONST UINT8
*Input
,
1738 Performs AES encryption on a data buffer of the specified size in CBC mode.
1740 This function performs AES encryption on data buffer pointed by Input, of specified
1741 size of InputSize, in CBC mode.
1742 InputSize must be multiple of block size (16 bytes). This function does not perform
1743 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1744 Initialization vector should be one block size (16 bytes).
1745 AesContext should be already correctly initialized by AesInit(). Behavior with
1746 invalid AES context is undefined.
1748 If AesContext is NULL, then return FALSE.
1749 If Input is NULL, then return FALSE.
1750 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1751 If Ivec is NULL, then return FALSE.
1752 If Output is NULL, then return FALSE.
1753 If this interface is not supported, then return FALSE.
1755 @param[in] AesContext Pointer to the AES context.
1756 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1757 @param[in] InputSize Size of the Input buffer in bytes.
1758 @param[in] Ivec Pointer to initialization vector.
1759 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1761 @retval TRUE AES encryption succeeded.
1762 @retval FALSE AES encryption failed.
1763 @retval FALSE This interface is not supported.
1769 IN VOID
*AesContext
,
1770 IN CONST UINT8
*Input
,
1772 IN CONST UINT8
*Ivec
,
1777 Performs AES decryption on a data buffer of the specified size in CBC mode.
1779 This function performs AES decryption on data buffer pointed by Input, of specified
1780 size of InputSize, in CBC mode.
1781 InputSize must be multiple of block size (16 bytes). This function does not perform
1782 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1783 Initialization vector should be one block size (16 bytes).
1784 AesContext should be already correctly initialized by AesInit(). Behavior with
1785 invalid AES context is undefined.
1787 If AesContext is NULL, then return FALSE.
1788 If Input is NULL, then return FALSE.
1789 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1790 If Ivec is NULL, then return FALSE.
1791 If Output is NULL, then return FALSE.
1792 If this interface is not supported, then return FALSE.
1794 @param[in] AesContext Pointer to the AES context.
1795 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1796 @param[in] InputSize Size of the Input buffer in bytes.
1797 @param[in] Ivec Pointer to initialization vector.
1798 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1800 @retval TRUE AES decryption succeeded.
1801 @retval FALSE AES decryption failed.
1802 @retval FALSE This interface is not supported.
1808 IN VOID
*AesContext
,
1809 IN CONST UINT8
*Input
,
1811 IN CONST UINT8
*Ivec
,
1816 Retrieves the size, in bytes, of the context buffer required for ARC4 operations.
1818 If this interface is not supported, then return zero.
1820 @return The size, in bytes, of the context buffer required for ARC4 operations.
1821 @retval 0 This interface is not supported.
1826 Arc4GetContextSize (
1831 Initializes user-supplied memory as ARC4 context for subsequent use.
1833 This function initializes user-supplied memory pointed by Arc4Context as ARC4 context.
1834 In addition, it sets up all ARC4 key materials for subsequent encryption and decryption
1837 If Arc4Context is NULL, then return FALSE.
1838 If Key is NULL, then return FALSE.
1839 If KeySize does not in the range of [5, 256] bytes, then return FALSE.
1840 If this interface is not supported, then return FALSE.
1842 @param[out] Arc4Context Pointer to ARC4 context being initialized.
1843 @param[in] Key Pointer to the user-supplied ARC4 key.
1844 @param[in] KeySize Size of ARC4 key in bytes.
1846 @retval TRUE ARC4 context initialization succeeded.
1847 @retval FALSE ARC4 context initialization failed.
1848 @retval FALSE This interface is not supported.
1854 OUT VOID
*Arc4Context
,
1855 IN CONST UINT8
*Key
,
1860 Performs ARC4 encryption on a data buffer of the specified size.
1862 This function performs ARC4 encryption on data buffer pointed by Input, of specified
1864 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
1865 invalid ARC4 context is undefined.
1867 If Arc4Context is NULL, then return FALSE.
1868 If Input is NULL, then return FALSE.
1869 If Output is NULL, then return FALSE.
1870 If this interface is not supported, then return FALSE.
1872 @param[in, out] Arc4Context Pointer to the ARC4 context.
1873 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1874 @param[in] InputSize Size of the Input buffer in bytes.
1875 @param[out] Output Pointer to a buffer that receives the ARC4 encryption output.
1877 @retval TRUE ARC4 encryption succeeded.
1878 @retval FALSE ARC4 encryption failed.
1879 @retval FALSE This interface is not supported.
1885 IN OUT VOID
*Arc4Context
,
1886 IN CONST UINT8
*Input
,
1892 Performs ARC4 decryption on a data buffer of the specified size.
1894 This function performs ARC4 decryption on data buffer pointed by Input, of specified
1896 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
1897 invalid ARC4 context is undefined.
1899 If Arc4Context is NULL, then return FALSE.
1900 If Input is NULL, then return FALSE.
1901 If Output is NULL, then return FALSE.
1902 If this interface is not supported, then return FALSE.
1904 @param[in, out] Arc4Context Pointer to the ARC4 context.
1905 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1906 @param[in] InputSize Size of the Input buffer in bytes.
1907 @param[out] Output Pointer to a buffer that receives the ARC4 decryption output.
1909 @retval TRUE ARC4 decryption succeeded.
1910 @retval FALSE ARC4 decryption failed.
1911 @retval FALSE This interface is not supported.
1917 IN OUT VOID
*Arc4Context
,
1924 Resets the ARC4 context to the initial state.
1926 The function resets the ARC4 context to the state it had immediately after the
1927 ARC4Init() function call.
1928 Contrary to ARC4Init(), Arc4Reset() requires no secret key as input, but ARC4 context
1929 should be already correctly initialized by ARC4Init().
1931 If Arc4Context is NULL, then return FALSE.
1932 If this interface is not supported, then return FALSE.
1934 @param[in, out] Arc4Context Pointer to the ARC4 context.
1936 @retval TRUE ARC4 reset succeeded.
1937 @retval FALSE ARC4 reset failed.
1938 @retval FALSE This interface is not supported.
1944 IN OUT VOID
*Arc4Context
1947 //=====================================================================================
1948 // Asymmetric Cryptography Primitive
1949 //=====================================================================================
1952 Allocates and initializes one RSA context for subsequent use.
1954 @return Pointer to the RSA context that has been initialized.
1955 If the allocations fails, RsaNew() returns NULL.
1965 Release the specified RSA context.
1967 If RsaContext is NULL, then return FALSE.
1969 @param[in] RsaContext Pointer to the RSA context to be released.
1979 Sets the tag-designated key component into the established RSA context.
1981 This function sets the tag-designated RSA key component into the established
1982 RSA context from the user-specified non-negative integer (octet string format
1983 represented in RSA PKCS#1).
1984 If BigNumber is NULL, then the specified key component in RSA context is cleared.
1986 If RsaContext is NULL, then return FALSE.
1988 @param[in, out] RsaContext Pointer to RSA context being set.
1989 @param[in] KeyTag Tag of RSA key component being set.
1990 @param[in] BigNumber Pointer to octet integer buffer.
1991 If NULL, then the specified key component in RSA
1993 @param[in] BnSize Size of big number buffer in bytes.
1994 If BigNumber is NULL, then it is ignored.
1996 @retval TRUE RSA key component was set successfully.
1997 @retval FALSE Invalid RSA key component tag.
2003 IN OUT VOID
*RsaContext
,
2004 IN RSA_KEY_TAG KeyTag
,
2005 IN CONST UINT8
*BigNumber
,
2010 Gets the tag-designated RSA key component from the established RSA context.
2012 This function retrieves the tag-designated RSA key component from the
2013 established RSA context as a non-negative integer (octet string format
2014 represented in RSA PKCS#1).
2015 If specified key component has not been set or has been cleared, then returned
2017 If the BigNumber buffer is too small to hold the contents of the key, FALSE
2018 is returned and BnSize is set to the required buffer size to obtain the key.
2020 If RsaContext is NULL, then return FALSE.
2021 If BnSize is NULL, then return FALSE.
2022 If BnSize is large enough but BigNumber is NULL, then return FALSE.
2023 If this interface is not supported, then return FALSE.
2025 @param[in, out] RsaContext Pointer to RSA context being set.
2026 @param[in] KeyTag Tag of RSA key component being set.
2027 @param[out] BigNumber Pointer to octet integer buffer.
2028 @param[in, out] BnSize On input, the size of big number buffer in bytes.
2029 On output, the size of data returned in big number buffer in bytes.
2031 @retval TRUE RSA key component was retrieved successfully.
2032 @retval FALSE Invalid RSA key component tag.
2033 @retval FALSE BnSize is too small.
2034 @retval FALSE This interface is not supported.
2040 IN OUT VOID
*RsaContext
,
2041 IN RSA_KEY_TAG KeyTag
,
2042 OUT UINT8
*BigNumber
,
2043 IN OUT UINTN
*BnSize
2047 Generates RSA key components.
2049 This function generates RSA key components. It takes RSA public exponent E and
2050 length in bits of RSA modulus N as input, and generates all key components.
2051 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
2053 Before this function can be invoked, pseudorandom number generator must be correctly
2054 initialized by RandomSeed().
2056 If RsaContext is NULL, then return FALSE.
2057 If this interface is not supported, then return FALSE.
2059 @param[in, out] RsaContext Pointer to RSA context being set.
2060 @param[in] ModulusLength Length of RSA modulus N in bits.
2061 @param[in] PublicExponent Pointer to RSA public exponent.
2062 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
2064 @retval TRUE RSA key component was generated successfully.
2065 @retval FALSE Invalid RSA key component tag.
2066 @retval FALSE This interface is not supported.
2072 IN OUT VOID
*RsaContext
,
2073 IN UINTN ModulusLength
,
2074 IN CONST UINT8
*PublicExponent
,
2075 IN UINTN PublicExponentSize
2079 Validates key components of RSA context.
2080 NOTE: This function performs integrity checks on all the RSA key material, so
2081 the RSA key structure must contain all the private key data.
2083 This function validates key components of RSA context in following aspects:
2084 - Whether p is a prime
2085 - Whether q is a prime
2087 - Whether d*e = 1 mod lcm(p-1,q-1)
2089 If RsaContext is NULL, then return FALSE.
2090 If this interface is not supported, then return FALSE.
2092 @param[in] RsaContext Pointer to RSA context to check.
2094 @retval TRUE RSA key components are valid.
2095 @retval FALSE RSA key components are not valid.
2096 @retval FALSE This interface is not supported.
2106 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
2108 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
2110 If the Signature buffer is too small to hold the contents of signature, FALSE
2111 is returned and SigSize is set to the required buffer size to obtain the signature.
2113 If RsaContext is NULL, then return FALSE.
2114 If MessageHash is NULL, then return FALSE.
2115 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
2116 If SigSize is large enough but Signature is NULL, then return FALSE.
2117 If this interface is not supported, then return FALSE.
2119 @param[in] RsaContext Pointer to RSA context for signature generation.
2120 @param[in] MessageHash Pointer to octet message hash to be signed.
2121 @param[in] HashSize Size of the message hash in bytes.
2122 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
2123 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
2124 On output, the size of data returned in Signature buffer in bytes.
2126 @retval TRUE Signature successfully generated in PKCS1-v1_5.
2127 @retval FALSE Signature generation failed.
2128 @retval FALSE SigSize is too small.
2129 @retval FALSE This interface is not supported.
2135 IN VOID
*RsaContext
,
2136 IN CONST UINT8
*MessageHash
,
2138 OUT UINT8
*Signature
,
2139 IN OUT UINTN
*SigSize
2143 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
2146 If RsaContext is NULL, then return FALSE.
2147 If MessageHash is NULL, then return FALSE.
2148 If Signature is NULL, then return FALSE.
2149 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
2151 @param[in] RsaContext Pointer to RSA context for signature verification.
2152 @param[in] MessageHash Pointer to octet message hash to be checked.
2153 @param[in] HashSize Size of the message hash in bytes.
2154 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
2155 @param[in] SigSize Size of signature in bytes.
2157 @retval TRUE Valid signature encoded in PKCS1-v1_5.
2158 @retval FALSE Invalid signature or invalid RSA context.
2164 IN VOID
*RsaContext
,
2165 IN CONST UINT8
*MessageHash
,
2167 IN CONST UINT8
*Signature
,
2172 Retrieve the RSA Private Key from the password-protected PEM key data.
2174 If PemData is NULL, then return FALSE.
2175 If RsaContext is NULL, then return FALSE.
2176 If this interface is not supported, then return FALSE.
2178 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
2179 @param[in] PemSize Size of the PEM key data in bytes.
2180 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
2181 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2182 RSA private key component. Use RsaFree() function to free the
2185 @retval TRUE RSA Private Key was retrieved successfully.
2186 @retval FALSE Invalid PEM key data or incorrect password.
2187 @retval FALSE This interface is not supported.
2192 RsaGetPrivateKeyFromPem (
2193 IN CONST UINT8
*PemData
,
2195 IN CONST CHAR8
*Password
,
2196 OUT VOID
**RsaContext
2200 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
2202 If Cert is NULL, then return FALSE.
2203 If RsaContext is NULL, then return FALSE.
2204 If this interface is not supported, then return FALSE.
2206 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2207 @param[in] CertSize Size of the X509 certificate in bytes.
2208 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2209 RSA public key component. Use RsaFree() function to free the
2212 @retval TRUE RSA Public Key was retrieved successfully.
2213 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
2214 @retval FALSE This interface is not supported.
2219 RsaGetPublicKeyFromX509 (
2220 IN CONST UINT8
*Cert
,
2222 OUT VOID
**RsaContext
2226 Retrieve the subject bytes from one X.509 certificate.
2228 If Cert is NULL, then return FALSE.
2229 If SubjectSize is NULL, then return FALSE.
2230 If this interface is not supported, then return FALSE.
2232 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2233 @param[in] CertSize Size of the X509 certificate in bytes.
2234 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
2235 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
2236 and the size of buffer returned CertSubject on output.
2238 @retval TRUE The certificate subject retrieved successfully.
2239 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
2240 The SubjectSize will be updated with the required size.
2241 @retval FALSE This interface is not supported.
2246 X509GetSubjectName (
2247 IN CONST UINT8
*Cert
,
2249 OUT UINT8
*CertSubject
,
2250 IN OUT UINTN
*SubjectSize
2254 Retrieve the common name (CN) string from one X.509 certificate.
2256 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2257 @param[in] CertSize Size of the X509 certificate in bytes.
2258 @param[out] CommonName Buffer to contain the retrieved certificate common
2259 name string (UTF8). At most CommonNameSize bytes will be
2260 written and the string will be null terminated. May be
2261 NULL in order to determine the size buffer needed.
2262 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
2263 and the size of buffer returned CommonName on output.
2264 If CommonName is NULL then the amount of space needed
2265 in buffer (including the final null) is returned.
2267 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
2268 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2269 If CommonNameSize is NULL.
2270 If CommonName is not NULL and *CommonNameSize is 0.
2271 If Certificate is invalid.
2272 @retval RETURN_NOT_FOUND If no CommonName entry exists.
2273 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
2274 (including the final null) is returned in the
2275 CommonNameSize parameter.
2276 @retval RETURN_UNSUPPORTED The operation is not supported.
2282 IN CONST UINT8
*Cert
,
2284 OUT CHAR8
*CommonName
, OPTIONAL
2285 IN OUT UINTN
*CommonNameSize
2289 Retrieve the organization name (O) string from one X.509 certificate.
2291 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2292 @param[in] CertSize Size of the X509 certificate in bytes.
2293 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
2294 name string. At most NameBufferSize bytes will be
2295 written and the string will be null terminated. May be
2296 NULL in order to determine the size buffer needed.
2297 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
2298 and the size of buffer returned Name on output.
2299 If NameBuffer is NULL then the amount of space needed
2300 in buffer (including the final null) is returned.
2302 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
2303 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2304 If NameBufferSize is NULL.
2305 If NameBuffer is not NULL and *CommonNameSize is 0.
2306 If Certificate is invalid.
2307 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
2308 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
2309 (including the final null) is returned in the
2310 CommonNameSize parameter.
2311 @retval RETURN_UNSUPPORTED The operation is not supported.
2316 X509GetOrganizationName (
2317 IN CONST UINT8
*Cert
,
2319 OUT CHAR8
*NameBuffer
, OPTIONAL
2320 IN OUT UINTN
*NameBufferSize
2324 Verify one X509 certificate was issued by the trusted CA.
2326 If Cert is NULL, then return FALSE.
2327 If CACert is NULL, then return FALSE.
2328 If this interface is not supported, then return FALSE.
2330 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
2331 @param[in] CertSize Size of the X509 certificate in bytes.
2332 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
2333 @param[in] CACertSize Size of the CA Certificate in bytes.
2335 @retval TRUE The certificate was issued by the trusted CA.
2336 @retval FALSE Invalid certificate or the certificate was not issued by the given
2338 @retval FALSE This interface is not supported.
2344 IN CONST UINT8
*Cert
,
2346 IN CONST UINT8
*CACert
,
2351 Construct a X509 object from DER-encoded certificate data.
2353 If Cert is NULL, then return FALSE.
2354 If SingleX509Cert is NULL, then return FALSE.
2355 If this interface is not supported, then return FALSE.
2357 @param[in] Cert Pointer to the DER-encoded certificate data.
2358 @param[in] CertSize The size of certificate data in bytes.
2359 @param[out] SingleX509Cert The generated X509 object.
2361 @retval TRUE The X509 object generation succeeded.
2362 @retval FALSE The operation failed.
2363 @retval FALSE This interface is not supported.
2368 X509ConstructCertificate (
2369 IN CONST UINT8
*Cert
,
2371 OUT UINT8
**SingleX509Cert
2375 Construct a X509 stack object from a list of DER-encoded certificate data.
2377 If X509Stack is NULL, then return FALSE.
2378 If this interface is not supported, then return FALSE.
2380 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2381 On output, pointer to the X509 stack object with new
2382 inserted X509 certificate.
2383 @param ... A list of DER-encoded single certificate data followed
2384 by certificate size. A NULL terminates the list. The
2385 pairs are the arguments to X509ConstructCertificate().
2387 @retval TRUE The X509 stack construction succeeded.
2388 @retval FALSE The construction operation failed.
2389 @retval FALSE This interface is not supported.
2394 X509ConstructCertificateStack (
2395 IN OUT UINT8
**X509Stack
,
2400 Release the specified X509 object.
2402 If the interface is not supported, then ASSERT().
2404 @param[in] X509Cert Pointer to the X509 object to be released.
2414 Release the specified X509 stack object.
2416 If the interface is not supported, then ASSERT().
2418 @param[in] X509Stack Pointer to the X509 stack object to be released.
2428 Retrieve the TBSCertificate from one given X.509 certificate.
2430 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
2431 @param[in] CertSize Size of the X509 certificate in bytes.
2432 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
2433 @param[out] TBSCertSize Size of the TBS certificate in bytes.
2435 If Cert is NULL, then return FALSE.
2436 If TBSCert is NULL, then return FALSE.
2437 If TBSCertSize is NULL, then return FALSE.
2438 If this interface is not supported, then return FALSE.
2440 @retval TRUE The TBSCertificate was retrieved successfully.
2441 @retval FALSE Invalid X.509 certificate.
2447 IN CONST UINT8
*Cert
,
2449 OUT UINT8
**TBSCert
,
2450 OUT UINTN
*TBSCertSize
2454 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2455 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2457 If Password or Salt or OutKey is NULL, then return FALSE.
2458 If the hash algorithm could not be determined, then return FALSE.
2459 If this interface is not supported, then return FALSE.
2461 @param[in] PasswordLength Length of input password in bytes.
2462 @param[in] Password Pointer to the array for the password.
2463 @param[in] SaltLength Size of the Salt in bytes.
2464 @param[in] Salt Pointer to the Salt.
2465 @param[in] IterationCount Number of iterations to perform. Its value should be
2466 greater than or equal to 1.
2467 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2468 NOTE: DigestSize will be used to determine the hash algorithm.
2469 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2470 @param[in] KeyLength Size of the derived key buffer in bytes.
2471 @param[out] OutKey Pointer to the output derived key buffer.
2473 @retval TRUE A key was derived successfully.
2474 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2475 @retval FALSE The hash algorithm could not be determined from the digest size.
2476 @retval FALSE The key derivation operation failed.
2477 @retval FALSE This interface is not supported.
2483 IN UINTN PasswordLength
,
2484 IN CONST CHAR8
*Password
,
2485 IN UINTN SaltLength
,
2486 IN CONST UINT8
*Salt
,
2487 IN UINTN IterationCount
,
2488 IN UINTN DigestSize
,
2494 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2495 encrypted message in a newly allocated buffer.
2497 Things that can cause a failure include:
2498 - X509 key size does not match any known key size.
2499 - Fail to parse X509 certificate.
2500 - Fail to allocate an intermediate buffer.
2501 - Null pointer provided for a non-optional parameter.
2502 - Data size is too large for the provided key size (max size is a function of key size
2503 and hash digest size).
2505 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2506 will be used to encrypt the data.
2507 @param[in] PublicKeySize Size of the X509 cert buffer.
2508 @param[in] InData Data to be encrypted.
2509 @param[in] InDataSize Size of the data buffer.
2510 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2511 to be used when initializing the PRNG. NULL otherwise.
2512 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2514 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2516 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2518 @retval TRUE Encryption was successful.
2519 @retval FALSE Encryption failed.
2525 IN CONST UINT8
*PublicKey
,
2526 IN UINTN PublicKeySize
,
2528 IN UINTN InDataSize
,
2529 IN CONST UINT8
*PrngSeed
, OPTIONAL
2530 IN UINTN PrngSeedSize
, OPTIONAL
2531 OUT UINT8
**EncryptedData
,
2532 OUT UINTN
*EncryptedDataSize
2536 The 3rd parameter of Pkcs7GetSigners will return all embedded
2537 X.509 certificate in one given PKCS7 signature. The format is:
2539 // UINT8 CertNumber;
2540 // UINT32 Cert1Length;
2542 // UINT32 Cert2Length;
2545 // UINT32 CertnLength;
2549 The two following C-structure are used for parsing CertStack more clearly.
2554 UINT32 CertDataLength
; // The length in bytes of X.509 certificate.
2555 UINT8 CertDataBuffer
[0]; // The X.509 certificate content (DER).
2559 UINT8 CertNumber
; // Number of X.509 certificate.
2560 //EFI_CERT_DATA CertArray[]; // An array of X.509 certificate.
2566 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2567 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2568 in a ContentInfo structure.
2570 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2571 return FALSE. If P7Length overflow, then return FALSE.
2572 If this interface is not supported, then return FALSE.
2574 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2575 @param[in] P7Length Length of the PKCS#7 message in bytes.
2576 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2577 It's caller's responsibility to free the buffer with
2579 This data structure is EFI_CERT_STACK type.
2580 @param[out] StackLength Length of signer's certificates in bytes.
2581 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2582 It's caller's responsibility to free the buffer with
2584 @param[out] CertLength Length of the trusted certificate in bytes.
2586 @retval TRUE The operation is finished successfully.
2587 @retval FALSE Error occurs during the operation.
2588 @retval FALSE This interface is not supported.
2594 IN CONST UINT8
*P7Data
,
2596 OUT UINT8
**CertStack
,
2597 OUT UINTN
*StackLength
,
2598 OUT UINT8
**TrustedCert
,
2599 OUT UINTN
*CertLength
2603 Wrap function to use free() to free allocated memory for certificates.
2605 If this interface is not supported, then ASSERT().
2607 @param[in] Certs Pointer to the certificates to be freed.
2617 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2618 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2619 unchained to the signer's certificates.
2620 The input signed data could be wrapped in a ContentInfo structure.
2622 @param[in] P7Data Pointer to the PKCS#7 message.
2623 @param[in] P7Length Length of the PKCS#7 message in bytes.
2624 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2625 certificate. It's caller's responsibility to free the buffer
2626 with Pkcs7FreeSigners().
2627 This data structure is EFI_CERT_STACK type.
2628 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2629 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2630 responsibility to free the buffer with Pkcs7FreeSigners().
2631 This data structure is EFI_CERT_STACK type.
2632 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2634 @retval TRUE The operation is finished successfully.
2635 @retval FALSE Error occurs during the operation.
2640 Pkcs7GetCertificatesList (
2641 IN CONST UINT8
*P7Data
,
2643 OUT UINT8
**SignerChainCerts
,
2644 OUT UINTN
*ChainLength
,
2645 OUT UINT8
**UnchainCerts
,
2646 OUT UINTN
*UnchainLength
2650 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2651 Syntax Standard, version 1.5". This interface is only intended to be used for
2652 application to perform PKCS#7 functionality validation.
2654 If this interface is not supported, then return FALSE.
2656 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2658 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2659 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2661 @param[in] InData Pointer to the content to be signed.
2662 @param[in] InDataSize Size of InData in bytes.
2663 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2664 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2665 include in the PKCS#7 signedData (e.g. any intermediate
2667 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2668 responsibility to free the buffer with FreePool().
2669 @param[out] SignedDataSize Size of SignedData in bytes.
2671 @retval TRUE PKCS#7 data signing succeeded.
2672 @retval FALSE PKCS#7 data signing failed.
2673 @retval FALSE This interface is not supported.
2679 IN CONST UINT8
*PrivateKey
,
2680 IN UINTN PrivateKeySize
,
2681 IN CONST UINT8
*KeyPassword
,
2683 IN UINTN InDataSize
,
2685 IN UINT8
*OtherCerts OPTIONAL
,
2686 OUT UINT8
**SignedData
,
2687 OUT UINTN
*SignedDataSize
2691 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2692 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2693 in a ContentInfo structure.
2695 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2696 If P7Length, CertLength or DataLength overflow, then return FALSE.
2697 If this interface is not supported, then return FALSE.
2699 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2700 @param[in] P7Length Length of the PKCS#7 message in bytes.
2701 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2702 is used for certificate chain verification.
2703 @param[in] CertLength Length of the trusted certificate in bytes.
2704 @param[in] InData Pointer to the content to be verified.
2705 @param[in] DataLength Length of InData in bytes.
2707 @retval TRUE The specified PKCS#7 signed data is valid.
2708 @retval FALSE Invalid PKCS#7 signed data.
2709 @retval FALSE This interface is not supported.
2715 IN CONST UINT8
*P7Data
,
2717 IN CONST UINT8
*TrustedCert
,
2718 IN UINTN CertLength
,
2719 IN CONST UINT8
*InData
,
2724 This function receives a PKCS7 formatted signature, and then verifies that
2725 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
2726 leaf signing certificate.
2727 Note that this function does not validate the certificate chain.
2729 Applications for custom EKU's are quite flexible. For example, a policy EKU
2730 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
2731 certificate issued might also contain this EKU, thus constraining the
2732 sub-ordinate certificate. Other applications might allow a certificate
2733 embedded in a device to specify that other Object Identifiers (OIDs) are
2734 present which contains binary data specifying custom capabilities that
2735 the device is able to do.
2737 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
2738 containing the content block with both the signature,
2739 the signer's certificate, and any necessary intermediate
2741 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
2742 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
2743 required EKUs that must be present in the signature.
2744 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
2745 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
2746 must be present in the leaf signer. If it is
2747 FALSE, then we will succeed if we find any
2748 of the specified EKU's.
2750 @retval EFI_SUCCESS The required EKUs were found in the signature.
2751 @retval EFI_INVALID_PARAMETER A parameter was invalid.
2752 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
2757 VerifyEKUsInPkcs7Signature (
2758 IN CONST UINT8
*Pkcs7Signature
,
2759 IN CONST UINT32 SignatureSize
,
2760 IN CONST CHAR8
*RequiredEKUs
[],
2761 IN CONST UINT32 RequiredEKUsSize
,
2762 IN BOOLEAN RequireAllPresent
2766 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2767 data could be wrapped in a ContentInfo structure.
2769 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2770 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2772 Caution: This function may receive untrusted input. So this function will do
2773 basic check for PKCS#7 data structure.
2775 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2776 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2777 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2778 It's caller's responsibility to free the buffer with FreePool().
2779 @param[out] ContentSize The size of the extracted content in bytes.
2781 @retval TRUE The P7Data was correctly formatted for processing.
2782 @retval FALSE The P7Data was not correctly formatted for processing.
2787 Pkcs7GetAttachedContent (
2788 IN CONST UINT8
*P7Data
,
2791 OUT UINTN
*ContentSize
2795 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2796 Authenticode Portable Executable Signature Format".
2798 If AuthData is NULL, then return FALSE.
2799 If ImageHash is NULL, then return FALSE.
2800 If this interface is not supported, then return FALSE.
2802 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2803 PE/COFF image to be verified.
2804 @param[in] DataSize Size of the Authenticode Signature in bytes.
2805 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2806 is used for certificate chain verification.
2807 @param[in] CertSize Size of the trusted certificate in bytes.
2808 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2809 for calculating the image hash value is described in Authenticode
2811 @param[in] HashSize Size of Image hash value in bytes.
2813 @retval TRUE The specified Authenticode Signature is valid.
2814 @retval FALSE Invalid Authenticode Signature.
2815 @retval FALSE This interface is not supported.
2820 AuthenticodeVerify (
2821 IN CONST UINT8
*AuthData
,
2823 IN CONST UINT8
*TrustedCert
,
2825 IN CONST UINT8
*ImageHash
,
2830 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2833 If AuthData is NULL, then return FALSE.
2834 If this interface is not supported, then return FALSE.
2836 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2837 PE/COFF image to be verified.
2838 @param[in] DataSize Size of the Authenticode Signature in bytes.
2839 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2840 is used for TSA certificate chain verification.
2841 @param[in] CertSize Size of the trusted certificate in bytes.
2842 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2845 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2846 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2851 ImageTimestampVerify (
2852 IN CONST UINT8
*AuthData
,
2854 IN CONST UINT8
*TsaCert
,
2856 OUT EFI_TIME
*SigningTime
2859 //=====================================================================================
2860 // DH Key Exchange Primitive
2861 //=====================================================================================
2864 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
2866 @return Pointer to the Diffie-Hellman Context that has been initialized.
2867 If the allocations fails, DhNew() returns NULL.
2868 If the interface is not supported, DhNew() returns NULL.
2878 Release the specified DH context.
2880 If the interface is not supported, then ASSERT().
2882 @param[in] DhContext Pointer to the DH context to be released.
2892 Generates DH parameter.
2894 Given generator g, and length of prime number p in bits, this function generates p,
2895 and sets DH context according to value of g and p.
2897 Before this function can be invoked, pseudorandom number generator must be correctly
2898 initialized by RandomSeed().
2900 If DhContext is NULL, then return FALSE.
2901 If Prime is NULL, then return FALSE.
2902 If this interface is not supported, then return FALSE.
2904 @param[in, out] DhContext Pointer to the DH context.
2905 @param[in] Generator Value of generator.
2906 @param[in] PrimeLength Length in bits of prime to be generated.
2907 @param[out] Prime Pointer to the buffer to receive the generated prime number.
2909 @retval TRUE DH parameter generation succeeded.
2910 @retval FALSE Value of Generator is not supported.
2911 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
2912 @retval FALSE This interface is not supported.
2917 DhGenerateParameter (
2918 IN OUT VOID
*DhContext
,
2920 IN UINTN PrimeLength
,
2925 Sets generator and prime parameters for DH.
2927 Given generator g, and prime number p, this function and sets DH
2928 context accordingly.
2930 If DhContext is NULL, then return FALSE.
2931 If Prime is NULL, then return FALSE.
2932 If this interface is not supported, then return FALSE.
2934 @param[in, out] DhContext Pointer to the DH context.
2935 @param[in] Generator Value of generator.
2936 @param[in] PrimeLength Length in bits of prime to be generated.
2937 @param[in] Prime Pointer to the prime number.
2939 @retval TRUE DH parameter setting succeeded.
2940 @retval FALSE Value of Generator is not supported.
2941 @retval FALSE Value of Generator is not suitable for the Prime.
2942 @retval FALSE Value of Prime is not a prime number.
2943 @retval FALSE Value of Prime is not a safe prime number.
2944 @retval FALSE This interface is not supported.
2950 IN OUT VOID
*DhContext
,
2952 IN UINTN PrimeLength
,
2953 IN CONST UINT8
*Prime
2957 Generates DH public key.
2959 This function generates random secret exponent, and computes the public key, which is
2960 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
2961 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
2962 PublicKeySize is set to the required buffer size to obtain the public key.
2964 If DhContext is NULL, then return FALSE.
2965 If PublicKeySize is NULL, then return FALSE.
2966 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
2967 If this interface is not supported, then return FALSE.
2969 @param[in, out] DhContext Pointer to the DH context.
2970 @param[out] PublicKey Pointer to the buffer to receive generated public key.
2971 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
2972 On output, the size of data returned in PublicKey buffer in bytes.
2974 @retval TRUE DH public key generation succeeded.
2975 @retval FALSE DH public key generation failed.
2976 @retval FALSE PublicKeySize is not large enough.
2977 @retval FALSE This interface is not supported.
2983 IN OUT VOID
*DhContext
,
2984 OUT UINT8
*PublicKey
,
2985 IN OUT UINTN
*PublicKeySize
2989 Computes exchanged common key.
2991 Given peer's public key, this function computes the exchanged common key, based on its own
2992 context including value of prime modulus and random secret exponent.
2994 If DhContext is NULL, then return FALSE.
2995 If PeerPublicKey is NULL, then return FALSE.
2996 If KeySize is NULL, then return FALSE.
2997 If Key is NULL, then return FALSE.
2998 If KeySize is not large enough, then return FALSE.
2999 If this interface is not supported, then return FALSE.
3001 @param[in, out] DhContext Pointer to the DH context.
3002 @param[in] PeerPublicKey Pointer to the peer's public key.
3003 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
3004 @param[out] Key Pointer to the buffer to receive generated key.
3005 @param[in, out] KeySize On input, the size of Key buffer in bytes.
3006 On output, the size of data returned in Key buffer in bytes.
3008 @retval TRUE DH exchanged key generation succeeded.
3009 @retval FALSE DH exchanged key generation failed.
3010 @retval FALSE KeySize is not large enough.
3011 @retval FALSE This interface is not supported.
3017 IN OUT VOID
*DhContext
,
3018 IN CONST UINT8
*PeerPublicKey
,
3019 IN UINTN PeerPublicKeySize
,
3021 IN OUT UINTN
*KeySize
3024 //=====================================================================================
3025 // Pseudo-Random Generation Primitive
3026 //=====================================================================================
3029 Sets up the seed value for the pseudorandom number generator.
3031 This function sets up the seed value for the pseudorandom number generator.
3032 If Seed is not NULL, then the seed passed in is used.
3033 If Seed is NULL, then default seed is used.
3034 If this interface is not supported, then return FALSE.
3036 @param[in] Seed Pointer to seed value.
3037 If NULL, default seed is used.
3038 @param[in] SeedSize Size of seed value.
3039 If Seed is NULL, this parameter is ignored.
3041 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
3042 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
3043 @retval FALSE This interface is not supported.
3049 IN CONST UINT8
*Seed OPTIONAL
,
3054 Generates a pseudorandom byte stream of the specified size.
3056 If Output is NULL, then return FALSE.
3057 If this interface is not supported, then return FALSE.
3059 @param[out] Output Pointer to buffer to receive random value.
3060 @param[in] Size Size of random bytes to generate.
3062 @retval TRUE Pseudorandom byte stream generated successfully.
3063 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
3064 @retval FALSE This interface is not supported.
3074 //=====================================================================================
3075 // Key Derivation Function Primitive
3076 //=====================================================================================
3079 Derive key data using HMAC-SHA256 based KDF.
3081 @param[in] Key Pointer to the user-supplied key.
3082 @param[in] KeySize Key size in bytes.
3083 @param[in] Salt Pointer to the salt(non-secret) value.
3084 @param[in] SaltSize Salt size in bytes.
3085 @param[in] Info Pointer to the application specific info.
3086 @param[in] InfoSize Info size in bytes.
3087 @param[out] Out Pointer to buffer to receive hkdf value.
3088 @param[in] OutSize Size of hkdf bytes to generate.
3090 @retval TRUE Hkdf generated successfully.
3091 @retval FALSE Hkdf generation failed.
3096 HkdfSha256ExtractAndExpand (
3097 IN CONST UINT8
*Key
,
3099 IN CONST UINT8
*Salt
,
3101 IN CONST UINT8
*Info
,
3107 #endif // __BASE_CRYPT_LIB_H__