2 Implements the EDK II Crypto Protocol/PPI services using the library services
3 from BaseCryptLib and TlsLib.
5 Copyright (C) Microsoft Corporation. All rights reserved.
6 Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/DebugLib.h>
12 #include <Library/BaseCryptLib.h>
13 #include <Library/TlsLib.h>
14 #include <Protocol/Crypto.h>
15 #include <Pcd/PcdCryptoServiceFamilyEnable.h>
18 A macro used to retrieve the FixedAtBuild PcdCryptoServiceFamilyEnable with a
19 typecast to its associcted structure type PCD_CRYPTO_SERVICE_FAMILY_ENABLE.
21 #define EDKII_CRYPTO_PCD ((const PCD_CRYPTO_SERVICE_FAMILY_ENABLE *) \
22 (FixedPcdGetPtr (PcdCryptoServiceFamilyEnable)))
25 A macro used to call a non-void BaseCryptLib function if it is enabled.
27 If a BaseCryptLib function is not enabled, there will be no references to it
28 from this module and will be optimized away reducing the size of this module.
30 @param Enable The name of the enable field in PCD
31 PcdCryptoServiceFamilyEnable for the BaseCryptLib
32 function being called. If the value of this field
33 is non-zero, then the BaseCryptLib function is
35 @param Function The name of the BaseCryptLib function.
36 @param Args The argument list to pass to Function.
37 @param ErrorReturnValue The value to return if the BaseCryptLib function is
41 #define CALL_BASECRYPTLIB(Enable, Function, Args, ErrorReturnValue) \
42 EDKII_CRYPTO_PCD->Enable \
44 : (BaseCryptLibServiceNotEnabled (#Function), ErrorReturnValue)
47 A macro used to call a void BaseCryptLib function if it is enabled.
49 If a BaseCryptLib function is not enabled, there will be no references to it
50 from this module and will be optimized away reducing the size of this module.
52 @param Enable The name of the enable field in PCD
53 PcdCryptoServiceFamilyEnable for the BaseCryptLib
54 function being called. If the value of this field
55 is non-zero, then the BaseCryptLib function is
57 @param Function The name of the BaseCryptLib function.
58 @param Args The argument list to pass to Function.
61 #define CALL_VOID_BASECRYPTLIB(Enable, Function, Args) \
62 EDKII_CRYPTO_PCD->Enable \
64 : BaseCryptLibServiceNotEnabled (#Function)
67 Internal worker function that prints a debug message and asserts if a call is
68 made to a BaseCryptLib function that is not enabled in the EDK II Crypto
71 If this debug message and assert are observed, then a module is using
72 BaseCryptLib function that is not enabled in a Crypto driver. The
73 PcdCryptoServiceFamilyEnable should be updated to enable the missing service.
75 @param[in] FunctionName Null-terminated ASCII string that is the name of an
76 EDK II Crypto service.
81 BaseCryptLibServiceNotEnabled (
82 IN CONST CHAR8
*FunctionName
85 DEBUG ((DEBUG_ERROR
, "[%a] Function %a() is not enabled\n", gEfiCallerBaseName
, FunctionName
));
86 ASSERT_EFI_ERROR (EFI_UNSUPPORTED
);
90 Internal worker function that prints a debug message and asserts if a call is
91 made to a BaseCryptLib function that is deprecated and unsupported any longer.
93 @param[in] FunctionName Null-terminated ASCII string that is the name of an
94 EDK II Crypto service.
99 BaseCryptLibServiceDeprecated (
100 IN CONST CHAR8
*FunctionName
103 DEBUG ((DEBUG_ERROR
, "[%a] Function %a() is deprecated and unsupported any longer\n", gEfiCallerBaseName
, FunctionName
));
104 ASSERT_EFI_ERROR (EFI_UNSUPPORTED
);
108 Returns the version of the EDK II Crypto Protocol.
110 @return The version of the EDK II Crypto Protocol.
115 CryptoServiceGetCryptoVersion (
119 return EDKII_CRYPTO_VERSION
;
122 //=====================================================================================
123 // One-Way Cryptographic Hash Primitives
124 //=====================================================================================
127 MD4 is deprecated and unsupported any longer.
128 Keep the function field for binary compability.
130 @retval 0 This interface is not supported.
135 DeprecatedCryptoServiceMd4GetContextSize (
139 return BaseCryptLibServiceDeprecated ("Md4GetContextSize"), 0;
143 MD4 is deprecated and unsupported any longer.
144 Keep the function field for binary compability.
146 @param[out] Md4Context Pointer to MD4 context being initialized.
148 @retval FALSE This interface is not supported.
153 DeprecatedCryptoServiceMd4Init (
157 return BaseCryptLibServiceDeprecated ("Md4Init"), FALSE
;
161 MD4 is deprecated and unsupported any longer.
162 Keep the function field for binary compability.
164 @param[in] Md4Context Pointer to MD4 context being copied.
165 @param[out] NewMd4Context Pointer to new MD4 context.
167 @retval FALSE This interface is not supported.
172 DeprecatedCryptoServiceMd4Duplicate (
173 IN CONST VOID
*Md4Context
,
174 OUT VOID
*NewMd4Context
177 return BaseCryptLibServiceDeprecated ("Md4Duplicate"), FALSE
;
181 MD4 is deprecated and unsupported any longer.
182 Keep the function field for binary compability.
184 @param[in, out] Md4Context Pointer to the MD4 context.
185 @param[in] Data Pointer to the buffer containing the data to be hashed.
186 @param[in] DataSize Size of Data buffer in bytes.
188 @retval FALSE This interface is not supported.
193 DeprecatedCryptoServiceMd4Update (
194 IN OUT VOID
*Md4Context
,
199 return BaseCryptLibServiceDeprecated ("Md4Update"), FALSE
;
203 MD4 is deprecated and unsupported any longer.
204 Keep the function field for binary compability.
206 @param[in, out] Md4Context Pointer to the MD4 context.
207 @param[out] HashValue Pointer to a buffer that receives the MD4 digest
210 @retval FALSE This interface is not supported.
215 DeprecatedCryptoServiceMd4Final (
216 IN OUT VOID
*Md4Context
,
220 return BaseCryptLibServiceDeprecated ("Md4Final"), FALSE
;
224 MD4 is deprecated and unsupported any longer.
225 Keep the function field for binary compability.
227 @param[in] Data Pointer to the buffer containing the data to be hashed.
228 @param[in] DataSize Size of Data buffer in bytes.
229 @param[out] HashValue Pointer to a buffer that receives the MD4 digest
232 @retval FALSE This interface is not supported.
237 DeprecatedCryptoServiceMd4HashAll (
243 return BaseCryptLibServiceDeprecated ("Md4HashAll"), FALSE
;
247 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.
249 If this interface is not supported, then return zero.
251 @return The size, in bytes, of the context buffer required for MD5 hash operations.
252 @retval 0 This interface is not supported.
257 CryptoServiceMd5GetContextSize (
261 return CALL_BASECRYPTLIB (Md5
.Services
.GetContextSize
, Md5GetContextSize
, (), 0);
265 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for
268 If Md5Context is NULL, then return FALSE.
269 If this interface is not supported, then return FALSE.
271 @param[out] Md5Context Pointer to MD5 context being initialized.
273 @retval TRUE MD5 context initialization succeeded.
274 @retval FALSE MD5 context initialization failed.
275 @retval FALSE This interface is not supported.
280 CryptoServiceMd5Init (
284 return CALL_BASECRYPTLIB (Md5
.Services
.Init
, Md5Init
, (Md5Context
), FALSE
);
288 Makes a copy of an existing MD5 context.
290 If Md5Context is NULL, then return FALSE.
291 If NewMd5Context is NULL, then return FALSE.
292 If this interface is not supported, then return FALSE.
294 @param[in] Md5Context Pointer to MD5 context being copied.
295 @param[out] NewMd5Context Pointer to new MD5 context.
297 @retval TRUE MD5 context copy succeeded.
298 @retval FALSE MD5 context copy failed.
299 @retval FALSE This interface is not supported.
304 CryptoServiceMd5Duplicate (
305 IN CONST VOID
*Md5Context
,
306 OUT VOID
*NewMd5Context
309 return CALL_BASECRYPTLIB (Md5
.Services
.Duplicate
, Md5Duplicate
, (Md5Context
, NewMd5Context
), FALSE
);
313 Digests the input data and updates MD5 context.
315 This function performs MD5 digest on a data buffer of the specified size.
316 It can be called multiple times to compute the digest of long or discontinuous data streams.
317 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized
318 by Md5Final(). Behavior with invalid context is undefined.
320 If Md5Context is NULL, then return FALSE.
321 If this interface is not supported, then return FALSE.
323 @param[in, out] Md5Context Pointer to the MD5 context.
324 @param[in] Data Pointer to the buffer containing the data to be hashed.
325 @param[in] DataSize Size of Data buffer in bytes.
327 @retval TRUE MD5 data digest succeeded.
328 @retval FALSE MD5 data digest failed.
329 @retval FALSE This interface is not supported.
334 CryptoServiceMd5Update (
335 IN OUT VOID
*Md5Context
,
340 return CALL_BASECRYPTLIB (Md5
.Services
.Update
, Md5Update
, (Md5Context
, Data
, DataSize
), FALSE
);
344 Completes computation of the MD5 digest value.
346 This function completes MD5 hash computation and retrieves the digest value into
347 the specified memory. After this function has been called, the MD5 context cannot
349 MD5 context should be already correctly initialized by Md5Init(), and should not be
350 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.
352 If Md5Context is NULL, then return FALSE.
353 If HashValue is NULL, then return FALSE.
354 If this interface is not supported, then return FALSE.
356 @param[in, out] Md5Context Pointer to the MD5 context.
357 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
360 @retval TRUE MD5 digest computation succeeded.
361 @retval FALSE MD5 digest computation failed.
362 @retval FALSE This interface is not supported.
367 CryptoServiceMd5Final (
368 IN OUT VOID
*Md5Context
,
372 return CALL_BASECRYPTLIB (Md5
.Services
.Final
, Md5Final
, (Md5Context
, HashValue
), FALSE
);
376 Computes the MD5 message digest of a input data buffer.
378 This function performs the MD5 message digest of a given data buffer, and places
379 the digest value into the specified memory.
381 If this interface is not supported, then return FALSE.
383 @param[in] Data Pointer to the buffer containing the data to be hashed.
384 @param[in] DataSize Size of Data buffer in bytes.
385 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
388 @retval TRUE MD5 digest computation succeeded.
389 @retval FALSE MD5 digest computation failed.
390 @retval FALSE This interface is not supported.
395 CryptoServiceMd5HashAll (
401 return CALL_BASECRYPTLIB (Md5
.Services
.HashAll
, Md5HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
405 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.
407 If this interface is not supported, then return zero.
409 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.
410 @retval 0 This interface is not supported.
415 CryptoServiceSha1GetContextSize (
419 return CALL_BASECRYPTLIB (Sha1
.Services
.GetContextSize
, Sha1GetContextSize
, (), 0);
423 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for
426 If Sha1Context is NULL, then return FALSE.
427 If this interface is not supported, then return FALSE.
429 @param[out] Sha1Context Pointer to SHA-1 context being initialized.
431 @retval TRUE SHA-1 context initialization succeeded.
432 @retval FALSE SHA-1 context initialization failed.
433 @retval FALSE This interface is not supported.
438 CryptoServiceSha1Init (
439 OUT VOID
*Sha1Context
442 return CALL_BASECRYPTLIB (Sha1
.Services
.Init
, Sha1Init
, (Sha1Context
), FALSE
);
446 Makes a copy of an existing SHA-1 context.
448 If Sha1Context is NULL, then return FALSE.
449 If NewSha1Context is NULL, then return FALSE.
450 If this interface is not supported, then return FALSE.
452 @param[in] Sha1Context Pointer to SHA-1 context being copied.
453 @param[out] NewSha1Context Pointer to new SHA-1 context.
455 @retval TRUE SHA-1 context copy succeeded.
456 @retval FALSE SHA-1 context copy failed.
457 @retval FALSE This interface is not supported.
462 CryptoServiceSha1Duplicate (
463 IN CONST VOID
*Sha1Context
,
464 OUT VOID
*NewSha1Context
467 return CALL_BASECRYPTLIB (Sha1
.Services
.Duplicate
, Sha1Duplicate
, (Sha1Context
, NewSha1Context
), FALSE
);
471 Digests the input data and updates SHA-1 context.
473 This function performs SHA-1 digest on a data buffer of the specified size.
474 It can be called multiple times to compute the digest of long or discontinuous data streams.
475 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized
476 by Sha1Final(). Behavior with invalid context is undefined.
478 If Sha1Context is NULL, then return FALSE.
479 If this interface is not supported, then return FALSE.
481 @param[in, out] Sha1Context Pointer to the SHA-1 context.
482 @param[in] Data Pointer to the buffer containing the data to be hashed.
483 @param[in] DataSize Size of Data buffer in bytes.
485 @retval TRUE SHA-1 data digest succeeded.
486 @retval FALSE SHA-1 data digest failed.
487 @retval FALSE This interface is not supported.
492 CryptoServiceSha1Update (
493 IN OUT VOID
*Sha1Context
,
498 return CALL_BASECRYPTLIB (Sha1
.Services
.Update
, Sha1Update
, (Sha1Context
, Data
, DataSize
), FALSE
);
502 Completes computation of the SHA-1 digest value.
504 This function completes SHA-1 hash computation and retrieves the digest value into
505 the specified memory. After this function has been called, the SHA-1 context cannot
507 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be
508 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.
510 If Sha1Context is NULL, then return FALSE.
511 If HashValue is NULL, then return FALSE.
512 If this interface is not supported, then return FALSE.
514 @param[in, out] Sha1Context Pointer to the SHA-1 context.
515 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
518 @retval TRUE SHA-1 digest computation succeeded.
519 @retval FALSE SHA-1 digest computation failed.
520 @retval FALSE This interface is not supported.
525 CryptoServiceSha1Final (
526 IN OUT VOID
*Sha1Context
,
530 return CALL_BASECRYPTLIB (Sha1
.Services
.Final
, Sha1Final
, (Sha1Context
, HashValue
), FALSE
);
534 Computes the SHA-1 message digest of a input data buffer.
536 This function performs the SHA-1 message digest of a given data buffer, and places
537 the digest value into the specified memory.
539 If this interface is not supported, then return FALSE.
541 @param[in] Data Pointer to the buffer containing the data to be hashed.
542 @param[in] DataSize Size of Data buffer in bytes.
543 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
546 @retval TRUE SHA-1 digest computation succeeded.
547 @retval FALSE SHA-1 digest computation failed.
548 @retval FALSE This interface is not supported.
553 CryptoServiceSha1HashAll (
559 return CALL_BASECRYPTLIB (Sha1
.Services
.HashAll
, Sha1HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
563 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.
565 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.
570 CryptoServiceSha256GetContextSize (
574 return CALL_BASECRYPTLIB (Sha256
.Services
.GetContextSize
, Sha256GetContextSize
, (), 0);
578 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for
581 If Sha256Context is NULL, then return FALSE.
583 @param[out] Sha256Context Pointer to SHA-256 context being initialized.
585 @retval TRUE SHA-256 context initialization succeeded.
586 @retval FALSE SHA-256 context initialization failed.
591 CryptoServiceSha256Init (
592 OUT VOID
*Sha256Context
595 return CALL_BASECRYPTLIB (Sha256
.Services
.Init
, Sha256Init
, (Sha256Context
), FALSE
);
599 Makes a copy of an existing SHA-256 context.
601 If Sha256Context is NULL, then return FALSE.
602 If NewSha256Context is NULL, then return FALSE.
603 If this interface is not supported, then return FALSE.
605 @param[in] Sha256Context Pointer to SHA-256 context being copied.
606 @param[out] NewSha256Context Pointer to new SHA-256 context.
608 @retval TRUE SHA-256 context copy succeeded.
609 @retval FALSE SHA-256 context copy failed.
610 @retval FALSE This interface is not supported.
615 CryptoServiceSha256Duplicate (
616 IN CONST VOID
*Sha256Context
,
617 OUT VOID
*NewSha256Context
620 return CALL_BASECRYPTLIB (Sha256
.Services
.Duplicate
, Sha256Duplicate
, (Sha256Context
, NewSha256Context
), FALSE
);
624 Digests the input data and updates SHA-256 context.
626 This function performs SHA-256 digest on a data buffer of the specified size.
627 It can be called multiple times to compute the digest of long or discontinuous data streams.
628 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized
629 by Sha256Final(). Behavior with invalid context is undefined.
631 If Sha256Context is NULL, then return FALSE.
633 @param[in, out] Sha256Context Pointer to the SHA-256 context.
634 @param[in] Data Pointer to the buffer containing the data to be hashed.
635 @param[in] DataSize Size of Data buffer in bytes.
637 @retval TRUE SHA-256 data digest succeeded.
638 @retval FALSE SHA-256 data digest failed.
643 CryptoServiceSha256Update (
644 IN OUT VOID
*Sha256Context
,
649 return CALL_BASECRYPTLIB (Sha256
.Services
.Update
, Sha256Update
, (Sha256Context
, Data
, DataSize
), FALSE
);
653 Completes computation of the SHA-256 digest value.
655 This function completes SHA-256 hash computation and retrieves the digest value into
656 the specified memory. After this function has been called, the SHA-256 context cannot
658 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be
659 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.
661 If Sha256Context is NULL, then return FALSE.
662 If HashValue is NULL, then return FALSE.
664 @param[in, out] Sha256Context Pointer to the SHA-256 context.
665 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
668 @retval TRUE SHA-256 digest computation succeeded.
669 @retval FALSE SHA-256 digest computation failed.
674 CryptoServiceSha256Final (
675 IN OUT VOID
*Sha256Context
,
679 return CALL_BASECRYPTLIB (Sha256
.Services
.Final
, Sha256Final
, (Sha256Context
, HashValue
), FALSE
);
683 Computes the SHA-256 message digest of a input data buffer.
685 This function performs the SHA-256 message digest of a given data buffer, and places
686 the digest value into the specified memory.
688 If this interface is not supported, then return FALSE.
690 @param[in] Data Pointer to the buffer containing the data to be hashed.
691 @param[in] DataSize Size of Data buffer in bytes.
692 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
695 @retval TRUE SHA-256 digest computation succeeded.
696 @retval FALSE SHA-256 digest computation failed.
697 @retval FALSE This interface is not supported.
702 CryptoServiceSha256HashAll (
708 return CALL_BASECRYPTLIB (Sha256
.Services
.HashAll
, Sha256HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
712 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.
714 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.
719 CryptoServiceSha384GetContextSize (
723 return CALL_BASECRYPTLIB (Sha384
.Services
.GetContextSize
, Sha384GetContextSize
, (), 0);
727 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for
730 If Sha384Context is NULL, then return FALSE.
732 @param[out] Sha384Context Pointer to SHA-384 context being initialized.
734 @retval TRUE SHA-384 context initialization succeeded.
735 @retval FALSE SHA-384 context initialization failed.
740 CryptoServiceSha384Init (
741 OUT VOID
*Sha384Context
744 return CALL_BASECRYPTLIB (Sha384
.Services
.Init
, Sha384Init
, (Sha384Context
), FALSE
);
748 Makes a copy of an existing SHA-384 context.
750 If Sha384Context is NULL, then return FALSE.
751 If NewSha384Context is NULL, then return FALSE.
752 If this interface is not supported, then return FALSE.
754 @param[in] Sha384Context Pointer to SHA-384 context being copied.
755 @param[out] NewSha384Context Pointer to new SHA-384 context.
757 @retval TRUE SHA-384 context copy succeeded.
758 @retval FALSE SHA-384 context copy failed.
759 @retval FALSE This interface is not supported.
764 CryptoServiceSha384Duplicate (
765 IN CONST VOID
*Sha384Context
,
766 OUT VOID
*NewSha384Context
769 return CALL_BASECRYPTLIB (Sha384
.Services
.Duplicate
, Sha384Duplicate
, (Sha384Context
, NewSha384Context
), FALSE
);
773 Digests the input data and updates SHA-384 context.
775 This function performs SHA-384 digest on a data buffer of the specified size.
776 It can be called multiple times to compute the digest of long or discontinuous data streams.
777 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized
778 by Sha384Final(). Behavior with invalid context is undefined.
780 If Sha384Context is NULL, then return FALSE.
782 @param[in, out] Sha384Context Pointer to the SHA-384 context.
783 @param[in] Data Pointer to the buffer containing the data to be hashed.
784 @param[in] DataSize Size of Data buffer in bytes.
786 @retval TRUE SHA-384 data digest succeeded.
787 @retval FALSE SHA-384 data digest failed.
792 CryptoServiceSha384Update (
793 IN OUT VOID
*Sha384Context
,
798 return CALL_BASECRYPTLIB (Sha384
.Services
.Update
, Sha384Update
, (Sha384Context
, Data
, DataSize
), FALSE
);
802 Completes computation of the SHA-384 digest value.
804 This function completes SHA-384 hash computation and retrieves the digest value into
805 the specified memory. After this function has been called, the SHA-384 context cannot
807 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be
808 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.
810 If Sha384Context is NULL, then return FALSE.
811 If HashValue is NULL, then return FALSE.
813 @param[in, out] Sha384Context Pointer to the SHA-384 context.
814 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
817 @retval TRUE SHA-384 digest computation succeeded.
818 @retval FALSE SHA-384 digest computation failed.
823 CryptoServiceSha384Final (
824 IN OUT VOID
*Sha384Context
,
828 return CALL_BASECRYPTLIB (Sha384
.Services
.Final
, Sha384Final
, (Sha384Context
, HashValue
), FALSE
);
832 Computes the SHA-384 message digest of a input data buffer.
834 This function performs the SHA-384 message digest of a given data buffer, and places
835 the digest value into the specified memory.
837 If this interface is not supported, then return FALSE.
839 @param[in] Data Pointer to the buffer containing the data to be hashed.
840 @param[in] DataSize Size of Data buffer in bytes.
841 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
844 @retval TRUE SHA-384 digest computation succeeded.
845 @retval FALSE SHA-384 digest computation failed.
846 @retval FALSE This interface is not supported.
851 CryptoServiceSha384HashAll (
857 return CALL_BASECRYPTLIB (Sha384
.Services
.HashAll
, Sha384HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
861 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.
863 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.
868 CryptoServiceSha512GetContextSize (
872 return CALL_BASECRYPTLIB (Sha512
.Services
.GetContextSize
, Sha512GetContextSize
, (), 0);
876 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for
879 If Sha512Context is NULL, then return FALSE.
881 @param[out] Sha512Context Pointer to SHA-512 context being initialized.
883 @retval TRUE SHA-512 context initialization succeeded.
884 @retval FALSE SHA-512 context initialization failed.
889 CryptoServiceSha512Init (
890 OUT VOID
*Sha512Context
893 return CALL_BASECRYPTLIB (Sha512
.Services
.Init
, Sha512Init
, (Sha512Context
), FALSE
);
897 Makes a copy of an existing SHA-512 context.
899 If Sha512Context is NULL, then return FALSE.
900 If NewSha512Context is NULL, then return FALSE.
901 If this interface is not supported, then return FALSE.
903 @param[in] Sha512Context Pointer to SHA-512 context being copied.
904 @param[out] NewSha512Context Pointer to new SHA-512 context.
906 @retval TRUE SHA-512 context copy succeeded.
907 @retval FALSE SHA-512 context copy failed.
908 @retval FALSE This interface is not supported.
913 CryptoServiceSha512Duplicate (
914 IN CONST VOID
*Sha512Context
,
915 OUT VOID
*NewSha512Context
918 return CALL_BASECRYPTLIB (Sha512
.Services
.Duplicate
, Sha512Duplicate
, (Sha512Context
, NewSha512Context
), FALSE
);
922 Digests the input data and updates SHA-512 context.
924 This function performs SHA-512 digest on a data buffer of the specified size.
925 It can be called multiple times to compute the digest of long or discontinuous data streams.
926 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized
927 by Sha512Final(). Behavior with invalid context is undefined.
929 If Sha512Context is NULL, then return FALSE.
931 @param[in, out] Sha512Context Pointer to the SHA-512 context.
932 @param[in] Data Pointer to the buffer containing the data to be hashed.
933 @param[in] DataSize Size of Data buffer in bytes.
935 @retval TRUE SHA-512 data digest succeeded.
936 @retval FALSE SHA-512 data digest failed.
941 CryptoServiceSha512Update (
942 IN OUT VOID
*Sha512Context
,
947 return CALL_BASECRYPTLIB (Sha512
.Services
.Update
, Sha512Update
, (Sha512Context
, Data
, DataSize
), FALSE
);
951 Completes computation of the SHA-512 digest value.
953 This function completes SHA-512 hash computation and retrieves the digest value into
954 the specified memory. After this function has been called, the SHA-512 context cannot
956 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be
957 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.
959 If Sha512Context is NULL, then return FALSE.
960 If HashValue is NULL, then return FALSE.
962 @param[in, out] Sha512Context Pointer to the SHA-512 context.
963 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
966 @retval TRUE SHA-512 digest computation succeeded.
967 @retval FALSE SHA-512 digest computation failed.
972 CryptoServiceSha512Final (
973 IN OUT VOID
*Sha512Context
,
977 return CALL_BASECRYPTLIB (Sha512
.Services
.Final
, Sha512Final
, (Sha512Context
, HashValue
), FALSE
);
981 Computes the SHA-512 message digest of a input data buffer.
983 This function performs the SHA-512 message digest of a given data buffer, and places
984 the digest value into the specified memory.
986 If this interface is not supported, then return FALSE.
988 @param[in] Data Pointer to the buffer containing the data to be hashed.
989 @param[in] DataSize Size of Data buffer in bytes.
990 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
993 @retval TRUE SHA-512 digest computation succeeded.
994 @retval FALSE SHA-512 digest computation failed.
995 @retval FALSE This interface is not supported.
1000 CryptoServiceSha512HashAll (
1001 IN CONST VOID
*Data
,
1003 OUT UINT8
*HashValue
1006 return CALL_BASECRYPTLIB (Sha512
.Services
.HashAll
, Sha512HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
1010 Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.
1012 @return The size, in bytes, of the context buffer required for SM3 hash operations.
1017 CryptoServiceSm3GetContextSize (
1021 return CALL_BASECRYPTLIB (Sm3
.Services
.GetContextSize
, Sm3GetContextSize
, (), 0);
1025 Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for
1028 If Sm3Context is NULL, then return FALSE.
1030 @param[out] Sm3Context Pointer to SM3 context being initialized.
1032 @retval TRUE SM3 context initialization succeeded.
1033 @retval FALSE SM3 context initialization failed.
1038 CryptoServiceSm3Init (
1039 OUT VOID
*Sm3Context
1042 return CALL_BASECRYPTLIB (Sm3
.Services
.Init
, Sm3Init
, (Sm3Context
), FALSE
);
1046 Makes a copy of an existing SM3 context.
1048 If Sm3Context is NULL, then return FALSE.
1049 If NewSm3Context is NULL, then return FALSE.
1050 If this interface is not supported, then return FALSE.
1052 @param[in] Sm3Context Pointer to SM3 context being copied.
1053 @param[out] NewSm3Context Pointer to new SM3 context.
1055 @retval TRUE SM3 context copy succeeded.
1056 @retval FALSE SM3 context copy failed.
1057 @retval FALSE This interface is not supported.
1062 CryptoServiceSm3Duplicate (
1063 IN CONST VOID
*Sm3Context
,
1064 OUT VOID
*NewSm3Context
1067 return CALL_BASECRYPTLIB (Sm3
.Services
.Duplicate
, Sm3Duplicate
, (Sm3Context
, NewSm3Context
), FALSE
);
1071 Digests the input data and updates SM3 context.
1073 This function performs SM3 digest on a data buffer of the specified size.
1074 It can be called multiple times to compute the digest of long or discontinuous data streams.
1075 SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized
1076 by Sm3Final(). Behavior with invalid context is undefined.
1078 If Sm3Context is NULL, then return FALSE.
1080 @param[in, out] Sm3Context Pointer to the SM3 context.
1081 @param[in] Data Pointer to the buffer containing the data to be hashed.
1082 @param[in] DataSize Size of Data buffer in bytes.
1084 @retval TRUE SM3 data digest succeeded.
1085 @retval FALSE SM3 data digest failed.
1090 CryptoServiceSm3Update (
1091 IN OUT VOID
*Sm3Context
,
1092 IN CONST VOID
*Data
,
1096 return CALL_BASECRYPTLIB (Sm3
.Services
.Update
, Sm3Update
, (Sm3Context
, Data
, DataSize
), FALSE
);
1100 Completes computation of the SM3 digest value.
1102 This function completes SM3 hash computation and retrieves the digest value into
1103 the specified memory. After this function has been called, the SM3 context cannot
1105 SM3 context should be already correctly initialized by Sm3Init(), and should not be
1106 finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.
1108 If Sm3Context is NULL, then return FALSE.
1109 If HashValue is NULL, then return FALSE.
1111 @param[in, out] Sm3Context Pointer to the SM3 context.
1112 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
1115 @retval TRUE SM3 digest computation succeeded.
1116 @retval FALSE SM3 digest computation failed.
1121 CryptoServiceSm3Final (
1122 IN OUT VOID
*Sm3Context
,
1123 OUT UINT8
*HashValue
1126 return CALL_BASECRYPTLIB (Sm3
.Services
.Final
, Sm3Final
, (Sm3Context
, HashValue
), FALSE
);
1130 Computes the SM3 message digest of a input data buffer.
1132 This function performs the SM3 message digest of a given data buffer, and places
1133 the digest value into the specified memory.
1135 If this interface is not supported, then return FALSE.
1137 @param[in] Data Pointer to the buffer containing the data to be hashed.
1138 @param[in] DataSize Size of Data buffer in bytes.
1139 @param[out] HashValue Pointer to a buffer that receives the SM3 digest
1142 @retval TRUE SM3 digest computation succeeded.
1143 @retval FALSE SM3 digest computation failed.
1144 @retval FALSE This interface is not supported.
1149 CryptoServiceSm3HashAll (
1150 IN CONST VOID
*Data
,
1152 OUT UINT8
*HashValue
1155 return CALL_BASECRYPTLIB (Sm3
.Services
.HashAll
, Sm3HashAll
, (Data
, DataSize
, HashValue
), FALSE
);
1158 //=====================================================================================
1159 // MAC (Message Authentication Code) Primitive
1160 //=====================================================================================
1163 Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD5 use.
1165 If this interface is not supported, then return NULL.
1167 @return Pointer to the HMAC_CTX context that has been initialized.
1168 If the allocations fails, HmacMd5New() returns NULL.
1169 @retval NULL This interface is not supported.
1174 CryptoServiceHmacMd5New (
1178 return CALL_BASECRYPTLIB (HmacMd5
.Services
.New
, HmacMd5New
, (), NULL
);
1182 Release the specified HMAC_CTX context.
1184 If this interface is not supported, then do nothing.
1186 @param[in] HmacMd5Ctx Pointer to the HMAC_CTX context to be released.
1191 CryptoServiceHmacMd5Free (
1195 CALL_VOID_BASECRYPTLIB (HmacMd5
.Services
.Free
, HmacMd5Free
, (HmacMd5Ctx
));
1199 Set user-supplied key for subsequent use. It must be done before any
1200 calling to HmacMd5Update().
1202 If HmacMd5Context is NULL, then return FALSE.
1203 If this interface is not supported, then return FALSE.
1205 @param[out] HmacMd5Context Pointer to HMAC-MD5 context.
1206 @param[in] Key Pointer to the user-supplied key.
1207 @param[in] KeySize Key size in bytes.
1209 @retval TRUE Key is set successfully.
1210 @retval FALSE Key is set unsuccessfully.
1211 @retval FALSE This interface is not supported.
1216 CryptoServiceHmacMd5SetKey (
1217 OUT VOID
*HmacMd5Context
,
1218 IN CONST UINT8
*Key
,
1222 return CALL_BASECRYPTLIB (HmacMd5
.Services
.SetKey
, HmacMd5SetKey
, (HmacMd5Context
, Key
, KeySize
), FALSE
);
1226 Makes a copy of an existing HMAC-MD5 context.
1228 If HmacMd5Context is NULL, then return FALSE.
1229 If NewHmacMd5Context is NULL, then return FALSE.
1230 If this interface is not supported, then return FALSE.
1232 @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied.
1233 @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context.
1235 @retval TRUE HMAC-MD5 context copy succeeded.
1236 @retval FALSE HMAC-MD5 context copy failed.
1237 @retval FALSE This interface is not supported.
1242 CryptoServiceHmacMd5Duplicate (
1243 IN CONST VOID
*HmacMd5Context
,
1244 OUT VOID
*NewHmacMd5Context
1247 return CALL_BASECRYPTLIB (HmacMd5
.Services
.Duplicate
, HmacMd5Duplicate
, (HmacMd5Context
, NewHmacMd5Context
), FALSE
);
1251 Digests the input data and updates HMAC-MD5 context.
1253 This function performs HMAC-MD5 digest on a data buffer of the specified size.
1254 It can be called multiple times to compute the digest of long or discontinuous data streams.
1255 HMAC-MD5 context should be initialized by HmacMd5New(), and should not be finalized by
1256 HmacMd5Final(). Behavior with invalid context is undefined.
1258 If HmacMd5Context is NULL, then return FALSE.
1259 If this interface is not supported, then return FALSE.
1261 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
1262 @param[in] Data Pointer to the buffer containing the data to be digested.
1263 @param[in] DataSize Size of Data buffer in bytes.
1265 @retval TRUE HMAC-MD5 data digest succeeded.
1266 @retval FALSE HMAC-MD5 data digest failed.
1267 @retval FALSE This interface is not supported.
1272 CryptoServiceHmacMd5Update (
1273 IN OUT VOID
*HmacMd5Context
,
1274 IN CONST VOID
*Data
,
1278 return CALL_BASECRYPTLIB (HmacMd5
.Services
.Update
, HmacMd5Update
, (HmacMd5Context
, Data
, DataSize
), FALSE
);
1282 Completes computation of the HMAC-MD5 digest value.
1284 This function completes HMAC-MD5 hash computation and retrieves the digest value into
1285 the specified memory. After this function has been called, the HMAC-MD5 context cannot
1287 HMAC-MD5 context should be initialized by HmacMd5New(), and should not be finalized by
1288 HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined.
1290 If HmacMd5Context is NULL, then return FALSE.
1291 If HmacValue is NULL, then return FALSE.
1292 If this interface is not supported, then return FALSE.
1294 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
1295 @param[out] HmacValue Pointer to a buffer that receives the HMAC-MD5 digest
1298 @retval TRUE HMAC-MD5 digest computation succeeded.
1299 @retval FALSE HMAC-MD5 digest computation failed.
1300 @retval FALSE This interface is not supported.
1305 CryptoServiceHmacMd5Final (
1306 IN OUT VOID
*HmacMd5Context
,
1307 OUT UINT8
*HmacValue
1310 return CALL_BASECRYPTLIB (HmacMd5
.Services
.Final
, HmacMd5Final
, (HmacMd5Context
, HmacValue
), FALSE
);
1314 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA1 use.
1316 If this interface is not supported, then return NULL.
1318 @return Pointer to the HMAC_CTX context that has been initialized.
1319 If the allocations fails, HmacSha1New() returns NULL.
1320 @return NULL This interface is not supported.
1325 CryptoServiceHmacSha1New (
1329 return CALL_BASECRYPTLIB (HmacSha1
.Services
.New
, HmacSha1New
, (), NULL
);
1333 Release the specified HMAC_CTX context.
1335 If this interface is not supported, then do nothing.
1337 @param[in] HmacSha1Ctx Pointer to the HMAC_CTX context to be released.
1342 CryptoServiceHmacSha1Free (
1343 IN VOID
*HmacSha1Ctx
1346 CALL_VOID_BASECRYPTLIB (HmacSha1
.Services
.Free
, HmacSha1Free
, (HmacSha1Ctx
));
1350 Set user-supplied key for subsequent use. It must be done before any
1351 calling to HmacSha1Update().
1353 If HmacSha1Context is NULL, then return FALSE.
1354 If this interface is not supported, then return FALSE.
1356 @param[out] HmacSha1Context Pointer to HMAC-SHA1 context.
1357 @param[in] Key Pointer to the user-supplied key.
1358 @param[in] KeySize Key size in bytes.
1360 @retval TRUE The Key is set successfully.
1361 @retval FALSE The Key is set unsuccessfully.
1362 @retval FALSE This interface is not supported.
1367 CryptoServiceHmacSha1SetKey (
1368 OUT VOID
*HmacSha1Context
,
1369 IN CONST UINT8
*Key
,
1373 return CALL_BASECRYPTLIB (HmacSha1
.Services
.SetKey
, HmacSha1SetKey
, (HmacSha1Context
, Key
, KeySize
), FALSE
);
1377 Makes a copy of an existing HMAC-SHA1 context.
1379 If HmacSha1Context is NULL, then return FALSE.
1380 If NewHmacSha1Context is NULL, then return FALSE.
1381 If this interface is not supported, then return FALSE.
1383 @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied.
1384 @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context.
1386 @retval TRUE HMAC-SHA1 context copy succeeded.
1387 @retval FALSE HMAC-SHA1 context copy failed.
1388 @retval FALSE This interface is not supported.
1393 CryptoServiceHmacSha1Duplicate (
1394 IN CONST VOID
*HmacSha1Context
,
1395 OUT VOID
*NewHmacSha1Context
1398 return CALL_BASECRYPTLIB (HmacSha1
.Services
.Duplicate
, HmacSha1Duplicate
, (HmacSha1Context
, NewHmacSha1Context
), FALSE
);
1402 Digests the input data and updates HMAC-SHA1 context.
1404 This function performs HMAC-SHA1 digest on a data buffer of the specified size.
1405 It can be called multiple times to compute the digest of long or discontinuous data streams.
1406 HMAC-SHA1 context should be initialized by HmacSha1New(), and should not be finalized by
1407 HmacSha1Final(). Behavior with invalid context is undefined.
1409 If HmacSha1Context is NULL, then return FALSE.
1410 If this interface is not supported, then return FALSE.
1412 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1413 @param[in] Data Pointer to the buffer containing the data to be digested.
1414 @param[in] DataSize Size of Data buffer in bytes.
1416 @retval TRUE HMAC-SHA1 data digest succeeded.
1417 @retval FALSE HMAC-SHA1 data digest failed.
1418 @retval FALSE This interface is not supported.
1423 CryptoServiceHmacSha1Update (
1424 IN OUT VOID
*HmacSha1Context
,
1425 IN CONST VOID
*Data
,
1429 return CALL_BASECRYPTLIB (HmacSha1
.Services
.Update
, HmacSha1Update
, (HmacSha1Context
, Data
, DataSize
), FALSE
);
1433 Completes computation of the HMAC-SHA1 digest value.
1435 This function completes HMAC-SHA1 hash computation and retrieves the digest value into
1436 the specified memory. After this function has been called, the HMAC-SHA1 context cannot
1438 HMAC-SHA1 context should be initialized by HmacSha1New(), and should not be finalized
1439 by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined.
1441 If HmacSha1Context is NULL, then return FALSE.
1442 If HmacValue is NULL, then return FALSE.
1443 If this interface is not supported, then return FALSE.
1445 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1446 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA1 digest
1449 @retval TRUE HMAC-SHA1 digest computation succeeded.
1450 @retval FALSE HMAC-SHA1 digest computation failed.
1451 @retval FALSE This interface is not supported.
1456 CryptoServiceHmacSha1Final (
1457 IN OUT VOID
*HmacSha1Context
,
1458 OUT UINT8
*HmacValue
1461 return CALL_BASECRYPTLIB (HmacSha1
.Services
.Final
, HmacSha1Final
, (HmacSha1Context
, HmacValue
), FALSE
);
1465 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
1467 @return Pointer to the HMAC_CTX context that has been initialized.
1468 If the allocations fails, HmacSha256New() returns NULL.
1473 CryptoServiceHmacSha256New (
1477 return CALL_BASECRYPTLIB (HmacSha256
.Services
.New
, HmacSha256New
, (), NULL
);
1481 Release the specified HMAC_CTX context.
1483 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.
1488 CryptoServiceHmacSha256Free (
1489 IN VOID
*HmacSha256Ctx
1492 CALL_VOID_BASECRYPTLIB (HmacSha256
.Services
.Free
, HmacSha256Free
, (HmacSha256Ctx
));
1496 Set user-supplied key for subsequent use. It must be done before any
1497 calling to HmacSha256Update().
1499 If HmacSha256Context is NULL, then return FALSE.
1500 If this interface is not supported, then return FALSE.
1502 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.
1503 @param[in] Key Pointer to the user-supplied key.
1504 @param[in] KeySize Key size in bytes.
1506 @retval TRUE The Key is set successfully.
1507 @retval FALSE The Key is set unsuccessfully.
1508 @retval FALSE This interface is not supported.
1513 CryptoServiceHmacSha256SetKey (
1514 OUT VOID
*HmacSha256Context
,
1515 IN CONST UINT8
*Key
,
1519 return CALL_BASECRYPTLIB (HmacSha256
.Services
.SetKey
, HmacSha256SetKey
, (HmacSha256Context
, Key
, KeySize
), FALSE
);
1523 Makes a copy of an existing HMAC-SHA256 context.
1525 If HmacSha256Context is NULL, then return FALSE.
1526 If NewHmacSha256Context is NULL, then return FALSE.
1527 If this interface is not supported, then return FALSE.
1529 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.
1530 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.
1532 @retval TRUE HMAC-SHA256 context copy succeeded.
1533 @retval FALSE HMAC-SHA256 context copy failed.
1534 @retval FALSE This interface is not supported.
1539 CryptoServiceHmacSha256Duplicate (
1540 IN CONST VOID
*HmacSha256Context
,
1541 OUT VOID
*NewHmacSha256Context
1544 return CALL_BASECRYPTLIB (HmacSha256
.Services
.Duplicate
, HmacSha256Duplicate
, (HmacSha256Context
, NewHmacSha256Context
), FALSE
);
1548 Digests the input data and updates HMAC-SHA256 context.
1550 This function performs HMAC-SHA256 digest on a data buffer of the specified size.
1551 It can be called multiple times to compute the digest of long or discontinuous data streams.
1552 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1553 by HmacSha256Final(). Behavior with invalid context is undefined.
1555 If HmacSha256Context is NULL, then return FALSE.
1556 If this interface is not supported, then return FALSE.
1558 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1559 @param[in] Data Pointer to the buffer containing the data to be digested.
1560 @param[in] DataSize Size of Data buffer in bytes.
1562 @retval TRUE HMAC-SHA256 data digest succeeded.
1563 @retval FALSE HMAC-SHA256 data digest failed.
1564 @retval FALSE This interface is not supported.
1569 CryptoServiceHmacSha256Update (
1570 IN OUT VOID
*HmacSha256Context
,
1571 IN CONST VOID
*Data
,
1575 return CALL_BASECRYPTLIB (HmacSha256
.Services
.Update
, HmacSha256Update
, (HmacSha256Context
, Data
, DataSize
), FALSE
);
1579 Completes computation of the HMAC-SHA256 digest value.
1581 This function completes HMAC-SHA256 hash computation and retrieves the digest value into
1582 the specified memory. After this function has been called, the HMAC-SHA256 context cannot
1584 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1585 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.
1587 If HmacSha256Context is NULL, then return FALSE.
1588 If HmacValue is NULL, then return FALSE.
1589 If this interface is not supported, then return FALSE.
1591 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1592 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
1595 @retval TRUE HMAC-SHA256 digest computation succeeded.
1596 @retval FALSE HMAC-SHA256 digest computation failed.
1597 @retval FALSE This interface is not supported.
1602 CryptoServiceHmacSha256Final (
1603 IN OUT VOID
*HmacSha256Context
,
1604 OUT UINT8
*HmacValue
1607 return CALL_BASECRYPTLIB (HmacSha256
.Services
.Final
, HmacSha256Final
, (HmacSha256Context
, HmacValue
), FALSE
);
1610 //=====================================================================================
1611 // Symmetric Cryptography Primitive
1612 //=====================================================================================
1615 TDES is deprecated and unsupported any longer.
1616 Keep the function field for binary compability.
1618 @retval 0 This interface is not supported.
1623 DeprecatedCryptoServiceTdesGetContextSize (
1627 return BaseCryptLibServiceDeprecated ("TdesGetContextSize"), 0;
1631 TDES is deprecated and unsupported any longer.
1632 Keep the function field for binary compability.
1634 @param[out] TdesContext Pointer to TDES context being initialized.
1635 @param[in] Key Pointer to the user-supplied TDES key.
1636 @param[in] KeyLength Length of TDES key in bits.
1638 @retval FALSE This interface is not supported.
1643 DeprecatedCryptoServiceTdesInit (
1644 OUT VOID
*TdesContext
,
1645 IN CONST UINT8
*Key
,
1649 return BaseCryptLibServiceDeprecated ("TdesInit"), FALSE
;
1653 TDES is deprecated and unsupported any longer.
1654 Keep the function field for binary compability.
1656 @param[in] TdesContext Pointer to the TDES context.
1657 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1658 @param[in] InputSize Size of the Input buffer in bytes.
1659 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1661 @retval FALSE This interface is not supported.
1666 DeprecatedCryptoServiceTdesEcbEncrypt (
1667 IN VOID
*TdesContext
,
1668 IN CONST UINT8
*Input
,
1673 return BaseCryptLibServiceDeprecated ("TdesEcbEncrypt"), FALSE
;
1677 TDES is deprecated and unsupported any longer.
1678 Keep the function field for binary compability.
1680 @param[in] TdesContext Pointer to the TDES context.
1681 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1682 @param[in] InputSize Size of the Input buffer in bytes.
1683 @param[out] Output Pointer to a buffer that receives the TDES decryption output.
1685 @retval FALSE This interface is not supported.
1690 DeprecatedCryptoServiceTdesEcbDecrypt (
1691 IN VOID
*TdesContext
,
1692 IN CONST UINT8
*Input
,
1697 return BaseCryptLibServiceDeprecated ("TdesEcbDecrypt"), FALSE
;
1701 TDES is deprecated and unsupported any longer.
1702 Keep the function field for binary compability.
1704 @param[in] TdesContext Pointer to the TDES context.
1705 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1706 @param[in] InputSize Size of the Input buffer in bytes.
1707 @param[in] Ivec Pointer to initialization vector.
1708 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1710 @retval FALSE This interface is not supported.
1715 DeprecatedCryptoServiceTdesCbcEncrypt (
1716 IN VOID
*TdesContext
,
1717 IN CONST UINT8
*Input
,
1719 IN CONST UINT8
*Ivec
,
1723 return BaseCryptLibServiceDeprecated ("TdesCbcEncrypt"), FALSE
;
1727 TDES is deprecated and unsupported any longer.
1728 Keep the function field for binary compability.
1730 @param[in] TdesContext Pointer to the TDES context.
1731 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1732 @param[in] InputSize Size of the Input buffer in bytes.
1733 @param[in] Ivec Pointer to initialization vector.
1734 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1736 @retval FALSE This interface is not supported.
1741 DeprecatedCryptoServiceTdesCbcDecrypt (
1742 IN VOID
*TdesContext
,
1743 IN CONST UINT8
*Input
,
1745 IN CONST UINT8
*Ivec
,
1749 return BaseCryptLibServiceDeprecated ("TdesCbcDecrypt"), FALSE
;
1753 Retrieves the size, in bytes, of the context buffer required for AES operations.
1755 If this interface is not supported, then return zero.
1757 @return The size, in bytes, of the context buffer required for AES operations.
1758 @retval 0 This interface is not supported.
1763 CryptoServiceAesGetContextSize (
1767 return CALL_BASECRYPTLIB (Aes
.Services
.GetContextSize
, AesGetContextSize
, (), 0);
1771 Initializes user-supplied memory as AES context for subsequent use.
1773 This function initializes user-supplied memory pointed by AesContext as AES context.
1774 In addition, it sets up all AES key materials for subsequent encryption and decryption
1776 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1778 If AesContext is NULL, then return FALSE.
1779 If Key is NULL, then return FALSE.
1780 If KeyLength is not valid, then return FALSE.
1781 If this interface is not supported, then return FALSE.
1783 @param[out] AesContext Pointer to AES context being initialized.
1784 @param[in] Key Pointer to the user-supplied AES key.
1785 @param[in] KeyLength Length of AES key in bits.
1787 @retval TRUE AES context initialization succeeded.
1788 @retval FALSE AES context initialization failed.
1789 @retval FALSE This interface is not supported.
1794 CryptoServiceAesInit (
1795 OUT VOID
*AesContext
,
1796 IN CONST UINT8
*Key
,
1800 return CALL_BASECRYPTLIB (Aes
.Services
.Init
, AesInit
, (AesContext
, Key
, KeyLength
), FALSE
);
1804 AES ECB Mode is deprecated and unsupported any longer.
1805 Keep the function field for binary compability.
1807 @param[in] AesContext Pointer to the AES context.
1808 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1809 @param[in] InputSize Size of the Input buffer in bytes.
1810 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1812 @retval FALSE This interface is not supported.
1817 DeprecatedCryptoServiceAesEcbEncrypt (
1818 IN VOID
*AesContext
,
1819 IN CONST UINT8
*Input
,
1824 return BaseCryptLibServiceDeprecated ("AesEcbEncrypt"), FALSE
;
1828 AES ECB Mode is deprecated and unsupported any longer.
1829 Keep the function field for binary compability.
1831 @param[in] AesContext Pointer to the AES context.
1832 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1833 @param[in] InputSize Size of the Input buffer in bytes.
1834 @param[out] Output Pointer to a buffer that receives the AES decryption output.
1836 @retval FALSE This interface is not supported.
1841 DeprecatedCryptoServiceAesEcbDecrypt (
1842 IN VOID
*AesContext
,
1843 IN CONST UINT8
*Input
,
1848 return BaseCryptLibServiceDeprecated ("AesEcbDecrypt"), FALSE
;
1852 Performs AES encryption on a data buffer of the specified size in CBC mode.
1854 This function performs AES encryption on data buffer pointed by Input, of specified
1855 size of InputSize, in CBC mode.
1856 InputSize must be multiple of block size (16 bytes). This function does not perform
1857 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1858 Initialization vector should be one block size (16 bytes).
1859 AesContext should be already correctly initialized by AesInit(). Behavior with
1860 invalid AES context is undefined.
1862 If AesContext is NULL, then return FALSE.
1863 If Input is NULL, then return FALSE.
1864 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1865 If Ivec is NULL, then return FALSE.
1866 If Output is NULL, then return FALSE.
1867 If this interface is not supported, then return FALSE.
1869 @param[in] AesContext Pointer to the AES context.
1870 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1871 @param[in] InputSize Size of the Input buffer in bytes.
1872 @param[in] Ivec Pointer to initialization vector.
1873 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1875 @retval TRUE AES encryption succeeded.
1876 @retval FALSE AES encryption failed.
1877 @retval FALSE This interface is not supported.
1882 CryptoServiceAesCbcEncrypt (
1883 IN VOID
*AesContext
,
1884 IN CONST UINT8
*Input
,
1886 IN CONST UINT8
*Ivec
,
1890 return CALL_BASECRYPTLIB (Aes
.Services
.CbcEncrypt
, AesCbcEncrypt
, (AesContext
, Input
, InputSize
, Ivec
, Output
), FALSE
);
1894 Performs AES decryption on a data buffer of the specified size in CBC mode.
1896 This function performs AES decryption on data buffer pointed by Input, of specified
1897 size of InputSize, in CBC mode.
1898 InputSize must be multiple of block size (16 bytes). This function does not perform
1899 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1900 Initialization vector should be one block size (16 bytes).
1901 AesContext should be already correctly initialized by AesInit(). Behavior with
1902 invalid AES context is undefined.
1904 If AesContext is NULL, then return FALSE.
1905 If Input is NULL, then return FALSE.
1906 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1907 If Ivec is NULL, then return FALSE.
1908 If Output is NULL, then return FALSE.
1909 If this interface is not supported, then return FALSE.
1911 @param[in] AesContext Pointer to the AES context.
1912 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1913 @param[in] InputSize Size of the Input buffer in bytes.
1914 @param[in] Ivec Pointer to initialization vector.
1915 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1917 @retval TRUE AES decryption succeeded.
1918 @retval FALSE AES decryption failed.
1919 @retval FALSE This interface is not supported.
1924 CryptoServiceAesCbcDecrypt (
1925 IN VOID
*AesContext
,
1926 IN CONST UINT8
*Input
,
1928 IN CONST UINT8
*Ivec
,
1932 return CALL_BASECRYPTLIB (Aes
.Services
.CbcDecrypt
, AesCbcDecrypt
, (AesContext
, Input
, InputSize
, Ivec
, Output
), FALSE
);
1936 ARC4 is deprecated and unsupported any longer.
1937 Keep the function field for binary compability.
1939 @retval 0 This interface is not supported.
1944 DeprecatedCryptoServiceArc4GetContextSize (
1948 return BaseCryptLibServiceDeprecated ("Arc4GetContextSize"), 0;
1952 ARC4 is deprecated and unsupported any longer.
1953 Keep the function field for binary compability.
1955 @param[out] Arc4Context Pointer to ARC4 context being initialized.
1956 @param[in] Key Pointer to the user-supplied ARC4 key.
1957 @param[in] KeySize Size of ARC4 key in bytes.
1959 @retval FALSE This interface is not supported.
1964 DeprecatedCryptoServiceArc4Init (
1965 OUT VOID
*Arc4Context
,
1966 IN CONST UINT8
*Key
,
1970 return BaseCryptLibServiceDeprecated ("Arc4Init"), FALSE
;
1974 ARC4 is deprecated and unsupported any longer.
1975 Keep the function field for binary compability.
1977 @param[in, out] Arc4Context Pointer to the ARC4 context.
1978 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1979 @param[in] InputSize Size of the Input buffer in bytes.
1980 @param[out] Output Pointer to a buffer that receives the ARC4 encryption output.
1982 @retval FALSE This interface is not supported.
1987 DeprecatedCryptoServiceArc4Encrypt (
1988 IN OUT VOID
*Arc4Context
,
1989 IN CONST UINT8
*Input
,
1994 return BaseCryptLibServiceDeprecated ("Arc4Encrypt"), FALSE
;
1998 ARC4 is deprecated and unsupported any longer.
1999 Keep the function field for binary compability.
2001 @param[in, out] Arc4Context Pointer to the ARC4 context.
2002 @param[in] Input Pointer to the buffer containing the data to be decrypted.
2003 @param[in] InputSize Size of the Input buffer in bytes.
2004 @param[out] Output Pointer to a buffer that receives the ARC4 decryption output.
2006 @retval FALSE This interface is not supported.
2011 DeprecatedCryptoServiceArc4Decrypt (
2012 IN OUT VOID
*Arc4Context
,
2018 return BaseCryptLibServiceDeprecated ("Arc4Decrypt"), FALSE
;
2022 ARC4 is deprecated and unsupported any longer.
2023 Keep the function field for binary compability.
2025 @param[in, out] Arc4Context Pointer to the ARC4 context.
2027 @retval FALSE This interface is not supported.
2032 DeprecatedCryptoServiceArc4Reset (
2033 IN OUT VOID
*Arc4Context
2036 return BaseCryptLibServiceDeprecated ("Arc4Reset"), FALSE
;
2039 //=====================================================================================
2040 // Asymmetric Cryptography Primitive
2041 //=====================================================================================
2044 Allocates and initializes one RSA context for subsequent use.
2046 @return Pointer to the RSA context that has been initialized.
2047 If the allocations fails, RsaNew() returns NULL.
2052 CryptoServiceRsaNew (
2056 return CALL_BASECRYPTLIB (Rsa
.Services
.New
, RsaNew
, (), NULL
);
2060 Release the specified RSA context.
2062 If RsaContext is NULL, then return FALSE.
2064 @param[in] RsaContext Pointer to the RSA context to be released.
2069 CryptoServiceRsaFree (
2073 CALL_VOID_BASECRYPTLIB (Rsa
.Services
.Free
, RsaFree
, (RsaContext
));
2077 Sets the tag-designated key component into the established RSA context.
2079 This function sets the tag-designated RSA key component into the established
2080 RSA context from the user-specified non-negative integer (octet string format
2081 represented in RSA PKCS#1).
2082 If BigNumber is NULL, then the specified key component in RSA context is cleared.
2084 If RsaContext is NULL, then return FALSE.
2086 @param[in, out] RsaContext Pointer to RSA context being set.
2087 @param[in] KeyTag Tag of RSA key component being set.
2088 @param[in] BigNumber Pointer to octet integer buffer.
2089 If NULL, then the specified key component in RSA
2091 @param[in] BnSize Size of big number buffer in bytes.
2092 If BigNumber is NULL, then it is ignored.
2094 @retval TRUE RSA key component was set successfully.
2095 @retval FALSE Invalid RSA key component tag.
2100 CryptoServiceRsaSetKey (
2101 IN OUT VOID
*RsaContext
,
2102 IN RSA_KEY_TAG KeyTag
,
2103 IN CONST UINT8
*BigNumber
,
2107 return CALL_BASECRYPTLIB (Rsa
.Services
.SetKey
, RsaSetKey
, (RsaContext
, KeyTag
, BigNumber
, BnSize
), FALSE
);
2111 Gets the tag-designated RSA key component from the established RSA context.
2113 This function retrieves the tag-designated RSA key component from the
2114 established RSA context as a non-negative integer (octet string format
2115 represented in RSA PKCS#1).
2116 If specified key component has not been set or has been cleared, then returned
2118 If the BigNumber buffer is too small to hold the contents of the key, FALSE
2119 is returned and BnSize is set to the required buffer size to obtain the key.
2121 If RsaContext is NULL, then return FALSE.
2122 If BnSize is NULL, then return FALSE.
2123 If BnSize is large enough but BigNumber is NULL, then return FALSE.
2124 If this interface is not supported, then return FALSE.
2126 @param[in, out] RsaContext Pointer to RSA context being set.
2127 @param[in] KeyTag Tag of RSA key component being set.
2128 @param[out] BigNumber Pointer to octet integer buffer.
2129 @param[in, out] BnSize On input, the size of big number buffer in bytes.
2130 On output, the size of data returned in big number buffer in bytes.
2132 @retval TRUE RSA key component was retrieved successfully.
2133 @retval FALSE Invalid RSA key component tag.
2134 @retval FALSE BnSize is too small.
2135 @retval FALSE This interface is not supported.
2140 CryptoServiceRsaGetKey (
2141 IN OUT VOID
*RsaContext
,
2142 IN RSA_KEY_TAG KeyTag
,
2143 OUT UINT8
*BigNumber
,
2144 IN OUT UINTN
*BnSize
2147 return CALL_BASECRYPTLIB (Rsa
.Services
.GetKey
, RsaGetKey
, (RsaContext
, KeyTag
, BigNumber
, BnSize
), FALSE
);
2151 Generates RSA key components.
2153 This function generates RSA key components. It takes RSA public exponent E and
2154 length in bits of RSA modulus N as input, and generates all key components.
2155 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
2157 Before this function can be invoked, pseudorandom number generator must be correctly
2158 initialized by RandomSeed().
2160 If RsaContext is NULL, then return FALSE.
2161 If this interface is not supported, then return FALSE.
2163 @param[in, out] RsaContext Pointer to RSA context being set.
2164 @param[in] ModulusLength Length of RSA modulus N in bits.
2165 @param[in] PublicExponent Pointer to RSA public exponent.
2166 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
2168 @retval TRUE RSA key component was generated successfully.
2169 @retval FALSE Invalid RSA key component tag.
2170 @retval FALSE This interface is not supported.
2175 CryptoServiceRsaGenerateKey (
2176 IN OUT VOID
*RsaContext
,
2177 IN UINTN ModulusLength
,
2178 IN CONST UINT8
*PublicExponent
,
2179 IN UINTN PublicExponentSize
2182 return CALL_BASECRYPTLIB (Rsa
.Services
.GenerateKey
, RsaGenerateKey
, (RsaContext
, ModulusLength
, PublicExponent
, PublicExponentSize
), FALSE
);
2186 Validates key components of RSA context.
2187 NOTE: This function performs integrity checks on all the RSA key material, so
2188 the RSA key structure must contain all the private key data.
2190 This function validates key components of RSA context in following aspects:
2191 - Whether p is a prime
2192 - Whether q is a prime
2194 - Whether d*e = 1 mod lcm(p-1,q-1)
2196 If RsaContext is NULL, then return FALSE.
2197 If this interface is not supported, then return FALSE.
2199 @param[in] RsaContext Pointer to RSA context to check.
2201 @retval TRUE RSA key components are valid.
2202 @retval FALSE RSA key components are not valid.
2203 @retval FALSE This interface is not supported.
2208 CryptoServiceRsaCheckKey (
2212 return CALL_BASECRYPTLIB (Rsa
.Services
.CheckKey
, RsaCheckKey
, (RsaContext
), FALSE
);
2216 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
2218 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
2220 If the Signature buffer is too small to hold the contents of signature, FALSE
2221 is returned and SigSize is set to the required buffer size to obtain the signature.
2223 If RsaContext is NULL, then return FALSE.
2224 If MessageHash is NULL, then return FALSE.
2225 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
2226 If SigSize is large enough but Signature is NULL, then return FALSE.
2227 If this interface is not supported, then return FALSE.
2229 @param[in] RsaContext Pointer to RSA context for signature generation.
2230 @param[in] MessageHash Pointer to octet message hash to be signed.
2231 @param[in] HashSize Size of the message hash in bytes.
2232 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
2233 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
2234 On output, the size of data returned in Signature buffer in bytes.
2236 @retval TRUE Signature successfully generated in PKCS1-v1_5.
2237 @retval FALSE Signature generation failed.
2238 @retval FALSE SigSize is too small.
2239 @retval FALSE This interface is not supported.
2244 CryptoServiceRsaPkcs1Sign (
2245 IN VOID
*RsaContext
,
2246 IN CONST UINT8
*MessageHash
,
2248 OUT UINT8
*Signature
,
2249 IN OUT UINTN
*SigSize
2252 return CALL_BASECRYPTLIB (Rsa
.Services
.Pkcs1Sign
, RsaPkcs1Sign
, (RsaContext
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
2256 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
2259 If RsaContext is NULL, then return FALSE.
2260 If MessageHash is NULL, then return FALSE.
2261 If Signature is NULL, then return FALSE.
2262 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
2264 @param[in] RsaContext Pointer to RSA context for signature verification.
2265 @param[in] MessageHash Pointer to octet message hash to be checked.
2266 @param[in] HashSize Size of the message hash in bytes.
2267 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
2268 @param[in] SigSize Size of signature in bytes.
2270 @retval TRUE Valid signature encoded in PKCS1-v1_5.
2271 @retval FALSE Invalid signature or invalid RSA context.
2276 CryptoServiceRsaPkcs1Verify (
2277 IN VOID
*RsaContext
,
2278 IN CONST UINT8
*MessageHash
,
2280 IN CONST UINT8
*Signature
,
2284 return CALL_BASECRYPTLIB (Rsa
.Services
.Pkcs1Verify
, RsaPkcs1Verify
, (RsaContext
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
2288 Retrieve the RSA Private Key from the password-protected PEM key data.
2290 If PemData is NULL, then return FALSE.
2291 If RsaContext is NULL, then return FALSE.
2292 If this interface is not supported, then return FALSE.
2294 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
2295 @param[in] PemSize Size of the PEM key data in bytes.
2296 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
2297 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2298 RSA private key component. Use RsaFree() function to free the
2301 @retval TRUE RSA Private Key was retrieved successfully.
2302 @retval FALSE Invalid PEM key data or incorrect password.
2303 @retval FALSE This interface is not supported.
2308 CryptoServiceRsaGetPrivateKeyFromPem (
2309 IN CONST UINT8
*PemData
,
2311 IN CONST CHAR8
*Password
,
2312 OUT VOID
**RsaContext
2315 return CALL_BASECRYPTLIB (Rsa
.Services
.GetPrivateKeyFromPem
, RsaGetPrivateKeyFromPem
, (PemData
, PemSize
, Password
, RsaContext
), FALSE
);
2319 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
2321 If Cert is NULL, then return FALSE.
2322 If RsaContext is NULL, then return FALSE.
2323 If this interface is not supported, then return FALSE.
2325 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2326 @param[in] CertSize Size of the X509 certificate in bytes.
2327 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2328 RSA public key component. Use RsaFree() function to free the
2331 @retval TRUE RSA Public Key was retrieved successfully.
2332 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
2333 @retval FALSE This interface is not supported.
2338 CryptoServiceRsaGetPublicKeyFromX509 (
2339 IN CONST UINT8
*Cert
,
2341 OUT VOID
**RsaContext
2344 return CALL_BASECRYPTLIB (Rsa
.Services
.GetPublicKeyFromX509
, RsaGetPublicKeyFromX509
, (Cert
, CertSize
, RsaContext
), FALSE
);
2348 Retrieve the subject bytes from one X.509 certificate.
2350 If Cert is NULL, then return FALSE.
2351 If SubjectSize is NULL, then return FALSE.
2352 If this interface is not supported, then return FALSE.
2354 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2355 @param[in] CertSize Size of the X509 certificate in bytes.
2356 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
2357 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
2358 and the size of buffer returned CertSubject on output.
2360 @retval TRUE The certificate subject retrieved successfully.
2361 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
2362 The SubjectSize will be updated with the required size.
2363 @retval FALSE This interface is not supported.
2368 CryptoServiceX509GetSubjectName (
2369 IN CONST UINT8
*Cert
,
2371 OUT UINT8
*CertSubject
,
2372 IN OUT UINTN
*SubjectSize
2375 return CALL_BASECRYPTLIB (X509
.Services
.GetSubjectName
, X509GetSubjectName
, (Cert
, CertSize
, CertSubject
, SubjectSize
), FALSE
);
2379 Retrieve the common name (CN) string from one X.509 certificate.
2381 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2382 @param[in] CertSize Size of the X509 certificate in bytes.
2383 @param[out] CommonName Buffer to contain the retrieved certificate common
2384 name string (UTF8). At most CommonNameSize bytes will be
2385 written and the string will be null terminated. May be
2386 NULL in order to determine the size buffer needed.
2387 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
2388 and the size of buffer returned CommonName on output.
2389 If CommonName is NULL then the amount of space needed
2390 in buffer (including the final null) is returned.
2392 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
2393 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2394 If CommonNameSize is NULL.
2395 If CommonName is not NULL and *CommonNameSize is 0.
2396 If Certificate is invalid.
2397 @retval RETURN_NOT_FOUND If no CommonName entry exists.
2398 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
2399 (including the final null) is returned in the
2400 CommonNameSize parameter.
2401 @retval RETURN_UNSUPPORTED The operation is not supported.
2406 CryptoServiceX509GetCommonName (
2407 IN CONST UINT8
*Cert
,
2409 OUT CHAR8
*CommonName
, OPTIONAL
2410 IN OUT UINTN
*CommonNameSize
2413 return CALL_BASECRYPTLIB (X509
.Services
.GetCommonName
, X509GetCommonName
, (Cert
, CertSize
, CommonName
, CommonNameSize
), RETURN_UNSUPPORTED
);
2417 Retrieve the organization name (O) string from one X.509 certificate.
2419 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2420 @param[in] CertSize Size of the X509 certificate in bytes.
2421 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
2422 name string. At most NameBufferSize bytes will be
2423 written and the string will be null terminated. May be
2424 NULL in order to determine the size buffer needed.
2425 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
2426 and the size of buffer returned Name on output.
2427 If NameBuffer is NULL then the amount of space needed
2428 in buffer (including the final null) is returned.
2430 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
2431 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2432 If NameBufferSize is NULL.
2433 If NameBuffer is not NULL and *CommonNameSize is 0.
2434 If Certificate is invalid.
2435 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
2436 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
2437 (including the final null) is returned in the
2438 CommonNameSize parameter.
2439 @retval RETURN_UNSUPPORTED The operation is not supported.
2444 CryptoServiceX509GetOrganizationName (
2445 IN CONST UINT8
*Cert
,
2447 OUT CHAR8
*NameBuffer
, OPTIONAL
2448 IN OUT UINTN
*NameBufferSize
2451 return CALL_BASECRYPTLIB (X509
.Services
.GetOrganizationName
, X509GetOrganizationName
, (Cert
, CertSize
, NameBuffer
, NameBufferSize
), RETURN_UNSUPPORTED
);
2455 Verify one X509 certificate was issued by the trusted CA.
2457 If Cert is NULL, then return FALSE.
2458 If CACert is NULL, then return FALSE.
2459 If this interface is not supported, then return FALSE.
2461 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
2462 @param[in] CertSize Size of the X509 certificate in bytes.
2463 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
2464 @param[in] CACertSize Size of the CA Certificate in bytes.
2466 @retval TRUE The certificate was issued by the trusted CA.
2467 @retval FALSE Invalid certificate or the certificate was not issued by the given
2469 @retval FALSE This interface is not supported.
2474 CryptoServiceX509VerifyCert (
2475 IN CONST UINT8
*Cert
,
2477 IN CONST UINT8
*CACert
,
2481 return CALL_BASECRYPTLIB (X509
.Services
.VerifyCert
, X509VerifyCert
, (Cert
, CertSize
, CACert
, CACertSize
), FALSE
);
2485 Construct a X509 object from DER-encoded certificate data.
2487 If Cert is NULL, then return FALSE.
2488 If SingleX509Cert is NULL, then return FALSE.
2489 If this interface is not supported, then return FALSE.
2491 @param[in] Cert Pointer to the DER-encoded certificate data.
2492 @param[in] CertSize The size of certificate data in bytes.
2493 @param[out] SingleX509Cert The generated X509 object.
2495 @retval TRUE The X509 object generation succeeded.
2496 @retval FALSE The operation failed.
2497 @retval FALSE This interface is not supported.
2502 CryptoServiceX509ConstructCertificate (
2503 IN CONST UINT8
*Cert
,
2505 OUT UINT8
**SingleX509Cert
2508 return CALL_BASECRYPTLIB (X509
.Services
.ConstructCertificate
, X509ConstructCertificate
, (Cert
, CertSize
, SingleX509Cert
), FALSE
);
2512 Construct a X509 stack object from a list of DER-encoded certificate data.
2514 If X509Stack is NULL, then return FALSE.
2515 If this interface is not supported, then return FALSE.
2517 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2518 On output, pointer to the X509 stack object with new
2519 inserted X509 certificate.
2520 @param[in] Args VA_LIST marker for the variable argument list.
2521 A list of DER-encoded single certificate data followed
2522 by certificate size. A NULL terminates the list. The
2523 pairs are the arguments to X509ConstructCertificate().
2525 @retval TRUE The X509 stack construction succeeded.
2526 @retval FALSE The construction operation failed.
2527 @retval FALSE This interface is not supported.
2532 CryptoServiceX509ConstructCertificateStackV (
2533 IN OUT UINT8
**X509Stack
,
2537 return CALL_BASECRYPTLIB (X509
.Services
.ConstructCertificateStackV
, X509ConstructCertificateStackV
, (X509Stack
, Args
), FALSE
);
2541 Construct a X509 stack object from a list of DER-encoded certificate data.
2543 If X509Stack is NULL, then return FALSE.
2544 If this interface is not supported, then return FALSE.
2546 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2547 On output, pointer to the X509 stack object with new
2548 inserted X509 certificate.
2549 @param ... A list of DER-encoded single certificate data followed
2550 by certificate size. A NULL terminates the list. The
2551 pairs are the arguments to X509ConstructCertificate().
2553 @retval TRUE The X509 stack construction succeeded.
2554 @retval FALSE The construction operation failed.
2555 @retval FALSE This interface is not supported.
2560 CryptoServiceX509ConstructCertificateStack (
2561 IN OUT UINT8
**X509Stack
,
2568 VA_START (Args
, X509Stack
);
2569 Result
= CryptoServiceX509ConstructCertificateStackV (X509Stack
, Args
);
2575 Release the specified X509 object.
2577 If the interface is not supported, then ASSERT().
2579 @param[in] X509Cert Pointer to the X509 object to be released.
2584 CryptoServiceX509Free (
2588 CALL_VOID_BASECRYPTLIB (X509
.Services
.Free
, X509Free
, (X509Cert
));
2592 Release the specified X509 stack object.
2594 If the interface is not supported, then ASSERT().
2596 @param[in] X509Stack Pointer to the X509 stack object to be released.
2601 CryptoServiceX509StackFree (
2605 CALL_VOID_BASECRYPTLIB (X509
.Services
.StackFree
, X509StackFree
, (X509Stack
));
2609 Retrieve the TBSCertificate from one given X.509 certificate.
2611 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
2612 @param[in] CertSize Size of the X509 certificate in bytes.
2613 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
2614 @param[out] TBSCertSize Size of the TBS certificate in bytes.
2616 If Cert is NULL, then return FALSE.
2617 If TBSCert is NULL, then return FALSE.
2618 If TBSCertSize is NULL, then return FALSE.
2619 If this interface is not supported, then return FALSE.
2621 @retval TRUE The TBSCertificate was retrieved successfully.
2622 @retval FALSE Invalid X.509 certificate.
2627 CryptoServiceX509GetTBSCert (
2628 IN CONST UINT8
*Cert
,
2630 OUT UINT8
**TBSCert
,
2631 OUT UINTN
*TBSCertSize
2634 return CALL_BASECRYPTLIB (X509
.Services
.GetTBSCert
, X509GetTBSCert
, (Cert
, CertSize
, TBSCert
, TBSCertSize
), FALSE
);
2638 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2639 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2641 If Password or Salt or OutKey is NULL, then return FALSE.
2642 If the hash algorithm could not be determined, then return FALSE.
2643 If this interface is not supported, then return FALSE.
2645 @param[in] PasswordLength Length of input password in bytes.
2646 @param[in] Password Pointer to the array for the password.
2647 @param[in] SaltLength Size of the Salt in bytes.
2648 @param[in] Salt Pointer to the Salt.
2649 @param[in] IterationCount Number of iterations to perform. Its value should be
2650 greater than or equal to 1.
2651 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2652 NOTE: DigestSize will be used to determine the hash algorithm.
2653 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2654 @param[in] KeyLength Size of the derived key buffer in bytes.
2655 @param[out] OutKey Pointer to the output derived key buffer.
2657 @retval TRUE A key was derived successfully.
2658 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2659 @retval FALSE The hash algorithm could not be determined from the digest size.
2660 @retval FALSE The key derivation operation failed.
2661 @retval FALSE This interface is not supported.
2666 CryptoServicePkcs5HashPassword (
2667 IN UINTN PasswordLength
,
2668 IN CONST CHAR8
*Password
,
2669 IN UINTN SaltLength
,
2670 IN CONST UINT8
*Salt
,
2671 IN UINTN IterationCount
,
2672 IN UINTN DigestSize
,
2677 return CALL_BASECRYPTLIB (Pkcs
.Services
.Pkcs5HashPassword
, Pkcs5HashPassword
, (PasswordLength
, Password
, SaltLength
, Salt
, IterationCount
, DigestSize
, KeyLength
, OutKey
), FALSE
);
2681 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2682 encrypted message in a newly allocated buffer.
2684 Things that can cause a failure include:
2685 - X509 key size does not match any known key size.
2686 - Fail to parse X509 certificate.
2687 - Fail to allocate an intermediate buffer.
2688 - Null pointer provided for a non-optional parameter.
2689 - Data size is too large for the provided key size (max size is a function of key size
2690 and hash digest size).
2692 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2693 will be used to encrypt the data.
2694 @param[in] PublicKeySize Size of the X509 cert buffer.
2695 @param[in] InData Data to be encrypted.
2696 @param[in] InDataSize Size of the data buffer.
2697 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2698 to be used when initializing the PRNG. NULL otherwise.
2699 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2701 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2703 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2705 @retval TRUE Encryption was successful.
2706 @retval FALSE Encryption failed.
2711 CryptoServicePkcs1v2Encrypt (
2712 IN CONST UINT8
*PublicKey
,
2713 IN UINTN PublicKeySize
,
2715 IN UINTN InDataSize
,
2716 IN CONST UINT8
*PrngSeed
, OPTIONAL
2717 IN UINTN PrngSeedSize
, OPTIONAL
2718 OUT UINT8
**EncryptedData
,
2719 OUT UINTN
*EncryptedDataSize
2722 return CALL_BASECRYPTLIB (Pkcs
.Services
.Pkcs1v2Encrypt
, Pkcs1v2Encrypt
, (PublicKey
, PublicKeySize
, InData
, InDataSize
, PrngSeed
, PrngSeedSize
, EncryptedData
, EncryptedDataSize
), FALSE
);
2726 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2727 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2728 in a ContentInfo structure.
2730 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2731 return FALSE. If P7Length overflow, then return FALSE.
2732 If this interface is not supported, then return FALSE.
2734 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2735 @param[in] P7Length Length of the PKCS#7 message in bytes.
2736 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2737 It's caller's responsibility to free the buffer with
2739 This data structure is EFI_CERT_STACK type.
2740 @param[out] StackLength Length of signer's certificates in bytes.
2741 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2742 It's caller's responsibility to free the buffer with
2744 @param[out] CertLength Length of the trusted certificate in bytes.
2746 @retval TRUE The operation is finished successfully.
2747 @retval FALSE Error occurs during the operation.
2748 @retval FALSE This interface is not supported.
2753 CryptoServicePkcs7GetSigners (
2754 IN CONST UINT8
*P7Data
,
2756 OUT UINT8
**CertStack
,
2757 OUT UINTN
*StackLength
,
2758 OUT UINT8
**TrustedCert
,
2759 OUT UINTN
*CertLength
2762 return CALL_BASECRYPTLIB (Pkcs
.Services
.Pkcs7GetSigners
, Pkcs7GetSigners
, (P7Data
, P7Length
, CertStack
, StackLength
, TrustedCert
, CertLength
), FALSE
);
2766 Wrap function to use free() to free allocated memory for certificates.
2768 If this interface is not supported, then ASSERT().
2770 @param[in] Certs Pointer to the certificates to be freed.
2775 CryptoServicePkcs7FreeSigners (
2779 CALL_VOID_BASECRYPTLIB (Pkcs
.Services
.Pkcs7FreeSigners
, Pkcs7FreeSigners
, (Certs
));
2783 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2784 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2785 unchained to the signer's certificates.
2786 The input signed data could be wrapped in a ContentInfo structure.
2788 @param[in] P7Data Pointer to the PKCS#7 message.
2789 @param[in] P7Length Length of the PKCS#7 message in bytes.
2790 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2791 certificate. It's caller's responsibility to free the buffer
2792 with Pkcs7FreeSigners().
2793 This data structure is EFI_CERT_STACK type.
2794 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2795 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2796 responsibility to free the buffer with Pkcs7FreeSigners().
2797 This data structure is EFI_CERT_STACK type.
2798 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2800 @retval TRUE The operation is finished successfully.
2801 @retval FALSE Error occurs during the operation.
2806 CryptoServicePkcs7GetCertificatesList (
2807 IN CONST UINT8
*P7Data
,
2809 OUT UINT8
**SignerChainCerts
,
2810 OUT UINTN
*ChainLength
,
2811 OUT UINT8
**UnchainCerts
,
2812 OUT UINTN
*UnchainLength
2815 return CALL_BASECRYPTLIB (Pkcs
.Services
.Pkcs7GetCertificatesList
, Pkcs7GetCertificatesList
, (P7Data
, P7Length
, SignerChainCerts
, ChainLength
, UnchainCerts
, UnchainLength
), FALSE
);
2819 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2820 Syntax Standard, version 1.5". This interface is only intended to be used for
2821 application to perform PKCS#7 functionality validation.
2823 If this interface is not supported, then return FALSE.
2825 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2827 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2828 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2830 @param[in] InData Pointer to the content to be signed.
2831 @param[in] InDataSize Size of InData in bytes.
2832 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2833 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2834 include in the PKCS#7 signedData (e.g. any intermediate
2836 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2837 responsibility to free the buffer with FreePool().
2838 @param[out] SignedDataSize Size of SignedData in bytes.
2840 @retval TRUE PKCS#7 data signing succeeded.
2841 @retval FALSE PKCS#7 data signing failed.
2842 @retval FALSE This interface is not supported.
2847 CryptoServicePkcs7Sign (
2848 IN CONST UINT8
*PrivateKey
,
2849 IN UINTN PrivateKeySize
,
2850 IN CONST UINT8
*KeyPassword
,
2852 IN UINTN InDataSize
,
2854 IN UINT8
*OtherCerts OPTIONAL
,
2855 OUT UINT8
**SignedData
,
2856 OUT UINTN
*SignedDataSize
2859 return CALL_BASECRYPTLIB (Pkcs
.Services
.Pkcs7Sign
, Pkcs7Sign
, (PrivateKey
, PrivateKeySize
, KeyPassword
, InData
, InDataSize
, SignCert
, OtherCerts
, SignedData
, SignedDataSize
), FALSE
);
2863 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2864 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2865 in a ContentInfo structure.
2867 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2868 If P7Length, CertLength or DataLength overflow, then return FALSE.
2869 If this interface is not supported, then return FALSE.
2871 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2872 @param[in] P7Length Length of the PKCS#7 message in bytes.
2873 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2874 is used for certificate chain verification.
2875 @param[in] CertLength Length of the trusted certificate in bytes.
2876 @param[in] InData Pointer to the content to be verified.
2877 @param[in] DataLength Length of InData in bytes.
2879 @retval TRUE The specified PKCS#7 signed data is valid.
2880 @retval FALSE Invalid PKCS#7 signed data.
2881 @retval FALSE This interface is not supported.
2886 CryptoServicePkcs7Verify (
2887 IN CONST UINT8
*P7Data
,
2889 IN CONST UINT8
*TrustedCert
,
2890 IN UINTN CertLength
,
2891 IN CONST UINT8
*InData
,
2895 return CALL_BASECRYPTLIB (Pkcs
.Services
.Pkcs7Verify
, Pkcs7Verify
, (P7Data
, P7Length
, TrustedCert
, CertLength
, InData
, DataLength
), FALSE
);
2899 This function receives a PKCS7 formatted signature, and then verifies that
2900 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
2901 leaf signing certificate.
2902 Note that this function does not validate the certificate chain.
2904 Applications for custom EKU's are quite flexible. For example, a policy EKU
2905 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
2906 certificate issued might also contain this EKU, thus constraining the
2907 sub-ordinate certificate. Other applications might allow a certificate
2908 embedded in a device to specify that other Object Identifiers (OIDs) are
2909 present which contains binary data specifying custom capabilities that
2910 the device is able to do.
2912 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
2913 containing the content block with both the signature,
2914 the signer's certificate, and any necessary intermediate
2916 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
2917 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
2918 required EKUs that must be present in the signature.
2919 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
2920 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
2921 must be present in the leaf signer. If it is
2922 FALSE, then we will succeed if we find any
2923 of the specified EKU's.
2925 @retval EFI_SUCCESS The required EKUs were found in the signature.
2926 @retval EFI_INVALID_PARAMETER A parameter was invalid.
2927 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
2932 CryptoServiceVerifyEKUsInPkcs7Signature (
2933 IN CONST UINT8
*Pkcs7Signature
,
2934 IN CONST UINT32 SignatureSize
,
2935 IN CONST CHAR8
*RequiredEKUs
[],
2936 IN CONST UINT32 RequiredEKUsSize
,
2937 IN BOOLEAN RequireAllPresent
2940 return CALL_BASECRYPTLIB (Pkcs
.Services
.VerifyEKUsInPkcs7Signature
, VerifyEKUsInPkcs7Signature
, (Pkcs7Signature
, SignatureSize
, RequiredEKUs
, RequiredEKUsSize
, RequireAllPresent
), FALSE
);
2945 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2946 data could be wrapped in a ContentInfo structure.
2948 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2949 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2951 Caution: This function may receive untrusted input. So this function will do
2952 basic check for PKCS#7 data structure.
2954 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2955 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2956 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2957 It's caller's responsibility to free the buffer with FreePool().
2958 @param[out] ContentSize The size of the extracted content in bytes.
2960 @retval TRUE The P7Data was correctly formatted for processing.
2961 @retval FALSE The P7Data was not correctly formatted for processing.
2966 CryptoServicePkcs7GetAttachedContent (
2967 IN CONST UINT8
*P7Data
,
2970 OUT UINTN
*ContentSize
2973 return CALL_BASECRYPTLIB (Pkcs
.Services
.Pkcs7GetAttachedContent
, Pkcs7GetAttachedContent
, (P7Data
, P7Length
, Content
, ContentSize
), FALSE
);
2977 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2978 Authenticode Portable Executable Signature Format".
2980 If AuthData is NULL, then return FALSE.
2981 If ImageHash is NULL, then return FALSE.
2982 If this interface is not supported, then return FALSE.
2984 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2985 PE/COFF image to be verified.
2986 @param[in] DataSize Size of the Authenticode Signature in bytes.
2987 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2988 is used for certificate chain verification.
2989 @param[in] CertSize Size of the trusted certificate in bytes.
2990 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2991 for calculating the image hash value is described in Authenticode
2993 @param[in] HashSize Size of Image hash value in bytes.
2995 @retval TRUE The specified Authenticode Signature is valid.
2996 @retval FALSE Invalid Authenticode Signature.
2997 @retval FALSE This interface is not supported.
3002 CryptoServiceAuthenticodeVerify (
3003 IN CONST UINT8
*AuthData
,
3005 IN CONST UINT8
*TrustedCert
,
3007 IN CONST UINT8
*ImageHash
,
3011 return CALL_BASECRYPTLIB (Pkcs
.Services
.AuthenticodeVerify
, AuthenticodeVerify
, (AuthData
, DataSize
, TrustedCert
, CertSize
, ImageHash
, HashSize
), FALSE
);
3015 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
3018 If AuthData is NULL, then return FALSE.
3019 If this interface is not supported, then return FALSE.
3021 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
3022 PE/COFF image to be verified.
3023 @param[in] DataSize Size of the Authenticode Signature in bytes.
3024 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
3025 is used for TSA certificate chain verification.
3026 @param[in] CertSize Size of the trusted certificate in bytes.
3027 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
3030 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
3031 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
3036 CryptoServiceImageTimestampVerify (
3037 IN CONST UINT8
*AuthData
,
3039 IN CONST UINT8
*TsaCert
,
3041 OUT EFI_TIME
*SigningTime
3044 return CALL_BASECRYPTLIB (Pkcs
.Services
.ImageTimestampVerify
, ImageTimestampVerify
, (AuthData
, DataSize
, TsaCert
, CertSize
, SigningTime
), FALSE
);
3047 //=====================================================================================
3048 // DH Key Exchange Primitive
3049 //=====================================================================================
3052 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
3054 @return Pointer to the Diffie-Hellman Context that has been initialized.
3055 If the allocations fails, DhNew() returns NULL.
3056 If the interface is not supported, DhNew() returns NULL.
3061 CryptoServiceDhNew (
3065 return CALL_BASECRYPTLIB (Dh
.Services
.New
, DhNew
, (), NULL
);
3069 Release the specified DH context.
3071 If the interface is not supported, then ASSERT().
3073 @param[in] DhContext Pointer to the DH context to be released.
3078 CryptoServiceDhFree (
3082 CALL_VOID_BASECRYPTLIB (Dh
.Services
.Free
, DhFree
, (DhContext
));
3086 Generates DH parameter.
3088 Given generator g, and length of prime number p in bits, this function generates p,
3089 and sets DH context according to value of g and p.
3091 Before this function can be invoked, pseudorandom number generator must be correctly
3092 initialized by RandomSeed().
3094 If DhContext is NULL, then return FALSE.
3095 If Prime is NULL, then return FALSE.
3096 If this interface is not supported, then return FALSE.
3098 @param[in, out] DhContext Pointer to the DH context.
3099 @param[in] Generator Value of generator.
3100 @param[in] PrimeLength Length in bits of prime to be generated.
3101 @param[out] Prime Pointer to the buffer to receive the generated prime number.
3103 @retval TRUE DH parameter generation succeeded.
3104 @retval FALSE Value of Generator is not supported.
3105 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
3106 @retval FALSE This interface is not supported.
3111 CryptoServiceDhGenerateParameter (
3112 IN OUT VOID
*DhContext
,
3114 IN UINTN PrimeLength
,
3118 return CALL_BASECRYPTLIB (Dh
.Services
.GenerateParameter
, DhGenerateParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
3122 Sets generator and prime parameters for DH.
3124 Given generator g, and prime number p, this function and sets DH
3125 context accordingly.
3127 If DhContext is NULL, then return FALSE.
3128 If Prime is NULL, then return FALSE.
3129 If this interface is not supported, then return FALSE.
3131 @param[in, out] DhContext Pointer to the DH context.
3132 @param[in] Generator Value of generator.
3133 @param[in] PrimeLength Length in bits of prime to be generated.
3134 @param[in] Prime Pointer to the prime number.
3136 @retval TRUE DH parameter setting succeeded.
3137 @retval FALSE Value of Generator is not supported.
3138 @retval FALSE Value of Generator is not suitable for the Prime.
3139 @retval FALSE Value of Prime is not a prime number.
3140 @retval FALSE Value of Prime is not a safe prime number.
3141 @retval FALSE This interface is not supported.
3146 CryptoServiceDhSetParameter (
3147 IN OUT VOID
*DhContext
,
3149 IN UINTN PrimeLength
,
3150 IN CONST UINT8
*Prime
3153 return CALL_BASECRYPTLIB (Dh
.Services
.SetParameter
, DhSetParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
3157 Generates DH public key.
3159 This function generates random secret exponent, and computes the public key, which is
3160 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
3161 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
3162 PublicKeySize is set to the required buffer size to obtain the public key.
3164 If DhContext is NULL, then return FALSE.
3165 If PublicKeySize is NULL, then return FALSE.
3166 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
3167 If this interface is not supported, then return FALSE.
3169 @param[in, out] DhContext Pointer to the DH context.
3170 @param[out] PublicKey Pointer to the buffer to receive generated public key.
3171 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
3172 On output, the size of data returned in PublicKey buffer in bytes.
3174 @retval TRUE DH public key generation succeeded.
3175 @retval FALSE DH public key generation failed.
3176 @retval FALSE PublicKeySize is not large enough.
3177 @retval FALSE This interface is not supported.
3182 CryptoServiceDhGenerateKey (
3183 IN OUT VOID
*DhContext
,
3184 OUT UINT8
*PublicKey
,
3185 IN OUT UINTN
*PublicKeySize
3188 return CALL_BASECRYPTLIB (Dh
.Services
.GenerateKey
, DhGenerateKey
, (DhContext
, PublicKey
, PublicKeySize
), FALSE
);
3192 Computes exchanged common key.
3194 Given peer's public key, this function computes the exchanged common key, based on its own
3195 context including value of prime modulus and random secret exponent.
3197 If DhContext is NULL, then return FALSE.
3198 If PeerPublicKey is NULL, then return FALSE.
3199 If KeySize is NULL, then return FALSE.
3200 If Key is NULL, then return FALSE.
3201 If KeySize is not large enough, then return FALSE.
3202 If this interface is not supported, then return FALSE.
3204 @param[in, out] DhContext Pointer to the DH context.
3205 @param[in] PeerPublicKey Pointer to the peer's public key.
3206 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
3207 @param[out] Key Pointer to the buffer to receive generated key.
3208 @param[in, out] KeySize On input, the size of Key buffer in bytes.
3209 On output, the size of data returned in Key buffer in bytes.
3211 @retval TRUE DH exchanged key generation succeeded.
3212 @retval FALSE DH exchanged key generation failed.
3213 @retval FALSE KeySize is not large enough.
3214 @retval FALSE This interface is not supported.
3219 CryptoServiceDhComputeKey (
3220 IN OUT VOID
*DhContext
,
3221 IN CONST UINT8
*PeerPublicKey
,
3222 IN UINTN PeerPublicKeySize
,
3224 IN OUT UINTN
*KeySize
3227 return CALL_BASECRYPTLIB (Dh
.Services
.ComputeKey
, DhComputeKey
, (DhContext
, PeerPublicKey
, PeerPublicKeySize
, Key
, KeySize
), FALSE
);
3230 //=====================================================================================
3231 // Pseudo-Random Generation Primitive
3232 //=====================================================================================
3235 Sets up the seed value for the pseudorandom number generator.
3237 This function sets up the seed value for the pseudorandom number generator.
3238 If Seed is not NULL, then the seed passed in is used.
3239 If Seed is NULL, then default seed is used.
3240 If this interface is not supported, then return FALSE.
3242 @param[in] Seed Pointer to seed value.
3243 If NULL, default seed is used.
3244 @param[in] SeedSize Size of seed value.
3245 If Seed is NULL, this parameter is ignored.
3247 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
3248 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
3249 @retval FALSE This interface is not supported.
3254 CryptoServiceRandomSeed (
3255 IN CONST UINT8
*Seed OPTIONAL
,
3259 return CALL_BASECRYPTLIB (Random
.Services
.Seed
, RandomSeed
, (Seed
, SeedSize
), FALSE
);
3263 Generates a pseudorandom byte stream of the specified size.
3265 If Output is NULL, then return FALSE.
3266 If this interface is not supported, then return FALSE.
3268 @param[out] Output Pointer to buffer to receive random value.
3269 @param[in] Size Size of random bytes to generate.
3271 @retval TRUE Pseudorandom byte stream generated successfully.
3272 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
3273 @retval FALSE This interface is not supported.
3278 CryptoServiceRandomBytes (
3283 return CALL_BASECRYPTLIB (Random
.Services
.Bytes
, RandomBytes
, (Output
, Size
), FALSE
);
3286 //=====================================================================================
3287 // Key Derivation Function Primitive
3288 //=====================================================================================
3291 Derive key data using HMAC-SHA256 based KDF.
3293 @param[in] Key Pointer to the user-supplied key.
3294 @param[in] KeySize Key size in bytes.
3295 @param[in] Salt Pointer to the salt(non-secret) value.
3296 @param[in] SaltSize Salt size in bytes.
3297 @param[in] Info Pointer to the application specific info.
3298 @param[in] InfoSize Info size in bytes.
3299 @param[out] Out Pointer to buffer to receive hkdf value.
3300 @param[in] OutSize Size of hkdf bytes to generate.
3302 @retval TRUE Hkdf generated successfully.
3303 @retval FALSE Hkdf generation failed.
3308 CryptoServiceHkdfSha256ExtractAndExpand (
3309 IN CONST UINT8
*Key
,
3311 IN CONST UINT8
*Salt
,
3313 IN CONST UINT8
*Info
,
3319 return CALL_BASECRYPTLIB (Hkdf
.Services
.Sha256ExtractAndExpand
, HkdfSha256ExtractAndExpand
, (Key
, KeySize
, Salt
, SaltSize
, Info
, InfoSize
, Out
, OutSize
), FALSE
);
3323 Initializes the OpenSSL library.
3325 This function registers ciphers and digests used directly and indirectly
3326 by SSL/TLS, and initializes the readable error messages.
3327 This function must be called before any other action takes places.
3329 @retval TRUE The OpenSSL library has been initialized.
3330 @retval FALSE Failed to initialize the OpenSSL library.
3335 CryptoServiceTlsInitialize (
3339 return CALL_BASECRYPTLIB (Tls
.Services
.Initialize
, TlsInitialize
, (), FALSE
);
3343 Free an allocated SSL_CTX object.
3345 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
3350 CryptoServiceTlsCtxFree (
3354 CALL_VOID_BASECRYPTLIB (Tls
.Services
.CtxFree
, TlsCtxFree
, (TlsCtx
));
3358 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
3361 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3362 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3364 @return Pointer to an allocated SSL_CTX object.
3365 If the creation failed, TlsCtxNew() returns NULL.
3370 CryptoServiceTlsCtxNew (
3375 return CALL_BASECRYPTLIB (Tls
.Services
.CtxNew
, TlsCtxNew
, (MajorVer
, MinorVer
), NULL
);
3379 Free an allocated TLS object.
3381 This function removes the TLS object pointed to by Tls and frees up the
3382 allocated memory. If Tls is NULL, nothing is done.
3384 @param[in] Tls Pointer to the TLS object to be freed.
3389 CryptoServiceTlsFree (
3393 CALL_VOID_BASECRYPTLIB (Tls
.Services
.Free
, TlsFree
, (Tls
));
3397 Create a new TLS object for a connection.
3399 This function creates a new TLS object for a connection. The new object
3400 inherits the setting of the underlying context TlsCtx: connection method,
3401 options, verification setting.
3403 @param[in] TlsCtx Pointer to the SSL_CTX object.
3405 @return Pointer to an allocated SSL object.
3406 If the creation failed, TlsNew() returns NULL.
3411 CryptoServiceTlsNew (
3415 return CALL_BASECRYPTLIB (Tls
.Services
.New
, TlsNew
, (TlsCtx
), NULL
);
3419 Checks if the TLS handshake was done.
3421 This function will check if the specified TLS handshake was done.
3423 @param[in] Tls Pointer to the TLS object for handshake state checking.
3425 @retval TRUE The TLS handshake was done.
3426 @retval FALSE The TLS handshake was not done.
3431 CryptoServiceTlsInHandshake (
3435 return CALL_BASECRYPTLIB (Tls
.Services
.InHandshake
, TlsInHandshake
, (Tls
), FALSE
);
3439 Perform a TLS/SSL handshake.
3441 This function will perform a TLS/SSL handshake.
3443 @param[in] Tls Pointer to the TLS object for handshake operation.
3444 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
3445 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3447 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3448 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3449 the buffer size provided by the caller. On output, it
3450 is the buffer size in fact needed to contain the
3453 @retval EFI_SUCCESS The required TLS packet is built successfully.
3454 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3456 BufferIn is NULL but BufferInSize is NOT 0.
3457 BufferInSize is 0 but BufferIn is NOT NULL.
3458 BufferOutSize is NULL.
3459 BufferOut is NULL if *BufferOutSize is not zero.
3460 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3461 @retval EFI_ABORTED Something wrong during handshake.
3466 CryptoServiceTlsDoHandshake (
3468 IN UINT8
*BufferIn
, OPTIONAL
3469 IN UINTN BufferInSize
, OPTIONAL
3470 OUT UINT8
*BufferOut
, OPTIONAL
3471 IN OUT UINTN
*BufferOutSize
3474 return CALL_BASECRYPTLIB (Tls
.Services
.DoHandshake
, TlsDoHandshake
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
3478 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
3479 TLS session has errors and the response packet needs to be Alert message based on error type.
3481 @param[in] Tls Pointer to the TLS object for state checking.
3482 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
3483 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3485 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3486 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3487 the buffer size provided by the caller. On output, it
3488 is the buffer size in fact needed to contain the
3491 @retval EFI_SUCCESS The required TLS packet is built successfully.
3492 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3494 BufferIn is NULL but BufferInSize is NOT 0.
3495 BufferInSize is 0 but BufferIn is NOT NULL.
3496 BufferOutSize is NULL.
3497 BufferOut is NULL if *BufferOutSize is not zero.
3498 @retval EFI_ABORTED An error occurred.
3499 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3504 CryptoServiceTlsHandleAlert (
3506 IN UINT8
*BufferIn
, OPTIONAL
3507 IN UINTN BufferInSize
, OPTIONAL
3508 OUT UINT8
*BufferOut
, OPTIONAL
3509 IN OUT UINTN
*BufferOutSize
3512 return CALL_BASECRYPTLIB (Tls
.Services
.HandleAlert
, TlsHandleAlert
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
3516 Build the CloseNotify packet.
3518 @param[in] Tls Pointer to the TLS object for state checking.
3519 @param[in, out] Buffer Pointer to the buffer to hold the built packet.
3520 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
3521 the buffer size provided by the caller. On output, it
3522 is the buffer size in fact needed to contain the
3525 @retval EFI_SUCCESS The required TLS packet is built successfully.
3526 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3529 Buffer is NULL if *BufferSize is not zero.
3530 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
3535 CryptoServiceTlsCloseNotify (
3537 IN OUT UINT8
*Buffer
,
3538 IN OUT UINTN
*BufferSize
3541 return CALL_BASECRYPTLIB (Tls
.Services
.CloseNotify
, TlsCloseNotify
, (Tls
, Buffer
, BufferSize
), EFI_UNSUPPORTED
);
3545 Attempts to read bytes from one TLS object and places the data in Buffer.
3547 This function will attempt to read BufferSize bytes from the TLS object
3548 and places the data in Buffer.
3550 @param[in] Tls Pointer to the TLS object.
3551 @param[in,out] Buffer Pointer to the buffer to store the data.
3552 @param[in] BufferSize The size of Buffer in bytes.
3554 @retval >0 The amount of data successfully read from the TLS object.
3555 @retval <=0 No data was successfully read.
3560 CryptoServiceTlsCtrlTrafficOut (
3562 IN OUT VOID
*Buffer
,
3566 return CALL_BASECRYPTLIB (Tls
.Services
.CtrlTrafficOut
, TlsCtrlTrafficOut
, (Tls
, Buffer
, BufferSize
), 0);
3570 Attempts to write data from the buffer to TLS object.
3572 This function will attempt to write BufferSize bytes data from the Buffer
3575 @param[in] Tls Pointer to the TLS object.
3576 @param[in] Buffer Pointer to the data buffer.
3577 @param[in] BufferSize The size of Buffer in bytes.
3579 @retval >0 The amount of data successfully written to the TLS object.
3580 @retval <=0 No data was successfully written.
3585 CryptoServiceTlsCtrlTrafficIn (
3591 return CALL_BASECRYPTLIB (Tls
.Services
.CtrlTrafficIn
, TlsCtrlTrafficIn
, (Tls
, Buffer
, BufferSize
), 0);
3595 Attempts to read bytes from the specified TLS connection into the buffer.
3597 This function tries to read BufferSize bytes data from the specified TLS
3598 connection into the Buffer.
3600 @param[in] Tls Pointer to the TLS connection for data reading.
3601 @param[in,out] Buffer Pointer to the data buffer.
3602 @param[in] BufferSize The size of Buffer in bytes.
3604 @retval >0 The read operation was successful, and return value is the
3605 number of bytes actually read from the TLS connection.
3606 @retval <=0 The read operation was not successful.
3611 CryptoServiceTlsRead (
3613 IN OUT VOID
*Buffer
,
3617 return CALL_BASECRYPTLIB (Tls
.Services
.Read
, TlsRead
, (Tls
, Buffer
, BufferSize
), 0);
3621 Attempts to write data to a TLS connection.
3623 This function tries to write BufferSize bytes data from the Buffer into the
3624 specified TLS connection.
3626 @param[in] Tls Pointer to the TLS connection for data writing.
3627 @param[in] Buffer Pointer to the data buffer.
3628 @param[in] BufferSize The size of Buffer in bytes.
3630 @retval >0 The write operation was successful, and return value is the
3631 number of bytes actually written to the TLS connection.
3632 @retval <=0 The write operation was not successful.
3637 CryptoServiceTlsWrite (
3643 return CALL_BASECRYPTLIB (Tls
.Services
.Write
, TlsWrite
, (Tls
, Buffer
, BufferSize
), 0);
3647 Set a new TLS/SSL method for a particular TLS object.
3649 This function sets a new TLS/SSL method for a particular TLS object.
3651 @param[in] Tls Pointer to a TLS object.
3652 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3653 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3655 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
3656 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3657 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
3662 CryptoServiceTlsSetVersion (
3668 return CALL_BASECRYPTLIB (TlsSet
.Services
.Version
, TlsSetVersion
, (Tls
, MajorVer
, MinorVer
), EFI_UNSUPPORTED
);
3672 Set TLS object to work in client or server mode.
3674 This function prepares a TLS object to work in client or server mode.
3676 @param[in] Tls Pointer to a TLS object.
3677 @param[in] IsServer Work in server mode.
3679 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
3680 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3681 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
3686 CryptoServiceTlsSetConnectionEnd (
3691 return CALL_BASECRYPTLIB (TlsSet
.Services
.ConnectionEnd
, TlsSetConnectionEnd
, (Tls
, IsServer
), EFI_UNSUPPORTED
);
3695 Set the ciphers list to be used by the TLS object.
3697 This function sets the ciphers for use by a specified TLS object.
3699 @param[in] Tls Pointer to a TLS object.
3700 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
3701 cipher identifier comes from the TLS Cipher Suite
3702 Registry of the IANA, interpreting Byte1 and Byte2
3703 in network (big endian) byte order.
3704 @param[in] CipherNum The number of cipher in the list.
3706 @retval EFI_SUCCESS The ciphers list was set successfully.
3707 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3708 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
3709 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
3714 CryptoServiceTlsSetCipherList (
3716 IN UINT16
*CipherId
,
3720 return CALL_BASECRYPTLIB (TlsSet
.Services
.CipherList
, TlsSetCipherList
, (Tls
, CipherId
, CipherNum
), EFI_UNSUPPORTED
);
3724 Set the compression method for TLS/SSL operations.
3726 This function handles TLS/SSL integrated compression methods.
3728 @param[in] CompMethod The compression method ID.
3730 @retval EFI_SUCCESS The compression method for the communication was
3732 @retval EFI_UNSUPPORTED Unsupported compression method.
3737 CryptoServiceTlsSetCompressionMethod (
3741 return CALL_BASECRYPTLIB (TlsSet
.Services
.CompressionMethod
, TlsSetCompressionMethod
, (CompMethod
), EFI_UNSUPPORTED
);
3745 Set peer certificate verification mode for the TLS connection.
3747 This function sets the verification mode flags for the TLS connection.
3749 @param[in] Tls Pointer to the TLS object.
3750 @param[in] VerifyMode A set of logically or'ed verification mode flags.
3755 CryptoServiceTlsSetVerify (
3757 IN UINT32 VerifyMode
3760 CALL_VOID_BASECRYPTLIB (TlsSet
.Services
.Verify
, TlsSetVerify
, (Tls
, VerifyMode
));
3764 Set the specified host name to be verified.
3766 @param[in] Tls Pointer to the TLS object.
3767 @param[in] Flags The setting flags during the validation.
3768 @param[in] HostName The specified host name to be verified.
3770 @retval EFI_SUCCESS The HostName setting was set successfully.
3771 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3772 @retval EFI_ABORTED Invalid HostName setting.
3777 CryptoServiceTlsSetVerifyHost (
3783 return CALL_BASECRYPTLIB (TlsSet
.Services
.VerifyHost
, TlsSetVerifyHost
, (Tls
, Flags
, HostName
), EFI_UNSUPPORTED
);
3787 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
3789 This function sets a session ID to be used when the TLS/SSL connection is
3792 @param[in] Tls Pointer to the TLS object.
3793 @param[in] SessionId Session ID data used for session resumption.
3794 @param[in] SessionIdLen Length of Session ID in bytes.
3796 @retval EFI_SUCCESS Session ID was set successfully.
3797 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3798 @retval EFI_UNSUPPORTED No available session for ID setting.
3803 CryptoServiceTlsSetSessionId (
3805 IN UINT8
*SessionId
,
3806 IN UINT16 SessionIdLen
3809 return CALL_BASECRYPTLIB (TlsSet
.Services
.SessionId
, TlsSetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
3813 Adds the CA to the cert store when requesting Server or Client authentication.
3815 This function adds the CA certificate to the list of CAs when requesting
3816 Server or Client authentication for the chosen TLS connection.
3818 @param[in] Tls Pointer to the TLS object.
3819 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3820 X.509 certificate or PEM-encoded X.509 certificate.
3821 @param[in] DataSize The size of data buffer in bytes.
3823 @retval EFI_SUCCESS The operation succeeded.
3824 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3825 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3826 @retval EFI_ABORTED Invalid X.509 certificate.
3831 CryptoServiceTlsSetCaCertificate (
3837 return CALL_BASECRYPTLIB (TlsSet
.Services
.CaCertificate
, TlsSetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3841 Loads the local public certificate into the specified TLS object.
3843 This function loads the X.509 certificate into the specified TLS object
3844 for TLS negotiation.
3846 @param[in] Tls Pointer to the TLS object.
3847 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3848 X.509 certificate or PEM-encoded X.509 certificate.
3849 @param[in] DataSize The size of data buffer in bytes.
3851 @retval EFI_SUCCESS The operation succeeded.
3852 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3853 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3854 @retval EFI_ABORTED Invalid X.509 certificate.
3859 CryptoServiceTlsSetHostPublicCert (
3865 return CALL_BASECRYPTLIB (TlsSet
.Services
.HostPublicCert
, TlsSetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3869 Adds the local private key to the specified TLS object.
3871 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
3872 key) into the specified TLS object for TLS negotiation.
3874 @param[in] Tls Pointer to the TLS object.
3875 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
3876 or PKCS#8 private key.
3877 @param[in] DataSize The size of data buffer in bytes.
3879 @retval EFI_SUCCESS The operation succeeded.
3880 @retval EFI_UNSUPPORTED This function is not supported.
3881 @retval EFI_ABORTED Invalid private key data.
3886 CryptoServiceTlsSetHostPrivateKey (
3892 return CALL_BASECRYPTLIB (TlsSet
.Services
.HostPrivateKey
, TlsSetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3896 Adds the CA-supplied certificate revocation list for certificate validation.
3898 This function adds the CA-supplied certificate revocation list data for
3899 certificate validity checking.
3901 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
3902 @param[in] DataSize The size of data buffer in bytes.
3904 @retval EFI_SUCCESS The operation succeeded.
3905 @retval EFI_UNSUPPORTED This function is not supported.
3906 @retval EFI_ABORTED Invalid CRL data.
3911 CryptoServiceTlsSetCertRevocationList (
3916 return CALL_BASECRYPTLIB (TlsSet
.Services
.CertRevocationList
, TlsSetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);
3920 Gets the protocol version used by the specified TLS connection.
3922 This function returns the protocol version used by the specified TLS
3925 If Tls is NULL, then ASSERT().
3927 @param[in] Tls Pointer to the TLS object.
3929 @return The protocol version of the specified TLS connection.
3934 CryptoServiceTlsGetVersion (
3938 return CALL_BASECRYPTLIB (TlsGet
.Services
.Version
, TlsGetVersion
, (Tls
), 0);
3942 Gets the connection end of the specified TLS connection.
3944 This function returns the connection end (as client or as server) used by
3945 the specified TLS connection.
3947 If Tls is NULL, then ASSERT().
3949 @param[in] Tls Pointer to the TLS object.
3951 @return The connection end used by the specified TLS connection.
3956 CryptoServiceTlsGetConnectionEnd (
3960 return CALL_BASECRYPTLIB (TlsGet
.Services
.ConnectionEnd
, TlsGetConnectionEnd
, (Tls
), 0);
3964 Gets the cipher suite used by the specified TLS connection.
3966 This function returns current cipher suite used by the specified
3969 @param[in] Tls Pointer to the TLS object.
3970 @param[in,out] CipherId The cipher suite used by the TLS object.
3972 @retval EFI_SUCCESS The cipher suite was returned successfully.
3973 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3974 @retval EFI_UNSUPPORTED Unsupported cipher suite.
3979 CryptoServiceTlsGetCurrentCipher (
3981 IN OUT UINT16
*CipherId
3984 return CALL_BASECRYPTLIB (TlsGet
.Services
.CurrentCipher
, TlsGetCurrentCipher
, (Tls
, CipherId
), EFI_UNSUPPORTED
);
3988 Gets the compression methods used by the specified TLS connection.
3990 This function returns current integrated compression methods used by
3991 the specified TLS connection.
3993 @param[in] Tls Pointer to the TLS object.
3994 @param[in,out] CompressionId The current compression method used by
3997 @retval EFI_SUCCESS The compression method was returned successfully.
3998 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3999 @retval EFI_ABORTED Invalid Compression method.
4000 @retval EFI_UNSUPPORTED This function is not supported.
4005 CryptoServiceTlsGetCurrentCompressionId (
4007 IN OUT UINT8
*CompressionId
4010 return CALL_BASECRYPTLIB (TlsGet
.Services
.CurrentCompressionId
, TlsGetCurrentCompressionId
, (Tls
, CompressionId
), EFI_UNSUPPORTED
);
4014 Gets the verification mode currently set in the TLS connection.
4016 This function returns the peer verification mode currently set in the
4017 specified TLS connection.
4019 If Tls is NULL, then ASSERT().
4021 @param[in] Tls Pointer to the TLS object.
4023 @return The verification mode set in the specified TLS connection.
4028 CryptoServiceTlsGetVerify (
4032 return CALL_BASECRYPTLIB (TlsGet
.Services
.Verify
, TlsGetVerify
, (Tls
), 0);
4036 Gets the session ID used by the specified TLS connection.
4038 This function returns the TLS/SSL session ID currently used by the
4039 specified TLS connection.
4041 @param[in] Tls Pointer to the TLS object.
4042 @param[in,out] SessionId Buffer to contain the returned session ID.
4043 @param[in,out] SessionIdLen The length of Session ID in bytes.
4045 @retval EFI_SUCCESS The Session ID was returned successfully.
4046 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4047 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
4052 CryptoServiceTlsGetSessionId (
4054 IN OUT UINT8
*SessionId
,
4055 IN OUT UINT16
*SessionIdLen
4058 return CALL_BASECRYPTLIB (TlsGet
.Services
.SessionId
, TlsGetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
4062 Gets the client random data used in the specified TLS connection.
4064 This function returns the TLS/SSL client random data currently used in
4065 the specified TLS connection.
4067 @param[in] Tls Pointer to the TLS object.
4068 @param[in,out] ClientRandom Buffer to contain the returned client
4069 random data (32 bytes).
4074 CryptoServiceTlsGetClientRandom (
4076 IN OUT UINT8
*ClientRandom
4079 CALL_VOID_BASECRYPTLIB (TlsGet
.Services
.ClientRandom
, TlsGetClientRandom
, (Tls
, ClientRandom
));
4083 Gets the server random data used in the specified TLS connection.
4085 This function returns the TLS/SSL server random data currently used in
4086 the specified TLS connection.
4088 @param[in] Tls Pointer to the TLS object.
4089 @param[in,out] ServerRandom Buffer to contain the returned server
4090 random data (32 bytes).
4095 CryptoServiceTlsGetServerRandom (
4097 IN OUT UINT8
*ServerRandom
4100 CALL_VOID_BASECRYPTLIB (TlsGet
.Services
.ServerRandom
, TlsGetServerRandom
, (Tls
, ServerRandom
));
4104 Gets the master key data used in the specified TLS connection.
4106 This function returns the TLS/SSL master key material currently used in
4107 the specified TLS connection.
4109 @param[in] Tls Pointer to the TLS object.
4110 @param[in,out] KeyMaterial Buffer to contain the returned key material.
4112 @retval EFI_SUCCESS Key material was returned successfully.
4113 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4114 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
4119 CryptoServiceTlsGetKeyMaterial (
4121 IN OUT UINT8
*KeyMaterial
4124 return CALL_BASECRYPTLIB (TlsGet
.Services
.KeyMaterial
, TlsGetKeyMaterial
, (Tls
, KeyMaterial
), EFI_UNSUPPORTED
);
4128 Gets the CA Certificate from the cert store.
4130 This function returns the CA certificate for the chosen
4133 @param[in] Tls Pointer to the TLS object.
4134 @param[out] Data Pointer to the data buffer to receive the CA
4135 certificate data sent to the client.
4136 @param[in,out] DataSize The size of data buffer in bytes.
4138 @retval EFI_SUCCESS The operation succeeded.
4139 @retval EFI_UNSUPPORTED This function is not supported.
4140 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4145 CryptoServiceTlsGetCaCertificate (
4148 IN OUT UINTN
*DataSize
4151 return CALL_BASECRYPTLIB (TlsGet
.Services
.CaCertificate
, TlsGetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4155 Gets the local public Certificate set in the specified TLS object.
4157 This function returns the local public certificate which was currently set
4158 in the specified TLS object.
4160 @param[in] Tls Pointer to the TLS object.
4161 @param[out] Data Pointer to the data buffer to receive the local
4163 @param[in,out] DataSize The size of data buffer in bytes.
4165 @retval EFI_SUCCESS The operation succeeded.
4166 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4167 @retval EFI_NOT_FOUND The certificate is not found.
4168 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4173 CryptoServiceTlsGetHostPublicCert (
4176 IN OUT UINTN
*DataSize
4179 return CALL_BASECRYPTLIB (TlsGet
.Services
.HostPublicCert
, TlsGetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4183 Gets the local private key set in the specified TLS object.
4185 This function returns the local private key data which was currently set
4186 in the specified TLS object.
4188 @param[in] Tls Pointer to the TLS object.
4189 @param[out] Data Pointer to the data buffer to receive the local
4191 @param[in,out] DataSize The size of data buffer in bytes.
4193 @retval EFI_SUCCESS The operation succeeded.
4194 @retval EFI_UNSUPPORTED This function is not supported.
4195 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4200 CryptoServiceTlsGetHostPrivateKey (
4203 IN OUT UINTN
*DataSize
4206 return CALL_BASECRYPTLIB (TlsGet
.Services
.HostPrivateKey
, TlsGetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4210 Gets the CA-supplied certificate revocation list data set in the specified
4213 This function returns the CA-supplied certificate revocation list data which
4214 was currently set in the specified TLS object.
4216 @param[out] Data Pointer to the data buffer to receive the CRL data.
4217 @param[in,out] DataSize The size of data buffer in bytes.
4219 @retval EFI_SUCCESS The operation succeeded.
4220 @retval EFI_UNSUPPORTED This function is not supported.
4221 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4226 CryptoServiceTlsGetCertRevocationList (
4228 IN OUT UINTN
*DataSize
4231 return CALL_BASECRYPTLIB (TlsGet
.Services
.CertRevocationList
, TlsGetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);
4234 const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto
= {
4236 CryptoServiceGetCryptoVersion
,
4238 CryptoServiceHmacMd5New
,
4239 CryptoServiceHmacMd5Free
,
4240 CryptoServiceHmacMd5SetKey
,
4241 CryptoServiceHmacMd5Duplicate
,
4242 CryptoServiceHmacMd5Update
,
4243 CryptoServiceHmacMd5Final
,
4245 CryptoServiceHmacSha1New
,
4246 CryptoServiceHmacSha1Free
,
4247 CryptoServiceHmacSha1SetKey
,
4248 CryptoServiceHmacSha1Duplicate
,
4249 CryptoServiceHmacSha1Update
,
4250 CryptoServiceHmacSha1Final
,
4252 CryptoServiceHmacSha256New
,
4253 CryptoServiceHmacSha256Free
,
4254 CryptoServiceHmacSha256SetKey
,
4255 CryptoServiceHmacSha256Duplicate
,
4256 CryptoServiceHmacSha256Update
,
4257 CryptoServiceHmacSha256Final
,
4258 /// Md4 - deprecated and unsupported
4259 DeprecatedCryptoServiceMd4GetContextSize
,
4260 DeprecatedCryptoServiceMd4Init
,
4261 DeprecatedCryptoServiceMd4Duplicate
,
4262 DeprecatedCryptoServiceMd4Update
,
4263 DeprecatedCryptoServiceMd4Final
,
4264 DeprecatedCryptoServiceMd4HashAll
,
4266 CryptoServiceMd5GetContextSize
,
4267 CryptoServiceMd5Init
,
4268 CryptoServiceMd5Duplicate
,
4269 CryptoServiceMd5Update
,
4270 CryptoServiceMd5Final
,
4271 CryptoServiceMd5HashAll
,
4273 CryptoServicePkcs1v2Encrypt
,
4274 CryptoServicePkcs5HashPassword
,
4275 CryptoServicePkcs7Verify
,
4276 CryptoServiceVerifyEKUsInPkcs7Signature
,
4277 CryptoServicePkcs7GetSigners
,
4278 CryptoServicePkcs7FreeSigners
,
4279 CryptoServicePkcs7Sign
,
4280 CryptoServicePkcs7GetAttachedContent
,
4281 CryptoServicePkcs7GetCertificatesList
,
4282 CryptoServiceAuthenticodeVerify
,
4283 CryptoServiceImageTimestampVerify
,
4286 CryptoServiceDhFree
,
4287 CryptoServiceDhGenerateParameter
,
4288 CryptoServiceDhSetParameter
,
4289 CryptoServiceDhGenerateKey
,
4290 CryptoServiceDhComputeKey
,
4292 CryptoServiceRandomSeed
,
4293 CryptoServiceRandomBytes
,
4295 CryptoServiceRsaPkcs1Verify
,
4296 CryptoServiceRsaNew
,
4297 CryptoServiceRsaFree
,
4298 CryptoServiceRsaSetKey
,
4299 CryptoServiceRsaGetKey
,
4300 CryptoServiceRsaGenerateKey
,
4301 CryptoServiceRsaCheckKey
,
4302 CryptoServiceRsaPkcs1Sign
,
4303 CryptoServiceRsaPkcs1Verify
,
4304 CryptoServiceRsaGetPrivateKeyFromPem
,
4305 CryptoServiceRsaGetPublicKeyFromX509
,
4307 CryptoServiceSha1GetContextSize
,
4308 CryptoServiceSha1Init
,
4309 CryptoServiceSha1Duplicate
,
4310 CryptoServiceSha1Update
,
4311 CryptoServiceSha1Final
,
4312 CryptoServiceSha1HashAll
,
4314 CryptoServiceSha256GetContextSize
,
4315 CryptoServiceSha256Init
,
4316 CryptoServiceSha256Duplicate
,
4317 CryptoServiceSha256Update
,
4318 CryptoServiceSha256Final
,
4319 CryptoServiceSha256HashAll
,
4321 CryptoServiceSha384GetContextSize
,
4322 CryptoServiceSha384Init
,
4323 CryptoServiceSha384Duplicate
,
4324 CryptoServiceSha384Update
,
4325 CryptoServiceSha384Final
,
4326 CryptoServiceSha384HashAll
,
4328 CryptoServiceSha512GetContextSize
,
4329 CryptoServiceSha512Init
,
4330 CryptoServiceSha512Duplicate
,
4331 CryptoServiceSha512Update
,
4332 CryptoServiceSha512Final
,
4333 CryptoServiceSha512HashAll
,
4335 CryptoServiceX509GetSubjectName
,
4336 CryptoServiceX509GetCommonName
,
4337 CryptoServiceX509GetOrganizationName
,
4338 CryptoServiceX509VerifyCert
,
4339 CryptoServiceX509ConstructCertificate
,
4340 CryptoServiceX509ConstructCertificateStack
,
4341 CryptoServiceX509Free
,
4342 CryptoServiceX509StackFree
,
4343 CryptoServiceX509GetTBSCert
,
4344 /// TDES - deprecated and unsupported
4345 DeprecatedCryptoServiceTdesGetContextSize
,
4346 DeprecatedCryptoServiceTdesInit
,
4347 DeprecatedCryptoServiceTdesEcbEncrypt
,
4348 DeprecatedCryptoServiceTdesEcbDecrypt
,
4349 DeprecatedCryptoServiceTdesCbcEncrypt
,
4350 DeprecatedCryptoServiceTdesCbcDecrypt
,
4351 /// AES - ECB mode is deprecated and unsupported
4352 CryptoServiceAesGetContextSize
,
4353 CryptoServiceAesInit
,
4354 DeprecatedCryptoServiceAesEcbEncrypt
,
4355 DeprecatedCryptoServiceAesEcbDecrypt
,
4356 CryptoServiceAesCbcEncrypt
,
4357 CryptoServiceAesCbcDecrypt
,
4358 /// Arc4 - deprecated and unsupported
4359 DeprecatedCryptoServiceArc4GetContextSize
,
4360 DeprecatedCryptoServiceArc4Init
,
4361 DeprecatedCryptoServiceArc4Encrypt
,
4362 DeprecatedCryptoServiceArc4Decrypt
,
4363 DeprecatedCryptoServiceArc4Reset
,
4365 CryptoServiceSm3GetContextSize
,
4366 CryptoServiceSm3Init
,
4367 CryptoServiceSm3Duplicate
,
4368 CryptoServiceSm3Update
,
4369 CryptoServiceSm3Final
,
4370 CryptoServiceSm3HashAll
,
4372 CryptoServiceHkdfSha256ExtractAndExpand
,
4373 /// X509 (Continued)
4374 CryptoServiceX509ConstructCertificateStackV
,
4376 CryptoServiceTlsInitialize
,
4377 CryptoServiceTlsCtxFree
,
4378 CryptoServiceTlsCtxNew
,
4379 CryptoServiceTlsFree
,
4380 CryptoServiceTlsNew
,
4381 CryptoServiceTlsInHandshake
,
4382 CryptoServiceTlsDoHandshake
,
4383 CryptoServiceTlsHandleAlert
,
4384 CryptoServiceTlsCloseNotify
,
4385 CryptoServiceTlsCtrlTrafficOut
,
4386 CryptoServiceTlsCtrlTrafficIn
,
4387 CryptoServiceTlsRead
,
4388 CryptoServiceTlsWrite
,
4390 CryptoServiceTlsSetVersion
,
4391 CryptoServiceTlsSetConnectionEnd
,
4392 CryptoServiceTlsSetCipherList
,
4393 CryptoServiceTlsSetCompressionMethod
,
4394 CryptoServiceTlsSetVerify
,
4395 CryptoServiceTlsSetVerifyHost
,
4396 CryptoServiceTlsSetSessionId
,
4397 CryptoServiceTlsSetCaCertificate
,
4398 CryptoServiceTlsSetHostPublicCert
,
4399 CryptoServiceTlsSetHostPrivateKey
,
4400 CryptoServiceTlsSetCertRevocationList
,
4402 CryptoServiceTlsGetVersion
,
4403 CryptoServiceTlsGetConnectionEnd
,
4404 CryptoServiceTlsGetCurrentCipher
,
4405 CryptoServiceTlsGetCurrentCompressionId
,
4406 CryptoServiceTlsGetVerify
,
4407 CryptoServiceTlsGetSessionId
,
4408 CryptoServiceTlsGetClientRandom
,
4409 CryptoServiceTlsGetServerRandom
,
4410 CryptoServiceTlsGetKeyMaterial
,
4411 CryptoServiceTlsGetCaCertificate
,
4412 CryptoServiceTlsGetHostPublicCert
,
4413 CryptoServiceTlsGetHostPrivateKey
,
4414 CryptoServiceTlsGetCertRevocationList