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 - 2018, 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 /// 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 MD4 hash operations.
78 If this interface is not supported, then return zero.
80 @return The size, in bytes, of the context buffer required for MD4 hash operations.
81 @retval 0 This interface is not supported.
91 Initializes user-supplied memory pointed by Md4Context as MD4 hash context for
94 If Md4Context is NULL, then return FALSE.
95 If this interface is not supported, then return FALSE.
97 @param[out] Md4Context Pointer to MD4 context being initialized.
99 @retval TRUE MD4 context initialization succeeded.
100 @retval FALSE MD4 context initialization failed.
101 @retval FALSE This interface is not supported.
111 Makes a copy of an existing MD4 context.
113 If Md4Context is NULL, then return FALSE.
114 If NewMd4Context is NULL, then return FALSE.
115 If this interface is not supported, then return FALSE.
117 @param[in] Md4Context Pointer to MD4 context being copied.
118 @param[out] NewMd4Context Pointer to new MD4 context.
120 @retval TRUE MD4 context copy succeeded.
121 @retval FALSE MD4 context copy failed.
122 @retval FALSE This interface is not supported.
128 IN CONST VOID
*Md4Context
,
129 OUT VOID
*NewMd4Context
133 Digests the input data and updates MD4 context.
135 This function performs MD4 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 MD4 context should be already correctly initialized by Md4Init(), and should not be finalized
138 by Md4Final(). Behavior with invalid context is undefined.
140 If Md4Context is NULL, then return FALSE.
141 If this interface is not supported, then return FALSE.
143 @param[in, out] Md4Context Pointer to the MD4 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 MD4 data digest succeeded.
148 @retval FALSE MD4 data digest failed.
149 @retval FALSE This interface is not supported.
155 IN OUT VOID
*Md4Context
,
161 Completes computation of the MD4 digest value.
163 This function completes MD4 hash computation and retrieves the digest value into
164 the specified memory. After this function has been called, the MD4 context cannot
166 MD4 context should be already correctly initialized by Md4Init(), and should not be
167 finalized by Md4Final(). Behavior with invalid MD4 context is undefined.
169 If Md4Context 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] Md4Context Pointer to the MD4 context.
174 @param[out] HashValue Pointer to a buffer that receives the MD4 digest
177 @retval TRUE MD4 digest computation succeeded.
178 @retval FALSE MD4 digest computation failed.
179 @retval FALSE This interface is not supported.
185 IN OUT VOID
*Md4Context
,
190 Computes the MD4 message digest of a input data buffer.
192 This function performs the MD4 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 MD4 digest
202 @retval TRUE MD4 digest computation succeeded.
203 @retval FALSE MD4 digest computation failed.
204 @retval FALSE This interface is not supported.
216 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.
218 If this interface is not supported, then return zero.
220 @return The size, in bytes, of the context buffer required for MD5 hash operations.
221 @retval 0 This interface is not supported.
231 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for
234 If Md5Context is NULL, then return FALSE.
235 If this interface is not supported, then return FALSE.
237 @param[out] Md5Context Pointer to MD5 context being initialized.
239 @retval TRUE MD5 context initialization succeeded.
240 @retval FALSE MD5 context initialization failed.
241 @retval FALSE This interface is not supported.
251 Makes a copy of an existing MD5 context.
253 If Md5Context is NULL, then return FALSE.
254 If NewMd5Context is NULL, then return FALSE.
255 If this interface is not supported, then return FALSE.
257 @param[in] Md5Context Pointer to MD5 context being copied.
258 @param[out] NewMd5Context Pointer to new MD5 context.
260 @retval TRUE MD5 context copy succeeded.
261 @retval FALSE MD5 context copy failed.
262 @retval FALSE This interface is not supported.
268 IN CONST VOID
*Md5Context
,
269 OUT VOID
*NewMd5Context
273 Digests the input data and updates MD5 context.
275 This function performs MD5 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 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized
278 by Md5Final(). Behavior with invalid context is undefined.
280 If Md5Context is NULL, then return FALSE.
281 If this interface is not supported, then return FALSE.
283 @param[in, out] Md5Context Pointer to the MD5 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 MD5 data digest succeeded.
288 @retval FALSE MD5 data digest failed.
289 @retval FALSE This interface is not supported.
295 IN OUT VOID
*Md5Context
,
301 Completes computation of the MD5 digest value.
303 This function completes MD5 hash computation and retrieves the digest value into
304 the specified memory. After this function has been called, the MD5 context cannot
306 MD5 context should be already correctly initialized by Md5Init(), and should not be
307 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.
309 If Md5Context 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] Md5Context Pointer to the MD5 context.
314 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
317 @retval TRUE MD5 digest computation succeeded.
318 @retval FALSE MD5 digest computation failed.
319 @retval FALSE This interface is not supported.
325 IN OUT VOID
*Md5Context
,
330 Computes the MD5 message digest of a input data buffer.
332 This function performs the MD5 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 MD5 digest
342 @retval TRUE MD5 digest computation succeeded.
343 @retval FALSE MD5 digest computation failed.
344 @retval FALSE This interface is not supported.
356 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.
358 If this interface is not supported, then return zero.
360 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.
361 @retval 0 This interface is not supported.
371 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for
374 If Sha1Context is NULL, then return FALSE.
375 If this interface is not supported, then return FALSE.
377 @param[out] Sha1Context Pointer to SHA-1 context being initialized.
379 @retval TRUE SHA-1 context initialization succeeded.
380 @retval FALSE SHA-1 context initialization failed.
381 @retval FALSE This interface is not supported.
387 OUT VOID
*Sha1Context
391 Makes a copy of an existing SHA-1 context.
393 If Sha1Context is NULL, then return FALSE.
394 If NewSha1Context is NULL, then return FALSE.
395 If this interface is not supported, then return FALSE.
397 @param[in] Sha1Context Pointer to SHA-1 context being copied.
398 @param[out] NewSha1Context Pointer to new SHA-1 context.
400 @retval TRUE SHA-1 context copy succeeded.
401 @retval FALSE SHA-1 context copy failed.
402 @retval FALSE This interface is not supported.
408 IN CONST VOID
*Sha1Context
,
409 OUT VOID
*NewSha1Context
413 Digests the input data and updates SHA-1 context.
415 This function performs SHA-1 digest on a data buffer of the specified size.
416 It can be called multiple times to compute the digest of long or discontinuous data streams.
417 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized
418 by Sha1Final(). Behavior with invalid context is undefined.
420 If Sha1Context is NULL, then return FALSE.
421 If this interface is not supported, then return FALSE.
423 @param[in, out] Sha1Context Pointer to the SHA-1 context.
424 @param[in] Data Pointer to the buffer containing the data to be hashed.
425 @param[in] DataSize Size of Data buffer in bytes.
427 @retval TRUE SHA-1 data digest succeeded.
428 @retval FALSE SHA-1 data digest failed.
429 @retval FALSE This interface is not supported.
435 IN OUT VOID
*Sha1Context
,
441 Completes computation of the SHA-1 digest value.
443 This function completes SHA-1 hash computation and retrieves the digest value into
444 the specified memory. After this function has been called, the SHA-1 context cannot
446 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be
447 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.
449 If Sha1Context is NULL, then return FALSE.
450 If HashValue is NULL, then return FALSE.
451 If this interface is not supported, then return FALSE.
453 @param[in, out] Sha1Context Pointer to the SHA-1 context.
454 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
457 @retval TRUE SHA-1 digest computation succeeded.
458 @retval FALSE SHA-1 digest computation failed.
459 @retval FALSE This interface is not supported.
465 IN OUT VOID
*Sha1Context
,
470 Computes the SHA-1 message digest of a input data buffer.
472 This function performs the SHA-1 message digest of a given data buffer, and places
473 the digest value into the specified memory.
475 If this interface is not supported, then return FALSE.
477 @param[in] Data Pointer to the buffer containing the data to be hashed.
478 @param[in] DataSize Size of Data buffer in bytes.
479 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
482 @retval TRUE SHA-1 digest computation succeeded.
483 @retval FALSE SHA-1 digest computation failed.
484 @retval FALSE This interface is not supported.
496 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.
498 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.
503 Sha256GetContextSize (
508 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for
511 If Sha256Context is NULL, then return FALSE.
513 @param[out] Sha256Context Pointer to SHA-256 context being initialized.
515 @retval TRUE SHA-256 context initialization succeeded.
516 @retval FALSE SHA-256 context initialization failed.
522 OUT VOID
*Sha256Context
526 Makes a copy of an existing SHA-256 context.
528 If Sha256Context is NULL, then return FALSE.
529 If NewSha256Context is NULL, then return FALSE.
530 If this interface is not supported, then return FALSE.
532 @param[in] Sha256Context Pointer to SHA-256 context being copied.
533 @param[out] NewSha256Context Pointer to new SHA-256 context.
535 @retval TRUE SHA-256 context copy succeeded.
536 @retval FALSE SHA-256 context copy failed.
537 @retval FALSE This interface is not supported.
543 IN CONST VOID
*Sha256Context
,
544 OUT VOID
*NewSha256Context
548 Digests the input data and updates SHA-256 context.
550 This function performs SHA-256 digest on a data buffer of the specified size.
551 It can be called multiple times to compute the digest of long or discontinuous data streams.
552 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized
553 by Sha256Final(). Behavior with invalid context is undefined.
555 If Sha256Context is NULL, then return FALSE.
557 @param[in, out] Sha256Context Pointer to the SHA-256 context.
558 @param[in] Data Pointer to the buffer containing the data to be hashed.
559 @param[in] DataSize Size of Data buffer in bytes.
561 @retval TRUE SHA-256 data digest succeeded.
562 @retval FALSE SHA-256 data digest failed.
568 IN OUT VOID
*Sha256Context
,
574 Completes computation of the SHA-256 digest value.
576 This function completes SHA-256 hash computation and retrieves the digest value into
577 the specified memory. After this function has been called, the SHA-256 context cannot
579 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be
580 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.
582 If Sha256Context is NULL, then return FALSE.
583 If HashValue is NULL, then return FALSE.
585 @param[in, out] Sha256Context Pointer to the SHA-256 context.
586 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
589 @retval TRUE SHA-256 digest computation succeeded.
590 @retval FALSE SHA-256 digest computation failed.
596 IN OUT VOID
*Sha256Context
,
601 Computes the SHA-256 message digest of a input data buffer.
603 This function performs the SHA-256 message digest of a given data buffer, and places
604 the digest value into the specified memory.
606 If this interface is not supported, then return FALSE.
608 @param[in] Data Pointer to the buffer containing the data to be hashed.
609 @param[in] DataSize Size of Data buffer in bytes.
610 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
613 @retval TRUE SHA-256 digest computation succeeded.
614 @retval FALSE SHA-256 digest computation failed.
615 @retval FALSE This interface is not supported.
627 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.
629 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.
634 Sha384GetContextSize (
639 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for
642 If Sha384Context is NULL, then return FALSE.
644 @param[out] Sha384Context Pointer to SHA-384 context being initialized.
646 @retval TRUE SHA-384 context initialization succeeded.
647 @retval FALSE SHA-384 context initialization failed.
653 OUT VOID
*Sha384Context
657 Makes a copy of an existing SHA-384 context.
659 If Sha384Context is NULL, then return FALSE.
660 If NewSha384Context is NULL, then return FALSE.
661 If this interface is not supported, then return FALSE.
663 @param[in] Sha384Context Pointer to SHA-384 context being copied.
664 @param[out] NewSha384Context Pointer to new SHA-384 context.
666 @retval TRUE SHA-384 context copy succeeded.
667 @retval FALSE SHA-384 context copy failed.
668 @retval FALSE This interface is not supported.
674 IN CONST VOID
*Sha384Context
,
675 OUT VOID
*NewSha384Context
679 Digests the input data and updates SHA-384 context.
681 This function performs SHA-384 digest on a data buffer of the specified size.
682 It can be called multiple times to compute the digest of long or discontinuous data streams.
683 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized
684 by Sha384Final(). Behavior with invalid context is undefined.
686 If Sha384Context is NULL, then return FALSE.
688 @param[in, out] Sha384Context Pointer to the SHA-384 context.
689 @param[in] Data Pointer to the buffer containing the data to be hashed.
690 @param[in] DataSize Size of Data buffer in bytes.
692 @retval TRUE SHA-384 data digest succeeded.
693 @retval FALSE SHA-384 data digest failed.
699 IN OUT VOID
*Sha384Context
,
705 Completes computation of the SHA-384 digest value.
707 This function completes SHA-384 hash computation and retrieves the digest value into
708 the specified memory. After this function has been called, the SHA-384 context cannot
710 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be
711 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.
713 If Sha384Context is NULL, then return FALSE.
714 If HashValue is NULL, then return FALSE.
716 @param[in, out] Sha384Context Pointer to the SHA-384 context.
717 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
720 @retval TRUE SHA-384 digest computation succeeded.
721 @retval FALSE SHA-384 digest computation failed.
727 IN OUT VOID
*Sha384Context
,
732 Computes the SHA-384 message digest of a input data buffer.
734 This function performs the SHA-384 message digest of a given data buffer, and places
735 the digest value into the specified memory.
737 If this interface is not supported, then return FALSE.
739 @param[in] Data Pointer to the buffer containing the data to be hashed.
740 @param[in] DataSize Size of Data buffer in bytes.
741 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
744 @retval TRUE SHA-384 digest computation succeeded.
745 @retval FALSE SHA-384 digest computation failed.
746 @retval FALSE This interface is not supported.
758 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.
760 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.
765 Sha512GetContextSize (
770 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for
773 If Sha512Context is NULL, then return FALSE.
775 @param[out] Sha512Context Pointer to SHA-512 context being initialized.
777 @retval TRUE SHA-512 context initialization succeeded.
778 @retval FALSE SHA-512 context initialization failed.
784 OUT VOID
*Sha512Context
788 Makes a copy of an existing SHA-512 context.
790 If Sha512Context is NULL, then return FALSE.
791 If NewSha512Context is NULL, then return FALSE.
792 If this interface is not supported, then return FALSE.
794 @param[in] Sha512Context Pointer to SHA-512 context being copied.
795 @param[out] NewSha512Context Pointer to new SHA-512 context.
797 @retval TRUE SHA-512 context copy succeeded.
798 @retval FALSE SHA-512 context copy failed.
799 @retval FALSE This interface is not supported.
805 IN CONST VOID
*Sha512Context
,
806 OUT VOID
*NewSha512Context
810 Digests the input data and updates SHA-512 context.
812 This function performs SHA-512 digest on a data buffer of the specified size.
813 It can be called multiple times to compute the digest of long or discontinuous data streams.
814 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized
815 by Sha512Final(). Behavior with invalid context is undefined.
817 If Sha512Context is NULL, then return FALSE.
819 @param[in, out] Sha512Context Pointer to the SHA-512 context.
820 @param[in] Data Pointer to the buffer containing the data to be hashed.
821 @param[in] DataSize Size of Data buffer in bytes.
823 @retval TRUE SHA-512 data digest succeeded.
824 @retval FALSE SHA-512 data digest failed.
830 IN OUT VOID
*Sha512Context
,
836 Completes computation of the SHA-512 digest value.
838 This function completes SHA-512 hash computation and retrieves the digest value into
839 the specified memory. After this function has been called, the SHA-512 context cannot
841 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be
842 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.
844 If Sha512Context is NULL, then return FALSE.
845 If HashValue is NULL, then return FALSE.
847 @param[in, out] Sha512Context Pointer to the SHA-512 context.
848 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
851 @retval TRUE SHA-512 digest computation succeeded.
852 @retval FALSE SHA-512 digest computation failed.
858 IN OUT VOID
*Sha512Context
,
863 Computes the SHA-512 message digest of a input data buffer.
865 This function performs the SHA-512 message digest of a given data buffer, and places
866 the digest value into the specified memory.
868 If this interface is not supported, then return FALSE.
870 @param[in] Data Pointer to the buffer containing the data to be hashed.
871 @param[in] DataSize Size of Data buffer in bytes.
872 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
875 @retval TRUE SHA-512 digest computation succeeded.
876 @retval FALSE SHA-512 digest computation failed.
877 @retval FALSE This interface is not supported.
888 //=====================================================================================
889 // MAC (Message Authentication Code) Primitive
890 //=====================================================================================
893 Retrieves the size, in bytes, of the context buffer required for HMAC-MD5 operations.
894 (NOTE: This API is deprecated.
895 Use HmacMd5New() / HmacMd5Free() for HMAC-MD5 Context operations.)
897 If this interface is not supported, then return zero.
899 @return The size, in bytes, of the context buffer required for HMAC-MD5 operations.
900 @retval 0 This interface is not supported.
905 HmacMd5GetContextSize (
910 Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD5 use.
912 If this interface is not supported, then return NULL.
914 @return Pointer to the HMAC_CTX context that has been initialized.
915 If the allocations fails, HmacMd5New() returns NULL.
916 @retval NULL This interface is not supported.
926 Release the specified HMAC_CTX context.
928 If this interface is not supported, then do nothing.
930 @param[in] HmacMd5Ctx Pointer to the HMAC_CTX context to be released.
940 Initializes user-supplied memory pointed by HmacMd5Context as HMAC-MD5 context for
943 If HmacMd5Context is NULL, then return FALSE.
944 If this interface is not supported, then return FALSE.
946 @param[out] HmacMd5Context Pointer to HMAC-MD5 context being initialized.
947 @param[in] Key Pointer to the user-supplied key.
948 @param[in] KeySize Key size in bytes.
950 @retval TRUE HMAC-MD5 context initialization succeeded.
951 @retval FALSE HMAC-MD5 context initialization failed.
952 @retval FALSE This interface is not supported.
958 OUT VOID
*HmacMd5Context
,
964 Makes a copy of an existing HMAC-MD5 context.
966 If HmacMd5Context is NULL, then return FALSE.
967 If NewHmacMd5Context is NULL, then return FALSE.
968 If this interface is not supported, then return FALSE.
970 @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied.
971 @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context.
973 @retval TRUE HMAC-MD5 context copy succeeded.
974 @retval FALSE HMAC-MD5 context copy failed.
975 @retval FALSE This interface is not supported.
981 IN CONST VOID
*HmacMd5Context
,
982 OUT VOID
*NewHmacMd5Context
986 Digests the input data and updates HMAC-MD5 context.
988 This function performs HMAC-MD5 digest on a data buffer of the specified size.
989 It can be called multiple times to compute the digest of long or discontinuous data streams.
990 HMAC-MD5 context should be already correctly initialized by HmacMd5Init(), and should not be
991 finalized by HmacMd5Final(). Behavior with invalid context is undefined.
993 If HmacMd5Context is NULL, then return FALSE.
994 If this interface is not supported, then return FALSE.
996 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
997 @param[in] Data Pointer to the buffer containing the data to be digested.
998 @param[in] DataSize Size of Data buffer in bytes.
1000 @retval TRUE HMAC-MD5 data digest succeeded.
1001 @retval FALSE HMAC-MD5 data digest failed.
1002 @retval FALSE This interface is not supported.
1008 IN OUT VOID
*HmacMd5Context
,
1009 IN CONST VOID
*Data
,
1014 Completes computation of the HMAC-MD5 digest value.
1016 This function completes HMAC-MD5 hash computation and retrieves the digest value into
1017 the specified memory. After this function has been called, the HMAC-MD5 context cannot
1019 HMAC-MD5 context should be already correctly initialized by HmacMd5Init(), and should not be
1020 finalized by HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined.
1022 If HmacMd5Context is NULL, then return FALSE.
1023 If HmacValue is NULL, then return FALSE.
1024 If this interface is not supported, then return FALSE.
1026 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
1027 @param[out] HmacValue Pointer to a buffer that receives the HMAC-MD5 digest
1030 @retval TRUE HMAC-MD5 digest computation succeeded.
1031 @retval FALSE HMAC-MD5 digest computation failed.
1032 @retval FALSE This interface is not supported.
1038 IN OUT VOID
*HmacMd5Context
,
1039 OUT UINT8
*HmacValue
1043 Retrieves the size, in bytes, of the context buffer required for HMAC-SHA1 operations.
1044 (NOTE: This API is deprecated.
1045 Use HmacSha1New() / HmacSha1Free() for HMAC-SHA1 Context operations.)
1047 If this interface is not supported, then return zero.
1049 @return The size, in bytes, of the context buffer required for HMAC-SHA1 operations.
1050 @retval 0 This interface is not supported.
1055 HmacSha1GetContextSize (
1060 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA1 use.
1062 If this interface is not supported, then return NULL.
1064 @return Pointer to the HMAC_CTX context that has been initialized.
1065 If the allocations fails, HmacSha1New() returns NULL.
1066 @return NULL This interface is not supported.
1076 Release the specified HMAC_CTX context.
1078 If this interface is not supported, then do nothing.
1080 @param[in] HmacSha1Ctx Pointer to the HMAC_CTX context to be released.
1086 IN VOID
*HmacSha1Ctx
1090 Initializes user-supplied memory pointed by HmacSha1Context as HMAC-SHA1 context for
1093 If HmacSha1Context is NULL, then return FALSE.
1094 If this interface is not supported, then return FALSE.
1096 @param[out] HmacSha1Context Pointer to HMAC-SHA1 context being initialized.
1097 @param[in] Key Pointer to the user-supplied key.
1098 @param[in] KeySize Key size in bytes.
1100 @retval TRUE HMAC-SHA1 context initialization succeeded.
1101 @retval FALSE HMAC-SHA1 context initialization failed.
1102 @retval FALSE This interface is not supported.
1108 OUT VOID
*HmacSha1Context
,
1109 IN CONST UINT8
*Key
,
1114 Makes a copy of an existing HMAC-SHA1 context.
1116 If HmacSha1Context is NULL, then return FALSE.
1117 If NewHmacSha1Context is NULL, then return FALSE.
1118 If this interface is not supported, then return FALSE.
1120 @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied.
1121 @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context.
1123 @retval TRUE HMAC-SHA1 context copy succeeded.
1124 @retval FALSE HMAC-SHA1 context copy failed.
1125 @retval FALSE This interface is not supported.
1131 IN CONST VOID
*HmacSha1Context
,
1132 OUT VOID
*NewHmacSha1Context
1136 Digests the input data and updates HMAC-SHA1 context.
1138 This function performs HMAC-SHA1 digest on a data buffer of the specified size.
1139 It can be called multiple times to compute the digest of long or discontinuous data streams.
1140 HMAC-SHA1 context should be already correctly initialized by HmacSha1Init(), and should not
1141 be finalized by HmacSha1Final(). Behavior with invalid context is undefined.
1143 If HmacSha1Context is NULL, then return FALSE.
1144 If this interface is not supported, then return FALSE.
1146 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1147 @param[in] Data Pointer to the buffer containing the data to be digested.
1148 @param[in] DataSize Size of Data buffer in bytes.
1150 @retval TRUE HMAC-SHA1 data digest succeeded.
1151 @retval FALSE HMAC-SHA1 data digest failed.
1152 @retval FALSE This interface is not supported.
1158 IN OUT VOID
*HmacSha1Context
,
1159 IN CONST VOID
*Data
,
1164 Completes computation of the HMAC-SHA1 digest value.
1166 This function completes HMAC-SHA1 hash computation and retrieves the digest value into
1167 the specified memory. After this function has been called, the HMAC-SHA1 context cannot
1169 HMAC-SHA1 context should be already correctly initialized by HmacSha1Init(), and should
1170 not be finalized by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined.
1172 If HmacSha1Context is NULL, then return FALSE.
1173 If HmacValue is NULL, then return FALSE.
1174 If this interface is not supported, then return FALSE.
1176 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1177 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA1 digest
1180 @retval TRUE HMAC-SHA1 digest computation succeeded.
1181 @retval FALSE HMAC-SHA1 digest computation failed.
1182 @retval FALSE This interface is not supported.
1188 IN OUT VOID
*HmacSha1Context
,
1189 OUT UINT8
*HmacValue
1193 Retrieves the size, in bytes, of the context buffer required for HMAC-SHA256 operations.
1194 (NOTE: This API is deprecated.
1195 Use HmacSha256New() / HmacSha256Free() for HMAC-SHA256 Context operations.)
1197 If this interface is not supported, then return zero.
1199 @return The size, in bytes, of the context buffer required for HMAC-SHA256 operations.
1200 @retval 0 This interface is not supported.
1205 HmacSha256GetContextSize (
1210 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
1212 @return Pointer to the HMAC_CTX context that has been initialized.
1213 If the allocations fails, HmacSha256New() returns NULL.
1223 Release the specified HMAC_CTX context.
1225 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.
1231 IN VOID
*HmacSha256Ctx
1235 Initializes user-supplied memory pointed by HmacSha256Context as HMAC-SHA256 context for
1238 If HmacSha256Context is NULL, then return FALSE.
1239 If this interface is not supported, then return FALSE.
1241 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context being initialized.
1242 @param[in] Key Pointer to the user-supplied key.
1243 @param[in] KeySize Key size in bytes.
1245 @retval TRUE HMAC-SHA256 context initialization succeeded.
1246 @retval FALSE HMAC-SHA256 context initialization failed.
1247 @retval FALSE This interface is not supported.
1253 OUT VOID
*HmacSha256Context
,
1254 IN CONST UINT8
*Key
,
1259 Makes a copy of an existing HMAC-SHA256 context.
1261 If HmacSha256Context is NULL, then return FALSE.
1262 If NewHmacSha256Context is NULL, then return FALSE.
1263 If this interface is not supported, then return FALSE.
1265 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.
1266 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.
1268 @retval TRUE HMAC-SHA256 context copy succeeded.
1269 @retval FALSE HMAC-SHA256 context copy failed.
1270 @retval FALSE This interface is not supported.
1275 HmacSha256Duplicate (
1276 IN CONST VOID
*HmacSha256Context
,
1277 OUT VOID
*NewHmacSha256Context
1281 Digests the input data and updates HMAC-SHA256 context.
1283 This function performs HMAC-SHA256 digest on a data buffer of the specified size.
1284 It can be called multiple times to compute the digest of long or discontinuous data streams.
1285 HMAC-SHA256 context should be already correctly initialized by HmacSha256Init(), and should not
1286 be finalized by HmacSha256Final(). Behavior with invalid context is undefined.
1288 If HmacSha256Context is NULL, then return FALSE.
1289 If this interface is not supported, then return FALSE.
1291 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1292 @param[in] Data Pointer to the buffer containing the data to be digested.
1293 @param[in] DataSize Size of Data buffer in bytes.
1295 @retval TRUE HMAC-SHA256 data digest succeeded.
1296 @retval FALSE HMAC-SHA256 data digest failed.
1297 @retval FALSE This interface is not supported.
1303 IN OUT VOID
*HmacSha256Context
,
1304 IN CONST VOID
*Data
,
1309 Completes computation of the HMAC-SHA256 digest value.
1311 This function completes HMAC-SHA256 hash computation and retrieves the digest value into
1312 the specified memory. After this function has been called, the HMAC-SHA256 context cannot
1314 HMAC-SHA256 context should be already correctly initialized by HmacSha256Init(), and should
1315 not be finalized by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.
1317 If HmacSha256Context is NULL, then return FALSE.
1318 If HmacValue is NULL, then return FALSE.
1319 If this interface is not supported, then return FALSE.
1321 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1322 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
1325 @retval TRUE HMAC-SHA256 digest computation succeeded.
1326 @retval FALSE HMAC-SHA256 digest computation failed.
1327 @retval FALSE This interface is not supported.
1333 IN OUT VOID
*HmacSha256Context
,
1334 OUT UINT8
*HmacValue
1337 //=====================================================================================
1338 // Symmetric Cryptography Primitive
1339 //=====================================================================================
1342 Retrieves the size, in bytes, of the context buffer required for TDES operations.
1344 If this interface is not supported, then return zero.
1346 @return The size, in bytes, of the context buffer required for TDES operations.
1347 @retval 0 This interface is not supported.
1352 TdesGetContextSize (
1357 Initializes user-supplied memory as TDES context for subsequent use.
1359 This function initializes user-supplied memory pointed by TdesContext as TDES context.
1360 In addition, it sets up all TDES key materials for subsequent encryption and decryption
1362 There are 3 key options as follows:
1363 KeyLength = 64, Keying option 1: K1 == K2 == K3 (Backward compatibility with DES)
1364 KeyLength = 128, Keying option 2: K1 != K2 and K3 = K1 (Less Security)
1365 KeyLength = 192 Keying option 3: K1 != K2 != K3 (Strongest)
1367 If TdesContext is NULL, then return FALSE.
1368 If Key is NULL, then return FALSE.
1369 If KeyLength is not valid, then return FALSE.
1370 If this interface is not supported, then return FALSE.
1372 @param[out] TdesContext Pointer to TDES context being initialized.
1373 @param[in] Key Pointer to the user-supplied TDES key.
1374 @param[in] KeyLength Length of TDES key in bits.
1376 @retval TRUE TDES context initialization succeeded.
1377 @retval FALSE TDES context initialization failed.
1378 @retval FALSE This interface is not supported.
1384 OUT VOID
*TdesContext
,
1385 IN CONST UINT8
*Key
,
1390 Performs TDES encryption on a data buffer of the specified size in ECB mode.
1392 This function performs TDES encryption on data buffer pointed by Input, of specified
1393 size of InputSize, in ECB mode.
1394 InputSize must be multiple of block size (8 bytes). This function does not perform
1395 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1396 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1397 invalid TDES context is undefined.
1399 If TdesContext is NULL, then return FALSE.
1400 If Input is NULL, then return FALSE.
1401 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1402 If Output is NULL, then return FALSE.
1403 If this interface is not supported, then return FALSE.
1405 @param[in] TdesContext Pointer to the TDES context.
1406 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1407 @param[in] InputSize Size of the Input buffer in bytes.
1408 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1410 @retval TRUE TDES encryption succeeded.
1411 @retval FALSE TDES encryption failed.
1412 @retval FALSE This interface is not supported.
1418 IN VOID
*TdesContext
,
1419 IN CONST UINT8
*Input
,
1425 Performs TDES decryption on a data buffer of the specified size in ECB mode.
1427 This function performs TDES decryption on data buffer pointed by Input, of specified
1428 size of InputSize, in ECB mode.
1429 InputSize must be multiple of block size (8 bytes). This function does not perform
1430 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1431 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1432 invalid TDES context is undefined.
1434 If TdesContext is NULL, then return FALSE.
1435 If Input is NULL, then return FALSE.
1436 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1437 If Output is NULL, then return FALSE.
1438 If this interface is not supported, then return FALSE.
1440 @param[in] TdesContext Pointer to the TDES context.
1441 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1442 @param[in] InputSize Size of the Input buffer in bytes.
1443 @param[out] Output Pointer to a buffer that receives the TDES decryption output.
1445 @retval TRUE TDES decryption succeeded.
1446 @retval FALSE TDES decryption failed.
1447 @retval FALSE This interface is not supported.
1453 IN VOID
*TdesContext
,
1454 IN CONST UINT8
*Input
,
1460 Performs TDES encryption on a data buffer of the specified size in CBC mode.
1462 This function performs TDES encryption on data buffer pointed by Input, of specified
1463 size of InputSize, in CBC mode.
1464 InputSize must be multiple of block size (8 bytes). This function does not perform
1465 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1466 Initialization vector should be one block size (8 bytes).
1467 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1468 invalid TDES context is undefined.
1470 If TdesContext is NULL, then return FALSE.
1471 If Input is NULL, then return FALSE.
1472 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1473 If Ivec is NULL, then return FALSE.
1474 If Output is NULL, then return FALSE.
1475 If this interface is not supported, then return FALSE.
1477 @param[in] TdesContext Pointer to the TDES context.
1478 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1479 @param[in] InputSize Size of the Input buffer in bytes.
1480 @param[in] Ivec Pointer to initialization vector.
1481 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1483 @retval TRUE TDES encryption succeeded.
1484 @retval FALSE TDES encryption failed.
1485 @retval FALSE This interface is not supported.
1491 IN VOID
*TdesContext
,
1492 IN CONST UINT8
*Input
,
1494 IN CONST UINT8
*Ivec
,
1499 Performs TDES decryption on a data buffer of the specified size in CBC mode.
1501 This function performs TDES decryption on data buffer pointed by Input, of specified
1502 size of InputSize, in CBC mode.
1503 InputSize must be multiple of block size (8 bytes). This function does not perform
1504 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1505 Initialization vector should be one block size (8 bytes).
1506 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1507 invalid TDES context is undefined.
1509 If TdesContext is NULL, then return FALSE.
1510 If Input is NULL, then return FALSE.
1511 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1512 If Ivec is NULL, then return FALSE.
1513 If Output is NULL, then return FALSE.
1514 If this interface is not supported, then return FALSE.
1516 @param[in] TdesContext Pointer to the TDES context.
1517 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1518 @param[in] InputSize Size of the Input buffer in bytes.
1519 @param[in] Ivec Pointer to initialization vector.
1520 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1522 @retval TRUE TDES decryption succeeded.
1523 @retval FALSE TDES decryption failed.
1524 @retval FALSE This interface is not supported.
1530 IN VOID
*TdesContext
,
1531 IN CONST UINT8
*Input
,
1533 IN CONST UINT8
*Ivec
,
1538 Retrieves the size, in bytes, of the context buffer required for AES operations.
1540 If this interface is not supported, then return zero.
1542 @return The size, in bytes, of the context buffer required for AES operations.
1543 @retval 0 This interface is not supported.
1553 Initializes user-supplied memory as AES context for subsequent use.
1555 This function initializes user-supplied memory pointed by AesContext as AES context.
1556 In addition, it sets up all AES key materials for subsequent encryption and decryption
1558 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1560 If AesContext is NULL, then return FALSE.
1561 If Key is NULL, then return FALSE.
1562 If KeyLength is not valid, then return FALSE.
1563 If this interface is not supported, then return FALSE.
1565 @param[out] AesContext Pointer to AES context being initialized.
1566 @param[in] Key Pointer to the user-supplied AES key.
1567 @param[in] KeyLength Length of AES key in bits.
1569 @retval TRUE AES context initialization succeeded.
1570 @retval FALSE AES context initialization failed.
1571 @retval FALSE This interface is not supported.
1577 OUT VOID
*AesContext
,
1578 IN CONST UINT8
*Key
,
1583 Performs AES encryption on a data buffer of the specified size in ECB mode.
1585 This function performs AES encryption on data buffer pointed by Input, of specified
1586 size of InputSize, in ECB mode.
1587 InputSize must be multiple of block size (16 bytes). This function does not perform
1588 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1589 AesContext should be already correctly initialized by AesInit(). Behavior with
1590 invalid AES context is undefined.
1592 If AesContext is NULL, then return FALSE.
1593 If Input is NULL, then return FALSE.
1594 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1595 If Output is NULL, then return FALSE.
1596 If this interface is not supported, then return FALSE.
1598 @param[in] AesContext Pointer to the AES context.
1599 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1600 @param[in] InputSize Size of the Input buffer in bytes.
1601 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1603 @retval TRUE AES encryption succeeded.
1604 @retval FALSE AES encryption failed.
1605 @retval FALSE This interface is not supported.
1611 IN VOID
*AesContext
,
1612 IN CONST UINT8
*Input
,
1618 Performs AES decryption on a data buffer of the specified size in ECB mode.
1620 This function performs AES decryption on data buffer pointed by Input, of specified
1621 size of InputSize, in ECB mode.
1622 InputSize must be multiple of block size (16 bytes). This function does not perform
1623 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1624 AesContext should be already correctly initialized by AesInit(). Behavior with
1625 invalid AES context is undefined.
1627 If AesContext is NULL, then return FALSE.
1628 If Input is NULL, then return FALSE.
1629 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1630 If Output is NULL, then return FALSE.
1631 If this interface is not supported, then return FALSE.
1633 @param[in] AesContext Pointer to the AES context.
1634 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1635 @param[in] InputSize Size of the Input buffer in bytes.
1636 @param[out] Output Pointer to a buffer that receives the AES decryption output.
1638 @retval TRUE AES decryption succeeded.
1639 @retval FALSE AES decryption failed.
1640 @retval FALSE This interface is not supported.
1646 IN VOID
*AesContext
,
1647 IN CONST UINT8
*Input
,
1653 Performs AES encryption on a data buffer of the specified size in CBC mode.
1655 This function performs AES encryption on data buffer pointed by Input, of specified
1656 size of InputSize, in CBC mode.
1657 InputSize must be multiple of block size (16 bytes). This function does not perform
1658 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1659 Initialization vector should be one block size (16 bytes).
1660 AesContext should be already correctly initialized by AesInit(). Behavior with
1661 invalid AES context is undefined.
1663 If AesContext is NULL, then return FALSE.
1664 If Input is NULL, then return FALSE.
1665 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1666 If Ivec is NULL, then return FALSE.
1667 If Output is NULL, then return FALSE.
1668 If this interface is not supported, then return FALSE.
1670 @param[in] AesContext Pointer to the AES context.
1671 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1672 @param[in] InputSize Size of the Input buffer in bytes.
1673 @param[in] Ivec Pointer to initialization vector.
1674 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1676 @retval TRUE AES encryption succeeded.
1677 @retval FALSE AES encryption failed.
1678 @retval FALSE This interface is not supported.
1684 IN VOID
*AesContext
,
1685 IN CONST UINT8
*Input
,
1687 IN CONST UINT8
*Ivec
,
1692 Performs AES decryption on a data buffer of the specified size in CBC mode.
1694 This function performs AES decryption on data buffer pointed by Input, of specified
1695 size of InputSize, in CBC mode.
1696 InputSize must be multiple of block size (16 bytes). This function does not perform
1697 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1698 Initialization vector should be one block size (16 bytes).
1699 AesContext should be already correctly initialized by AesInit(). Behavior with
1700 invalid AES context is undefined.
1702 If AesContext is NULL, then return FALSE.
1703 If Input is NULL, then return FALSE.
1704 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1705 If Ivec is NULL, then return FALSE.
1706 If Output is NULL, then return FALSE.
1707 If this interface is not supported, then return FALSE.
1709 @param[in] AesContext Pointer to the AES context.
1710 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1711 @param[in] InputSize Size of the Input buffer in bytes.
1712 @param[in] Ivec Pointer to initialization vector.
1713 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1715 @retval TRUE AES decryption succeeded.
1716 @retval FALSE AES decryption failed.
1717 @retval FALSE This interface is not supported.
1723 IN VOID
*AesContext
,
1724 IN CONST UINT8
*Input
,
1726 IN CONST UINT8
*Ivec
,
1731 Retrieves the size, in bytes, of the context buffer required for ARC4 operations.
1733 If this interface is not supported, then return zero.
1735 @return The size, in bytes, of the context buffer required for ARC4 operations.
1736 @retval 0 This interface is not supported.
1741 Arc4GetContextSize (
1746 Initializes user-supplied memory as ARC4 context for subsequent use.
1748 This function initializes user-supplied memory pointed by Arc4Context as ARC4 context.
1749 In addition, it sets up all ARC4 key materials for subsequent encryption and decryption
1752 If Arc4Context is NULL, then return FALSE.
1753 If Key is NULL, then return FALSE.
1754 If KeySize does not in the range of [5, 256] bytes, then return FALSE.
1755 If this interface is not supported, then return FALSE.
1757 @param[out] Arc4Context Pointer to ARC4 context being initialized.
1758 @param[in] Key Pointer to the user-supplied ARC4 key.
1759 @param[in] KeySize Size of ARC4 key in bytes.
1761 @retval TRUE ARC4 context initialization succeeded.
1762 @retval FALSE ARC4 context initialization failed.
1763 @retval FALSE This interface is not supported.
1769 OUT VOID
*Arc4Context
,
1770 IN CONST UINT8
*Key
,
1775 Performs ARC4 encryption on a data buffer of the specified size.
1777 This function performs ARC4 encryption on data buffer pointed by Input, of specified
1779 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
1780 invalid ARC4 context is undefined.
1782 If Arc4Context is NULL, then return FALSE.
1783 If Input is NULL, then return FALSE.
1784 If Output is NULL, then return FALSE.
1785 If this interface is not supported, then return FALSE.
1787 @param[in, out] Arc4Context Pointer to the ARC4 context.
1788 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1789 @param[in] InputSize Size of the Input buffer in bytes.
1790 @param[out] Output Pointer to a buffer that receives the ARC4 encryption output.
1792 @retval TRUE ARC4 encryption succeeded.
1793 @retval FALSE ARC4 encryption failed.
1794 @retval FALSE This interface is not supported.
1800 IN OUT VOID
*Arc4Context
,
1801 IN CONST UINT8
*Input
,
1807 Performs ARC4 decryption on a data buffer of the specified size.
1809 This function performs ARC4 decryption on data buffer pointed by Input, of specified
1811 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
1812 invalid ARC4 context is undefined.
1814 If Arc4Context is NULL, then return FALSE.
1815 If Input is NULL, then return FALSE.
1816 If Output is NULL, then return FALSE.
1817 If this interface is not supported, then return FALSE.
1819 @param[in, out] Arc4Context Pointer to the ARC4 context.
1820 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1821 @param[in] InputSize Size of the Input buffer in bytes.
1822 @param[out] Output Pointer to a buffer that receives the ARC4 decryption output.
1824 @retval TRUE ARC4 decryption succeeded.
1825 @retval FALSE ARC4 decryption failed.
1826 @retval FALSE This interface is not supported.
1832 IN OUT VOID
*Arc4Context
,
1839 Resets the ARC4 context to the initial state.
1841 The function resets the ARC4 context to the state it had immediately after the
1842 ARC4Init() function call.
1843 Contrary to ARC4Init(), Arc4Reset() requires no secret key as input, but ARC4 context
1844 should be already correctly initialized by ARC4Init().
1846 If Arc4Context is NULL, then return FALSE.
1847 If this interface is not supported, then return FALSE.
1849 @param[in, out] Arc4Context Pointer to the ARC4 context.
1851 @retval TRUE ARC4 reset succeeded.
1852 @retval FALSE ARC4 reset failed.
1853 @retval FALSE This interface is not supported.
1859 IN OUT VOID
*Arc4Context
1862 //=====================================================================================
1863 // Asymmetric Cryptography Primitive
1864 //=====================================================================================
1867 Allocates and initializes one RSA context for subsequent use.
1869 @return Pointer to the RSA context that has been initialized.
1870 If the allocations fails, RsaNew() returns NULL.
1880 Release the specified RSA context.
1882 If RsaContext is NULL, then return FALSE.
1884 @param[in] RsaContext Pointer to the RSA context to be released.
1894 Sets the tag-designated key component into the established RSA context.
1896 This function sets the tag-designated RSA key component into the established
1897 RSA context from the user-specified non-negative integer (octet string format
1898 represented in RSA PKCS#1).
1899 If BigNumber is NULL, then the specified key component in RSA context is cleared.
1901 If RsaContext is NULL, then return FALSE.
1903 @param[in, out] RsaContext Pointer to RSA context being set.
1904 @param[in] KeyTag Tag of RSA key component being set.
1905 @param[in] BigNumber Pointer to octet integer buffer.
1906 If NULL, then the specified key component in RSA
1908 @param[in] BnSize Size of big number buffer in bytes.
1909 If BigNumber is NULL, then it is ignored.
1911 @retval TRUE RSA key component was set successfully.
1912 @retval FALSE Invalid RSA key component tag.
1918 IN OUT VOID
*RsaContext
,
1919 IN RSA_KEY_TAG KeyTag
,
1920 IN CONST UINT8
*BigNumber
,
1925 Gets the tag-designated RSA key component from the established RSA context.
1927 This function retrieves the tag-designated RSA key component from the
1928 established RSA context as a non-negative integer (octet string format
1929 represented in RSA PKCS#1).
1930 If specified key component has not been set or has been cleared, then returned
1932 If the BigNumber buffer is too small to hold the contents of the key, FALSE
1933 is returned and BnSize is set to the required buffer size to obtain the key.
1935 If RsaContext is NULL, then return FALSE.
1936 If BnSize is NULL, then return FALSE.
1937 If BnSize is large enough but BigNumber is NULL, then return FALSE.
1938 If this interface is not supported, then return FALSE.
1940 @param[in, out] RsaContext Pointer to RSA context being set.
1941 @param[in] KeyTag Tag of RSA key component being set.
1942 @param[out] BigNumber Pointer to octet integer buffer.
1943 @param[in, out] BnSize On input, the size of big number buffer in bytes.
1944 On output, the size of data returned in big number buffer in bytes.
1946 @retval TRUE RSA key component was retrieved successfully.
1947 @retval FALSE Invalid RSA key component tag.
1948 @retval FALSE BnSize is too small.
1949 @retval FALSE This interface is not supported.
1955 IN OUT VOID
*RsaContext
,
1956 IN RSA_KEY_TAG KeyTag
,
1957 OUT UINT8
*BigNumber
,
1958 IN OUT UINTN
*BnSize
1962 Generates RSA key components.
1964 This function generates RSA key components. It takes RSA public exponent E and
1965 length in bits of RSA modulus N as input, and generates all key components.
1966 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
1968 Before this function can be invoked, pseudorandom number generator must be correctly
1969 initialized by RandomSeed().
1971 If RsaContext is NULL, then return FALSE.
1972 If this interface is not supported, then return FALSE.
1974 @param[in, out] RsaContext Pointer to RSA context being set.
1975 @param[in] ModulusLength Length of RSA modulus N in bits.
1976 @param[in] PublicExponent Pointer to RSA public exponent.
1977 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
1979 @retval TRUE RSA key component was generated successfully.
1980 @retval FALSE Invalid RSA key component tag.
1981 @retval FALSE This interface is not supported.
1987 IN OUT VOID
*RsaContext
,
1988 IN UINTN ModulusLength
,
1989 IN CONST UINT8
*PublicExponent
,
1990 IN UINTN PublicExponentSize
1994 Validates key components of RSA context.
1995 NOTE: This function performs integrity checks on all the RSA key material, so
1996 the RSA key structure must contain all the private key data.
1998 This function validates key components of RSA context in following aspects:
1999 - Whether p is a prime
2000 - Whether q is a prime
2002 - Whether d*e = 1 mod lcm(p-1,q-1)
2004 If RsaContext is NULL, then return FALSE.
2005 If this interface is not supported, then return FALSE.
2007 @param[in] RsaContext Pointer to RSA context to check.
2009 @retval TRUE RSA key components are valid.
2010 @retval FALSE RSA key components are not valid.
2011 @retval FALSE This interface is not supported.
2021 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
2023 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
2025 If the Signature buffer is too small to hold the contents of signature, FALSE
2026 is returned and SigSize is set to the required buffer size to obtain the signature.
2028 If RsaContext is NULL, then return FALSE.
2029 If MessageHash is NULL, then return FALSE.
2030 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
2031 If SigSize is large enough but Signature is NULL, then return FALSE.
2032 If this interface is not supported, then return FALSE.
2034 @param[in] RsaContext Pointer to RSA context for signature generation.
2035 @param[in] MessageHash Pointer to octet message hash to be signed.
2036 @param[in] HashSize Size of the message hash in bytes.
2037 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
2038 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
2039 On output, the size of data returned in Signature buffer in bytes.
2041 @retval TRUE Signature successfully generated in PKCS1-v1_5.
2042 @retval FALSE Signature generation failed.
2043 @retval FALSE SigSize is too small.
2044 @retval FALSE This interface is not supported.
2050 IN VOID
*RsaContext
,
2051 IN CONST UINT8
*MessageHash
,
2053 OUT UINT8
*Signature
,
2054 IN OUT UINTN
*SigSize
2058 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
2061 If RsaContext is NULL, then return FALSE.
2062 If MessageHash is NULL, then return FALSE.
2063 If Signature is NULL, then return FALSE.
2064 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
2066 @param[in] RsaContext Pointer to RSA context for signature verification.
2067 @param[in] MessageHash Pointer to octet message hash to be checked.
2068 @param[in] HashSize Size of the message hash in bytes.
2069 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
2070 @param[in] SigSize Size of signature in bytes.
2072 @retval TRUE Valid signature encoded in PKCS1-v1_5.
2073 @retval FALSE Invalid signature or invalid RSA context.
2079 IN VOID
*RsaContext
,
2080 IN CONST UINT8
*MessageHash
,
2082 IN CONST UINT8
*Signature
,
2087 Retrieve the RSA Private Key from the password-protected PEM key data.
2089 If PemData is NULL, then return FALSE.
2090 If RsaContext is NULL, then return FALSE.
2091 If this interface is not supported, then return FALSE.
2093 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
2094 @param[in] PemSize Size of the PEM key data in bytes.
2095 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
2096 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2097 RSA private key component. Use RsaFree() function to free the
2100 @retval TRUE RSA Private Key was retrieved successfully.
2101 @retval FALSE Invalid PEM key data or incorrect password.
2102 @retval FALSE This interface is not supported.
2107 RsaGetPrivateKeyFromPem (
2108 IN CONST UINT8
*PemData
,
2110 IN CONST CHAR8
*Password
,
2111 OUT VOID
**RsaContext
2115 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
2117 If Cert is NULL, then return FALSE.
2118 If RsaContext is NULL, then return FALSE.
2119 If this interface is not supported, then return FALSE.
2121 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2122 @param[in] CertSize Size of the X509 certificate in bytes.
2123 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2124 RSA public key component. Use RsaFree() function to free the
2127 @retval TRUE RSA Public Key was retrieved successfully.
2128 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
2129 @retval FALSE This interface is not supported.
2134 RsaGetPublicKeyFromX509 (
2135 IN CONST UINT8
*Cert
,
2137 OUT VOID
**RsaContext
2141 Retrieve the subject bytes from one X.509 certificate.
2143 If Cert is NULL, then return FALSE.
2144 If SubjectSize is NULL, then return FALSE.
2145 If this interface is not supported, then return FALSE.
2147 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2148 @param[in] CertSize Size of the X509 certificate in bytes.
2149 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
2150 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
2151 and the size of buffer returned CertSubject on output.
2153 @retval TRUE The certificate subject retrieved successfully.
2154 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
2155 The SubjectSize will be updated with the required size.
2156 @retval FALSE This interface is not supported.
2161 X509GetSubjectName (
2162 IN CONST UINT8
*Cert
,
2164 OUT UINT8
*CertSubject
,
2165 IN OUT UINTN
*SubjectSize
2169 Retrieve the common name (CN) string from one X.509 certificate.
2171 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2172 @param[in] CertSize Size of the X509 certificate in bytes.
2173 @param[out] CommonName Buffer to contain the retrieved certificate common
2174 name string (UTF8). At most CommonNameSize bytes will be
2175 written and the string will be null terminated. May be
2176 NULL in order to determine the size buffer needed.
2177 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
2178 and the size of buffer returned CommonName on output.
2179 If CommonName is NULL then the amount of space needed
2180 in buffer (including the final null) is returned.
2182 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
2183 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2184 If CommonNameSize is NULL.
2185 If CommonName is not NULL and *CommonNameSize is 0.
2186 If Certificate is invalid.
2187 @retval RETURN_NOT_FOUND If no CommonName entry exists.
2188 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
2189 (including the final null) is returned in the
2190 CommonNameSize parameter.
2191 @retval RETURN_UNSUPPORTED The operation is not supported.
2197 IN CONST UINT8
*Cert
,
2199 OUT CHAR8
*CommonName
, OPTIONAL
2200 IN OUT UINTN
*CommonNameSize
2204 Verify one X509 certificate was issued by the trusted CA.
2206 If Cert is NULL, then return FALSE.
2207 If CACert is NULL, then return FALSE.
2208 If this interface is not supported, then return FALSE.
2210 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
2211 @param[in] CertSize Size of the X509 certificate in bytes.
2212 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
2213 @param[in] CACertSize Size of the CA Certificate in bytes.
2215 @retval TRUE The certificate was issued by the trusted CA.
2216 @retval FALSE Invalid certificate or the certificate was not issued by the given
2218 @retval FALSE This interface is not supported.
2224 IN CONST UINT8
*Cert
,
2226 IN CONST UINT8
*CACert
,
2231 Construct a X509 object from DER-encoded certificate data.
2233 If Cert is NULL, then return FALSE.
2234 If SingleX509Cert is NULL, then return FALSE.
2235 If this interface is not supported, then return FALSE.
2237 @param[in] Cert Pointer to the DER-encoded certificate data.
2238 @param[in] CertSize The size of certificate data in bytes.
2239 @param[out] SingleX509Cert The generated X509 object.
2241 @retval TRUE The X509 object generation succeeded.
2242 @retval FALSE The operation failed.
2243 @retval FALSE This interface is not supported.
2248 X509ConstructCertificate (
2249 IN CONST UINT8
*Cert
,
2251 OUT UINT8
**SingleX509Cert
2255 Construct a X509 stack object from a list of DER-encoded certificate data.
2257 If X509Stack is NULL, then return FALSE.
2258 If this interface is not supported, then return FALSE.
2260 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2261 On output, pointer to the X509 stack object with new
2262 inserted X509 certificate.
2263 @param ... A list of DER-encoded single certificate data followed
2264 by certificate size. A NULL terminates the list. The
2265 pairs are the arguments to X509ConstructCertificate().
2267 @retval TRUE The X509 stack construction succeeded.
2268 @retval FALSE The construction operation failed.
2269 @retval FALSE This interface is not supported.
2274 X509ConstructCertificateStack (
2275 IN OUT UINT8
**X509Stack
,
2280 Release the specified X509 object.
2282 If the interface is not supported, then ASSERT().
2284 @param[in] X509Cert Pointer to the X509 object to be released.
2294 Release the specified X509 stack object.
2296 If the interface is not supported, then ASSERT().
2298 @param[in] X509Stack Pointer to the X509 stack object to be released.
2308 Retrieve the TBSCertificate from one given X.509 certificate.
2310 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
2311 @param[in] CertSize Size of the X509 certificate in bytes.
2312 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
2313 @param[out] TBSCertSize Size of the TBS certificate in bytes.
2315 If Cert is NULL, then return FALSE.
2316 If TBSCert is NULL, then return FALSE.
2317 If TBSCertSize is NULL, then return FALSE.
2318 If this interface is not supported, then return FALSE.
2320 @retval TRUE The TBSCertificate was retrieved successfully.
2321 @retval FALSE Invalid X.509 certificate.
2327 IN CONST UINT8
*Cert
,
2329 OUT UINT8
**TBSCert
,
2330 OUT UINTN
*TBSCertSize
2334 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2335 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2337 If Password or Salt or OutKey is NULL, then return FALSE.
2338 If the hash algorithm could not be determined, then return FALSE.
2339 If this interface is not supported, then return FALSE.
2341 @param[in] PasswordLength Length of input password in bytes.
2342 @param[in] Password Pointer to the array for the password.
2343 @param[in] SaltLength Size of the Salt in bytes.
2344 @param[in] Salt Pointer to the Salt.
2345 @param[in] IterationCount Number of iterations to perform. Its value should be
2346 greater than or equal to 1.
2347 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2348 NOTE: DigestSize will be used to determine the hash algorithm.
2349 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2350 @param[in] KeyLength Size of the derived key buffer in bytes.
2351 @param[out] OutKey Pointer to the output derived key buffer.
2353 @retval TRUE A key was derived successfully.
2354 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2355 @retval FALSE The hash algorithm could not be determined from the digest size.
2356 @retval FALSE The key derivation operation failed.
2357 @retval FALSE This interface is not supported.
2363 IN UINTN PasswordLength
,
2364 IN CONST CHAR8
*Password
,
2365 IN UINTN SaltLength
,
2366 IN CONST UINT8
*Salt
,
2367 IN UINTN IterationCount
,
2368 IN UINTN DigestSize
,
2374 The 3rd parameter of Pkcs7GetSigners will return all embedded
2375 X.509 certificate in one given PKCS7 signature. The format is:
2377 // UINT8 CertNumber;
2378 // UINT32 Cert1Length;
2380 // UINT32 Cert2Length;
2383 // UINT32 CertnLength;
2387 The two following C-structure are used for parsing CertStack more clearly.
2392 UINT32 CertDataLength
; // The length in bytes of X.509 certificate.
2393 UINT8 CertDataBuffer
[0]; // The X.509 certificate content (DER).
2397 UINT8 CertNumber
; // Number of X.509 certificate.
2398 //EFI_CERT_DATA CertArray[]; // An array of X.509 certificate.
2404 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2405 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2406 in a ContentInfo structure.
2408 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2409 return FALSE. If P7Length overflow, then return FALSE.
2410 If this interface is not supported, then return FALSE.
2412 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2413 @param[in] P7Length Length of the PKCS#7 message in bytes.
2414 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2415 It's caller's responsibility to free the buffer with
2417 This data structure is EFI_CERT_STACK type.
2418 @param[out] StackLength Length of signer's certificates in bytes.
2419 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2420 It's caller's responsibility to free the buffer with
2422 @param[out] CertLength Length of the trusted certificate in bytes.
2424 @retval TRUE The operation is finished successfully.
2425 @retval FALSE Error occurs during the operation.
2426 @retval FALSE This interface is not supported.
2432 IN CONST UINT8
*P7Data
,
2434 OUT UINT8
**CertStack
,
2435 OUT UINTN
*StackLength
,
2436 OUT UINT8
**TrustedCert
,
2437 OUT UINTN
*CertLength
2441 Wrap function to use free() to free allocated memory for certificates.
2443 If this interface is not supported, then ASSERT().
2445 @param[in] Certs Pointer to the certificates to be freed.
2455 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2456 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2457 unchained to the signer's certificates.
2458 The input signed data could be wrapped in a ContentInfo structure.
2460 @param[in] P7Data Pointer to the PKCS#7 message.
2461 @param[in] P7Length Length of the PKCS#7 message in bytes.
2462 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2463 certificate. It's caller's responsibility to free the buffer
2464 with Pkcs7FreeSigners().
2465 This data structure is EFI_CERT_STACK type.
2466 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2467 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2468 responsibility to free the buffer with Pkcs7FreeSigners().
2469 This data structure is EFI_CERT_STACK type.
2470 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2472 @retval TRUE The operation is finished successfully.
2473 @retval FALSE Error occurs during the operation.
2478 Pkcs7GetCertificatesList (
2479 IN CONST UINT8
*P7Data
,
2481 OUT UINT8
**SignerChainCerts
,
2482 OUT UINTN
*ChainLength
,
2483 OUT UINT8
**UnchainCerts
,
2484 OUT UINTN
*UnchainLength
2488 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2489 Syntax Standard, version 1.5". This interface is only intended to be used for
2490 application to perform PKCS#7 functionality validation.
2492 If this interface is not supported, then return FALSE.
2494 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2496 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2497 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2499 @param[in] InData Pointer to the content to be signed.
2500 @param[in] InDataSize Size of InData in bytes.
2501 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2502 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2503 include in the PKCS#7 signedData (e.g. any intermediate
2505 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2506 responsibility to free the buffer with FreePool().
2507 @param[out] SignedDataSize Size of SignedData in bytes.
2509 @retval TRUE PKCS#7 data signing succeeded.
2510 @retval FALSE PKCS#7 data signing failed.
2511 @retval FALSE This interface is not supported.
2517 IN CONST UINT8
*PrivateKey
,
2518 IN UINTN PrivateKeySize
,
2519 IN CONST UINT8
*KeyPassword
,
2521 IN UINTN InDataSize
,
2523 IN UINT8
*OtherCerts OPTIONAL
,
2524 OUT UINT8
**SignedData
,
2525 OUT UINTN
*SignedDataSize
2529 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2530 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2531 in a ContentInfo structure.
2533 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2534 If P7Length, CertLength or DataLength overflow, then return FALSE.
2535 If this interface is not supported, then return FALSE.
2537 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2538 @param[in] P7Length Length of the PKCS#7 message in bytes.
2539 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2540 is used for certificate chain verification.
2541 @param[in] CertLength Length of the trusted certificate in bytes.
2542 @param[in] InData Pointer to the content to be verified.
2543 @param[in] DataLength Length of InData in bytes.
2545 @retval TRUE The specified PKCS#7 signed data is valid.
2546 @retval FALSE Invalid PKCS#7 signed data.
2547 @retval FALSE This interface is not supported.
2553 IN CONST UINT8
*P7Data
,
2555 IN CONST UINT8
*TrustedCert
,
2556 IN UINTN CertLength
,
2557 IN CONST UINT8
*InData
,
2562 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2563 data could be wrapped in a ContentInfo structure.
2565 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2566 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2568 Caution: This function may receive untrusted input. So this function will do
2569 basic check for PKCS#7 data structure.
2571 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2572 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2573 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2574 It's caller's responsibility to free the buffer with FreePool().
2575 @param[out] ContentSize The size of the extracted content in bytes.
2577 @retval TRUE The P7Data was correctly formatted for processing.
2578 @retval FALSE The P7Data was not correctly formatted for processing.
2583 Pkcs7GetAttachedContent (
2584 IN CONST UINT8
*P7Data
,
2587 OUT UINTN
*ContentSize
2591 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2592 Authenticode Portable Executable Signature Format".
2594 If AuthData is NULL, then return FALSE.
2595 If ImageHash is NULL, then return FALSE.
2596 If this interface is not supported, then return FALSE.
2598 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2599 PE/COFF image to be verified.
2600 @param[in] DataSize Size of the Authenticode Signature in bytes.
2601 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2602 is used for certificate chain verification.
2603 @param[in] CertSize Size of the trusted certificate in bytes.
2604 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2605 for calculating the image hash value is described in Authenticode
2607 @param[in] HashSize Size of Image hash value in bytes.
2609 @retval TRUE The specified Authenticode Signature is valid.
2610 @retval FALSE Invalid Authenticode Signature.
2611 @retval FALSE This interface is not supported.
2616 AuthenticodeVerify (
2617 IN CONST UINT8
*AuthData
,
2619 IN CONST UINT8
*TrustedCert
,
2621 IN CONST UINT8
*ImageHash
,
2626 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2629 If AuthData is NULL, then return FALSE.
2630 If this interface is not supported, then return FALSE.
2632 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2633 PE/COFF image to be verified.
2634 @param[in] DataSize Size of the Authenticode Signature in bytes.
2635 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2636 is used for TSA certificate chain verification.
2637 @param[in] CertSize Size of the trusted certificate in bytes.
2638 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2641 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2642 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2647 ImageTimestampVerify (
2648 IN CONST UINT8
*AuthData
,
2650 IN CONST UINT8
*TsaCert
,
2652 OUT EFI_TIME
*SigningTime
2655 //=====================================================================================
2656 // DH Key Exchange Primitive
2657 //=====================================================================================
2660 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
2662 @return Pointer to the Diffie-Hellman Context that has been initialized.
2663 If the allocations fails, DhNew() returns NULL.
2664 If the interface is not supported, DhNew() returns NULL.
2674 Release the specified DH context.
2676 If the interface is not supported, then ASSERT().
2678 @param[in] DhContext Pointer to the DH context to be released.
2688 Generates DH parameter.
2690 Given generator g, and length of prime number p in bits, this function generates p,
2691 and sets DH context according to value of g and p.
2693 Before this function can be invoked, pseudorandom number generator must be correctly
2694 initialized by RandomSeed().
2696 If DhContext is NULL, then return FALSE.
2697 If Prime is NULL, then return FALSE.
2698 If this interface is not supported, then return FALSE.
2700 @param[in, out] DhContext Pointer to the DH context.
2701 @param[in] Generator Value of generator.
2702 @param[in] PrimeLength Length in bits of prime to be generated.
2703 @param[out] Prime Pointer to the buffer to receive the generated prime number.
2705 @retval TRUE DH parameter generation succeeded.
2706 @retval FALSE Value of Generator is not supported.
2707 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
2708 @retval FALSE This interface is not supported.
2713 DhGenerateParameter (
2714 IN OUT VOID
*DhContext
,
2716 IN UINTN PrimeLength
,
2721 Sets generator and prime parameters for DH.
2723 Given generator g, and prime number p, this function and sets DH
2724 context accordingly.
2726 If DhContext is NULL, then return FALSE.
2727 If Prime is NULL, then return FALSE.
2728 If this interface is not supported, then return FALSE.
2730 @param[in, out] DhContext Pointer to the DH context.
2731 @param[in] Generator Value of generator.
2732 @param[in] PrimeLength Length in bits of prime to be generated.
2733 @param[in] Prime Pointer to the prime number.
2735 @retval TRUE DH parameter setting succeeded.
2736 @retval FALSE Value of Generator is not supported.
2737 @retval FALSE Value of Generator is not suitable for the Prime.
2738 @retval FALSE Value of Prime is not a prime number.
2739 @retval FALSE Value of Prime is not a safe prime number.
2740 @retval FALSE This interface is not supported.
2746 IN OUT VOID
*DhContext
,
2748 IN UINTN PrimeLength
,
2749 IN CONST UINT8
*Prime
2753 Generates DH public key.
2755 This function generates random secret exponent, and computes the public key, which is
2756 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
2757 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
2758 PublicKeySize is set to the required buffer size to obtain the public key.
2760 If DhContext is NULL, then return FALSE.
2761 If PublicKeySize is NULL, then return FALSE.
2762 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
2763 If this interface is not supported, then return FALSE.
2765 @param[in, out] DhContext Pointer to the DH context.
2766 @param[out] PublicKey Pointer to the buffer to receive generated public key.
2767 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
2768 On output, the size of data returned in PublicKey buffer in bytes.
2770 @retval TRUE DH public key generation succeeded.
2771 @retval FALSE DH public key generation failed.
2772 @retval FALSE PublicKeySize is not large enough.
2773 @retval FALSE This interface is not supported.
2779 IN OUT VOID
*DhContext
,
2780 OUT UINT8
*PublicKey
,
2781 IN OUT UINTN
*PublicKeySize
2785 Computes exchanged common key.
2787 Given peer's public key, this function computes the exchanged common key, based on its own
2788 context including value of prime modulus and random secret exponent.
2790 If DhContext is NULL, then return FALSE.
2791 If PeerPublicKey is NULL, then return FALSE.
2792 If KeySize is NULL, then return FALSE.
2793 If Key is NULL, then return FALSE.
2794 If KeySize is not large enough, then return FALSE.
2795 If this interface is not supported, then return FALSE.
2797 @param[in, out] DhContext Pointer to the DH context.
2798 @param[in] PeerPublicKey Pointer to the peer's public key.
2799 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
2800 @param[out] Key Pointer to the buffer to receive generated key.
2801 @param[in, out] KeySize On input, the size of Key buffer in bytes.
2802 On output, the size of data returned in Key buffer in bytes.
2804 @retval TRUE DH exchanged key generation succeeded.
2805 @retval FALSE DH exchanged key generation failed.
2806 @retval FALSE KeySize is not large enough.
2807 @retval FALSE This interface is not supported.
2813 IN OUT VOID
*DhContext
,
2814 IN CONST UINT8
*PeerPublicKey
,
2815 IN UINTN PeerPublicKeySize
,
2817 IN OUT UINTN
*KeySize
2820 //=====================================================================================
2821 // Pseudo-Random Generation Primitive
2822 //=====================================================================================
2825 Sets up the seed value for the pseudorandom number generator.
2827 This function sets up the seed value for the pseudorandom number generator.
2828 If Seed is not NULL, then the seed passed in is used.
2829 If Seed is NULL, then default seed is used.
2830 If this interface is not supported, then return FALSE.
2832 @param[in] Seed Pointer to seed value.
2833 If NULL, default seed is used.
2834 @param[in] SeedSize Size of seed value.
2835 If Seed is NULL, this parameter is ignored.
2837 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
2838 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
2839 @retval FALSE This interface is not supported.
2845 IN CONST UINT8
*Seed OPTIONAL
,
2850 Generates a pseudorandom byte stream of the specified size.
2852 If Output is NULL, then return FALSE.
2853 If this interface is not supported, then return FALSE.
2855 @param[out] Output Pointer to buffer to receive random value.
2856 @param[in] Size Size of random bytes to generate.
2858 @retval TRUE Pseudorandom byte stream generated successfully.
2859 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
2860 @retval FALSE This interface is not supported.
2870 #endif // __BASE_CRYPT_LIB_H__