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_SECP256R1 0x0204
21 #define CRYPTO_NID_SECP384R1 0x0205
22 #define CRYPTO_NID_SECP521R1 0x0206
25 /// MD5 digest size in bytes
27 #define MD5_DIGEST_SIZE 16
30 /// SHA-1 digest size in bytes.
32 #define SHA1_DIGEST_SIZE 20
35 /// SHA-256 digest size in bytes
37 #define SHA256_DIGEST_SIZE 32
40 /// SHA-384 digest size in bytes
42 #define SHA384_DIGEST_SIZE 48
45 /// SHA-512 digest size in bytes
47 #define SHA512_DIGEST_SIZE 64
50 /// SM3 digest size in bytes
52 #define SM3_256_DIGEST_SIZE 32
55 /// TDES block size in bytes
57 #define TDES_BLOCK_SIZE 8
60 /// AES block size in bytes
62 #define AES_BLOCK_SIZE 16
65 /// RSA Key Tags Definition used in RsaSetKey() function for key component identification.
68 RsaKeyN
, ///< RSA public Modulus (N)
69 RsaKeyE
, ///< RSA Public exponent (e)
70 RsaKeyD
, ///< RSA Private exponent (d)
71 RsaKeyP
, ///< RSA secret prime factor of Modulus (p)
72 RsaKeyQ
, ///< RSA secret prime factor of Modules (q)
73 RsaKeyDp
, ///< p's CRT exponent (== d mod (p - 1))
74 RsaKeyDq
, ///< q's CRT exponent (== d mod (q - 1))
75 RsaKeyQInv
///< The CRT coefficient (== 1/q mod p)
78 // =====================================================================================
79 // One-Way Cryptographic Hash Primitives
80 // =====================================================================================
82 #ifdef ENABLE_MD5_DEPRECATED_INTERFACES
85 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.
87 If this interface is not supported, then return zero.
89 @return The size, in bytes, of the context buffer required for MD5 hash operations.
90 @retval 0 This interface is not supported.
100 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for
103 If Md5Context is NULL, then return FALSE.
104 If this interface is not supported, then return FALSE.
106 @param[out] Md5Context Pointer to MD5 context being initialized.
108 @retval TRUE MD5 context initialization succeeded.
109 @retval FALSE MD5 context initialization failed.
110 @retval FALSE This interface is not supported.
120 Makes a copy of an existing MD5 context.
122 If Md5Context is NULL, then return FALSE.
123 If NewMd5Context is NULL, then return FALSE.
124 If this interface is not supported, then return FALSE.
126 @param[in] Md5Context Pointer to MD5 context being copied.
127 @param[out] NewMd5Context Pointer to new MD5 context.
129 @retval TRUE MD5 context copy succeeded.
130 @retval FALSE MD5 context copy failed.
131 @retval FALSE This interface is not supported.
137 IN CONST VOID
*Md5Context
,
138 OUT VOID
*NewMd5Context
142 Digests the input data and updates MD5 context.
144 This function performs MD5 digest on a data buffer of the specified size.
145 It can be called multiple times to compute the digest of long or discontinuous data streams.
146 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized
147 by Md5Final(). Behavior with invalid context is undefined.
149 If Md5Context is NULL, then return FALSE.
150 If this interface is not supported, then return FALSE.
152 @param[in, out] Md5Context Pointer to the MD5 context.
153 @param[in] Data Pointer to the buffer containing the data to be hashed.
154 @param[in] DataSize Size of Data buffer in bytes.
156 @retval TRUE MD5 data digest succeeded.
157 @retval FALSE MD5 data digest failed.
158 @retval FALSE This interface is not supported.
164 IN OUT VOID
*Md5Context
,
170 Completes computation of the MD5 digest value.
172 This function completes MD5 hash computation and retrieves the digest value into
173 the specified memory. After this function has been called, the MD5 context cannot
175 MD5 context should be already correctly initialized by Md5Init(), and should not be
176 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.
178 If Md5Context is NULL, then return FALSE.
179 If HashValue is NULL, then return FALSE.
180 If this interface is not supported, then return FALSE.
182 @param[in, out] Md5Context Pointer to the MD5 context.
183 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
186 @retval TRUE MD5 digest computation succeeded.
187 @retval FALSE MD5 digest computation failed.
188 @retval FALSE This interface is not supported.
194 IN OUT VOID
*Md5Context
,
199 Computes the MD5 message digest of a input data buffer.
201 This function performs the MD5 message digest of a given data buffer, and places
202 the digest value into the specified memory.
204 If this interface is not supported, then return FALSE.
206 @param[in] Data Pointer to the buffer containing the data to be hashed.
207 @param[in] DataSize Size of Data buffer in bytes.
208 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
211 @retval TRUE MD5 digest computation succeeded.
212 @retval FALSE MD5 digest computation failed.
213 @retval FALSE This interface is not supported.
226 #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
229 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.
231 If this interface is not supported, then return zero.
233 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.
234 @retval 0 This interface is not supported.
244 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for
247 If Sha1Context is NULL, then return FALSE.
248 If this interface is not supported, then return FALSE.
250 @param[out] Sha1Context Pointer to SHA-1 context being initialized.
252 @retval TRUE SHA-1 context initialization succeeded.
253 @retval FALSE SHA-1 context initialization failed.
254 @retval FALSE This interface is not supported.
260 OUT VOID
*Sha1Context
264 Makes a copy of an existing SHA-1 context.
266 If Sha1Context is NULL, then return FALSE.
267 If NewSha1Context is NULL, then return FALSE.
268 If this interface is not supported, then return FALSE.
270 @param[in] Sha1Context Pointer to SHA-1 context being copied.
271 @param[out] NewSha1Context Pointer to new SHA-1 context.
273 @retval TRUE SHA-1 context copy succeeded.
274 @retval FALSE SHA-1 context copy failed.
275 @retval FALSE This interface is not supported.
281 IN CONST VOID
*Sha1Context
,
282 OUT VOID
*NewSha1Context
286 Digests the input data and updates SHA-1 context.
288 This function performs SHA-1 digest on a data buffer of the specified size.
289 It can be called multiple times to compute the digest of long or discontinuous data streams.
290 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized
291 by Sha1Final(). Behavior with invalid context is undefined.
293 If Sha1Context is NULL, then return FALSE.
294 If this interface is not supported, then return FALSE.
296 @param[in, out] Sha1Context Pointer to the SHA-1 context.
297 @param[in] Data Pointer to the buffer containing the data to be hashed.
298 @param[in] DataSize Size of Data buffer in bytes.
300 @retval TRUE SHA-1 data digest succeeded.
301 @retval FALSE SHA-1 data digest failed.
302 @retval FALSE This interface is not supported.
308 IN OUT VOID
*Sha1Context
,
314 Completes computation of the SHA-1 digest value.
316 This function completes SHA-1 hash computation and retrieves the digest value into
317 the specified memory. After this function has been called, the SHA-1 context cannot
319 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be
320 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.
322 If Sha1Context is NULL, then return FALSE.
323 If HashValue is NULL, then return FALSE.
324 If this interface is not supported, then return FALSE.
326 @param[in, out] Sha1Context Pointer to the SHA-1 context.
327 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
330 @retval TRUE SHA-1 digest computation succeeded.
331 @retval FALSE SHA-1 digest computation failed.
332 @retval FALSE This interface is not supported.
338 IN OUT VOID
*Sha1Context
,
343 Computes the SHA-1 message digest of a input data buffer.
345 This function performs the SHA-1 message digest of a given data buffer, and places
346 the digest value into the specified memory.
348 If this interface is not supported, then return FALSE.
350 @param[in] Data Pointer to the buffer containing the data to be hashed.
351 @param[in] DataSize Size of Data buffer in bytes.
352 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
355 @retval TRUE SHA-1 digest computation succeeded.
356 @retval FALSE SHA-1 digest computation failed.
357 @retval FALSE This interface is not supported.
371 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.
373 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.
378 Sha256GetContextSize (
383 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for
386 If Sha256Context is NULL, then return FALSE.
388 @param[out] Sha256Context Pointer to SHA-256 context being initialized.
390 @retval TRUE SHA-256 context initialization succeeded.
391 @retval FALSE SHA-256 context initialization failed.
397 OUT VOID
*Sha256Context
401 Makes a copy of an existing SHA-256 context.
403 If Sha256Context is NULL, then return FALSE.
404 If NewSha256Context is NULL, then return FALSE.
405 If this interface is not supported, then return FALSE.
407 @param[in] Sha256Context Pointer to SHA-256 context being copied.
408 @param[out] NewSha256Context Pointer to new SHA-256 context.
410 @retval TRUE SHA-256 context copy succeeded.
411 @retval FALSE SHA-256 context copy failed.
412 @retval FALSE This interface is not supported.
418 IN CONST VOID
*Sha256Context
,
419 OUT VOID
*NewSha256Context
423 Digests the input data and updates SHA-256 context.
425 This function performs SHA-256 digest on a data buffer of the specified size.
426 It can be called multiple times to compute the digest of long or discontinuous data streams.
427 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized
428 by Sha256Final(). Behavior with invalid context is undefined.
430 If Sha256Context is NULL, then return FALSE.
432 @param[in, out] Sha256Context Pointer to the SHA-256 context.
433 @param[in] Data Pointer to the buffer containing the data to be hashed.
434 @param[in] DataSize Size of Data buffer in bytes.
436 @retval TRUE SHA-256 data digest succeeded.
437 @retval FALSE SHA-256 data digest failed.
443 IN OUT VOID
*Sha256Context
,
449 Completes computation of the SHA-256 digest value.
451 This function completes SHA-256 hash computation and retrieves the digest value into
452 the specified memory. After this function has been called, the SHA-256 context cannot
454 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be
455 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.
457 If Sha256Context is NULL, then return FALSE.
458 If HashValue is NULL, then return FALSE.
460 @param[in, out] Sha256Context Pointer to the SHA-256 context.
461 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
464 @retval TRUE SHA-256 digest computation succeeded.
465 @retval FALSE SHA-256 digest computation failed.
471 IN OUT VOID
*Sha256Context
,
476 Computes the SHA-256 message digest of a input data buffer.
478 This function performs the SHA-256 message digest of a given data buffer, and places
479 the digest value into the specified memory.
481 If this interface is not supported, then return FALSE.
483 @param[in] Data Pointer to the buffer containing the data to be hashed.
484 @param[in] DataSize Size of Data buffer in bytes.
485 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
488 @retval TRUE SHA-256 digest computation succeeded.
489 @retval FALSE SHA-256 digest computation failed.
490 @retval FALSE This interface is not supported.
502 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.
504 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.
509 Sha384GetContextSize (
514 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for
517 If Sha384Context is NULL, then return FALSE.
519 @param[out] Sha384Context Pointer to SHA-384 context being initialized.
521 @retval TRUE SHA-384 context initialization succeeded.
522 @retval FALSE SHA-384 context initialization failed.
528 OUT VOID
*Sha384Context
532 Makes a copy of an existing SHA-384 context.
534 If Sha384Context is NULL, then return FALSE.
535 If NewSha384Context is NULL, then return FALSE.
536 If this interface is not supported, then return FALSE.
538 @param[in] Sha384Context Pointer to SHA-384 context being copied.
539 @param[out] NewSha384Context Pointer to new SHA-384 context.
541 @retval TRUE SHA-384 context copy succeeded.
542 @retval FALSE SHA-384 context copy failed.
543 @retval FALSE This interface is not supported.
549 IN CONST VOID
*Sha384Context
,
550 OUT VOID
*NewSha384Context
554 Digests the input data and updates SHA-384 context.
556 This function performs SHA-384 digest on a data buffer of the specified size.
557 It can be called multiple times to compute the digest of long or discontinuous data streams.
558 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized
559 by Sha384Final(). Behavior with invalid context is undefined.
561 If Sha384Context is NULL, then return FALSE.
563 @param[in, out] Sha384Context Pointer to the SHA-384 context.
564 @param[in] Data Pointer to the buffer containing the data to be hashed.
565 @param[in] DataSize Size of Data buffer in bytes.
567 @retval TRUE SHA-384 data digest succeeded.
568 @retval FALSE SHA-384 data digest failed.
574 IN OUT VOID
*Sha384Context
,
580 Completes computation of the SHA-384 digest value.
582 This function completes SHA-384 hash computation and retrieves the digest value into
583 the specified memory. After this function has been called, the SHA-384 context cannot
585 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be
586 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.
588 If Sha384Context is NULL, then return FALSE.
589 If HashValue is NULL, then return FALSE.
591 @param[in, out] Sha384Context Pointer to the SHA-384 context.
592 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
595 @retval TRUE SHA-384 digest computation succeeded.
596 @retval FALSE SHA-384 digest computation failed.
602 IN OUT VOID
*Sha384Context
,
607 Computes the SHA-384 message digest of a input data buffer.
609 This function performs the SHA-384 message digest of a given data buffer, and places
610 the digest value into the specified memory.
612 If this interface is not supported, then return FALSE.
614 @param[in] Data Pointer to the buffer containing the data to be hashed.
615 @param[in] DataSize Size of Data buffer in bytes.
616 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
619 @retval TRUE SHA-384 digest computation succeeded.
620 @retval FALSE SHA-384 digest computation failed.
621 @retval FALSE This interface is not supported.
633 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.
635 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.
640 Sha512GetContextSize (
645 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for
648 If Sha512Context is NULL, then return FALSE.
650 @param[out] Sha512Context Pointer to SHA-512 context being initialized.
652 @retval TRUE SHA-512 context initialization succeeded.
653 @retval FALSE SHA-512 context initialization failed.
659 OUT VOID
*Sha512Context
663 Makes a copy of an existing SHA-512 context.
665 If Sha512Context is NULL, then return FALSE.
666 If NewSha512Context is NULL, then return FALSE.
667 If this interface is not supported, then return FALSE.
669 @param[in] Sha512Context Pointer to SHA-512 context being copied.
670 @param[out] NewSha512Context Pointer to new SHA-512 context.
672 @retval TRUE SHA-512 context copy succeeded.
673 @retval FALSE SHA-512 context copy failed.
674 @retval FALSE This interface is not supported.
680 IN CONST VOID
*Sha512Context
,
681 OUT VOID
*NewSha512Context
685 Digests the input data and updates SHA-512 context.
687 This function performs SHA-512 digest on a data buffer of the specified size.
688 It can be called multiple times to compute the digest of long or discontinuous data streams.
689 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized
690 by Sha512Final(). Behavior with invalid context is undefined.
692 If Sha512Context is NULL, then return FALSE.
694 @param[in, out] Sha512Context Pointer to the SHA-512 context.
695 @param[in] Data Pointer to the buffer containing the data to be hashed.
696 @param[in] DataSize Size of Data buffer in bytes.
698 @retval TRUE SHA-512 data digest succeeded.
699 @retval FALSE SHA-512 data digest failed.
705 IN OUT VOID
*Sha512Context
,
711 Completes computation of the SHA-512 digest value.
713 This function completes SHA-512 hash computation and retrieves the digest value into
714 the specified memory. After this function has been called, the SHA-512 context cannot
716 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be
717 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.
719 If Sha512Context is NULL, then return FALSE.
720 If HashValue is NULL, then return FALSE.
722 @param[in, out] Sha512Context Pointer to the SHA-512 context.
723 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
726 @retval TRUE SHA-512 digest computation succeeded.
727 @retval FALSE SHA-512 digest computation failed.
733 IN OUT VOID
*Sha512Context
,
738 Computes the SHA-512 message digest of a input data buffer.
740 This function performs the SHA-512 message digest of a given data buffer, and places
741 the digest value into the specified memory.
743 If this interface is not supported, then return FALSE.
745 @param[in] Data Pointer to the buffer containing the data to be hashed.
746 @param[in] DataSize Size of Data buffer in bytes.
747 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
750 @retval TRUE SHA-512 digest computation succeeded.
751 @retval FALSE SHA-512 digest computation failed.
752 @retval FALSE This interface is not supported.
764 Parallel hash function ParallelHash256, as defined in NIST's Special Publication 800-185,
765 published December 2016.
767 @param[in] Input Pointer to the input message (X).
768 @param[in] InputByteLen The number(>0) of input bytes provided for the input data.
769 @param[in] BlockSize The size of each block (B).
770 @param[out] Output Pointer to the output buffer.
771 @param[in] OutputByteLen The desired number of output bytes (L).
772 @param[in] Customization Pointer to the customization string (S).
773 @param[in] CustomByteLen The length of the customization string in bytes.
775 @retval TRUE ParallelHash256 digest computation succeeded.
776 @retval FALSE ParallelHash256 digest computation failed.
777 @retval FALSE This interface is not supported.
782 ParallelHash256HashAll (
783 IN CONST VOID
*Input
,
784 IN UINTN InputByteLen
,
787 IN UINTN OutputByteLen
,
788 IN CONST VOID
*Customization
,
789 IN UINTN CustomByteLen
793 Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.
795 @return The size, in bytes, of the context buffer required for SM3 hash operations.
805 Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for
808 If Sm3Context is NULL, then return FALSE.
810 @param[out] Sm3Context Pointer to SM3 context being initialized.
812 @retval TRUE SM3 context initialization succeeded.
813 @retval FALSE SM3 context initialization failed.
823 Makes a copy of an existing SM3 context.
825 If Sm3Context is NULL, then return FALSE.
826 If NewSm3Context is NULL, then return FALSE.
827 If this interface is not supported, then return FALSE.
829 @param[in] Sm3Context Pointer to SM3 context being copied.
830 @param[out] NewSm3Context Pointer to new SM3 context.
832 @retval TRUE SM3 context copy succeeded.
833 @retval FALSE SM3 context copy failed.
834 @retval FALSE This interface is not supported.
840 IN CONST VOID
*Sm3Context
,
841 OUT VOID
*NewSm3Context
845 Digests the input data and updates SM3 context.
847 This function performs SM3 digest on a data buffer of the specified size.
848 It can be called multiple times to compute the digest of long or discontinuous data streams.
849 SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized
850 by Sm3Final(). Behavior with invalid context is undefined.
852 If Sm3Context is NULL, then return FALSE.
854 @param[in, out] Sm3Context Pointer to the SM3 context.
855 @param[in] Data Pointer to the buffer containing the data to be hashed.
856 @param[in] DataSize Size of Data buffer in bytes.
858 @retval TRUE SM3 data digest succeeded.
859 @retval FALSE SM3 data digest failed.
865 IN OUT VOID
*Sm3Context
,
871 Completes computation of the SM3 digest value.
873 This function completes SM3 hash computation and retrieves the digest value into
874 the specified memory. After this function has been called, the SM3 context cannot
876 SM3 context should be already correctly initialized by Sm3Init(), and should not be
877 finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.
879 If Sm3Context is NULL, then return FALSE.
880 If HashValue is NULL, then return FALSE.
882 @param[in, out] Sm3Context Pointer to the SM3 context.
883 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
886 @retval TRUE SM3 digest computation succeeded.
887 @retval FALSE SM3 digest computation failed.
893 IN OUT VOID
*Sm3Context
,
898 Computes the SM3 message digest of a input data buffer.
900 This function performs the SM3 message digest of a given data buffer, and places
901 the digest value into the specified memory.
903 If this interface is not supported, then return FALSE.
905 @param[in] Data Pointer to the buffer containing the data to be hashed.
906 @param[in] DataSize Size of Data buffer in bytes.
907 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
910 @retval TRUE SM3 digest computation succeeded.
911 @retval FALSE SM3 digest computation failed.
912 @retval FALSE This interface is not supported.
923 // =====================================================================================
924 // MAC (Message Authentication Code) Primitive
925 // =====================================================================================
928 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
930 @return Pointer to the HMAC_CTX context that has been initialized.
931 If the allocations fails, HmacSha256New() returns NULL.
941 Release the specified HMAC_CTX context.
943 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.
949 IN VOID
*HmacSha256Ctx
953 Set user-supplied key for subsequent use. It must be done before any
954 calling to HmacSha256Update().
956 If HmacSha256Context is NULL, then return FALSE.
957 If this interface is not supported, then return FALSE.
959 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.
960 @param[in] Key Pointer to the user-supplied key.
961 @param[in] KeySize Key size in bytes.
963 @retval TRUE The Key is set successfully.
964 @retval FALSE The Key is set unsuccessfully.
965 @retval FALSE This interface is not supported.
971 OUT VOID
*HmacSha256Context
,
977 Makes a copy of an existing HMAC-SHA256 context.
979 If HmacSha256Context is NULL, then return FALSE.
980 If NewHmacSha256Context is NULL, then return FALSE.
981 If this interface is not supported, then return FALSE.
983 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.
984 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.
986 @retval TRUE HMAC-SHA256 context copy succeeded.
987 @retval FALSE HMAC-SHA256 context copy failed.
988 @retval FALSE This interface is not supported.
993 HmacSha256Duplicate (
994 IN CONST VOID
*HmacSha256Context
,
995 OUT VOID
*NewHmacSha256Context
999 Digests the input data and updates HMAC-SHA256 context.
1001 This function performs HMAC-SHA256 digest on a data buffer of the specified size.
1002 It can be called multiple times to compute the digest of long or discontinuous data streams.
1003 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1004 by HmacSha256Final(). Behavior with invalid context is undefined.
1006 If HmacSha256Context is NULL, then return FALSE.
1007 If this interface is not supported, then return FALSE.
1009 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1010 @param[in] Data Pointer to the buffer containing the data to be digested.
1011 @param[in] DataSize Size of Data buffer in bytes.
1013 @retval TRUE HMAC-SHA256 data digest succeeded.
1014 @retval FALSE HMAC-SHA256 data digest failed.
1015 @retval FALSE This interface is not supported.
1021 IN OUT VOID
*HmacSha256Context
,
1022 IN CONST VOID
*Data
,
1027 Completes computation of the HMAC-SHA256 digest value.
1029 This function completes HMAC-SHA256 hash computation and retrieves the digest value into
1030 the specified memory. After this function has been called, the HMAC-SHA256 context cannot
1032 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1033 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.
1035 If HmacSha256Context is NULL, then return FALSE.
1036 If HmacValue is NULL, then return FALSE.
1037 If this interface is not supported, then return FALSE.
1039 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1040 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
1043 @retval TRUE HMAC-SHA256 digest computation succeeded.
1044 @retval FALSE HMAC-SHA256 digest computation failed.
1045 @retval FALSE This interface is not supported.
1051 IN OUT VOID
*HmacSha256Context
,
1052 OUT UINT8
*HmacValue
1056 Computes the HMAC-SHA256 digest of a input data buffer.
1058 This function performs the HMAC-SHA256 digest of a given data buffer, and places
1059 the digest value into the specified memory.
1061 If this interface is not supported, then return FALSE.
1063 @param[in] Data Pointer to the buffer containing the data to be digested.
1064 @param[in] DataSize Size of Data buffer in bytes.
1065 @param[in] Key Pointer to the user-supplied key.
1066 @param[in] KeySize Key size in bytes.
1067 @param[out] HashValue Pointer to a buffer that receives the HMAC-SHA256 digest
1070 @retval TRUE HMAC-SHA256 digest computation succeeded.
1071 @retval FALSE HMAC-SHA256 digest computation failed.
1072 @retval FALSE This interface is not supported.
1078 IN CONST VOID
*Data
,
1080 IN CONST UINT8
*Key
,
1082 OUT UINT8
*HmacValue
1086 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA384 use.
1088 @return Pointer to the HMAC_CTX context that has been initialized.
1089 If the allocations fails, HmacSha384New() returns NULL.
1099 Release the specified HMAC_CTX context.
1101 @param[in] HmacSha384Ctx Pointer to the HMAC_CTX context to be released.
1107 IN VOID
*HmacSha384Ctx
1111 Set user-supplied key for subsequent use. It must be done before any
1112 calling to HmacSha384Update().
1114 If HmacSha384Context is NULL, then return FALSE.
1115 If this interface is not supported, then return FALSE.
1117 @param[out] HmacSha384Context Pointer to HMAC-SHA384 context.
1118 @param[in] Key Pointer to the user-supplied key.
1119 @param[in] KeySize Key size in bytes.
1121 @retval TRUE The Key is set successfully.
1122 @retval FALSE The Key is set unsuccessfully.
1123 @retval FALSE This interface is not supported.
1129 OUT VOID
*HmacSha384Context
,
1130 IN CONST UINT8
*Key
,
1135 Makes a copy of an existing HMAC-SHA384 context.
1137 If HmacSha384Context is NULL, then return FALSE.
1138 If NewHmacSha384Context is NULL, then return FALSE.
1139 If this interface is not supported, then return FALSE.
1141 @param[in] HmacSha384Context Pointer to HMAC-SHA384 context being copied.
1142 @param[out] NewHmacSha384Context Pointer to new HMAC-SHA384 context.
1144 @retval TRUE HMAC-SHA384 context copy succeeded.
1145 @retval FALSE HMAC-SHA384 context copy failed.
1146 @retval FALSE This interface is not supported.
1151 HmacSha384Duplicate (
1152 IN CONST VOID
*HmacSha384Context
,
1153 OUT VOID
*NewHmacSha384Context
1157 Digests the input data and updates HMAC-SHA384 context.
1159 This function performs HMAC-SHA384 digest on a data buffer of the specified size.
1160 It can be called multiple times to compute the digest of long or discontinuous data streams.
1161 HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized
1162 by HmacSha384Final(). Behavior with invalid context is undefined.
1164 If HmacSha384Context is NULL, then return FALSE.
1165 If this interface is not supported, then return FALSE.
1167 @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.
1168 @param[in] Data Pointer to the buffer containing the data to be digested.
1169 @param[in] DataSize Size of Data buffer in bytes.
1171 @retval TRUE HMAC-SHA384 data digest succeeded.
1172 @retval FALSE HMAC-SHA384 data digest failed.
1173 @retval FALSE This interface is not supported.
1179 IN OUT VOID
*HmacSha384Context
,
1180 IN CONST VOID
*Data
,
1185 Completes computation of the HMAC-SHA384 digest value.
1187 This function completes HMAC-SHA384 hash computation and retrieves the digest value into
1188 the specified memory. After this function has been called, the HMAC-SHA384 context cannot
1190 HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized
1191 by HmacSha384Final(). Behavior with invalid HMAC-SHA384 context is undefined.
1193 If HmacSha384Context is NULL, then return FALSE.
1194 If HmacValue is NULL, then return FALSE.
1195 If this interface is not supported, then return FALSE.
1197 @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.
1198 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA384 digest
1201 @retval TRUE HMAC-SHA384 digest computation succeeded.
1202 @retval FALSE HMAC-SHA384 digest computation failed.
1203 @retval FALSE This interface is not supported.
1209 IN OUT VOID
*HmacSha384Context
,
1210 OUT UINT8
*HmacValue
1214 Computes the HMAC-SHA384 digest of a input data buffer.
1216 This function performs the HMAC-SHA384 digest of a given data buffer, and places
1217 the digest value into the specified memory.
1219 If this interface is not supported, then return FALSE.
1221 @param[in] Data Pointer to the buffer containing the data to be digested.
1222 @param[in] DataSize Size of Data buffer in bytes.
1223 @param[in] Key Pointer to the user-supplied key.
1224 @param[in] KeySize Key size in bytes.
1225 @param[out] HashValue Pointer to a buffer that receives the HMAC-SHA384 digest
1228 @retval TRUE HMAC-SHA384 digest computation succeeded.
1229 @retval FALSE HMAC-SHA384 digest computation failed.
1230 @retval FALSE This interface is not supported.
1236 IN CONST VOID
*Data
,
1238 IN CONST UINT8
*Key
,
1240 OUT UINT8
*HmacValue
1243 // =====================================================================================
1244 // Symmetric Cryptography Primitive
1245 // =====================================================================================
1248 Retrieves the size, in bytes, of the context buffer required for AES operations.
1250 If this interface is not supported, then return zero.
1252 @return The size, in bytes, of the context buffer required for AES operations.
1253 @retval 0 This interface is not supported.
1263 Initializes user-supplied memory as AES context for subsequent use.
1265 This function initializes user-supplied memory pointed by AesContext as AES context.
1266 In addition, it sets up all AES key materials for subsequent encryption and decryption
1268 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1270 If AesContext is NULL, then return FALSE.
1271 If Key is NULL, then return FALSE.
1272 If KeyLength is not valid, then return FALSE.
1273 If this interface is not supported, then return FALSE.
1275 @param[out] AesContext Pointer to AES context being initialized.
1276 @param[in] Key Pointer to the user-supplied AES key.
1277 @param[in] KeyLength Length of AES key in bits.
1279 @retval TRUE AES context initialization succeeded.
1280 @retval FALSE AES context initialization failed.
1281 @retval FALSE This interface is not supported.
1287 OUT VOID
*AesContext
,
1288 IN CONST UINT8
*Key
,
1293 Performs AES encryption on a data buffer of the specified size in CBC mode.
1295 This function performs AES encryption on data buffer pointed by Input, of specified
1296 size of InputSize, in CBC mode.
1297 InputSize must be multiple of block size (16 bytes). This function does not perform
1298 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1299 Initialization vector should be one block size (16 bytes).
1300 AesContext should be already correctly initialized by AesInit(). Behavior with
1301 invalid AES context is undefined.
1303 If AesContext is NULL, then return FALSE.
1304 If Input is NULL, then return FALSE.
1305 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1306 If Ivec is NULL, then return FALSE.
1307 If Output is NULL, then return FALSE.
1308 If this interface is not supported, then return FALSE.
1310 @param[in] AesContext Pointer to the AES context.
1311 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1312 @param[in] InputSize Size of the Input buffer in bytes.
1313 @param[in] Ivec Pointer to initialization vector.
1314 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1316 @retval TRUE AES encryption succeeded.
1317 @retval FALSE AES encryption failed.
1318 @retval FALSE This interface is not supported.
1324 IN VOID
*AesContext
,
1325 IN CONST UINT8
*Input
,
1327 IN CONST UINT8
*Ivec
,
1332 Performs AES decryption on a data buffer of the specified size in CBC mode.
1334 This function performs AES decryption on data buffer pointed by Input, of specified
1335 size of InputSize, in CBC mode.
1336 InputSize must be multiple of block size (16 bytes). This function does not perform
1337 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1338 Initialization vector should be one block size (16 bytes).
1339 AesContext should be already correctly initialized by AesInit(). Behavior with
1340 invalid AES context is undefined.
1342 If AesContext is NULL, then return FALSE.
1343 If Input is NULL, then return FALSE.
1344 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1345 If Ivec is NULL, then return FALSE.
1346 If Output is NULL, then return FALSE.
1347 If this interface is not supported, then return FALSE.
1349 @param[in] AesContext Pointer to the AES context.
1350 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1351 @param[in] InputSize Size of the Input buffer in bytes.
1352 @param[in] Ivec Pointer to initialization vector.
1353 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1355 @retval TRUE AES decryption succeeded.
1356 @retval FALSE AES decryption failed.
1357 @retval FALSE This interface is not supported.
1363 IN VOID
*AesContext
,
1364 IN CONST UINT8
*Input
,
1366 IN CONST UINT8
*Ivec
,
1370 // =====================================================================================
1371 // Authenticated Encryption with Associated Data (AEAD) Cryptography Primitive
1372 // =====================================================================================
1375 Performs AEAD AES-GCM authenticated encryption on a data buffer and additional authenticated data (AAD).
1377 IvSize must be 12, otherwise FALSE is returned.
1378 KeySize must be 16, 24 or 32, otherwise FALSE is returned.
1379 TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.
1381 @param[in] Key Pointer to the encryption key.
1382 @param[in] KeySize Size of the encryption key in bytes.
1383 @param[in] Iv Pointer to the IV value.
1384 @param[in] IvSize Size of the IV value in bytes.
1385 @param[in] AData Pointer to the additional authenticated data (AAD).
1386 @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.
1387 @param[in] DataIn Pointer to the input data buffer to be encrypted.
1388 @param[in] DataInSize Size of the input data buffer in bytes.
1389 @param[out] TagOut Pointer to a buffer that receives the authentication tag output.
1390 @param[in] TagSize Size of the authentication tag in bytes.
1391 @param[out] DataOut Pointer to a buffer that receives the encryption output.
1392 @param[out] DataOutSize Size of the output data buffer in bytes.
1394 @retval TRUE AEAD AES-GCM authenticated encryption succeeded.
1395 @retval FALSE AEAD AES-GCM authenticated encryption failed.
1401 IN CONST UINT8
*Key
,
1405 IN CONST UINT8
*AData
,
1407 IN CONST UINT8
*DataIn
,
1408 IN UINTN DataInSize
,
1412 OUT UINTN
*DataOutSize
1416 Performs AEAD AES-GCM authenticated decryption on a data buffer and additional authenticated data (AAD).
1418 IvSize must be 12, otherwise FALSE is returned.
1419 KeySize must be 16, 24 or 32, otherwise FALSE is returned.
1420 TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.
1421 If additional authenticated data verification fails, FALSE is returned.
1423 @param[in] Key Pointer to the encryption key.
1424 @param[in] KeySize Size of the encryption key in bytes.
1425 @param[in] Iv Pointer to the IV value.
1426 @param[in] IvSize Size of the IV value in bytes.
1427 @param[in] AData Pointer to the additional authenticated data (AAD).
1428 @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.
1429 @param[in] DataIn Pointer to the input data buffer to be decrypted.
1430 @param[in] DataInSize Size of the input data buffer in bytes.
1431 @param[in] Tag Pointer to a buffer that contains the authentication tag.
1432 @param[in] TagSize Size of the authentication tag in bytes.
1433 @param[out] DataOut Pointer to a buffer that receives the decryption output.
1434 @param[out] DataOutSize Size of the output data buffer in bytes.
1436 @retval TRUE AEAD AES-GCM authenticated decryption succeeded.
1437 @retval FALSE AEAD AES-GCM authenticated decryption failed.
1443 IN CONST UINT8
*Key
,
1447 IN CONST UINT8
*AData
,
1449 IN CONST UINT8
*DataIn
,
1450 IN UINTN DataInSize
,
1451 IN CONST UINT8
*Tag
,
1454 OUT UINTN
*DataOutSize
1457 // =====================================================================================
1458 // Asymmetric Cryptography Primitive
1459 // =====================================================================================
1462 Allocates and initializes one RSA context for subsequent use.
1464 @return Pointer to the RSA context that has been initialized.
1465 If the allocations fails, RsaNew() returns NULL.
1475 Release the specified RSA context.
1477 If RsaContext is NULL, then return FALSE.
1479 @param[in] RsaContext Pointer to the RSA context to be released.
1489 Sets the tag-designated key component into the established RSA context.
1491 This function sets the tag-designated RSA key component into the established
1492 RSA context from the user-specified non-negative integer (octet string format
1493 represented in RSA PKCS#1).
1494 If BigNumber is NULL, then the specified key component in RSA context is cleared.
1496 If RsaContext is NULL, then return FALSE.
1498 @param[in, out] RsaContext Pointer to RSA context being set.
1499 @param[in] KeyTag Tag of RSA key component being set.
1500 @param[in] BigNumber Pointer to octet integer buffer.
1501 If NULL, then the specified key component in RSA
1503 @param[in] BnSize Size of big number buffer in bytes.
1504 If BigNumber is NULL, then it is ignored.
1506 @retval TRUE RSA key component was set successfully.
1507 @retval FALSE Invalid RSA key component tag.
1513 IN OUT VOID
*RsaContext
,
1514 IN RSA_KEY_TAG KeyTag
,
1515 IN CONST UINT8
*BigNumber
,
1520 Gets the tag-designated RSA key component from the established RSA context.
1522 This function retrieves the tag-designated RSA key component from the
1523 established RSA context as a non-negative integer (octet string format
1524 represented in RSA PKCS#1).
1525 If specified key component has not been set or has been cleared, then returned
1527 If the BigNumber buffer is too small to hold the contents of the key, FALSE
1528 is returned and BnSize is set to the required buffer size to obtain the key.
1530 If RsaContext is NULL, then return FALSE.
1531 If BnSize is NULL, then return FALSE.
1532 If BnSize is large enough but BigNumber is NULL, then return FALSE.
1533 If this interface is not supported, then return FALSE.
1535 @param[in, out] RsaContext Pointer to RSA context being set.
1536 @param[in] KeyTag Tag of RSA key component being set.
1537 @param[out] BigNumber Pointer to octet integer buffer.
1538 @param[in, out] BnSize On input, the size of big number buffer in bytes.
1539 On output, the size of data returned in big number buffer in bytes.
1541 @retval TRUE RSA key component was retrieved successfully.
1542 @retval FALSE Invalid RSA key component tag.
1543 @retval FALSE BnSize is too small.
1544 @retval FALSE This interface is not supported.
1550 IN OUT VOID
*RsaContext
,
1551 IN RSA_KEY_TAG KeyTag
,
1552 OUT UINT8
*BigNumber
,
1553 IN OUT UINTN
*BnSize
1557 Generates RSA key components.
1559 This function generates RSA key components. It takes RSA public exponent E and
1560 length in bits of RSA modulus N as input, and generates all key components.
1561 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
1563 Before this function can be invoked, pseudorandom number generator must be correctly
1564 initialized by RandomSeed().
1566 If RsaContext is NULL, then return FALSE.
1567 If this interface is not supported, then return FALSE.
1569 @param[in, out] RsaContext Pointer to RSA context being set.
1570 @param[in] ModulusLength Length of RSA modulus N in bits.
1571 @param[in] PublicExponent Pointer to RSA public exponent.
1572 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
1574 @retval TRUE RSA key component was generated successfully.
1575 @retval FALSE Invalid RSA key component tag.
1576 @retval FALSE This interface is not supported.
1582 IN OUT VOID
*RsaContext
,
1583 IN UINTN ModulusLength
,
1584 IN CONST UINT8
*PublicExponent
,
1585 IN UINTN PublicExponentSize
1589 Validates key components of RSA context.
1590 NOTE: This function performs integrity checks on all the RSA key material, so
1591 the RSA key structure must contain all the private key data.
1593 This function validates key components of RSA context in following aspects:
1594 - Whether p is a prime
1595 - Whether q is a prime
1597 - Whether d*e = 1 mod lcm(p-1,q-1)
1599 If RsaContext is NULL, then return FALSE.
1600 If this interface is not supported, then return FALSE.
1602 @param[in] RsaContext Pointer to RSA context to check.
1604 @retval TRUE RSA key components are valid.
1605 @retval FALSE RSA key components are not valid.
1606 @retval FALSE This interface is not supported.
1616 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
1618 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
1620 If the Signature buffer is too small to hold the contents of signature, FALSE
1621 is returned and SigSize is set to the required buffer size to obtain the signature.
1623 If RsaContext is NULL, then return FALSE.
1624 If MessageHash is NULL, then return FALSE.
1625 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
1626 If SigSize is large enough but Signature is NULL, then return FALSE.
1627 If this interface is not supported, then return FALSE.
1629 @param[in] RsaContext Pointer to RSA context for signature generation.
1630 @param[in] MessageHash Pointer to octet message hash to be signed.
1631 @param[in] HashSize Size of the message hash in bytes.
1632 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
1633 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1634 On output, the size of data returned in Signature buffer in bytes.
1636 @retval TRUE Signature successfully generated in PKCS1-v1_5.
1637 @retval FALSE Signature generation failed.
1638 @retval FALSE SigSize is too small.
1639 @retval FALSE This interface is not supported.
1645 IN VOID
*RsaContext
,
1646 IN CONST UINT8
*MessageHash
,
1648 OUT UINT8
*Signature
,
1649 IN OUT UINTN
*SigSize
1653 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
1656 If RsaContext is NULL, then return FALSE.
1657 If MessageHash is NULL, then return FALSE.
1658 If Signature is NULL, then return FALSE.
1659 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
1661 @param[in] RsaContext Pointer to RSA context for signature verification.
1662 @param[in] MessageHash Pointer to octet message hash to be checked.
1663 @param[in] HashSize Size of the message hash in bytes.
1664 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
1665 @param[in] SigSize Size of signature in bytes.
1667 @retval TRUE Valid signature encoded in PKCS1-v1_5.
1668 @retval FALSE Invalid signature or invalid RSA context.
1674 IN VOID
*RsaContext
,
1675 IN CONST UINT8
*MessageHash
,
1677 IN CONST UINT8
*Signature
,
1682 Carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme.
1684 This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in
1686 Mask generation function is the same as the message digest algorithm.
1687 If the Signature buffer is too small to hold the contents of signature, FALSE
1688 is returned and SigSize is set to the required buffer size to obtain the signature.
1690 If RsaContext is NULL, then return FALSE.
1691 If Message is NULL, then return FALSE.
1692 If MsgSize is zero or > INT_MAX, then return FALSE.
1693 If DigestLen is NOT 32, 48 or 64, return FALSE.
1694 If SaltLen is not equal to DigestLen, then return FALSE.
1695 If SigSize is large enough but Signature is NULL, then return FALSE.
1696 If this interface is not supported, then return FALSE.
1698 @param[in] RsaContext Pointer to RSA context for signature generation.
1699 @param[in] Message Pointer to octet message to be signed.
1700 @param[in] MsgSize Size of the message in bytes.
1701 @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.
1702 @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.
1703 @param[out] Signature Pointer to buffer to receive RSA PSS signature.
1704 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
1705 On output, the size of data returned in Signature buffer in bytes.
1707 @retval TRUE Signature successfully generated in RSASSA-PSS.
1708 @retval FALSE Signature generation failed.
1709 @retval FALSE SigSize is too small.
1710 @retval FALSE This interface is not supported.
1716 IN VOID
*RsaContext
,
1717 IN CONST UINT8
*Message
,
1719 IN UINT16 DigestLen
,
1721 OUT UINT8
*Signature
,
1722 IN OUT UINTN
*SigSize
1726 Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
1727 Implementation determines salt length automatically from the signature encoding.
1728 Mask generation function is the same as the message digest algorithm.
1729 Salt length should be equal to digest length.
1731 @param[in] RsaContext Pointer to RSA context for signature verification.
1732 @param[in] Message Pointer to octet message to be verified.
1733 @param[in] MsgSize Size of the message in bytes.
1734 @param[in] Signature Pointer to RSASSA-PSS signature to be verified.
1735 @param[in] SigSize Size of signature in bytes.
1736 @param[in] DigestLen Length of digest for RSA operation.
1737 @param[in] SaltLen Salt length for PSS encoding.
1739 @retval TRUE Valid signature encoded in RSASSA-PSS.
1740 @retval FALSE Invalid signature or invalid RSA context.
1746 IN VOID
*RsaContext
,
1747 IN CONST UINT8
*Message
,
1749 IN CONST UINT8
*Signature
,
1751 IN UINT16 DigestLen
,
1756 Retrieve the RSA Private Key from the password-protected PEM key data.
1758 If PemData is NULL, then return FALSE.
1759 If RsaContext is NULL, then return FALSE.
1760 If this interface is not supported, then return FALSE.
1762 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
1763 @param[in] PemSize Size of the PEM key data in bytes.
1764 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
1765 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1766 RSA private key component. Use RsaFree() function to free the
1769 @retval TRUE RSA Private Key was retrieved successfully.
1770 @retval FALSE Invalid PEM key data or incorrect password.
1771 @retval FALSE This interface is not supported.
1776 RsaGetPrivateKeyFromPem (
1777 IN CONST UINT8
*PemData
,
1779 IN CONST CHAR8
*Password
,
1780 OUT VOID
**RsaContext
1784 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
1786 If Cert is NULL, then return FALSE.
1787 If RsaContext is NULL, then return FALSE.
1788 If this interface is not supported, then return FALSE.
1790 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1791 @param[in] CertSize Size of the X509 certificate in bytes.
1792 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
1793 RSA public key component. Use RsaFree() function to free the
1796 @retval TRUE RSA Public Key was retrieved successfully.
1797 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
1798 @retval FALSE This interface is not supported.
1803 RsaGetPublicKeyFromX509 (
1804 IN CONST UINT8
*Cert
,
1806 OUT VOID
**RsaContext
1810 Retrieve the subject bytes from one X.509 certificate.
1812 If Cert is NULL, then return FALSE.
1813 If SubjectSize is NULL, then return FALSE.
1814 If this interface is not supported, then return FALSE.
1816 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1817 @param[in] CertSize Size of the X509 certificate in bytes.
1818 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
1819 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
1820 and the size of buffer returned CertSubject on output.
1822 @retval TRUE The certificate subject retrieved successfully.
1823 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
1824 The SubjectSize will be updated with the required size.
1825 @retval FALSE This interface is not supported.
1830 X509GetSubjectName (
1831 IN CONST UINT8
*Cert
,
1833 OUT UINT8
*CertSubject
,
1834 IN OUT UINTN
*SubjectSize
1838 Retrieve the common name (CN) string from one X.509 certificate.
1840 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1841 @param[in] CertSize Size of the X509 certificate in bytes.
1842 @param[out] CommonName Buffer to contain the retrieved certificate common
1843 name string (UTF8). At most CommonNameSize bytes will be
1844 written and the string will be null terminated. May be
1845 NULL in order to determine the size buffer needed.
1846 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
1847 and the size of buffer returned CommonName on output.
1848 If CommonName is NULL then the amount of space needed
1849 in buffer (including the final null) is returned.
1851 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
1852 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
1853 If CommonNameSize is NULL.
1854 If CommonName is not NULL and *CommonNameSize is 0.
1855 If Certificate is invalid.
1856 @retval RETURN_NOT_FOUND If no CommonName entry exists.
1857 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
1858 (including the final null) is returned in the
1859 CommonNameSize parameter.
1860 @retval RETURN_UNSUPPORTED The operation is not supported.
1866 IN CONST UINT8
*Cert
,
1868 OUT CHAR8
*CommonName OPTIONAL
,
1869 IN OUT UINTN
*CommonNameSize
1873 Retrieve the organization name (O) string from one X.509 certificate.
1875 @param[in] Cert Pointer to the DER-encoded X509 certificate.
1876 @param[in] CertSize Size of the X509 certificate in bytes.
1877 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
1878 name string. At most NameBufferSize bytes will be
1879 written and the string will be null terminated. May be
1880 NULL in order to determine the size buffer needed.
1881 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
1882 and the size of buffer returned Name on output.
1883 If NameBuffer is NULL then the amount of space needed
1884 in buffer (including the final null) is returned.
1886 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
1887 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
1888 If NameBufferSize is NULL.
1889 If NameBuffer is not NULL and *CommonNameSize is 0.
1890 If Certificate is invalid.
1891 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
1892 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
1893 (including the final null) is returned in the
1894 CommonNameSize parameter.
1895 @retval RETURN_UNSUPPORTED The operation is not supported.
1900 X509GetOrganizationName (
1901 IN CONST UINT8
*Cert
,
1903 OUT CHAR8
*NameBuffer OPTIONAL
,
1904 IN OUT UINTN
*NameBufferSize
1908 Verify one X509 certificate was issued by the trusted CA.
1910 If Cert is NULL, then return FALSE.
1911 If CACert is NULL, then return FALSE.
1912 If this interface is not supported, then return FALSE.
1914 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
1915 @param[in] CertSize Size of the X509 certificate in bytes.
1916 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
1917 @param[in] CACertSize Size of the CA Certificate in bytes.
1919 @retval TRUE The certificate was issued by the trusted CA.
1920 @retval FALSE Invalid certificate or the certificate was not issued by the given
1922 @retval FALSE This interface is not supported.
1928 IN CONST UINT8
*Cert
,
1930 IN CONST UINT8
*CACert
,
1935 Construct a X509 object from DER-encoded certificate data.
1937 If Cert is NULL, then return FALSE.
1938 If SingleX509Cert is NULL, then return FALSE.
1939 If this interface is not supported, then return FALSE.
1941 @param[in] Cert Pointer to the DER-encoded certificate data.
1942 @param[in] CertSize The size of certificate data in bytes.
1943 @param[out] SingleX509Cert The generated X509 object.
1945 @retval TRUE The X509 object generation succeeded.
1946 @retval FALSE The operation failed.
1947 @retval FALSE This interface is not supported.
1952 X509ConstructCertificate (
1953 IN CONST UINT8
*Cert
,
1955 OUT UINT8
**SingleX509Cert
1959 Construct a X509 stack object from a list of DER-encoded certificate data.
1961 If X509Stack is NULL, then return FALSE.
1962 If this interface is not supported, then return FALSE.
1964 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
1965 On output, pointer to the X509 stack object with new
1966 inserted X509 certificate.
1967 @param[in] Args VA_LIST marker for the variable argument list.
1968 A list of DER-encoded single certificate data followed
1969 by certificate size. A NULL terminates the list. The
1970 pairs are the arguments to X509ConstructCertificate().
1972 @retval TRUE The X509 stack construction succeeded.
1973 @retval FALSE The construction operation failed.
1974 @retval FALSE This interface is not supported.
1979 X509ConstructCertificateStackV (
1980 IN OUT UINT8
**X509Stack
,
1985 Construct a X509 stack object from a list of DER-encoded certificate data.
1987 If X509Stack is NULL, then return FALSE.
1988 If this interface is not supported, then return FALSE.
1990 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
1991 On output, pointer to the X509 stack object with new
1992 inserted X509 certificate.
1993 @param ... A list of DER-encoded single certificate data followed
1994 by certificate size. A NULL terminates the list. The
1995 pairs are the arguments to X509ConstructCertificate().
1997 @retval TRUE The X509 stack construction succeeded.
1998 @retval FALSE The construction operation failed.
1999 @retval FALSE This interface is not supported.
2004 X509ConstructCertificateStack (
2005 IN OUT UINT8
**X509Stack
,
2010 Release the specified X509 object.
2012 If the interface is not supported, then ASSERT().
2014 @param[in] X509Cert Pointer to the X509 object to be released.
2024 Release the specified X509 stack object.
2026 If the interface is not supported, then ASSERT().
2028 @param[in] X509Stack Pointer to the X509 stack object to be released.
2038 Retrieve the TBSCertificate from one given X.509 certificate.
2040 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
2041 @param[in] CertSize Size of the X509 certificate in bytes.
2042 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
2043 @param[out] TBSCertSize Size of the TBS certificate in bytes.
2045 If Cert is NULL, then return FALSE.
2046 If TBSCert is NULL, then return FALSE.
2047 If TBSCertSize is NULL, then return FALSE.
2048 If this interface is not supported, then return FALSE.
2050 @retval TRUE The TBSCertificate was retrieved successfully.
2051 @retval FALSE Invalid X.509 certificate.
2057 IN CONST UINT8
*Cert
,
2059 OUT UINT8
**TBSCert
,
2060 OUT UINTN
*TBSCertSize
2064 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2065 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2067 If Password or Salt or OutKey is NULL, then return FALSE.
2068 If the hash algorithm could not be determined, then return FALSE.
2069 If this interface is not supported, then return FALSE.
2071 @param[in] PasswordLength Length of input password in bytes.
2072 @param[in] Password Pointer to the array for the password.
2073 @param[in] SaltLength Size of the Salt in bytes.
2074 @param[in] Salt Pointer to the Salt.
2075 @param[in] IterationCount Number of iterations to perform. Its value should be
2076 greater than or equal to 1.
2077 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2078 NOTE: DigestSize will be used to determine the hash algorithm.
2079 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2080 @param[in] KeyLength Size of the derived key buffer in bytes.
2081 @param[out] OutKey Pointer to the output derived key buffer.
2083 @retval TRUE A key was derived successfully.
2084 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2085 @retval FALSE The hash algorithm could not be determined from the digest size.
2086 @retval FALSE The key derivation operation failed.
2087 @retval FALSE This interface is not supported.
2093 IN UINTN PasswordLength
,
2094 IN CONST CHAR8
*Password
,
2095 IN UINTN SaltLength
,
2096 IN CONST UINT8
*Salt
,
2097 IN UINTN IterationCount
,
2098 IN UINTN DigestSize
,
2104 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2105 encrypted message in a newly allocated buffer.
2107 Things that can cause a failure include:
2108 - X509 key size does not match any known key size.
2109 - Fail to parse X509 certificate.
2110 - Fail to allocate an intermediate buffer.
2111 - Null pointer provided for a non-optional parameter.
2112 - Data size is too large for the provided key size (max size is a function of key size
2113 and hash digest size).
2115 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2116 will be used to encrypt the data.
2117 @param[in] PublicKeySize Size of the X509 cert buffer.
2118 @param[in] InData Data to be encrypted.
2119 @param[in] InDataSize Size of the data buffer.
2120 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2121 to be used when initializing the PRNG. NULL otherwise.
2122 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2124 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2126 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2128 @retval TRUE Encryption was successful.
2129 @retval FALSE Encryption failed.
2135 IN CONST UINT8
*PublicKey
,
2136 IN UINTN PublicKeySize
,
2138 IN UINTN InDataSize
,
2139 IN CONST UINT8
*PrngSeed OPTIONAL
,
2140 IN UINTN PrngSeedSize OPTIONAL
,
2141 OUT UINT8
**EncryptedData
,
2142 OUT UINTN
*EncryptedDataSize
2146 The 3rd parameter of Pkcs7GetSigners will return all embedded
2147 X.509 certificate in one given PKCS7 signature. The format is:
2149 // UINT8 CertNumber;
2150 // UINT32 Cert1Length;
2152 // UINT32 Cert2Length;
2155 // UINT32 CertnLength;
2159 The two following C-structure are used for parsing CertStack more clearly.
2164 UINT32 CertDataLength
; // The length in bytes of X.509 certificate.
2165 UINT8 CertDataBuffer
[0]; // The X.509 certificate content (DER).
2169 UINT8 CertNumber
; // Number of X.509 certificate.
2170 // EFI_CERT_DATA CertArray[]; // An array of X.509 certificate.
2176 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2177 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2178 in a ContentInfo structure.
2180 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2181 return FALSE. If P7Length overflow, then return FALSE.
2182 If this interface is not supported, then return FALSE.
2184 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2185 @param[in] P7Length Length of the PKCS#7 message in bytes.
2186 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2187 It's caller's responsibility to free the buffer with
2189 This data structure is EFI_CERT_STACK type.
2190 @param[out] StackLength Length of signer's certificates in bytes.
2191 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2192 It's caller's responsibility to free the buffer with
2194 @param[out] CertLength Length of the trusted certificate in bytes.
2196 @retval TRUE The operation is finished successfully.
2197 @retval FALSE Error occurs during the operation.
2198 @retval FALSE This interface is not supported.
2204 IN CONST UINT8
*P7Data
,
2206 OUT UINT8
**CertStack
,
2207 OUT UINTN
*StackLength
,
2208 OUT UINT8
**TrustedCert
,
2209 OUT UINTN
*CertLength
2213 Wrap function to use free() to free allocated memory for certificates.
2215 If this interface is not supported, then ASSERT().
2217 @param[in] Certs Pointer to the certificates to be freed.
2227 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2228 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2229 unchained to the signer's certificates.
2230 The input signed data could be wrapped in a ContentInfo structure.
2232 @param[in] P7Data Pointer to the PKCS#7 message.
2233 @param[in] P7Length Length of the PKCS#7 message in bytes.
2234 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2235 certificate. It's caller's responsibility to free the buffer
2236 with Pkcs7FreeSigners().
2237 This data structure is EFI_CERT_STACK type.
2238 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2239 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2240 responsibility to free the buffer with Pkcs7FreeSigners().
2241 This data structure is EFI_CERT_STACK type.
2242 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2244 @retval TRUE The operation is finished successfully.
2245 @retval FALSE Error occurs during the operation.
2250 Pkcs7GetCertificatesList (
2251 IN CONST UINT8
*P7Data
,
2253 OUT UINT8
**SignerChainCerts
,
2254 OUT UINTN
*ChainLength
,
2255 OUT UINT8
**UnchainCerts
,
2256 OUT UINTN
*UnchainLength
2260 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2261 Syntax Standard, version 1.5". This interface is only intended to be used for
2262 application to perform PKCS#7 functionality validation.
2264 If this interface is not supported, then return FALSE.
2266 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2268 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2269 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2271 @param[in] InData Pointer to the content to be signed.
2272 @param[in] InDataSize Size of InData in bytes.
2273 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2274 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2275 include in the PKCS#7 signedData (e.g. any intermediate
2277 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2278 responsibility to free the buffer with FreePool().
2279 @param[out] SignedDataSize Size of SignedData in bytes.
2281 @retval TRUE PKCS#7 data signing succeeded.
2282 @retval FALSE PKCS#7 data signing failed.
2283 @retval FALSE This interface is not supported.
2289 IN CONST UINT8
*PrivateKey
,
2290 IN UINTN PrivateKeySize
,
2291 IN CONST UINT8
*KeyPassword
,
2293 IN UINTN InDataSize
,
2295 IN UINT8
*OtherCerts OPTIONAL
,
2296 OUT UINT8
**SignedData
,
2297 OUT UINTN
*SignedDataSize
2301 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2302 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2303 in a ContentInfo structure.
2305 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2306 If P7Length, CertLength or DataLength overflow, then return FALSE.
2307 If this interface is not supported, then return FALSE.
2309 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2310 @param[in] P7Length Length of the PKCS#7 message in bytes.
2311 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2312 is used for certificate chain verification.
2313 @param[in] CertLength Length of the trusted certificate in bytes.
2314 @param[in] InData Pointer to the content to be verified.
2315 @param[in] DataLength Length of InData in bytes.
2317 @retval TRUE The specified PKCS#7 signed data is valid.
2318 @retval FALSE Invalid PKCS#7 signed data.
2319 @retval FALSE This interface is not supported.
2325 IN CONST UINT8
*P7Data
,
2327 IN CONST UINT8
*TrustedCert
,
2328 IN UINTN CertLength
,
2329 IN CONST UINT8
*InData
,
2334 This function receives a PKCS7 formatted signature, and then verifies that
2335 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
2336 leaf signing certificate.
2337 Note that this function does not validate the certificate chain.
2339 Applications for custom EKU's are quite flexible. For example, a policy EKU
2340 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
2341 certificate issued might also contain this EKU, thus constraining the
2342 sub-ordinate certificate. Other applications might allow a certificate
2343 embedded in a device to specify that other Object Identifiers (OIDs) are
2344 present which contains binary data specifying custom capabilities that
2345 the device is able to do.
2347 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
2348 containing the content block with both the signature,
2349 the signer's certificate, and any necessary intermediate
2351 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
2352 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
2353 required EKUs that must be present in the signature.
2354 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
2355 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
2356 must be present in the leaf signer. If it is
2357 FALSE, then we will succeed if we find any
2358 of the specified EKU's.
2360 @retval EFI_SUCCESS The required EKUs were found in the signature.
2361 @retval EFI_INVALID_PARAMETER A parameter was invalid.
2362 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
2367 VerifyEKUsInPkcs7Signature (
2368 IN CONST UINT8
*Pkcs7Signature
,
2369 IN CONST UINT32 SignatureSize
,
2370 IN CONST CHAR8
*RequiredEKUs
[],
2371 IN CONST UINT32 RequiredEKUsSize
,
2372 IN BOOLEAN RequireAllPresent
2376 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2377 data could be wrapped in a ContentInfo structure.
2379 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2380 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2382 Caution: This function may receive untrusted input. So this function will do
2383 basic check for PKCS#7 data structure.
2385 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2386 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2387 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2388 It's caller's responsibility to free the buffer with FreePool().
2389 @param[out] ContentSize The size of the extracted content in bytes.
2391 @retval TRUE The P7Data was correctly formatted for processing.
2392 @retval FALSE The P7Data was not correctly formatted for processing.
2397 Pkcs7GetAttachedContent (
2398 IN CONST UINT8
*P7Data
,
2401 OUT UINTN
*ContentSize
2405 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2406 Authenticode Portable Executable Signature Format".
2408 If AuthData is NULL, then return FALSE.
2409 If ImageHash is NULL, then return FALSE.
2410 If this interface is not supported, then return FALSE.
2412 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2413 PE/COFF image to be verified.
2414 @param[in] DataSize Size of the Authenticode Signature in bytes.
2415 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2416 is used for certificate chain verification.
2417 @param[in] CertSize Size of the trusted certificate in bytes.
2418 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2419 for calculating the image hash value is described in Authenticode
2421 @param[in] HashSize Size of Image hash value in bytes.
2423 @retval TRUE The specified Authenticode Signature is valid.
2424 @retval FALSE Invalid Authenticode Signature.
2425 @retval FALSE This interface is not supported.
2430 AuthenticodeVerify (
2431 IN CONST UINT8
*AuthData
,
2433 IN CONST UINT8
*TrustedCert
,
2435 IN CONST UINT8
*ImageHash
,
2440 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2443 If AuthData is NULL, then return FALSE.
2444 If this interface is not supported, then return FALSE.
2446 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2447 PE/COFF image to be verified.
2448 @param[in] DataSize Size of the Authenticode Signature in bytes.
2449 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2450 is used for TSA certificate chain verification.
2451 @param[in] CertSize Size of the trusted certificate in bytes.
2452 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2455 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2456 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2461 ImageTimestampVerify (
2462 IN CONST UINT8
*AuthData
,
2464 IN CONST UINT8
*TsaCert
,
2466 OUT EFI_TIME
*SigningTime
2469 // =====================================================================================
2470 // DH Key Exchange Primitive
2471 // =====================================================================================
2474 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
2476 @return Pointer to the Diffie-Hellman Context that has been initialized.
2477 If the allocations fails, DhNew() returns NULL.
2478 If the interface is not supported, DhNew() returns NULL.
2488 Release the specified DH context.
2490 If the interface is not supported, then ASSERT().
2492 @param[in] DhContext Pointer to the DH context to be released.
2502 Generates DH parameter.
2504 Given generator g, and length of prime number p in bits, this function generates p,
2505 and sets DH context according to value of g and p.
2507 Before this function can be invoked, pseudorandom number generator must be correctly
2508 initialized by RandomSeed().
2510 If DhContext is NULL, then return FALSE.
2511 If Prime is NULL, then return FALSE.
2512 If this interface is not supported, then return FALSE.
2514 @param[in, out] DhContext Pointer to the DH context.
2515 @param[in] Generator Value of generator.
2516 @param[in] PrimeLength Length in bits of prime to be generated.
2517 @param[out] Prime Pointer to the buffer to receive the generated prime number.
2519 @retval TRUE DH parameter generation succeeded.
2520 @retval FALSE Value of Generator is not supported.
2521 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
2522 @retval FALSE This interface is not supported.
2527 DhGenerateParameter (
2528 IN OUT VOID
*DhContext
,
2530 IN UINTN PrimeLength
,
2535 Sets generator and prime parameters for DH.
2537 Given generator g, and prime number p, this function and sets DH
2538 context accordingly.
2540 If DhContext is NULL, then return FALSE.
2541 If Prime is NULL, then return FALSE.
2542 If this interface is not supported, then return FALSE.
2544 @param[in, out] DhContext Pointer to the DH context.
2545 @param[in] Generator Value of generator.
2546 @param[in] PrimeLength Length in bits of prime to be generated.
2547 @param[in] Prime Pointer to the prime number.
2549 @retval TRUE DH parameter setting succeeded.
2550 @retval FALSE Value of Generator is not supported.
2551 @retval FALSE Value of Generator is not suitable for the Prime.
2552 @retval FALSE Value of Prime is not a prime number.
2553 @retval FALSE Value of Prime is not a safe prime number.
2554 @retval FALSE This interface is not supported.
2560 IN OUT VOID
*DhContext
,
2562 IN UINTN PrimeLength
,
2563 IN CONST UINT8
*Prime
2567 Generates DH public key.
2569 This function generates random secret exponent, and computes the public key, which is
2570 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
2571 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
2572 PublicKeySize is set to the required buffer size to obtain the public key.
2574 If DhContext is NULL, then return FALSE.
2575 If PublicKeySize is NULL, then return FALSE.
2576 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
2577 If this interface is not supported, then return FALSE.
2579 @param[in, out] DhContext Pointer to the DH context.
2580 @param[out] PublicKey Pointer to the buffer to receive generated public key.
2581 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
2582 On output, the size of data returned in PublicKey buffer in bytes.
2584 @retval TRUE DH public key generation succeeded.
2585 @retval FALSE DH public key generation failed.
2586 @retval FALSE PublicKeySize is not large enough.
2587 @retval FALSE This interface is not supported.
2593 IN OUT VOID
*DhContext
,
2594 OUT UINT8
*PublicKey
,
2595 IN OUT UINTN
*PublicKeySize
2599 Computes exchanged common key.
2601 Given peer's public key, this function computes the exchanged common key, based on its own
2602 context including value of prime modulus and random secret exponent.
2604 If DhContext is NULL, then return FALSE.
2605 If PeerPublicKey is NULL, then return FALSE.
2606 If KeySize is NULL, then return FALSE.
2607 If Key is NULL, then return FALSE.
2608 If KeySize is not large enough, then return FALSE.
2609 If this interface is not supported, then return FALSE.
2611 @param[in, out] DhContext Pointer to the DH context.
2612 @param[in] PeerPublicKey Pointer to the peer's public key.
2613 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
2614 @param[out] Key Pointer to the buffer to receive generated key.
2615 @param[in, out] KeySize On input, the size of Key buffer in bytes.
2616 On output, the size of data returned in Key buffer in bytes.
2618 @retval TRUE DH exchanged key generation succeeded.
2619 @retval FALSE DH exchanged key generation failed.
2620 @retval FALSE KeySize is not large enough.
2621 @retval FALSE This interface is not supported.
2627 IN OUT VOID
*DhContext
,
2628 IN CONST UINT8
*PeerPublicKey
,
2629 IN UINTN PeerPublicKeySize
,
2631 IN OUT UINTN
*KeySize
2634 // =====================================================================================
2635 // Pseudo-Random Generation Primitive
2636 // =====================================================================================
2639 Sets up the seed value for the pseudorandom number generator.
2641 This function sets up the seed value for the pseudorandom number generator.
2642 If Seed is not NULL, then the seed passed in is used.
2643 If Seed is NULL, then default seed is used.
2644 If this interface is not supported, then return FALSE.
2646 @param[in] Seed Pointer to seed value.
2647 If NULL, default seed is used.
2648 @param[in] SeedSize Size of seed value.
2649 If Seed is NULL, this parameter is ignored.
2651 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
2652 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
2653 @retval FALSE This interface is not supported.
2659 IN CONST UINT8
*Seed OPTIONAL
,
2664 Generates a pseudorandom byte stream of the specified size.
2666 If Output is NULL, then return FALSE.
2667 If this interface is not supported, then return FALSE.
2669 @param[out] Output Pointer to buffer to receive random value.
2670 @param[in] Size Size of random bytes to generate.
2672 @retval TRUE Pseudorandom byte stream generated successfully.
2673 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
2674 @retval FALSE This interface is not supported.
2684 // =====================================================================================
2685 // Key Derivation Function Primitive
2686 // =====================================================================================
2689 Derive key data using HMAC-SHA256 based KDF.
2691 @param[in] Key Pointer to the user-supplied key.
2692 @param[in] KeySize Key size in bytes.
2693 @param[in] Salt Pointer to the salt(non-secret) value.
2694 @param[in] SaltSize Salt size in bytes.
2695 @param[in] Info Pointer to the application specific info.
2696 @param[in] InfoSize Info size in bytes.
2697 @param[out] Out Pointer to buffer to receive hkdf value.
2698 @param[in] OutSize Size of hkdf bytes to generate.
2700 @retval TRUE Hkdf generated successfully.
2701 @retval FALSE Hkdf generation failed.
2706 HkdfSha256ExtractAndExpand (
2707 IN CONST UINT8
*Key
,
2709 IN CONST UINT8
*Salt
,
2711 IN CONST UINT8
*Info
,
2718 Derive SHA256 HMAC-based Extract key Derivation Function (HKDF).
2720 @param[in] Key Pointer to the user-supplied key.
2721 @param[in] KeySize key size in bytes.
2722 @param[in] Salt Pointer to the salt(non-secret) value.
2723 @param[in] SaltSize salt size in bytes.
2724 @param[out] PrkOut Pointer to buffer to receive hkdf value.
2725 @param[in] PrkOutSize size of hkdf bytes to generate.
2727 @retval true Hkdf generated successfully.
2728 @retval false Hkdf generation failed.
2734 IN CONST UINT8
*Key
,
2736 IN CONST UINT8
*Salt
,
2743 Derive SHA256 HMAC-based Expand Key Derivation Function (HKDF).
2745 @param[in] Prk Pointer to the user-supplied key.
2746 @param[in] PrkSize Key size in bytes.
2747 @param[in] Info Pointer to the application specific info.
2748 @param[in] InfoSize Info size in bytes.
2749 @param[out] Out Pointer to buffer to receive hkdf value.
2750 @param[in] OutSize Size of hkdf bytes to generate.
2752 @retval TRUE Hkdf generated successfully.
2753 @retval FALSE Hkdf generation failed.
2759 IN CONST UINT8
*Prk
,
2761 IN CONST UINT8
*Info
,
2768 Derive SHA384 HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
2770 @param[in] Key Pointer to the user-supplied key.
2771 @param[in] KeySize Key size in bytes.
2772 @param[in] Salt Pointer to the salt(non-secret) value.
2773 @param[in] SaltSize Salt size in bytes.
2774 @param[in] Info Pointer to the application specific info.
2775 @param[in] InfoSize Info size in bytes.
2776 @param[out] Out Pointer to buffer to receive hkdf value.
2777 @param[in] OutSize Size of hkdf bytes to generate.
2779 @retval TRUE Hkdf generated successfully.
2780 @retval FALSE Hkdf generation failed.
2785 HkdfSha384ExtractAndExpand (
2786 IN CONST UINT8
*Key
,
2788 IN CONST UINT8
*Salt
,
2790 IN CONST UINT8
*Info
,
2797 Derive SHA384 HMAC-based Extract key Derivation Function (HKDF).
2799 @param[in] Key Pointer to the user-supplied key.
2800 @param[in] KeySize key size in bytes.
2801 @param[in] Salt Pointer to the salt(non-secret) value.
2802 @param[in] SaltSize salt size in bytes.
2803 @param[out] PrkOut Pointer to buffer to receive hkdf value.
2804 @param[in] PrkOutSize size of hkdf bytes to generate.
2806 @retval true Hkdf generated successfully.
2807 @retval false Hkdf generation failed.
2813 IN CONST UINT8
*Key
,
2815 IN CONST UINT8
*Salt
,
2822 Derive SHA384 HMAC-based Expand Key Derivation Function (HKDF).
2824 @param[in] Prk Pointer to the user-supplied key.
2825 @param[in] PrkSize Key size in bytes.
2826 @param[in] Info Pointer to the application specific info.
2827 @param[in] InfoSize Info size in bytes.
2828 @param[out] Out Pointer to buffer to receive hkdf value.
2829 @param[in] OutSize Size of hkdf bytes to generate.
2831 @retval TRUE Hkdf generated successfully.
2832 @retval FALSE Hkdf generation failed.
2838 IN CONST UINT8
*Prk
,
2840 IN CONST UINT8
*Info
,
2846 // =====================================================================================
2847 // Big number primitives
2848 // =====================================================================================
2851 Allocate new Big Number.
2853 @retval New BigNum opaque structure or NULL on failure.
2862 Allocate new Big Number and assign the provided value to it.
2864 @param[in] Buf Big endian encoded buffer.
2865 @param[in] Len Buffer length.
2867 @retval New BigNum opaque structure or NULL on failure.
2872 IN CONST UINT8
*Buf
,
2877 Convert the absolute value of Bn into big-endian form and store it at Buf.
2878 The Buf array should have at least BigNumBytes() in it.
2880 @param[in] Bn Big number to convert.
2881 @param[out] Buf Output buffer.
2883 @retval The length of the big-endian number placed at Buf or -1 on error.
2893 Free the Big Number.
2895 @param[in] Bn Big number to free.
2896 @param[in] Clear TRUE if the buffer should be cleared.
2906 Calculate the sum of two Big Numbers.
2907 Please note, all "out" Big number arguments should be properly initialized
2908 by calling to BigNumInit() or BigNumFromBin() functions.
2910 @param[in] BnA Big number.
2911 @param[in] BnB Big number.
2912 @param[out] BnRes The result of BnA + BnB.
2914 @retval TRUE On success.
2915 @retval FALSE Otherwise.
2926 Subtract two Big Numbers.
2927 Please note, all "out" Big number arguments should be properly initialized
2928 by calling to BigNumInit() or BigNumFromBin() functions.
2930 @param[in] BnA Big number.
2931 @param[in] BnB Big number.
2932 @param[out] BnRes The result of BnA - BnB.
2934 @retval TRUE On success.
2935 @retval FALSE Otherwise.
2946 Calculate remainder: BnRes = BnA % BnB.
2947 Please note, all "out" Big number arguments should be properly initialized
2948 by calling to BigNumInit() or BigNumFromBin() functions.
2950 @param[in] BnA Big number.
2951 @param[in] BnB Big number.
2952 @param[out] BnRes The result of BnA % BnB.
2954 @retval TRUE On success.
2955 @retval FALSE Otherwise.
2966 Compute BnA to the BnP-th power modulo BnM.
2967 Please note, all "out" Big number arguments should be properly initialized
2968 by calling to BigNumInit() or BigNumFromBin() functions.
2970 @param[in] BnA Big number.
2971 @param[in] BnP Big number (power).
2972 @param[in] BnM Big number (modulo).
2973 @param[out] BnRes The result of (BnA ^ BnP) % BnM.
2975 @retval TRUE On success.
2976 @retval FALSE Otherwise.
2988 Compute BnA inverse modulo BnM.
2989 Please note, all "out" Big number arguments should be properly initialized
2990 by calling to BigNumInit() or BigNumFromBin() functions.
2992 @param[in] BnA Big number.
2993 @param[in] BnM Big number (modulo).
2994 @param[out] BnRes The result, such that (BnA * BnRes) % BnM == 1.
2996 @retval TRUE On success.
2997 @retval FALSE Otherwise.
3008 Divide two Big Numbers.
3009 Please note, all "out" Big number arguments should be properly initialized
3010 by calling to BigNumInit() or BigNumFromBin() functions.
3012 @param[in] BnA Big number.
3013 @param[in] BnB Big number.
3014 @param[out] BnRes The result, such that BnA / BnB.
3016 @retval TRUE On success.
3017 @retval FALSE Otherwise.
3028 Multiply two Big Numbers modulo BnM.
3029 Please note, all "out" Big number arguments should be properly initialized
3030 by calling to BigNumInit() or BigNumFromBin() functions.
3032 @param[in] BnA Big number.
3033 @param[in] BnB Big number.
3034 @param[in] BnM Big number (modulo).
3035 @param[out] BnRes The result, such that (BnA * BnB) % BnM.
3037 @retval TRUE On success.
3038 @retval FALSE Otherwise.
3050 Compare two Big Numbers.
3052 @param[in] BnA Big number.
3053 @param[in] BnB Big number.
3055 @retval 0 BnA == BnB.
3056 @retval 1 BnA > BnB.
3057 @retval -1 BnA < BnB.
3067 Get number of bits in Bn.
3069 @param[in] Bn Big number.
3071 @retval Number of bits.
3081 Get number of bytes in Bn.
3083 @param[in] Bn Big number.
3085 @retval Number of bytes.
3094 Checks if Big Number equals to the given Num.
3096 @param[in] Bn Big number.
3097 @param[in] Num Number.
3099 @retval TRUE iff Bn == Num.
3100 @retval FALSE otherwise.
3110 Checks if Big Number is odd.
3112 @param[in] Bn Big number.
3114 @retval TRUE Bn is odd (Bn % 2 == 1).
3115 @retval FALSE otherwise.
3126 @param[out] BnDst Destination.
3127 @param[in] BnSrc Source.
3129 @retval BnDst on success.
3130 @retval NULL otherwise.
3136 IN CONST VOID
*BnSrc
3140 Get constant Big number with value of "1".
3141 This may be used to save expensive allocations.
3143 @retval Big Number with value of 1.
3152 Shift right Big Number.
3153 Please note, all "out" Big number arguments should be properly initialized
3154 by calling to BigNumInit() or BigNumFromBin() functions.
3156 @param[in] Bn Big number.
3157 @param[in] N Number of bits to shift.
3158 @param[out] BnRes The result.
3160 @retval TRUE On success.
3161 @retval FALSE Otherwise.
3172 Mark Big Number for constant time computations.
3173 This function should be called before any constant time computations are
3174 performed on the given Big number.
3176 @param[in] Bn Big number.
3185 Calculate square modulo.
3186 Please note, all "out" Big number arguments should be properly initialized
3187 by calling to BigNumInit() or BigNumFromBin() functions.
3189 @param[in] BnA Big number.
3190 @param[in] BnM Big number (modulo).
3191 @param[out] BnRes The result, such that (BnA ^ 2) % BnM.
3193 @retval TRUE On success.
3194 @retval FALSE Otherwise.
3205 Create new Big Number computation context. This is an opaque structure
3206 which should be passed to any function that requires it. The BN context is
3207 needed to optimize calculations and expensive allocations.
3209 @retval Big Number context struct or NULL on failure.
3218 Free Big Number context that was allocated with BigNumNewContext().
3220 @param[in] BnCtx Big number context to free.
3229 Set Big Number to a given value.
3231 @param[in] Bn Big number to set.
3232 @param[in] Val Value to set.
3234 @retval TRUE On success.
3235 @retval FALSE Otherwise.
3245 Add two Big Numbers modulo BnM.
3247 @param[in] BnA Big number.
3248 @param[in] BnB Big number.
3249 @param[in] BnM Big number (modulo).
3250 @param[out] BnRes The result, such that (BnA + BnB) % BnM.
3252 @retval TRUE On success.
3253 @retval FALSE Otherwise.
3264 // =====================================================================================
3265 // Basic Elliptic Curve Primitives
3266 // =====================================================================================
3269 Initialize new opaque EcGroup object. This object represents an EC curve and
3270 and is used for calculation within this group. This object should be freed
3271 using EcGroupFree() function.
3273 @param[in] CryptoNid Identifying number for the ECC curve (Defined in
3276 @retval EcGroup object On success.
3277 @retval NULL On failure.
3286 Get EC curve parameters. While elliptic curve equation is Y^2 mod P = (X^3 + AX + B) Mod P.
3287 This function will set the provided Big Number objects to the corresponding
3288 values. The caller needs to make sure all the "out" BigNumber parameters
3289 are properly initialized.
3291 @param[in] EcGroup EC group object.
3292 @param[out] BnPrime Group prime number.
3293 @param[out] BnA A coefficient.
3294 @param[out] BnB B coefficient.
3295 @param[in] BnCtx BN context.
3297 @retval TRUE On success.
3298 @retval FALSE Otherwise.
3303 IN CONST VOID
*EcGroup
,
3312 This function will set the provided Big Number object to the corresponding
3313 value. The caller needs to make sure that the "out" BigNumber parameter
3314 is properly initialized.
3316 @param[in] EcGroup EC group object.
3317 @param[out] BnOrder Group prime number.
3319 @retval TRUE On success.
3320 @retval FALSE Otherwise.
3330 Free previously allocated EC group object using EcGroupInit().
3332 @param[in] EcGroup EC group object to free.
3341 Initialize new opaque EC Point object. This object represents an EC point
3342 within the given EC group (curve).
3344 @param[in] EC Group, properly initialized using EcGroupInit().
3346 @retval EC Point object On success.
3347 @retval NULL On failure.
3352 IN CONST VOID
*EcGroup
3356 Free previously allocated EC Point object using EcPointInit().
3358 @param[in] EcPoint EC Point to free.
3359 @param[in] Clear TRUE iff the memory should be cleared.
3369 Get EC point affine (x,y) coordinates.
3370 This function will set the provided Big Number objects to the corresponding
3371 values. The caller needs to make sure all the "out" BigNumber parameters
3372 are properly initialized.
3374 @param[in] EcGroup EC group object.
3375 @param[in] EcPoint EC point object.
3376 @param[out] BnX X coordinate.
3377 @param[out] BnY Y coordinate.
3378 @param[in] BnCtx BN context, created with BigNumNewContext().
3380 @retval TRUE On success.
3381 @retval FALSE Otherwise.
3385 EcPointGetAffineCoordinates (
3386 IN CONST VOID
*EcGroup
,
3387 IN CONST VOID
*EcPoint
,
3394 Set EC point affine (x,y) coordinates.
3396 @param[in] EcGroup EC group object.
3397 @param[in] EcPoint EC point object.
3398 @param[in] BnX X coordinate.
3399 @param[in] BnY Y coordinate.
3400 @param[in] BnCtx BN context, created with BigNumNewContext().
3402 @retval TRUE On success.
3403 @retval FALSE Otherwise.
3407 EcPointSetAffineCoordinates (
3408 IN CONST VOID
*EcGroup
,
3416 EC Point addition. EcPointResult = EcPointA + EcPointB.
3418 @param[in] EcGroup EC group object.
3419 @param[out] EcPointResult EC point to hold the result. The point should
3420 be properly initialized.
3421 @param[in] EcPointA EC Point.
3422 @param[in] EcPointB EC Point.
3423 @param[in] BnCtx BN context, created with BigNumNewContext().
3425 @retval TRUE On success.
3426 @retval FALSE Otherwise.
3431 IN CONST VOID
*EcGroup
,
3432 OUT VOID
*EcPointResult
,
3433 IN CONST VOID
*EcPointA
,
3434 IN CONST VOID
*EcPointB
,
3439 Variable EC point multiplication. EcPointResult = EcPoint * BnPScalar.
3441 @param[in] EcGroup EC group object.
3442 @param[out] EcPointResult EC point to hold the result. The point should
3443 be properly initialized.
3444 @param[in] EcPoint EC Point.
3445 @param[in] BnPScalar P Scalar.
3446 @param[in] BnCtx BN context, created with BigNumNewContext().
3448 @retval TRUE On success.
3449 @retval FALSE Otherwise.
3454 IN CONST VOID
*EcGroup
,
3455 OUT VOID
*EcPointResult
,
3456 IN CONST VOID
*EcPoint
,
3457 IN CONST VOID
*BnPScalar
,
3462 Calculate the inverse of the supplied EC point.
3464 @param[in] EcGroup EC group object.
3465 @param[in,out] EcPoint EC point to invert.
3466 @param[in] BnCtx BN context, created with BigNumNewContext().
3468 @retval TRUE On success.
3469 @retval FALSE Otherwise.
3474 IN CONST VOID
*EcGroup
,
3475 IN OUT VOID
*EcPoint
,
3480 Check if the supplied point is on EC curve.
3482 @param[in] EcGroup EC group object.
3483 @param[in] EcPoint EC point to check.
3484 @param[in] BnCtx BN context, created with BigNumNewContext().
3486 @retval TRUE On curve.
3487 @retval FALSE Otherwise.
3492 IN CONST VOID
*EcGroup
,
3493 IN CONST VOID
*EcPoint
,
3498 Check if the supplied point is at infinity.
3500 @param[in] EcGroup EC group object.
3501 @param[in] EcPoint EC point to check.
3503 @retval TRUE At infinity.
3504 @retval FALSE Otherwise.
3508 EcPointIsAtInfinity (
3509 IN CONST VOID
*EcGroup
,
3510 IN CONST VOID
*EcPoint
3514 Check if EC points are equal.
3516 @param[in] EcGroup EC group object.
3517 @param[in] EcPointA EC point A.
3518 @param[in] EcPointB EC point B.
3519 @param[in] BnCtx BN context, created with BigNumNewContext().
3521 @retval TRUE A == B.
3522 @retval FALSE Otherwise.
3527 IN CONST VOID
*EcGroup
,
3528 IN CONST VOID
*EcPointA
,
3529 IN CONST VOID
*EcPointB
,
3534 Set EC point compressed coordinates. Points can be described in terms of
3535 their compressed coordinates. For a point (x, y), for any given value for x
3536 such that the point is on the curve there will only ever be two possible
3537 values for y. Therefore, a point can be set using this function where BnX is
3538 the x coordinate and YBit is a value 0 or 1 to identify which of the two
3539 possible values for y should be used.
3541 @param[in] EcGroup EC group object.
3542 @param[in] EcPoint EC Point.
3543 @param[in] BnX X coordinate.
3544 @param[in] YBit 0 or 1 to identify which Y value is used.
3545 @param[in] BnCtx BN context, created with BigNumNewContext().
3547 @retval TRUE On success.
3548 @retval FALSE Otherwise.
3552 EcPointSetCompressedCoordinates (
3553 IN CONST VOID
*EcGroup
,
3560 // =====================================================================================
3561 // Elliptic Curve Diffie Hellman Primitives
3562 // =====================================================================================
3565 Allocates and Initializes one Elliptic Curve Context for subsequent use
3568 @param[in] Nid cipher NID
3569 @return Pointer to the Elliptic Curve Context that has been initialized.
3570 If the allocations fails, EcNewByNid() returns NULL.
3579 Release the specified EC context.
3581 @param[in] EcContext Pointer to the EC context to be released.
3590 Generates EC key and returns EC public key (X, Y), Please note, this function uses
3591 pseudo random number generator. The caller must make sure RandomSeed()
3592 function was properly called before.
3593 The Ec context should be correctly initialized by EcNewByNid.
3594 This function generates random secret, and computes the public key (X, Y), which is
3595 returned via parameter Public, PublicSize.
3596 X is the first half of Public with size being PublicSize / 2,
3597 Y is the second half of Public with size being PublicSize / 2.
3598 EC context is updated accordingly.
3599 If the Public buffer is too small to hold the public X, Y, FALSE is returned and
3600 PublicSize is set to the required buffer size to obtain the public X, Y.
3601 For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.
3602 For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.
3603 For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.
3604 If EcContext is NULL, then return FALSE.
3605 If PublicSize is NULL, then return FALSE.
3606 If PublicSize is large enough but Public is NULL, then return FALSE.
3607 @param[in, out] EcContext Pointer to the EC context.
3608 @param[out] PublicKey Pointer to t buffer to receive generated public X,Y.
3609 @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.
3610 On output, the size of data returned in Public buffer in bytes.
3611 @retval TRUE EC public X,Y generation succeeded.
3612 @retval FALSE EC public X,Y generation failed.
3613 @retval FALSE PublicKeySize is not large enough.
3618 IN OUT VOID
*EcContext
,
3619 OUT UINT8
*PublicKey
,
3620 IN OUT UINTN
*PublicKeySize
3624 Gets the public key component from the established EC context.
3625 The Ec context should be correctly initialized by EcNewByNid, and successfully
3626 generate key pair from EcGenerateKey().
3627 For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.
3628 For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.
3629 For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.
3630 @param[in, out] EcContext Pointer to EC context being set.
3631 @param[out] PublicKey Pointer to t buffer to receive generated public X,Y.
3632 @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.
3633 On output, the size of data returned in Public buffer in bytes.
3634 @retval TRUE EC key component was retrieved successfully.
3635 @retval FALSE Invalid EC key component.
3640 IN OUT VOID
*EcContext
,
3641 OUT UINT8
*PublicKey
,
3642 IN OUT UINTN
*PublicKeySize
3646 Computes exchanged common key.
3647 Given peer's public key (X, Y), this function computes the exchanged common key,
3648 based on its own context including value of curve parameter and random secret.
3649 X is the first half of PeerPublic with size being PeerPublicSize / 2,
3650 Y is the second half of PeerPublic with size being PeerPublicSize / 2.
3651 If EcContext is NULL, then return FALSE.
3652 If PeerPublic is NULL, then return FALSE.
3653 If PeerPublicSize is 0, then return FALSE.
3654 If Key is NULL, then return FALSE.
3655 If KeySize is not large enough, then return FALSE.
3656 For P-256, the PeerPublicSize is 64. First 32-byte is X, Second 32-byte is Y.
3657 For P-384, the PeerPublicSize is 96. First 48-byte is X, Second 48-byte is Y.
3658 For P-521, the PeerPublicSize is 132. First 66-byte is X, Second 66-byte is Y.
3659 @param[in, out] EcContext Pointer to the EC context.
3660 @param[in] PeerPublic Pointer to the peer's public X,Y.
3661 @param[in] PeerPublicSize Size of peer's public X,Y in bytes.
3662 @param[in] CompressFlag Flag of PeerPublic is compressed or not.
3663 @param[out] Key Pointer to the buffer to receive generated key.
3664 @param[in, out] KeySize On input, the size of Key buffer in bytes.
3665 On output, the size of data returned in Key buffer in bytes.
3666 @retval TRUE EC exchanged key generation succeeded.
3667 @retval FALSE EC exchanged key generation failed.
3668 @retval FALSE KeySize is not large enough.
3673 IN OUT VOID
*EcContext
,
3674 IN CONST UINT8
*PeerPublic
,
3675 IN UINTN PeerPublicSize
,
3676 IN CONST INT32
*CompressFlag
,
3678 IN OUT UINTN
*KeySize
3681 #endif // __BASE_CRYPT_LIB_H__