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 - 2022, Intel Corporation. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #ifndef __BASE_CRYPT_LIB_H__
13 #define __BASE_CRYPT_LIB_H__
15 #include <Uefi/UefiBaseType.h>
17 #define CRYPTO_NID_NULL 0x0000
20 #define CRYPTO_NID_SHA256 0x0001
21 #define CRYPTO_NID_SHA384 0x0002
22 #define CRYPTO_NID_SHA512 0x0003
25 #define CRYPTO_NID_SECP256R1 0x0204
26 #define CRYPTO_NID_SECP384R1 0x0205
27 #define CRYPTO_NID_SECP521R1 0x0206
30 /// MD5 digest size in bytes
32 #define MD5_DIGEST_SIZE 16
35 /// SHA-1 digest size in bytes.
37 #define SHA1_DIGEST_SIZE 20
40 /// SHA-256 digest size in bytes
42 #define SHA256_DIGEST_SIZE 32
45 /// SHA-384 digest size in bytes
47 #define SHA384_DIGEST_SIZE 48
50 /// SHA-512 digest size in bytes
52 #define SHA512_DIGEST_SIZE 64
55 /// SM3 digest size in bytes
57 #define SM3_256_DIGEST_SIZE 32
60 /// TDES block size in bytes
62 #define TDES_BLOCK_SIZE 8
65 /// AES block size in bytes
67 #define AES_BLOCK_SIZE 16
70 /// RSA Key Tags Definition used in RsaSetKey() function for key component identification.
73 RsaKeyN
, ///< RSA public Modulus (N)
74 RsaKeyE
, ///< RSA Public exponent (e)
75 RsaKeyD
, ///< RSA Private exponent (d)
76 RsaKeyP
, ///< RSA secret prime factor of Modulus (p)
77 RsaKeyQ
, ///< RSA secret prime factor of Modules (q)
78 RsaKeyDp
, ///< p's CRT exponent (== d mod (p - 1))
79 RsaKeyDq
, ///< q's CRT exponent (== d mod (q - 1))
80 RsaKeyQInv
///< The CRT coefficient (== 1/q mod p)
83 // =====================================================================================
84 // One-Way Cryptographic Hash Primitives
85 // =====================================================================================
87 #ifdef ENABLE_MD5_DEPRECATED_INTERFACES
90 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.
92 If this interface is not supported, then return zero.
94 @return The size, in bytes, of the context buffer required for MD5 hash operations.
95 @retval 0 This interface is not supported.
105 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for
108 If Md5Context is NULL, then return FALSE.
109 If this interface is not supported, then return FALSE.
111 @param[out] Md5Context Pointer to MD5 context being initialized.
113 @retval TRUE MD5 context initialization succeeded.
114 @retval FALSE MD5 context initialization failed.
115 @retval FALSE This interface is not supported.
125 Makes a copy of an existing MD5 context.
127 If Md5Context is NULL, then return FALSE.
128 If NewMd5Context is NULL, then return FALSE.
129 If this interface is not supported, then return FALSE.
131 @param[in] Md5Context Pointer to MD5 context being copied.
132 @param[out] NewMd5Context Pointer to new MD5 context.
134 @retval TRUE MD5 context copy succeeded.
135 @retval FALSE MD5 context copy failed.
136 @retval FALSE This interface is not supported.
142 IN CONST VOID
*Md5Context
,
143 OUT VOID
*NewMd5Context
147 Digests the input data and updates MD5 context.
149 This function performs MD5 digest on a data buffer of the specified size.
150 It can be called multiple times to compute the digest of long or discontinuous data streams.
151 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized
152 by Md5Final(). Behavior with invalid context is undefined.
154 If Md5Context is NULL, then return FALSE.
155 If this interface is not supported, then return FALSE.
157 @param[in, out] Md5Context Pointer to the MD5 context.
158 @param[in] Data Pointer to the buffer containing the data to be hashed.
159 @param[in] DataSize Size of Data buffer in bytes.
161 @retval TRUE MD5 data digest succeeded.
162 @retval FALSE MD5 data digest failed.
163 @retval FALSE This interface is not supported.
169 IN OUT VOID
*Md5Context
,
175 Completes computation of the MD5 digest value.
177 This function completes MD5 hash computation and retrieves the digest value into
178 the specified memory. After this function has been called, the MD5 context cannot
180 MD5 context should be already correctly initialized by Md5Init(), and should not be
181 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.
183 If Md5Context is NULL, then return FALSE.
184 If HashValue is NULL, then return FALSE.
185 If this interface is not supported, then return FALSE.
187 @param[in, out] Md5Context Pointer to the MD5 context.
188 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
191 @retval TRUE MD5 digest computation succeeded.
192 @retval FALSE MD5 digest computation failed.
193 @retval FALSE This interface is not supported.
199 IN OUT VOID
*Md5Context
,
204 Computes the MD5 message digest of a input data buffer.
206 This function performs the MD5 message digest of a given data buffer, and places
207 the digest value into the specified memory.
209 If this interface is not supported, then return FALSE.
211 @param[in] Data Pointer to the buffer containing the data to be hashed.
212 @param[in] DataSize Size of Data buffer in bytes.
213 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
216 @retval TRUE MD5 digest computation succeeded.
217 @retval FALSE MD5 digest computation failed.
218 @retval FALSE This interface is not supported.
231 #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
234 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.
236 If this interface is not supported, then return zero.
238 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.
239 @retval 0 This interface is not supported.
249 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for
252 If Sha1Context is NULL, then return FALSE.
253 If this interface is not supported, then return FALSE.
255 @param[out] Sha1Context Pointer to SHA-1 context being initialized.
257 @retval TRUE SHA-1 context initialization succeeded.
258 @retval FALSE SHA-1 context initialization failed.
259 @retval FALSE This interface is not supported.
265 OUT VOID
*Sha1Context
269 Makes a copy of an existing SHA-1 context.
271 If Sha1Context is NULL, then return FALSE.
272 If NewSha1Context is NULL, then return FALSE.
273 If this interface is not supported, then return FALSE.
275 @param[in] Sha1Context Pointer to SHA-1 context being copied.
276 @param[out] NewSha1Context Pointer to new SHA-1 context.
278 @retval TRUE SHA-1 context copy succeeded.
279 @retval FALSE SHA-1 context copy failed.
280 @retval FALSE This interface is not supported.
286 IN CONST VOID
*Sha1Context
,
287 OUT VOID
*NewSha1Context
291 Digests the input data and updates SHA-1 context.
293 This function performs SHA-1 digest on a data buffer of the specified size.
294 It can be called multiple times to compute the digest of long or discontinuous data streams.
295 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized
296 by Sha1Final(). Behavior with invalid context is undefined.
298 If Sha1Context is NULL, then return FALSE.
299 If this interface is not supported, then return FALSE.
301 @param[in, out] Sha1Context Pointer to the SHA-1 context.
302 @param[in] Data Pointer to the buffer containing the data to be hashed.
303 @param[in] DataSize Size of Data buffer in bytes.
305 @retval TRUE SHA-1 data digest succeeded.
306 @retval FALSE SHA-1 data digest failed.
307 @retval FALSE This interface is not supported.
313 IN OUT VOID
*Sha1Context
,
319 Completes computation of the SHA-1 digest value.
321 This function completes SHA-1 hash computation and retrieves the digest value into
322 the specified memory. After this function has been called, the SHA-1 context cannot
324 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be
325 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.
327 If Sha1Context is NULL, then return FALSE.
328 If HashValue is NULL, then return FALSE.
329 If this interface is not supported, then return FALSE.
331 @param[in, out] Sha1Context Pointer to the SHA-1 context.
332 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
335 @retval TRUE SHA-1 digest computation succeeded.
336 @retval FALSE SHA-1 digest computation failed.
337 @retval FALSE This interface is not supported.
343 IN OUT VOID
*Sha1Context
,
348 Computes the SHA-1 message digest of a input data buffer.
350 This function performs the SHA-1 message digest of a given data buffer, and places
351 the digest value into the specified memory.
353 If this interface is not supported, then return FALSE.
355 @param[in] Data Pointer to the buffer containing the data to be hashed.
356 @param[in] DataSize Size of Data buffer in bytes.
357 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
360 @retval TRUE SHA-1 digest computation succeeded.
361 @retval FALSE SHA-1 digest computation failed.
362 @retval FALSE This interface is not supported.
376 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.
378 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.
383 Sha256GetContextSize (
388 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for
391 If Sha256Context is NULL, then return FALSE.
393 @param[out] Sha256Context Pointer to SHA-256 context being initialized.
395 @retval TRUE SHA-256 context initialization succeeded.
396 @retval FALSE SHA-256 context initialization failed.
402 OUT VOID
*Sha256Context
406 Makes a copy of an existing SHA-256 context.
408 If Sha256Context is NULL, then return FALSE.
409 If NewSha256Context is NULL, then return FALSE.
410 If this interface is not supported, then return FALSE.
412 @param[in] Sha256Context Pointer to SHA-256 context being copied.
413 @param[out] NewSha256Context Pointer to new SHA-256 context.
415 @retval TRUE SHA-256 context copy succeeded.
416 @retval FALSE SHA-256 context copy failed.
417 @retval FALSE This interface is not supported.
423 IN CONST VOID
*Sha256Context
,
424 OUT VOID
*NewSha256Context
428 Digests the input data and updates SHA-256 context.
430 This function performs SHA-256 digest on a data buffer of the specified size.
431 It can be called multiple times to compute the digest of long or discontinuous data streams.
432 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized
433 by Sha256Final(). Behavior with invalid context is undefined.
435 If Sha256Context is NULL, then return FALSE.
437 @param[in, out] Sha256Context Pointer to the SHA-256 context.
438 @param[in] Data Pointer to the buffer containing the data to be hashed.
439 @param[in] DataSize Size of Data buffer in bytes.
441 @retval TRUE SHA-256 data digest succeeded.
442 @retval FALSE SHA-256 data digest failed.
448 IN OUT VOID
*Sha256Context
,
454 Completes computation of the SHA-256 digest value.
456 This function completes SHA-256 hash computation and retrieves the digest value into
457 the specified memory. After this function has been called, the SHA-256 context cannot
459 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be
460 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.
462 If Sha256Context is NULL, then return FALSE.
463 If HashValue is NULL, then return FALSE.
465 @param[in, out] Sha256Context Pointer to the SHA-256 context.
466 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
469 @retval TRUE SHA-256 digest computation succeeded.
470 @retval FALSE SHA-256 digest computation failed.
476 IN OUT VOID
*Sha256Context
,
481 Computes the SHA-256 message digest of a input data buffer.
483 This function performs the SHA-256 message digest of a given data buffer, and places
484 the digest value into the specified memory.
486 If this interface is not supported, then return FALSE.
488 @param[in] Data Pointer to the buffer containing the data to be hashed.
489 @param[in] DataSize Size of Data buffer in bytes.
490 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
493 @retval TRUE SHA-256 digest computation succeeded.
494 @retval FALSE SHA-256 digest computation failed.
495 @retval FALSE This interface is not supported.
507 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.
509 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.
514 Sha384GetContextSize (
519 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for
522 If Sha384Context is NULL, then return FALSE.
524 @param[out] Sha384Context Pointer to SHA-384 context being initialized.
526 @retval TRUE SHA-384 context initialization succeeded.
527 @retval FALSE SHA-384 context initialization failed.
533 OUT VOID
*Sha384Context
537 Makes a copy of an existing SHA-384 context.
539 If Sha384Context is NULL, then return FALSE.
540 If NewSha384Context is NULL, then return FALSE.
541 If this interface is not supported, then return FALSE.
543 @param[in] Sha384Context Pointer to SHA-384 context being copied.
544 @param[out] NewSha384Context Pointer to new SHA-384 context.
546 @retval TRUE SHA-384 context copy succeeded.
547 @retval FALSE SHA-384 context copy failed.
548 @retval FALSE This interface is not supported.
554 IN CONST VOID
*Sha384Context
,
555 OUT VOID
*NewSha384Context
559 Digests the input data and updates SHA-384 context.
561 This function performs SHA-384 digest on a data buffer of the specified size.
562 It can be called multiple times to compute the digest of long or discontinuous data streams.
563 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized
564 by Sha384Final(). Behavior with invalid context is undefined.
566 If Sha384Context is NULL, then return FALSE.
568 @param[in, out] Sha384Context Pointer to the SHA-384 context.
569 @param[in] Data Pointer to the buffer containing the data to be hashed.
570 @param[in] DataSize Size of Data buffer in bytes.
572 @retval TRUE SHA-384 data digest succeeded.
573 @retval FALSE SHA-384 data digest failed.
579 IN OUT VOID
*Sha384Context
,
585 Completes computation of the SHA-384 digest value.
587 This function completes SHA-384 hash computation and retrieves the digest value into
588 the specified memory. After this function has been called, the SHA-384 context cannot
590 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be
591 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.
593 If Sha384Context is NULL, then return FALSE.
594 If HashValue is NULL, then return FALSE.
596 @param[in, out] Sha384Context Pointer to the SHA-384 context.
597 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
600 @retval TRUE SHA-384 digest computation succeeded.
601 @retval FALSE SHA-384 digest computation failed.
607 IN OUT VOID
*Sha384Context
,
612 Computes the SHA-384 message digest of a input data buffer.
614 This function performs the SHA-384 message digest of a given data buffer, and places
615 the digest value into the specified memory.
617 If this interface is not supported, then return FALSE.
619 @param[in] Data Pointer to the buffer containing the data to be hashed.
620 @param[in] DataSize Size of Data buffer in bytes.
621 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
624 @retval TRUE SHA-384 digest computation succeeded.
625 @retval FALSE SHA-384 digest computation failed.
626 @retval FALSE This interface is not supported.
638 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.
640 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.
645 Sha512GetContextSize (
650 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for
653 If Sha512Context is NULL, then return FALSE.
655 @param[out] Sha512Context Pointer to SHA-512 context being initialized.
657 @retval TRUE SHA-512 context initialization succeeded.
658 @retval FALSE SHA-512 context initialization failed.
664 OUT VOID
*Sha512Context
668 Makes a copy of an existing SHA-512 context.
670 If Sha512Context is NULL, then return FALSE.
671 If NewSha512Context is NULL, then return FALSE.
672 If this interface is not supported, then return FALSE.
674 @param[in] Sha512Context Pointer to SHA-512 context being copied.
675 @param[out] NewSha512Context Pointer to new SHA-512 context.
677 @retval TRUE SHA-512 context copy succeeded.
678 @retval FALSE SHA-512 context copy failed.
679 @retval FALSE This interface is not supported.
685 IN CONST VOID
*Sha512Context
,
686 OUT VOID
*NewSha512Context
690 Digests the input data and updates SHA-512 context.
692 This function performs SHA-512 digest on a data buffer of the specified size.
693 It can be called multiple times to compute the digest of long or discontinuous data streams.
694 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized
695 by Sha512Final(). Behavior with invalid context is undefined.
697 If Sha512Context is NULL, then return FALSE.
699 @param[in, out] Sha512Context Pointer to the SHA-512 context.
700 @param[in] Data Pointer to the buffer containing the data to be hashed.
701 @param[in] DataSize Size of Data buffer in bytes.
703 @retval TRUE SHA-512 data digest succeeded.
704 @retval FALSE SHA-512 data digest failed.
710 IN OUT VOID
*Sha512Context
,
716 Completes computation of the SHA-512 digest value.
718 This function completes SHA-512 hash computation and retrieves the digest value into
719 the specified memory. After this function has been called, the SHA-512 context cannot
721 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be
722 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.
724 If Sha512Context is NULL, then return FALSE.
725 If HashValue is NULL, then return FALSE.
727 @param[in, out] Sha512Context Pointer to the SHA-512 context.
728 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
731 @retval TRUE SHA-512 digest computation succeeded.
732 @retval FALSE SHA-512 digest computation failed.
738 IN OUT VOID
*Sha512Context
,
743 Computes the SHA-512 message digest of a input data buffer.
745 This function performs the SHA-512 message digest of a given data buffer, and places
746 the digest value into the specified memory.
748 If this interface is not supported, then return FALSE.
750 @param[in] Data Pointer to the buffer containing the data to be hashed.
751 @param[in] DataSize Size of Data buffer in bytes.
752 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
755 @retval TRUE SHA-512 digest computation succeeded.
756 @retval FALSE SHA-512 digest computation failed.
757 @retval FALSE This interface is not supported.
769 Parallel hash function ParallelHash256, as defined in NIST's Special Publication 800-185,
770 published December 2016.
772 @param[in] Input Pointer to the input message (X).
773 @param[in] InputByteLen The number(>0) of input bytes provided for the input data.
774 @param[in] BlockSize The size of each block (B).
775 @param[out] Output Pointer to the output buffer.
776 @param[in] OutputByteLen The desired number of output bytes (L).
777 @param[in] Customization Pointer to the customization string (S).
778 @param[in] CustomByteLen The length of the customization string in bytes.
780 @retval TRUE ParallelHash256 digest computation succeeded.
781 @retval FALSE ParallelHash256 digest computation failed.
782 @retval FALSE This interface is not supported.
787 ParallelHash256HashAll (
788 IN CONST VOID
*Input
,
789 IN UINTN InputByteLen
,
792 IN UINTN OutputByteLen
,
793 IN CONST VOID
*Customization
,
794 IN UINTN CustomByteLen
798 Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.
800 @return The size, in bytes, of the context buffer required for SM3 hash operations.
810 Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for
813 If Sm3Context is NULL, then return FALSE.
815 @param[out] Sm3Context Pointer to SM3 context being initialized.
817 @retval TRUE SM3 context initialization succeeded.
818 @retval FALSE SM3 context initialization failed.
828 Makes a copy of an existing SM3 context.
830 If Sm3Context is NULL, then return FALSE.
831 If NewSm3Context is NULL, then return FALSE.
832 If this interface is not supported, then return FALSE.
834 @param[in] Sm3Context Pointer to SM3 context being copied.
835 @param[out] NewSm3Context Pointer to new SM3 context.
837 @retval TRUE SM3 context copy succeeded.
838 @retval FALSE SM3 context copy failed.
839 @retval FALSE This interface is not supported.
845 IN CONST VOID
*Sm3Context
,
846 OUT VOID
*NewSm3Context
850 Digests the input data and updates SM3 context.
852 This function performs SM3 digest on a data buffer of the specified size.
853 It can be called multiple times to compute the digest of long or discontinuous data streams.
854 SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized
855 by Sm3Final(). Behavior with invalid context is undefined.
857 If Sm3Context is NULL, then return FALSE.
859 @param[in, out] Sm3Context Pointer to the SM3 context.
860 @param[in] Data Pointer to the buffer containing the data to be hashed.
861 @param[in] DataSize Size of Data buffer in bytes.
863 @retval TRUE SM3 data digest succeeded.
864 @retval FALSE SM3 data digest failed.
870 IN OUT VOID
*Sm3Context
,
876 Completes computation of the SM3 digest value.
878 This function completes SM3 hash computation and retrieves the digest value into
879 the specified memory. After this function has been called, the SM3 context cannot
881 SM3 context should be already correctly initialized by Sm3Init(), and should not be
882 finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.
884 If Sm3Context is NULL, then return FALSE.
885 If HashValue is NULL, then return FALSE.
887 @param[in, out] Sm3Context Pointer to the SM3 context.
888 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
891 @retval TRUE SM3 digest computation succeeded.
892 @retval FALSE SM3 digest computation failed.
898 IN OUT VOID
*Sm3Context
,
903 Computes the SM3 message digest of a input data buffer.
905 This function performs the SM3 message digest of a given data buffer, and places
906 the digest value into the specified memory.
908 If this interface is not supported, then return FALSE.
910 @param[in] Data Pointer to the buffer containing the data to be hashed.
911 @param[in] DataSize Size of Data buffer in bytes.
912 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
915 @retval TRUE SM3 digest computation succeeded.
916 @retval FALSE SM3 digest computation failed.
917 @retval FALSE This interface is not supported.
928 // =====================================================================================
929 // MAC (Message Authentication Code) Primitive
930 // =====================================================================================
933 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
935 @return Pointer to the HMAC_CTX context that has been initialized.
936 If the allocations fails, HmacSha256New() returns NULL.
946 Release the specified HMAC_CTX context.
948 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.
954 IN VOID
*HmacSha256Ctx
958 Set user-supplied key for subsequent use. It must be done before any
959 calling to HmacSha256Update().
961 If HmacSha256Context is NULL, then return FALSE.
962 If this interface is not supported, then return FALSE.
964 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.
965 @param[in] Key Pointer to the user-supplied key.
966 @param[in] KeySize Key size in bytes.
968 @retval TRUE The Key is set successfully.
969 @retval FALSE The Key is set unsuccessfully.
970 @retval FALSE This interface is not supported.
976 OUT VOID
*HmacSha256Context
,
982 Makes a copy of an existing HMAC-SHA256 context.
984 If HmacSha256Context is NULL, then return FALSE.
985 If NewHmacSha256Context is NULL, then return FALSE.
986 If this interface is not supported, then return FALSE.
988 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.
989 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.
991 @retval TRUE HMAC-SHA256 context copy succeeded.
992 @retval FALSE HMAC-SHA256 context copy failed.
993 @retval FALSE This interface is not supported.
998 HmacSha256Duplicate (
999 IN CONST VOID
*HmacSha256Context
,
1000 OUT VOID
*NewHmacSha256Context
1004 Digests the input data and updates HMAC-SHA256 context.
1006 This function performs HMAC-SHA256 digest on a data buffer of the specified size.
1007 It can be called multiple times to compute the digest of long or discontinuous data streams.
1008 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1009 by HmacSha256Final(). Behavior with invalid context is undefined.
1011 If HmacSha256Context is NULL, then return FALSE.
1012 If this interface is not supported, then return FALSE.
1014 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1015 @param[in] Data Pointer to the buffer containing the data to be digested.
1016 @param[in] DataSize Size of Data buffer in bytes.
1018 @retval TRUE HMAC-SHA256 data digest succeeded.
1019 @retval FALSE HMAC-SHA256 data digest failed.
1020 @retval FALSE This interface is not supported.
1026 IN OUT VOID
*HmacSha256Context
,
1027 IN CONST VOID
*Data
,
1032 Completes computation of the HMAC-SHA256 digest value.
1034 This function completes HMAC-SHA256 hash computation and retrieves the digest value into
1035 the specified memory. After this function has been called, the HMAC-SHA256 context cannot
1037 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1038 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.
1040 If HmacSha256Context is NULL, then return FALSE.
1041 If HmacValue is NULL, then return FALSE.
1042 If this interface is not supported, then return FALSE.
1044 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1045 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
1048 @retval TRUE HMAC-SHA256 digest computation succeeded.
1049 @retval FALSE HMAC-SHA256 digest computation failed.
1050 @retval FALSE This interface is not supported.
1056 IN OUT VOID
*HmacSha256Context
,
1057 OUT UINT8
*HmacValue
1061 Computes the HMAC-SHA256 digest of a input data buffer.
1063 This function performs the HMAC-SHA256 digest of a given data buffer, and places
1064 the digest value into the specified memory.
1066 If this interface is not supported, then return FALSE.
1068 @param[in] Data Pointer to the buffer containing the data to be digested.
1069 @param[in] DataSize Size of Data buffer in bytes.
1070 @param[in] Key Pointer to the user-supplied key.
1071 @param[in] KeySize Key size in bytes.
1072 @param[out] HashValue Pointer to a buffer that receives the HMAC-SHA256 digest
1075 @retval TRUE HMAC-SHA256 digest computation succeeded.
1076 @retval FALSE HMAC-SHA256 digest computation failed.
1077 @retval FALSE This interface is not supported.
1083 IN CONST VOID
*Data
,
1085 IN CONST UINT8
*Key
,
1087 OUT UINT8
*HmacValue
1091 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA384 use.
1093 @return Pointer to the HMAC_CTX context that has been initialized.
1094 If the allocations fails, HmacSha384New() returns NULL.
1104 Release the specified HMAC_CTX context.
1106 @param[in] HmacSha384Ctx Pointer to the HMAC_CTX context to be released.
1112 IN VOID
*HmacSha384Ctx
1116 Set user-supplied key for subsequent use. It must be done before any
1117 calling to HmacSha384Update().
1119 If HmacSha384Context is NULL, then return FALSE.
1120 If this interface is not supported, then return FALSE.
1122 @param[out] HmacSha384Context Pointer to HMAC-SHA384 context.
1123 @param[in] Key Pointer to the user-supplied key.
1124 @param[in] KeySize Key size in bytes.
1126 @retval TRUE The Key is set successfully.
1127 @retval FALSE The Key is set unsuccessfully.
1128 @retval FALSE This interface is not supported.
1134 OUT VOID
*HmacSha384Context
,
1135 IN CONST UINT8
*Key
,
1140 Makes a copy of an existing HMAC-SHA384 context.
1142 If HmacSha384Context is NULL, then return FALSE.
1143 If NewHmacSha384Context is NULL, then return FALSE.
1144 If this interface is not supported, then return FALSE.
1146 @param[in] HmacSha384Context Pointer to HMAC-SHA384 context being copied.
1147 @param[out] NewHmacSha384Context Pointer to new HMAC-SHA384 context.
1149 @retval TRUE HMAC-SHA384 context copy succeeded.
1150 @retval FALSE HMAC-SHA384 context copy failed.
1151 @retval FALSE This interface is not supported.
1156 HmacSha384Duplicate (
1157 IN CONST VOID
*HmacSha384Context
,
1158 OUT VOID
*NewHmacSha384Context
1162 Digests the input data and updates HMAC-SHA384 context.
1164 This function performs HMAC-SHA384 digest on a data buffer of the specified size.
1165 It can be called multiple times to compute the digest of long or discontinuous data streams.
1166 HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized
1167 by HmacSha384Final(). Behavior with invalid context is undefined.
1169 If HmacSha384Context is NULL, then return FALSE.
1170 If this interface is not supported, then return FALSE.
1172 @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.
1173 @param[in] Data Pointer to the buffer containing the data to be digested.
1174 @param[in] DataSize Size of Data buffer in bytes.
1176 @retval TRUE HMAC-SHA384 data digest succeeded.
1177 @retval FALSE HMAC-SHA384 data digest failed.
1178 @retval FALSE This interface is not supported.
1184 IN OUT VOID
*HmacSha384Context
,
1185 IN CONST VOID
*Data
,
1190 Completes computation of the HMAC-SHA384 digest value.
1192 This function completes HMAC-SHA384 hash computation and retrieves the digest value into
1193 the specified memory. After this function has been called, the HMAC-SHA384 context cannot
1195 HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized
1196 by HmacSha384Final(). Behavior with invalid HMAC-SHA384 context is undefined.
1198 If HmacSha384Context is NULL, then return FALSE.
1199 If HmacValue is NULL, then return FALSE.
1200 If this interface is not supported, then return FALSE.
1202 @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.
1203 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA384 digest
1206 @retval TRUE HMAC-SHA384 digest computation succeeded.
1207 @retval FALSE HMAC-SHA384 digest computation failed.
1208 @retval FALSE This interface is not supported.
1214 IN OUT VOID
*HmacSha384Context
,
1215 OUT UINT8
*HmacValue
1219 Computes the HMAC-SHA384 digest of a input data buffer.
1221 This function performs the HMAC-SHA384 digest of a given data buffer, and places
1222 the digest value into the specified memory.
1224 If this interface is not supported, then return FALSE.
1226 @param[in] Data Pointer to the buffer containing the data to be digested.
1227 @param[in] DataSize Size of Data buffer in bytes.
1228 @param[in] Key Pointer to the user-supplied key.
1229 @param[in] KeySize Key size in bytes.
1230 @param[out] HashValue Pointer to a buffer that receives the HMAC-SHA384 digest
1233 @retval TRUE HMAC-SHA384 digest computation succeeded.
1234 @retval FALSE HMAC-SHA384 digest computation failed.
1235 @retval FALSE This interface is not supported.
1241 IN CONST VOID
*Data
,
1243 IN CONST UINT8
*Key
,
1245 OUT UINT8
*HmacValue
1248 // =====================================================================================
1249 // Symmetric Cryptography Primitive
1250 // =====================================================================================
1253 Retrieves the size, in bytes, of the context buffer required for AES operations.
1255 If this interface is not supported, then return zero.
1257 @return The size, in bytes, of the context buffer required for AES operations.
1258 @retval 0 This interface is not supported.
1268 Initializes user-supplied memory as AES context for subsequent use.
1270 This function initializes user-supplied memory pointed by AesContext as AES context.
1271 In addition, it sets up all AES key materials for subsequent encryption and decryption
1273 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1275 If AesContext is NULL, then return FALSE.
1276 If Key is NULL, then return FALSE.
1277 If KeyLength is not valid, then return FALSE.
1278 If this interface is not supported, then return FALSE.
1280 @param[out] AesContext Pointer to AES context being initialized.
1281 @param[in] Key Pointer to the user-supplied AES key.
1282 @param[in] KeyLength Length of AES key in bits.
1284 @retval TRUE AES context initialization succeeded.
1285 @retval FALSE AES context initialization failed.
1286 @retval FALSE This interface is not supported.
1292 OUT VOID
*AesContext
,
1293 IN CONST UINT8
*Key
,
1298 Performs AES encryption on a data buffer of the specified size in CBC mode.
1300 This function performs AES encryption on data buffer pointed by Input, of specified
1301 size of InputSize, in CBC mode.
1302 InputSize must be multiple of block size (16 bytes). This function does not perform
1303 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1304 Initialization vector should be one block size (16 bytes).
1305 AesContext should be already correctly initialized by AesInit(). Behavior with
1306 invalid AES context is undefined.
1308 If AesContext is NULL, then return FALSE.
1309 If Input is NULL, then return FALSE.
1310 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1311 If Ivec is NULL, then return FALSE.
1312 If Output is NULL, then return FALSE.
1313 If this interface is not supported, then return FALSE.
1315 @param[in] AesContext Pointer to the AES context.
1316 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1317 @param[in] InputSize Size of the Input buffer in bytes.
1318 @param[in] Ivec Pointer to initialization vector.
1319 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1321 @retval TRUE AES encryption succeeded.
1322 @retval FALSE AES encryption failed.
1323 @retval FALSE This interface is not supported.
1329 IN VOID
*AesContext
,
1330 IN CONST UINT8
*Input
,
1332 IN CONST UINT8
*Ivec
,
1337 Performs AES decryption on a data buffer of the specified size in CBC mode.
1339 This function performs AES decryption on data buffer pointed by Input, of specified
1340 size of InputSize, in CBC mode.
1341 InputSize must be multiple of block size (16 bytes). This function does not perform
1342 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1343 Initialization vector should be one block size (16 bytes).
1344 AesContext should be already correctly initialized by AesInit(). Behavior with
1345 invalid AES context is undefined.
1347 If AesContext is NULL, then return FALSE.
1348 If Input is NULL, then return FALSE.
1349 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1350 If Ivec is NULL, then return FALSE.
1351 If Output is NULL, then return FALSE.
1352 If this interface is not supported, then return FALSE.
1354 @param[in] AesContext Pointer to the AES context.
1355 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1356 @param[in] InputSize Size of the Input buffer in bytes.
1357 @param[in] Ivec Pointer to initialization vector.
1358 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1360 @retval TRUE AES decryption succeeded.
1361 @retval FALSE AES decryption failed.
1362 @retval FALSE This interface is not supported.
1368 IN VOID
*AesContext
,
1369 IN CONST UINT8
*Input
,
1371 IN CONST UINT8
*Ivec
,
1375 // =====================================================================================
1376 // Authenticated Encryption with Associated Data (AEAD) Cryptography Primitive
1377 // =====================================================================================
1380 Performs AEAD AES-GCM authenticated encryption on a data buffer and additional authenticated data (AAD).
1382 IvSize must be 12, otherwise FALSE is returned.
1383 KeySize must be 16, 24 or 32, otherwise FALSE is returned.
1384 TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.
1386 @param[in] Key Pointer to the encryption key.
1387 @param[in] KeySize Size of the encryption key in bytes.
1388 @param[in] Iv Pointer to the IV value.
1389 @param[in] IvSize Size of the IV value in bytes.
1390 @param[in] AData Pointer to the additional authenticated data (AAD).
1391 @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.
1392 @param[in] DataIn Pointer to the input data buffer to be encrypted.
1393 @param[in] DataInSize Size of the input data buffer in bytes.
1394 @param[out] TagOut Pointer to a buffer that receives the authentication tag output.
1395 @param[in] TagSize Size of the authentication tag in bytes.
1396 @param[out] DataOut Pointer to a buffer that receives the encryption output.
1397 @param[out] DataOutSize Size of the output data buffer in bytes.
1399 @retval TRUE AEAD AES-GCM authenticated encryption succeeded.
1400 @retval FALSE AEAD AES-GCM authenticated encryption failed.
1406 IN CONST UINT8
*Key
,
1410 IN CONST UINT8
*AData
,
1412 IN CONST UINT8
*DataIn
,
1413 IN UINTN DataInSize
,
1417 OUT UINTN
*DataOutSize
1421 Performs AEAD AES-GCM authenticated decryption on a data buffer and additional authenticated data (AAD).
1423 IvSize must be 12, otherwise FALSE is returned.
1424 KeySize must be 16, 24 or 32, otherwise FALSE is returned.
1425 TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.
1426 If additional authenticated data verification fails, FALSE is returned.
1428 @param[in] Key Pointer to the encryption key.
1429 @param[in] KeySize Size of the encryption key in bytes.
1430 @param[in] Iv Pointer to the IV value.
1431 @param[in] IvSize Size of the IV value in bytes.
1432 @param[in] AData Pointer to the additional authenticated data (AAD).
1433 @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.
1434 @param[in] DataIn Pointer to the input data buffer to be decrypted.
1435 @param[in] DataInSize Size of the input data buffer in bytes.
1436 @param[in] Tag Pointer to a buffer that contains the authentication tag.
1437 @param[in] TagSize Size of the authentication tag in bytes.
1438 @param[out] DataOut Pointer to a buffer that receives the decryption output.
1439 @param[out] DataOutSize Size of the output data buffer in bytes.
1441 @retval TRUE AEAD AES-GCM authenticated decryption succeeded.
1442 @retval FALSE AEAD AES-GCM authenticated decryption failed.
1448 IN CONST UINT8
*Key
,
1452 IN CONST UINT8
*AData
,
1454 IN CONST UINT8
*DataIn
,
1455 IN UINTN DataInSize
,
1456 IN CONST UINT8
*Tag
,
1459 OUT UINTN
*DataOutSize
1462 // =====================================================================================
1463 // Asymmetric Cryptography Primitive
1464 // =====================================================================================
1467 Allocates and initializes one RSA context for subsequent use.
1469 @return Pointer to the RSA context that has been initialized.
1470 If the allocations fails, RsaNew() returns NULL.
1480 Release the specified RSA context.
1482 If RsaContext is NULL, then return FALSE.
1484 @param[in] RsaContext Pointer to the RSA context to be released.
1494 Sets the tag-designated key component into the established RSA context.
1496 This function sets the tag-designated RSA key component into the established
1497 RSA context from the user-specified non-negative integer (octet string format
1498 represented in RSA PKCS#1).
1499 If BigNumber is NULL, then the specified key component in RSA context is cleared.
1501 If RsaContext is NULL, then return FALSE.
1503 @param[in, out] RsaContext Pointer to RSA context being set.
1504 @param[in] KeyTag Tag of RSA key component being set.
1505 @param[in] BigNumber Pointer to octet integer buffer.
1506 If NULL, then the specified key component in RSA
1508 @param[in] BnSize Size of big number buffer in bytes.
1509 If BigNumber is NULL, then it is ignored.
1511 @retval TRUE RSA key component was set successfully.
1512 @retval FALSE Invalid RSA key component tag.
1518 IN OUT VOID
*RsaContext
,
1519 IN RSA_KEY_TAG KeyTag
,
1520 IN CONST UINT8
*BigNumber
,
1525 Gets the tag-designated RSA key component from the established RSA context.
1527 This function retrieves the tag-designated RSA key component from the
1528 established RSA context as a non-negative integer (octet string format
1529 represented in RSA PKCS#1).
1530 If specified key component has not been set or has been cleared, then returned
1532 If the BigNumber buffer is too small to hold the contents of the key, FALSE
1533 is returned and BnSize is set to the required buffer size to obtain the key.
1535 If RsaContext is NULL, then return FALSE.
1536 If BnSize is NULL, then return FALSE.
1537 If BnSize is large enough but BigNumber is NULL, then return FALSE.
1538 If this interface is not supported, then return FALSE.
1540 @param[in, out] RsaContext Pointer to RSA context being set.
1541 @param[in] KeyTag Tag of RSA key component being set.
1542 @param[out] BigNumber Pointer to octet integer buffer.
1543 @param[in, out] BnSize On input, the size of big number buffer in bytes.
1544 On output, the size of data returned in big number buffer in bytes.
1546 @retval TRUE RSA key component was retrieved successfully.
1547 @retval FALSE Invalid RSA key component tag.
1548 @retval FALSE BnSize is too small.
1549 @retval FALSE This interface is not supported.
1555 IN OUT VOID
*RsaContext
,
1556 IN RSA_KEY_TAG KeyTag
,
1557 OUT UINT8
*BigNumber
,
1558 IN OUT UINTN
*BnSize
1562 Generates RSA key components.
1564 This function generates RSA key components. It takes RSA public exponent E and
1565 length in bits of RSA modulus N as input, and generates all key components.
1566 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
1568 Before this function can be invoked, pseudorandom number generator must be correctly
1569 initialized by RandomSeed().
1571 If RsaContext is NULL, then return FALSE.
1572 If this interface is not supported, then return FALSE.
1574 @param[in, out] RsaContext Pointer to RSA context being set.
1575 @param[in] ModulusLength Length of RSA modulus N in bits.
1576 @param[in] PublicExponent Pointer to RSA public exponent.
1577 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
1579 @retval TRUE RSA key component was generated successfully.
1580 @retval FALSE Invalid RSA key component tag.
1581 @retval FALSE This interface is not supported.
1587 IN OUT VOID
*RsaContext
,
1588 IN UINTN ModulusLength
,
1589 IN CONST UINT8
*PublicExponent
,
1590 IN UINTN PublicExponentSize
1594 Validates key components of RSA context.
1595 NOTE: This function performs integrity checks on all the RSA key material, so
1596 the RSA key structure must contain all the private key data.
1598 This function validates key components of RSA context in following aspects:
1599 - Whether p is a prime
1600 - Whether q is a prime
1602 - Whether d*e = 1 mod lcm(p-1,q-1)
1604 If RsaContext is NULL, then return FALSE.
1605 If this interface is not supported, then return FALSE.
1607 @param[in] RsaContext Pointer to RSA context to check.
1609 @retval TRUE RSA key components are valid.
1610 @retval FALSE RSA key components are not valid.
1611 @retval FALSE This interface is not supported.
1621 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
1623 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
1625 If the Signature buffer is too small to hold the contents of signature, FALSE
1626 is returned and SigSize is set to the required buffer size to obtain the signature.
1628 If RsaContext is NULL, then return FALSE.
1629 If MessageHash is NULL, then return FALSE.
1630 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
1631 If SigSize is large enough but Signature is NULL, then return FALSE.
1632 If this interface is not supported, then return FALSE.
1634 @param[in] RsaContext Pointer to RSA context for signature generation.
1635 @param[in] MessageHash Pointer to octet message hash to be signed.
1636 @param[in] HashSize Size of the message hash in bytes.
1637 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
1638 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1639 On output, the size of data returned in Signature buffer in bytes.
1641 @retval TRUE Signature successfully generated in PKCS1-v1_5.
1642 @retval FALSE Signature generation failed.
1643 @retval FALSE SigSize is too small.
1644 @retval FALSE This interface is not supported.
1650 IN VOID
*RsaContext
,
1651 IN CONST UINT8
*MessageHash
,
1653 OUT UINT8
*Signature
,
1654 IN OUT UINTN
*SigSize
1658 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
1661 If RsaContext is NULL, then return FALSE.
1662 If MessageHash is NULL, then return FALSE.
1663 If Signature is NULL, then return FALSE.
1664 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
1666 @param[in] RsaContext Pointer to RSA context for signature verification.
1667 @param[in] MessageHash Pointer to octet message hash to be checked.
1668 @param[in] HashSize Size of the message hash in bytes.
1669 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
1670 @param[in] SigSize Size of signature in bytes.
1672 @retval TRUE Valid signature encoded in PKCS1-v1_5.
1673 @retval FALSE Invalid signature or invalid RSA context.
1679 IN VOID
*RsaContext
,
1680 IN CONST UINT8
*MessageHash
,
1682 IN CONST UINT8
*Signature
,
1687 Carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme.
1689 This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in
1691 Mask generation function is the same as the message digest algorithm.
1692 If the Signature buffer is too small to hold the contents of signature, FALSE
1693 is returned and SigSize is set to the required buffer size to obtain the signature.
1695 If RsaContext is NULL, then return FALSE.
1696 If Message is NULL, then return FALSE.
1697 If MsgSize is zero or > INT_MAX, then return FALSE.
1698 If DigestLen is NOT 32, 48 or 64, return FALSE.
1699 If SaltLen is not equal to DigestLen, then return FALSE.
1700 If SigSize is large enough but Signature is NULL, then return FALSE.
1701 If this interface is not supported, then return FALSE.
1703 @param[in] RsaContext Pointer to RSA context for signature generation.
1704 @param[in] Message Pointer to octet message to be signed.
1705 @param[in] MsgSize Size of the message in bytes.
1706 @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.
1707 @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.
1708 @param[out] Signature Pointer to buffer to receive RSA PSS signature.
1709 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1710 On output, the size of data returned in Signature buffer in bytes.
1712 @retval TRUE Signature successfully generated in RSASSA-PSS.
1713 @retval FALSE Signature generation failed.
1714 @retval FALSE SigSize is too small.
1715 @retval FALSE This interface is not supported.
1721 IN VOID
*RsaContext
,
1722 IN CONST UINT8
*Message
,
1724 IN UINT16 DigestLen
,
1726 OUT UINT8
*Signature
,
1727 IN OUT UINTN
*SigSize
1731 Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
1732 Implementation determines salt length automatically from the signature encoding.
1733 Mask generation function is the same as the message digest algorithm.
1734 Salt length should be equal to digest length.
1736 @param[in] RsaContext Pointer to RSA context for signature verification.
1737 @param[in] Message Pointer to octet message to be verified.
1738 @param[in] MsgSize Size of the message in bytes.
1739 @param[in] Signature Pointer to RSASSA-PSS signature to be verified.
1740 @param[in] SigSize Size of signature in bytes.
1741 @param[in] DigestLen Length of digest for RSA operation.
1742 @param[in] SaltLen Salt length for PSS encoding.
1744 @retval TRUE Valid signature encoded in RSASSA-PSS.
1745 @retval FALSE Invalid signature or invalid RSA context.
1751 IN VOID
*RsaContext
,
1752 IN CONST UINT8
*Message
,
1754 IN CONST UINT8
*Signature
,
1756 IN UINT16 DigestLen
,
1761 Retrieve the RSA Private Key from the password-protected PEM key data.
1763 If PemData is NULL, then return FALSE.
1764 If RsaContext is NULL, then return FALSE.
1765 If this interface is not supported, then return FALSE.
1767 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
1768 @param[in] PemSize Size of the PEM key data in bytes.
1769 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
1770 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1771 RSA private key component. Use RsaFree() function to free the
1774 @retval TRUE RSA Private Key was retrieved successfully.
1775 @retval FALSE Invalid PEM key data or incorrect password.
1776 @retval FALSE This interface is not supported.
1781 RsaGetPrivateKeyFromPem (
1782 IN CONST UINT8
*PemData
,
1784 IN CONST CHAR8
*Password
,
1785 OUT VOID
**RsaContext
1789 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
1791 If Cert is NULL, then return FALSE.
1792 If RsaContext is NULL, then return FALSE.
1793 If this interface is not supported, then return FALSE.
1795 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1796 @param[in] CertSize Size of the X509 certificate in bytes.
1797 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1798 RSA public key component. Use RsaFree() function to free the
1801 @retval TRUE RSA Public Key was retrieved successfully.
1802 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
1803 @retval FALSE This interface is not supported.
1808 RsaGetPublicKeyFromX509 (
1809 IN CONST UINT8
*Cert
,
1811 OUT VOID
**RsaContext
1815 Retrieve the subject bytes from one X.509 certificate.
1817 If Cert is NULL, then return FALSE.
1818 If SubjectSize is NULL, then return FALSE.
1819 If this interface is not supported, then return FALSE.
1821 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1822 @param[in] CertSize Size of the X509 certificate in bytes.
1823 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
1824 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
1825 and the size of buffer returned CertSubject on output.
1827 @retval TRUE The certificate subject retrieved successfully.
1828 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
1829 The SubjectSize will be updated with the required size.
1830 @retval FALSE This interface is not supported.
1835 X509GetSubjectName (
1836 IN CONST UINT8
*Cert
,
1838 OUT UINT8
*CertSubject
,
1839 IN OUT UINTN
*SubjectSize
1843 Retrieve the common name (CN) string from one X.509 certificate.
1845 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1846 @param[in] CertSize Size of the X509 certificate in bytes.
1847 @param[out] CommonName Buffer to contain the retrieved certificate common
1848 name string (UTF8). At most CommonNameSize bytes will be
1849 written and the string will be null terminated. May be
1850 NULL in order to determine the size buffer needed.
1851 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
1852 and the size of buffer returned CommonName on output.
1853 If CommonName is NULL then the amount of space needed
1854 in buffer (including the final null) is returned.
1856 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
1857 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
1858 If CommonNameSize is NULL.
1859 If CommonName is not NULL and *CommonNameSize is 0.
1860 If Certificate is invalid.
1861 @retval RETURN_NOT_FOUND If no CommonName entry exists.
1862 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
1863 (including the final null) is returned in the
1864 CommonNameSize parameter.
1865 @retval RETURN_UNSUPPORTED The operation is not supported.
1871 IN CONST UINT8
*Cert
,
1873 OUT CHAR8
*CommonName OPTIONAL
,
1874 IN OUT UINTN
*CommonNameSize
1878 Retrieve the organization name (O) string from one X.509 certificate.
1880 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1881 @param[in] CertSize Size of the X509 certificate in bytes.
1882 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
1883 name string. At most NameBufferSize bytes will be
1884 written and the string will be null terminated. May be
1885 NULL in order to determine the size buffer needed.
1886 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
1887 and the size of buffer returned Name on output.
1888 If NameBuffer is NULL then the amount of space needed
1889 in buffer (including the final null) is returned.
1891 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
1892 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
1893 If NameBufferSize is NULL.
1894 If NameBuffer is not NULL and *CommonNameSize is 0.
1895 If Certificate is invalid.
1896 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
1897 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
1898 (including the final null) is returned in the
1899 CommonNameSize parameter.
1900 @retval RETURN_UNSUPPORTED The operation is not supported.
1905 X509GetOrganizationName (
1906 IN CONST UINT8
*Cert
,
1908 OUT CHAR8
*NameBuffer OPTIONAL
,
1909 IN OUT UINTN
*NameBufferSize
1913 Verify one X509 certificate was issued by the trusted CA.
1915 If Cert is NULL, then return FALSE.
1916 If CACert is NULL, then return FALSE.
1917 If this interface is not supported, then return FALSE.
1919 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
1920 @param[in] CertSize Size of the X509 certificate in bytes.
1921 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
1922 @param[in] CACertSize Size of the CA Certificate in bytes.
1924 @retval TRUE The certificate was issued by the trusted CA.
1925 @retval FALSE Invalid certificate or the certificate was not issued by the given
1927 @retval FALSE This interface is not supported.
1933 IN CONST UINT8
*Cert
,
1935 IN CONST UINT8
*CACert
,
1940 Construct a X509 object from DER-encoded certificate data.
1942 If Cert is NULL, then return FALSE.
1943 If SingleX509Cert is NULL, then return FALSE.
1944 If this interface is not supported, then return FALSE.
1946 @param[in] Cert Pointer to the DER-encoded certificate data.
1947 @param[in] CertSize The size of certificate data in bytes.
1948 @param[out] SingleX509Cert The generated X509 object.
1950 @retval TRUE The X509 object generation succeeded.
1951 @retval FALSE The operation failed.
1952 @retval FALSE This interface is not supported.
1957 X509ConstructCertificate (
1958 IN CONST UINT8
*Cert
,
1960 OUT UINT8
**SingleX509Cert
1964 Construct a X509 stack object from a list of DER-encoded certificate data.
1966 If X509Stack is NULL, then return FALSE.
1967 If this interface is not supported, then return FALSE.
1969 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
1970 On output, pointer to the X509 stack object with new
1971 inserted X509 certificate.
1972 @param[in] Args VA_LIST marker for the variable argument list.
1973 A list of DER-encoded single certificate data followed
1974 by certificate size. A NULL terminates the list. The
1975 pairs are the arguments to X509ConstructCertificate().
1977 @retval TRUE The X509 stack construction succeeded.
1978 @retval FALSE The construction operation failed.
1979 @retval FALSE This interface is not supported.
1984 X509ConstructCertificateStackV (
1985 IN OUT UINT8
**X509Stack
,
1990 Construct a X509 stack object from a list of DER-encoded certificate data.
1992 If X509Stack is NULL, then return FALSE.
1993 If this interface is not supported, then return FALSE.
1995 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
1996 On output, pointer to the X509 stack object with new
1997 inserted X509 certificate.
1998 @param ... A list of DER-encoded single certificate data followed
1999 by certificate size. A NULL terminates the list. The
2000 pairs are the arguments to X509ConstructCertificate().
2002 @retval TRUE The X509 stack construction succeeded.
2003 @retval FALSE The construction operation failed.
2004 @retval FALSE This interface is not supported.
2009 X509ConstructCertificateStack (
2010 IN OUT UINT8
**X509Stack
,
2015 Release the specified X509 object.
2017 If the interface is not supported, then ASSERT().
2019 @param[in] X509Cert Pointer to the X509 object to be released.
2029 Release the specified X509 stack object.
2031 If the interface is not supported, then ASSERT().
2033 @param[in] X509Stack Pointer to the X509 stack object to be released.
2043 Retrieve the TBSCertificate from one given X.509 certificate.
2045 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
2046 @param[in] CertSize Size of the X509 certificate in bytes.
2047 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
2048 @param[out] TBSCertSize Size of the TBS certificate in bytes.
2050 If Cert is NULL, then return FALSE.
2051 If TBSCert is NULL, then return FALSE.
2052 If TBSCertSize is NULL, then return FALSE.
2053 If this interface is not supported, then return FALSE.
2055 @retval TRUE The TBSCertificate was retrieved successfully.
2056 @retval FALSE Invalid X.509 certificate.
2062 IN CONST UINT8
*Cert
,
2064 OUT UINT8
**TBSCert
,
2065 OUT UINTN
*TBSCertSize
2069 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2070 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2072 If Password or Salt or OutKey is NULL, then return FALSE.
2073 If the hash algorithm could not be determined, then return FALSE.
2074 If this interface is not supported, then return FALSE.
2076 @param[in] PasswordLength Length of input password in bytes.
2077 @param[in] Password Pointer to the array for the password.
2078 @param[in] SaltLength Size of the Salt in bytes.
2079 @param[in] Salt Pointer to the Salt.
2080 @param[in] IterationCount Number of iterations to perform. Its value should be
2081 greater than or equal to 1.
2082 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2083 NOTE: DigestSize will be used to determine the hash algorithm.
2084 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2085 @param[in] KeyLength Size of the derived key buffer in bytes.
2086 @param[out] OutKey Pointer to the output derived key buffer.
2088 @retval TRUE A key was derived successfully.
2089 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2090 @retval FALSE The hash algorithm could not be determined from the digest size.
2091 @retval FALSE The key derivation operation failed.
2092 @retval FALSE This interface is not supported.
2098 IN UINTN PasswordLength
,
2099 IN CONST CHAR8
*Password
,
2100 IN UINTN SaltLength
,
2101 IN CONST UINT8
*Salt
,
2102 IN UINTN IterationCount
,
2103 IN UINTN DigestSize
,
2109 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2110 encrypted message in a newly allocated buffer.
2112 Things that can cause a failure include:
2113 - X509 key size does not match any known key size.
2114 - Fail to parse X509 certificate.
2115 - Fail to allocate an intermediate buffer.
2116 - Null pointer provided for a non-optional parameter.
2117 - Data size is too large for the provided key size (max size is a function of key size
2118 and hash digest size).
2120 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2121 will be used to encrypt the data.
2122 @param[in] PublicKeySize Size of the X509 cert buffer.
2123 @param[in] InData Data to be encrypted.
2124 @param[in] InDataSize Size of the data buffer.
2125 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2126 to be used when initializing the PRNG. NULL otherwise.
2127 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2129 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2131 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2133 @retval TRUE Encryption was successful.
2134 @retval FALSE Encryption failed.
2140 IN CONST UINT8
*PublicKey
,
2141 IN UINTN PublicKeySize
,
2143 IN UINTN InDataSize
,
2144 IN CONST UINT8
*PrngSeed OPTIONAL
,
2145 IN UINTN PrngSeedSize OPTIONAL
,
2146 OUT UINT8
**EncryptedData
,
2147 OUT UINTN
*EncryptedDataSize
2151 The 3rd parameter of Pkcs7GetSigners will return all embedded
2152 X.509 certificate in one given PKCS7 signature. The format is:
2154 // UINT8 CertNumber;
2155 // UINT32 Cert1Length;
2157 // UINT32 Cert2Length;
2160 // UINT32 CertnLength;
2164 The two following C-structure are used for parsing CertStack more clearly.
2169 UINT32 CertDataLength
; // The length in bytes of X.509 certificate.
2170 UINT8 CertDataBuffer
[0]; // The X.509 certificate content (DER).
2174 UINT8 CertNumber
; // Number of X.509 certificate.
2175 // EFI_CERT_DATA CertArray[]; // An array of X.509 certificate.
2181 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2182 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2183 in a ContentInfo structure.
2185 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2186 return FALSE. If P7Length overflow, then return FALSE.
2187 If this interface is not supported, then return FALSE.
2189 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2190 @param[in] P7Length Length of the PKCS#7 message in bytes.
2191 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2192 It's caller's responsibility to free the buffer with
2194 This data structure is EFI_CERT_STACK type.
2195 @param[out] StackLength Length of signer's certificates in bytes.
2196 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2197 It's caller's responsibility to free the buffer with
2199 @param[out] CertLength Length of the trusted certificate in bytes.
2201 @retval TRUE The operation is finished successfully.
2202 @retval FALSE Error occurs during the operation.
2203 @retval FALSE This interface is not supported.
2209 IN CONST UINT8
*P7Data
,
2211 OUT UINT8
**CertStack
,
2212 OUT UINTN
*StackLength
,
2213 OUT UINT8
**TrustedCert
,
2214 OUT UINTN
*CertLength
2218 Wrap function to use free() to free allocated memory for certificates.
2220 If this interface is not supported, then ASSERT().
2222 @param[in] Certs Pointer to the certificates to be freed.
2232 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2233 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2234 unchained to the signer's certificates.
2235 The input signed data could be wrapped in a ContentInfo structure.
2237 @param[in] P7Data Pointer to the PKCS#7 message.
2238 @param[in] P7Length Length of the PKCS#7 message in bytes.
2239 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2240 certificate. It's caller's responsibility to free the buffer
2241 with Pkcs7FreeSigners().
2242 This data structure is EFI_CERT_STACK type.
2243 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2244 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2245 responsibility to free the buffer with Pkcs7FreeSigners().
2246 This data structure is EFI_CERT_STACK type.
2247 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2249 @retval TRUE The operation is finished successfully.
2250 @retval FALSE Error occurs during the operation.
2255 Pkcs7GetCertificatesList (
2256 IN CONST UINT8
*P7Data
,
2258 OUT UINT8
**SignerChainCerts
,
2259 OUT UINTN
*ChainLength
,
2260 OUT UINT8
**UnchainCerts
,
2261 OUT UINTN
*UnchainLength
2265 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2266 Syntax Standard, version 1.5". This interface is only intended to be used for
2267 application to perform PKCS#7 functionality validation.
2269 If this interface is not supported, then return FALSE.
2271 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2273 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2274 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2276 @param[in] InData Pointer to the content to be signed.
2277 @param[in] InDataSize Size of InData in bytes.
2278 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2279 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2280 include in the PKCS#7 signedData (e.g. any intermediate
2282 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2283 responsibility to free the buffer with FreePool().
2284 @param[out] SignedDataSize Size of SignedData in bytes.
2286 @retval TRUE PKCS#7 data signing succeeded.
2287 @retval FALSE PKCS#7 data signing failed.
2288 @retval FALSE This interface is not supported.
2294 IN CONST UINT8
*PrivateKey
,
2295 IN UINTN PrivateKeySize
,
2296 IN CONST UINT8
*KeyPassword
,
2298 IN UINTN InDataSize
,
2300 IN UINT8
*OtherCerts OPTIONAL
,
2301 OUT UINT8
**SignedData
,
2302 OUT UINTN
*SignedDataSize
2306 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2307 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2308 in a ContentInfo structure.
2310 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2311 If P7Length, CertLength or DataLength overflow, then return FALSE.
2312 If this interface is not supported, then return FALSE.
2314 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2315 @param[in] P7Length Length of the PKCS#7 message in bytes.
2316 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2317 is used for certificate chain verification.
2318 @param[in] CertLength Length of the trusted certificate in bytes.
2319 @param[in] InData Pointer to the content to be verified.
2320 @param[in] DataLength Length of InData in bytes.
2322 @retval TRUE The specified PKCS#7 signed data is valid.
2323 @retval FALSE Invalid PKCS#7 signed data.
2324 @retval FALSE This interface is not supported.
2330 IN CONST UINT8
*P7Data
,
2332 IN CONST UINT8
*TrustedCert
,
2333 IN UINTN CertLength
,
2334 IN CONST UINT8
*InData
,
2339 This function receives a PKCS7 formatted signature, and then verifies that
2340 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
2341 leaf signing certificate.
2342 Note that this function does not validate the certificate chain.
2344 Applications for custom EKU's are quite flexible. For example, a policy EKU
2345 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
2346 certificate issued might also contain this EKU, thus constraining the
2347 sub-ordinate certificate. Other applications might allow a certificate
2348 embedded in a device to specify that other Object Identifiers (OIDs) are
2349 present which contains binary data specifying custom capabilities that
2350 the device is able to do.
2352 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
2353 containing the content block with both the signature,
2354 the signer's certificate, and any necessary intermediate
2356 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
2357 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
2358 required EKUs that must be present in the signature.
2359 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
2360 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
2361 must be present in the leaf signer. If it is
2362 FALSE, then we will succeed if we find any
2363 of the specified EKU's.
2365 @retval EFI_SUCCESS The required EKUs were found in the signature.
2366 @retval EFI_INVALID_PARAMETER A parameter was invalid.
2367 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
2372 VerifyEKUsInPkcs7Signature (
2373 IN CONST UINT8
*Pkcs7Signature
,
2374 IN CONST UINT32 SignatureSize
,
2375 IN CONST CHAR8
*RequiredEKUs
[],
2376 IN CONST UINT32 RequiredEKUsSize
,
2377 IN BOOLEAN RequireAllPresent
2381 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2382 data could be wrapped in a ContentInfo structure.
2384 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2385 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2387 Caution: This function may receive untrusted input. So this function will do
2388 basic check for PKCS#7 data structure.
2390 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2391 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2392 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2393 It's caller's responsibility to free the buffer with FreePool().
2394 @param[out] ContentSize The size of the extracted content in bytes.
2396 @retval TRUE The P7Data was correctly formatted for processing.
2397 @retval FALSE The P7Data was not correctly formatted for processing.
2402 Pkcs7GetAttachedContent (
2403 IN CONST UINT8
*P7Data
,
2406 OUT UINTN
*ContentSize
2410 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2411 Authenticode Portable Executable Signature Format".
2413 If AuthData is NULL, then return FALSE.
2414 If ImageHash is NULL, then return FALSE.
2415 If this interface is not supported, then return FALSE.
2417 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2418 PE/COFF image to be verified.
2419 @param[in] DataSize Size of the Authenticode Signature in bytes.
2420 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2421 is used for certificate chain verification.
2422 @param[in] CertSize Size of the trusted certificate in bytes.
2423 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2424 for calculating the image hash value is described in Authenticode
2426 @param[in] HashSize Size of Image hash value in bytes.
2428 @retval TRUE The specified Authenticode Signature is valid.
2429 @retval FALSE Invalid Authenticode Signature.
2430 @retval FALSE This interface is not supported.
2435 AuthenticodeVerify (
2436 IN CONST UINT8
*AuthData
,
2438 IN CONST UINT8
*TrustedCert
,
2440 IN CONST UINT8
*ImageHash
,
2445 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2448 If AuthData is NULL, then return FALSE.
2449 If this interface is not supported, then return FALSE.
2451 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2452 PE/COFF image to be verified.
2453 @param[in] DataSize Size of the Authenticode Signature in bytes.
2454 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2455 is used for TSA certificate chain verification.
2456 @param[in] CertSize Size of the trusted certificate in bytes.
2457 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2460 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2461 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2466 ImageTimestampVerify (
2467 IN CONST UINT8
*AuthData
,
2469 IN CONST UINT8
*TsaCert
,
2471 OUT EFI_TIME
*SigningTime
2474 // =====================================================================================
2475 // DH Key Exchange Primitive
2476 // =====================================================================================
2479 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
2481 @return Pointer to the Diffie-Hellman Context that has been initialized.
2482 If the allocations fails, DhNew() returns NULL.
2483 If the interface is not supported, DhNew() returns NULL.
2493 Release the specified DH context.
2495 If the interface is not supported, then ASSERT().
2497 @param[in] DhContext Pointer to the DH context to be released.
2507 Generates DH parameter.
2509 Given generator g, and length of prime number p in bits, this function generates p,
2510 and sets DH context according to value of g and p.
2512 Before this function can be invoked, pseudorandom number generator must be correctly
2513 initialized by RandomSeed().
2515 If DhContext is NULL, then return FALSE.
2516 If Prime is NULL, then return FALSE.
2517 If this interface is not supported, then return FALSE.
2519 @param[in, out] DhContext Pointer to the DH context.
2520 @param[in] Generator Value of generator.
2521 @param[in] PrimeLength Length in bits of prime to be generated.
2522 @param[out] Prime Pointer to the buffer to receive the generated prime number.
2524 @retval TRUE DH parameter generation succeeded.
2525 @retval FALSE Value of Generator is not supported.
2526 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
2527 @retval FALSE This interface is not supported.
2532 DhGenerateParameter (
2533 IN OUT VOID
*DhContext
,
2535 IN UINTN PrimeLength
,
2540 Sets generator and prime parameters for DH.
2542 Given generator g, and prime number p, this function and sets DH
2543 context accordingly.
2545 If DhContext is NULL, then return FALSE.
2546 If Prime is NULL, then return FALSE.
2547 If this interface is not supported, then return FALSE.
2549 @param[in, out] DhContext Pointer to the DH context.
2550 @param[in] Generator Value of generator.
2551 @param[in] PrimeLength Length in bits of prime to be generated.
2552 @param[in] Prime Pointer to the prime number.
2554 @retval TRUE DH parameter setting succeeded.
2555 @retval FALSE Value of Generator is not supported.
2556 @retval FALSE Value of Generator is not suitable for the Prime.
2557 @retval FALSE Value of Prime is not a prime number.
2558 @retval FALSE Value of Prime is not a safe prime number.
2559 @retval FALSE This interface is not supported.
2565 IN OUT VOID
*DhContext
,
2567 IN UINTN PrimeLength
,
2568 IN CONST UINT8
*Prime
2572 Generates DH public key.
2574 This function generates random secret exponent, and computes the public key, which is
2575 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
2576 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
2577 PublicKeySize is set to the required buffer size to obtain the public key.
2579 If DhContext is NULL, then return FALSE.
2580 If PublicKeySize is NULL, then return FALSE.
2581 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
2582 If this interface is not supported, then return FALSE.
2584 @param[in, out] DhContext Pointer to the DH context.
2585 @param[out] PublicKey Pointer to the buffer to receive generated public key.
2586 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
2587 On output, the size of data returned in PublicKey buffer in bytes.
2589 @retval TRUE DH public key generation succeeded.
2590 @retval FALSE DH public key generation failed.
2591 @retval FALSE PublicKeySize is not large enough.
2592 @retval FALSE This interface is not supported.
2598 IN OUT VOID
*DhContext
,
2599 OUT UINT8
*PublicKey
,
2600 IN OUT UINTN
*PublicKeySize
2604 Computes exchanged common key.
2606 Given peer's public key, this function computes the exchanged common key, based on its own
2607 context including value of prime modulus and random secret exponent.
2609 If DhContext is NULL, then return FALSE.
2610 If PeerPublicKey is NULL, then return FALSE.
2611 If KeySize is NULL, then return FALSE.
2612 If Key is NULL, then return FALSE.
2613 If KeySize is not large enough, then return FALSE.
2614 If this interface is not supported, then return FALSE.
2616 @param[in, out] DhContext Pointer to the DH context.
2617 @param[in] PeerPublicKey Pointer to the peer's public key.
2618 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
2619 @param[out] Key Pointer to the buffer to receive generated key.
2620 @param[in, out] KeySize On input, the size of Key buffer in bytes.
2621 On output, the size of data returned in Key buffer in bytes.
2623 @retval TRUE DH exchanged key generation succeeded.
2624 @retval FALSE DH exchanged key generation failed.
2625 @retval FALSE KeySize is not large enough.
2626 @retval FALSE This interface is not supported.
2632 IN OUT VOID
*DhContext
,
2633 IN CONST UINT8
*PeerPublicKey
,
2634 IN UINTN PeerPublicKeySize
,
2636 IN OUT UINTN
*KeySize
2639 // =====================================================================================
2640 // Pseudo-Random Generation Primitive
2641 // =====================================================================================
2644 Sets up the seed value for the pseudorandom number generator.
2646 This function sets up the seed value for the pseudorandom number generator.
2647 If Seed is not NULL, then the seed passed in is used.
2648 If Seed is NULL, then default seed is used.
2649 If this interface is not supported, then return FALSE.
2651 @param[in] Seed Pointer to seed value.
2652 If NULL, default seed is used.
2653 @param[in] SeedSize Size of seed value.
2654 If Seed is NULL, this parameter is ignored.
2656 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
2657 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
2658 @retval FALSE This interface is not supported.
2664 IN CONST UINT8
*Seed OPTIONAL
,
2669 Generates a pseudorandom byte stream of the specified size.
2671 If Output is NULL, then return FALSE.
2672 If this interface is not supported, then return FALSE.
2674 @param[out] Output Pointer to buffer to receive random value.
2675 @param[in] Size Size of random bytes to generate.
2677 @retval TRUE Pseudorandom byte stream generated successfully.
2678 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
2679 @retval FALSE This interface is not supported.
2689 // =====================================================================================
2690 // Key Derivation Function Primitive
2691 // =====================================================================================
2694 Derive key data using HMAC-SHA256 based KDF.
2696 @param[in] Key Pointer to the user-supplied key.
2697 @param[in] KeySize Key size in bytes.
2698 @param[in] Salt Pointer to the salt(non-secret) value.
2699 @param[in] SaltSize Salt size in bytes.
2700 @param[in] Info Pointer to the application specific info.
2701 @param[in] InfoSize Info size in bytes.
2702 @param[out] Out Pointer to buffer to receive hkdf value.
2703 @param[in] OutSize Size of hkdf bytes to generate.
2705 @retval TRUE Hkdf generated successfully.
2706 @retval FALSE Hkdf generation failed.
2711 HkdfSha256ExtractAndExpand (
2712 IN CONST UINT8
*Key
,
2714 IN CONST UINT8
*Salt
,
2716 IN CONST UINT8
*Info
,
2723 Derive SHA256 HMAC-based Extract key Derivation Function (HKDF).
2725 @param[in] Key Pointer to the user-supplied key.
2726 @param[in] KeySize key size in bytes.
2727 @param[in] Salt Pointer to the salt(non-secret) value.
2728 @param[in] SaltSize salt size in bytes.
2729 @param[out] PrkOut Pointer to buffer to receive hkdf value.
2730 @param[in] PrkOutSize size of hkdf bytes to generate.
2732 @retval true Hkdf generated successfully.
2733 @retval false Hkdf generation failed.
2739 IN CONST UINT8
*Key
,
2741 IN CONST UINT8
*Salt
,
2748 Derive SHA256 HMAC-based Expand Key Derivation Function (HKDF).
2750 @param[in] Prk Pointer to the user-supplied key.
2751 @param[in] PrkSize Key size in bytes.
2752 @param[in] Info Pointer to the application specific info.
2753 @param[in] InfoSize Info size in bytes.
2754 @param[out] Out Pointer to buffer to receive hkdf value.
2755 @param[in] OutSize Size of hkdf bytes to generate.
2757 @retval TRUE Hkdf generated successfully.
2758 @retval FALSE Hkdf generation failed.
2764 IN CONST UINT8
*Prk
,
2766 IN CONST UINT8
*Info
,
2773 Derive SHA384 HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
2775 @param[in] Key Pointer to the user-supplied key.
2776 @param[in] KeySize Key size in bytes.
2777 @param[in] Salt Pointer to the salt(non-secret) value.
2778 @param[in] SaltSize Salt size in bytes.
2779 @param[in] Info Pointer to the application specific info.
2780 @param[in] InfoSize Info size in bytes.
2781 @param[out] Out Pointer to buffer to receive hkdf value.
2782 @param[in] OutSize Size of hkdf bytes to generate.
2784 @retval TRUE Hkdf generated successfully.
2785 @retval FALSE Hkdf generation failed.
2790 HkdfSha384ExtractAndExpand (
2791 IN CONST UINT8
*Key
,
2793 IN CONST UINT8
*Salt
,
2795 IN CONST UINT8
*Info
,
2802 Derive SHA384 HMAC-based Extract key Derivation Function (HKDF).
2804 @param[in] Key Pointer to the user-supplied key.
2805 @param[in] KeySize key size in bytes.
2806 @param[in] Salt Pointer to the salt(non-secret) value.
2807 @param[in] SaltSize salt size in bytes.
2808 @param[out] PrkOut Pointer to buffer to receive hkdf value.
2809 @param[in] PrkOutSize size of hkdf bytes to generate.
2811 @retval true Hkdf generated successfully.
2812 @retval false Hkdf generation failed.
2818 IN CONST UINT8
*Key
,
2820 IN CONST UINT8
*Salt
,
2827 Derive SHA384 HMAC-based Expand Key Derivation Function (HKDF).
2829 @param[in] Prk Pointer to the user-supplied key.
2830 @param[in] PrkSize Key size in bytes.
2831 @param[in] Info Pointer to the application specific info.
2832 @param[in] InfoSize Info size in bytes.
2833 @param[out] Out Pointer to buffer to receive hkdf value.
2834 @param[in] OutSize Size of hkdf bytes to generate.
2836 @retval TRUE Hkdf generated successfully.
2837 @retval FALSE Hkdf generation failed.
2843 IN CONST UINT8
*Prk
,
2845 IN CONST UINT8
*Info
,
2851 // =====================================================================================
2852 // Big number primitives
2853 // =====================================================================================
2856 Allocate new Big Number.
2858 @retval New BigNum opaque structure or NULL on failure.
2867 Allocate new Big Number and assign the provided value to it.
2869 @param[in] Buf Big endian encoded buffer.
2870 @param[in] Len Buffer length.
2872 @retval New BigNum opaque structure or NULL on failure.
2877 IN CONST UINT8
*Buf
,
2882 Convert the absolute value of Bn into big-endian form and store it at Buf.
2883 The Buf array should have at least BigNumBytes() in it.
2885 @param[in] Bn Big number to convert.
2886 @param[out] Buf Output buffer.
2888 @retval The length of the big-endian number placed at Buf or -1 on error.
2898 Free the Big Number.
2900 @param[in] Bn Big number to free.
2901 @param[in] Clear TRUE if the buffer should be cleared.
2911 Calculate the sum of two Big Numbers.
2912 Please note, all "out" Big number arguments should be properly initialized
2913 by calling to BigNumInit() or BigNumFromBin() functions.
2915 @param[in] BnA Big number.
2916 @param[in] BnB Big number.
2917 @param[out] BnRes The result of BnA + BnB.
2919 @retval TRUE On success.
2920 @retval FALSE Otherwise.
2931 Subtract two Big Numbers.
2932 Please note, all "out" Big number arguments should be properly initialized
2933 by calling to BigNumInit() or BigNumFromBin() functions.
2935 @param[in] BnA Big number.
2936 @param[in] BnB Big number.
2937 @param[out] BnRes The result of BnA - BnB.
2939 @retval TRUE On success.
2940 @retval FALSE Otherwise.
2951 Calculate remainder: BnRes = BnA % BnB.
2952 Please note, all "out" Big number arguments should be properly initialized
2953 by calling to BigNumInit() or BigNumFromBin() functions.
2955 @param[in] BnA Big number.
2956 @param[in] BnB Big number.
2957 @param[out] BnRes The result of BnA % BnB.
2959 @retval TRUE On success.
2960 @retval FALSE Otherwise.
2971 Compute BnA to the BnP-th power modulo BnM.
2972 Please note, all "out" Big number arguments should be properly initialized
2973 by calling to BigNumInit() or BigNumFromBin() functions.
2975 @param[in] BnA Big number.
2976 @param[in] BnP Big number (power).
2977 @param[in] BnM Big number (modulo).
2978 @param[out] BnRes The result of (BnA ^ BnP) % BnM.
2980 @retval TRUE On success.
2981 @retval FALSE Otherwise.
2993 Compute BnA inverse modulo BnM.
2994 Please note, all "out" Big number arguments should be properly initialized
2995 by calling to BigNumInit() or BigNumFromBin() functions.
2997 @param[in] BnA Big number.
2998 @param[in] BnM Big number (modulo).
2999 @param[out] BnRes The result, such that (BnA * BnRes) % BnM == 1.
3001 @retval TRUE On success.
3002 @retval FALSE Otherwise.
3013 Divide two Big Numbers.
3014 Please note, all "out" Big number arguments should be properly initialized
3015 by calling to BigNumInit() or BigNumFromBin() functions.
3017 @param[in] BnA Big number.
3018 @param[in] BnB Big number.
3019 @param[out] BnRes The result, such that BnA / BnB.
3021 @retval TRUE On success.
3022 @retval FALSE Otherwise.
3033 Multiply two Big Numbers modulo BnM.
3034 Please note, all "out" Big number arguments should be properly initialized
3035 by calling to BigNumInit() or BigNumFromBin() functions.
3037 @param[in] BnA Big number.
3038 @param[in] BnB Big number.
3039 @param[in] BnM Big number (modulo).
3040 @param[out] BnRes The result, such that (BnA * BnB) % BnM.
3042 @retval TRUE On success.
3043 @retval FALSE Otherwise.
3055 Compare two Big Numbers.
3057 @param[in] BnA Big number.
3058 @param[in] BnB Big number.
3060 @retval 0 BnA == BnB.
3061 @retval 1 BnA > BnB.
3062 @retval -1 BnA < BnB.
3072 Get number of bits in Bn.
3074 @param[in] Bn Big number.
3076 @retval Number of bits.
3086 Get number of bytes in Bn.
3088 @param[in] Bn Big number.
3090 @retval Number of bytes.
3099 Checks if Big Number equals to the given Num.
3101 @param[in] Bn Big number.
3102 @param[in] Num Number.
3104 @retval TRUE iff Bn == Num.
3105 @retval FALSE otherwise.
3115 Checks if Big Number is odd.
3117 @param[in] Bn Big number.
3119 @retval TRUE Bn is odd (Bn % 2 == 1).
3120 @retval FALSE otherwise.
3131 @param[out] BnDst Destination.
3132 @param[in] BnSrc Source.
3134 @retval BnDst on success.
3135 @retval NULL otherwise.
3141 IN CONST VOID
*BnSrc
3145 Get constant Big number with value of "1".
3146 This may be used to save expensive allocations.
3148 @retval Big Number with value of 1.
3157 Shift right Big Number.
3158 Please note, all "out" Big number arguments should be properly initialized
3159 by calling to BigNumInit() or BigNumFromBin() functions.
3161 @param[in] Bn Big number.
3162 @param[in] N Number of bits to shift.
3163 @param[out] BnRes The result.
3165 @retval TRUE On success.
3166 @retval FALSE Otherwise.
3177 Mark Big Number for constant time computations.
3178 This function should be called before any constant time computations are
3179 performed on the given Big number.
3181 @param[in] Bn Big number.
3190 Calculate square modulo.
3191 Please note, all "out" Big number arguments should be properly initialized
3192 by calling to BigNumInit() or BigNumFromBin() functions.
3194 @param[in] BnA Big number.
3195 @param[in] BnM Big number (modulo).
3196 @param[out] BnRes The result, such that (BnA ^ 2) % BnM.
3198 @retval TRUE On success.
3199 @retval FALSE Otherwise.
3210 Create new Big Number computation context. This is an opaque structure
3211 which should be passed to any function that requires it. The BN context is
3212 needed to optimize calculations and expensive allocations.
3214 @retval Big Number context struct or NULL on failure.
3223 Free Big Number context that was allocated with BigNumNewContext().
3225 @param[in] BnCtx Big number context to free.
3234 Set Big Number to a given value.
3236 @param[in] Bn Big number to set.
3237 @param[in] Val Value to set.
3239 @retval TRUE On success.
3240 @retval FALSE Otherwise.
3250 Add two Big Numbers modulo BnM.
3252 @param[in] BnA Big number.
3253 @param[in] BnB Big number.
3254 @param[in] BnM Big number (modulo).
3255 @param[out] BnRes The result, such that (BnA + BnB) % BnM.
3257 @retval TRUE On success.
3258 @retval FALSE Otherwise.
3269 // =====================================================================================
3270 // Basic Elliptic Curve Primitives
3271 // =====================================================================================
3274 Initialize new opaque EcGroup object. This object represents an EC curve and
3275 and is used for calculation within this group. This object should be freed
3276 using EcGroupFree() function.
3278 @param[in] CryptoNid Identifying number for the ECC curve (Defined in
3281 @retval EcGroup object On success.
3282 @retval NULL On failure.
3291 Get EC curve parameters. While elliptic curve equation is Y^2 mod P = (X^3 + AX + B) Mod P.
3292 This function will set the provided Big Number objects to the corresponding
3293 values. The caller needs to make sure all the "out" BigNumber parameters
3294 are properly initialized.
3296 @param[in] EcGroup EC group object.
3297 @param[out] BnPrime Group prime number.
3298 @param[out] BnA A coefficient.
3299 @param[out] BnB B coefficient.
3300 @param[in] BnCtx BN context.
3302 @retval TRUE On success.
3303 @retval FALSE Otherwise.
3308 IN CONST VOID
*EcGroup
,
3317 This function will set the provided Big Number object to the corresponding
3318 value. The caller needs to make sure that the "out" BigNumber parameter
3319 is properly initialized.
3321 @param[in] EcGroup EC group object.
3322 @param[out] BnOrder Group prime number.
3324 @retval TRUE On success.
3325 @retval FALSE Otherwise.
3335 Free previously allocated EC group object using EcGroupInit().
3337 @param[in] EcGroup EC group object to free.
3346 Initialize new opaque EC Point object. This object represents an EC point
3347 within the given EC group (curve).
3349 @param[in] EC Group, properly initialized using EcGroupInit().
3351 @retval EC Point object On success.
3352 @retval NULL On failure.
3357 IN CONST VOID
*EcGroup
3361 Free previously allocated EC Point object using EcPointInit().
3363 @param[in] EcPoint EC Point to free.
3364 @param[in] Clear TRUE iff the memory should be cleared.
3374 Get EC point affine (x,y) coordinates.
3375 This function will set the provided Big Number objects to the corresponding
3376 values. The caller needs to make sure all the "out" BigNumber parameters
3377 are properly initialized.
3379 @param[in] EcGroup EC group object.
3380 @param[in] EcPoint EC point object.
3381 @param[out] BnX X coordinate.
3382 @param[out] BnY Y coordinate.
3383 @param[in] BnCtx BN context, created with BigNumNewContext().
3385 @retval TRUE On success.
3386 @retval FALSE Otherwise.
3390 EcPointGetAffineCoordinates (
3391 IN CONST VOID
*EcGroup
,
3392 IN CONST VOID
*EcPoint
,
3399 Set EC point affine (x,y) coordinates.
3401 @param[in] EcGroup EC group object.
3402 @param[in] EcPoint EC point object.
3403 @param[in] BnX X coordinate.
3404 @param[in] BnY Y coordinate.
3405 @param[in] BnCtx BN context, created with BigNumNewContext().
3407 @retval TRUE On success.
3408 @retval FALSE Otherwise.
3412 EcPointSetAffineCoordinates (
3413 IN CONST VOID
*EcGroup
,
3421 EC Point addition. EcPointResult = EcPointA + EcPointB.
3423 @param[in] EcGroup EC group object.
3424 @param[out] EcPointResult EC point to hold the result. The point should
3425 be properly initialized.
3426 @param[in] EcPointA EC Point.
3427 @param[in] EcPointB EC Point.
3428 @param[in] BnCtx BN context, created with BigNumNewContext().
3430 @retval TRUE On success.
3431 @retval FALSE Otherwise.
3436 IN CONST VOID
*EcGroup
,
3437 OUT VOID
*EcPointResult
,
3438 IN CONST VOID
*EcPointA
,
3439 IN CONST VOID
*EcPointB
,
3444 Variable EC point multiplication. EcPointResult = EcPoint * BnPScalar.
3446 @param[in] EcGroup EC group object.
3447 @param[out] EcPointResult EC point to hold the result. The point should
3448 be properly initialized.
3449 @param[in] EcPoint EC Point.
3450 @param[in] BnPScalar P Scalar.
3451 @param[in] BnCtx BN context, created with BigNumNewContext().
3453 @retval TRUE On success.
3454 @retval FALSE Otherwise.
3459 IN CONST VOID
*EcGroup
,
3460 OUT VOID
*EcPointResult
,
3461 IN CONST VOID
*EcPoint
,
3462 IN CONST VOID
*BnPScalar
,
3467 Calculate the inverse of the supplied EC point.
3469 @param[in] EcGroup EC group object.
3470 @param[in,out] EcPoint EC point to invert.
3471 @param[in] BnCtx BN context, created with BigNumNewContext().
3473 @retval TRUE On success.
3474 @retval FALSE Otherwise.
3479 IN CONST VOID
*EcGroup
,
3480 IN OUT VOID
*EcPoint
,
3485 Check if the supplied point is on EC curve.
3487 @param[in] EcGroup EC group object.
3488 @param[in] EcPoint EC point to check.
3489 @param[in] BnCtx BN context, created with BigNumNewContext().
3491 @retval TRUE On curve.
3492 @retval FALSE Otherwise.
3497 IN CONST VOID
*EcGroup
,
3498 IN CONST VOID
*EcPoint
,
3503 Check if the supplied point is at infinity.
3505 @param[in] EcGroup EC group object.
3506 @param[in] EcPoint EC point to check.
3508 @retval TRUE At infinity.
3509 @retval FALSE Otherwise.
3513 EcPointIsAtInfinity (
3514 IN CONST VOID
*EcGroup
,
3515 IN CONST VOID
*EcPoint
3519 Check if EC points are equal.
3521 @param[in] EcGroup EC group object.
3522 @param[in] EcPointA EC point A.
3523 @param[in] EcPointB EC point B.
3524 @param[in] BnCtx BN context, created with BigNumNewContext().
3526 @retval TRUE A == B.
3527 @retval FALSE Otherwise.
3532 IN CONST VOID
*EcGroup
,
3533 IN CONST VOID
*EcPointA
,
3534 IN CONST VOID
*EcPointB
,
3539 Set EC point compressed coordinates. Points can be described in terms of
3540 their compressed coordinates. For a point (x, y), for any given value for x
3541 such that the point is on the curve there will only ever be two possible
3542 values for y. Therefore, a point can be set using this function where BnX is
3543 the x coordinate and YBit is a value 0 or 1 to identify which of the two
3544 possible values for y should be used.
3546 @param[in] EcGroup EC group object.
3547 @param[in] EcPoint EC Point.
3548 @param[in] BnX X coordinate.
3549 @param[in] YBit 0 or 1 to identify which Y value is used.
3550 @param[in] BnCtx BN context, created with BigNumNewContext().
3552 @retval TRUE On success.
3553 @retval FALSE Otherwise.
3557 EcPointSetCompressedCoordinates (
3558 IN CONST VOID
*EcGroup
,
3565 // =====================================================================================
3566 // Elliptic Curve Diffie Hellman Primitives
3567 // =====================================================================================
3570 Allocates and Initializes one Elliptic Curve Context for subsequent use
3573 @param[in] Nid cipher NID
3574 @return Pointer to the Elliptic Curve Context that has been initialized.
3575 If the allocations fails, EcNewByNid() returns NULL.
3584 Release the specified EC context.
3586 @param[in] EcContext Pointer to the EC context to be released.
3595 Generates EC key and returns EC public key (X, Y), Please note, this function uses
3596 pseudo random number generator. The caller must make sure RandomSeed()
3597 function was properly called before.
3598 The Ec context should be correctly initialized by EcNewByNid.
3599 This function generates random secret, and computes the public key (X, Y), which is
3600 returned via parameter Public, PublicSize.
3601 X is the first half of Public with size being PublicSize / 2,
3602 Y is the second half of Public with size being PublicSize / 2.
3603 EC context is updated accordingly.
3604 If the Public buffer is too small to hold the public X, Y, FALSE is returned and
3605 PublicSize is set to the required buffer size to obtain the public X, Y.
3606 For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.
3607 For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.
3608 For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.
3609 If EcContext is NULL, then return FALSE.
3610 If PublicSize is NULL, then return FALSE.
3611 If PublicSize is large enough but Public is NULL, then return FALSE.
3612 @param[in, out] EcContext Pointer to the EC context.
3613 @param[out] PublicKey Pointer to t buffer to receive generated public X,Y.
3614 @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.
3615 On output, the size of data returned in Public buffer in bytes.
3616 @retval TRUE EC public X,Y generation succeeded.
3617 @retval FALSE EC public X,Y generation failed.
3618 @retval FALSE PublicKeySize is not large enough.
3623 IN OUT VOID
*EcContext
,
3624 OUT UINT8
*PublicKey
,
3625 IN OUT UINTN
*PublicKeySize
3629 Gets the public key component from the established EC context.
3630 The Ec context should be correctly initialized by EcNewByNid, and successfully
3631 generate key pair from EcGenerateKey().
3632 For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.
3633 For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.
3634 For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.
3635 @param[in, out] EcContext Pointer to EC context being set.
3636 @param[out] PublicKey Pointer to t buffer to receive generated public X,Y.
3637 @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.
3638 On output, the size of data returned in Public buffer in bytes.
3639 @retval TRUE EC key component was retrieved successfully.
3640 @retval FALSE Invalid EC key component.
3645 IN OUT VOID
*EcContext
,
3646 OUT UINT8
*PublicKey
,
3647 IN OUT UINTN
*PublicKeySize
3651 Computes exchanged common key.
3652 Given peer's public key (X, Y), this function computes the exchanged common key,
3653 based on its own context including value of curve parameter and random secret.
3654 X is the first half of PeerPublic with size being PeerPublicSize / 2,
3655 Y is the second half of PeerPublic with size being PeerPublicSize / 2.
3656 If EcContext is NULL, then return FALSE.
3657 If PeerPublic is NULL, then return FALSE.
3658 If PeerPublicSize is 0, then return FALSE.
3659 If Key is NULL, then return FALSE.
3660 If KeySize is not large enough, then return FALSE.
3661 For P-256, the PeerPublicSize is 64. First 32-byte is X, Second 32-byte is Y.
3662 For P-384, the PeerPublicSize is 96. First 48-byte is X, Second 48-byte is Y.
3663 For P-521, the PeerPublicSize is 132. First 66-byte is X, Second 66-byte is Y.
3664 @param[in, out] EcContext Pointer to the EC context.
3665 @param[in] PeerPublic Pointer to the peer's public X,Y.
3666 @param[in] PeerPublicSize Size of peer's public X,Y in bytes.
3667 @param[in] CompressFlag Flag of PeerPublic is compressed or not.
3668 @param[out] Key Pointer to the buffer to receive generated key.
3669 @param[in, out] KeySize On input, the size of Key buffer in bytes.
3670 On output, the size of data returned in Key buffer in bytes.
3671 @retval TRUE EC exchanged key generation succeeded.
3672 @retval FALSE EC exchanged key generation failed.
3673 @retval FALSE KeySize is not large enough.
3678 IN OUT VOID
*EcContext
,
3679 IN CONST UINT8
*PeerPublic
,
3680 IN UINTN PeerPublicSize
,
3681 IN CONST INT32
*CompressFlag
,
3683 IN OUT UINTN
*KeySize
3687 Retrieve the EC Private Key from the password-protected PEM key data.
3689 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
3690 @param[in] PemSize Size of the PEM key data in bytes.
3691 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
3692 @param[out] EcContext Pointer to new-generated EC DSA context which contain the retrieved
3693 EC private key component. Use EcFree() function to free the
3696 If PemData is NULL, then return FALSE.
3697 If EcContext is NULL, then return FALSE.
3699 @retval TRUE EC Private Key was retrieved successfully.
3700 @retval FALSE Invalid PEM key data or incorrect password.
3705 EcGetPrivateKeyFromPem (
3706 IN CONST UINT8
*PemData
,
3708 IN CONST CHAR8
*Password
,
3709 OUT VOID
**EcContext
3713 Retrieve the EC Public Key from one DER-encoded X509 certificate.
3715 @param[in] Cert Pointer to the DER-encoded X509 certificate.
3716 @param[in] CertSize Size of the X509 certificate in bytes.
3717 @param[out] EcContext Pointer to new-generated EC DSA context which contain the retrieved
3718 EC public key component. Use EcFree() function to free the
3721 If Cert is NULL, then return FALSE.
3722 If EcContext is NULL, then return FALSE.
3724 @retval TRUE EC Public Key was retrieved successfully.
3725 @retval FALSE Fail to retrieve EC public key from X509 certificate.
3730 EcGetPublicKeyFromX509 (
3731 IN CONST UINT8
*Cert
,
3733 OUT VOID
**EcContext
3737 Carries out the EC-DSA signature.
3739 This function carries out the EC-DSA signature.
3740 If the Signature buffer is too small to hold the contents of signature, FALSE
3741 is returned and SigSize is set to the required buffer size to obtain the signature.
3743 If EcContext is NULL, then return FALSE.
3744 If MessageHash is NULL, then return FALSE.
3745 If HashSize need match the HashNid. HashNid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
3746 If SigSize is large enough but Signature is NULL, then return FALSE.
3748 For P-256, the SigSize is 64. First 32-byte is R, Second 32-byte is S.
3749 For P-384, the SigSize is 96. First 48-byte is R, Second 48-byte is S.
3750 For P-521, the SigSize is 132. First 66-byte is R, Second 66-byte is S.
3752 @param[in] EcContext Pointer to EC context for signature generation.
3753 @param[in] HashNid hash NID
3754 @param[in] MessageHash Pointer to octet message hash to be signed.
3755 @param[in] HashSize Size of the message hash in bytes.
3756 @param[out] Signature Pointer to buffer to receive EC-DSA signature.
3757 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
3758 On output, the size of data returned in Signature buffer in bytes.
3760 @retval TRUE Signature successfully generated in EC-DSA.
3761 @retval FALSE Signature generation failed.
3762 @retval FALSE SigSize is too small.
3770 IN CONST UINT8
*MessageHash
,
3772 OUT UINT8
*Signature
,
3773 IN OUT UINTN
*SigSize
3777 Verifies the EC-DSA signature.
3779 If EcContext is NULL, then return FALSE.
3780 If MessageHash is NULL, then return FALSE.
3781 If Signature is NULL, then return FALSE.
3782 If HashSize need match the HashNid. HashNid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
3784 For P-256, the SigSize is 64. First 32-byte is R, Second 32-byte is S.
3785 For P-384, the SigSize is 96. First 48-byte is R, Second 48-byte is S.
3786 For P-521, the SigSize is 132. First 66-byte is R, Second 66-byte is S.
3788 @param[in] EcContext Pointer to EC context for signature verification.
3789 @param[in] HashNid hash NID
3790 @param[in] MessageHash Pointer to octet message hash to be checked.
3791 @param[in] HashSize Size of the message hash in bytes.
3792 @param[in] Signature Pointer to EC-DSA signature to be verified.
3793 @param[in] SigSize Size of signature in bytes.
3795 @retval TRUE Valid signature encoded in EC-DSA.
3796 @retval FALSE Invalid signature or invalid EC context.
3804 IN CONST UINT8
*MessageHash
,
3806 IN CONST UINT8
*Signature
,
3810 #endif // __BASE_CRYPT_LIB_H__