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 /// MD5 digest size in bytes
20 #define MD5_DIGEST_SIZE 16
23 /// SHA-1 digest size in bytes.
25 #define SHA1_DIGEST_SIZE 20
28 /// SHA-256 digest size in bytes
30 #define SHA256_DIGEST_SIZE 32
33 /// SHA-384 digest size in bytes
35 #define SHA384_DIGEST_SIZE 48
38 /// SHA-512 digest size in bytes
40 #define SHA512_DIGEST_SIZE 64
43 /// SM3 digest size in bytes
45 #define SM3_256_DIGEST_SIZE 32
48 /// TDES block size in bytes
50 #define TDES_BLOCK_SIZE 8
53 /// AES block size in bytes
55 #define AES_BLOCK_SIZE 16
58 /// RSA Key Tags Definition used in RsaSetKey() function for key component identification.
61 RsaKeyN
, ///< RSA public Modulus (N)
62 RsaKeyE
, ///< RSA Public exponent (e)
63 RsaKeyD
, ///< RSA Private exponent (d)
64 RsaKeyP
, ///< RSA secret prime factor of Modulus (p)
65 RsaKeyQ
, ///< RSA secret prime factor of Modules (q)
66 RsaKeyDp
, ///< p's CRT exponent (== d mod (p - 1))
67 RsaKeyDq
, ///< q's CRT exponent (== d mod (q - 1))
68 RsaKeyQInv
///< The CRT coefficient (== 1/q mod p)
71 //=====================================================================================
72 // One-Way Cryptographic Hash Primitives
73 //=====================================================================================
76 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.
78 If this interface is not supported, then return zero.
80 @return The size, in bytes, of the context buffer required for MD5 hash operations.
81 @retval 0 This interface is not supported.
91 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for
94 If Md5Context is NULL, then return FALSE.
95 If this interface is not supported, then return FALSE.
97 @param[out] Md5Context Pointer to MD5 context being initialized.
99 @retval TRUE MD5 context initialization succeeded.
100 @retval FALSE MD5 context initialization failed.
101 @retval FALSE This interface is not supported.
111 Makes a copy of an existing MD5 context.
113 If Md5Context is NULL, then return FALSE.
114 If NewMd5Context is NULL, then return FALSE.
115 If this interface is not supported, then return FALSE.
117 @param[in] Md5Context Pointer to MD5 context being copied.
118 @param[out] NewMd5Context Pointer to new MD5 context.
120 @retval TRUE MD5 context copy succeeded.
121 @retval FALSE MD5 context copy failed.
122 @retval FALSE This interface is not supported.
128 IN CONST VOID
*Md5Context
,
129 OUT VOID
*NewMd5Context
133 Digests the input data and updates MD5 context.
135 This function performs MD5 digest on a data buffer of the specified size.
136 It can be called multiple times to compute the digest of long or discontinuous data streams.
137 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized
138 by Md5Final(). Behavior with invalid context is undefined.
140 If Md5Context is NULL, then return FALSE.
141 If this interface is not supported, then return FALSE.
143 @param[in, out] Md5Context Pointer to the MD5 context.
144 @param[in] Data Pointer to the buffer containing the data to be hashed.
145 @param[in] DataSize Size of Data buffer in bytes.
147 @retval TRUE MD5 data digest succeeded.
148 @retval FALSE MD5 data digest failed.
149 @retval FALSE This interface is not supported.
155 IN OUT VOID
*Md5Context
,
161 Completes computation of the MD5 digest value.
163 This function completes MD5 hash computation and retrieves the digest value into
164 the specified memory. After this function has been called, the MD5 context cannot
166 MD5 context should be already correctly initialized by Md5Init(), and should not be
167 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.
169 If Md5Context is NULL, then return FALSE.
170 If HashValue is NULL, then return FALSE.
171 If this interface is not supported, then return FALSE.
173 @param[in, out] Md5Context Pointer to the MD5 context.
174 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
177 @retval TRUE MD5 digest computation succeeded.
178 @retval FALSE MD5 digest computation failed.
179 @retval FALSE This interface is not supported.
185 IN OUT VOID
*Md5Context
,
190 Computes the MD5 message digest of a input data buffer.
192 This function performs the MD5 message digest of a given data buffer, and places
193 the digest value into the specified memory.
195 If this interface is not supported, then return FALSE.
197 @param[in] Data Pointer to the buffer containing the data to be hashed.
198 @param[in] DataSize Size of Data buffer in bytes.
199 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
202 @retval TRUE MD5 digest computation succeeded.
203 @retval FALSE MD5 digest computation failed.
204 @retval FALSE This interface is not supported.
216 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.
218 If this interface is not supported, then return zero.
220 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.
221 @retval 0 This interface is not supported.
231 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for
234 If Sha1Context is NULL, then return FALSE.
235 If this interface is not supported, then return FALSE.
237 @param[out] Sha1Context Pointer to SHA-1 context being initialized.
239 @retval TRUE SHA-1 context initialization succeeded.
240 @retval FALSE SHA-1 context initialization failed.
241 @retval FALSE This interface is not supported.
247 OUT VOID
*Sha1Context
251 Makes a copy of an existing SHA-1 context.
253 If Sha1Context is NULL, then return FALSE.
254 If NewSha1Context is NULL, then return FALSE.
255 If this interface is not supported, then return FALSE.
257 @param[in] Sha1Context Pointer to SHA-1 context being copied.
258 @param[out] NewSha1Context Pointer to new SHA-1 context.
260 @retval TRUE SHA-1 context copy succeeded.
261 @retval FALSE SHA-1 context copy failed.
262 @retval FALSE This interface is not supported.
268 IN CONST VOID
*Sha1Context
,
269 OUT VOID
*NewSha1Context
273 Digests the input data and updates SHA-1 context.
275 This function performs SHA-1 digest on a data buffer of the specified size.
276 It can be called multiple times to compute the digest of long or discontinuous data streams.
277 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized
278 by Sha1Final(). Behavior with invalid context is undefined.
280 If Sha1Context is NULL, then return FALSE.
281 If this interface is not supported, then return FALSE.
283 @param[in, out] Sha1Context Pointer to the SHA-1 context.
284 @param[in] Data Pointer to the buffer containing the data to be hashed.
285 @param[in] DataSize Size of Data buffer in bytes.
287 @retval TRUE SHA-1 data digest succeeded.
288 @retval FALSE SHA-1 data digest failed.
289 @retval FALSE This interface is not supported.
295 IN OUT VOID
*Sha1Context
,
301 Completes computation of the SHA-1 digest value.
303 This function completes SHA-1 hash computation and retrieves the digest value into
304 the specified memory. After this function has been called, the SHA-1 context cannot
306 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be
307 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.
309 If Sha1Context is NULL, then return FALSE.
310 If HashValue is NULL, then return FALSE.
311 If this interface is not supported, then return FALSE.
313 @param[in, out] Sha1Context Pointer to the SHA-1 context.
314 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
317 @retval TRUE SHA-1 digest computation succeeded.
318 @retval FALSE SHA-1 digest computation failed.
319 @retval FALSE This interface is not supported.
325 IN OUT VOID
*Sha1Context
,
330 Computes the SHA-1 message digest of a input data buffer.
332 This function performs the SHA-1 message digest of a given data buffer, and places
333 the digest value into the specified memory.
335 If this interface is not supported, then return FALSE.
337 @param[in] Data Pointer to the buffer containing the data to be hashed.
338 @param[in] DataSize Size of Data buffer in bytes.
339 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
342 @retval TRUE SHA-1 digest computation succeeded.
343 @retval FALSE SHA-1 digest computation failed.
344 @retval FALSE This interface is not supported.
356 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.
358 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.
363 Sha256GetContextSize (
368 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for
371 If Sha256Context is NULL, then return FALSE.
373 @param[out] Sha256Context Pointer to SHA-256 context being initialized.
375 @retval TRUE SHA-256 context initialization succeeded.
376 @retval FALSE SHA-256 context initialization failed.
382 OUT VOID
*Sha256Context
386 Makes a copy of an existing SHA-256 context.
388 If Sha256Context is NULL, then return FALSE.
389 If NewSha256Context is NULL, then return FALSE.
390 If this interface is not supported, then return FALSE.
392 @param[in] Sha256Context Pointer to SHA-256 context being copied.
393 @param[out] NewSha256Context Pointer to new SHA-256 context.
395 @retval TRUE SHA-256 context copy succeeded.
396 @retval FALSE SHA-256 context copy failed.
397 @retval FALSE This interface is not supported.
403 IN CONST VOID
*Sha256Context
,
404 OUT VOID
*NewSha256Context
408 Digests the input data and updates SHA-256 context.
410 This function performs SHA-256 digest on a data buffer of the specified size.
411 It can be called multiple times to compute the digest of long or discontinuous data streams.
412 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized
413 by Sha256Final(). Behavior with invalid context is undefined.
415 If Sha256Context is NULL, then return FALSE.
417 @param[in, out] Sha256Context Pointer to the SHA-256 context.
418 @param[in] Data Pointer to the buffer containing the data to be hashed.
419 @param[in] DataSize Size of Data buffer in bytes.
421 @retval TRUE SHA-256 data digest succeeded.
422 @retval FALSE SHA-256 data digest failed.
428 IN OUT VOID
*Sha256Context
,
434 Completes computation of the SHA-256 digest value.
436 This function completes SHA-256 hash computation and retrieves the digest value into
437 the specified memory. After this function has been called, the SHA-256 context cannot
439 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be
440 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.
442 If Sha256Context is NULL, then return FALSE.
443 If HashValue is NULL, then return FALSE.
445 @param[in, out] Sha256Context Pointer to the SHA-256 context.
446 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
449 @retval TRUE SHA-256 digest computation succeeded.
450 @retval FALSE SHA-256 digest computation failed.
456 IN OUT VOID
*Sha256Context
,
461 Computes the SHA-256 message digest of a input data buffer.
463 This function performs the SHA-256 message digest of a given data buffer, and places
464 the digest value into the specified memory.
466 If this interface is not supported, then return FALSE.
468 @param[in] Data Pointer to the buffer containing the data to be hashed.
469 @param[in] DataSize Size of Data buffer in bytes.
470 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
473 @retval TRUE SHA-256 digest computation succeeded.
474 @retval FALSE SHA-256 digest computation failed.
475 @retval FALSE This interface is not supported.
487 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.
489 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.
494 Sha384GetContextSize (
499 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for
502 If Sha384Context is NULL, then return FALSE.
504 @param[out] Sha384Context Pointer to SHA-384 context being initialized.
506 @retval TRUE SHA-384 context initialization succeeded.
507 @retval FALSE SHA-384 context initialization failed.
513 OUT VOID
*Sha384Context
517 Makes a copy of an existing SHA-384 context.
519 If Sha384Context is NULL, then return FALSE.
520 If NewSha384Context is NULL, then return FALSE.
521 If this interface is not supported, then return FALSE.
523 @param[in] Sha384Context Pointer to SHA-384 context being copied.
524 @param[out] NewSha384Context Pointer to new SHA-384 context.
526 @retval TRUE SHA-384 context copy succeeded.
527 @retval FALSE SHA-384 context copy failed.
528 @retval FALSE This interface is not supported.
534 IN CONST VOID
*Sha384Context
,
535 OUT VOID
*NewSha384Context
539 Digests the input data and updates SHA-384 context.
541 This function performs SHA-384 digest on a data buffer of the specified size.
542 It can be called multiple times to compute the digest of long or discontinuous data streams.
543 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized
544 by Sha384Final(). Behavior with invalid context is undefined.
546 If Sha384Context is NULL, then return FALSE.
548 @param[in, out] Sha384Context Pointer to the SHA-384 context.
549 @param[in] Data Pointer to the buffer containing the data to be hashed.
550 @param[in] DataSize Size of Data buffer in bytes.
552 @retval TRUE SHA-384 data digest succeeded.
553 @retval FALSE SHA-384 data digest failed.
559 IN OUT VOID
*Sha384Context
,
565 Completes computation of the SHA-384 digest value.
567 This function completes SHA-384 hash computation and retrieves the digest value into
568 the specified memory. After this function has been called, the SHA-384 context cannot
570 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be
571 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.
573 If Sha384Context is NULL, then return FALSE.
574 If HashValue is NULL, then return FALSE.
576 @param[in, out] Sha384Context Pointer to the SHA-384 context.
577 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
580 @retval TRUE SHA-384 digest computation succeeded.
581 @retval FALSE SHA-384 digest computation failed.
587 IN OUT VOID
*Sha384Context
,
592 Computes the SHA-384 message digest of a input data buffer.
594 This function performs the SHA-384 message digest of a given data buffer, and places
595 the digest value into the specified memory.
597 If this interface is not supported, then return FALSE.
599 @param[in] Data Pointer to the buffer containing the data to be hashed.
600 @param[in] DataSize Size of Data buffer in bytes.
601 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
604 @retval TRUE SHA-384 digest computation succeeded.
605 @retval FALSE SHA-384 digest computation failed.
606 @retval FALSE This interface is not supported.
618 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.
620 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.
625 Sha512GetContextSize (
630 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for
633 If Sha512Context is NULL, then return FALSE.
635 @param[out] Sha512Context Pointer to SHA-512 context being initialized.
637 @retval TRUE SHA-512 context initialization succeeded.
638 @retval FALSE SHA-512 context initialization failed.
644 OUT VOID
*Sha512Context
648 Makes a copy of an existing SHA-512 context.
650 If Sha512Context is NULL, then return FALSE.
651 If NewSha512Context is NULL, then return FALSE.
652 If this interface is not supported, then return FALSE.
654 @param[in] Sha512Context Pointer to SHA-512 context being copied.
655 @param[out] NewSha512Context Pointer to new SHA-512 context.
657 @retval TRUE SHA-512 context copy succeeded.
658 @retval FALSE SHA-512 context copy failed.
659 @retval FALSE This interface is not supported.
665 IN CONST VOID
*Sha512Context
,
666 OUT VOID
*NewSha512Context
670 Digests the input data and updates SHA-512 context.
672 This function performs SHA-512 digest on a data buffer of the specified size.
673 It can be called multiple times to compute the digest of long or discontinuous data streams.
674 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized
675 by Sha512Final(). Behavior with invalid context is undefined.
677 If Sha512Context is NULL, then return FALSE.
679 @param[in, out] Sha512Context Pointer to the SHA-512 context.
680 @param[in] Data Pointer to the buffer containing the data to be hashed.
681 @param[in] DataSize Size of Data buffer in bytes.
683 @retval TRUE SHA-512 data digest succeeded.
684 @retval FALSE SHA-512 data digest failed.
690 IN OUT VOID
*Sha512Context
,
696 Completes computation of the SHA-512 digest value.
698 This function completes SHA-512 hash computation and retrieves the digest value into
699 the specified memory. After this function has been called, the SHA-512 context cannot
701 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be
702 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.
704 If Sha512Context is NULL, then return FALSE.
705 If HashValue is NULL, then return FALSE.
707 @param[in, out] Sha512Context Pointer to the SHA-512 context.
708 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
711 @retval TRUE SHA-512 digest computation succeeded.
712 @retval FALSE SHA-512 digest computation failed.
718 IN OUT VOID
*Sha512Context
,
723 Computes the SHA-512 message digest of a input data buffer.
725 This function performs the SHA-512 message digest of a given data buffer, and places
726 the digest value into the specified memory.
728 If this interface is not supported, then return FALSE.
730 @param[in] Data Pointer to the buffer containing the data to be hashed.
731 @param[in] DataSize Size of Data buffer in bytes.
732 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
735 @retval TRUE SHA-512 digest computation succeeded.
736 @retval FALSE SHA-512 digest computation failed.
737 @retval FALSE This interface is not supported.
749 Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.
751 @return The size, in bytes, of the context buffer required for SM3 hash operations.
761 Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for
764 If Sm3Context is NULL, then return FALSE.
766 @param[out] Sm3Context Pointer to SM3 context being initialized.
768 @retval TRUE SM3 context initialization succeeded.
769 @retval FALSE SM3 context initialization failed.
779 Makes a copy of an existing SM3 context.
781 If Sm3Context is NULL, then return FALSE.
782 If NewSm3Context is NULL, then return FALSE.
783 If this interface is not supported, then return FALSE.
785 @param[in] Sm3Context Pointer to SM3 context being copied.
786 @param[out] NewSm3Context Pointer to new SM3 context.
788 @retval TRUE SM3 context copy succeeded.
789 @retval FALSE SM3 context copy failed.
790 @retval FALSE This interface is not supported.
796 IN CONST VOID
*Sm3Context
,
797 OUT VOID
*NewSm3Context
801 Digests the input data and updates SM3 context.
803 This function performs SM3 digest on a data buffer of the specified size.
804 It can be called multiple times to compute the digest of long or discontinuous data streams.
805 SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized
806 by Sm3Final(). Behavior with invalid context is undefined.
808 If Sm3Context is NULL, then return FALSE.
810 @param[in, out] Sm3Context Pointer to the SM3 context.
811 @param[in] Data Pointer to the buffer containing the data to be hashed.
812 @param[in] DataSize Size of Data buffer in bytes.
814 @retval TRUE SM3 data digest succeeded.
815 @retval FALSE SM3 data digest failed.
821 IN OUT VOID
*Sm3Context
,
827 Completes computation of the SM3 digest value.
829 This function completes SM3 hash computation and retrieves the digest value into
830 the specified memory. After this function has been called, the SM3 context cannot
832 SM3 context should be already correctly initialized by Sm3Init(), and should not be
833 finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.
835 If Sm3Context is NULL, then return FALSE.
836 If HashValue is NULL, then return FALSE.
838 @param[in, out] Sm3Context Pointer to the SM3 context.
839 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
842 @retval TRUE SM3 digest computation succeeded.
843 @retval FALSE SM3 digest computation failed.
849 IN OUT VOID
*Sm3Context
,
854 Computes the SM3 message digest of a input data buffer.
856 This function performs the SM3 message digest of a given data buffer, and places
857 the digest value into the specified memory.
859 If this interface is not supported, then return FALSE.
861 @param[in] Data Pointer to the buffer containing the data to be hashed.
862 @param[in] DataSize Size of Data buffer in bytes.
863 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
866 @retval TRUE SM3 digest computation succeeded.
867 @retval FALSE SM3 digest computation failed.
868 @retval FALSE This interface is not supported.
879 //=====================================================================================
880 // MAC (Message Authentication Code) Primitive
881 //=====================================================================================
884 Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD5 use.
886 If this interface is not supported, then return NULL.
888 @return Pointer to the HMAC_CTX context that has been initialized.
889 If the allocations fails, HmacMd5New() returns NULL.
890 @retval NULL This interface is not supported.
900 Release the specified HMAC_CTX context.
902 If this interface is not supported, then do nothing.
904 @param[in] HmacMd5Ctx Pointer to the HMAC_CTX context to be released.
914 Set user-supplied key for subsequent use. It must be done before any
915 calling to HmacMd5Update().
917 If HmacMd5Context is NULL, then return FALSE.
918 If this interface is not supported, then return FALSE.
920 @param[out] HmacMd5Context Pointer to HMAC-MD5 context.
921 @param[in] Key Pointer to the user-supplied key.
922 @param[in] KeySize Key size in bytes.
924 @retval TRUE Key is set successfully.
925 @retval FALSE Key is set unsuccessfully.
926 @retval FALSE This interface is not supported.
932 OUT VOID
*HmacMd5Context
,
938 Makes a copy of an existing HMAC-MD5 context.
940 If HmacMd5Context is NULL, then return FALSE.
941 If NewHmacMd5Context is NULL, then return FALSE.
942 If this interface is not supported, then return FALSE.
944 @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied.
945 @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context.
947 @retval TRUE HMAC-MD5 context copy succeeded.
948 @retval FALSE HMAC-MD5 context copy failed.
949 @retval FALSE This interface is not supported.
955 IN CONST VOID
*HmacMd5Context
,
956 OUT VOID
*NewHmacMd5Context
960 Digests the input data and updates HMAC-MD5 context.
962 This function performs HMAC-MD5 digest on a data buffer of the specified size.
963 It can be called multiple times to compute the digest of long or discontinuous data streams.
964 HMAC-MD5 context should be initialized by HmacMd5New(), and should not be finalized by
965 HmacMd5Final(). Behavior with invalid context is undefined.
967 If HmacMd5Context is NULL, then return FALSE.
968 If this interface is not supported, then return FALSE.
970 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
971 @param[in] Data Pointer to the buffer containing the data to be digested.
972 @param[in] DataSize Size of Data buffer in bytes.
974 @retval TRUE HMAC-MD5 data digest succeeded.
975 @retval FALSE HMAC-MD5 data digest failed.
976 @retval FALSE This interface is not supported.
982 IN OUT VOID
*HmacMd5Context
,
988 Completes computation of the HMAC-MD5 digest value.
990 This function completes HMAC-MD5 hash computation and retrieves the digest value into
991 the specified memory. After this function has been called, the HMAC-MD5 context cannot
993 HMAC-MD5 context should be initialized by HmacMd5New(), and should not be finalized by
994 HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined.
996 If HmacMd5Context is NULL, then return FALSE.
997 If HmacValue is NULL, then return FALSE.
998 If this interface is not supported, then return FALSE.
1000 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
1001 @param[out] HmacValue Pointer to a buffer that receives the HMAC-MD5 digest
1004 @retval TRUE HMAC-MD5 digest computation succeeded.
1005 @retval FALSE HMAC-MD5 digest computation failed.
1006 @retval FALSE This interface is not supported.
1012 IN OUT VOID
*HmacMd5Context
,
1013 OUT UINT8
*HmacValue
1017 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA1 use.
1019 If this interface is not supported, then return NULL.
1021 @return Pointer to the HMAC_CTX context that has been initialized.
1022 If the allocations fails, HmacSha1New() returns NULL.
1023 @return NULL This interface is not supported.
1033 Release the specified HMAC_CTX context.
1035 If this interface is not supported, then do nothing.
1037 @param[in] HmacSha1Ctx Pointer to the HMAC_CTX context to be released.
1043 IN VOID
*HmacSha1Ctx
1047 Set user-supplied key for subsequent use. It must be done before any
1048 calling to HmacSha1Update().
1050 If HmacSha1Context is NULL, then return FALSE.
1051 If this interface is not supported, then return FALSE.
1053 @param[out] HmacSha1Context Pointer to HMAC-SHA1 context.
1054 @param[in] Key Pointer to the user-supplied key.
1055 @param[in] KeySize Key size in bytes.
1057 @retval TRUE The Key is set successfully.
1058 @retval FALSE The Key is set unsuccessfully.
1059 @retval FALSE This interface is not supported.
1065 OUT VOID
*HmacSha1Context
,
1066 IN CONST UINT8
*Key
,
1071 Makes a copy of an existing HMAC-SHA1 context.
1073 If HmacSha1Context is NULL, then return FALSE.
1074 If NewHmacSha1Context is NULL, then return FALSE.
1075 If this interface is not supported, then return FALSE.
1077 @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied.
1078 @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context.
1080 @retval TRUE HMAC-SHA1 context copy succeeded.
1081 @retval FALSE HMAC-SHA1 context copy failed.
1082 @retval FALSE This interface is not supported.
1088 IN CONST VOID
*HmacSha1Context
,
1089 OUT VOID
*NewHmacSha1Context
1093 Digests the input data and updates HMAC-SHA1 context.
1095 This function performs HMAC-SHA1 digest on a data buffer of the specified size.
1096 It can be called multiple times to compute the digest of long or discontinuous data streams.
1097 HMAC-SHA1 context should be initialized by HmacSha1New(), and should not be finalized by
1098 HmacSha1Final(). Behavior with invalid context is undefined.
1100 If HmacSha1Context is NULL, then return FALSE.
1101 If this interface is not supported, then return FALSE.
1103 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1104 @param[in] Data Pointer to the buffer containing the data to be digested.
1105 @param[in] DataSize Size of Data buffer in bytes.
1107 @retval TRUE HMAC-SHA1 data digest succeeded.
1108 @retval FALSE HMAC-SHA1 data digest failed.
1109 @retval FALSE This interface is not supported.
1115 IN OUT VOID
*HmacSha1Context
,
1116 IN CONST VOID
*Data
,
1121 Completes computation of the HMAC-SHA1 digest value.
1123 This function completes HMAC-SHA1 hash computation and retrieves the digest value into
1124 the specified memory. After this function has been called, the HMAC-SHA1 context cannot
1126 HMAC-SHA1 context should be initialized by HmacSha1New(), and should not be finalized
1127 by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined.
1129 If HmacSha1Context is NULL, then return FALSE.
1130 If HmacValue is NULL, then return FALSE.
1131 If this interface is not supported, then return FALSE.
1133 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1134 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA1 digest
1137 @retval TRUE HMAC-SHA1 digest computation succeeded.
1138 @retval FALSE HMAC-SHA1 digest computation failed.
1139 @retval FALSE This interface is not supported.
1145 IN OUT VOID
*HmacSha1Context
,
1146 OUT UINT8
*HmacValue
1150 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
1152 @return Pointer to the HMAC_CTX context that has been initialized.
1153 If the allocations fails, HmacSha256New() returns NULL.
1163 Release the specified HMAC_CTX context.
1165 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.
1171 IN VOID
*HmacSha256Ctx
1175 Set user-supplied key for subsequent use. It must be done before any
1176 calling to HmacSha256Update().
1178 If HmacSha256Context is NULL, then return FALSE.
1179 If this interface is not supported, then return FALSE.
1181 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.
1182 @param[in] Key Pointer to the user-supplied key.
1183 @param[in] KeySize Key size in bytes.
1185 @retval TRUE The Key is set successfully.
1186 @retval FALSE The Key is set unsuccessfully.
1187 @retval FALSE This interface is not supported.
1193 OUT VOID
*HmacSha256Context
,
1194 IN CONST UINT8
*Key
,
1199 Makes a copy of an existing HMAC-SHA256 context.
1201 If HmacSha256Context is NULL, then return FALSE.
1202 If NewHmacSha256Context is NULL, then return FALSE.
1203 If this interface is not supported, then return FALSE.
1205 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.
1206 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.
1208 @retval TRUE HMAC-SHA256 context copy succeeded.
1209 @retval FALSE HMAC-SHA256 context copy failed.
1210 @retval FALSE This interface is not supported.
1215 HmacSha256Duplicate (
1216 IN CONST VOID
*HmacSha256Context
,
1217 OUT VOID
*NewHmacSha256Context
1221 Digests the input data and updates HMAC-SHA256 context.
1223 This function performs HMAC-SHA256 digest on a data buffer of the specified size.
1224 It can be called multiple times to compute the digest of long or discontinuous data streams.
1225 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1226 by HmacSha256Final(). Behavior with invalid context is undefined.
1228 If HmacSha256Context is NULL, then return FALSE.
1229 If this interface is not supported, then return FALSE.
1231 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1232 @param[in] Data Pointer to the buffer containing the data to be digested.
1233 @param[in] DataSize Size of Data buffer in bytes.
1235 @retval TRUE HMAC-SHA256 data digest succeeded.
1236 @retval FALSE HMAC-SHA256 data digest failed.
1237 @retval FALSE This interface is not supported.
1243 IN OUT VOID
*HmacSha256Context
,
1244 IN CONST VOID
*Data
,
1249 Completes computation of the HMAC-SHA256 digest value.
1251 This function completes HMAC-SHA256 hash computation and retrieves the digest value into
1252 the specified memory. After this function has been called, the HMAC-SHA256 context cannot
1254 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1255 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.
1257 If HmacSha256Context is NULL, then return FALSE.
1258 If HmacValue is NULL, then return FALSE.
1259 If this interface is not supported, then return FALSE.
1261 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1262 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
1265 @retval TRUE HMAC-SHA256 digest computation succeeded.
1266 @retval FALSE HMAC-SHA256 digest computation failed.
1267 @retval FALSE This interface is not supported.
1273 IN OUT VOID
*HmacSha256Context
,
1274 OUT UINT8
*HmacValue
1277 //=====================================================================================
1278 // Symmetric Cryptography Primitive
1279 //=====================================================================================
1282 Retrieves the size, in bytes, of the context buffer required for TDES operations.
1284 If this interface is not supported, then return zero.
1286 @return The size, in bytes, of the context buffer required for TDES operations.
1287 @retval 0 This interface is not supported.
1292 TdesGetContextSize (
1297 Initializes user-supplied memory as TDES context for subsequent use.
1299 This function initializes user-supplied memory pointed by TdesContext as TDES context.
1300 In addition, it sets up all TDES key materials for subsequent encryption and decryption
1302 There are 3 key options as follows:
1303 KeyLength = 64, Keying option 1: K1 == K2 == K3 (Backward compatibility with DES)
1304 KeyLength = 128, Keying option 2: K1 != K2 and K3 = K1 (Less Security)
1305 KeyLength = 192 Keying option 3: K1 != K2 != K3 (Strongest)
1307 If TdesContext is NULL, then return FALSE.
1308 If Key is NULL, then return FALSE.
1309 If KeyLength is not valid, then return FALSE.
1310 If this interface is not supported, then return FALSE.
1312 @param[out] TdesContext Pointer to TDES context being initialized.
1313 @param[in] Key Pointer to the user-supplied TDES key.
1314 @param[in] KeyLength Length of TDES key in bits.
1316 @retval TRUE TDES context initialization succeeded.
1317 @retval FALSE TDES context initialization failed.
1318 @retval FALSE This interface is not supported.
1324 OUT VOID
*TdesContext
,
1325 IN CONST UINT8
*Key
,
1330 Performs TDES encryption on a data buffer of the specified size in ECB mode.
1332 This function performs TDES encryption on data buffer pointed by Input, of specified
1333 size of InputSize, in ECB mode.
1334 InputSize must be multiple of block size (8 bytes). This function does not perform
1335 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1336 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1337 invalid TDES context is undefined.
1339 If TdesContext is NULL, then return FALSE.
1340 If Input is NULL, then return FALSE.
1341 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1342 If Output is NULL, then return FALSE.
1343 If this interface is not supported, then return FALSE.
1345 @param[in] TdesContext Pointer to the TDES context.
1346 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1347 @param[in] InputSize Size of the Input buffer in bytes.
1348 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1350 @retval TRUE TDES encryption succeeded.
1351 @retval FALSE TDES encryption failed.
1352 @retval FALSE This interface is not supported.
1358 IN VOID
*TdesContext
,
1359 IN CONST UINT8
*Input
,
1365 Performs TDES decryption on a data buffer of the specified size in ECB mode.
1367 This function performs TDES decryption on data buffer pointed by Input, of specified
1368 size of InputSize, in ECB mode.
1369 InputSize must be multiple of block size (8 bytes). This function does not perform
1370 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1371 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1372 invalid TDES context is undefined.
1374 If TdesContext is NULL, then return FALSE.
1375 If Input is NULL, then return FALSE.
1376 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1377 If Output is NULL, then return FALSE.
1378 If this interface is not supported, then return FALSE.
1380 @param[in] TdesContext Pointer to the TDES context.
1381 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1382 @param[in] InputSize Size of the Input buffer in bytes.
1383 @param[out] Output Pointer to a buffer that receives the TDES decryption output.
1385 @retval TRUE TDES decryption succeeded.
1386 @retval FALSE TDES decryption failed.
1387 @retval FALSE This interface is not supported.
1393 IN VOID
*TdesContext
,
1394 IN CONST UINT8
*Input
,
1400 Performs TDES encryption on a data buffer of the specified size in CBC mode.
1402 This function performs TDES encryption on data buffer pointed by Input, of specified
1403 size of InputSize, in CBC mode.
1404 InputSize must be multiple of block size (8 bytes). This function does not perform
1405 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1406 Initialization vector should be one block size (8 bytes).
1407 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1408 invalid TDES context is undefined.
1410 If TdesContext is NULL, then return FALSE.
1411 If Input is NULL, then return FALSE.
1412 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1413 If Ivec is NULL, then return FALSE.
1414 If Output is NULL, then return FALSE.
1415 If this interface is not supported, then return FALSE.
1417 @param[in] TdesContext Pointer to the TDES context.
1418 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1419 @param[in] InputSize Size of the Input buffer in bytes.
1420 @param[in] Ivec Pointer to initialization vector.
1421 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1423 @retval TRUE TDES encryption succeeded.
1424 @retval FALSE TDES encryption failed.
1425 @retval FALSE This interface is not supported.
1431 IN VOID
*TdesContext
,
1432 IN CONST UINT8
*Input
,
1434 IN CONST UINT8
*Ivec
,
1439 Performs TDES decryption on a data buffer of the specified size in CBC mode.
1441 This function performs TDES decryption on data buffer pointed by Input, of specified
1442 size of InputSize, in CBC mode.
1443 InputSize must be multiple of block size (8 bytes). This function does not perform
1444 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1445 Initialization vector should be one block size (8 bytes).
1446 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1447 invalid TDES context is undefined.
1449 If TdesContext is NULL, then return FALSE.
1450 If Input is NULL, then return FALSE.
1451 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1452 If Ivec is NULL, then return FALSE.
1453 If Output is NULL, then return FALSE.
1454 If this interface is not supported, then return FALSE.
1456 @param[in] TdesContext Pointer to the TDES context.
1457 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1458 @param[in] InputSize Size of the Input buffer in bytes.
1459 @param[in] Ivec Pointer to initialization vector.
1460 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1462 @retval TRUE TDES decryption succeeded.
1463 @retval FALSE TDES decryption failed.
1464 @retval FALSE This interface is not supported.
1470 IN VOID
*TdesContext
,
1471 IN CONST UINT8
*Input
,
1473 IN CONST UINT8
*Ivec
,
1478 Retrieves the size, in bytes, of the context buffer required for AES operations.
1480 If this interface is not supported, then return zero.
1482 @return The size, in bytes, of the context buffer required for AES operations.
1483 @retval 0 This interface is not supported.
1493 Initializes user-supplied memory as AES context for subsequent use.
1495 This function initializes user-supplied memory pointed by AesContext as AES context.
1496 In addition, it sets up all AES key materials for subsequent encryption and decryption
1498 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1500 If AesContext is NULL, then return FALSE.
1501 If Key is NULL, then return FALSE.
1502 If KeyLength is not valid, then return FALSE.
1503 If this interface is not supported, then return FALSE.
1505 @param[out] AesContext Pointer to AES context being initialized.
1506 @param[in] Key Pointer to the user-supplied AES key.
1507 @param[in] KeyLength Length of AES key in bits.
1509 @retval TRUE AES context initialization succeeded.
1510 @retval FALSE AES context initialization failed.
1511 @retval FALSE This interface is not supported.
1517 OUT VOID
*AesContext
,
1518 IN CONST UINT8
*Key
,
1523 Performs AES encryption on a data buffer of the specified size in ECB mode.
1525 This function performs AES encryption on data buffer pointed by Input, of specified
1526 size of InputSize, in ECB mode.
1527 InputSize must be multiple of block size (16 bytes). This function does not perform
1528 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1529 AesContext should be already correctly initialized by AesInit(). Behavior with
1530 invalid AES context is undefined.
1532 If AesContext is NULL, then return FALSE.
1533 If Input is NULL, then return FALSE.
1534 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1535 If Output is NULL, then return FALSE.
1536 If this interface is not supported, then return FALSE.
1538 @param[in] AesContext Pointer to the AES context.
1539 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1540 @param[in] InputSize Size of the Input buffer in bytes.
1541 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1543 @retval TRUE AES encryption succeeded.
1544 @retval FALSE AES encryption failed.
1545 @retval FALSE This interface is not supported.
1551 IN VOID
*AesContext
,
1552 IN CONST UINT8
*Input
,
1558 Performs AES decryption on a data buffer of the specified size in ECB mode.
1560 This function performs AES decryption on data buffer pointed by Input, of specified
1561 size of InputSize, in ECB mode.
1562 InputSize must be multiple of block size (16 bytes). This function does not perform
1563 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1564 AesContext should be already correctly initialized by AesInit(). Behavior with
1565 invalid AES context is undefined.
1567 If AesContext is NULL, then return FALSE.
1568 If Input is NULL, then return FALSE.
1569 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1570 If Output is NULL, then return FALSE.
1571 If this interface is not supported, then return FALSE.
1573 @param[in] AesContext Pointer to the AES context.
1574 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1575 @param[in] InputSize Size of the Input buffer in bytes.
1576 @param[out] Output Pointer to a buffer that receives the AES decryption output.
1578 @retval TRUE AES decryption succeeded.
1579 @retval FALSE AES decryption failed.
1580 @retval FALSE This interface is not supported.
1586 IN VOID
*AesContext
,
1587 IN CONST UINT8
*Input
,
1593 Performs AES encryption on a data buffer of the specified size in CBC mode.
1595 This function performs AES encryption on data buffer pointed by Input, of specified
1596 size of InputSize, in CBC mode.
1597 InputSize must be multiple of block size (16 bytes). This function does not perform
1598 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1599 Initialization vector should be one block size (16 bytes).
1600 AesContext should be already correctly initialized by AesInit(). Behavior with
1601 invalid AES context is undefined.
1603 If AesContext is NULL, then return FALSE.
1604 If Input is NULL, then return FALSE.
1605 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1606 If Ivec is NULL, then return FALSE.
1607 If Output is NULL, then return FALSE.
1608 If this interface is not supported, then return FALSE.
1610 @param[in] AesContext Pointer to the AES context.
1611 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1612 @param[in] InputSize Size of the Input buffer in bytes.
1613 @param[in] Ivec Pointer to initialization vector.
1614 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1616 @retval TRUE AES encryption succeeded.
1617 @retval FALSE AES encryption failed.
1618 @retval FALSE This interface is not supported.
1624 IN VOID
*AesContext
,
1625 IN CONST UINT8
*Input
,
1627 IN CONST UINT8
*Ivec
,
1632 Performs AES decryption on a data buffer of the specified size in CBC mode.
1634 This function performs AES decryption on data buffer pointed by Input, of specified
1635 size of InputSize, in CBC mode.
1636 InputSize must be multiple of block size (16 bytes). This function does not perform
1637 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1638 Initialization vector should be one block size (16 bytes).
1639 AesContext should be already correctly initialized by AesInit(). Behavior with
1640 invalid AES context is undefined.
1642 If AesContext is NULL, then return FALSE.
1643 If Input is NULL, then return FALSE.
1644 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1645 If Ivec is NULL, then return FALSE.
1646 If Output is NULL, then return FALSE.
1647 If this interface is not supported, then return FALSE.
1649 @param[in] AesContext Pointer to the AES context.
1650 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1651 @param[in] InputSize Size of the Input buffer in bytes.
1652 @param[in] Ivec Pointer to initialization vector.
1653 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1655 @retval TRUE AES decryption succeeded.
1656 @retval FALSE AES decryption failed.
1657 @retval FALSE This interface is not supported.
1663 IN VOID
*AesContext
,
1664 IN CONST UINT8
*Input
,
1666 IN CONST UINT8
*Ivec
,
1671 Retrieves the size, in bytes, of the context buffer required for ARC4 operations.
1673 If this interface is not supported, then return zero.
1675 @return The size, in bytes, of the context buffer required for ARC4 operations.
1676 @retval 0 This interface is not supported.
1681 Arc4GetContextSize (
1686 Initializes user-supplied memory as ARC4 context for subsequent use.
1688 This function initializes user-supplied memory pointed by Arc4Context as ARC4 context.
1689 In addition, it sets up all ARC4 key materials for subsequent encryption and decryption
1692 If Arc4Context is NULL, then return FALSE.
1693 If Key is NULL, then return FALSE.
1694 If KeySize does not in the range of [5, 256] bytes, then return FALSE.
1695 If this interface is not supported, then return FALSE.
1697 @param[out] Arc4Context Pointer to ARC4 context being initialized.
1698 @param[in] Key Pointer to the user-supplied ARC4 key.
1699 @param[in] KeySize Size of ARC4 key in bytes.
1701 @retval TRUE ARC4 context initialization succeeded.
1702 @retval FALSE ARC4 context initialization failed.
1703 @retval FALSE This interface is not supported.
1709 OUT VOID
*Arc4Context
,
1710 IN CONST UINT8
*Key
,
1715 Performs ARC4 encryption on a data buffer of the specified size.
1717 This function performs ARC4 encryption on data buffer pointed by Input, of specified
1719 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
1720 invalid ARC4 context is undefined.
1722 If Arc4Context is NULL, then return FALSE.
1723 If Input is NULL, then return FALSE.
1724 If Output is NULL, then return FALSE.
1725 If this interface is not supported, then return FALSE.
1727 @param[in, out] Arc4Context Pointer to the ARC4 context.
1728 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1729 @param[in] InputSize Size of the Input buffer in bytes.
1730 @param[out] Output Pointer to a buffer that receives the ARC4 encryption output.
1732 @retval TRUE ARC4 encryption succeeded.
1733 @retval FALSE ARC4 encryption failed.
1734 @retval FALSE This interface is not supported.
1740 IN OUT VOID
*Arc4Context
,
1741 IN CONST UINT8
*Input
,
1747 Performs ARC4 decryption on a data buffer of the specified size.
1749 This function performs ARC4 decryption on data buffer pointed by Input, of specified
1751 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
1752 invalid ARC4 context is undefined.
1754 If Arc4Context is NULL, then return FALSE.
1755 If Input is NULL, then return FALSE.
1756 If Output is NULL, then return FALSE.
1757 If this interface is not supported, then return FALSE.
1759 @param[in, out] Arc4Context Pointer to the ARC4 context.
1760 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1761 @param[in] InputSize Size of the Input buffer in bytes.
1762 @param[out] Output Pointer to a buffer that receives the ARC4 decryption output.
1764 @retval TRUE ARC4 decryption succeeded.
1765 @retval FALSE ARC4 decryption failed.
1766 @retval FALSE This interface is not supported.
1772 IN OUT VOID
*Arc4Context
,
1779 Resets the ARC4 context to the initial state.
1781 The function resets the ARC4 context to the state it had immediately after the
1782 ARC4Init() function call.
1783 Contrary to ARC4Init(), Arc4Reset() requires no secret key as input, but ARC4 context
1784 should be already correctly initialized by ARC4Init().
1786 If Arc4Context is NULL, then return FALSE.
1787 If this interface is not supported, then return FALSE.
1789 @param[in, out] Arc4Context Pointer to the ARC4 context.
1791 @retval TRUE ARC4 reset succeeded.
1792 @retval FALSE ARC4 reset failed.
1793 @retval FALSE This interface is not supported.
1799 IN OUT VOID
*Arc4Context
1802 //=====================================================================================
1803 // Asymmetric Cryptography Primitive
1804 //=====================================================================================
1807 Allocates and initializes one RSA context for subsequent use.
1809 @return Pointer to the RSA context that has been initialized.
1810 If the allocations fails, RsaNew() returns NULL.
1820 Release the specified RSA context.
1822 If RsaContext is NULL, then return FALSE.
1824 @param[in] RsaContext Pointer to the RSA context to be released.
1834 Sets the tag-designated key component into the established RSA context.
1836 This function sets the tag-designated RSA key component into the established
1837 RSA context from the user-specified non-negative integer (octet string format
1838 represented in RSA PKCS#1).
1839 If BigNumber is NULL, then the specified key component in RSA context is cleared.
1841 If RsaContext is NULL, then return FALSE.
1843 @param[in, out] RsaContext Pointer to RSA context being set.
1844 @param[in] KeyTag Tag of RSA key component being set.
1845 @param[in] BigNumber Pointer to octet integer buffer.
1846 If NULL, then the specified key component in RSA
1848 @param[in] BnSize Size of big number buffer in bytes.
1849 If BigNumber is NULL, then it is ignored.
1851 @retval TRUE RSA key component was set successfully.
1852 @retval FALSE Invalid RSA key component tag.
1858 IN OUT VOID
*RsaContext
,
1859 IN RSA_KEY_TAG KeyTag
,
1860 IN CONST UINT8
*BigNumber
,
1865 Gets the tag-designated RSA key component from the established RSA context.
1867 This function retrieves the tag-designated RSA key component from the
1868 established RSA context as a non-negative integer (octet string format
1869 represented in RSA PKCS#1).
1870 If specified key component has not been set or has been cleared, then returned
1872 If the BigNumber buffer is too small to hold the contents of the key, FALSE
1873 is returned and BnSize is set to the required buffer size to obtain the key.
1875 If RsaContext is NULL, then return FALSE.
1876 If BnSize is NULL, then return FALSE.
1877 If BnSize is large enough but BigNumber is NULL, then return FALSE.
1878 If this interface is not supported, then return FALSE.
1880 @param[in, out] RsaContext Pointer to RSA context being set.
1881 @param[in] KeyTag Tag of RSA key component being set.
1882 @param[out] BigNumber Pointer to octet integer buffer.
1883 @param[in, out] BnSize On input, the size of big number buffer in bytes.
1884 On output, the size of data returned in big number buffer in bytes.
1886 @retval TRUE RSA key component was retrieved successfully.
1887 @retval FALSE Invalid RSA key component tag.
1888 @retval FALSE BnSize is too small.
1889 @retval FALSE This interface is not supported.
1895 IN OUT VOID
*RsaContext
,
1896 IN RSA_KEY_TAG KeyTag
,
1897 OUT UINT8
*BigNumber
,
1898 IN OUT UINTN
*BnSize
1902 Generates RSA key components.
1904 This function generates RSA key components. It takes RSA public exponent E and
1905 length in bits of RSA modulus N as input, and generates all key components.
1906 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
1908 Before this function can be invoked, pseudorandom number generator must be correctly
1909 initialized by RandomSeed().
1911 If RsaContext is NULL, then return FALSE.
1912 If this interface is not supported, then return FALSE.
1914 @param[in, out] RsaContext Pointer to RSA context being set.
1915 @param[in] ModulusLength Length of RSA modulus N in bits.
1916 @param[in] PublicExponent Pointer to RSA public exponent.
1917 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
1919 @retval TRUE RSA key component was generated successfully.
1920 @retval FALSE Invalid RSA key component tag.
1921 @retval FALSE This interface is not supported.
1927 IN OUT VOID
*RsaContext
,
1928 IN UINTN ModulusLength
,
1929 IN CONST UINT8
*PublicExponent
,
1930 IN UINTN PublicExponentSize
1934 Validates key components of RSA context.
1935 NOTE: This function performs integrity checks on all the RSA key material, so
1936 the RSA key structure must contain all the private key data.
1938 This function validates key components of RSA context in following aspects:
1939 - Whether p is a prime
1940 - Whether q is a prime
1942 - Whether d*e = 1 mod lcm(p-1,q-1)
1944 If RsaContext is NULL, then return FALSE.
1945 If this interface is not supported, then return FALSE.
1947 @param[in] RsaContext Pointer to RSA context to check.
1949 @retval TRUE RSA key components are valid.
1950 @retval FALSE RSA key components are not valid.
1951 @retval FALSE This interface is not supported.
1961 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
1963 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
1965 If the Signature buffer is too small to hold the contents of signature, FALSE
1966 is returned and SigSize is set to the required buffer size to obtain the signature.
1968 If RsaContext is NULL, then return FALSE.
1969 If MessageHash is NULL, then return FALSE.
1970 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
1971 If SigSize is large enough but Signature is NULL, then return FALSE.
1972 If this interface is not supported, then return FALSE.
1974 @param[in] RsaContext Pointer to RSA context for signature generation.
1975 @param[in] MessageHash Pointer to octet message hash to be signed.
1976 @param[in] HashSize Size of the message hash in bytes.
1977 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
1978 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1979 On output, the size of data returned in Signature buffer in bytes.
1981 @retval TRUE Signature successfully generated in PKCS1-v1_5.
1982 @retval FALSE Signature generation failed.
1983 @retval FALSE SigSize is too small.
1984 @retval FALSE This interface is not supported.
1990 IN VOID
*RsaContext
,
1991 IN CONST UINT8
*MessageHash
,
1993 OUT UINT8
*Signature
,
1994 IN OUT UINTN
*SigSize
1998 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
2001 If RsaContext is NULL, then return FALSE.
2002 If MessageHash is NULL, then return FALSE.
2003 If Signature is NULL, then return FALSE.
2004 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
2006 @param[in] RsaContext Pointer to RSA context for signature verification.
2007 @param[in] MessageHash Pointer to octet message hash to be checked.
2008 @param[in] HashSize Size of the message hash in bytes.
2009 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
2010 @param[in] SigSize Size of signature in bytes.
2012 @retval TRUE Valid signature encoded in PKCS1-v1_5.
2013 @retval FALSE Invalid signature or invalid RSA context.
2019 IN VOID
*RsaContext
,
2020 IN CONST UINT8
*MessageHash
,
2022 IN CONST UINT8
*Signature
,
2027 Retrieve the RSA Private Key from the password-protected PEM key data.
2029 If PemData is NULL, then return FALSE.
2030 If RsaContext is NULL, then return FALSE.
2031 If this interface is not supported, then return FALSE.
2033 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
2034 @param[in] PemSize Size of the PEM key data in bytes.
2035 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
2036 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2037 RSA private key component. Use RsaFree() function to free the
2040 @retval TRUE RSA Private Key was retrieved successfully.
2041 @retval FALSE Invalid PEM key data or incorrect password.
2042 @retval FALSE This interface is not supported.
2047 RsaGetPrivateKeyFromPem (
2048 IN CONST UINT8
*PemData
,
2050 IN CONST CHAR8
*Password
,
2051 OUT VOID
**RsaContext
2055 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
2057 If Cert is NULL, then return FALSE.
2058 If RsaContext is NULL, then return FALSE.
2059 If this interface is not supported, then return FALSE.
2061 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2062 @param[in] CertSize Size of the X509 certificate in bytes.
2063 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2064 RSA public key component. Use RsaFree() function to free the
2067 @retval TRUE RSA Public Key was retrieved successfully.
2068 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
2069 @retval FALSE This interface is not supported.
2074 RsaGetPublicKeyFromX509 (
2075 IN CONST UINT8
*Cert
,
2077 OUT VOID
**RsaContext
2081 Retrieve the subject bytes from one X.509 certificate.
2083 If Cert is NULL, then return FALSE.
2084 If SubjectSize is NULL, then return FALSE.
2085 If this interface is not supported, then return FALSE.
2087 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2088 @param[in] CertSize Size of the X509 certificate in bytes.
2089 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
2090 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
2091 and the size of buffer returned CertSubject on output.
2093 @retval TRUE The certificate subject retrieved successfully.
2094 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
2095 The SubjectSize will be updated with the required size.
2096 @retval FALSE This interface is not supported.
2101 X509GetSubjectName (
2102 IN CONST UINT8
*Cert
,
2104 OUT UINT8
*CertSubject
,
2105 IN OUT UINTN
*SubjectSize
2109 Retrieve the common name (CN) string from one X.509 certificate.
2111 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2112 @param[in] CertSize Size of the X509 certificate in bytes.
2113 @param[out] CommonName Buffer to contain the retrieved certificate common
2114 name string (UTF8). At most CommonNameSize bytes will be
2115 written and the string will be null terminated. May be
2116 NULL in order to determine the size buffer needed.
2117 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
2118 and the size of buffer returned CommonName on output.
2119 If CommonName is NULL then the amount of space needed
2120 in buffer (including the final null) is returned.
2122 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
2123 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2124 If CommonNameSize is NULL.
2125 If CommonName is not NULL and *CommonNameSize is 0.
2126 If Certificate is invalid.
2127 @retval RETURN_NOT_FOUND If no CommonName entry exists.
2128 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
2129 (including the final null) is returned in the
2130 CommonNameSize parameter.
2131 @retval RETURN_UNSUPPORTED The operation is not supported.
2137 IN CONST UINT8
*Cert
,
2139 OUT CHAR8
*CommonName
, OPTIONAL
2140 IN OUT UINTN
*CommonNameSize
2144 Retrieve the organization name (O) string from one X.509 certificate.
2146 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2147 @param[in] CertSize Size of the X509 certificate in bytes.
2148 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
2149 name string. At most NameBufferSize bytes will be
2150 written and the string will be null terminated. May be
2151 NULL in order to determine the size buffer needed.
2152 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
2153 and the size of buffer returned Name on output.
2154 If NameBuffer is NULL then the amount of space needed
2155 in buffer (including the final null) is returned.
2157 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
2158 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2159 If NameBufferSize is NULL.
2160 If NameBuffer is not NULL and *CommonNameSize is 0.
2161 If Certificate is invalid.
2162 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
2163 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
2164 (including the final null) is returned in the
2165 CommonNameSize parameter.
2166 @retval RETURN_UNSUPPORTED The operation is not supported.
2171 X509GetOrganizationName (
2172 IN CONST UINT8
*Cert
,
2174 OUT CHAR8
*NameBuffer
, OPTIONAL
2175 IN OUT UINTN
*NameBufferSize
2179 Verify one X509 certificate was issued by the trusted CA.
2181 If Cert is NULL, then return FALSE.
2182 If CACert is NULL, then return FALSE.
2183 If this interface is not supported, then return FALSE.
2185 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
2186 @param[in] CertSize Size of the X509 certificate in bytes.
2187 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
2188 @param[in] CACertSize Size of the CA Certificate in bytes.
2190 @retval TRUE The certificate was issued by the trusted CA.
2191 @retval FALSE Invalid certificate or the certificate was not issued by the given
2193 @retval FALSE This interface is not supported.
2199 IN CONST UINT8
*Cert
,
2201 IN CONST UINT8
*CACert
,
2206 Construct a X509 object from DER-encoded certificate data.
2208 If Cert is NULL, then return FALSE.
2209 If SingleX509Cert is NULL, then return FALSE.
2210 If this interface is not supported, then return FALSE.
2212 @param[in] Cert Pointer to the DER-encoded certificate data.
2213 @param[in] CertSize The size of certificate data in bytes.
2214 @param[out] SingleX509Cert The generated X509 object.
2216 @retval TRUE The X509 object generation succeeded.
2217 @retval FALSE The operation failed.
2218 @retval FALSE This interface is not supported.
2223 X509ConstructCertificate (
2224 IN CONST UINT8
*Cert
,
2226 OUT UINT8
**SingleX509Cert
2230 Construct a X509 stack object from a list of DER-encoded certificate data.
2232 If X509Stack is NULL, then return FALSE.
2233 If this interface is not supported, then return FALSE.
2235 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2236 On output, pointer to the X509 stack object with new
2237 inserted X509 certificate.
2238 @param[in] Args VA_LIST marker for the variable argument list.
2239 A list of DER-encoded single certificate data followed
2240 by certificate size. A NULL terminates the list. The
2241 pairs are the arguments to X509ConstructCertificate().
2243 @retval TRUE The X509 stack construction succeeded.
2244 @retval FALSE The construction operation failed.
2245 @retval FALSE This interface is not supported.
2250 X509ConstructCertificateStackV (
2251 IN OUT UINT8
**X509Stack
,
2256 Construct a X509 stack object from a list of DER-encoded certificate data.
2258 If X509Stack is NULL, then return FALSE.
2259 If this interface is not supported, then return FALSE.
2261 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2262 On output, pointer to the X509 stack object with new
2263 inserted X509 certificate.
2264 @param ... A list of DER-encoded single certificate data followed
2265 by certificate size. A NULL terminates the list. The
2266 pairs are the arguments to X509ConstructCertificate().
2268 @retval TRUE The X509 stack construction succeeded.
2269 @retval FALSE The construction operation failed.
2270 @retval FALSE This interface is not supported.
2275 X509ConstructCertificateStack (
2276 IN OUT UINT8
**X509Stack
,
2281 Release the specified X509 object.
2283 If the interface is not supported, then ASSERT().
2285 @param[in] X509Cert Pointer to the X509 object to be released.
2295 Release the specified X509 stack object.
2297 If the interface is not supported, then ASSERT().
2299 @param[in] X509Stack Pointer to the X509 stack object to be released.
2309 Retrieve the TBSCertificate from one given X.509 certificate.
2311 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
2312 @param[in] CertSize Size of the X509 certificate in bytes.
2313 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
2314 @param[out] TBSCertSize Size of the TBS certificate in bytes.
2316 If Cert is NULL, then return FALSE.
2317 If TBSCert is NULL, then return FALSE.
2318 If TBSCertSize is NULL, then return FALSE.
2319 If this interface is not supported, then return FALSE.
2321 @retval TRUE The TBSCertificate was retrieved successfully.
2322 @retval FALSE Invalid X.509 certificate.
2328 IN CONST UINT8
*Cert
,
2330 OUT UINT8
**TBSCert
,
2331 OUT UINTN
*TBSCertSize
2335 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2336 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2338 If Password or Salt or OutKey is NULL, then return FALSE.
2339 If the hash algorithm could not be determined, then return FALSE.
2340 If this interface is not supported, then return FALSE.
2342 @param[in] PasswordLength Length of input password in bytes.
2343 @param[in] Password Pointer to the array for the password.
2344 @param[in] SaltLength Size of the Salt in bytes.
2345 @param[in] Salt Pointer to the Salt.
2346 @param[in] IterationCount Number of iterations to perform. Its value should be
2347 greater than or equal to 1.
2348 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2349 NOTE: DigestSize will be used to determine the hash algorithm.
2350 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2351 @param[in] KeyLength Size of the derived key buffer in bytes.
2352 @param[out] OutKey Pointer to the output derived key buffer.
2354 @retval TRUE A key was derived successfully.
2355 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2356 @retval FALSE The hash algorithm could not be determined from the digest size.
2357 @retval FALSE The key derivation operation failed.
2358 @retval FALSE This interface is not supported.
2364 IN UINTN PasswordLength
,
2365 IN CONST CHAR8
*Password
,
2366 IN UINTN SaltLength
,
2367 IN CONST UINT8
*Salt
,
2368 IN UINTN IterationCount
,
2369 IN UINTN DigestSize
,
2375 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2376 encrypted message in a newly allocated buffer.
2378 Things that can cause a failure include:
2379 - X509 key size does not match any known key size.
2380 - Fail to parse X509 certificate.
2381 - Fail to allocate an intermediate buffer.
2382 - Null pointer provided for a non-optional parameter.
2383 - Data size is too large for the provided key size (max size is a function of key size
2384 and hash digest size).
2386 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2387 will be used to encrypt the data.
2388 @param[in] PublicKeySize Size of the X509 cert buffer.
2389 @param[in] InData Data to be encrypted.
2390 @param[in] InDataSize Size of the data buffer.
2391 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2392 to be used when initializing the PRNG. NULL otherwise.
2393 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2395 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2397 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2399 @retval TRUE Encryption was successful.
2400 @retval FALSE Encryption failed.
2406 IN CONST UINT8
*PublicKey
,
2407 IN UINTN PublicKeySize
,
2409 IN UINTN InDataSize
,
2410 IN CONST UINT8
*PrngSeed
, OPTIONAL
2411 IN UINTN PrngSeedSize
, OPTIONAL
2412 OUT UINT8
**EncryptedData
,
2413 OUT UINTN
*EncryptedDataSize
2417 The 3rd parameter of Pkcs7GetSigners will return all embedded
2418 X.509 certificate in one given PKCS7 signature. The format is:
2420 // UINT8 CertNumber;
2421 // UINT32 Cert1Length;
2423 // UINT32 Cert2Length;
2426 // UINT32 CertnLength;
2430 The two following C-structure are used for parsing CertStack more clearly.
2435 UINT32 CertDataLength
; // The length in bytes of X.509 certificate.
2436 UINT8 CertDataBuffer
[0]; // The X.509 certificate content (DER).
2440 UINT8 CertNumber
; // Number of X.509 certificate.
2441 //EFI_CERT_DATA CertArray[]; // An array of X.509 certificate.
2447 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2448 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2449 in a ContentInfo structure.
2451 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2452 return FALSE. If P7Length overflow, then return FALSE.
2453 If this interface is not supported, then return FALSE.
2455 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2456 @param[in] P7Length Length of the PKCS#7 message in bytes.
2457 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2458 It's caller's responsibility to free the buffer with
2460 This data structure is EFI_CERT_STACK type.
2461 @param[out] StackLength Length of signer's certificates in bytes.
2462 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2463 It's caller's responsibility to free the buffer with
2465 @param[out] CertLength Length of the trusted certificate in bytes.
2467 @retval TRUE The operation is finished successfully.
2468 @retval FALSE Error occurs during the operation.
2469 @retval FALSE This interface is not supported.
2475 IN CONST UINT8
*P7Data
,
2477 OUT UINT8
**CertStack
,
2478 OUT UINTN
*StackLength
,
2479 OUT UINT8
**TrustedCert
,
2480 OUT UINTN
*CertLength
2484 Wrap function to use free() to free allocated memory for certificates.
2486 If this interface is not supported, then ASSERT().
2488 @param[in] Certs Pointer to the certificates to be freed.
2498 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2499 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2500 unchained to the signer's certificates.
2501 The input signed data could be wrapped in a ContentInfo structure.
2503 @param[in] P7Data Pointer to the PKCS#7 message.
2504 @param[in] P7Length Length of the PKCS#7 message in bytes.
2505 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2506 certificate. It's caller's responsibility to free the buffer
2507 with Pkcs7FreeSigners().
2508 This data structure is EFI_CERT_STACK type.
2509 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2510 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2511 responsibility to free the buffer with Pkcs7FreeSigners().
2512 This data structure is EFI_CERT_STACK type.
2513 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2515 @retval TRUE The operation is finished successfully.
2516 @retval FALSE Error occurs during the operation.
2521 Pkcs7GetCertificatesList (
2522 IN CONST UINT8
*P7Data
,
2524 OUT UINT8
**SignerChainCerts
,
2525 OUT UINTN
*ChainLength
,
2526 OUT UINT8
**UnchainCerts
,
2527 OUT UINTN
*UnchainLength
2531 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2532 Syntax Standard, version 1.5". This interface is only intended to be used for
2533 application to perform PKCS#7 functionality validation.
2535 If this interface is not supported, then return FALSE.
2537 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2539 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2540 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2542 @param[in] InData Pointer to the content to be signed.
2543 @param[in] InDataSize Size of InData in bytes.
2544 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2545 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2546 include in the PKCS#7 signedData (e.g. any intermediate
2548 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2549 responsibility to free the buffer with FreePool().
2550 @param[out] SignedDataSize Size of SignedData in bytes.
2552 @retval TRUE PKCS#7 data signing succeeded.
2553 @retval FALSE PKCS#7 data signing failed.
2554 @retval FALSE This interface is not supported.
2560 IN CONST UINT8
*PrivateKey
,
2561 IN UINTN PrivateKeySize
,
2562 IN CONST UINT8
*KeyPassword
,
2564 IN UINTN InDataSize
,
2566 IN UINT8
*OtherCerts OPTIONAL
,
2567 OUT UINT8
**SignedData
,
2568 OUT UINTN
*SignedDataSize
2572 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2573 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2574 in a ContentInfo structure.
2576 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2577 If P7Length, CertLength or DataLength overflow, then return FALSE.
2578 If this interface is not supported, then return FALSE.
2580 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2581 @param[in] P7Length Length of the PKCS#7 message in bytes.
2582 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2583 is used for certificate chain verification.
2584 @param[in] CertLength Length of the trusted certificate in bytes.
2585 @param[in] InData Pointer to the content to be verified.
2586 @param[in] DataLength Length of InData in bytes.
2588 @retval TRUE The specified PKCS#7 signed data is valid.
2589 @retval FALSE Invalid PKCS#7 signed data.
2590 @retval FALSE This interface is not supported.
2596 IN CONST UINT8
*P7Data
,
2598 IN CONST UINT8
*TrustedCert
,
2599 IN UINTN CertLength
,
2600 IN CONST UINT8
*InData
,
2605 This function receives a PKCS7 formatted signature, and then verifies that
2606 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
2607 leaf signing certificate.
2608 Note that this function does not validate the certificate chain.
2610 Applications for custom EKU's are quite flexible. For example, a policy EKU
2611 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
2612 certificate issued might also contain this EKU, thus constraining the
2613 sub-ordinate certificate. Other applications might allow a certificate
2614 embedded in a device to specify that other Object Identifiers (OIDs) are
2615 present which contains binary data specifying custom capabilities that
2616 the device is able to do.
2618 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
2619 containing the content block with both the signature,
2620 the signer's certificate, and any necessary intermediate
2622 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
2623 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
2624 required EKUs that must be present in the signature.
2625 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
2626 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
2627 must be present in the leaf signer. If it is
2628 FALSE, then we will succeed if we find any
2629 of the specified EKU's.
2631 @retval EFI_SUCCESS The required EKUs were found in the signature.
2632 @retval EFI_INVALID_PARAMETER A parameter was invalid.
2633 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
2638 VerifyEKUsInPkcs7Signature (
2639 IN CONST UINT8
*Pkcs7Signature
,
2640 IN CONST UINT32 SignatureSize
,
2641 IN CONST CHAR8
*RequiredEKUs
[],
2642 IN CONST UINT32 RequiredEKUsSize
,
2643 IN BOOLEAN RequireAllPresent
2647 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2648 data could be wrapped in a ContentInfo structure.
2650 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2651 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2653 Caution: This function may receive untrusted input. So this function will do
2654 basic check for PKCS#7 data structure.
2656 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2657 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2658 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2659 It's caller's responsibility to free the buffer with FreePool().
2660 @param[out] ContentSize The size of the extracted content in bytes.
2662 @retval TRUE The P7Data was correctly formatted for processing.
2663 @retval FALSE The P7Data was not correctly formatted for processing.
2668 Pkcs7GetAttachedContent (
2669 IN CONST UINT8
*P7Data
,
2672 OUT UINTN
*ContentSize
2676 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2677 Authenticode Portable Executable Signature Format".
2679 If AuthData is NULL, then return FALSE.
2680 If ImageHash is NULL, then return FALSE.
2681 If this interface is not supported, then return FALSE.
2683 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2684 PE/COFF image to be verified.
2685 @param[in] DataSize Size of the Authenticode Signature in bytes.
2686 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2687 is used for certificate chain verification.
2688 @param[in] CertSize Size of the trusted certificate in bytes.
2689 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2690 for calculating the image hash value is described in Authenticode
2692 @param[in] HashSize Size of Image hash value in bytes.
2694 @retval TRUE The specified Authenticode Signature is valid.
2695 @retval FALSE Invalid Authenticode Signature.
2696 @retval FALSE This interface is not supported.
2701 AuthenticodeVerify (
2702 IN CONST UINT8
*AuthData
,
2704 IN CONST UINT8
*TrustedCert
,
2706 IN CONST UINT8
*ImageHash
,
2711 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2714 If AuthData is NULL, then return FALSE.
2715 If this interface is not supported, then return FALSE.
2717 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2718 PE/COFF image to be verified.
2719 @param[in] DataSize Size of the Authenticode Signature in bytes.
2720 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2721 is used for TSA certificate chain verification.
2722 @param[in] CertSize Size of the trusted certificate in bytes.
2723 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2726 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2727 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2732 ImageTimestampVerify (
2733 IN CONST UINT8
*AuthData
,
2735 IN CONST UINT8
*TsaCert
,
2737 OUT EFI_TIME
*SigningTime
2740 //=====================================================================================
2741 // DH Key Exchange Primitive
2742 //=====================================================================================
2745 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
2747 @return Pointer to the Diffie-Hellman Context that has been initialized.
2748 If the allocations fails, DhNew() returns NULL.
2749 If the interface is not supported, DhNew() returns NULL.
2759 Release the specified DH context.
2761 If the interface is not supported, then ASSERT().
2763 @param[in] DhContext Pointer to the DH context to be released.
2773 Generates DH parameter.
2775 Given generator g, and length of prime number p in bits, this function generates p,
2776 and sets DH context according to value of g and p.
2778 Before this function can be invoked, pseudorandom number generator must be correctly
2779 initialized by RandomSeed().
2781 If DhContext is NULL, then return FALSE.
2782 If Prime is NULL, then return FALSE.
2783 If this interface is not supported, then return FALSE.
2785 @param[in, out] DhContext Pointer to the DH context.
2786 @param[in] Generator Value of generator.
2787 @param[in] PrimeLength Length in bits of prime to be generated.
2788 @param[out] Prime Pointer to the buffer to receive the generated prime number.
2790 @retval TRUE DH parameter generation succeeded.
2791 @retval FALSE Value of Generator is not supported.
2792 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
2793 @retval FALSE This interface is not supported.
2798 DhGenerateParameter (
2799 IN OUT VOID
*DhContext
,
2801 IN UINTN PrimeLength
,
2806 Sets generator and prime parameters for DH.
2808 Given generator g, and prime number p, this function and sets DH
2809 context accordingly.
2811 If DhContext is NULL, then return FALSE.
2812 If Prime is NULL, then return FALSE.
2813 If this interface is not supported, then return FALSE.
2815 @param[in, out] DhContext Pointer to the DH context.
2816 @param[in] Generator Value of generator.
2817 @param[in] PrimeLength Length in bits of prime to be generated.
2818 @param[in] Prime Pointer to the prime number.
2820 @retval TRUE DH parameter setting succeeded.
2821 @retval FALSE Value of Generator is not supported.
2822 @retval FALSE Value of Generator is not suitable for the Prime.
2823 @retval FALSE Value of Prime is not a prime number.
2824 @retval FALSE Value of Prime is not a safe prime number.
2825 @retval FALSE This interface is not supported.
2831 IN OUT VOID
*DhContext
,
2833 IN UINTN PrimeLength
,
2834 IN CONST UINT8
*Prime
2838 Generates DH public key.
2840 This function generates random secret exponent, and computes the public key, which is
2841 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
2842 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
2843 PublicKeySize is set to the required buffer size to obtain the public key.
2845 If DhContext is NULL, then return FALSE.
2846 If PublicKeySize is NULL, then return FALSE.
2847 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
2848 If this interface is not supported, then return FALSE.
2850 @param[in, out] DhContext Pointer to the DH context.
2851 @param[out] PublicKey Pointer to the buffer to receive generated public key.
2852 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
2853 On output, the size of data returned in PublicKey buffer in bytes.
2855 @retval TRUE DH public key generation succeeded.
2856 @retval FALSE DH public key generation failed.
2857 @retval FALSE PublicKeySize is not large enough.
2858 @retval FALSE This interface is not supported.
2864 IN OUT VOID
*DhContext
,
2865 OUT UINT8
*PublicKey
,
2866 IN OUT UINTN
*PublicKeySize
2870 Computes exchanged common key.
2872 Given peer's public key, this function computes the exchanged common key, based on its own
2873 context including value of prime modulus and random secret exponent.
2875 If DhContext is NULL, then return FALSE.
2876 If PeerPublicKey is NULL, then return FALSE.
2877 If KeySize is NULL, then return FALSE.
2878 If Key is NULL, then return FALSE.
2879 If KeySize is not large enough, then return FALSE.
2880 If this interface is not supported, then return FALSE.
2882 @param[in, out] DhContext Pointer to the DH context.
2883 @param[in] PeerPublicKey Pointer to the peer's public key.
2884 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
2885 @param[out] Key Pointer to the buffer to receive generated key.
2886 @param[in, out] KeySize On input, the size of Key buffer in bytes.
2887 On output, the size of data returned in Key buffer in bytes.
2889 @retval TRUE DH exchanged key generation succeeded.
2890 @retval FALSE DH exchanged key generation failed.
2891 @retval FALSE KeySize is not large enough.
2892 @retval FALSE This interface is not supported.
2898 IN OUT VOID
*DhContext
,
2899 IN CONST UINT8
*PeerPublicKey
,
2900 IN UINTN PeerPublicKeySize
,
2902 IN OUT UINTN
*KeySize
2905 //=====================================================================================
2906 // Pseudo-Random Generation Primitive
2907 //=====================================================================================
2910 Sets up the seed value for the pseudorandom number generator.
2912 This function sets up the seed value for the pseudorandom number generator.
2913 If Seed is not NULL, then the seed passed in is used.
2914 If Seed is NULL, then default seed is used.
2915 If this interface is not supported, then return FALSE.
2917 @param[in] Seed Pointer to seed value.
2918 If NULL, default seed is used.
2919 @param[in] SeedSize Size of seed value.
2920 If Seed is NULL, this parameter is ignored.
2922 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
2923 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
2924 @retval FALSE This interface is not supported.
2930 IN CONST UINT8
*Seed OPTIONAL
,
2935 Generates a pseudorandom byte stream of the specified size.
2937 If Output is NULL, then return FALSE.
2938 If this interface is not supported, then return FALSE.
2940 @param[out] Output Pointer to buffer to receive random value.
2941 @param[in] Size Size of random bytes to generate.
2943 @retval TRUE Pseudorandom byte stream generated successfully.
2944 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
2945 @retval FALSE This interface is not supported.
2955 //=====================================================================================
2956 // Key Derivation Function Primitive
2957 //=====================================================================================
2960 Derive key data using HMAC-SHA256 based KDF.
2962 @param[in] Key Pointer to the user-supplied key.
2963 @param[in] KeySize Key size in bytes.
2964 @param[in] Salt Pointer to the salt(non-secret) value.
2965 @param[in] SaltSize Salt size in bytes.
2966 @param[in] Info Pointer to the application specific info.
2967 @param[in] InfoSize Info size in bytes.
2968 @param[out] Out Pointer to buffer to receive hkdf value.
2969 @param[in] OutSize Size of hkdf bytes to generate.
2971 @retval TRUE Hkdf generated successfully.
2972 @retval FALSE Hkdf generation failed.
2977 HkdfSha256ExtractAndExpand (
2978 IN CONST UINT8
*Key
,
2980 IN CONST UINT8
*Salt
,
2982 IN CONST UINT8
*Info
,
2988 #endif // __BASE_CRYPT_LIB_H__