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 - 2017, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #ifndef __BASE_CRYPT_LIB_H__
19 #define __BASE_CRYPT_LIB_H__
21 #include <Uefi/UefiBaseType.h>
24 /// MD4 digest size in bytes
26 #define MD4_DIGEST_SIZE 16
29 /// MD5 digest size in bytes
31 #define MD5_DIGEST_SIZE 16
34 /// SHA-1 digest size in bytes.
36 #define SHA1_DIGEST_SIZE 20
39 /// SHA-256 digest size in bytes
41 #define SHA256_DIGEST_SIZE 32
44 /// SHA-384 digest size in bytes
46 #define SHA384_DIGEST_SIZE 48
49 /// SHA-512 digest size in bytes
51 #define SHA512_DIGEST_SIZE 64
54 /// TDES block size in bytes
56 #define TDES_BLOCK_SIZE 8
59 /// AES block size in bytes
61 #define AES_BLOCK_SIZE 16
64 /// RSA Key Tags Definition used in RsaSetKey() function for key component identification.
67 RsaKeyN
, ///< RSA public Modulus (N)
68 RsaKeyE
, ///< RSA Public exponent (e)
69 RsaKeyD
, ///< RSA Private exponent (d)
70 RsaKeyP
, ///< RSA secret prime factor of Modulus (p)
71 RsaKeyQ
, ///< RSA secret prime factor of Modules (q)
72 RsaKeyDp
, ///< p's CRT exponent (== d mod (p - 1))
73 RsaKeyDq
, ///< q's CRT exponent (== d mod (q - 1))
74 RsaKeyQInv
///< The CRT coefficient (== 1/q mod p)
77 //=====================================================================================
78 // One-Way Cryptographic Hash Primitives
79 //=====================================================================================
82 Retrieves the size, in bytes, of the context buffer required for MD4 hash operations.
84 If this interface is not supported, then return zero.
86 @return The size, in bytes, of the context buffer required for MD4 hash operations.
87 @retval 0 This interface is not supported.
97 Initializes user-supplied memory pointed by Md4Context as MD4 hash context for
100 If Md4Context is NULL, then return FALSE.
101 If this interface is not supported, then return FALSE.
103 @param[out] Md4Context Pointer to MD4 context being initialized.
105 @retval TRUE MD4 context initialization succeeded.
106 @retval FALSE MD4 context initialization failed.
107 @retval FALSE This interface is not supported.
117 Makes a copy of an existing MD4 context.
119 If Md4Context is NULL, then return FALSE.
120 If NewMd4Context is NULL, then return FALSE.
121 If this interface is not supported, then return FALSE.
123 @param[in] Md4Context Pointer to MD4 context being copied.
124 @param[out] NewMd4Context Pointer to new MD4 context.
126 @retval TRUE MD4 context copy succeeded.
127 @retval FALSE MD4 context copy failed.
128 @retval FALSE This interface is not supported.
134 IN CONST VOID
*Md4Context
,
135 OUT VOID
*NewMd4Context
139 Digests the input data and updates MD4 context.
141 This function performs MD4 digest on a data buffer of the specified size.
142 It can be called multiple times to compute the digest of long or discontinuous data streams.
143 MD4 context should be already correctly initialized by Md4Init(), and should not be finalized
144 by Md4Final(). Behavior with invalid context is undefined.
146 If Md4Context is NULL, then return FALSE.
147 If this interface is not supported, then return FALSE.
149 @param[in, out] Md4Context Pointer to the MD4 context.
150 @param[in] Data Pointer to the buffer containing the data to be hashed.
151 @param[in] DataSize Size of Data buffer in bytes.
153 @retval TRUE MD4 data digest succeeded.
154 @retval FALSE MD4 data digest failed.
155 @retval FALSE This interface is not supported.
161 IN OUT VOID
*Md4Context
,
167 Completes computation of the MD4 digest value.
169 This function completes MD4 hash computation and retrieves the digest value into
170 the specified memory. After this function has been called, the MD4 context cannot
172 MD4 context should be already correctly initialized by Md4Init(), and should not be
173 finalized by Md4Final(). Behavior with invalid MD4 context is undefined.
175 If Md4Context is NULL, then return FALSE.
176 If HashValue is NULL, then return FALSE.
177 If this interface is not supported, then return FALSE.
179 @param[in, out] Md4Context Pointer to the MD4 context.
180 @param[out] HashValue Pointer to a buffer that receives the MD4 digest
183 @retval TRUE MD4 digest computation succeeded.
184 @retval FALSE MD4 digest computation failed.
185 @retval FALSE This interface is not supported.
191 IN OUT VOID
*Md4Context
,
196 Computes the MD4 message digest of a input data buffer.
198 This function performs the MD4 message digest of a given data buffer, and places
199 the digest value into the specified memory.
201 If this interface is not supported, then return FALSE.
203 @param[in] Data Pointer to the buffer containing the data to be hashed.
204 @param[in] DataSize Size of Data buffer in bytes.
205 @param[out] HashValue Pointer to a buffer that receives the MD4 digest
208 @retval TRUE MD4 digest computation succeeded.
209 @retval FALSE MD4 digest computation failed.
210 @retval FALSE This interface is not supported.
222 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.
224 If this interface is not supported, then return zero.
226 @return The size, in bytes, of the context buffer required for MD5 hash operations.
227 @retval 0 This interface is not supported.
237 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for
240 If Md5Context is NULL, then return FALSE.
241 If this interface is not supported, then return FALSE.
243 @param[out] Md5Context Pointer to MD5 context being initialized.
245 @retval TRUE MD5 context initialization succeeded.
246 @retval FALSE MD5 context initialization failed.
247 @retval FALSE This interface is not supported.
257 Makes a copy of an existing MD5 context.
259 If Md5Context is NULL, then return FALSE.
260 If NewMd5Context is NULL, then return FALSE.
261 If this interface is not supported, then return FALSE.
263 @param[in] Md5Context Pointer to MD5 context being copied.
264 @param[out] NewMd5Context Pointer to new MD5 context.
266 @retval TRUE MD5 context copy succeeded.
267 @retval FALSE MD5 context copy failed.
268 @retval FALSE This interface is not supported.
274 IN CONST VOID
*Md5Context
,
275 OUT VOID
*NewMd5Context
279 Digests the input data and updates MD5 context.
281 This function performs MD5 digest on a data buffer of the specified size.
282 It can be called multiple times to compute the digest of long or discontinuous data streams.
283 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized
284 by Md5Final(). Behavior with invalid context is undefined.
286 If Md5Context is NULL, then return FALSE.
287 If this interface is not supported, then return FALSE.
289 @param[in, out] Md5Context Pointer to the MD5 context.
290 @param[in] Data Pointer to the buffer containing the data to be hashed.
291 @param[in] DataSize Size of Data buffer in bytes.
293 @retval TRUE MD5 data digest succeeded.
294 @retval FALSE MD5 data digest failed.
295 @retval FALSE This interface is not supported.
301 IN OUT VOID
*Md5Context
,
307 Completes computation of the MD5 digest value.
309 This function completes MD5 hash computation and retrieves the digest value into
310 the specified memory. After this function has been called, the MD5 context cannot
312 MD5 context should be already correctly initialized by Md5Init(), and should not be
313 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.
315 If Md5Context is NULL, then return FALSE.
316 If HashValue is NULL, then return FALSE.
317 If this interface is not supported, then return FALSE.
319 @param[in, out] Md5Context Pointer to the MD5 context.
320 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
323 @retval TRUE MD5 digest computation succeeded.
324 @retval FALSE MD5 digest computation failed.
325 @retval FALSE This interface is not supported.
331 IN OUT VOID
*Md5Context
,
336 Computes the MD5 message digest of a input data buffer.
338 This function performs the MD5 message digest of a given data buffer, and places
339 the digest value into the specified memory.
341 If this interface is not supported, then return FALSE.
343 @param[in] Data Pointer to the buffer containing the data to be hashed.
344 @param[in] DataSize Size of Data buffer in bytes.
345 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
348 @retval TRUE MD5 digest computation succeeded.
349 @retval FALSE MD5 digest computation failed.
350 @retval FALSE This interface is not supported.
362 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.
364 If this interface is not supported, then return zero.
366 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.
367 @retval 0 This interface is not supported.
377 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for
380 If Sha1Context is NULL, then return FALSE.
381 If this interface is not supported, then return FALSE.
383 @param[out] Sha1Context Pointer to SHA-1 context being initialized.
385 @retval TRUE SHA-1 context initialization succeeded.
386 @retval FALSE SHA-1 context initialization failed.
387 @retval FALSE This interface is not supported.
393 OUT VOID
*Sha1Context
397 Makes a copy of an existing SHA-1 context.
399 If Sha1Context is NULL, then return FALSE.
400 If NewSha1Context is NULL, then return FALSE.
401 If this interface is not supported, then return FALSE.
403 @param[in] Sha1Context Pointer to SHA-1 context being copied.
404 @param[out] NewSha1Context Pointer to new SHA-1 context.
406 @retval TRUE SHA-1 context copy succeeded.
407 @retval FALSE SHA-1 context copy failed.
408 @retval FALSE This interface is not supported.
414 IN CONST VOID
*Sha1Context
,
415 OUT VOID
*NewSha1Context
419 Digests the input data and updates SHA-1 context.
421 This function performs SHA-1 digest on a data buffer of the specified size.
422 It can be called multiple times to compute the digest of long or discontinuous data streams.
423 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized
424 by Sha1Final(). Behavior with invalid context is undefined.
426 If Sha1Context is NULL, then return FALSE.
427 If this interface is not supported, then return FALSE.
429 @param[in, out] Sha1Context Pointer to the SHA-1 context.
430 @param[in] Data Pointer to the buffer containing the data to be hashed.
431 @param[in] DataSize Size of Data buffer in bytes.
433 @retval TRUE SHA-1 data digest succeeded.
434 @retval FALSE SHA-1 data digest failed.
435 @retval FALSE This interface is not supported.
441 IN OUT VOID
*Sha1Context
,
447 Completes computation of the SHA-1 digest value.
449 This function completes SHA-1 hash computation and retrieves the digest value into
450 the specified memory. After this function has been called, the SHA-1 context cannot
452 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be
453 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.
455 If Sha1Context is NULL, then return FALSE.
456 If HashValue is NULL, then return FALSE.
457 If this interface is not supported, then return FALSE.
459 @param[in, out] Sha1Context Pointer to the SHA-1 context.
460 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
463 @retval TRUE SHA-1 digest computation succeeded.
464 @retval FALSE SHA-1 digest computation failed.
465 @retval FALSE This interface is not supported.
471 IN OUT VOID
*Sha1Context
,
476 Computes the SHA-1 message digest of a input data buffer.
478 This function performs the SHA-1 message digest of a given data buffer, and places
479 the digest value into the specified memory.
481 If this interface is not supported, then return FALSE.
483 @param[in] Data Pointer to the buffer containing the data to be hashed.
484 @param[in] DataSize Size of Data buffer in bytes.
485 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
488 @retval TRUE SHA-1 digest computation succeeded.
489 @retval FALSE SHA-1 digest computation failed.
490 @retval FALSE This interface is not supported.
502 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.
504 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.
509 Sha256GetContextSize (
514 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for
517 If Sha256Context is NULL, then return FALSE.
519 @param[out] Sha256Context Pointer to SHA-256 context being initialized.
521 @retval TRUE SHA-256 context initialization succeeded.
522 @retval FALSE SHA-256 context initialization failed.
528 OUT VOID
*Sha256Context
532 Makes a copy of an existing SHA-256 context.
534 If Sha256Context is NULL, then return FALSE.
535 If NewSha256Context is NULL, then return FALSE.
536 If this interface is not supported, then return FALSE.
538 @param[in] Sha256Context Pointer to SHA-256 context being copied.
539 @param[out] NewSha256Context Pointer to new SHA-256 context.
541 @retval TRUE SHA-256 context copy succeeded.
542 @retval FALSE SHA-256 context copy failed.
543 @retval FALSE This interface is not supported.
549 IN CONST VOID
*Sha256Context
,
550 OUT VOID
*NewSha256Context
554 Digests the input data and updates SHA-256 context.
556 This function performs SHA-256 digest on a data buffer of the specified size.
557 It can be called multiple times to compute the digest of long or discontinuous data streams.
558 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized
559 by Sha256Final(). Behavior with invalid context is undefined.
561 If Sha256Context is NULL, then return FALSE.
563 @param[in, out] Sha256Context Pointer to the SHA-256 context.
564 @param[in] Data Pointer to the buffer containing the data to be hashed.
565 @param[in] DataSize Size of Data buffer in bytes.
567 @retval TRUE SHA-256 data digest succeeded.
568 @retval FALSE SHA-256 data digest failed.
574 IN OUT VOID
*Sha256Context
,
580 Completes computation of the SHA-256 digest value.
582 This function completes SHA-256 hash computation and retrieves the digest value into
583 the specified memory. After this function has been called, the SHA-256 context cannot
585 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be
586 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.
588 If Sha256Context is NULL, then return FALSE.
589 If HashValue is NULL, then return FALSE.
591 @param[in, out] Sha256Context Pointer to the SHA-256 context.
592 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
595 @retval TRUE SHA-256 digest computation succeeded.
596 @retval FALSE SHA-256 digest computation failed.
602 IN OUT VOID
*Sha256Context
,
607 Computes the SHA-256 message digest of a input data buffer.
609 This function performs the SHA-256 message digest of a given data buffer, and places
610 the digest value into the specified memory.
612 If this interface is not supported, then return FALSE.
614 @param[in] Data Pointer to the buffer containing the data to be hashed.
615 @param[in] DataSize Size of Data buffer in bytes.
616 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
619 @retval TRUE SHA-256 digest computation succeeded.
620 @retval FALSE SHA-256 digest computation failed.
621 @retval FALSE This interface is not supported.
633 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.
635 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.
640 Sha384GetContextSize (
645 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for
648 If Sha384Context is NULL, then return FALSE.
650 @param[out] Sha384Context Pointer to SHA-384 context being initialized.
652 @retval TRUE SHA-384 context initialization succeeded.
653 @retval FALSE SHA-384 context initialization failed.
659 OUT VOID
*Sha384Context
663 Makes a copy of an existing SHA-384 context.
665 If Sha384Context is NULL, then return FALSE.
666 If NewSha384Context is NULL, then return FALSE.
667 If this interface is not supported, then return FALSE.
669 @param[in] Sha384Context Pointer to SHA-384 context being copied.
670 @param[out] NewSha384Context Pointer to new SHA-384 context.
672 @retval TRUE SHA-384 context copy succeeded.
673 @retval FALSE SHA-384 context copy failed.
674 @retval FALSE This interface is not supported.
680 IN CONST VOID
*Sha384Context
,
681 OUT VOID
*NewSha384Context
685 Digests the input data and updates SHA-384 context.
687 This function performs SHA-384 digest on a data buffer of the specified size.
688 It can be called multiple times to compute the digest of long or discontinuous data streams.
689 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized
690 by Sha384Final(). Behavior with invalid context is undefined.
692 If Sha384Context is NULL, then return FALSE.
694 @param[in, out] Sha384Context Pointer to the SHA-384 context.
695 @param[in] Data Pointer to the buffer containing the data to be hashed.
696 @param[in] DataSize Size of Data buffer in bytes.
698 @retval TRUE SHA-384 data digest succeeded.
699 @retval FALSE SHA-384 data digest failed.
705 IN OUT VOID
*Sha384Context
,
711 Completes computation of the SHA-384 digest value.
713 This function completes SHA-384 hash computation and retrieves the digest value into
714 the specified memory. After this function has been called, the SHA-384 context cannot
716 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be
717 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.
719 If Sha384Context is NULL, then return FALSE.
720 If HashValue is NULL, then return FALSE.
722 @param[in, out] Sha384Context Pointer to the SHA-384 context.
723 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
726 @retval TRUE SHA-384 digest computation succeeded.
727 @retval FALSE SHA-384 digest computation failed.
733 IN OUT VOID
*Sha384Context
,
738 Computes the SHA-384 message digest of a input data buffer.
740 This function performs the SHA-384 message digest of a given data buffer, and places
741 the digest value into the specified memory.
743 If this interface is not supported, then return FALSE.
745 @param[in] Data Pointer to the buffer containing the data to be hashed.
746 @param[in] DataSize Size of Data buffer in bytes.
747 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
750 @retval TRUE SHA-384 digest computation succeeded.
751 @retval FALSE SHA-384 digest computation failed.
752 @retval FALSE This interface is not supported.
764 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.
766 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.
771 Sha512GetContextSize (
776 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for
779 If Sha512Context is NULL, then return FALSE.
781 @param[out] Sha512Context Pointer to SHA-512 context being initialized.
783 @retval TRUE SHA-512 context initialization succeeded.
784 @retval FALSE SHA-512 context initialization failed.
790 OUT VOID
*Sha512Context
794 Makes a copy of an existing SHA-512 context.
796 If Sha512Context is NULL, then return FALSE.
797 If NewSha512Context is NULL, then return FALSE.
798 If this interface is not supported, then return FALSE.
800 @param[in] Sha512Context Pointer to SHA-512 context being copied.
801 @param[out] NewSha512Context Pointer to new SHA-512 context.
803 @retval TRUE SHA-512 context copy succeeded.
804 @retval FALSE SHA-512 context copy failed.
805 @retval FALSE This interface is not supported.
811 IN CONST VOID
*Sha512Context
,
812 OUT VOID
*NewSha512Context
816 Digests the input data and updates SHA-512 context.
818 This function performs SHA-512 digest on a data buffer of the specified size.
819 It can be called multiple times to compute the digest of long or discontinuous data streams.
820 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized
821 by Sha512Final(). Behavior with invalid context is undefined.
823 If Sha512Context is NULL, then return FALSE.
825 @param[in, out] Sha512Context Pointer to the SHA-512 context.
826 @param[in] Data Pointer to the buffer containing the data to be hashed.
827 @param[in] DataSize Size of Data buffer in bytes.
829 @retval TRUE SHA-512 data digest succeeded.
830 @retval FALSE SHA-512 data digest failed.
836 IN OUT VOID
*Sha512Context
,
842 Completes computation of the SHA-512 digest value.
844 This function completes SHA-512 hash computation and retrieves the digest value into
845 the specified memory. After this function has been called, the SHA-512 context cannot
847 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be
848 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.
850 If Sha512Context is NULL, then return FALSE.
851 If HashValue is NULL, then return FALSE.
853 @param[in, out] Sha512Context Pointer to the SHA-512 context.
854 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
857 @retval TRUE SHA-512 digest computation succeeded.
858 @retval FALSE SHA-512 digest computation failed.
864 IN OUT VOID
*Sha512Context
,
869 Computes the SHA-512 message digest of a input data buffer.
871 This function performs the SHA-512 message digest of a given data buffer, and places
872 the digest value into the specified memory.
874 If this interface is not supported, then return FALSE.
876 @param[in] Data Pointer to the buffer containing the data to be hashed.
877 @param[in] DataSize Size of Data buffer in bytes.
878 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
881 @retval TRUE SHA-512 digest computation succeeded.
882 @retval FALSE SHA-512 digest computation failed.
883 @retval FALSE This interface is not supported.
894 //=====================================================================================
895 // MAC (Message Authentication Code) Primitive
896 //=====================================================================================
899 Retrieves the size, in bytes, of the context buffer required for HMAC-MD5 operations.
900 (NOTE: This API is deprecated.
901 Use HmacMd5New() / HmacMd5Free() for HMAC-MD5 Context operations.)
903 If this interface is not supported, then return zero.
905 @return The size, in bytes, of the context buffer required for HMAC-MD5 operations.
906 @retval 0 This interface is not supported.
911 HmacMd5GetContextSize (
916 Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD5 use.
918 If this interface is not supported, then return NULL.
920 @return Pointer to the HMAC_CTX context that has been initialized.
921 If the allocations fails, HmacMd5New() returns NULL.
922 @retval NULL This interface is not supported.
932 Release the specified HMAC_CTX context.
934 If this interface is not supported, then do nothing.
936 @param[in] HmacMd5Ctx Pointer to the HMAC_CTX context to be released.
946 Initializes user-supplied memory pointed by HmacMd5Context as HMAC-MD5 context for
949 If HmacMd5Context is NULL, then return FALSE.
950 If this interface is not supported, then return FALSE.
952 @param[out] HmacMd5Context Pointer to HMAC-MD5 context being initialized.
953 @param[in] Key Pointer to the user-supplied key.
954 @param[in] KeySize Key size in bytes.
956 @retval TRUE HMAC-MD5 context initialization succeeded.
957 @retval FALSE HMAC-MD5 context initialization failed.
958 @retval FALSE This interface is not supported.
964 OUT VOID
*HmacMd5Context
,
970 Makes a copy of an existing HMAC-MD5 context.
972 If HmacMd5Context is NULL, then return FALSE.
973 If NewHmacMd5Context is NULL, then return FALSE.
974 If this interface is not supported, then return FALSE.
976 @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied.
977 @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context.
979 @retval TRUE HMAC-MD5 context copy succeeded.
980 @retval FALSE HMAC-MD5 context copy failed.
981 @retval FALSE This interface is not supported.
987 IN CONST VOID
*HmacMd5Context
,
988 OUT VOID
*NewHmacMd5Context
992 Digests the input data and updates HMAC-MD5 context.
994 This function performs HMAC-MD5 digest on a data buffer of the specified size.
995 It can be called multiple times to compute the digest of long or discontinuous data streams.
996 HMAC-MD5 context should be already correctly initialized by HmacMd5Init(), and should not be
997 finalized by HmacMd5Final(). Behavior with invalid context is undefined.
999 If HmacMd5Context is NULL, then return FALSE.
1000 If this interface is not supported, then return FALSE.
1002 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
1003 @param[in] Data Pointer to the buffer containing the data to be digested.
1004 @param[in] DataSize Size of Data buffer in bytes.
1006 @retval TRUE HMAC-MD5 data digest succeeded.
1007 @retval FALSE HMAC-MD5 data digest failed.
1008 @retval FALSE This interface is not supported.
1014 IN OUT VOID
*HmacMd5Context
,
1015 IN CONST VOID
*Data
,
1020 Completes computation of the HMAC-MD5 digest value.
1022 This function completes HMAC-MD5 hash computation and retrieves the digest value into
1023 the specified memory. After this function has been called, the HMAC-MD5 context cannot
1025 HMAC-MD5 context should be already correctly initialized by HmacMd5Init(), and should not be
1026 finalized by HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined.
1028 If HmacMd5Context is NULL, then return FALSE.
1029 If HmacValue is NULL, then return FALSE.
1030 If this interface is not supported, then return FALSE.
1032 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
1033 @param[out] HmacValue Pointer to a buffer that receives the HMAC-MD5 digest
1036 @retval TRUE HMAC-MD5 digest computation succeeded.
1037 @retval FALSE HMAC-MD5 digest computation failed.
1038 @retval FALSE This interface is not supported.
1044 IN OUT VOID
*HmacMd5Context
,
1045 OUT UINT8
*HmacValue
1049 Retrieves the size, in bytes, of the context buffer required for HMAC-SHA1 operations.
1050 (NOTE: This API is deprecated.
1051 Use HmacSha1New() / HmacSha1Free() for HMAC-SHA1 Context operations.)
1053 If this interface is not supported, then return zero.
1055 @return The size, in bytes, of the context buffer required for HMAC-SHA1 operations.
1056 @retval 0 This interface is not supported.
1061 HmacSha1GetContextSize (
1066 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA1 use.
1068 If this interface is not supported, then return NULL.
1070 @return Pointer to the HMAC_CTX context that has been initialized.
1071 If the allocations fails, HmacSha1New() returns NULL.
1072 @return NULL This interface is not supported.
1082 Release the specified HMAC_CTX context.
1084 If this interface is not supported, then do nothing.
1086 @param[in] HmacSha1Ctx Pointer to the HMAC_CTX context to be released.
1092 IN VOID
*HmacSha1Ctx
1096 Initializes user-supplied memory pointed by HmacSha1Context as HMAC-SHA1 context for
1099 If HmacSha1Context is NULL, then return FALSE.
1100 If this interface is not supported, then return FALSE.
1102 @param[out] HmacSha1Context Pointer to HMAC-SHA1 context being initialized.
1103 @param[in] Key Pointer to the user-supplied key.
1104 @param[in] KeySize Key size in bytes.
1106 @retval TRUE HMAC-SHA1 context initialization succeeded.
1107 @retval FALSE HMAC-SHA1 context initialization failed.
1108 @retval FALSE This interface is not supported.
1114 OUT VOID
*HmacSha1Context
,
1115 IN CONST UINT8
*Key
,
1120 Makes a copy of an existing HMAC-SHA1 context.
1122 If HmacSha1Context is NULL, then return FALSE.
1123 If NewHmacSha1Context is NULL, then return FALSE.
1124 If this interface is not supported, then return FALSE.
1126 @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied.
1127 @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context.
1129 @retval TRUE HMAC-SHA1 context copy succeeded.
1130 @retval FALSE HMAC-SHA1 context copy failed.
1131 @retval FALSE This interface is not supported.
1137 IN CONST VOID
*HmacSha1Context
,
1138 OUT VOID
*NewHmacSha1Context
1142 Digests the input data and updates HMAC-SHA1 context.
1144 This function performs HMAC-SHA1 digest on a data buffer of the specified size.
1145 It can be called multiple times to compute the digest of long or discontinuous data streams.
1146 HMAC-SHA1 context should be already correctly initialized by HmacSha1Init(), and should not
1147 be finalized by HmacSha1Final(). Behavior with invalid context is undefined.
1149 If HmacSha1Context is NULL, then return FALSE.
1150 If this interface is not supported, then return FALSE.
1152 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1153 @param[in] Data Pointer to the buffer containing the data to be digested.
1154 @param[in] DataSize Size of Data buffer in bytes.
1156 @retval TRUE HMAC-SHA1 data digest succeeded.
1157 @retval FALSE HMAC-SHA1 data digest failed.
1158 @retval FALSE This interface is not supported.
1164 IN OUT VOID
*HmacSha1Context
,
1165 IN CONST VOID
*Data
,
1170 Completes computation of the HMAC-SHA1 digest value.
1172 This function completes HMAC-SHA1 hash computation and retrieves the digest value into
1173 the specified memory. After this function has been called, the HMAC-SHA1 context cannot
1175 HMAC-SHA1 context should be already correctly initialized by HmacSha1Init(), and should
1176 not be finalized by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined.
1178 If HmacSha1Context is NULL, then return FALSE.
1179 If HmacValue is NULL, then return FALSE.
1180 If this interface is not supported, then return FALSE.
1182 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1183 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA1 digest
1186 @retval TRUE HMAC-SHA1 digest computation succeeded.
1187 @retval FALSE HMAC-SHA1 digest computation failed.
1188 @retval FALSE This interface is not supported.
1194 IN OUT VOID
*HmacSha1Context
,
1195 OUT UINT8
*HmacValue
1199 Retrieves the size, in bytes, of the context buffer required for HMAC-SHA256 operations.
1200 (NOTE: This API is deprecated.
1201 Use HmacSha256New() / HmacSha256Free() for HMAC-SHA256 Context operations.)
1203 If this interface is not supported, then return zero.
1205 @return The size, in bytes, of the context buffer required for HMAC-SHA256 operations.
1206 @retval 0 This interface is not supported.
1211 HmacSha256GetContextSize (
1216 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
1218 @return Pointer to the HMAC_CTX context that has been initialized.
1219 If the allocations fails, HmacSha256New() returns NULL.
1229 Release the specified HMAC_CTX context.
1231 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.
1237 IN VOID
*HmacSha256Ctx
1241 Initializes user-supplied memory pointed by HmacSha256Context as HMAC-SHA256 context for
1244 If HmacSha256Context is NULL, then return FALSE.
1245 If this interface is not supported, then return FALSE.
1247 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context being initialized.
1248 @param[in] Key Pointer to the user-supplied key.
1249 @param[in] KeySize Key size in bytes.
1251 @retval TRUE HMAC-SHA256 context initialization succeeded.
1252 @retval FALSE HMAC-SHA256 context initialization failed.
1253 @retval FALSE This interface is not supported.
1259 OUT VOID
*HmacSha256Context
,
1260 IN CONST UINT8
*Key
,
1265 Makes a copy of an existing HMAC-SHA256 context.
1267 If HmacSha256Context is NULL, then return FALSE.
1268 If NewHmacSha256Context is NULL, then return FALSE.
1269 If this interface is not supported, then return FALSE.
1271 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.
1272 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.
1274 @retval TRUE HMAC-SHA256 context copy succeeded.
1275 @retval FALSE HMAC-SHA256 context copy failed.
1276 @retval FALSE This interface is not supported.
1281 HmacSha256Duplicate (
1282 IN CONST VOID
*HmacSha256Context
,
1283 OUT VOID
*NewHmacSha256Context
1287 Digests the input data and updates HMAC-SHA256 context.
1289 This function performs HMAC-SHA256 digest on a data buffer of the specified size.
1290 It can be called multiple times to compute the digest of long or discontinuous data streams.
1291 HMAC-SHA256 context should be already correctly initialized by HmacSha256Init(), and should not
1292 be finalized by HmacSha256Final(). Behavior with invalid context is undefined.
1294 If HmacSha256Context is NULL, then return FALSE.
1295 If this interface is not supported, then return FALSE.
1297 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1298 @param[in] Data Pointer to the buffer containing the data to be digested.
1299 @param[in] DataSize Size of Data buffer in bytes.
1301 @retval TRUE HMAC-SHA256 data digest succeeded.
1302 @retval FALSE HMAC-SHA256 data digest failed.
1303 @retval FALSE This interface is not supported.
1309 IN OUT VOID
*HmacSha256Context
,
1310 IN CONST VOID
*Data
,
1315 Completes computation of the HMAC-SHA256 digest value.
1317 This function completes HMAC-SHA256 hash computation and retrieves the digest value into
1318 the specified memory. After this function has been called, the HMAC-SHA256 context cannot
1320 HMAC-SHA256 context should be already correctly initialized by HmacSha256Init(), and should
1321 not be finalized by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.
1323 If HmacSha256Context is NULL, then return FALSE.
1324 If HmacValue is NULL, then return FALSE.
1325 If this interface is not supported, then return FALSE.
1327 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1328 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
1331 @retval TRUE HMAC-SHA256 digest computation succeeded.
1332 @retval FALSE HMAC-SHA256 digest computation failed.
1333 @retval FALSE This interface is not supported.
1339 IN OUT VOID
*HmacSha256Context
,
1340 OUT UINT8
*HmacValue
1343 //=====================================================================================
1344 // Symmetric Cryptography Primitive
1345 //=====================================================================================
1348 Retrieves the size, in bytes, of the context buffer required for TDES operations.
1350 If this interface is not supported, then return zero.
1352 @return The size, in bytes, of the context buffer required for TDES operations.
1353 @retval 0 This interface is not supported.
1358 TdesGetContextSize (
1363 Initializes user-supplied memory as TDES context for subsequent use.
1365 This function initializes user-supplied memory pointed by TdesContext as TDES context.
1366 In addition, it sets up all TDES key materials for subsequent encryption and decryption
1368 There are 3 key options as follows:
1369 KeyLength = 64, Keying option 1: K1 == K2 == K3 (Backward compatibility with DES)
1370 KeyLength = 128, Keying option 2: K1 != K2 and K3 = K1 (Less Security)
1371 KeyLength = 192 Keying option 3: K1 != K2 != K3 (Strongest)
1373 If TdesContext is NULL, then return FALSE.
1374 If Key is NULL, then return FALSE.
1375 If KeyLength is not valid, then return FALSE.
1376 If this interface is not supported, then return FALSE.
1378 @param[out] TdesContext Pointer to TDES context being initialized.
1379 @param[in] Key Pointer to the user-supplied TDES key.
1380 @param[in] KeyLength Length of TDES key in bits.
1382 @retval TRUE TDES context initialization succeeded.
1383 @retval FALSE TDES context initialization failed.
1384 @retval FALSE This interface is not supported.
1390 OUT VOID
*TdesContext
,
1391 IN CONST UINT8
*Key
,
1396 Performs TDES encryption on a data buffer of the specified size in ECB mode.
1398 This function performs TDES encryption on data buffer pointed by Input, of specified
1399 size of InputSize, in ECB mode.
1400 InputSize must be multiple of block size (8 bytes). This function does not perform
1401 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1402 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1403 invalid TDES context is undefined.
1405 If TdesContext is NULL, then return FALSE.
1406 If Input is NULL, then return FALSE.
1407 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1408 If Output is NULL, then return FALSE.
1409 If this interface is not supported, then return FALSE.
1411 @param[in] TdesContext Pointer to the TDES context.
1412 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1413 @param[in] InputSize Size of the Input buffer in bytes.
1414 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1416 @retval TRUE TDES encryption succeeded.
1417 @retval FALSE TDES encryption failed.
1418 @retval FALSE This interface is not supported.
1424 IN VOID
*TdesContext
,
1425 IN CONST UINT8
*Input
,
1431 Performs TDES decryption on a data buffer of the specified size in ECB mode.
1433 This function performs TDES decryption on data buffer pointed by Input, of specified
1434 size of InputSize, in ECB mode.
1435 InputSize must be multiple of block size (8 bytes). This function does not perform
1436 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1437 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1438 invalid TDES context is undefined.
1440 If TdesContext is NULL, then return FALSE.
1441 If Input is NULL, then return FALSE.
1442 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1443 If Output is NULL, then return FALSE.
1444 If this interface is not supported, then return FALSE.
1446 @param[in] TdesContext Pointer to the TDES context.
1447 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1448 @param[in] InputSize Size of the Input buffer in bytes.
1449 @param[out] Output Pointer to a buffer that receives the TDES decryption output.
1451 @retval TRUE TDES decryption succeeded.
1452 @retval FALSE TDES decryption failed.
1453 @retval FALSE This interface is not supported.
1459 IN VOID
*TdesContext
,
1460 IN CONST UINT8
*Input
,
1466 Performs TDES encryption on a data buffer of the specified size in CBC mode.
1468 This function performs TDES encryption on data buffer pointed by Input, of specified
1469 size of InputSize, in CBC mode.
1470 InputSize must be multiple of block size (8 bytes). This function does not perform
1471 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1472 Initialization vector should be one block size (8 bytes).
1473 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1474 invalid TDES context is undefined.
1476 If TdesContext is NULL, then return FALSE.
1477 If Input is NULL, then return FALSE.
1478 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1479 If Ivec is NULL, then return FALSE.
1480 If Output is NULL, then return FALSE.
1481 If this interface is not supported, then return FALSE.
1483 @param[in] TdesContext Pointer to the TDES context.
1484 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1485 @param[in] InputSize Size of the Input buffer in bytes.
1486 @param[in] Ivec Pointer to initialization vector.
1487 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1489 @retval TRUE TDES encryption succeeded.
1490 @retval FALSE TDES encryption failed.
1491 @retval FALSE This interface is not supported.
1497 IN VOID
*TdesContext
,
1498 IN CONST UINT8
*Input
,
1500 IN CONST UINT8
*Ivec
,
1505 Performs TDES decryption on a data buffer of the specified size in CBC mode.
1507 This function performs TDES decryption on data buffer pointed by Input, of specified
1508 size of InputSize, in CBC mode.
1509 InputSize must be multiple of block size (8 bytes). This function does not perform
1510 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1511 Initialization vector should be one block size (8 bytes).
1512 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1513 invalid TDES context is undefined.
1515 If TdesContext is NULL, then return FALSE.
1516 If Input is NULL, then return FALSE.
1517 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1518 If Ivec is NULL, then return FALSE.
1519 If Output is NULL, then return FALSE.
1520 If this interface is not supported, then return FALSE.
1522 @param[in] TdesContext Pointer to the TDES context.
1523 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1524 @param[in] InputSize Size of the Input buffer in bytes.
1525 @param[in] Ivec Pointer to initialization vector.
1526 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1528 @retval TRUE TDES decryption succeeded.
1529 @retval FALSE TDES decryption failed.
1530 @retval FALSE This interface is not supported.
1536 IN VOID
*TdesContext
,
1537 IN CONST UINT8
*Input
,
1539 IN CONST UINT8
*Ivec
,
1544 Retrieves the size, in bytes, of the context buffer required for AES operations.
1546 If this interface is not supported, then return zero.
1548 @return The size, in bytes, of the context buffer required for AES operations.
1549 @retval 0 This interface is not supported.
1559 Initializes user-supplied memory as AES context for subsequent use.
1561 This function initializes user-supplied memory pointed by AesContext as AES context.
1562 In addition, it sets up all AES key materials for subsequent encryption and decryption
1564 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1566 If AesContext is NULL, then return FALSE.
1567 If Key is NULL, then return FALSE.
1568 If KeyLength is not valid, then return FALSE.
1569 If this interface is not supported, then return FALSE.
1571 @param[out] AesContext Pointer to AES context being initialized.
1572 @param[in] Key Pointer to the user-supplied AES key.
1573 @param[in] KeyLength Length of AES key in bits.
1575 @retval TRUE AES context initialization succeeded.
1576 @retval FALSE AES context initialization failed.
1577 @retval FALSE This interface is not supported.
1583 OUT VOID
*AesContext
,
1584 IN CONST UINT8
*Key
,
1589 Performs AES encryption on a data buffer of the specified size in ECB mode.
1591 This function performs AES encryption on data buffer pointed by Input, of specified
1592 size of InputSize, in ECB mode.
1593 InputSize must be multiple of block size (16 bytes). This function does not perform
1594 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1595 AesContext should be already correctly initialized by AesInit(). Behavior with
1596 invalid AES context is undefined.
1598 If AesContext is NULL, then return FALSE.
1599 If Input is NULL, then return FALSE.
1600 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1601 If Output is NULL, then return FALSE.
1602 If this interface is not supported, then return FALSE.
1604 @param[in] AesContext Pointer to the AES context.
1605 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1606 @param[in] InputSize Size of the Input buffer in bytes.
1607 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1609 @retval TRUE AES encryption succeeded.
1610 @retval FALSE AES encryption failed.
1611 @retval FALSE This interface is not supported.
1617 IN VOID
*AesContext
,
1618 IN CONST UINT8
*Input
,
1624 Performs AES decryption on a data buffer of the specified size in ECB mode.
1626 This function performs AES decryption on data buffer pointed by Input, of specified
1627 size of InputSize, in ECB mode.
1628 InputSize must be multiple of block size (16 bytes). This function does not perform
1629 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1630 AesContext should be already correctly initialized by AesInit(). Behavior with
1631 invalid AES context is undefined.
1633 If AesContext is NULL, then return FALSE.
1634 If Input is NULL, then return FALSE.
1635 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1636 If Output is NULL, then return FALSE.
1637 If this interface is not supported, then return FALSE.
1639 @param[in] AesContext Pointer to the AES context.
1640 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1641 @param[in] InputSize Size of the Input buffer in bytes.
1642 @param[out] Output Pointer to a buffer that receives the AES decryption output.
1644 @retval TRUE AES decryption succeeded.
1645 @retval FALSE AES decryption failed.
1646 @retval FALSE This interface is not supported.
1652 IN VOID
*AesContext
,
1653 IN CONST UINT8
*Input
,
1659 Performs AES encryption on a data buffer of the specified size in CBC mode.
1661 This function performs AES encryption on data buffer pointed by Input, of specified
1662 size of InputSize, in CBC mode.
1663 InputSize must be multiple of block size (16 bytes). This function does not perform
1664 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1665 Initialization vector should be one block size (16 bytes).
1666 AesContext should be already correctly initialized by AesInit(). Behavior with
1667 invalid AES context is undefined.
1669 If AesContext is NULL, then return FALSE.
1670 If Input is NULL, then return FALSE.
1671 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1672 If Ivec is NULL, then return FALSE.
1673 If Output is NULL, then return FALSE.
1674 If this interface is not supported, then return FALSE.
1676 @param[in] AesContext Pointer to the AES context.
1677 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1678 @param[in] InputSize Size of the Input buffer in bytes.
1679 @param[in] Ivec Pointer to initialization vector.
1680 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1682 @retval TRUE AES encryption succeeded.
1683 @retval FALSE AES encryption failed.
1684 @retval FALSE This interface is not supported.
1690 IN VOID
*AesContext
,
1691 IN CONST UINT8
*Input
,
1693 IN CONST UINT8
*Ivec
,
1698 Performs AES decryption on a data buffer of the specified size in CBC mode.
1700 This function performs AES decryption on data buffer pointed by Input, of specified
1701 size of InputSize, in CBC mode.
1702 InputSize must be multiple of block size (16 bytes). This function does not perform
1703 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1704 Initialization vector should be one block size (16 bytes).
1705 AesContext should be already correctly initialized by AesInit(). Behavior with
1706 invalid AES context is undefined.
1708 If AesContext is NULL, then return FALSE.
1709 If Input is NULL, then return FALSE.
1710 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1711 If Ivec is NULL, then return FALSE.
1712 If Output is NULL, then return FALSE.
1713 If this interface is not supported, then return FALSE.
1715 @param[in] AesContext Pointer to the AES context.
1716 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1717 @param[in] InputSize Size of the Input buffer in bytes.
1718 @param[in] Ivec Pointer to initialization vector.
1719 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1721 @retval TRUE AES decryption succeeded.
1722 @retval FALSE AES decryption failed.
1723 @retval FALSE This interface is not supported.
1729 IN VOID
*AesContext
,
1730 IN CONST UINT8
*Input
,
1732 IN CONST UINT8
*Ivec
,
1737 Retrieves the size, in bytes, of the context buffer required for ARC4 operations.
1739 If this interface is not supported, then return zero.
1741 @return The size, in bytes, of the context buffer required for ARC4 operations.
1742 @retval 0 This interface is not supported.
1747 Arc4GetContextSize (
1752 Initializes user-supplied memory as ARC4 context for subsequent use.
1754 This function initializes user-supplied memory pointed by Arc4Context as ARC4 context.
1755 In addition, it sets up all ARC4 key materials for subsequent encryption and decryption
1758 If Arc4Context is NULL, then return FALSE.
1759 If Key is NULL, then return FALSE.
1760 If KeySize does not in the range of [5, 256] bytes, then return FALSE.
1761 If this interface is not supported, then return FALSE.
1763 @param[out] Arc4Context Pointer to ARC4 context being initialized.
1764 @param[in] Key Pointer to the user-supplied ARC4 key.
1765 @param[in] KeySize Size of ARC4 key in bytes.
1767 @retval TRUE ARC4 context initialization succeeded.
1768 @retval FALSE ARC4 context initialization failed.
1769 @retval FALSE This interface is not supported.
1775 OUT VOID
*Arc4Context
,
1776 IN CONST UINT8
*Key
,
1781 Performs ARC4 encryption on a data buffer of the specified size.
1783 This function performs ARC4 encryption on data buffer pointed by Input, of specified
1785 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
1786 invalid ARC4 context is undefined.
1788 If Arc4Context is NULL, then return FALSE.
1789 If Input is NULL, then return FALSE.
1790 If Output is NULL, then return FALSE.
1791 If this interface is not supported, then return FALSE.
1793 @param[in, out] Arc4Context Pointer to the ARC4 context.
1794 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1795 @param[in] InputSize Size of the Input buffer in bytes.
1796 @param[out] Output Pointer to a buffer that receives the ARC4 encryption output.
1798 @retval TRUE ARC4 encryption succeeded.
1799 @retval FALSE ARC4 encryption failed.
1800 @retval FALSE This interface is not supported.
1806 IN OUT VOID
*Arc4Context
,
1807 IN CONST UINT8
*Input
,
1813 Performs ARC4 decryption on a data buffer of the specified size.
1815 This function performs ARC4 decryption on data buffer pointed by Input, of specified
1817 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
1818 invalid ARC4 context is undefined.
1820 If Arc4Context is NULL, then return FALSE.
1821 If Input is NULL, then return FALSE.
1822 If Output is NULL, then return FALSE.
1823 If this interface is not supported, then return FALSE.
1825 @param[in, out] Arc4Context Pointer to the ARC4 context.
1826 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1827 @param[in] InputSize Size of the Input buffer in bytes.
1828 @param[out] Output Pointer to a buffer that receives the ARC4 decryption output.
1830 @retval TRUE ARC4 decryption succeeded.
1831 @retval FALSE ARC4 decryption failed.
1832 @retval FALSE This interface is not supported.
1838 IN OUT VOID
*Arc4Context
,
1845 Resets the ARC4 context to the initial state.
1847 The function resets the ARC4 context to the state it had immediately after the
1848 ARC4Init() function call.
1849 Contrary to ARC4Init(), Arc4Reset() requires no secret key as input, but ARC4 context
1850 should be already correctly initialized by ARC4Init().
1852 If Arc4Context is NULL, then return FALSE.
1853 If this interface is not supported, then return FALSE.
1855 @param[in, out] Arc4Context Pointer to the ARC4 context.
1857 @retval TRUE ARC4 reset succeeded.
1858 @retval FALSE ARC4 reset failed.
1859 @retval FALSE This interface is not supported.
1865 IN OUT VOID
*Arc4Context
1868 //=====================================================================================
1869 // Asymmetric Cryptography Primitive
1870 //=====================================================================================
1873 Allocates and initializes one RSA context for subsequent use.
1875 @return Pointer to the RSA context that has been initialized.
1876 If the allocations fails, RsaNew() returns NULL.
1886 Release the specified RSA context.
1888 If RsaContext is NULL, then return FALSE.
1890 @param[in] RsaContext Pointer to the RSA context to be released.
1900 Sets the tag-designated key component into the established RSA context.
1902 This function sets the tag-designated RSA key component into the established
1903 RSA context from the user-specified non-negative integer (octet string format
1904 represented in RSA PKCS#1).
1905 If BigNumber is NULL, then the specified key component in RSA context is cleared.
1907 If RsaContext is NULL, then return FALSE.
1909 @param[in, out] RsaContext Pointer to RSA context being set.
1910 @param[in] KeyTag Tag of RSA key component being set.
1911 @param[in] BigNumber Pointer to octet integer buffer.
1912 If NULL, then the specified key component in RSA
1914 @param[in] BnSize Size of big number buffer in bytes.
1915 If BigNumber is NULL, then it is ignored.
1917 @retval TRUE RSA key component was set successfully.
1918 @retval FALSE Invalid RSA key component tag.
1924 IN OUT VOID
*RsaContext
,
1925 IN RSA_KEY_TAG KeyTag
,
1926 IN CONST UINT8
*BigNumber
,
1931 Gets the tag-designated RSA key component from the established RSA context.
1933 This function retrieves the tag-designated RSA key component from the
1934 established RSA context as a non-negative integer (octet string format
1935 represented in RSA PKCS#1).
1936 If specified key component has not been set or has been cleared, then returned
1938 If the BigNumber buffer is too small to hold the contents of the key, FALSE
1939 is returned and BnSize is set to the required buffer size to obtain the key.
1941 If RsaContext is NULL, then return FALSE.
1942 If BnSize is NULL, then return FALSE.
1943 If BnSize is large enough but BigNumber is NULL, then return FALSE.
1944 If this interface is not supported, then return FALSE.
1946 @param[in, out] RsaContext Pointer to RSA context being set.
1947 @param[in] KeyTag Tag of RSA key component being set.
1948 @param[out] BigNumber Pointer to octet integer buffer.
1949 @param[in, out] BnSize On input, the size of big number buffer in bytes.
1950 On output, the size of data returned in big number buffer in bytes.
1952 @retval TRUE RSA key component was retrieved successfully.
1953 @retval FALSE Invalid RSA key component tag.
1954 @retval FALSE BnSize is too small.
1955 @retval FALSE This interface is not supported.
1961 IN OUT VOID
*RsaContext
,
1962 IN RSA_KEY_TAG KeyTag
,
1963 OUT UINT8
*BigNumber
,
1964 IN OUT UINTN
*BnSize
1968 Generates RSA key components.
1970 This function generates RSA key components. It takes RSA public exponent E and
1971 length in bits of RSA modulus N as input, and generates all key components.
1972 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
1974 Before this function can be invoked, pseudorandom number generator must be correctly
1975 initialized by RandomSeed().
1977 If RsaContext is NULL, then return FALSE.
1978 If this interface is not supported, then return FALSE.
1980 @param[in, out] RsaContext Pointer to RSA context being set.
1981 @param[in] ModulusLength Length of RSA modulus N in bits.
1982 @param[in] PublicExponent Pointer to RSA public exponent.
1983 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
1985 @retval TRUE RSA key component was generated successfully.
1986 @retval FALSE Invalid RSA key component tag.
1987 @retval FALSE This interface is not supported.
1993 IN OUT VOID
*RsaContext
,
1994 IN UINTN ModulusLength
,
1995 IN CONST UINT8
*PublicExponent
,
1996 IN UINTN PublicExponentSize
2000 Validates key components of RSA context.
2001 NOTE: This function performs integrity checks on all the RSA key material, so
2002 the RSA key structure must contain all the private key data.
2004 This function validates key components of RSA context in following aspects:
2005 - Whether p is a prime
2006 - Whether q is a prime
2008 - Whether d*e = 1 mod lcm(p-1,q-1)
2010 If RsaContext is NULL, then return FALSE.
2011 If this interface is not supported, then return FALSE.
2013 @param[in] RsaContext Pointer to RSA context to check.
2015 @retval TRUE RSA key components are valid.
2016 @retval FALSE RSA key components are not valid.
2017 @retval FALSE This interface is not supported.
2027 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
2029 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
2031 If the Signature buffer is too small to hold the contents of signature, FALSE
2032 is returned and SigSize is set to the required buffer size to obtain the signature.
2034 If RsaContext is NULL, then return FALSE.
2035 If MessageHash is NULL, then return FALSE.
2036 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
2037 If SigSize is large enough but Signature is NULL, then return FALSE.
2038 If this interface is not supported, then return FALSE.
2040 @param[in] RsaContext Pointer to RSA context for signature generation.
2041 @param[in] MessageHash Pointer to octet message hash to be signed.
2042 @param[in] HashSize Size of the message hash in bytes.
2043 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
2044 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
2045 On output, the size of data returned in Signature buffer in bytes.
2047 @retval TRUE Signature successfully generated in PKCS1-v1_5.
2048 @retval FALSE Signature generation failed.
2049 @retval FALSE SigSize is too small.
2050 @retval FALSE This interface is not supported.
2056 IN VOID
*RsaContext
,
2057 IN CONST UINT8
*MessageHash
,
2059 OUT UINT8
*Signature
,
2060 IN OUT UINTN
*SigSize
2064 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
2067 If RsaContext is NULL, then return FALSE.
2068 If MessageHash is NULL, then return FALSE.
2069 If Signature is NULL, then return FALSE.
2070 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
2072 @param[in] RsaContext Pointer to RSA context for signature verification.
2073 @param[in] MessageHash Pointer to octet message hash to be checked.
2074 @param[in] HashSize Size of the message hash in bytes.
2075 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
2076 @param[in] SigSize Size of signature in bytes.
2078 @retval TRUE Valid signature encoded in PKCS1-v1_5.
2079 @retval FALSE Invalid signature or invalid RSA context.
2085 IN VOID
*RsaContext
,
2086 IN CONST UINT8
*MessageHash
,
2088 IN CONST UINT8
*Signature
,
2093 Retrieve the RSA Private Key from the password-protected PEM key data.
2095 If PemData is NULL, then return FALSE.
2096 If RsaContext is NULL, then return FALSE.
2097 If this interface is not supported, then return FALSE.
2099 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
2100 @param[in] PemSize Size of the PEM key data in bytes.
2101 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
2102 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2103 RSA private key component. Use RsaFree() function to free the
2106 @retval TRUE RSA Private Key was retrieved successfully.
2107 @retval FALSE Invalid PEM key data or incorrect password.
2108 @retval FALSE This interface is not supported.
2113 RsaGetPrivateKeyFromPem (
2114 IN CONST UINT8
*PemData
,
2116 IN CONST CHAR8
*Password
,
2117 OUT VOID
**RsaContext
2121 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
2123 If Cert is NULL, then return FALSE.
2124 If RsaContext is NULL, then return FALSE.
2125 If this interface is not supported, then return FALSE.
2127 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2128 @param[in] CertSize Size of the X509 certificate in bytes.
2129 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2130 RSA public key component. Use RsaFree() function to free the
2133 @retval TRUE RSA Public Key was retrieved successfully.
2134 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
2135 @retval FALSE This interface is not supported.
2140 RsaGetPublicKeyFromX509 (
2141 IN CONST UINT8
*Cert
,
2143 OUT VOID
**RsaContext
2147 Retrieve the subject bytes from one X.509 certificate.
2149 If Cert is NULL, then return FALSE.
2150 If SubjectSize is NULL, then return FALSE.
2151 If this interface is not supported, then return FALSE.
2153 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2154 @param[in] CertSize Size of the X509 certificate in bytes.
2155 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
2156 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
2157 and the size of buffer returned CertSubject on output.
2159 @retval TRUE The certificate subject retrieved successfully.
2160 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
2161 The SubjectSize will be updated with the required size.
2162 @retval FALSE This interface is not supported.
2167 X509GetSubjectName (
2168 IN CONST UINT8
*Cert
,
2170 OUT UINT8
*CertSubject
,
2171 IN OUT UINTN
*SubjectSize
2175 Retrieve the common name (CN) string from one X.509 certificate.
2177 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2178 @param[in] CertSize Size of the X509 certificate in bytes.
2179 @param[out] CommonName Buffer to contain the retrieved certificate common
2180 name string. At most CommonNameSize bytes will be
2181 written and the string will be null terminated. May be
2182 NULL in order to determine the size buffer needed.
2183 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
2184 and the size of buffer returned CommonName on output.
2185 If CommonName is NULL then the amount of space needed
2186 in buffer (including the final null) is returned.
2188 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
2189 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2190 If CommonNameSize is NULL.
2191 If CommonName is not NULL and *CommonNameSize is 0.
2192 If Certificate is invalid.
2193 @retval RETURN_NOT_FOUND If no CommonName entry exists.
2194 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
2195 (including the final null) is returned in the
2196 CommonNameSize parameter.
2197 @retval RETURN_UNSUPPORTED The operation is not supported.
2203 IN CONST UINT8
*Cert
,
2205 OUT CHAR8
*CommonName
, OPTIONAL
2206 IN OUT UINTN
*CommonNameSize
2210 Verify one X509 certificate was issued by the trusted CA.
2212 If Cert is NULL, then return FALSE.
2213 If CACert is NULL, then return FALSE.
2214 If this interface is not supported, then return FALSE.
2216 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
2217 @param[in] CertSize Size of the X509 certificate in bytes.
2218 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
2219 @param[in] CACertSize Size of the CA Certificate in bytes.
2221 @retval TRUE The certificate was issued by the trusted CA.
2222 @retval FALSE Invalid certificate or the certificate was not issued by the given
2224 @retval FALSE This interface is not supported.
2230 IN CONST UINT8
*Cert
,
2232 IN CONST UINT8
*CACert
,
2237 Construct a X509 object from DER-encoded certificate data.
2239 If Cert is NULL, then return FALSE.
2240 If SingleX509Cert is NULL, then return FALSE.
2241 If this interface is not supported, then return FALSE.
2243 @param[in] Cert Pointer to the DER-encoded certificate data.
2244 @param[in] CertSize The size of certificate data in bytes.
2245 @param[out] SingleX509Cert The generated X509 object.
2247 @retval TRUE The X509 object generation succeeded.
2248 @retval FALSE The operation failed.
2249 @retval FALSE This interface is not supported.
2254 X509ConstructCertificate (
2255 IN CONST UINT8
*Cert
,
2257 OUT UINT8
**SingleX509Cert
2261 Construct a X509 stack object from a list of DER-encoded certificate data.
2263 If X509Stack is NULL, then return FALSE.
2264 If this interface is not supported, then return FALSE.
2266 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2267 On output, pointer to the X509 stack object with new
2268 inserted X509 certificate.
2269 @param ... A list of DER-encoded single certificate data followed
2270 by certificate size. A NULL terminates the list. The
2271 pairs are the arguments to X509ConstructCertificate().
2273 @retval TRUE The X509 stack construction succeeded.
2274 @retval FALSE The construction operation failed.
2275 @retval FALSE This interface is not supported.
2280 X509ConstructCertificateStack (
2281 IN OUT UINT8
**X509Stack
,
2286 Release the specified X509 object.
2288 If the interface is not supported, then ASSERT().
2290 @param[in] X509Cert Pointer to the X509 object to be released.
2300 Release the specified X509 stack object.
2302 If the interface is not supported, then ASSERT().
2304 @param[in] X509Stack Pointer to the X509 stack object to be released.
2314 Retrieve the TBSCertificate from one given X.509 certificate.
2316 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
2317 @param[in] CertSize Size of the X509 certificate in bytes.
2318 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
2319 @param[out] TBSCertSize Size of the TBS certificate in bytes.
2321 If Cert is NULL, then return FALSE.
2322 If TBSCert is NULL, then return FALSE.
2323 If TBSCertSize is NULL, then return FALSE.
2324 If this interface is not supported, then return FALSE.
2326 @retval TRUE The TBSCertificate was retrieved successfully.
2327 @retval FALSE Invalid X.509 certificate.
2333 IN CONST UINT8
*Cert
,
2335 OUT UINT8
**TBSCert
,
2336 OUT UINTN
*TBSCertSize
2340 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2341 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2343 If Password or Salt or OutKey is NULL, then return FALSE.
2344 If the hash algorithm could not be determined, then return FALSE.
2345 If this interface is not supported, then return FALSE.
2347 @param[in] PasswordLength Length of input password in bytes.
2348 @param[in] Password Pointer to the array for the password.
2349 @param[in] SaltLength Size of the Salt in bytes.
2350 @param[in] Salt Pointer to the Salt.
2351 @param[in] IterationCount Number of iterations to perform. Its value should be
2352 greater than or equal to 1.
2353 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2354 NOTE: DigestSize will be used to determine the hash algorithm.
2355 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2356 @param[in] KeyLength Size of the derived key buffer in bytes.
2357 @param[out] OutKey Pointer to the output derived key buffer.
2359 @retval TRUE A key was derived successfully.
2360 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2361 @retval FALSE The hash algorithm could not be determined from the digest size.
2362 @retval FALSE The key derivation operation failed.
2363 @retval FALSE This interface is not supported.
2369 IN UINTN PasswordLength
,
2370 IN CONST CHAR8
*Password
,
2371 IN UINTN SaltLength
,
2372 IN CONST UINT8
*Salt
,
2373 IN UINTN IterationCount
,
2374 IN UINTN DigestSize
,
2380 The 3rd parameter of Pkcs7GetSigners will return all embedded
2381 X.509 certificate in one given PKCS7 signature. The format is:
2383 // UINT8 CertNumber;
2384 // UINT32 Cert1Length;
2386 // UINT32 Cert2Length;
2389 // UINT32 CertnLength;
2393 The two following C-structure are used for parsing CertStack more clearly.
2398 UINT32 CertDataLength
; // The length in bytes of X.509 certificate.
2399 UINT8 CertDataBuffer
[0]; // The X.509 certificate content (DER).
2403 UINT8 CertNumber
; // Number of X.509 certificate.
2404 //EFI_CERT_DATA CertArray[]; // An array of X.509 certificate.
2410 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2411 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2412 in a ContentInfo structure.
2414 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2415 return FALSE. If P7Length overflow, then return FALSE.
2416 If this interface is not supported, then return FALSE.
2418 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2419 @param[in] P7Length Length of the PKCS#7 message in bytes.
2420 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2421 It's caller's responsibility to free the buffer with
2423 This data structure is EFI_CERT_STACK type.
2424 @param[out] StackLength Length of signer's certificates in bytes.
2425 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2426 It's caller's responsibility to free the buffer with
2428 @param[out] CertLength Length of the trusted certificate in bytes.
2430 @retval TRUE The operation is finished successfully.
2431 @retval FALSE Error occurs during the operation.
2432 @retval FALSE This interface is not supported.
2438 IN CONST UINT8
*P7Data
,
2440 OUT UINT8
**CertStack
,
2441 OUT UINTN
*StackLength
,
2442 OUT UINT8
**TrustedCert
,
2443 OUT UINTN
*CertLength
2447 Wrap function to use free() to free allocated memory for certificates.
2449 If this interface is not supported, then ASSERT().
2451 @param[in] Certs Pointer to the certificates to be freed.
2461 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2462 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2463 unchained to the signer's certificates.
2464 The input signed data could be wrapped in a ContentInfo structure.
2466 @param[in] P7Data Pointer to the PKCS#7 message.
2467 @param[in] P7Length Length of the PKCS#7 message in bytes.
2468 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2469 certificate. It's caller's responsibility to free the buffer
2470 with Pkcs7FreeSigners().
2471 This data structure is EFI_CERT_STACK type.
2472 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2473 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2474 responsibility to free the buffer with Pkcs7FreeSigners().
2475 This data structure is EFI_CERT_STACK type.
2476 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2478 @retval TRUE The operation is finished successfully.
2479 @retval FALSE Error occurs during the operation.
2484 Pkcs7GetCertificatesList (
2485 IN CONST UINT8
*P7Data
,
2487 OUT UINT8
**SignerChainCerts
,
2488 OUT UINTN
*ChainLength
,
2489 OUT UINT8
**UnchainCerts
,
2490 OUT UINTN
*UnchainLength
2494 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2495 Syntax Standard, version 1.5". This interface is only intended to be used for
2496 application to perform PKCS#7 functionality validation.
2498 If this interface is not supported, then return FALSE.
2500 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2502 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2503 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2505 @param[in] InData Pointer to the content to be signed.
2506 @param[in] InDataSize Size of InData in bytes.
2507 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2508 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2509 include in the PKCS#7 signedData (e.g. any intermediate
2511 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2512 responsibility to free the buffer with FreePool().
2513 @param[out] SignedDataSize Size of SignedData in bytes.
2515 @retval TRUE PKCS#7 data signing succeeded.
2516 @retval FALSE PKCS#7 data signing failed.
2517 @retval FALSE This interface is not supported.
2523 IN CONST UINT8
*PrivateKey
,
2524 IN UINTN PrivateKeySize
,
2525 IN CONST UINT8
*KeyPassword
,
2527 IN UINTN InDataSize
,
2529 IN UINT8
*OtherCerts OPTIONAL
,
2530 OUT UINT8
**SignedData
,
2531 OUT UINTN
*SignedDataSize
2535 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2536 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2537 in a ContentInfo structure.
2539 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2540 If P7Length, CertLength or DataLength overflow, then return FALSE.
2541 If this interface is not supported, then return FALSE.
2543 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2544 @param[in] P7Length Length of the PKCS#7 message in bytes.
2545 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2546 is used for certificate chain verification.
2547 @param[in] CertLength Length of the trusted certificate in bytes.
2548 @param[in] InData Pointer to the content to be verified.
2549 @param[in] DataLength Length of InData in bytes.
2551 @retval TRUE The specified PKCS#7 signed data is valid.
2552 @retval FALSE Invalid PKCS#7 signed data.
2553 @retval FALSE This interface is not supported.
2559 IN CONST UINT8
*P7Data
,
2561 IN CONST UINT8
*TrustedCert
,
2562 IN UINTN CertLength
,
2563 IN CONST UINT8
*InData
,
2568 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2569 data could be wrapped in a ContentInfo structure.
2571 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2572 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2574 Caution: This function may receive untrusted input. So this function will do
2575 basic check for PKCS#7 data structure.
2577 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2578 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2579 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2580 It's caller's responsibility to free the buffer with FreePool().
2581 @param[out] ContentSize The size of the extracted content in bytes.
2583 @retval TRUE The P7Data was correctly formatted for processing.
2584 @retval FALSE The P7Data was not correctly formatted for processing.
2589 Pkcs7GetAttachedContent (
2590 IN CONST UINT8
*P7Data
,
2593 OUT UINTN
*ContentSize
2597 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2598 Authenticode Portable Executable Signature Format".
2600 If AuthData is NULL, then return FALSE.
2601 If ImageHash is NULL, then return FALSE.
2602 If this interface is not supported, then return FALSE.
2604 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2605 PE/COFF image to be verified.
2606 @param[in] DataSize Size of the Authenticode Signature in bytes.
2607 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2608 is used for certificate chain verification.
2609 @param[in] CertSize Size of the trusted certificate in bytes.
2610 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2611 for calculating the image hash value is described in Authenticode
2613 @param[in] HashSize Size of Image hash value in bytes.
2615 @retval TRUE The specified Authenticode Signature is valid.
2616 @retval FALSE Invalid Authenticode Signature.
2617 @retval FALSE This interface is not supported.
2622 AuthenticodeVerify (
2623 IN CONST UINT8
*AuthData
,
2625 IN CONST UINT8
*TrustedCert
,
2627 IN CONST UINT8
*ImageHash
,
2632 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2635 If AuthData is NULL, then return FALSE.
2636 If this interface is not supported, then return FALSE.
2638 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2639 PE/COFF image to be verified.
2640 @param[in] DataSize Size of the Authenticode Signature in bytes.
2641 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2642 is used for TSA certificate chain verification.
2643 @param[in] CertSize Size of the trusted certificate in bytes.
2644 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2647 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2648 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2653 ImageTimestampVerify (
2654 IN CONST UINT8
*AuthData
,
2656 IN CONST UINT8
*TsaCert
,
2658 OUT EFI_TIME
*SigningTime
2661 //=====================================================================================
2662 // DH Key Exchange Primitive
2663 //=====================================================================================
2666 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
2668 @return Pointer to the Diffie-Hellman Context that has been initialized.
2669 If the allocations fails, DhNew() returns NULL.
2670 If the interface is not supported, DhNew() returns NULL.
2680 Release the specified DH context.
2682 If the interface is not supported, then ASSERT().
2684 @param[in] DhContext Pointer to the DH context to be released.
2694 Generates DH parameter.
2696 Given generator g, and length of prime number p in bits, this function generates p,
2697 and sets DH context according to value of g and p.
2699 Before this function can be invoked, pseudorandom number generator must be correctly
2700 initialized by RandomSeed().
2702 If DhContext is NULL, then return FALSE.
2703 If Prime is NULL, then return FALSE.
2704 If this interface is not supported, then return FALSE.
2706 @param[in, out] DhContext Pointer to the DH context.
2707 @param[in] Generator Value of generator.
2708 @param[in] PrimeLength Length in bits of prime to be generated.
2709 @param[out] Prime Pointer to the buffer to receive the generated prime number.
2711 @retval TRUE DH parameter generation succeeded.
2712 @retval FALSE Value of Generator is not supported.
2713 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
2714 @retval FALSE This interface is not supported.
2719 DhGenerateParameter (
2720 IN OUT VOID
*DhContext
,
2722 IN UINTN PrimeLength
,
2727 Sets generator and prime parameters for DH.
2729 Given generator g, and prime number p, this function and sets DH
2730 context accordingly.
2732 If DhContext is NULL, then return FALSE.
2733 If Prime is NULL, then return FALSE.
2734 If this interface is not supported, then return FALSE.
2736 @param[in, out] DhContext Pointer to the DH context.
2737 @param[in] Generator Value of generator.
2738 @param[in] PrimeLength Length in bits of prime to be generated.
2739 @param[in] Prime Pointer to the prime number.
2741 @retval TRUE DH parameter setting succeeded.
2742 @retval FALSE Value of Generator is not supported.
2743 @retval FALSE Value of Generator is not suitable for the Prime.
2744 @retval FALSE Value of Prime is not a prime number.
2745 @retval FALSE Value of Prime is not a safe prime number.
2746 @retval FALSE This interface is not supported.
2752 IN OUT VOID
*DhContext
,
2754 IN UINTN PrimeLength
,
2755 IN CONST UINT8
*Prime
2759 Generates DH public key.
2761 This function generates random secret exponent, and computes the public key, which is
2762 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
2763 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
2764 PublicKeySize is set to the required buffer size to obtain the public key.
2766 If DhContext is NULL, then return FALSE.
2767 If PublicKeySize is NULL, then return FALSE.
2768 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
2769 If this interface is not supported, then return FALSE.
2771 @param[in, out] DhContext Pointer to the DH context.
2772 @param[out] PublicKey Pointer to the buffer to receive generated public key.
2773 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
2774 On output, the size of data returned in PublicKey buffer in bytes.
2776 @retval TRUE DH public key generation succeeded.
2777 @retval FALSE DH public key generation failed.
2778 @retval FALSE PublicKeySize is not large enough.
2779 @retval FALSE This interface is not supported.
2785 IN OUT VOID
*DhContext
,
2786 OUT UINT8
*PublicKey
,
2787 IN OUT UINTN
*PublicKeySize
2791 Computes exchanged common key.
2793 Given peer's public key, this function computes the exchanged common key, based on its own
2794 context including value of prime modulus and random secret exponent.
2796 If DhContext is NULL, then return FALSE.
2797 If PeerPublicKey is NULL, then return FALSE.
2798 If KeySize is NULL, then return FALSE.
2799 If Key is NULL, then return FALSE.
2800 If KeySize is not large enough, then return FALSE.
2801 If this interface is not supported, then return FALSE.
2803 @param[in, out] DhContext Pointer to the DH context.
2804 @param[in] PeerPublicKey Pointer to the peer's public key.
2805 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
2806 @param[out] Key Pointer to the buffer to receive generated key.
2807 @param[in, out] KeySize On input, the size of Key buffer in bytes.
2808 On output, the size of data returned in Key buffer in bytes.
2810 @retval TRUE DH exchanged key generation succeeded.
2811 @retval FALSE DH exchanged key generation failed.
2812 @retval FALSE KeySize is not large enough.
2813 @retval FALSE This interface is not supported.
2819 IN OUT VOID
*DhContext
,
2820 IN CONST UINT8
*PeerPublicKey
,
2821 IN UINTN PeerPublicKeySize
,
2823 IN OUT UINTN
*KeySize
2826 //=====================================================================================
2827 // Pseudo-Random Generation Primitive
2828 //=====================================================================================
2831 Sets up the seed value for the pseudorandom number generator.
2833 This function sets up the seed value for the pseudorandom number generator.
2834 If Seed is not NULL, then the seed passed in is used.
2835 If Seed is NULL, then default seed is used.
2836 If this interface is not supported, then return FALSE.
2838 @param[in] Seed Pointer to seed value.
2839 If NULL, default seed is used.
2840 @param[in] SeedSize Size of seed value.
2841 If Seed is NULL, this parameter is ignored.
2843 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
2844 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
2845 @retval FALSE This interface is not supported.
2851 IN CONST UINT8
*Seed OPTIONAL
,
2856 Generates a pseudorandom byte stream of the specified size.
2858 If Output is NULL, then return FALSE.
2859 If this interface is not supported, then return FALSE.
2861 @param[out] Output Pointer to buffer to receive random value.
2862 @param[in] Size Size of random bytes to generate.
2864 @retval TRUE Pseudorandom byte stream generated successfully.
2865 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
2866 @retval FALSE This interface is not supported.
2876 #endif // __BASE_CRYPT_LIB_H__