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 - 2015, 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 intialized 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 intialized 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 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.
198 If this interface is not supported, then return zero.
200 @return The size, in bytes, of the context buffer required for MD5 hash operations.
201 @retval 0 This interface is not supported.
211 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for
214 If Md5Context is NULL, then return FALSE.
215 If this interface is not supported, then return FALSE.
217 @param[out] Md5Context Pointer to MD5 context being initialized.
219 @retval TRUE MD5 context initialization succeeded.
220 @retval FALSE MD5 context initialization failed.
221 @retval FALSE This interface is not supported.
231 Makes a copy of an existing MD5 context.
233 If Md5Context is NULL, then return FALSE.
234 If NewMd5Context is NULL, then return FALSE.
235 If this interface is not supported, then return FALSE.
237 @param[in] Md5Context Pointer to MD5 context being copied.
238 @param[out] NewMd5Context Pointer to new MD5 context.
240 @retval TRUE MD5 context copy succeeded.
241 @retval FALSE MD5 context copy failed.
242 @retval FALSE This interface is not supported.
248 IN CONST VOID
*Md5Context
,
249 OUT VOID
*NewMd5Context
253 Digests the input data and updates MD5 context.
255 This function performs MD5 digest on a data buffer of the specified size.
256 It can be called multiple times to compute the digest of long or discontinuous data streams.
257 MD5 context should be already correctly intialized by Md5Init(), and should not be finalized
258 by Md5Final(). Behavior with invalid context is undefined.
260 If Md5Context is NULL, then return FALSE.
261 If this interface is not supported, then return FALSE.
263 @param[in, out] Md5Context Pointer to the MD5 context.
264 @param[in] Data Pointer to the buffer containing the data to be hashed.
265 @param[in] DataSize Size of Data buffer in bytes.
267 @retval TRUE MD5 data digest succeeded.
268 @retval FALSE MD5 data digest failed.
269 @retval FALSE This interface is not supported.
275 IN OUT VOID
*Md5Context
,
281 Completes computation of the MD5 digest value.
283 This function completes MD5 hash computation and retrieves the digest value into
284 the specified memory. After this function has been called, the MD5 context cannot
286 MD5 context should be already correctly intialized by Md5Init(), and should not be
287 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.
289 If Md5Context is NULL, then return FALSE.
290 If HashValue is NULL, then return FALSE.
291 If this interface is not supported, then return FALSE.
293 @param[in, out] Md5Context Pointer to the MD5 context.
294 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
297 @retval TRUE MD5 digest computation succeeded.
298 @retval FALSE MD5 digest computation failed.
299 @retval FALSE This interface is not supported.
305 IN OUT VOID
*Md5Context
,
310 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.
312 If this interface is not supported, then return zero.
314 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.
315 @retval 0 This interface is not supported.
325 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for
328 If Sha1Context is NULL, then return FALSE.
329 If this interface is not supported, then return FALSE.
331 @param[out] Sha1Context Pointer to SHA-1 context being initialized.
333 @retval TRUE SHA-1 context initialization succeeded.
334 @retval FALSE SHA-1 context initialization failed.
335 @retval FALSE This interface is not supported.
341 OUT VOID
*Sha1Context
345 Makes a copy of an existing SHA-1 context.
347 If Sha1Context is NULL, then return FALSE.
348 If NewSha1Context is NULL, then return FALSE.
349 If this interface is not supported, then return FALSE.
351 @param[in] Sha1Context Pointer to SHA-1 context being copied.
352 @param[out] NewSha1Context Pointer to new SHA-1 context.
354 @retval TRUE SHA-1 context copy succeeded.
355 @retval FALSE SHA-1 context copy failed.
356 @retval FALSE This interface is not supported.
362 IN CONST VOID
*Sha1Context
,
363 OUT VOID
*NewSha1Context
367 Digests the input data and updates SHA-1 context.
369 This function performs SHA-1 digest on a data buffer of the specified size.
370 It can be called multiple times to compute the digest of long or discontinuous data streams.
371 SHA-1 context should be already correctly intialized by Sha1Init(), and should not be finalized
372 by Sha1Final(). Behavior with invalid context is undefined.
374 If Sha1Context is NULL, then return FALSE.
375 If this interface is not supported, then return FALSE.
377 @param[in, out] Sha1Context Pointer to the SHA-1 context.
378 @param[in] Data Pointer to the buffer containing the data to be hashed.
379 @param[in] DataSize Size of Data buffer in bytes.
381 @retval TRUE SHA-1 data digest succeeded.
382 @retval FALSE SHA-1 data digest failed.
383 @retval FALSE This interface is not supported.
389 IN OUT VOID
*Sha1Context
,
395 Completes computation of the SHA-1 digest value.
397 This function completes SHA-1 hash computation and retrieves the digest value into
398 the specified memory. After this function has been called, the SHA-1 context cannot
400 SHA-1 context should be already correctly intialized by Sha1Init(), and should not be
401 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.
403 If Sha1Context is NULL, then return FALSE.
404 If HashValue is NULL, then return FALSE.
405 If this interface is not supported, then return FALSE.
407 @param[in, out] Sha1Context Pointer to the SHA-1 context.
408 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
411 @retval TRUE SHA-1 digest computation succeeded.
412 @retval FALSE SHA-1 digest computation failed.
413 @retval FALSE This interface is not supported.
419 IN OUT VOID
*Sha1Context
,
424 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.
426 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.
431 Sha256GetContextSize (
436 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for
439 If Sha256Context is NULL, then return FALSE.
441 @param[out] Sha256Context Pointer to SHA-256 context being initialized.
443 @retval TRUE SHA-256 context initialization succeeded.
444 @retval FALSE SHA-256 context initialization failed.
450 OUT VOID
*Sha256Context
454 Makes a copy of an existing SHA-256 context.
456 If Sha256Context is NULL, then return FALSE.
457 If NewSha256Context is NULL, then return FALSE.
458 If this interface is not supported, then return FALSE.
460 @param[in] Sha256Context Pointer to SHA-256 context being copied.
461 @param[out] NewSha256Context Pointer to new SHA-256 context.
463 @retval TRUE SHA-256 context copy succeeded.
464 @retval FALSE SHA-256 context copy failed.
465 @retval FALSE This interface is not supported.
471 IN CONST VOID
*Sha256Context
,
472 OUT VOID
*NewSha256Context
476 Digests the input data and updates SHA-256 context.
478 This function performs SHA-256 digest on a data buffer of the specified size.
479 It can be called multiple times to compute the digest of long or discontinuous data streams.
480 SHA-256 context should be already correctly intialized by Sha256Init(), and should not be finalized
481 by Sha256Final(). Behavior with invalid context is undefined.
483 If Sha256Context is NULL, then return FALSE.
485 @param[in, out] Sha256Context Pointer to the SHA-256 context.
486 @param[in] Data Pointer to the buffer containing the data to be hashed.
487 @param[in] DataSize Size of Data buffer in bytes.
489 @retval TRUE SHA-256 data digest succeeded.
490 @retval FALSE SHA-256 data digest failed.
496 IN OUT VOID
*Sha256Context
,
502 Completes computation of the SHA-256 digest value.
504 This function completes SHA-256 hash computation and retrieves the digest value into
505 the specified memory. After this function has been called, the SHA-256 context cannot
507 SHA-256 context should be already correctly intialized by Sha256Init(), and should not be
508 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.
510 If Sha256Context is NULL, then return FALSE.
511 If HashValue is NULL, then return FALSE.
513 @param[in, out] Sha256Context Pointer to the SHA-256 context.
514 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
517 @retval TRUE SHA-256 digest computation succeeded.
518 @retval FALSE SHA-256 digest computation failed.
524 IN OUT VOID
*Sha256Context
,
529 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.
531 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.
536 Sha384GetContextSize (
541 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for
544 If Sha384Context is NULL, then return FALSE.
546 @param[out] Sha384Context Pointer to SHA-384 context being initialized.
548 @retval TRUE SHA-384 context initialization succeeded.
549 @retval FALSE SHA-384 context initialization failed.
555 OUT VOID
*Sha384Context
559 Makes a copy of an existing SHA-384 context.
561 If Sha384Context is NULL, then return FALSE.
562 If NewSha384Context is NULL, then return FALSE.
563 If this interface is not supported, then return FALSE.
565 @param[in] Sha384Context Pointer to SHA-384 context being copied.
566 @param[out] NewSha384Context Pointer to new SHA-384 context.
568 @retval TRUE SHA-384 context copy succeeded.
569 @retval FALSE SHA-384 context copy failed.
570 @retval FALSE This interface is not supported.
576 IN CONST VOID
*Sha384Context
,
577 OUT VOID
*NewSha384Context
581 Digests the input data and updates SHA-384 context.
583 This function performs SHA-384 digest on a data buffer of the specified size.
584 It can be called multiple times to compute the digest of long or discontinuous data streams.
585 SHA-384 context should be already correctly intialized by Sha384Init(), and should not be finalized
586 by Sha384Final(). Behavior with invalid context is undefined.
588 If Sha384Context is NULL, then return FALSE.
590 @param[in, out] Sha384Context Pointer to the SHA-384 context.
591 @param[in] Data Pointer to the buffer containing the data to be hashed.
592 @param[in] DataSize Size of Data buffer in bytes.
594 @retval TRUE SHA-384 data digest succeeded.
595 @retval FALSE SHA-384 data digest failed.
601 IN OUT VOID
*Sha384Context
,
607 Completes computation of the SHA-384 digest value.
609 This function completes SHA-384 hash computation and retrieves the digest value into
610 the specified memory. After this function has been called, the SHA-384 context cannot
612 SHA-384 context should be already correctly intialized by Sha384Init(), and should not be
613 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.
615 If Sha384Context is NULL, then return FALSE.
616 If HashValue is NULL, then return FALSE.
618 @param[in, out] Sha384Context Pointer to the SHA-384 context.
619 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
622 @retval TRUE SHA-384 digest computation succeeded.
623 @retval FALSE SHA-384 digest computation failed.
629 IN OUT VOID
*Sha384Context
,
634 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.
636 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.
641 Sha512GetContextSize (
646 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for
649 If Sha512Context is NULL, then return FALSE.
651 @param[out] Sha512Context Pointer to SHA-512 context being initialized.
653 @retval TRUE SHA-512 context initialization succeeded.
654 @retval FALSE SHA-512 context initialization failed.
660 OUT VOID
*Sha512Context
664 Makes a copy of an existing SHA-512 context.
666 If Sha512Context is NULL, then return FALSE.
667 If NewSha512Context is NULL, then return FALSE.
668 If this interface is not supported, then return FALSE.
670 @param[in] Sha512Context Pointer to SHA-512 context being copied.
671 @param[out] NewSha512Context Pointer to new SHA-512 context.
673 @retval TRUE SHA-512 context copy succeeded.
674 @retval FALSE SHA-512 context copy failed.
675 @retval FALSE This interface is not supported.
681 IN CONST VOID
*Sha512Context
,
682 OUT VOID
*NewSha512Context
686 Digests the input data and updates SHA-512 context.
688 This function performs SHA-512 digest on a data buffer of the specified size.
689 It can be called multiple times to compute the digest of long or discontinuous data streams.
690 SHA-512 context should be already correctly intialized by Sha512Init(), and should not be finalized
691 by Sha512Final(). Behavior with invalid context is undefined.
693 If Sha512Context is NULL, then return FALSE.
695 @param[in, out] Sha512Context Pointer to the SHA-512 context.
696 @param[in] Data Pointer to the buffer containing the data to be hashed.
697 @param[in] DataSize Size of Data buffer in bytes.
699 @retval TRUE SHA-512 data digest succeeded.
700 @retval FALSE SHA-512 data digest failed.
706 IN OUT VOID
*Sha512Context
,
712 Completes computation of the SHA-512 digest value.
714 This function completes SHA-512 hash computation and retrieves the digest value into
715 the specified memory. After this function has been called, the SHA-512 context cannot
717 SHA-512 context should be already correctly intialized by Sha512Init(), and should not be
718 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.
720 If Sha512Context is NULL, then return FALSE.
721 If HashValue is NULL, then return FALSE.
723 @param[in, out] Sha512Context Pointer to the SHA-512 context.
724 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
727 @retval TRUE SHA-512 digest computation succeeded.
728 @retval FALSE SHA-512 digest computation failed.
734 IN OUT VOID
*Sha512Context
,
738 //=====================================================================================
739 // MAC (Message Authentication Code) Primitive
740 //=====================================================================================
743 Retrieves the size, in bytes, of the context buffer required for HMAC-MD5 operations.
745 If this interface is not supported, then return zero.
747 @return The size, in bytes, of the context buffer required for HMAC-MD5 operations.
748 @retval 0 This interface is not supported.
753 HmacMd5GetContextSize (
758 Initializes user-supplied memory pointed by HmacMd5Context as HMAC-MD5 context for
761 If HmacMd5Context is NULL, then return FALSE.
762 If this interface is not supported, then return FALSE.
764 @param[out] HmacMd5Context Pointer to HMAC-MD5 context being initialized.
765 @param[in] Key Pointer to the user-supplied key.
766 @param[in] KeySize Key size in bytes.
768 @retval TRUE HMAC-MD5 context initialization succeeded.
769 @retval FALSE HMAC-MD5 context initialization failed.
770 @retval FALSE This interface is not supported.
776 OUT VOID
*HmacMd5Context
,
782 Makes a copy of an existing HMAC-MD5 context.
784 If HmacMd5Context is NULL, then return FALSE.
785 If NewHmacMd5Context is NULL, then return FALSE.
786 If this interface is not supported, then return FALSE.
788 @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied.
789 @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context.
791 @retval TRUE HMAC-MD5 context copy succeeded.
792 @retval FALSE HMAC-MD5 context copy failed.
793 @retval FALSE This interface is not supported.
799 IN CONST VOID
*HmacMd5Context
,
800 OUT VOID
*NewHmacMd5Context
804 Digests the input data and updates HMAC-MD5 context.
806 This function performs HMAC-MD5 digest on a data buffer of the specified size.
807 It can be called multiple times to compute the digest of long or discontinuous data streams.
808 HMAC-MD5 context should be already correctly intialized by HmacMd5Init(), and should not be
809 finalized by HmacMd5Final(). Behavior with invalid context is undefined.
811 If HmacMd5Context is NULL, then return FALSE.
812 If this interface is not supported, then return FALSE.
814 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
815 @param[in] Data Pointer to the buffer containing the data to be digested.
816 @param[in] DataSize Size of Data buffer in bytes.
818 @retval TRUE HMAC-MD5 data digest succeeded.
819 @retval FALSE HMAC-MD5 data digest failed.
820 @retval FALSE This interface is not supported.
826 IN OUT VOID
*HmacMd5Context
,
832 Completes computation of the HMAC-MD5 digest value.
834 This function completes HMAC-MD5 hash computation and retrieves the digest value into
835 the specified memory. After this function has been called, the HMAC-MD5 context cannot
837 HMAC-MD5 context should be already correctly intialized by HmacMd5Init(), and should not be
838 finalized by HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined.
840 If HmacMd5Context is NULL, then return FALSE.
841 If HashValue is NULL, then return FALSE.
842 If this interface is not supported, then return FALSE.
844 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
845 @param[out] HashValue Pointer to a buffer that receives the HMAC-MD5 digest
848 @retval TRUE HMAC-MD5 digest computation succeeded.
849 @retval FALSE HMAC-MD5 digest computation failed.
850 @retval FALSE This interface is not supported.
856 IN OUT VOID
*HmacMd5Context
,
861 Retrieves the size, in bytes, of the context buffer required for HMAC-SHA1 operations.
863 If this interface is not supported, then return zero.
865 @return The size, in bytes, of the context buffer required for HMAC-SHA1 operations.
866 @retval 0 This interface is not supported.
871 HmacSha1GetContextSize (
876 Initializes user-supplied memory pointed by HmacSha1Context as HMAC-SHA1 context for
879 If HmacSha1Context is NULL, then return FALSE.
880 If this interface is not supported, then return FALSE.
882 @param[out] HmacSha1Context Pointer to HMAC-SHA1 context being initialized.
883 @param[in] Key Pointer to the user-supplied key.
884 @param[in] KeySize Key size in bytes.
886 @retval TRUE HMAC-SHA1 context initialization succeeded.
887 @retval FALSE HMAC-SHA1 context initialization failed.
888 @retval FALSE This interface is not supported.
894 OUT VOID
*HmacSha1Context
,
900 Makes a copy of an existing HMAC-SHA1 context.
902 If HmacSha1Context is NULL, then return FALSE.
903 If NewHmacSha1Context is NULL, then return FALSE.
904 If this interface is not supported, then return FALSE.
906 @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied.
907 @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context.
909 @retval TRUE HMAC-SHA1 context copy succeeded.
910 @retval FALSE HMAC-SHA1 context copy failed.
911 @retval FALSE This interface is not supported.
917 IN CONST VOID
*HmacSha1Context
,
918 OUT VOID
*NewHmacSha1Context
922 Digests the input data and updates HMAC-SHA1 context.
924 This function performs HMAC-SHA1 digest on a data buffer of the specified size.
925 It can be called multiple times to compute the digest of long or discontinuous data streams.
926 HMAC-SHA1 context should be already correctly intialized by HmacSha1Init(), and should not
927 be finalized by HmacSha1Final(). Behavior with invalid context is undefined.
929 If HmacSha1Context is NULL, then return FALSE.
930 If this interface is not supported, then return FALSE.
932 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
933 @param[in] Data Pointer to the buffer containing the data to be digested.
934 @param[in] DataSize Size of Data buffer in bytes.
936 @retval TRUE HMAC-SHA1 data digest succeeded.
937 @retval FALSE HMAC-SHA1 data digest failed.
938 @retval FALSE This interface is not supported.
944 IN OUT VOID
*HmacSha1Context
,
950 Completes computation of the HMAC-SHA1 digest value.
952 This function completes HMAC-SHA1 hash computation and retrieves the digest value into
953 the specified memory. After this function has been called, the HMAC-SHA1 context cannot
955 HMAC-SHA1 context should be already correctly intialized by HmacSha1Init(), and should
956 not be finalized by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined.
958 If HmacSha1Context is NULL, then return FALSE.
959 If HashValue is NULL, then return FALSE.
960 If this interface is not supported, then return FALSE.
962 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
963 @param[out] HashValue Pointer to a buffer that receives the HMAC-SHA1 digest
966 @retval TRUE HMAC-SHA1 digest computation succeeded.
967 @retval FALSE HMAC-SHA1 digest computation failed.
968 @retval FALSE This interface is not supported.
974 IN OUT VOID
*HmacSha1Context
,
978 //=====================================================================================
979 // Symmetric Cryptography Primitive
980 //=====================================================================================
983 Retrieves the size, in bytes, of the context buffer required for TDES operations.
985 If this interface is not supported, then return zero.
987 @return The size, in bytes, of the context buffer required for TDES operations.
988 @retval 0 This interface is not supported.
998 Initializes user-supplied memory as TDES context for subsequent use.
1000 This function initializes user-supplied memory pointed by TdesContext as TDES context.
1001 In addition, it sets up all TDES key materials for subsequent encryption and decryption
1003 There are 3 key options as follows:
1004 KeyLength = 64, Keying option 1: K1 == K2 == K3 (Backward compatibility with DES)
1005 KeyLength = 128, Keying option 2: K1 != K2 and K3 = K1 (Less Security)
1006 KeyLength = 192 Keying option 3: K1 != K2 != K3 (Strongest)
1008 If TdesContext is NULL, then return FALSE.
1009 If Key is NULL, then return FALSE.
1010 If KeyLength is not valid, then return FALSE.
1011 If this interface is not supported, then return FALSE.
1013 @param[out] TdesContext Pointer to TDES context being initialized.
1014 @param[in] Key Pointer to the user-supplied TDES key.
1015 @param[in] KeyLength Length of TDES key in bits.
1017 @retval TRUE TDES context initialization succeeded.
1018 @retval FALSE TDES context initialization failed.
1019 @retval FALSE This interface is not supported.
1025 OUT VOID
*TdesContext
,
1026 IN CONST UINT8
*Key
,
1031 Performs TDES encryption on a data buffer of the specified size in ECB mode.
1033 This function performs TDES encryption on data buffer pointed by Input, of specified
1034 size of InputSize, in ECB mode.
1035 InputSize must be multiple of block size (8 bytes). This function does not perform
1036 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1037 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1038 invalid TDES context is undefined.
1040 If TdesContext is NULL, then return FALSE.
1041 If Input is NULL, then return FALSE.
1042 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1043 If Output is NULL, then return FALSE.
1044 If this interface is not supported, then return FALSE.
1046 @param[in] TdesContext Pointer to the TDES context.
1047 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1048 @param[in] InputSize Size of the Input buffer in bytes.
1049 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1051 @retval TRUE TDES encryption succeeded.
1052 @retval FALSE TDES encryption failed.
1053 @retval FALSE This interface is not supported.
1059 IN VOID
*TdesContext
,
1060 IN CONST UINT8
*Input
,
1066 Performs TDES decryption on a data buffer of the specified size in ECB mode.
1068 This function performs TDES decryption on data buffer pointed by Input, of specified
1069 size of InputSize, in ECB mode.
1070 InputSize must be multiple of block size (8 bytes). This function does not perform
1071 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1072 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1073 invalid TDES context is undefined.
1075 If TdesContext is NULL, then return FALSE.
1076 If Input is NULL, then return FALSE.
1077 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1078 If Output is NULL, then return FALSE.
1079 If this interface is not supported, then return FALSE.
1081 @param[in] TdesContext Pointer to the TDES context.
1082 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1083 @param[in] InputSize Size of the Input buffer in bytes.
1084 @param[out] Output Pointer to a buffer that receives the TDES decryption output.
1086 @retval TRUE TDES decryption succeeded.
1087 @retval FALSE TDES decryption failed.
1088 @retval FALSE This interface is not supported.
1094 IN VOID
*TdesContext
,
1095 IN CONST UINT8
*Input
,
1101 Performs TDES encryption on a data buffer of the specified size in CBC mode.
1103 This function performs TDES encryption on data buffer pointed by Input, of specified
1104 size of InputSize, in CBC mode.
1105 InputSize must be multiple of block size (8 bytes). This function does not perform
1106 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1107 Initialization vector should be one block size (8 bytes).
1108 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1109 invalid TDES context is undefined.
1111 If TdesContext is NULL, then return FALSE.
1112 If Input is NULL, then return FALSE.
1113 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1114 If Ivec is NULL, then return FALSE.
1115 If Output is NULL, then return FALSE.
1116 If this interface is not supported, then return FALSE.
1118 @param[in] TdesContext Pointer to the TDES context.
1119 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1120 @param[in] InputSize Size of the Input buffer in bytes.
1121 @param[in] Ivec Pointer to initialization vector.
1122 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1124 @retval TRUE TDES encryption succeeded.
1125 @retval FALSE TDES encryption failed.
1126 @retval FALSE This interface is not supported.
1132 IN VOID
*TdesContext
,
1133 IN CONST UINT8
*Input
,
1135 IN CONST UINT8
*Ivec
,
1140 Performs TDES decryption on a data buffer of the specified size in CBC mode.
1142 This function performs TDES decryption on data buffer pointed by Input, of specified
1143 size of InputSize, in CBC mode.
1144 InputSize must be multiple of block size (8 bytes). This function does not perform
1145 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1146 Initialization vector should be one block size (8 bytes).
1147 TdesContext should be already correctly initialized by TdesInit(). Behavior with
1148 invalid TDES context is undefined.
1150 If TdesContext is NULL, then return FALSE.
1151 If Input is NULL, then return FALSE.
1152 If InputSize is not multiple of block size (8 bytes), then return FALSE.
1153 If Ivec is NULL, then return FALSE.
1154 If Output is NULL, then return FALSE.
1155 If this interface is not supported, then return FALSE.
1157 @param[in] TdesContext Pointer to the TDES context.
1158 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1159 @param[in] InputSize Size of the Input buffer in bytes.
1160 @param[in] Ivec Pointer to initialization vector.
1161 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1163 @retval TRUE TDES decryption succeeded.
1164 @retval FALSE TDES decryption failed.
1165 @retval FALSE This interface is not supported.
1171 IN VOID
*TdesContext
,
1172 IN CONST UINT8
*Input
,
1174 IN CONST UINT8
*Ivec
,
1179 Retrieves the size, in bytes, of the context buffer required for AES operations.
1181 If this interface is not supported, then return zero.
1183 @return The size, in bytes, of the context buffer required for AES operations.
1184 @retval 0 This interface is not supported.
1194 Initializes user-supplied memory as AES context for subsequent use.
1196 This function initializes user-supplied memory pointed by AesContext as AES context.
1197 In addition, it sets up all AES key materials for subsequent encryption and decryption
1199 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1201 If AesContext is NULL, then return FALSE.
1202 If Key is NULL, then return FALSE.
1203 If KeyLength is not valid, then return FALSE.
1204 If this interface is not supported, then return FALSE.
1206 @param[out] AesContext Pointer to AES context being initialized.
1207 @param[in] Key Pointer to the user-supplied AES key.
1208 @param[in] KeyLength Length of AES key in bits.
1210 @retval TRUE AES context initialization succeeded.
1211 @retval FALSE AES context initialization failed.
1212 @retval FALSE This interface is not supported.
1218 OUT VOID
*AesContext
,
1219 IN CONST UINT8
*Key
,
1224 Performs AES encryption on a data buffer of the specified size in ECB mode.
1226 This function performs AES encryption on data buffer pointed by Input, of specified
1227 size of InputSize, in ECB mode.
1228 InputSize must be multiple of block size (16 bytes). This function does not perform
1229 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1230 AesContext should be already correctly initialized by AesInit(). Behavior with
1231 invalid AES context is undefined.
1233 If AesContext is NULL, then return FALSE.
1234 If Input is NULL, then return FALSE.
1235 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1236 If Output is NULL, then return FALSE.
1237 If this interface is not supported, then return FALSE.
1239 @param[in] AesContext Pointer to the AES context.
1240 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1241 @param[in] InputSize Size of the Input buffer in bytes.
1242 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1244 @retval TRUE AES encryption succeeded.
1245 @retval FALSE AES encryption failed.
1246 @retval FALSE This interface is not supported.
1252 IN VOID
*AesContext
,
1253 IN CONST UINT8
*Input
,
1259 Performs AES decryption on a data buffer of the specified size in ECB mode.
1261 This function performs AES decryption on data buffer pointed by Input, of specified
1262 size of InputSize, in ECB mode.
1263 InputSize must be multiple of block size (16 bytes). This function does not perform
1264 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1265 AesContext should be already correctly initialized by AesInit(). Behavior with
1266 invalid AES context is undefined.
1268 If AesContext is NULL, then return FALSE.
1269 If Input is NULL, then return FALSE.
1270 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1271 If Output is NULL, then return FALSE.
1272 If this interface is not supported, then return FALSE.
1274 @param[in] AesContext Pointer to the AES context.
1275 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1276 @param[in] InputSize Size of the Input buffer in bytes.
1277 @param[out] Output Pointer to a buffer that receives the AES decryption output.
1279 @retval TRUE AES decryption succeeded.
1280 @retval FALSE AES decryption failed.
1281 @retval FALSE This interface is not supported.
1287 IN VOID
*AesContext
,
1288 IN CONST UINT8
*Input
,
1294 Performs AES encryption on a data buffer of the specified size in CBC mode.
1296 This function performs AES encryption on data buffer pointed by Input, of specified
1297 size of InputSize, in CBC mode.
1298 InputSize must be multiple of block size (16 bytes). This function does not perform
1299 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1300 Initialization vector should be one block size (16 bytes).
1301 AesContext should be already correctly initialized by AesInit(). Behavior with
1302 invalid AES context is undefined.
1304 If AesContext is NULL, then return FALSE.
1305 If Input is NULL, then return FALSE.
1306 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1307 If Ivec is NULL, then return FALSE.
1308 If Output is NULL, then return FALSE.
1309 If this interface is not supported, then return FALSE.
1311 @param[in] AesContext Pointer to the AES context.
1312 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1313 @param[in] InputSize Size of the Input buffer in bytes.
1314 @param[in] Ivec Pointer to initialization vector.
1315 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1317 @retval TRUE AES encryption succeeded.
1318 @retval FALSE AES encryption failed.
1319 @retval FALSE This interface is not supported.
1325 IN VOID
*AesContext
,
1326 IN CONST UINT8
*Input
,
1328 IN CONST UINT8
*Ivec
,
1333 Performs AES decryption on a data buffer of the specified size in CBC mode.
1335 This function performs AES decryption on data buffer pointed by Input, of specified
1336 size of InputSize, in CBC mode.
1337 InputSize must be multiple of block size (16 bytes). This function does not perform
1338 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1339 Initialization vector should be one block size (16 bytes).
1340 AesContext should be already correctly initialized by AesInit(). Behavior with
1341 invalid AES context is undefined.
1343 If AesContext is NULL, then return FALSE.
1344 If Input is NULL, then return FALSE.
1345 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1346 If Ivec is NULL, then return FALSE.
1347 If Output is NULL, then return FALSE.
1348 If this interface is not supported, then return FALSE.
1350 @param[in] AesContext Pointer to the AES context.
1351 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1352 @param[in] InputSize Size of the Input buffer in bytes.
1353 @param[in] Ivec Pointer to initialization vector.
1354 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1356 @retval TRUE AES decryption succeeded.
1357 @retval FALSE AES decryption failed.
1358 @retval FALSE This interface is not supported.
1364 IN VOID
*AesContext
,
1365 IN CONST UINT8
*Input
,
1367 IN CONST UINT8
*Ivec
,
1372 Retrieves the size, in bytes, of the context buffer required for ARC4 operations.
1374 If this interface is not supported, then return zero.
1376 @return The size, in bytes, of the context buffer required for ARC4 operations.
1377 @retval 0 This interface is not supported.
1382 Arc4GetContextSize (
1387 Initializes user-supplied memory as ARC4 context for subsequent use.
1389 This function initializes user-supplied memory pointed by Arc4Context as ARC4 context.
1390 In addition, it sets up all ARC4 key materials for subsequent encryption and decryption
1393 If Arc4Context is NULL, then return FALSE.
1394 If Key is NULL, then return FALSE.
1395 If KeySize does not in the range of [5, 256] bytes, then return FALSE.
1396 If this interface is not supported, then return FALSE.
1398 @param[out] Arc4Context Pointer to ARC4 context being initialized.
1399 @param[in] Key Pointer to the user-supplied ARC4 key.
1400 @param[in] KeySize Size of ARC4 key in bytes.
1402 @retval TRUE ARC4 context initialization succeeded.
1403 @retval FALSE ARC4 context initialization failed.
1404 @retval FALSE This interface is not supported.
1410 OUT VOID
*Arc4Context
,
1411 IN CONST UINT8
*Key
,
1416 Performs ARC4 encryption on a data buffer of the specified size.
1418 This function performs ARC4 encryption on data buffer pointed by Input, of specified
1420 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
1421 invalid ARC4 context is undefined.
1423 If Arc4Context is NULL, then return FALSE.
1424 If Input is NULL, then return FALSE.
1425 If Output is NULL, then return FALSE.
1426 If this interface is not supported, then return FALSE.
1428 @param[in] Arc4Context Pointer to the ARC4 context.
1429 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1430 @param[in] InputSize Size of the Input buffer in bytes.
1431 @param[out] Output Pointer to a buffer that receives the ARC4 encryption output.
1433 @retval TRUE ARC4 encryption succeeded.
1434 @retval FALSE ARC4 encryption failed.
1435 @retval FALSE This interface is not supported.
1441 IN OUT VOID
*Arc4Context
,
1442 IN CONST UINT8
*Input
,
1448 Performs ARC4 decryption on a data buffer of the specified size.
1450 This function performs ARC4 decryption on data buffer pointed by Input, of specified
1452 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
1453 invalid ARC4 context is undefined.
1455 If Arc4Context is NULL, then return FALSE.
1456 If Input is NULL, then return FALSE.
1457 If Output is NULL, then return FALSE.
1458 If this interface is not supported, then return FALSE.
1460 @param[in] Arc4Context Pointer to the ARC4 context.
1461 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1462 @param[in] InputSize Size of the Input buffer in bytes.
1463 @param[out] Output Pointer to a buffer that receives the ARC4 decryption output.
1465 @retval TRUE ARC4 decryption succeeded.
1466 @retval FALSE ARC4 decryption failed.
1467 @retval FALSE This interface is not supported.
1473 IN OUT VOID
*Arc4Context
,
1480 Resets the ARC4 context to the initial state.
1482 The function resets the ARC4 context to the state it had immediately after the
1483 ARC4Init() function call.
1484 Contrary to ARC4Init(), Arc4Reset() requires no secret key as input, but ARC4 context
1485 should be already correctly initialized by ARC4Init().
1487 If Arc4Context is NULL, then return FALSE.
1488 If this interface is not supported, then return FALSE.
1490 @param[in, out] Arc4Context Pointer to the ARC4 context.
1492 @retval TRUE ARC4 reset succeeded.
1493 @retval FALSE ARC4 reset failed.
1494 @retval FALSE This interface is not supported.
1500 IN OUT VOID
*Arc4Context
1503 //=====================================================================================
1504 // Asymmetric Cryptography Primitive
1505 //=====================================================================================
1508 Allocates and initializes one RSA context for subsequent use.
1510 @return Pointer to the RSA context that has been initialized.
1511 If the allocations fails, RsaNew() returns NULL.
1521 Release the specified RSA context.
1523 If RsaContext is NULL, then return FALSE.
1525 @param[in] RsaContext Pointer to the RSA context to be released.
1535 Sets the tag-designated key component into the established RSA context.
1537 This function sets the tag-designated RSA key component into the established
1538 RSA context from the user-specified non-negative integer (octet string format
1539 represented in RSA PKCS#1).
1540 If BigNumber is NULL, then the specified key componenet in RSA context is cleared.
1542 If RsaContext is NULL, then return FALSE.
1544 @param[in, out] RsaContext Pointer to RSA context being set.
1545 @param[in] KeyTag Tag of RSA key component being set.
1546 @param[in] BigNumber Pointer to octet integer buffer.
1547 If NULL, then the specified key componenet in RSA
1549 @param[in] BnSize Size of big number buffer in bytes.
1550 If BigNumber is NULL, then it is ignored.
1552 @retval TRUE RSA key component was set successfully.
1553 @retval FALSE Invalid RSA key component tag.
1559 IN OUT VOID
*RsaContext
,
1560 IN RSA_KEY_TAG KeyTag
,
1561 IN CONST UINT8
*BigNumber
,
1566 Gets the tag-designated RSA key component from the established RSA context.
1568 This function retrieves the tag-designated RSA key component from the
1569 established RSA context as a non-negative integer (octet string format
1570 represented in RSA PKCS#1).
1571 If specified key component has not been set or has been cleared, then returned
1573 If the BigNumber buffer is too small to hold the contents of the key, FALSE
1574 is returned and BnSize is set to the required buffer size to obtain the key.
1576 If RsaContext is NULL, then return FALSE.
1577 If BnSize is NULL, then return FALSE.
1578 If BnSize is large enough but BigNumber is NULL, then return FALSE.
1579 If this interface is not supported, then return FALSE.
1581 @param[in, out] RsaContext Pointer to RSA context being set.
1582 @param[in] KeyTag Tag of RSA key component being set.
1583 @param[out] BigNumber Pointer to octet integer buffer.
1584 @param[in, out] BnSize On input, the size of big number buffer in bytes.
1585 On output, the size of data returned in big number buffer in bytes.
1587 @retval TRUE RSA key component was retrieved successfully.
1588 @retval FALSE Invalid RSA key component tag.
1589 @retval FALSE BnSize is too small.
1590 @retval FALSE This interface is not supported.
1596 IN OUT VOID
*RsaContext
,
1597 IN RSA_KEY_TAG KeyTag
,
1598 OUT UINT8
*BigNumber
,
1599 IN OUT UINTN
*BnSize
1603 Generates RSA key components.
1605 This function generates RSA key components. It takes RSA public exponent E and
1606 length in bits of RSA modulus N as input, and generates all key components.
1607 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
1609 Before this function can be invoked, pseudorandom number generator must be correctly
1610 initialized by RandomSeed().
1612 If RsaContext is NULL, then return FALSE.
1613 If this interface is not supported, then return FALSE.
1615 @param[in, out] RsaContext Pointer to RSA context being set.
1616 @param[in] ModulusLength Length of RSA modulus N in bits.
1617 @param[in] PublicExponent Pointer to RSA public exponent.
1618 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
1620 @retval TRUE RSA key component was generated successfully.
1621 @retval FALSE Invalid RSA key component tag.
1622 @retval FALSE This interface is not supported.
1628 IN OUT VOID
*RsaContext
,
1629 IN UINTN ModulusLength
,
1630 IN CONST UINT8
*PublicExponent
,
1631 IN UINTN PublicExponentSize
1635 Validates key components of RSA context.
1636 NOTE: This function performs integrity checks on all the RSA key material, so
1637 the RSA key structure must contain all the private key data.
1639 This function validates key compoents of RSA context in following aspects:
1640 - Whether p is a prime
1641 - Whether q is a prime
1643 - Whether d*e = 1 mod lcm(p-1,q-1)
1645 If RsaContext is NULL, then return FALSE.
1646 If this interface is not supported, then return FALSE.
1648 @param[in] RsaContext Pointer to RSA context to check.
1650 @retval TRUE RSA key components are valid.
1651 @retval FALSE RSA key components are not valid.
1652 @retval FALSE This interface is not supported.
1662 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
1664 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
1666 If the Signature buffer is too small to hold the contents of signature, FALSE
1667 is returned and SigSize is set to the required buffer size to obtain the signature.
1669 If RsaContext is NULL, then return FALSE.
1670 If MessageHash is NULL, then return FALSE.
1671 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
1672 If SigSize is large enough but Signature is NULL, then return FALSE.
1673 If this interface is not supported, then return FALSE.
1675 @param[in] RsaContext Pointer to RSA context for signature generation.
1676 @param[in] MessageHash Pointer to octet message hash to be signed.
1677 @param[in] HashSize Size of the message hash in bytes.
1678 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
1679 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1680 On output, the size of data returned in Signature buffer in bytes.
1682 @retval TRUE Signature successfully generated in PKCS1-v1_5.
1683 @retval FALSE Signature generation failed.
1684 @retval FALSE SigSize is too small.
1685 @retval FALSE This interface is not supported.
1691 IN VOID
*RsaContext
,
1692 IN CONST UINT8
*MessageHash
,
1694 OUT UINT8
*Signature
,
1695 IN OUT UINTN
*SigSize
1699 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
1702 If RsaContext is NULL, then return FALSE.
1703 If MessageHash is NULL, then return FALSE.
1704 If Signature is NULL, then return FALSE.
1705 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
1707 @param[in] RsaContext Pointer to RSA context for signature verification.
1708 @param[in] MessageHash Pointer to octet message hash to be checked.
1709 @param[in] HashSize Size of the message hash in bytes.
1710 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
1711 @param[in] SigSize Size of signature in bytes.
1713 @retval TRUE Valid signature encoded in PKCS1-v1_5.
1714 @retval FALSE Invalid signature or invalid RSA context.
1720 IN VOID
*RsaContext
,
1721 IN CONST UINT8
*MessageHash
,
1723 IN CONST UINT8
*Signature
,
1728 Retrieve the RSA Private Key from the password-protected PEM key data.
1730 If PemData is NULL, then return FALSE.
1731 If RsaContext is NULL, then return FALSE.
1732 If this interface is not supported, then return FALSE.
1734 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
1735 @param[in] PemSize Size of the PEM key data in bytes.
1736 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
1737 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1738 RSA private key component. Use RsaFree() function to free the
1741 @retval TRUE RSA Private Key was retrieved successfully.
1742 @retval FALSE Invalid PEM key data or incorrect password.
1743 @retval FALSE This interface is not supported.
1748 RsaGetPrivateKeyFromPem (
1749 IN CONST UINT8
*PemData
,
1751 IN CONST CHAR8
*Password
,
1752 OUT VOID
**RsaContext
1756 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
1758 If Cert is NULL, then return FALSE.
1759 If RsaContext is NULL, then return FALSE.
1760 If this interface is not supported, then return FALSE.
1762 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1763 @param[in] CertSize Size of the X509 certificate in bytes.
1764 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1765 RSA public key component. Use RsaFree() function to free the
1768 @retval TRUE RSA Public Key was retrieved successfully.
1769 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
1770 @retval FALSE This interface is not supported.
1775 RsaGetPublicKeyFromX509 (
1776 IN CONST UINT8
*Cert
,
1778 OUT VOID
**RsaContext
1782 Retrieve the subject bytes from one X.509 certificate.
1784 If Cert is NULL, then return FALSE.
1785 If SubjectSize is NULL, then return FALSE.
1786 If this interface is not supported, then return FALSE.
1788 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1789 @param[in] CertSize Size of the X509 certificate in bytes.
1790 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
1791 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
1792 and the size of buffer returned CertSubject on output.
1794 @retval TRUE The certificate subject retrieved successfully.
1795 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
1796 The SubjectSize will be updated with the required size.
1797 @retval FALSE This interface is not supported.
1802 X509GetSubjectName (
1803 IN CONST UINT8
*Cert
,
1805 OUT UINT8
*CertSubject
,
1806 IN OUT UINTN
*SubjectSize
1810 Verify one X509 certificate was issued by the trusted CA.
1812 If Cert is NULL, then return FALSE.
1813 If CACert is NULL, then return FALSE.
1814 If this interface is not supported, then return FALSE.
1816 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
1817 @param[in] CertSize Size of the X509 certificate in bytes.
1818 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
1819 @param[in] CACertSize Size of the CA Certificate in bytes.
1821 @retval TRUE The certificate was issued by the trusted CA.
1822 @retval FALSE Invalid certificate or the certificate was not issued by the given
1824 @retval FALSE This interface is not supported.
1830 IN CONST UINT8
*Cert
,
1832 IN CONST UINT8
*CACert
,
1837 Construct a X509 object from DER-encoded certificate data.
1839 If Cert is NULL, then return FALSE.
1840 If SingleX509Cert is NULL, then return FALSE.
1841 If this interface is not supported, then return FALSE.
1843 @param[in] Cert Pointer to the DER-encoded certificate data.
1844 @param[in] CertSize The size of certificate data in bytes.
1845 @param[out] SingleX509Cert The generated X509 object.
1847 @retval TRUE The X509 object generation succeeded.
1848 @retval FALSE The operation failed.
1849 @retval FALSE This interface is not supported.
1854 X509ConstructCertificate (
1855 IN CONST UINT8
*Cert
,
1857 OUT UINT8
**SingleX509Cert
1861 Construct a X509 stack object from a list of DER-encoded certificate data.
1863 If X509Stack is NULL, then return FALSE.
1864 If this interface is not supported, then return FALSE.
1866 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
1867 On output, pointer to the X509 stack object with new
1868 inserted X509 certificate.
1869 @param ... A list of DER-encoded single certificate data followed
1870 by certificate size. A NULL terminates the list. The
1871 pairs are the arguments to X509ConstructCertificate().
1873 @retval TRUE The X509 stack construction succeeded.
1874 @retval FALSE The construction operation failed.
1875 @retval FALSE This interface is not supported.
1880 X509ConstructCertificateStack (
1881 IN OUT UINT8
**X509Stack
,
1886 Release the specified X509 object.
1888 If the interface is not supported, then ASSERT().
1890 @param[in] X509Cert Pointer to the X509 object to be released.
1900 Release the specified X509 stack object.
1902 If the interface is not supported, then ASSERT().
1904 @param[in] X509Stack Pointer to the X509 stack object to be released.
1914 Retrieve the TBSCertificate from one given X.509 certificate.
1916 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
1917 @param[in] CertSize Size of the X509 certificate in bytes.
1918 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
1919 @param[out] TBSCertSize Size of the TBS certificate in bytes.
1921 If Cert is NULL, then return FALSE.
1922 If TBSCert is NULL, then return FALSE.
1923 If TBSCertSize is NULL, then return FALSE.
1924 If this interface is not supported, then return FALSE.
1926 @retval TRUE The TBSCertificate was retrieved successfully.
1927 @retval FALSE Invalid X.509 certificate.
1933 IN CONST UINT8
*Cert
,
1935 OUT UINT8
**TBSCert
,
1936 OUT UINTN
*TBSCertSize
1940 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
1941 Cryptographic Message Syntax Standard". The input signed data could be wrapped
1942 in a ContentInfo structure.
1944 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
1945 return FALSE. If P7Length overflow, then return FAlSE.
1946 If this interface is not supported, then return FALSE.
1948 @param[in] P7Data Pointer to the PKCS#7 message to verify.
1949 @param[in] P7Length Length of the PKCS#7 message in bytes.
1950 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
1951 It's caller's responsiblity to free the buffer.
1952 @param[out] StackLength Length of signer's certificates in bytes.
1953 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
1954 It's caller's responsiblity to free the buffer.
1955 @param[out] CertLength Length of the trusted certificate in bytes.
1957 @retval TRUE The operation is finished successfully.
1958 @retval FALSE Error occurs during the operation.
1959 @retval FALSE This interface is not supported.
1965 IN CONST UINT8
*P7Data
,
1967 OUT UINT8
**CertStack
,
1968 OUT UINTN
*StackLength
,
1969 OUT UINT8
**TrustedCert
,
1970 OUT UINTN
*CertLength
1974 Wrap function to use free() to free allocated memory for certificates.
1976 If this interface is not supported, then ASSERT().
1978 @param[in] Certs Pointer to the certificates to be freed.
1988 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
1989 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
1990 unchained to the signer's certificates.
1991 The input signed data could be wrapped in a ContentInfo structure.
1993 @param[in] P7Data Pointer to the PKCS#7 message.
1994 @param[in] P7Length Length of the PKCS#7 message in bytes.
1995 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
1996 certificate. It's caller's responsiblity to free the buffer.
1997 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
1998 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
1999 responsiblity to free the buffer.
2000 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2002 @retval TRUE The operation is finished successfully.
2003 @retval FALSE Error occurs during the operation.
2008 Pkcs7GetCertificatesList (
2009 IN CONST UINT8
*P7Data
,
2011 OUT UINT8
**SignerChainCerts
,
2012 OUT UINTN
*ChainLength
,
2013 OUT UINT8
**UnchainCerts
,
2014 OUT UINTN
*UnchainLength
2018 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2019 Syntax Standard, version 1.5". This interface is only intended to be used for
2020 application to perform PKCS#7 functionality validation.
2022 If this interface is not supported, then return FALSE.
2024 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2026 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2027 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2029 @param[in] InData Pointer to the content to be signed.
2030 @param[in] InDataSize Size of InData in bytes.
2031 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2032 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2033 include in the PKCS#7 signedData (e.g. any intermediate
2035 @param[out] SignedData Pointer to output PKCS#7 signedData.
2036 @param[out] SignedDataSize Size of SignedData in bytes.
2038 @retval TRUE PKCS#7 data signing succeeded.
2039 @retval FALSE PKCS#7 data signing failed.
2040 @retval FALSE This interface is not supported.
2046 IN CONST UINT8
*PrivateKey
,
2047 IN UINTN PrivateKeySize
,
2048 IN CONST UINT8
*KeyPassword
,
2050 IN UINTN InDataSize
,
2052 IN UINT8
*OtherCerts OPTIONAL
,
2053 OUT UINT8
**SignedData
,
2054 OUT UINTN
*SignedDataSize
2058 Verifies the validility of a PKCS#7 signed data as described in "PKCS #7:
2059 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2060 in a ContentInfo structure.
2062 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2063 If P7Length, CertLength or DataLength overflow, then return FAlSE.
2064 If this interface is not supported, then return FALSE.
2066 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2067 @param[in] P7Length Length of the PKCS#7 message in bytes.
2068 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2069 is used for certificate chain verification.
2070 @param[in] CertLength Length of the trusted certificate in bytes.
2071 @param[in] InData Pointer to the content to be verified.
2072 @param[in] DataLength Length of InData in bytes.
2074 @retval TRUE The specified PKCS#7 signed data is valid.
2075 @retval FALSE Invalid PKCS#7 signed data.
2076 @retval FALSE This interface is not supported.
2082 IN CONST UINT8
*P7Data
,
2084 IN CONST UINT8
*TrustedCert
,
2085 IN UINTN CertLength
,
2086 IN CONST UINT8
*InData
,
2091 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2092 data could be wrapped in a ContentInfo structure.
2094 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2095 then return FAlSE. If the P7Data is not correctly formatted, then return FALSE.
2097 Caution: This function may receive untrusted input. So this function will do
2098 basic check for PKCS#7 data structure.
2100 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2101 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2102 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2103 It's caller's responsiblity to free the buffer.
2104 @param[out] ContentSize The size of the extracted content in bytes.
2106 @retval TRUE The P7Data was correctly formatted for processing.
2107 @retval FALSE The P7Data was not correctly formatted for processing.
2112 Pkcs7GetAttachedContent (
2113 IN CONST UINT8
*P7Data
,
2116 OUT UINTN
*ContentSize
2120 Verifies the validility of a PE/COFF Authenticode Signature as described in "Windows
2121 Authenticode Portable Executable Signature Format".
2123 If AuthData is NULL, then return FALSE.
2124 If ImageHash is NULL, then return FALSE.
2125 If this interface is not supported, then return FALSE.
2127 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2128 PE/COFF image to be verified.
2129 @param[in] DataSize Size of the Authenticode Signature in bytes.
2130 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2131 is used for certificate chain verification.
2132 @param[in] CertSize Size of the trusted certificate in bytes.
2133 @param[in] ImageHash Pointer to the original image file hash value. The procudure
2134 for calculating the image hash value is described in Authenticode
2136 @param[in] HashSize Size of Image hash value in bytes.
2138 @retval TRUE The specified Authenticode Signature is valid.
2139 @retval FALSE Invalid Authenticode Signature.
2140 @retval FALSE This interface is not supported.
2145 AuthenticodeVerify (
2146 IN CONST UINT8
*AuthData
,
2148 IN CONST UINT8
*TrustedCert
,
2150 IN CONST UINT8
*ImageHash
,
2155 Verifies the validility of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2158 If AuthData is NULL, then return FALSE.
2159 If this interface is not supported, then return FALSE.
2161 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2162 PE/COFF image to be verified.
2163 @param[in] DataSize Size of the Authenticode Signature in bytes.
2164 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2165 is used for TSA certificate chain verification.
2166 @param[in] CertSize Size of the trusted certificate in bytes.
2167 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2170 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2171 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2176 ImageTimestampVerify (
2177 IN CONST UINT8
*AuthData
,
2179 IN CONST UINT8
*TsaCert
,
2181 OUT EFI_TIME
*SigningTime
2184 //=====================================================================================
2185 // DH Key Exchange Primitive
2186 //=====================================================================================
2189 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
2191 @return Pointer to the Diffie-Hellman Context that has been initialized.
2192 If the allocations fails, DhNew() returns NULL.
2193 If the interface is not supported, DhNew() returns NULL.
2203 Release the specified DH context.
2205 If the interface is not supported, then ASSERT().
2207 @param[in] DhContext Pointer to the DH context to be released.
2217 Generates DH parameter.
2219 Given generator g, and length of prime number p in bits, this function generates p,
2220 and sets DH context according to value of g and p.
2222 Before this function can be invoked, pseudorandom number generator must be correctly
2223 initialized by RandomSeed().
2225 If DhContext is NULL, then return FALSE.
2226 If Prime is NULL, then return FALSE.
2227 If this interface is not supported, then return FALSE.
2229 @param[in, out] DhContext Pointer to the DH context.
2230 @param[in] Generator Value of generator.
2231 @param[in] PrimeLength Length in bits of prime to be generated.
2232 @param[out] Prime Pointer to the buffer to receive the generated prime number.
2234 @retval TRUE DH pamameter generation succeeded.
2235 @retval FALSE Value of Generator is not supported.
2236 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
2237 @retval FALSE This interface is not supported.
2242 DhGenerateParameter (
2243 IN OUT VOID
*DhContext
,
2245 IN UINTN PrimeLength
,
2250 Sets generator and prime parameters for DH.
2252 Given generator g, and prime number p, this function and sets DH
2253 context accordingly.
2255 If DhContext is NULL, then return FALSE.
2256 If Prime is NULL, then return FALSE.
2257 If this interface is not supported, then return FALSE.
2259 @param[in, out] DhContext Pointer to the DH context.
2260 @param[in] Generator Value of generator.
2261 @param[in] PrimeLength Length in bits of prime to be generated.
2262 @param[in] Prime Pointer to the prime number.
2264 @retval TRUE DH pamameter setting succeeded.
2265 @retval FALSE Value of Generator is not supported.
2266 @retval FALSE Value of Generator is not suitable for the Prime.
2267 @retval FALSE Value of Prime is not a prime number.
2268 @retval FALSE Value of Prime is not a safe prime number.
2269 @retval FALSE This interface is not supported.
2275 IN OUT VOID
*DhContext
,
2277 IN UINTN PrimeLength
,
2278 IN CONST UINT8
*Prime
2282 Generates DH public key.
2284 This function generates random secret exponent, and computes the public key, which is
2285 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
2286 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
2287 PublicKeySize is set to the required buffer size to obtain the public key.
2289 If DhContext is NULL, then return FALSE.
2290 If PublicKeySize is NULL, then return FALSE.
2291 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
2292 If this interface is not supported, then return FALSE.
2294 @param[in, out] DhContext Pointer to the DH context.
2295 @param[out] PublicKey Pointer to the buffer to receive generated public key.
2296 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
2297 On output, the size of data returned in PublicKey buffer in bytes.
2299 @retval TRUE DH public key generation succeeded.
2300 @retval FALSE DH public key generation failed.
2301 @retval FALSE PublicKeySize is not large enough.
2302 @retval FALSE This interface is not supported.
2308 IN OUT VOID
*DhContext
,
2309 OUT UINT8
*PublicKey
,
2310 IN OUT UINTN
*PublicKeySize
2314 Computes exchanged common key.
2316 Given peer's public key, this function computes the exchanged common key, based on its own
2317 context including value of prime modulus and random secret exponent.
2319 If DhContext is NULL, then return FALSE.
2320 If PeerPublicKey is NULL, then return FALSE.
2321 If KeySize is NULL, then return FALSE.
2322 If Key is NULL, then return FALSE.
2323 If KeySize is not large enough, then return FALSE.
2324 If this interface is not supported, then return FALSE.
2326 @param[in, out] DhContext Pointer to the DH context.
2327 @param[in] PeerPublicKey Pointer to the peer's public key.
2328 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
2329 @param[out] Key Pointer to the buffer to receive generated key.
2330 @param[in, out] KeySize On input, the size of Key buffer in bytes.
2331 On output, the size of data returned in Key buffer in bytes.
2333 @retval TRUE DH exchanged key generation succeeded.
2334 @retval FALSE DH exchanged key generation failed.
2335 @retval FALSE KeySize is not large enough.
2336 @retval FALSE This interface is not supported.
2342 IN OUT VOID
*DhContext
,
2343 IN CONST UINT8
*PeerPublicKey
,
2344 IN UINTN PeerPublicKeySize
,
2346 IN OUT UINTN
*KeySize
2349 //=====================================================================================
2350 // Pseudo-Random Generation Primitive
2351 //=====================================================================================
2354 Sets up the seed value for the pseudorandom number generator.
2356 This function sets up the seed value for the pseudorandom number generator.
2357 If Seed is not NULL, then the seed passed in is used.
2358 If Seed is NULL, then default seed is used.
2359 If this interface is not supported, then return FALSE.
2361 @param[in] Seed Pointer to seed value.
2362 If NULL, default seed is used.
2363 @param[in] SeedSize Size of seed value.
2364 If Seed is NULL, this parameter is ignored.
2366 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
2367 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
2368 @retval FALSE This interface is not supported.
2374 IN CONST UINT8
*Seed OPTIONAL
,
2379 Generates a pseudorandom byte stream of the specified size.
2381 If Output is NULL, then return FALSE.
2382 If this interface is not supported, then return FALSE.
2384 @param[out] Output Pointer to buffer to receive random value.
2385 @param[in] Size Size of randome bytes to generate.
2387 @retval TRUE Pseudorandom byte stream generated successfully.
2388 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
2389 @retval FALSE This interface is not supported.
2399 #endif // __BASE_CRYPT_LIB_H__