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 HMAC MD5 is deprecated and unsupported any longer.
1164 Keep the function field for binary compability.
1166 @retval NULL This interface is not supported.
1171 DeprecatedCryptoServiceHmacMd5New (
1175 return BaseCryptLibServiceDeprecated ("HmacMd5New"), NULL
;
1179 HMAC MD5 is deprecated and unsupported any longer.
1180 Keep the function field for binary compability.
1182 @param[in] HmacMd5Ctx Pointer to the HMAC_CTX context to be released.
1187 DeprecatedCryptoServiceHmacMd5Free (
1191 BaseCryptLibServiceDeprecated ("HmacMd5Free");
1195 HMAC MD5 is deprecated and unsupported any longer.
1196 Keep the function field for binary compability.
1198 @param[out] HmacMd5Context Pointer to HMAC-MD5 context.
1199 @param[in] Key Pointer to the user-supplied key.
1200 @param[in] KeySize Key size in bytes.
1202 @retval FALSE This interface is not supported.
1207 DeprecatedCryptoServiceHmacMd5SetKey (
1208 OUT VOID
*HmacMd5Context
,
1209 IN CONST UINT8
*Key
,
1213 return BaseCryptLibServiceDeprecated ("HmacMd5SetKey"), FALSE
;
1217 HMAC MD5 is deprecated and unsupported any longer.
1218 Keep the function field for binary compability.
1220 @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied.
1221 @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context.
1223 @retval FALSE This interface is not supported.
1228 DeprecatedCryptoServiceHmacMd5Duplicate (
1229 IN CONST VOID
*HmacMd5Context
,
1230 OUT VOID
*NewHmacMd5Context
1233 return BaseCryptLibServiceDeprecated ("HmacMd5Duplicate"), FALSE
;
1237 HMAC MD5 is deprecated and unsupported any longer.
1238 Keep the function field for binary compability.
1240 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
1241 @param[in] Data Pointer to the buffer containing the data to be digested.
1242 @param[in] DataSize Size of Data buffer in bytes.
1244 @retval FALSE This interface is not supported.
1249 DeprecatedCryptoServiceHmacMd5Update (
1250 IN OUT VOID
*HmacMd5Context
,
1251 IN CONST VOID
*Data
,
1255 return BaseCryptLibServiceDeprecated ("HmacMd5Update"), FALSE
;
1259 HMAC MD5 is deprecated and unsupported any longer.
1260 Keep the function field for binary compability.
1262 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
1263 @param[out] HmacValue Pointer to a buffer that receives the HMAC-MD5 digest
1266 @retval FALSE This interface is not supported.
1271 DeprecatedCryptoServiceHmacMd5Final (
1272 IN OUT VOID
*HmacMd5Context
,
1273 OUT UINT8
*HmacValue
1276 return BaseCryptLibServiceDeprecated ("HmacMd5Final"), FALSE
;
1280 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA1 use.
1282 If this interface is not supported, then return NULL.
1284 @return Pointer to the HMAC_CTX context that has been initialized.
1285 If the allocations fails, HmacSha1New() returns NULL.
1286 @return NULL This interface is not supported.
1291 CryptoServiceHmacSha1New (
1295 return CALL_BASECRYPTLIB (HmacSha1
.Services
.New
, HmacSha1New
, (), NULL
);
1299 Release the specified HMAC_CTX context.
1301 If this interface is not supported, then do nothing.
1303 @param[in] HmacSha1Ctx Pointer to the HMAC_CTX context to be released.
1308 CryptoServiceHmacSha1Free (
1309 IN VOID
*HmacSha1Ctx
1312 CALL_VOID_BASECRYPTLIB (HmacSha1
.Services
.Free
, HmacSha1Free
, (HmacSha1Ctx
));
1316 Set user-supplied key for subsequent use. It must be done before any
1317 calling to HmacSha1Update().
1319 If HmacSha1Context is NULL, then return FALSE.
1320 If this interface is not supported, then return FALSE.
1322 @param[out] HmacSha1Context Pointer to HMAC-SHA1 context.
1323 @param[in] Key Pointer to the user-supplied key.
1324 @param[in] KeySize Key size in bytes.
1326 @retval TRUE The Key is set successfully.
1327 @retval FALSE The Key is set unsuccessfully.
1328 @retval FALSE This interface is not supported.
1333 CryptoServiceHmacSha1SetKey (
1334 OUT VOID
*HmacSha1Context
,
1335 IN CONST UINT8
*Key
,
1339 return CALL_BASECRYPTLIB (HmacSha1
.Services
.SetKey
, HmacSha1SetKey
, (HmacSha1Context
, Key
, KeySize
), FALSE
);
1343 Makes a copy of an existing HMAC-SHA1 context.
1345 If HmacSha1Context is NULL, then return FALSE.
1346 If NewHmacSha1Context is NULL, then return FALSE.
1347 If this interface is not supported, then return FALSE.
1349 @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied.
1350 @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context.
1352 @retval TRUE HMAC-SHA1 context copy succeeded.
1353 @retval FALSE HMAC-SHA1 context copy failed.
1354 @retval FALSE This interface is not supported.
1359 CryptoServiceHmacSha1Duplicate (
1360 IN CONST VOID
*HmacSha1Context
,
1361 OUT VOID
*NewHmacSha1Context
1364 return CALL_BASECRYPTLIB (HmacSha1
.Services
.Duplicate
, HmacSha1Duplicate
, (HmacSha1Context
, NewHmacSha1Context
), FALSE
);
1368 Digests the input data and updates HMAC-SHA1 context.
1370 This function performs HMAC-SHA1 digest on a data buffer of the specified size.
1371 It can be called multiple times to compute the digest of long or discontinuous data streams.
1372 HMAC-SHA1 context should be initialized by HmacSha1New(), and should not be finalized by
1373 HmacSha1Final(). Behavior with invalid context is undefined.
1375 If HmacSha1Context is NULL, then return FALSE.
1376 If this interface is not supported, then return FALSE.
1378 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1379 @param[in] Data Pointer to the buffer containing the data to be digested.
1380 @param[in] DataSize Size of Data buffer in bytes.
1382 @retval TRUE HMAC-SHA1 data digest succeeded.
1383 @retval FALSE HMAC-SHA1 data digest failed.
1384 @retval FALSE This interface is not supported.
1389 CryptoServiceHmacSha1Update (
1390 IN OUT VOID
*HmacSha1Context
,
1391 IN CONST VOID
*Data
,
1395 return CALL_BASECRYPTLIB (HmacSha1
.Services
.Update
, HmacSha1Update
, (HmacSha1Context
, Data
, DataSize
), FALSE
);
1399 Completes computation of the HMAC-SHA1 digest value.
1401 This function completes HMAC-SHA1 hash computation and retrieves the digest value into
1402 the specified memory. After this function has been called, the HMAC-SHA1 context cannot
1404 HMAC-SHA1 context should be initialized by HmacSha1New(), and should not be finalized
1405 by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined.
1407 If HmacSha1Context is NULL, then return FALSE.
1408 If HmacValue is NULL, then return FALSE.
1409 If this interface is not supported, then return FALSE.
1411 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1412 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA1 digest
1415 @retval TRUE HMAC-SHA1 digest computation succeeded.
1416 @retval FALSE HMAC-SHA1 digest computation failed.
1417 @retval FALSE This interface is not supported.
1422 CryptoServiceHmacSha1Final (
1423 IN OUT VOID
*HmacSha1Context
,
1424 OUT UINT8
*HmacValue
1427 return CALL_BASECRYPTLIB (HmacSha1
.Services
.Final
, HmacSha1Final
, (HmacSha1Context
, HmacValue
), FALSE
);
1431 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
1433 @return Pointer to the HMAC_CTX context that has been initialized.
1434 If the allocations fails, HmacSha256New() returns NULL.
1439 CryptoServiceHmacSha256New (
1443 return CALL_BASECRYPTLIB (HmacSha256
.Services
.New
, HmacSha256New
, (), NULL
);
1447 Release the specified HMAC_CTX context.
1449 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.
1454 CryptoServiceHmacSha256Free (
1455 IN VOID
*HmacSha256Ctx
1458 CALL_VOID_BASECRYPTLIB (HmacSha256
.Services
.Free
, HmacSha256Free
, (HmacSha256Ctx
));
1462 Set user-supplied key for subsequent use. It must be done before any
1463 calling to HmacSha256Update().
1465 If HmacSha256Context is NULL, then return FALSE.
1466 If this interface is not supported, then return FALSE.
1468 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.
1469 @param[in] Key Pointer to the user-supplied key.
1470 @param[in] KeySize Key size in bytes.
1472 @retval TRUE The Key is set successfully.
1473 @retval FALSE The Key is set unsuccessfully.
1474 @retval FALSE This interface is not supported.
1479 CryptoServiceHmacSha256SetKey (
1480 OUT VOID
*HmacSha256Context
,
1481 IN CONST UINT8
*Key
,
1485 return CALL_BASECRYPTLIB (HmacSha256
.Services
.SetKey
, HmacSha256SetKey
, (HmacSha256Context
, Key
, KeySize
), FALSE
);
1489 Makes a copy of an existing HMAC-SHA256 context.
1491 If HmacSha256Context is NULL, then return FALSE.
1492 If NewHmacSha256Context is NULL, then return FALSE.
1493 If this interface is not supported, then return FALSE.
1495 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.
1496 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.
1498 @retval TRUE HMAC-SHA256 context copy succeeded.
1499 @retval FALSE HMAC-SHA256 context copy failed.
1500 @retval FALSE This interface is not supported.
1505 CryptoServiceHmacSha256Duplicate (
1506 IN CONST VOID
*HmacSha256Context
,
1507 OUT VOID
*NewHmacSha256Context
1510 return CALL_BASECRYPTLIB (HmacSha256
.Services
.Duplicate
, HmacSha256Duplicate
, (HmacSha256Context
, NewHmacSha256Context
), FALSE
);
1514 Digests the input data and updates HMAC-SHA256 context.
1516 This function performs HMAC-SHA256 digest on a data buffer of the specified size.
1517 It can be called multiple times to compute the digest of long or discontinuous data streams.
1518 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1519 by HmacSha256Final(). Behavior with invalid context is undefined.
1521 If HmacSha256Context is NULL, then return FALSE.
1522 If this interface is not supported, then return FALSE.
1524 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1525 @param[in] Data Pointer to the buffer containing the data to be digested.
1526 @param[in] DataSize Size of Data buffer in bytes.
1528 @retval TRUE HMAC-SHA256 data digest succeeded.
1529 @retval FALSE HMAC-SHA256 data digest failed.
1530 @retval FALSE This interface is not supported.
1535 CryptoServiceHmacSha256Update (
1536 IN OUT VOID
*HmacSha256Context
,
1537 IN CONST VOID
*Data
,
1541 return CALL_BASECRYPTLIB (HmacSha256
.Services
.Update
, HmacSha256Update
, (HmacSha256Context
, Data
, DataSize
), FALSE
);
1545 Completes computation of the HMAC-SHA256 digest value.
1547 This function completes HMAC-SHA256 hash computation and retrieves the digest value into
1548 the specified memory. After this function has been called, the HMAC-SHA256 context cannot
1550 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1551 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.
1553 If HmacSha256Context is NULL, then return FALSE.
1554 If HmacValue is NULL, then return FALSE.
1555 If this interface is not supported, then return FALSE.
1557 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1558 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
1561 @retval TRUE HMAC-SHA256 digest computation succeeded.
1562 @retval FALSE HMAC-SHA256 digest computation failed.
1563 @retval FALSE This interface is not supported.
1568 CryptoServiceHmacSha256Final (
1569 IN OUT VOID
*HmacSha256Context
,
1570 OUT UINT8
*HmacValue
1573 return CALL_BASECRYPTLIB (HmacSha256
.Services
.Final
, HmacSha256Final
, (HmacSha256Context
, HmacValue
), FALSE
);
1576 //=====================================================================================
1577 // Symmetric Cryptography Primitive
1578 //=====================================================================================
1581 TDES is deprecated and unsupported any longer.
1582 Keep the function field for binary compability.
1584 @retval 0 This interface is not supported.
1589 DeprecatedCryptoServiceTdesGetContextSize (
1593 return BaseCryptLibServiceDeprecated ("TdesGetContextSize"), 0;
1597 TDES is deprecated and unsupported any longer.
1598 Keep the function field for binary compability.
1600 @param[out] TdesContext Pointer to TDES context being initialized.
1601 @param[in] Key Pointer to the user-supplied TDES key.
1602 @param[in] KeyLength Length of TDES key in bits.
1604 @retval FALSE This interface is not supported.
1609 DeprecatedCryptoServiceTdesInit (
1610 OUT VOID
*TdesContext
,
1611 IN CONST UINT8
*Key
,
1615 return BaseCryptLibServiceDeprecated ("TdesInit"), FALSE
;
1619 TDES is deprecated and unsupported any longer.
1620 Keep the function field for binary compability.
1622 @param[in] TdesContext Pointer to the TDES context.
1623 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1624 @param[in] InputSize Size of the Input buffer in bytes.
1625 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1627 @retval FALSE This interface is not supported.
1632 DeprecatedCryptoServiceTdesEcbEncrypt (
1633 IN VOID
*TdesContext
,
1634 IN CONST UINT8
*Input
,
1639 return BaseCryptLibServiceDeprecated ("TdesEcbEncrypt"), FALSE
;
1643 TDES is deprecated and unsupported any longer.
1644 Keep the function field for binary compability.
1646 @param[in] TdesContext Pointer to the TDES context.
1647 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1648 @param[in] InputSize Size of the Input buffer in bytes.
1649 @param[out] Output Pointer to a buffer that receives the TDES decryption output.
1651 @retval FALSE This interface is not supported.
1656 DeprecatedCryptoServiceTdesEcbDecrypt (
1657 IN VOID
*TdesContext
,
1658 IN CONST UINT8
*Input
,
1663 return BaseCryptLibServiceDeprecated ("TdesEcbDecrypt"), FALSE
;
1667 TDES is deprecated and unsupported any longer.
1668 Keep the function field for binary compability.
1670 @param[in] TdesContext Pointer to the TDES context.
1671 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1672 @param[in] InputSize Size of the Input buffer in bytes.
1673 @param[in] Ivec Pointer to initialization vector.
1674 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1676 @retval FALSE This interface is not supported.
1681 DeprecatedCryptoServiceTdesCbcEncrypt (
1682 IN VOID
*TdesContext
,
1683 IN CONST UINT8
*Input
,
1685 IN CONST UINT8
*Ivec
,
1689 return BaseCryptLibServiceDeprecated ("TdesCbcEncrypt"), FALSE
;
1693 TDES is deprecated and unsupported any longer.
1694 Keep the function field for binary compability.
1696 @param[in] TdesContext Pointer to the TDES context.
1697 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1698 @param[in] InputSize Size of the Input buffer in bytes.
1699 @param[in] Ivec Pointer to initialization vector.
1700 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1702 @retval FALSE This interface is not supported.
1707 DeprecatedCryptoServiceTdesCbcDecrypt (
1708 IN VOID
*TdesContext
,
1709 IN CONST UINT8
*Input
,
1711 IN CONST UINT8
*Ivec
,
1715 return BaseCryptLibServiceDeprecated ("TdesCbcDecrypt"), FALSE
;
1719 Retrieves the size, in bytes, of the context buffer required for AES operations.
1721 If this interface is not supported, then return zero.
1723 @return The size, in bytes, of the context buffer required for AES operations.
1724 @retval 0 This interface is not supported.
1729 CryptoServiceAesGetContextSize (
1733 return CALL_BASECRYPTLIB (Aes
.Services
.GetContextSize
, AesGetContextSize
, (), 0);
1737 Initializes user-supplied memory as AES context for subsequent use.
1739 This function initializes user-supplied memory pointed by AesContext as AES context.
1740 In addition, it sets up all AES key materials for subsequent encryption and decryption
1742 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1744 If AesContext is NULL, then return FALSE.
1745 If Key is NULL, then return FALSE.
1746 If KeyLength is not valid, then return FALSE.
1747 If this interface is not supported, then return FALSE.
1749 @param[out] AesContext Pointer to AES context being initialized.
1750 @param[in] Key Pointer to the user-supplied AES key.
1751 @param[in] KeyLength Length of AES key in bits.
1753 @retval TRUE AES context initialization succeeded.
1754 @retval FALSE AES context initialization failed.
1755 @retval FALSE This interface is not supported.
1760 CryptoServiceAesInit (
1761 OUT VOID
*AesContext
,
1762 IN CONST UINT8
*Key
,
1766 return CALL_BASECRYPTLIB (Aes
.Services
.Init
, AesInit
, (AesContext
, Key
, KeyLength
), FALSE
);
1770 AES ECB Mode is deprecated and unsupported any longer.
1771 Keep the function field for binary compability.
1773 @param[in] AesContext Pointer to the AES context.
1774 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1775 @param[in] InputSize Size of the Input buffer in bytes.
1776 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1778 @retval FALSE This interface is not supported.
1783 DeprecatedCryptoServiceAesEcbEncrypt (
1784 IN VOID
*AesContext
,
1785 IN CONST UINT8
*Input
,
1790 return BaseCryptLibServiceDeprecated ("AesEcbEncrypt"), FALSE
;
1794 AES ECB Mode is deprecated and unsupported any longer.
1795 Keep the function field for binary compability.
1797 @param[in] AesContext Pointer to the AES context.
1798 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1799 @param[in] InputSize Size of the Input buffer in bytes.
1800 @param[out] Output Pointer to a buffer that receives the AES decryption output.
1802 @retval FALSE This interface is not supported.
1807 DeprecatedCryptoServiceAesEcbDecrypt (
1808 IN VOID
*AesContext
,
1809 IN CONST UINT8
*Input
,
1814 return BaseCryptLibServiceDeprecated ("AesEcbDecrypt"), FALSE
;
1818 Performs AES encryption on a data buffer of the specified size in CBC mode.
1820 This function performs AES encryption on data buffer pointed by Input, of specified
1821 size of InputSize, in CBC mode.
1822 InputSize must be multiple of block size (16 bytes). This function does not perform
1823 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1824 Initialization vector should be one block size (16 bytes).
1825 AesContext should be already correctly initialized by AesInit(). Behavior with
1826 invalid AES context is undefined.
1828 If AesContext is NULL, then return FALSE.
1829 If Input is NULL, then return FALSE.
1830 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1831 If Ivec is NULL, then return FALSE.
1832 If Output is NULL, then return FALSE.
1833 If this interface is not supported, then return FALSE.
1835 @param[in] AesContext Pointer to the AES context.
1836 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1837 @param[in] InputSize Size of the Input buffer in bytes.
1838 @param[in] Ivec Pointer to initialization vector.
1839 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1841 @retval TRUE AES encryption succeeded.
1842 @retval FALSE AES encryption failed.
1843 @retval FALSE This interface is not supported.
1848 CryptoServiceAesCbcEncrypt (
1849 IN VOID
*AesContext
,
1850 IN CONST UINT8
*Input
,
1852 IN CONST UINT8
*Ivec
,
1856 return CALL_BASECRYPTLIB (Aes
.Services
.CbcEncrypt
, AesCbcEncrypt
, (AesContext
, Input
, InputSize
, Ivec
, Output
), FALSE
);
1860 Performs AES decryption on a data buffer of the specified size in CBC mode.
1862 This function performs AES decryption on data buffer pointed by Input, of specified
1863 size of InputSize, in CBC mode.
1864 InputSize must be multiple of block size (16 bytes). This function does not perform
1865 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1866 Initialization vector should be one block size (16 bytes).
1867 AesContext should be already correctly initialized by AesInit(). Behavior with
1868 invalid AES context is undefined.
1870 If AesContext is NULL, then return FALSE.
1871 If Input is NULL, then return FALSE.
1872 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1873 If Ivec is NULL, then return FALSE.
1874 If Output is NULL, then return FALSE.
1875 If this interface is not supported, then return FALSE.
1877 @param[in] AesContext Pointer to the AES context.
1878 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1879 @param[in] InputSize Size of the Input buffer in bytes.
1880 @param[in] Ivec Pointer to initialization vector.
1881 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1883 @retval TRUE AES decryption succeeded.
1884 @retval FALSE AES decryption failed.
1885 @retval FALSE This interface is not supported.
1890 CryptoServiceAesCbcDecrypt (
1891 IN VOID
*AesContext
,
1892 IN CONST UINT8
*Input
,
1894 IN CONST UINT8
*Ivec
,
1898 return CALL_BASECRYPTLIB (Aes
.Services
.CbcDecrypt
, AesCbcDecrypt
, (AesContext
, Input
, InputSize
, Ivec
, Output
), FALSE
);
1902 ARC4 is deprecated and unsupported any longer.
1903 Keep the function field for binary compability.
1905 @retval 0 This interface is not supported.
1910 DeprecatedCryptoServiceArc4GetContextSize (
1914 return BaseCryptLibServiceDeprecated ("Arc4GetContextSize"), 0;
1918 ARC4 is deprecated and unsupported any longer.
1919 Keep the function field for binary compability.
1921 @param[out] Arc4Context Pointer to ARC4 context being initialized.
1922 @param[in] Key Pointer to the user-supplied ARC4 key.
1923 @param[in] KeySize Size of ARC4 key in bytes.
1925 @retval FALSE This interface is not supported.
1930 DeprecatedCryptoServiceArc4Init (
1931 OUT VOID
*Arc4Context
,
1932 IN CONST UINT8
*Key
,
1936 return BaseCryptLibServiceDeprecated ("Arc4Init"), FALSE
;
1940 ARC4 is deprecated and unsupported any longer.
1941 Keep the function field for binary compability.
1943 @param[in, out] Arc4Context Pointer to the ARC4 context.
1944 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1945 @param[in] InputSize Size of the Input buffer in bytes.
1946 @param[out] Output Pointer to a buffer that receives the ARC4 encryption output.
1948 @retval FALSE This interface is not supported.
1953 DeprecatedCryptoServiceArc4Encrypt (
1954 IN OUT VOID
*Arc4Context
,
1955 IN CONST UINT8
*Input
,
1960 return BaseCryptLibServiceDeprecated ("Arc4Encrypt"), FALSE
;
1964 ARC4 is deprecated and unsupported any longer.
1965 Keep the function field for binary compability.
1967 @param[in, out] Arc4Context Pointer to the ARC4 context.
1968 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1969 @param[in] InputSize Size of the Input buffer in bytes.
1970 @param[out] Output Pointer to a buffer that receives the ARC4 decryption output.
1972 @retval FALSE This interface is not supported.
1977 DeprecatedCryptoServiceArc4Decrypt (
1978 IN OUT VOID
*Arc4Context
,
1984 return BaseCryptLibServiceDeprecated ("Arc4Decrypt"), FALSE
;
1988 ARC4 is deprecated and unsupported any longer.
1989 Keep the function field for binary compability.
1991 @param[in, out] Arc4Context Pointer to the ARC4 context.
1993 @retval FALSE This interface is not supported.
1998 DeprecatedCryptoServiceArc4Reset (
1999 IN OUT VOID
*Arc4Context
2002 return BaseCryptLibServiceDeprecated ("Arc4Reset"), FALSE
;
2005 //=====================================================================================
2006 // Asymmetric Cryptography Primitive
2007 //=====================================================================================
2010 Allocates and initializes one RSA context for subsequent use.
2012 @return Pointer to the RSA context that has been initialized.
2013 If the allocations fails, RsaNew() returns NULL.
2018 CryptoServiceRsaNew (
2022 return CALL_BASECRYPTLIB (Rsa
.Services
.New
, RsaNew
, (), NULL
);
2026 Release the specified RSA context.
2028 If RsaContext is NULL, then return FALSE.
2030 @param[in] RsaContext Pointer to the RSA context to be released.
2035 CryptoServiceRsaFree (
2039 CALL_VOID_BASECRYPTLIB (Rsa
.Services
.Free
, RsaFree
, (RsaContext
));
2043 Sets the tag-designated key component into the established RSA context.
2045 This function sets the tag-designated RSA key component into the established
2046 RSA context from the user-specified non-negative integer (octet string format
2047 represented in RSA PKCS#1).
2048 If BigNumber is NULL, then the specified key component in RSA context is cleared.
2050 If RsaContext is NULL, then return FALSE.
2052 @param[in, out] RsaContext Pointer to RSA context being set.
2053 @param[in] KeyTag Tag of RSA key component being set.
2054 @param[in] BigNumber Pointer to octet integer buffer.
2055 If NULL, then the specified key component in RSA
2057 @param[in] BnSize Size of big number buffer in bytes.
2058 If BigNumber is NULL, then it is ignored.
2060 @retval TRUE RSA key component was set successfully.
2061 @retval FALSE Invalid RSA key component tag.
2066 CryptoServiceRsaSetKey (
2067 IN OUT VOID
*RsaContext
,
2068 IN RSA_KEY_TAG KeyTag
,
2069 IN CONST UINT8
*BigNumber
,
2073 return CALL_BASECRYPTLIB (Rsa
.Services
.SetKey
, RsaSetKey
, (RsaContext
, KeyTag
, BigNumber
, BnSize
), FALSE
);
2077 Gets the tag-designated RSA key component from the established RSA context.
2079 This function retrieves the tag-designated RSA key component from the
2080 established RSA context as a non-negative integer (octet string format
2081 represented in RSA PKCS#1).
2082 If specified key component has not been set or has been cleared, then returned
2084 If the BigNumber buffer is too small to hold the contents of the key, FALSE
2085 is returned and BnSize is set to the required buffer size to obtain the key.
2087 If RsaContext is NULL, then return FALSE.
2088 If BnSize is NULL, then return FALSE.
2089 If BnSize is large enough but BigNumber is NULL, then return FALSE.
2090 If this interface is not supported, then return FALSE.
2092 @param[in, out] RsaContext Pointer to RSA context being set.
2093 @param[in] KeyTag Tag of RSA key component being set.
2094 @param[out] BigNumber Pointer to octet integer buffer.
2095 @param[in, out] BnSize On input, the size of big number buffer in bytes.
2096 On output, the size of data returned in big number buffer in bytes.
2098 @retval TRUE RSA key component was retrieved successfully.
2099 @retval FALSE Invalid RSA key component tag.
2100 @retval FALSE BnSize is too small.
2101 @retval FALSE This interface is not supported.
2106 CryptoServiceRsaGetKey (
2107 IN OUT VOID
*RsaContext
,
2108 IN RSA_KEY_TAG KeyTag
,
2109 OUT UINT8
*BigNumber
,
2110 IN OUT UINTN
*BnSize
2113 return CALL_BASECRYPTLIB (Rsa
.Services
.GetKey
, RsaGetKey
, (RsaContext
, KeyTag
, BigNumber
, BnSize
), FALSE
);
2117 Generates RSA key components.
2119 This function generates RSA key components. It takes RSA public exponent E and
2120 length in bits of RSA modulus N as input, and generates all key components.
2121 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
2123 Before this function can be invoked, pseudorandom number generator must be correctly
2124 initialized by RandomSeed().
2126 If RsaContext is NULL, then return FALSE.
2127 If this interface is not supported, then return FALSE.
2129 @param[in, out] RsaContext Pointer to RSA context being set.
2130 @param[in] ModulusLength Length of RSA modulus N in bits.
2131 @param[in] PublicExponent Pointer to RSA public exponent.
2132 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
2134 @retval TRUE RSA key component was generated successfully.
2135 @retval FALSE Invalid RSA key component tag.
2136 @retval FALSE This interface is not supported.
2141 CryptoServiceRsaGenerateKey (
2142 IN OUT VOID
*RsaContext
,
2143 IN UINTN ModulusLength
,
2144 IN CONST UINT8
*PublicExponent
,
2145 IN UINTN PublicExponentSize
2148 return CALL_BASECRYPTLIB (Rsa
.Services
.GenerateKey
, RsaGenerateKey
, (RsaContext
, ModulusLength
, PublicExponent
, PublicExponentSize
), FALSE
);
2152 Validates key components of RSA context.
2153 NOTE: This function performs integrity checks on all the RSA key material, so
2154 the RSA key structure must contain all the private key data.
2156 This function validates key components of RSA context in following aspects:
2157 - Whether p is a prime
2158 - Whether q is a prime
2160 - Whether d*e = 1 mod lcm(p-1,q-1)
2162 If RsaContext is NULL, then return FALSE.
2163 If this interface is not supported, then return FALSE.
2165 @param[in] RsaContext Pointer to RSA context to check.
2167 @retval TRUE RSA key components are valid.
2168 @retval FALSE RSA key components are not valid.
2169 @retval FALSE This interface is not supported.
2174 CryptoServiceRsaCheckKey (
2178 return CALL_BASECRYPTLIB (Rsa
.Services
.CheckKey
, RsaCheckKey
, (RsaContext
), FALSE
);
2182 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
2184 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
2186 If the Signature buffer is too small to hold the contents of signature, FALSE
2187 is returned and SigSize is set to the required buffer size to obtain the signature.
2189 If RsaContext is NULL, then return FALSE.
2190 If MessageHash is NULL, then return FALSE.
2191 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
2192 If SigSize is large enough but Signature is NULL, then return FALSE.
2193 If this interface is not supported, then return FALSE.
2195 @param[in] RsaContext Pointer to RSA context for signature generation.
2196 @param[in] MessageHash Pointer to octet message hash to be signed.
2197 @param[in] HashSize Size of the message hash in bytes.
2198 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
2199 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
2200 On output, the size of data returned in Signature buffer in bytes.
2202 @retval TRUE Signature successfully generated in PKCS1-v1_5.
2203 @retval FALSE Signature generation failed.
2204 @retval FALSE SigSize is too small.
2205 @retval FALSE This interface is not supported.
2210 CryptoServiceRsaPkcs1Sign (
2211 IN VOID
*RsaContext
,
2212 IN CONST UINT8
*MessageHash
,
2214 OUT UINT8
*Signature
,
2215 IN OUT UINTN
*SigSize
2218 return CALL_BASECRYPTLIB (Rsa
.Services
.Pkcs1Sign
, RsaPkcs1Sign
, (RsaContext
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
2222 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
2225 If RsaContext is NULL, then return FALSE.
2226 If MessageHash is NULL, then return FALSE.
2227 If Signature is NULL, then return FALSE.
2228 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
2230 @param[in] RsaContext Pointer to RSA context for signature verification.
2231 @param[in] MessageHash Pointer to octet message hash to be checked.
2232 @param[in] HashSize Size of the message hash in bytes.
2233 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
2234 @param[in] SigSize Size of signature in bytes.
2236 @retval TRUE Valid signature encoded in PKCS1-v1_5.
2237 @retval FALSE Invalid signature or invalid RSA context.
2242 CryptoServiceRsaPkcs1Verify (
2243 IN VOID
*RsaContext
,
2244 IN CONST UINT8
*MessageHash
,
2246 IN CONST UINT8
*Signature
,
2250 return CALL_BASECRYPTLIB (Rsa
.Services
.Pkcs1Verify
, RsaPkcs1Verify
, (RsaContext
, MessageHash
, HashSize
, Signature
, SigSize
), FALSE
);
2254 Retrieve the RSA Private Key from the password-protected PEM key data.
2256 If PemData is NULL, then return FALSE.
2257 If RsaContext is NULL, then return FALSE.
2258 If this interface is not supported, then return FALSE.
2260 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
2261 @param[in] PemSize Size of the PEM key data in bytes.
2262 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
2263 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2264 RSA private key component. Use RsaFree() function to free the
2267 @retval TRUE RSA Private Key was retrieved successfully.
2268 @retval FALSE Invalid PEM key data or incorrect password.
2269 @retval FALSE This interface is not supported.
2274 CryptoServiceRsaGetPrivateKeyFromPem (
2275 IN CONST UINT8
*PemData
,
2277 IN CONST CHAR8
*Password
,
2278 OUT VOID
**RsaContext
2281 return CALL_BASECRYPTLIB (Rsa
.Services
.GetPrivateKeyFromPem
, RsaGetPrivateKeyFromPem
, (PemData
, PemSize
, Password
, RsaContext
), FALSE
);
2285 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
2287 If Cert is NULL, then return FALSE.
2288 If RsaContext is NULL, then return FALSE.
2289 If this interface is not supported, then return FALSE.
2291 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2292 @param[in] CertSize Size of the X509 certificate in bytes.
2293 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2294 RSA public key component. Use RsaFree() function to free the
2297 @retval TRUE RSA Public Key was retrieved successfully.
2298 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
2299 @retval FALSE This interface is not supported.
2304 CryptoServiceRsaGetPublicKeyFromX509 (
2305 IN CONST UINT8
*Cert
,
2307 OUT VOID
**RsaContext
2310 return CALL_BASECRYPTLIB (Rsa
.Services
.GetPublicKeyFromX509
, RsaGetPublicKeyFromX509
, (Cert
, CertSize
, RsaContext
), FALSE
);
2314 Retrieve the subject bytes from one X.509 certificate.
2316 If Cert is NULL, then return FALSE.
2317 If SubjectSize is NULL, then return FALSE.
2318 If this interface is not supported, then return FALSE.
2320 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2321 @param[in] CertSize Size of the X509 certificate in bytes.
2322 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
2323 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
2324 and the size of buffer returned CertSubject on output.
2326 @retval TRUE The certificate subject retrieved successfully.
2327 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
2328 The SubjectSize will be updated with the required size.
2329 @retval FALSE This interface is not supported.
2334 CryptoServiceX509GetSubjectName (
2335 IN CONST UINT8
*Cert
,
2337 OUT UINT8
*CertSubject
,
2338 IN OUT UINTN
*SubjectSize
2341 return CALL_BASECRYPTLIB (X509
.Services
.GetSubjectName
, X509GetSubjectName
, (Cert
, CertSize
, CertSubject
, SubjectSize
), FALSE
);
2345 Retrieve the common name (CN) string from one X.509 certificate.
2347 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2348 @param[in] CertSize Size of the X509 certificate in bytes.
2349 @param[out] CommonName Buffer to contain the retrieved certificate common
2350 name string (UTF8). At most CommonNameSize bytes will be
2351 written and the string will be null terminated. May be
2352 NULL in order to determine the size buffer needed.
2353 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
2354 and the size of buffer returned CommonName on output.
2355 If CommonName is NULL then the amount of space needed
2356 in buffer (including the final null) is returned.
2358 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
2359 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2360 If CommonNameSize is NULL.
2361 If CommonName is not NULL and *CommonNameSize is 0.
2362 If Certificate is invalid.
2363 @retval RETURN_NOT_FOUND If no CommonName entry exists.
2364 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
2365 (including the final null) is returned in the
2366 CommonNameSize parameter.
2367 @retval RETURN_UNSUPPORTED The operation is not supported.
2372 CryptoServiceX509GetCommonName (
2373 IN CONST UINT8
*Cert
,
2375 OUT CHAR8
*CommonName
, OPTIONAL
2376 IN OUT UINTN
*CommonNameSize
2379 return CALL_BASECRYPTLIB (X509
.Services
.GetCommonName
, X509GetCommonName
, (Cert
, CertSize
, CommonName
, CommonNameSize
), RETURN_UNSUPPORTED
);
2383 Retrieve the organization name (O) string from one X.509 certificate.
2385 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2386 @param[in] CertSize Size of the X509 certificate in bytes.
2387 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
2388 name string. At most NameBufferSize bytes will be
2389 written and the string will be null terminated. May be
2390 NULL in order to determine the size buffer needed.
2391 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
2392 and the size of buffer returned Name on output.
2393 If NameBuffer is NULL then the amount of space needed
2394 in buffer (including the final null) is returned.
2396 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
2397 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2398 If NameBufferSize is NULL.
2399 If NameBuffer is not NULL and *CommonNameSize is 0.
2400 If Certificate is invalid.
2401 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
2402 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
2403 (including the final null) is returned in the
2404 CommonNameSize parameter.
2405 @retval RETURN_UNSUPPORTED The operation is not supported.
2410 CryptoServiceX509GetOrganizationName (
2411 IN CONST UINT8
*Cert
,
2413 OUT CHAR8
*NameBuffer
, OPTIONAL
2414 IN OUT UINTN
*NameBufferSize
2417 return CALL_BASECRYPTLIB (X509
.Services
.GetOrganizationName
, X509GetOrganizationName
, (Cert
, CertSize
, NameBuffer
, NameBufferSize
), RETURN_UNSUPPORTED
);
2421 Verify one X509 certificate was issued by the trusted CA.
2423 If Cert is NULL, then return FALSE.
2424 If CACert is NULL, then return FALSE.
2425 If this interface is not supported, then return FALSE.
2427 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
2428 @param[in] CertSize Size of the X509 certificate in bytes.
2429 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
2430 @param[in] CACertSize Size of the CA Certificate in bytes.
2432 @retval TRUE The certificate was issued by the trusted CA.
2433 @retval FALSE Invalid certificate or the certificate was not issued by the given
2435 @retval FALSE This interface is not supported.
2440 CryptoServiceX509VerifyCert (
2441 IN CONST UINT8
*Cert
,
2443 IN CONST UINT8
*CACert
,
2447 return CALL_BASECRYPTLIB (X509
.Services
.VerifyCert
, X509VerifyCert
, (Cert
, CertSize
, CACert
, CACertSize
), FALSE
);
2451 Construct a X509 object from DER-encoded certificate data.
2453 If Cert is NULL, then return FALSE.
2454 If SingleX509Cert is NULL, then return FALSE.
2455 If this interface is not supported, then return FALSE.
2457 @param[in] Cert Pointer to the DER-encoded certificate data.
2458 @param[in] CertSize The size of certificate data in bytes.
2459 @param[out] SingleX509Cert The generated X509 object.
2461 @retval TRUE The X509 object generation succeeded.
2462 @retval FALSE The operation failed.
2463 @retval FALSE This interface is not supported.
2468 CryptoServiceX509ConstructCertificate (
2469 IN CONST UINT8
*Cert
,
2471 OUT UINT8
**SingleX509Cert
2474 return CALL_BASECRYPTLIB (X509
.Services
.ConstructCertificate
, X509ConstructCertificate
, (Cert
, CertSize
, SingleX509Cert
), FALSE
);
2478 Construct a X509 stack object from a list of DER-encoded certificate data.
2480 If X509Stack is NULL, then return FALSE.
2481 If this interface is not supported, then return FALSE.
2483 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2484 On output, pointer to the X509 stack object with new
2485 inserted X509 certificate.
2486 @param[in] Args VA_LIST marker for the variable argument list.
2487 A list of DER-encoded single certificate data followed
2488 by certificate size. A NULL terminates the list. The
2489 pairs are the arguments to X509ConstructCertificate().
2491 @retval TRUE The X509 stack construction succeeded.
2492 @retval FALSE The construction operation failed.
2493 @retval FALSE This interface is not supported.
2498 CryptoServiceX509ConstructCertificateStackV (
2499 IN OUT UINT8
**X509Stack
,
2503 return CALL_BASECRYPTLIB (X509
.Services
.ConstructCertificateStackV
, X509ConstructCertificateStackV
, (X509Stack
, Args
), FALSE
);
2507 Construct a X509 stack object from a list of DER-encoded certificate data.
2509 If X509Stack is NULL, then return FALSE.
2510 If this interface is not supported, then return FALSE.
2512 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2513 On output, pointer to the X509 stack object with new
2514 inserted X509 certificate.
2515 @param ... A list of DER-encoded single certificate data followed
2516 by certificate size. A NULL terminates the list. The
2517 pairs are the arguments to X509ConstructCertificate().
2519 @retval TRUE The X509 stack construction succeeded.
2520 @retval FALSE The construction operation failed.
2521 @retval FALSE This interface is not supported.
2526 CryptoServiceX509ConstructCertificateStack (
2527 IN OUT UINT8
**X509Stack
,
2534 VA_START (Args
, X509Stack
);
2535 Result
= CryptoServiceX509ConstructCertificateStackV (X509Stack
, Args
);
2541 Release the specified X509 object.
2543 If the interface is not supported, then ASSERT().
2545 @param[in] X509Cert Pointer to the X509 object to be released.
2550 CryptoServiceX509Free (
2554 CALL_VOID_BASECRYPTLIB (X509
.Services
.Free
, X509Free
, (X509Cert
));
2558 Release the specified X509 stack object.
2560 If the interface is not supported, then ASSERT().
2562 @param[in] X509Stack Pointer to the X509 stack object to be released.
2567 CryptoServiceX509StackFree (
2571 CALL_VOID_BASECRYPTLIB (X509
.Services
.StackFree
, X509StackFree
, (X509Stack
));
2575 Retrieve the TBSCertificate from one given X.509 certificate.
2577 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
2578 @param[in] CertSize Size of the X509 certificate in bytes.
2579 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
2580 @param[out] TBSCertSize Size of the TBS certificate in bytes.
2582 If Cert is NULL, then return FALSE.
2583 If TBSCert is NULL, then return FALSE.
2584 If TBSCertSize is NULL, then return FALSE.
2585 If this interface is not supported, then return FALSE.
2587 @retval TRUE The TBSCertificate was retrieved successfully.
2588 @retval FALSE Invalid X.509 certificate.
2593 CryptoServiceX509GetTBSCert (
2594 IN CONST UINT8
*Cert
,
2596 OUT UINT8
**TBSCert
,
2597 OUT UINTN
*TBSCertSize
2600 return CALL_BASECRYPTLIB (X509
.Services
.GetTBSCert
, X509GetTBSCert
, (Cert
, CertSize
, TBSCert
, TBSCertSize
), FALSE
);
2604 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2605 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2607 If Password or Salt or OutKey is NULL, then return FALSE.
2608 If the hash algorithm could not be determined, then return FALSE.
2609 If this interface is not supported, then return FALSE.
2611 @param[in] PasswordLength Length of input password in bytes.
2612 @param[in] Password Pointer to the array for the password.
2613 @param[in] SaltLength Size of the Salt in bytes.
2614 @param[in] Salt Pointer to the Salt.
2615 @param[in] IterationCount Number of iterations to perform. Its value should be
2616 greater than or equal to 1.
2617 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2618 NOTE: DigestSize will be used to determine the hash algorithm.
2619 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2620 @param[in] KeyLength Size of the derived key buffer in bytes.
2621 @param[out] OutKey Pointer to the output derived key buffer.
2623 @retval TRUE A key was derived successfully.
2624 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2625 @retval FALSE The hash algorithm could not be determined from the digest size.
2626 @retval FALSE The key derivation operation failed.
2627 @retval FALSE This interface is not supported.
2632 CryptoServicePkcs5HashPassword (
2633 IN UINTN PasswordLength
,
2634 IN CONST CHAR8
*Password
,
2635 IN UINTN SaltLength
,
2636 IN CONST UINT8
*Salt
,
2637 IN UINTN IterationCount
,
2638 IN UINTN DigestSize
,
2643 return CALL_BASECRYPTLIB (Pkcs
.Services
.Pkcs5HashPassword
, Pkcs5HashPassword
, (PasswordLength
, Password
, SaltLength
, Salt
, IterationCount
, DigestSize
, KeyLength
, OutKey
), FALSE
);
2647 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2648 encrypted message in a newly allocated buffer.
2650 Things that can cause a failure include:
2651 - X509 key size does not match any known key size.
2652 - Fail to parse X509 certificate.
2653 - Fail to allocate an intermediate buffer.
2654 - Null pointer provided for a non-optional parameter.
2655 - Data size is too large for the provided key size (max size is a function of key size
2656 and hash digest size).
2658 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2659 will be used to encrypt the data.
2660 @param[in] PublicKeySize Size of the X509 cert buffer.
2661 @param[in] InData Data to be encrypted.
2662 @param[in] InDataSize Size of the data buffer.
2663 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2664 to be used when initializing the PRNG. NULL otherwise.
2665 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2667 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2669 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2671 @retval TRUE Encryption was successful.
2672 @retval FALSE Encryption failed.
2677 CryptoServicePkcs1v2Encrypt (
2678 IN CONST UINT8
*PublicKey
,
2679 IN UINTN PublicKeySize
,
2681 IN UINTN InDataSize
,
2682 IN CONST UINT8
*PrngSeed
, OPTIONAL
2683 IN UINTN PrngSeedSize
, OPTIONAL
2684 OUT UINT8
**EncryptedData
,
2685 OUT UINTN
*EncryptedDataSize
2688 return CALL_BASECRYPTLIB (Pkcs
.Services
.Pkcs1v2Encrypt
, Pkcs1v2Encrypt
, (PublicKey
, PublicKeySize
, InData
, InDataSize
, PrngSeed
, PrngSeedSize
, EncryptedData
, EncryptedDataSize
), FALSE
);
2692 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2693 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2694 in a ContentInfo structure.
2696 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2697 return FALSE. If P7Length overflow, then return FALSE.
2698 If this interface is not supported, then return FALSE.
2700 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2701 @param[in] P7Length Length of the PKCS#7 message in bytes.
2702 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2703 It's caller's responsibility to free the buffer with
2705 This data structure is EFI_CERT_STACK type.
2706 @param[out] StackLength Length of signer's certificates in bytes.
2707 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2708 It's caller's responsibility to free the buffer with
2710 @param[out] CertLength Length of the trusted certificate in bytes.
2712 @retval TRUE The operation is finished successfully.
2713 @retval FALSE Error occurs during the operation.
2714 @retval FALSE This interface is not supported.
2719 CryptoServicePkcs7GetSigners (
2720 IN CONST UINT8
*P7Data
,
2722 OUT UINT8
**CertStack
,
2723 OUT UINTN
*StackLength
,
2724 OUT UINT8
**TrustedCert
,
2725 OUT UINTN
*CertLength
2728 return CALL_BASECRYPTLIB (Pkcs
.Services
.Pkcs7GetSigners
, Pkcs7GetSigners
, (P7Data
, P7Length
, CertStack
, StackLength
, TrustedCert
, CertLength
), FALSE
);
2732 Wrap function to use free() to free allocated memory for certificates.
2734 If this interface is not supported, then ASSERT().
2736 @param[in] Certs Pointer to the certificates to be freed.
2741 CryptoServicePkcs7FreeSigners (
2745 CALL_VOID_BASECRYPTLIB (Pkcs
.Services
.Pkcs7FreeSigners
, Pkcs7FreeSigners
, (Certs
));
2749 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2750 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2751 unchained to the signer's certificates.
2752 The input signed data could be wrapped in a ContentInfo structure.
2754 @param[in] P7Data Pointer to the PKCS#7 message.
2755 @param[in] P7Length Length of the PKCS#7 message in bytes.
2756 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2757 certificate. It's caller's responsibility to free the buffer
2758 with Pkcs7FreeSigners().
2759 This data structure is EFI_CERT_STACK type.
2760 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2761 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2762 responsibility to free the buffer with Pkcs7FreeSigners().
2763 This data structure is EFI_CERT_STACK type.
2764 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2766 @retval TRUE The operation is finished successfully.
2767 @retval FALSE Error occurs during the operation.
2772 CryptoServicePkcs7GetCertificatesList (
2773 IN CONST UINT8
*P7Data
,
2775 OUT UINT8
**SignerChainCerts
,
2776 OUT UINTN
*ChainLength
,
2777 OUT UINT8
**UnchainCerts
,
2778 OUT UINTN
*UnchainLength
2781 return CALL_BASECRYPTLIB (Pkcs
.Services
.Pkcs7GetCertificatesList
, Pkcs7GetCertificatesList
, (P7Data
, P7Length
, SignerChainCerts
, ChainLength
, UnchainCerts
, UnchainLength
), FALSE
);
2785 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2786 Syntax Standard, version 1.5". This interface is only intended to be used for
2787 application to perform PKCS#7 functionality validation.
2789 If this interface is not supported, then return FALSE.
2791 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2793 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2794 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2796 @param[in] InData Pointer to the content to be signed.
2797 @param[in] InDataSize Size of InData in bytes.
2798 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2799 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2800 include in the PKCS#7 signedData (e.g. any intermediate
2802 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2803 responsibility to free the buffer with FreePool().
2804 @param[out] SignedDataSize Size of SignedData in bytes.
2806 @retval TRUE PKCS#7 data signing succeeded.
2807 @retval FALSE PKCS#7 data signing failed.
2808 @retval FALSE This interface is not supported.
2813 CryptoServicePkcs7Sign (
2814 IN CONST UINT8
*PrivateKey
,
2815 IN UINTN PrivateKeySize
,
2816 IN CONST UINT8
*KeyPassword
,
2818 IN UINTN InDataSize
,
2820 IN UINT8
*OtherCerts OPTIONAL
,
2821 OUT UINT8
**SignedData
,
2822 OUT UINTN
*SignedDataSize
2825 return CALL_BASECRYPTLIB (Pkcs
.Services
.Pkcs7Sign
, Pkcs7Sign
, (PrivateKey
, PrivateKeySize
, KeyPassword
, InData
, InDataSize
, SignCert
, OtherCerts
, SignedData
, SignedDataSize
), FALSE
);
2829 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2830 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2831 in a ContentInfo structure.
2833 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2834 If P7Length, CertLength or DataLength overflow, then return FALSE.
2835 If this interface is not supported, then return FALSE.
2837 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2838 @param[in] P7Length Length of the PKCS#7 message in bytes.
2839 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2840 is used for certificate chain verification.
2841 @param[in] CertLength Length of the trusted certificate in bytes.
2842 @param[in] InData Pointer to the content to be verified.
2843 @param[in] DataLength Length of InData in bytes.
2845 @retval TRUE The specified PKCS#7 signed data is valid.
2846 @retval FALSE Invalid PKCS#7 signed data.
2847 @retval FALSE This interface is not supported.
2852 CryptoServicePkcs7Verify (
2853 IN CONST UINT8
*P7Data
,
2855 IN CONST UINT8
*TrustedCert
,
2856 IN UINTN CertLength
,
2857 IN CONST UINT8
*InData
,
2861 return CALL_BASECRYPTLIB (Pkcs
.Services
.Pkcs7Verify
, Pkcs7Verify
, (P7Data
, P7Length
, TrustedCert
, CertLength
, InData
, DataLength
), FALSE
);
2865 This function receives a PKCS7 formatted signature, and then verifies that
2866 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
2867 leaf signing certificate.
2868 Note that this function does not validate the certificate chain.
2870 Applications for custom EKU's are quite flexible. For example, a policy EKU
2871 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
2872 certificate issued might also contain this EKU, thus constraining the
2873 sub-ordinate certificate. Other applications might allow a certificate
2874 embedded in a device to specify that other Object Identifiers (OIDs) are
2875 present which contains binary data specifying custom capabilities that
2876 the device is able to do.
2878 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
2879 containing the content block with both the signature,
2880 the signer's certificate, and any necessary intermediate
2882 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
2883 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
2884 required EKUs that must be present in the signature.
2885 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
2886 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
2887 must be present in the leaf signer. If it is
2888 FALSE, then we will succeed if we find any
2889 of the specified EKU's.
2891 @retval EFI_SUCCESS The required EKUs were found in the signature.
2892 @retval EFI_INVALID_PARAMETER A parameter was invalid.
2893 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
2898 CryptoServiceVerifyEKUsInPkcs7Signature (
2899 IN CONST UINT8
*Pkcs7Signature
,
2900 IN CONST UINT32 SignatureSize
,
2901 IN CONST CHAR8
*RequiredEKUs
[],
2902 IN CONST UINT32 RequiredEKUsSize
,
2903 IN BOOLEAN RequireAllPresent
2906 return CALL_BASECRYPTLIB (Pkcs
.Services
.VerifyEKUsInPkcs7Signature
, VerifyEKUsInPkcs7Signature
, (Pkcs7Signature
, SignatureSize
, RequiredEKUs
, RequiredEKUsSize
, RequireAllPresent
), FALSE
);
2911 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2912 data could be wrapped in a ContentInfo structure.
2914 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2915 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2917 Caution: This function may receive untrusted input. So this function will do
2918 basic check for PKCS#7 data structure.
2920 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2921 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2922 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2923 It's caller's responsibility to free the buffer with FreePool().
2924 @param[out] ContentSize The size of the extracted content in bytes.
2926 @retval TRUE The P7Data was correctly formatted for processing.
2927 @retval FALSE The P7Data was not correctly formatted for processing.
2932 CryptoServicePkcs7GetAttachedContent (
2933 IN CONST UINT8
*P7Data
,
2936 OUT UINTN
*ContentSize
2939 return CALL_BASECRYPTLIB (Pkcs
.Services
.Pkcs7GetAttachedContent
, Pkcs7GetAttachedContent
, (P7Data
, P7Length
, Content
, ContentSize
), FALSE
);
2943 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2944 Authenticode Portable Executable Signature Format".
2946 If AuthData is NULL, then return FALSE.
2947 If ImageHash is NULL, then return FALSE.
2948 If this interface is not supported, then return FALSE.
2950 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2951 PE/COFF image to be verified.
2952 @param[in] DataSize Size of the Authenticode Signature in bytes.
2953 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2954 is used for certificate chain verification.
2955 @param[in] CertSize Size of the trusted certificate in bytes.
2956 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2957 for calculating the image hash value is described in Authenticode
2959 @param[in] HashSize Size of Image hash value in bytes.
2961 @retval TRUE The specified Authenticode Signature is valid.
2962 @retval FALSE Invalid Authenticode Signature.
2963 @retval FALSE This interface is not supported.
2968 CryptoServiceAuthenticodeVerify (
2969 IN CONST UINT8
*AuthData
,
2971 IN CONST UINT8
*TrustedCert
,
2973 IN CONST UINT8
*ImageHash
,
2977 return CALL_BASECRYPTLIB (Pkcs
.Services
.AuthenticodeVerify
, AuthenticodeVerify
, (AuthData
, DataSize
, TrustedCert
, CertSize
, ImageHash
, HashSize
), FALSE
);
2981 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2984 If AuthData is NULL, then return FALSE.
2985 If this interface is not supported, then return FALSE.
2987 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2988 PE/COFF image to be verified.
2989 @param[in] DataSize Size of the Authenticode Signature in bytes.
2990 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2991 is used for TSA certificate chain verification.
2992 @param[in] CertSize Size of the trusted certificate in bytes.
2993 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2996 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2997 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
3002 CryptoServiceImageTimestampVerify (
3003 IN CONST UINT8
*AuthData
,
3005 IN CONST UINT8
*TsaCert
,
3007 OUT EFI_TIME
*SigningTime
3010 return CALL_BASECRYPTLIB (Pkcs
.Services
.ImageTimestampVerify
, ImageTimestampVerify
, (AuthData
, DataSize
, TsaCert
, CertSize
, SigningTime
), FALSE
);
3013 //=====================================================================================
3014 // DH Key Exchange Primitive
3015 //=====================================================================================
3018 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
3020 @return Pointer to the Diffie-Hellman Context that has been initialized.
3021 If the allocations fails, DhNew() returns NULL.
3022 If the interface is not supported, DhNew() returns NULL.
3027 CryptoServiceDhNew (
3031 return CALL_BASECRYPTLIB (Dh
.Services
.New
, DhNew
, (), NULL
);
3035 Release the specified DH context.
3037 If the interface is not supported, then ASSERT().
3039 @param[in] DhContext Pointer to the DH context to be released.
3044 CryptoServiceDhFree (
3048 CALL_VOID_BASECRYPTLIB (Dh
.Services
.Free
, DhFree
, (DhContext
));
3052 Generates DH parameter.
3054 Given generator g, and length of prime number p in bits, this function generates p,
3055 and sets DH context according to value of g and p.
3057 Before this function can be invoked, pseudorandom number generator must be correctly
3058 initialized by RandomSeed().
3060 If DhContext is NULL, then return FALSE.
3061 If Prime is NULL, then return FALSE.
3062 If this interface is not supported, then return FALSE.
3064 @param[in, out] DhContext Pointer to the DH context.
3065 @param[in] Generator Value of generator.
3066 @param[in] PrimeLength Length in bits of prime to be generated.
3067 @param[out] Prime Pointer to the buffer to receive the generated prime number.
3069 @retval TRUE DH parameter generation succeeded.
3070 @retval FALSE Value of Generator is not supported.
3071 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
3072 @retval FALSE This interface is not supported.
3077 CryptoServiceDhGenerateParameter (
3078 IN OUT VOID
*DhContext
,
3080 IN UINTN PrimeLength
,
3084 return CALL_BASECRYPTLIB (Dh
.Services
.GenerateParameter
, DhGenerateParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
3088 Sets generator and prime parameters for DH.
3090 Given generator g, and prime number p, this function and sets DH
3091 context accordingly.
3093 If DhContext is NULL, then return FALSE.
3094 If Prime is NULL, then return FALSE.
3095 If this interface is not supported, then return FALSE.
3097 @param[in, out] DhContext Pointer to the DH context.
3098 @param[in] Generator Value of generator.
3099 @param[in] PrimeLength Length in bits of prime to be generated.
3100 @param[in] Prime Pointer to the prime number.
3102 @retval TRUE DH parameter setting succeeded.
3103 @retval FALSE Value of Generator is not supported.
3104 @retval FALSE Value of Generator is not suitable for the Prime.
3105 @retval FALSE Value of Prime is not a prime number.
3106 @retval FALSE Value of Prime is not a safe prime number.
3107 @retval FALSE This interface is not supported.
3112 CryptoServiceDhSetParameter (
3113 IN OUT VOID
*DhContext
,
3115 IN UINTN PrimeLength
,
3116 IN CONST UINT8
*Prime
3119 return CALL_BASECRYPTLIB (Dh
.Services
.SetParameter
, DhSetParameter
, (DhContext
, Generator
, PrimeLength
, Prime
), FALSE
);
3123 Generates DH public key.
3125 This function generates random secret exponent, and computes the public key, which is
3126 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
3127 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
3128 PublicKeySize is set to the required buffer size to obtain the public key.
3130 If DhContext is NULL, then return FALSE.
3131 If PublicKeySize is NULL, then return FALSE.
3132 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
3133 If this interface is not supported, then return FALSE.
3135 @param[in, out] DhContext Pointer to the DH context.
3136 @param[out] PublicKey Pointer to the buffer to receive generated public key.
3137 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
3138 On output, the size of data returned in PublicKey buffer in bytes.
3140 @retval TRUE DH public key generation succeeded.
3141 @retval FALSE DH public key generation failed.
3142 @retval FALSE PublicKeySize is not large enough.
3143 @retval FALSE This interface is not supported.
3148 CryptoServiceDhGenerateKey (
3149 IN OUT VOID
*DhContext
,
3150 OUT UINT8
*PublicKey
,
3151 IN OUT UINTN
*PublicKeySize
3154 return CALL_BASECRYPTLIB (Dh
.Services
.GenerateKey
, DhGenerateKey
, (DhContext
, PublicKey
, PublicKeySize
), FALSE
);
3158 Computes exchanged common key.
3160 Given peer's public key, this function computes the exchanged common key, based on its own
3161 context including value of prime modulus and random secret exponent.
3163 If DhContext is NULL, then return FALSE.
3164 If PeerPublicKey is NULL, then return FALSE.
3165 If KeySize is NULL, then return FALSE.
3166 If Key is NULL, then return FALSE.
3167 If KeySize is not large enough, then return FALSE.
3168 If this interface is not supported, then return FALSE.
3170 @param[in, out] DhContext Pointer to the DH context.
3171 @param[in] PeerPublicKey Pointer to the peer's public key.
3172 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
3173 @param[out] Key Pointer to the buffer to receive generated key.
3174 @param[in, out] KeySize On input, the size of Key buffer in bytes.
3175 On output, the size of data returned in Key buffer in bytes.
3177 @retval TRUE DH exchanged key generation succeeded.
3178 @retval FALSE DH exchanged key generation failed.
3179 @retval FALSE KeySize is not large enough.
3180 @retval FALSE This interface is not supported.
3185 CryptoServiceDhComputeKey (
3186 IN OUT VOID
*DhContext
,
3187 IN CONST UINT8
*PeerPublicKey
,
3188 IN UINTN PeerPublicKeySize
,
3190 IN OUT UINTN
*KeySize
3193 return CALL_BASECRYPTLIB (Dh
.Services
.ComputeKey
, DhComputeKey
, (DhContext
, PeerPublicKey
, PeerPublicKeySize
, Key
, KeySize
), FALSE
);
3196 //=====================================================================================
3197 // Pseudo-Random Generation Primitive
3198 //=====================================================================================
3201 Sets up the seed value for the pseudorandom number generator.
3203 This function sets up the seed value for the pseudorandom number generator.
3204 If Seed is not NULL, then the seed passed in is used.
3205 If Seed is NULL, then default seed is used.
3206 If this interface is not supported, then return FALSE.
3208 @param[in] Seed Pointer to seed value.
3209 If NULL, default seed is used.
3210 @param[in] SeedSize Size of seed value.
3211 If Seed is NULL, this parameter is ignored.
3213 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
3214 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
3215 @retval FALSE This interface is not supported.
3220 CryptoServiceRandomSeed (
3221 IN CONST UINT8
*Seed OPTIONAL
,
3225 return CALL_BASECRYPTLIB (Random
.Services
.Seed
, RandomSeed
, (Seed
, SeedSize
), FALSE
);
3229 Generates a pseudorandom byte stream of the specified size.
3231 If Output is NULL, then return FALSE.
3232 If this interface is not supported, then return FALSE.
3234 @param[out] Output Pointer to buffer to receive random value.
3235 @param[in] Size Size of random bytes to generate.
3237 @retval TRUE Pseudorandom byte stream generated successfully.
3238 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
3239 @retval FALSE This interface is not supported.
3244 CryptoServiceRandomBytes (
3249 return CALL_BASECRYPTLIB (Random
.Services
.Bytes
, RandomBytes
, (Output
, Size
), FALSE
);
3252 //=====================================================================================
3253 // Key Derivation Function Primitive
3254 //=====================================================================================
3257 Derive key data using HMAC-SHA256 based KDF.
3259 @param[in] Key Pointer to the user-supplied key.
3260 @param[in] KeySize Key size in bytes.
3261 @param[in] Salt Pointer to the salt(non-secret) value.
3262 @param[in] SaltSize Salt size in bytes.
3263 @param[in] Info Pointer to the application specific info.
3264 @param[in] InfoSize Info size in bytes.
3265 @param[out] Out Pointer to buffer to receive hkdf value.
3266 @param[in] OutSize Size of hkdf bytes to generate.
3268 @retval TRUE Hkdf generated successfully.
3269 @retval FALSE Hkdf generation failed.
3274 CryptoServiceHkdfSha256ExtractAndExpand (
3275 IN CONST UINT8
*Key
,
3277 IN CONST UINT8
*Salt
,
3279 IN CONST UINT8
*Info
,
3285 return CALL_BASECRYPTLIB (Hkdf
.Services
.Sha256ExtractAndExpand
, HkdfSha256ExtractAndExpand
, (Key
, KeySize
, Salt
, SaltSize
, Info
, InfoSize
, Out
, OutSize
), FALSE
);
3289 Initializes the OpenSSL library.
3291 This function registers ciphers and digests used directly and indirectly
3292 by SSL/TLS, and initializes the readable error messages.
3293 This function must be called before any other action takes places.
3295 @retval TRUE The OpenSSL library has been initialized.
3296 @retval FALSE Failed to initialize the OpenSSL library.
3301 CryptoServiceTlsInitialize (
3305 return CALL_BASECRYPTLIB (Tls
.Services
.Initialize
, TlsInitialize
, (), FALSE
);
3309 Free an allocated SSL_CTX object.
3311 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
3316 CryptoServiceTlsCtxFree (
3320 CALL_VOID_BASECRYPTLIB (Tls
.Services
.CtxFree
, TlsCtxFree
, (TlsCtx
));
3324 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
3327 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3328 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3330 @return Pointer to an allocated SSL_CTX object.
3331 If the creation failed, TlsCtxNew() returns NULL.
3336 CryptoServiceTlsCtxNew (
3341 return CALL_BASECRYPTLIB (Tls
.Services
.CtxNew
, TlsCtxNew
, (MajorVer
, MinorVer
), NULL
);
3345 Free an allocated TLS object.
3347 This function removes the TLS object pointed to by Tls and frees up the
3348 allocated memory. If Tls is NULL, nothing is done.
3350 @param[in] Tls Pointer to the TLS object to be freed.
3355 CryptoServiceTlsFree (
3359 CALL_VOID_BASECRYPTLIB (Tls
.Services
.Free
, TlsFree
, (Tls
));
3363 Create a new TLS object for a connection.
3365 This function creates a new TLS object for a connection. The new object
3366 inherits the setting of the underlying context TlsCtx: connection method,
3367 options, verification setting.
3369 @param[in] TlsCtx Pointer to the SSL_CTX object.
3371 @return Pointer to an allocated SSL object.
3372 If the creation failed, TlsNew() returns NULL.
3377 CryptoServiceTlsNew (
3381 return CALL_BASECRYPTLIB (Tls
.Services
.New
, TlsNew
, (TlsCtx
), NULL
);
3385 Checks if the TLS handshake was done.
3387 This function will check if the specified TLS handshake was done.
3389 @param[in] Tls Pointer to the TLS object for handshake state checking.
3391 @retval TRUE The TLS handshake was done.
3392 @retval FALSE The TLS handshake was not done.
3397 CryptoServiceTlsInHandshake (
3401 return CALL_BASECRYPTLIB (Tls
.Services
.InHandshake
, TlsInHandshake
, (Tls
), FALSE
);
3405 Perform a TLS/SSL handshake.
3407 This function will perform a TLS/SSL handshake.
3409 @param[in] Tls Pointer to the TLS object for handshake operation.
3410 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
3411 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3413 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3414 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3415 the buffer size provided by the caller. On output, it
3416 is the buffer size in fact needed to contain the
3419 @retval EFI_SUCCESS The required TLS packet is built successfully.
3420 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3422 BufferIn is NULL but BufferInSize is NOT 0.
3423 BufferInSize is 0 but BufferIn is NOT NULL.
3424 BufferOutSize is NULL.
3425 BufferOut is NULL if *BufferOutSize is not zero.
3426 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3427 @retval EFI_ABORTED Something wrong during handshake.
3432 CryptoServiceTlsDoHandshake (
3434 IN UINT8
*BufferIn
, OPTIONAL
3435 IN UINTN BufferInSize
, OPTIONAL
3436 OUT UINT8
*BufferOut
, OPTIONAL
3437 IN OUT UINTN
*BufferOutSize
3440 return CALL_BASECRYPTLIB (Tls
.Services
.DoHandshake
, TlsDoHandshake
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
3444 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
3445 TLS session has errors and the response packet needs to be Alert message based on error type.
3447 @param[in] Tls Pointer to the TLS object for state checking.
3448 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
3449 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3451 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3452 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3453 the buffer size provided by the caller. On output, it
3454 is the buffer size in fact needed to contain the
3457 @retval EFI_SUCCESS The required TLS packet is built successfully.
3458 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3460 BufferIn is NULL but BufferInSize is NOT 0.
3461 BufferInSize is 0 but BufferIn is NOT NULL.
3462 BufferOutSize is NULL.
3463 BufferOut is NULL if *BufferOutSize is not zero.
3464 @retval EFI_ABORTED An error occurred.
3465 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3470 CryptoServiceTlsHandleAlert (
3472 IN UINT8
*BufferIn
, OPTIONAL
3473 IN UINTN BufferInSize
, OPTIONAL
3474 OUT UINT8
*BufferOut
, OPTIONAL
3475 IN OUT UINTN
*BufferOutSize
3478 return CALL_BASECRYPTLIB (Tls
.Services
.HandleAlert
, TlsHandleAlert
, (Tls
, BufferIn
, BufferInSize
, BufferOut
, BufferOutSize
), EFI_UNSUPPORTED
);
3482 Build the CloseNotify packet.
3484 @param[in] Tls Pointer to the TLS object for state checking.
3485 @param[in, out] Buffer Pointer to the buffer to hold the built packet.
3486 @param[in, out] BufferSize 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:
3495 Buffer is NULL if *BufferSize is not zero.
3496 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
3501 CryptoServiceTlsCloseNotify (
3503 IN OUT UINT8
*Buffer
,
3504 IN OUT UINTN
*BufferSize
3507 return CALL_BASECRYPTLIB (Tls
.Services
.CloseNotify
, TlsCloseNotify
, (Tls
, Buffer
, BufferSize
), EFI_UNSUPPORTED
);
3511 Attempts to read bytes from one TLS object and places the data in Buffer.
3513 This function will attempt to read BufferSize bytes from the TLS object
3514 and places the data in Buffer.
3516 @param[in] Tls Pointer to the TLS object.
3517 @param[in,out] Buffer Pointer to the buffer to store the data.
3518 @param[in] BufferSize The size of Buffer in bytes.
3520 @retval >0 The amount of data successfully read from the TLS object.
3521 @retval <=0 No data was successfully read.
3526 CryptoServiceTlsCtrlTrafficOut (
3528 IN OUT VOID
*Buffer
,
3532 return CALL_BASECRYPTLIB (Tls
.Services
.CtrlTrafficOut
, TlsCtrlTrafficOut
, (Tls
, Buffer
, BufferSize
), 0);
3536 Attempts to write data from the buffer to TLS object.
3538 This function will attempt to write BufferSize bytes data from the Buffer
3541 @param[in] Tls Pointer to the TLS object.
3542 @param[in] Buffer Pointer to the data buffer.
3543 @param[in] BufferSize The size of Buffer in bytes.
3545 @retval >0 The amount of data successfully written to the TLS object.
3546 @retval <=0 No data was successfully written.
3551 CryptoServiceTlsCtrlTrafficIn (
3557 return CALL_BASECRYPTLIB (Tls
.Services
.CtrlTrafficIn
, TlsCtrlTrafficIn
, (Tls
, Buffer
, BufferSize
), 0);
3561 Attempts to read bytes from the specified TLS connection into the buffer.
3563 This function tries to read BufferSize bytes data from the specified TLS
3564 connection into the Buffer.
3566 @param[in] Tls Pointer to the TLS connection for data reading.
3567 @param[in,out] Buffer Pointer to the data buffer.
3568 @param[in] BufferSize The size of Buffer in bytes.
3570 @retval >0 The read operation was successful, and return value is the
3571 number of bytes actually read from the TLS connection.
3572 @retval <=0 The read operation was not successful.
3577 CryptoServiceTlsRead (
3579 IN OUT VOID
*Buffer
,
3583 return CALL_BASECRYPTLIB (Tls
.Services
.Read
, TlsRead
, (Tls
, Buffer
, BufferSize
), 0);
3587 Attempts to write data to a TLS connection.
3589 This function tries to write BufferSize bytes data from the Buffer into the
3590 specified TLS connection.
3592 @param[in] Tls Pointer to the TLS connection for data writing.
3593 @param[in] Buffer Pointer to the data buffer.
3594 @param[in] BufferSize The size of Buffer in bytes.
3596 @retval >0 The write operation was successful, and return value is the
3597 number of bytes actually written to the TLS connection.
3598 @retval <=0 The write operation was not successful.
3603 CryptoServiceTlsWrite (
3609 return CALL_BASECRYPTLIB (Tls
.Services
.Write
, TlsWrite
, (Tls
, Buffer
, BufferSize
), 0);
3613 Set a new TLS/SSL method for a particular TLS object.
3615 This function sets a new TLS/SSL method for a particular TLS object.
3617 @param[in] Tls Pointer to a TLS object.
3618 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3619 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3621 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
3622 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3623 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
3628 CryptoServiceTlsSetVersion (
3634 return CALL_BASECRYPTLIB (TlsSet
.Services
.Version
, TlsSetVersion
, (Tls
, MajorVer
, MinorVer
), EFI_UNSUPPORTED
);
3638 Set TLS object to work in client or server mode.
3640 This function prepares a TLS object to work in client or server mode.
3642 @param[in] Tls Pointer to a TLS object.
3643 @param[in] IsServer Work in server mode.
3645 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
3646 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3647 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
3652 CryptoServiceTlsSetConnectionEnd (
3657 return CALL_BASECRYPTLIB (TlsSet
.Services
.ConnectionEnd
, TlsSetConnectionEnd
, (Tls
, IsServer
), EFI_UNSUPPORTED
);
3661 Set the ciphers list to be used by the TLS object.
3663 This function sets the ciphers for use by a specified TLS object.
3665 @param[in] Tls Pointer to a TLS object.
3666 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
3667 cipher identifier comes from the TLS Cipher Suite
3668 Registry of the IANA, interpreting Byte1 and Byte2
3669 in network (big endian) byte order.
3670 @param[in] CipherNum The number of cipher in the list.
3672 @retval EFI_SUCCESS The ciphers list was set successfully.
3673 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3674 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
3675 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
3680 CryptoServiceTlsSetCipherList (
3682 IN UINT16
*CipherId
,
3686 return CALL_BASECRYPTLIB (TlsSet
.Services
.CipherList
, TlsSetCipherList
, (Tls
, CipherId
, CipherNum
), EFI_UNSUPPORTED
);
3690 Set the compression method for TLS/SSL operations.
3692 This function handles TLS/SSL integrated compression methods.
3694 @param[in] CompMethod The compression method ID.
3696 @retval EFI_SUCCESS The compression method for the communication was
3698 @retval EFI_UNSUPPORTED Unsupported compression method.
3703 CryptoServiceTlsSetCompressionMethod (
3707 return CALL_BASECRYPTLIB (TlsSet
.Services
.CompressionMethod
, TlsSetCompressionMethod
, (CompMethod
), EFI_UNSUPPORTED
);
3711 Set peer certificate verification mode for the TLS connection.
3713 This function sets the verification mode flags for the TLS connection.
3715 @param[in] Tls Pointer to the TLS object.
3716 @param[in] VerifyMode A set of logically or'ed verification mode flags.
3721 CryptoServiceTlsSetVerify (
3723 IN UINT32 VerifyMode
3726 CALL_VOID_BASECRYPTLIB (TlsSet
.Services
.Verify
, TlsSetVerify
, (Tls
, VerifyMode
));
3730 Set the specified host name to be verified.
3732 @param[in] Tls Pointer to the TLS object.
3733 @param[in] Flags The setting flags during the validation.
3734 @param[in] HostName The specified host name to be verified.
3736 @retval EFI_SUCCESS The HostName setting was set successfully.
3737 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3738 @retval EFI_ABORTED Invalid HostName setting.
3743 CryptoServiceTlsSetVerifyHost (
3749 return CALL_BASECRYPTLIB (TlsSet
.Services
.VerifyHost
, TlsSetVerifyHost
, (Tls
, Flags
, HostName
), EFI_UNSUPPORTED
);
3753 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
3755 This function sets a session ID to be used when the TLS/SSL connection is
3758 @param[in] Tls Pointer to the TLS object.
3759 @param[in] SessionId Session ID data used for session resumption.
3760 @param[in] SessionIdLen Length of Session ID in bytes.
3762 @retval EFI_SUCCESS Session ID was set successfully.
3763 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3764 @retval EFI_UNSUPPORTED No available session for ID setting.
3769 CryptoServiceTlsSetSessionId (
3771 IN UINT8
*SessionId
,
3772 IN UINT16 SessionIdLen
3775 return CALL_BASECRYPTLIB (TlsSet
.Services
.SessionId
, TlsSetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
3779 Adds the CA to the cert store when requesting Server or Client authentication.
3781 This function adds the CA certificate to the list of CAs when requesting
3782 Server or Client authentication for the chosen TLS connection.
3784 @param[in] Tls Pointer to the TLS object.
3785 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3786 X.509 certificate or PEM-encoded X.509 certificate.
3787 @param[in] DataSize The size of data buffer in bytes.
3789 @retval EFI_SUCCESS The operation succeeded.
3790 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3791 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3792 @retval EFI_ABORTED Invalid X.509 certificate.
3797 CryptoServiceTlsSetCaCertificate (
3803 return CALL_BASECRYPTLIB (TlsSet
.Services
.CaCertificate
, TlsSetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3807 Loads the local public certificate into the specified TLS object.
3809 This function loads the X.509 certificate into the specified TLS object
3810 for TLS negotiation.
3812 @param[in] Tls Pointer to the TLS object.
3813 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3814 X.509 certificate or PEM-encoded X.509 certificate.
3815 @param[in] DataSize The size of data buffer in bytes.
3817 @retval EFI_SUCCESS The operation succeeded.
3818 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3819 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3820 @retval EFI_ABORTED Invalid X.509 certificate.
3825 CryptoServiceTlsSetHostPublicCert (
3831 return CALL_BASECRYPTLIB (TlsSet
.Services
.HostPublicCert
, TlsSetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3835 Adds the local private key to the specified TLS object.
3837 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
3838 key) into the specified TLS object for TLS negotiation.
3840 @param[in] Tls Pointer to the TLS object.
3841 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
3842 or PKCS#8 private key.
3843 @param[in] DataSize The size of data buffer in bytes.
3845 @retval EFI_SUCCESS The operation succeeded.
3846 @retval EFI_UNSUPPORTED This function is not supported.
3847 @retval EFI_ABORTED Invalid private key data.
3852 CryptoServiceTlsSetHostPrivateKey (
3858 return CALL_BASECRYPTLIB (TlsSet
.Services
.HostPrivateKey
, TlsSetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
3862 Adds the CA-supplied certificate revocation list for certificate validation.
3864 This function adds the CA-supplied certificate revocation list data for
3865 certificate validity checking.
3867 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
3868 @param[in] DataSize The size of data buffer in bytes.
3870 @retval EFI_SUCCESS The operation succeeded.
3871 @retval EFI_UNSUPPORTED This function is not supported.
3872 @retval EFI_ABORTED Invalid CRL data.
3877 CryptoServiceTlsSetCertRevocationList (
3882 return CALL_BASECRYPTLIB (TlsSet
.Services
.CertRevocationList
, TlsSetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);
3886 Gets the protocol version used by the specified TLS connection.
3888 This function returns the protocol version used by the specified TLS
3891 If Tls is NULL, then ASSERT().
3893 @param[in] Tls Pointer to the TLS object.
3895 @return The protocol version of the specified TLS connection.
3900 CryptoServiceTlsGetVersion (
3904 return CALL_BASECRYPTLIB (TlsGet
.Services
.Version
, TlsGetVersion
, (Tls
), 0);
3908 Gets the connection end of the specified TLS connection.
3910 This function returns the connection end (as client or as server) used by
3911 the specified TLS connection.
3913 If Tls is NULL, then ASSERT().
3915 @param[in] Tls Pointer to the TLS object.
3917 @return The connection end used by the specified TLS connection.
3922 CryptoServiceTlsGetConnectionEnd (
3926 return CALL_BASECRYPTLIB (TlsGet
.Services
.ConnectionEnd
, TlsGetConnectionEnd
, (Tls
), 0);
3930 Gets the cipher suite used by the specified TLS connection.
3932 This function returns current cipher suite used by the specified
3935 @param[in] Tls Pointer to the TLS object.
3936 @param[in,out] CipherId The cipher suite used by the TLS object.
3938 @retval EFI_SUCCESS The cipher suite was returned successfully.
3939 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3940 @retval EFI_UNSUPPORTED Unsupported cipher suite.
3945 CryptoServiceTlsGetCurrentCipher (
3947 IN OUT UINT16
*CipherId
3950 return CALL_BASECRYPTLIB (TlsGet
.Services
.CurrentCipher
, TlsGetCurrentCipher
, (Tls
, CipherId
), EFI_UNSUPPORTED
);
3954 Gets the compression methods used by the specified TLS connection.
3956 This function returns current integrated compression methods used by
3957 the specified TLS connection.
3959 @param[in] Tls Pointer to the TLS object.
3960 @param[in,out] CompressionId The current compression method used by
3963 @retval EFI_SUCCESS The compression method was returned successfully.
3964 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3965 @retval EFI_ABORTED Invalid Compression method.
3966 @retval EFI_UNSUPPORTED This function is not supported.
3971 CryptoServiceTlsGetCurrentCompressionId (
3973 IN OUT UINT8
*CompressionId
3976 return CALL_BASECRYPTLIB (TlsGet
.Services
.CurrentCompressionId
, TlsGetCurrentCompressionId
, (Tls
, CompressionId
), EFI_UNSUPPORTED
);
3980 Gets the verification mode currently set in the TLS connection.
3982 This function returns the peer verification mode currently set in the
3983 specified TLS connection.
3985 If Tls is NULL, then ASSERT().
3987 @param[in] Tls Pointer to the TLS object.
3989 @return The verification mode set in the specified TLS connection.
3994 CryptoServiceTlsGetVerify (
3998 return CALL_BASECRYPTLIB (TlsGet
.Services
.Verify
, TlsGetVerify
, (Tls
), 0);
4002 Gets the session ID used by the specified TLS connection.
4004 This function returns the TLS/SSL session ID currently used by the
4005 specified TLS connection.
4007 @param[in] Tls Pointer to the TLS object.
4008 @param[in,out] SessionId Buffer to contain the returned session ID.
4009 @param[in,out] SessionIdLen The length of Session ID in bytes.
4011 @retval EFI_SUCCESS The Session ID was returned successfully.
4012 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4013 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
4018 CryptoServiceTlsGetSessionId (
4020 IN OUT UINT8
*SessionId
,
4021 IN OUT UINT16
*SessionIdLen
4024 return CALL_BASECRYPTLIB (TlsGet
.Services
.SessionId
, TlsGetSessionId
, (Tls
, SessionId
, SessionIdLen
), EFI_UNSUPPORTED
);
4028 Gets the client random data used in the specified TLS connection.
4030 This function returns the TLS/SSL client random data currently used in
4031 the specified TLS connection.
4033 @param[in] Tls Pointer to the TLS object.
4034 @param[in,out] ClientRandom Buffer to contain the returned client
4035 random data (32 bytes).
4040 CryptoServiceTlsGetClientRandom (
4042 IN OUT UINT8
*ClientRandom
4045 CALL_VOID_BASECRYPTLIB (TlsGet
.Services
.ClientRandom
, TlsGetClientRandom
, (Tls
, ClientRandom
));
4049 Gets the server random data used in the specified TLS connection.
4051 This function returns the TLS/SSL server random data currently used in
4052 the specified TLS connection.
4054 @param[in] Tls Pointer to the TLS object.
4055 @param[in,out] ServerRandom Buffer to contain the returned server
4056 random data (32 bytes).
4061 CryptoServiceTlsGetServerRandom (
4063 IN OUT UINT8
*ServerRandom
4066 CALL_VOID_BASECRYPTLIB (TlsGet
.Services
.ServerRandom
, TlsGetServerRandom
, (Tls
, ServerRandom
));
4070 Gets the master key data used in the specified TLS connection.
4072 This function returns the TLS/SSL master key material currently used in
4073 the specified TLS connection.
4075 @param[in] Tls Pointer to the TLS object.
4076 @param[in,out] KeyMaterial Buffer to contain the returned key material.
4078 @retval EFI_SUCCESS Key material was returned successfully.
4079 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4080 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
4085 CryptoServiceTlsGetKeyMaterial (
4087 IN OUT UINT8
*KeyMaterial
4090 return CALL_BASECRYPTLIB (TlsGet
.Services
.KeyMaterial
, TlsGetKeyMaterial
, (Tls
, KeyMaterial
), EFI_UNSUPPORTED
);
4094 Gets the CA Certificate from the cert store.
4096 This function returns the CA certificate for the chosen
4099 @param[in] Tls Pointer to the TLS object.
4100 @param[out] Data Pointer to the data buffer to receive the CA
4101 certificate data sent to the client.
4102 @param[in,out] DataSize The size of data buffer in bytes.
4104 @retval EFI_SUCCESS The operation succeeded.
4105 @retval EFI_UNSUPPORTED This function is not supported.
4106 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4111 CryptoServiceTlsGetCaCertificate (
4114 IN OUT UINTN
*DataSize
4117 return CALL_BASECRYPTLIB (TlsGet
.Services
.CaCertificate
, TlsGetCaCertificate
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4121 Gets the local public Certificate set in the specified TLS object.
4123 This function returns the local public certificate which was currently set
4124 in the specified TLS object.
4126 @param[in] Tls Pointer to the TLS object.
4127 @param[out] Data Pointer to the data buffer to receive the local
4129 @param[in,out] DataSize The size of data buffer in bytes.
4131 @retval EFI_SUCCESS The operation succeeded.
4132 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4133 @retval EFI_NOT_FOUND The certificate is not found.
4134 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4139 CryptoServiceTlsGetHostPublicCert (
4142 IN OUT UINTN
*DataSize
4145 return CALL_BASECRYPTLIB (TlsGet
.Services
.HostPublicCert
, TlsGetHostPublicCert
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4149 Gets the local private key set in the specified TLS object.
4151 This function returns the local private key data which was currently set
4152 in the specified TLS object.
4154 @param[in] Tls Pointer to the TLS object.
4155 @param[out] Data Pointer to the data buffer to receive the local
4157 @param[in,out] DataSize The size of data buffer in bytes.
4159 @retval EFI_SUCCESS The operation succeeded.
4160 @retval EFI_UNSUPPORTED This function is not supported.
4161 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4166 CryptoServiceTlsGetHostPrivateKey (
4169 IN OUT UINTN
*DataSize
4172 return CALL_BASECRYPTLIB (TlsGet
.Services
.HostPrivateKey
, TlsGetHostPrivateKey
, (Tls
, Data
, DataSize
), EFI_UNSUPPORTED
);
4176 Gets the CA-supplied certificate revocation list data set in the specified
4179 This function returns the CA-supplied certificate revocation list data which
4180 was currently set in the specified TLS object.
4182 @param[out] Data Pointer to the data buffer to receive the CRL data.
4183 @param[in,out] DataSize The size of data buffer in bytes.
4185 @retval EFI_SUCCESS The operation succeeded.
4186 @retval EFI_UNSUPPORTED This function is not supported.
4187 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4192 CryptoServiceTlsGetCertRevocationList (
4194 IN OUT UINTN
*DataSize
4197 return CALL_BASECRYPTLIB (TlsGet
.Services
.CertRevocationList
, TlsGetCertRevocationList
, (Data
, DataSize
), EFI_UNSUPPORTED
);
4200 const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto
= {
4202 CryptoServiceGetCryptoVersion
,
4203 /// HMAC MD5 - deprecated and unsupported
4204 DeprecatedCryptoServiceHmacMd5New
,
4205 DeprecatedCryptoServiceHmacMd5Free
,
4206 DeprecatedCryptoServiceHmacMd5SetKey
,
4207 DeprecatedCryptoServiceHmacMd5Duplicate
,
4208 DeprecatedCryptoServiceHmacMd5Update
,
4209 DeprecatedCryptoServiceHmacMd5Final
,
4211 CryptoServiceHmacSha1New
,
4212 CryptoServiceHmacSha1Free
,
4213 CryptoServiceHmacSha1SetKey
,
4214 CryptoServiceHmacSha1Duplicate
,
4215 CryptoServiceHmacSha1Update
,
4216 CryptoServiceHmacSha1Final
,
4218 CryptoServiceHmacSha256New
,
4219 CryptoServiceHmacSha256Free
,
4220 CryptoServiceHmacSha256SetKey
,
4221 CryptoServiceHmacSha256Duplicate
,
4222 CryptoServiceHmacSha256Update
,
4223 CryptoServiceHmacSha256Final
,
4224 /// Md4 - deprecated and unsupported
4225 DeprecatedCryptoServiceMd4GetContextSize
,
4226 DeprecatedCryptoServiceMd4Init
,
4227 DeprecatedCryptoServiceMd4Duplicate
,
4228 DeprecatedCryptoServiceMd4Update
,
4229 DeprecatedCryptoServiceMd4Final
,
4230 DeprecatedCryptoServiceMd4HashAll
,
4232 CryptoServiceMd5GetContextSize
,
4233 CryptoServiceMd5Init
,
4234 CryptoServiceMd5Duplicate
,
4235 CryptoServiceMd5Update
,
4236 CryptoServiceMd5Final
,
4237 CryptoServiceMd5HashAll
,
4239 CryptoServicePkcs1v2Encrypt
,
4240 CryptoServicePkcs5HashPassword
,
4241 CryptoServicePkcs7Verify
,
4242 CryptoServiceVerifyEKUsInPkcs7Signature
,
4243 CryptoServicePkcs7GetSigners
,
4244 CryptoServicePkcs7FreeSigners
,
4245 CryptoServicePkcs7Sign
,
4246 CryptoServicePkcs7GetAttachedContent
,
4247 CryptoServicePkcs7GetCertificatesList
,
4248 CryptoServiceAuthenticodeVerify
,
4249 CryptoServiceImageTimestampVerify
,
4252 CryptoServiceDhFree
,
4253 CryptoServiceDhGenerateParameter
,
4254 CryptoServiceDhSetParameter
,
4255 CryptoServiceDhGenerateKey
,
4256 CryptoServiceDhComputeKey
,
4258 CryptoServiceRandomSeed
,
4259 CryptoServiceRandomBytes
,
4261 CryptoServiceRsaPkcs1Verify
,
4262 CryptoServiceRsaNew
,
4263 CryptoServiceRsaFree
,
4264 CryptoServiceRsaSetKey
,
4265 CryptoServiceRsaGetKey
,
4266 CryptoServiceRsaGenerateKey
,
4267 CryptoServiceRsaCheckKey
,
4268 CryptoServiceRsaPkcs1Sign
,
4269 CryptoServiceRsaPkcs1Verify
,
4270 CryptoServiceRsaGetPrivateKeyFromPem
,
4271 CryptoServiceRsaGetPublicKeyFromX509
,
4273 CryptoServiceSha1GetContextSize
,
4274 CryptoServiceSha1Init
,
4275 CryptoServiceSha1Duplicate
,
4276 CryptoServiceSha1Update
,
4277 CryptoServiceSha1Final
,
4278 CryptoServiceSha1HashAll
,
4280 CryptoServiceSha256GetContextSize
,
4281 CryptoServiceSha256Init
,
4282 CryptoServiceSha256Duplicate
,
4283 CryptoServiceSha256Update
,
4284 CryptoServiceSha256Final
,
4285 CryptoServiceSha256HashAll
,
4287 CryptoServiceSha384GetContextSize
,
4288 CryptoServiceSha384Init
,
4289 CryptoServiceSha384Duplicate
,
4290 CryptoServiceSha384Update
,
4291 CryptoServiceSha384Final
,
4292 CryptoServiceSha384HashAll
,
4294 CryptoServiceSha512GetContextSize
,
4295 CryptoServiceSha512Init
,
4296 CryptoServiceSha512Duplicate
,
4297 CryptoServiceSha512Update
,
4298 CryptoServiceSha512Final
,
4299 CryptoServiceSha512HashAll
,
4301 CryptoServiceX509GetSubjectName
,
4302 CryptoServiceX509GetCommonName
,
4303 CryptoServiceX509GetOrganizationName
,
4304 CryptoServiceX509VerifyCert
,
4305 CryptoServiceX509ConstructCertificate
,
4306 CryptoServiceX509ConstructCertificateStack
,
4307 CryptoServiceX509Free
,
4308 CryptoServiceX509StackFree
,
4309 CryptoServiceX509GetTBSCert
,
4310 /// TDES - deprecated and unsupported
4311 DeprecatedCryptoServiceTdesGetContextSize
,
4312 DeprecatedCryptoServiceTdesInit
,
4313 DeprecatedCryptoServiceTdesEcbEncrypt
,
4314 DeprecatedCryptoServiceTdesEcbDecrypt
,
4315 DeprecatedCryptoServiceTdesCbcEncrypt
,
4316 DeprecatedCryptoServiceTdesCbcDecrypt
,
4317 /// AES - ECB mode is deprecated and unsupported
4318 CryptoServiceAesGetContextSize
,
4319 CryptoServiceAesInit
,
4320 DeprecatedCryptoServiceAesEcbEncrypt
,
4321 DeprecatedCryptoServiceAesEcbDecrypt
,
4322 CryptoServiceAesCbcEncrypt
,
4323 CryptoServiceAesCbcDecrypt
,
4324 /// Arc4 - deprecated and unsupported
4325 DeprecatedCryptoServiceArc4GetContextSize
,
4326 DeprecatedCryptoServiceArc4Init
,
4327 DeprecatedCryptoServiceArc4Encrypt
,
4328 DeprecatedCryptoServiceArc4Decrypt
,
4329 DeprecatedCryptoServiceArc4Reset
,
4331 CryptoServiceSm3GetContextSize
,
4332 CryptoServiceSm3Init
,
4333 CryptoServiceSm3Duplicate
,
4334 CryptoServiceSm3Update
,
4335 CryptoServiceSm3Final
,
4336 CryptoServiceSm3HashAll
,
4338 CryptoServiceHkdfSha256ExtractAndExpand
,
4339 /// X509 (Continued)
4340 CryptoServiceX509ConstructCertificateStackV
,
4342 CryptoServiceTlsInitialize
,
4343 CryptoServiceTlsCtxFree
,
4344 CryptoServiceTlsCtxNew
,
4345 CryptoServiceTlsFree
,
4346 CryptoServiceTlsNew
,
4347 CryptoServiceTlsInHandshake
,
4348 CryptoServiceTlsDoHandshake
,
4349 CryptoServiceTlsHandleAlert
,
4350 CryptoServiceTlsCloseNotify
,
4351 CryptoServiceTlsCtrlTrafficOut
,
4352 CryptoServiceTlsCtrlTrafficIn
,
4353 CryptoServiceTlsRead
,
4354 CryptoServiceTlsWrite
,
4356 CryptoServiceTlsSetVersion
,
4357 CryptoServiceTlsSetConnectionEnd
,
4358 CryptoServiceTlsSetCipherList
,
4359 CryptoServiceTlsSetCompressionMethod
,
4360 CryptoServiceTlsSetVerify
,
4361 CryptoServiceTlsSetVerifyHost
,
4362 CryptoServiceTlsSetSessionId
,
4363 CryptoServiceTlsSetCaCertificate
,
4364 CryptoServiceTlsSetHostPublicCert
,
4365 CryptoServiceTlsSetHostPrivateKey
,
4366 CryptoServiceTlsSetCertRevocationList
,
4368 CryptoServiceTlsGetVersion
,
4369 CryptoServiceTlsGetConnectionEnd
,
4370 CryptoServiceTlsGetCurrentCipher
,
4371 CryptoServiceTlsGetCurrentCompressionId
,
4372 CryptoServiceTlsGetVerify
,
4373 CryptoServiceTlsGetSessionId
,
4374 CryptoServiceTlsGetClientRandom
,
4375 CryptoServiceTlsGetServerRandom
,
4376 CryptoServiceTlsGetKeyMaterial
,
4377 CryptoServiceTlsGetCaCertificate
,
4378 CryptoServiceTlsGetHostPublicCert
,
4379 CryptoServiceTlsGetHostPrivateKey
,
4380 CryptoServiceTlsGetCertRevocationList