X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=CryptoPkg%2FInclude%2FLibrary%2FBaseCryptLib.h;h=0371d73b86b17630c6d89ecd95c44006068197d7;hp=ee8c44d367efa9163bc0790545f343f85d25ef25;hb=0f5f6b3db7c12405e4c942cd00ead0749cce41f2;hpb=a8c4464502aabcbda7032daddc772a1bc7386bdf diff --git a/CryptoPkg/Include/Library/BaseCryptLib.h b/CryptoPkg/Include/Library/BaseCryptLib.h index ee8c44d367..0371d73b86 100644 --- a/CryptoPkg/Include/Library/BaseCryptLib.h +++ b/CryptoPkg/Include/Library/BaseCryptLib.h @@ -4,7 +4,7 @@ primitives (Hash Serials, HMAC, RSA, Diffie-Hellman, etc) for UEFI security functionality enabling. -Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -18,6 +18,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #ifndef __BASE_CRYPT_LIB_H__ #define __BASE_CRYPT_LIB_H__ +#include + +/// +/// MD4 digest size in bytes +/// +#define MD4_DIGEST_SIZE 16 + /// /// MD5 digest size in bytes /// @@ -33,6 +40,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. /// #define SHA256_DIGEST_SIZE 32 +/// +/// SHA-384 digest size in bytes +/// +#define SHA384_DIGEST_SIZE 48 + +/// +/// SHA-512 digest size in bytes +/// +#define SHA512_DIGEST_SIZE 64 + /// /// TDES block size in bytes /// @@ -61,10 +78,127 @@ typedef enum { // One-Way Cryptographic Hash Primitives //===================================================================================== +/** + Retrieves the size, in bytes, of the context buffer required for MD4 hash operations. + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for MD4 hash operations. + @retval 0 This interface is not supported. + +**/ +UINTN +EFIAPI +Md4GetContextSize ( + VOID + ); + +/** + Initializes user-supplied memory pointed by Md4Context as MD4 hash context for + subsequent use. + + If Md4Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] Md4Context Pointer to MD4 context being initialized. + + @retval TRUE MD4 context initialization succeeded. + @retval FALSE MD4 context initialization failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Md4Init ( + OUT VOID *Md4Context + ); + +/** + Makes a copy of an existing MD4 context. + + If Md4Context is NULL, then return FALSE. + If NewMd4Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Md4Context Pointer to MD4 context being copied. + @param[out] NewMd4Context Pointer to new MD4 context. + + @retval TRUE MD4 context copy succeeded. + @retval FALSE MD4 context copy failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Md4Duplicate ( + IN CONST VOID *Md4Context, + OUT VOID *NewMd4Context + ); + +/** + Digests the input data and updates MD4 context. + + This function performs MD4 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + MD4 context should be already correctly intialized by Md4Init(), and should not be finalized + by Md4Final(). Behavior with invalid context is undefined. + + If Md4Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Md4Context Pointer to the MD4 context. + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE MD4 data digest succeeded. + @retval FALSE MD4 data digest failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Md4Update ( + IN OUT VOID *Md4Context, + IN CONST VOID *Data, + IN UINTN DataSize + ); + +/** + Completes computation of the MD4 digest value. + + This function completes MD4 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the MD4 context cannot + be used again. + MD4 context should be already correctly intialized by Md4Init(), and should not be + finalized by Md4Final(). Behavior with invalid MD4 context is undefined. + + If Md4Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Md4Context Pointer to the MD4 context. + @param[out] HashValue Pointer to a buffer that receives the MD4 digest + value (16 bytes). + + @retval TRUE MD4 digest computation succeeded. + @retval FALSE MD4 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Md4Final ( + IN OUT VOID *Md4Context, + OUT UINT8 *HashValue + ); + /** Retrieves the size, in bytes, of the context buffer required for MD5 hash operations. + If this interface is not supported, then return zero. + @return The size, in bytes, of the context buffer required for MD5 hash operations. + @retval 0 This interface is not supported. **/ UINTN @@ -77,12 +211,14 @@ Md5GetContextSize ( Initializes user-supplied memory pointed by Md5Context as MD5 hash context for subsequent use. - If Md5Context is NULL, then ASSERT(). + If Md5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[out] Md5Context Pointer to MD5 context being initialized. @retval TRUE MD5 context initialization succeeded. @retval FALSE MD5 context initialization failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -94,14 +230,16 @@ Md5Init ( /** Makes a copy of an existing MD5 context. - If Md5Context is NULL, then ASSERT(). - If NewMd5Context is NULL, then ASSERT(). + If Md5Context is NULL, then return FALSE. + If NewMd5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] Md5Context Pointer to MD5 context being copied. @param[out] NewMd5Context Pointer to new MD5 context. @retval TRUE MD5 context copy succeeded. @retval FALSE MD5 context copy failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -119,7 +257,8 @@ Md5Duplicate ( MD5 context should be already correctly intialized by Md5Init(), and should not be finalized by Md5Final(). Behavior with invalid context is undefined. - If Md5Context is NULL, then ASSERT(). + If Md5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in, out] Md5Context Pointer to the MD5 context. @param[in] Data Pointer to the buffer containing the data to be hashed. @@ -127,6 +266,7 @@ Md5Duplicate ( @retval TRUE MD5 data digest succeeded. @retval FALSE MD5 data digest failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -146,8 +286,9 @@ Md5Update ( MD5 context should be already correctly intialized by Md5Init(), and should not be finalized by Md5Final(). Behavior with invalid MD5 context is undefined. - If Md5Context is NULL, then ASSERT(). - If HashValue is NULL, then ASSERT(). + If Md5Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in, out] Md5Context Pointer to the MD5 context. @param[out] HashValue Pointer to a buffer that receives the MD5 digest @@ -155,6 +296,7 @@ Md5Update ( @retval TRUE MD5 digest computation succeeded. @retval FALSE MD5 digest computation failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -167,7 +309,10 @@ Md5Final ( /** Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations. + If this interface is not supported, then return zero. + @return The size, in bytes, of the context buffer required for SHA-1 hash operations. + @retval 0 This interface is not supported. **/ UINTN @@ -180,12 +325,14 @@ Sha1GetContextSize ( Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for subsequent use. - If Sha1Context is NULL, then ASSERT(). + If Sha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[out] Sha1Context Pointer to SHA-1 context being initialized. @retval TRUE SHA-1 context initialization succeeded. @retval FALSE SHA-1 context initialization failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -197,14 +344,16 @@ Sha1Init ( /** Makes a copy of an existing SHA-1 context. - If Sha1Context is NULL, then ASSERT(). - If NewSha1Context is NULL, then ASSERT(). + If Sha1Context is NULL, then return FALSE. + If NewSha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] Sha1Context Pointer to SHA-1 context being copied. @param[out] NewSha1Context Pointer to new SHA-1 context. @retval TRUE SHA-1 context copy succeeded. @retval FALSE SHA-1 context copy failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -222,7 +371,8 @@ Sha1Duplicate ( SHA-1 context should be already correctly intialized by Sha1Init(), and should not be finalized by Sha1Final(). Behavior with invalid context is undefined. - If Sha1Context is NULL, then ASSERT(). + If Sha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in, out] Sha1Context Pointer to the SHA-1 context. @param[in] Data Pointer to the buffer containing the data to be hashed. @@ -230,6 +380,7 @@ Sha1Duplicate ( @retval TRUE SHA-1 data digest succeeded. @retval FALSE SHA-1 data digest failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -249,8 +400,9 @@ Sha1Update ( SHA-1 context should be already correctly intialized by Sha1Init(), and should not be finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined. - If Sha1Context is NULL, then ASSERT(). - If HashValue is NULL, then ASSERT(). + If Sha1Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in, out] Sha1Context Pointer to the SHA-1 context. @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest @@ -258,6 +410,7 @@ Sha1Update ( @retval TRUE SHA-1 digest computation succeeded. @retval FALSE SHA-1 digest computation failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -283,7 +436,7 @@ Sha256GetContextSize ( Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for subsequent use. - If Sha256Context is NULL, then ASSERT(). + If Sha256Context is NULL, then return FALSE. @param[out] Sha256Context Pointer to SHA-256 context being initialized. @@ -300,14 +453,16 @@ Sha256Init ( /** Makes a copy of an existing SHA-256 context. - If Sha256Context is NULL, then ASSERT(). - If NewSha256Context is NULL, then ASSERT(). + If Sha256Context is NULL, then return FALSE. + If NewSha256Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] Sha256Context Pointer to SHA-256 context being copied. @param[out] NewSha256Context Pointer to new SHA-256 context. @retval TRUE SHA-256 context copy succeeded. @retval FALSE SHA-256 context copy failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -325,7 +480,7 @@ Sha256Duplicate ( SHA-256 context should be already correctly intialized by Sha256Init(), and should not be finalized by Sha256Final(). Behavior with invalid context is undefined. - If Sha256Context is NULL, then ASSERT(). + If Sha256Context is NULL, then return FALSE. @param[in, out] Sha256Context Pointer to the SHA-256 context. @param[in] Data Pointer to the buffer containing the data to be hashed. @@ -352,8 +507,8 @@ Sha256Update ( SHA-256 context should be already correctly intialized by Sha256Init(), and should not be finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined. - If Sha256Context is NULL, then ASSERT(). - If HashValue is NULL, then ASSERT(). + If Sha256Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. @param[in, out] Sha256Context Pointer to the SHA-256 context. @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest @@ -370,6 +525,215 @@ Sha256Final ( OUT UINT8 *HashValue ); +/** + Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations. + + @return The size, in bytes, of the context buffer required for SHA-384 hash operations. + +**/ +UINTN +EFIAPI +Sha384GetContextSize ( + VOID + ); + +/** + Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for + subsequent use. + + If Sha384Context is NULL, then return FALSE. + + @param[out] Sha384Context Pointer to SHA-384 context being initialized. + + @retval TRUE SHA-384 context initialization succeeded. + @retval FALSE SHA-384 context initialization failed. + +**/ +BOOLEAN +EFIAPI +Sha384Init ( + OUT VOID *Sha384Context + ); + +/** + Makes a copy of an existing SHA-384 context. + + If Sha384Context is NULL, then return FALSE. + If NewSha384Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Sha384Context Pointer to SHA-384 context being copied. + @param[out] NewSha384Context Pointer to new SHA-384 context. + + @retval TRUE SHA-384 context copy succeeded. + @retval FALSE SHA-384 context copy failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Sha384Duplicate ( + IN CONST VOID *Sha384Context, + OUT VOID *NewSha384Context + ); + +/** + Digests the input data and updates SHA-384 context. + + This function performs SHA-384 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + SHA-384 context should be already correctly intialized by Sha384Init(), and should not be finalized + by Sha384Final(). Behavior with invalid context is undefined. + + If Sha384Context is NULL, then return FALSE. + + @param[in, out] Sha384Context Pointer to the SHA-384 context. + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE SHA-384 data digest succeeded. + @retval FALSE SHA-384 data digest failed. + +**/ +BOOLEAN +EFIAPI +Sha384Update ( + IN OUT VOID *Sha384Context, + IN CONST VOID *Data, + IN UINTN DataSize + ); + +/** + Completes computation of the SHA-384 digest value. + + This function completes SHA-384 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the SHA-384 context cannot + be used again. + SHA-384 context should be already correctly intialized by Sha384Init(), and should not be + finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined. + + If Sha384Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + + @param[in, out] Sha384Context Pointer to the SHA-384 context. + @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest + value (48 bytes). + + @retval TRUE SHA-384 digest computation succeeded. + @retval FALSE SHA-384 digest computation failed. + +**/ +BOOLEAN +EFIAPI +Sha384Final ( + IN OUT VOID *Sha384Context, + OUT UINT8 *HashValue + ); + +/** + Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations. + + @return The size, in bytes, of the context buffer required for SHA-512 hash operations. + +**/ +UINTN +EFIAPI +Sha512GetContextSize ( + VOID + ); + +/** + Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for + subsequent use. + + If Sha512Context is NULL, then return FALSE. + + @param[out] Sha512Context Pointer to SHA-512 context being initialized. + + @retval TRUE SHA-512 context initialization succeeded. + @retval FALSE SHA-512 context initialization failed. + +**/ +BOOLEAN +EFIAPI +Sha512Init ( + OUT VOID *Sha512Context + ); + +/** + Makes a copy of an existing SHA-512 context. + + If Sha512Context is NULL, then return FALSE. + If NewSha512Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Sha512Context Pointer to SHA-512 context being copied. + @param[out] NewSha512Context Pointer to new SHA-512 context. + + @retval TRUE SHA-512 context copy succeeded. + @retval FALSE SHA-512 context copy failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Sha512Duplicate ( + IN CONST VOID *Sha512Context, + OUT VOID *NewSha512Context + ); + +/** + Digests the input data and updates SHA-512 context. + + This function performs SHA-512 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + SHA-512 context should be already correctly intialized by Sha512Init(), and should not be finalized + by Sha512Final(). Behavior with invalid context is undefined. + + If Sha512Context is NULL, then return FALSE. + + @param[in, out] Sha512Context Pointer to the SHA-512 context. + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE SHA-512 data digest succeeded. + @retval FALSE SHA-512 data digest failed. + +**/ +BOOLEAN +EFIAPI +Sha512Update ( + IN OUT VOID *Sha512Context, + IN CONST VOID *Data, + IN UINTN DataSize + ); + +/** + Completes computation of the SHA-512 digest value. + + This function completes SHA-512 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the SHA-512 context cannot + be used again. + SHA-512 context should be already correctly intialized by Sha512Init(), and should not be + finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined. + + If Sha512Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + + @param[in, out] Sha512Context Pointer to the SHA-512 context. + @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest + value (64 bytes). + + @retval TRUE SHA-512 digest computation succeeded. + @retval FALSE SHA-512 digest computation failed. + +**/ +BOOLEAN +EFIAPI +Sha512Final ( + IN OUT VOID *Sha512Context, + OUT UINT8 *HashValue + ); //===================================================================================== // MAC (Message Authentication Code) Primitive @@ -378,7 +742,10 @@ Sha256Final ( /** Retrieves the size, in bytes, of the context buffer required for HMAC-MD5 operations. + If this interface is not supported, then return zero. + @return The size, in bytes, of the context buffer required for HMAC-MD5 operations. + @retval 0 This interface is not supported. **/ UINTN @@ -391,7 +758,8 @@ HmacMd5GetContextSize ( Initializes user-supplied memory pointed by HmacMd5Context as HMAC-MD5 context for subsequent use. - If HmacMd5Context is NULL, then ASSERT(). + If HmacMd5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[out] HmacMd5Context Pointer to HMAC-MD5 context being initialized. @param[in] Key Pointer to the user-supplied key. @@ -399,6 +767,7 @@ HmacMd5GetContextSize ( @retval TRUE HMAC-MD5 context initialization succeeded. @retval FALSE HMAC-MD5 context initialization failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -412,14 +781,16 @@ HmacMd5Init ( /** Makes a copy of an existing HMAC-MD5 context. - If HmacMd5Context is NULL, then ASSERT(). - If NewHmacMd5Context is NULL, then ASSERT(). + If HmacMd5Context is NULL, then return FALSE. + If NewHmacMd5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied. @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context. @retval TRUE HMAC-MD5 context copy succeeded. @retval FALSE HMAC-MD5 context copy failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -437,7 +808,8 @@ HmacMd5Duplicate ( HMAC-MD5 context should be already correctly intialized by HmacMd5Init(), and should not be finalized by HmacMd5Final(). Behavior with invalid context is undefined. - If HmacMd5Context is NULL, then ASSERT(). + If HmacMd5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context. @param[in] Data Pointer to the buffer containing the data to be digested. @@ -445,6 +817,7 @@ HmacMd5Duplicate ( @retval TRUE HMAC-MD5 data digest succeeded. @retval FALSE HMAC-MD5 data digest failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -464,8 +837,9 @@ HmacMd5Update ( HMAC-MD5 context should be already correctly intialized by HmacMd5Init(), and should not be finalized by HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined. - If HmacMd5Context is NULL, then ASSERT(). - If HashValue is NULL, then ASSERT(). + If HmacMd5Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context. @param[out] HashValue Pointer to a buffer that receives the HMAC-MD5 digest @@ -473,6 +847,7 @@ HmacMd5Update ( @retval TRUE HMAC-MD5 digest computation succeeded. @retval FALSE HMAC-MD5 digest computation failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -485,7 +860,10 @@ HmacMd5Final ( /** Retrieves the size, in bytes, of the context buffer required for HMAC-SHA1 operations. + If this interface is not supported, then return zero. + @return The size, in bytes, of the context buffer required for HMAC-SHA1 operations. + @retval 0 This interface is not supported. **/ UINTN @@ -498,7 +876,8 @@ HmacSha1GetContextSize ( Initializes user-supplied memory pointed by HmacSha1Context as HMAC-SHA1 context for subsequent use. - If HmacSha1Context is NULL, then ASSERT(). + If HmacSha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[out] HmacSha1Context Pointer to HMAC-SHA1 context being initialized. @param[in] Key Pointer to the user-supplied key. @@ -506,6 +885,7 @@ HmacSha1GetContextSize ( @retval TRUE HMAC-SHA1 context initialization succeeded. @retval FALSE HMAC-SHA1 context initialization failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -519,14 +899,16 @@ HmacSha1Init ( /** Makes a copy of an existing HMAC-SHA1 context. - If HmacSha1Context is NULL, then ASSERT(). - If NewHmacSha1Context is NULL, then ASSERT(). + If HmacSha1Context is NULL, then return FALSE. + If NewHmacSha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied. @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context. @retval TRUE HMAC-SHA1 context copy succeeded. @retval FALSE HMAC-SHA1 context copy failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -544,7 +926,8 @@ HmacSha1Duplicate ( HMAC-SHA1 context should be already correctly intialized by HmacSha1Init(), and should not be finalized by HmacSha1Final(). Behavior with invalid context is undefined. - If HmacSha1Context is NULL, then ASSERT(). + If HmacSha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context. @param[in] Data Pointer to the buffer containing the data to be digested. @@ -552,6 +935,7 @@ HmacSha1Duplicate ( @retval TRUE HMAC-SHA1 data digest succeeded. @retval FALSE HMAC-SHA1 data digest failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -571,8 +955,9 @@ HmacSha1Update ( HMAC-SHA1 context should be already correctly intialized by HmacSha1Init(), and should not be finalized by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined. - If HmacSha1Context is NULL, then ASSERT(). - If HashValue is NULL, then ASSERT(). + If HmacSha1Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context. @param[out] HashValue Pointer to a buffer that receives the HMAC-SHA1 digest @@ -580,6 +965,7 @@ HmacSha1Update ( @retval TRUE HMAC-SHA1 digest computation succeeded. @retval FALSE HMAC-SHA1 digest computation failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -589,7 +975,6 @@ HmacSha1Final ( OUT UINT8 *HmacValue ); - //===================================================================================== // Symmetric Cryptography Primitive //===================================================================================== @@ -597,7 +982,10 @@ HmacSha1Final ( /** Retrieves the size, in bytes, of the context buffer required for TDES operations. + If this interface is not supported, then return zero. + @return The size, in bytes, of the context buffer required for TDES operations. + @retval 0 This interface is not supported. **/ UINTN @@ -610,16 +998,17 @@ TdesGetContextSize ( Initializes user-supplied memory as TDES context for subsequent use. This function initializes user-supplied memory pointed by TdesContext as TDES context. - In addtion, it sets up all TDES key materials for subsequent encryption and decryption + In addition, it sets up all TDES key materials for subsequent encryption and decryption operations. There are 3 key options as follows: KeyLength = 64, Keying option 1: K1 == K2 == K3 (Backward compatibility with DES) KeyLength = 128, Keying option 2: K1 != K2 and K3 = K1 (Less Security) KeyLength = 192 Keying option 3: K1 != K2 != K3 (Strongest) - If TdesContext is NULL, then ASSERT(). - If Key is NULL, then ASSERT(). - If KeyLength is not valid, then ASSERT(). + If TdesContext is NULL, then return FALSE. + If Key is NULL, then return FALSE. + If KeyLength is not valid, then return FALSE. + If this interface is not supported, then return FALSE. @param[out] TdesContext Pointer to TDES context being initialized. @param[in] Key Pointer to the user-supplied TDES key. @@ -627,6 +1016,7 @@ TdesGetContextSize ( @retval TRUE TDES context initialization succeeded. @retval FALSE TDES context initialization failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -647,10 +1037,11 @@ TdesInit ( TdesContext should be already correctly initialized by TdesInit(). Behavior with invalid TDES context is undefined. - If TdesContext is NULL, then ASSERT(). - If Input is NULL, then ASSERT(). - If InputSize is not multiple of block size (8 bytes), then ASSERT(). - If Output is NULL, then ASSERT(). + If TdesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (8 bytes), then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] TdesContext Pointer to the TDES context. @param[in] Input Pointer to the buffer containing the data to be encrypted. @@ -659,6 +1050,7 @@ TdesInit ( @retval TRUE TDES encryption succeeded. @retval FALSE TDES encryption failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -680,10 +1072,11 @@ TdesEcbEncrypt ( TdesContext should be already correctly initialized by TdesInit(). Behavior with invalid TDES context is undefined. - If TdesContext is NULL, then ASSERT(). - If Input is NULL, then ASSERT(). - If InputSize is not multiple of block size (8 bytes), then ASSERT(). - If Output is NULL, then ASSERT(). + If TdesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (8 bytes), then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] TdesContext Pointer to the TDES context. @param[in] Input Pointer to the buffer containing the data to be decrypted. @@ -692,6 +1085,7 @@ TdesEcbEncrypt ( @retval TRUE TDES decryption succeeded. @retval FALSE TDES decryption failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -714,11 +1108,12 @@ TdesEcbDecrypt ( TdesContext should be already correctly initialized by TdesInit(). Behavior with invalid TDES context is undefined. - If TdesContext is NULL, then ASSERT(). - If Input is NULL, then ASSERT(). - If InputSize is not multiple of block size (8 bytes), then ASSERT(). - If Ivec is NULL, then ASSERT(). - If Output is NULL, then ASSERT(). + If TdesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (8 bytes), then return FALSE. + If Ivec is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] TdesContext Pointer to the TDES context. @param[in] Input Pointer to the buffer containing the data to be encrypted. @@ -728,6 +1123,7 @@ TdesEcbDecrypt ( @retval TRUE TDES encryption succeeded. @retval FALSE TDES encryption failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -751,11 +1147,12 @@ TdesCbcEncrypt ( TdesContext should be already correctly initialized by TdesInit(). Behavior with invalid TDES context is undefined. - If TdesContext is NULL, then ASSERT(). - If Input is NULL, then ASSERT(). - If InputSize is not multiple of block size (8 bytes), then ASSERT(). - If Ivec is NULL, then ASSERT(). - If Output is NULL, then ASSERT(). + If TdesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (8 bytes), then return FALSE. + If Ivec is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] TdesContext Pointer to the TDES context. @param[in] Input Pointer to the buffer containing the data to be encrypted. @@ -765,6 +1162,7 @@ TdesCbcEncrypt ( @retval TRUE TDES decryption succeeded. @retval FALSE TDES decryption failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -780,7 +1178,10 @@ TdesCbcDecrypt ( /** Retrieves the size, in bytes, of the context buffer required for AES operations. + If this interface is not supported, then return zero. + @return The size, in bytes, of the context buffer required for AES operations. + @retval 0 This interface is not supported. **/ UINTN @@ -793,13 +1194,14 @@ AesGetContextSize ( Initializes user-supplied memory as AES context for subsequent use. This function initializes user-supplied memory pointed by AesContext as AES context. - In addtion, it sets up all AES key materials for subsequent encryption and decryption + In addition, it sets up all AES key materials for subsequent encryption and decryption operations. There are 3 options for key length, 128 bits, 192 bits, and 256 bits. - If AesContext is NULL, then ASSERT(). - If Key is NULL, then ASSERT(). - If KeyLength is not valid, then ASSERT(). + If AesContext is NULL, then return FALSE. + If Key is NULL, then return FALSE. + If KeyLength is not valid, then return FALSE. + If this interface is not supported, then return FALSE. @param[out] AesContext Pointer to AES context being initialized. @param[in] Key Pointer to the user-supplied AES key. @@ -807,6 +1209,7 @@ AesGetContextSize ( @retval TRUE AES context initialization succeeded. @retval FALSE AES context initialization failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -827,10 +1230,11 @@ AesInit ( AesContext should be already correctly initialized by AesInit(). Behavior with invalid AES context is undefined. - If AesContext is NULL, then ASSERT(). - If Input is NULL, then ASSERT(). - If InputSize is not multiple of block size (16 bytes), then ASSERT(). - If Output is NULL, then ASSERT(). + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (16 bytes), then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] AesContext Pointer to the AES context. @param[in] Input Pointer to the buffer containing the data to be encrypted. @@ -839,6 +1243,7 @@ AesInit ( @retval TRUE AES encryption succeeded. @retval FALSE AES encryption failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -860,10 +1265,11 @@ AesEcbEncrypt ( AesContext should be already correctly initialized by AesInit(). Behavior with invalid AES context is undefined. - If AesContext is NULL, then ASSERT(). - If Input is NULL, then ASSERT(). - If InputSize is not multiple of block size (16 bytes), then ASSERT(). - If Output is NULL, then ASSERT(). + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (16 bytes), then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] AesContext Pointer to the AES context. @param[in] Input Pointer to the buffer containing the data to be decrypted. @@ -872,6 +1278,7 @@ AesEcbEncrypt ( @retval TRUE AES decryption succeeded. @retval FALSE AES decryption failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -894,11 +1301,12 @@ AesEcbDecrypt ( AesContext should be already correctly initialized by AesInit(). Behavior with invalid AES context is undefined. - If AesContext is NULL, then ASSERT(). - If Input is NULL, then ASSERT(). - If InputSize is not multiple of block size (16 bytes), then ASSERT(). - If Ivec is NULL, then ASSERT(). - If Output is NULL, then ASSERT(). + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (16 bytes), then return FALSE. + If Ivec is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] AesContext Pointer to the AES context. @param[in] Input Pointer to the buffer containing the data to be encrypted. @@ -908,6 +1316,7 @@ AesEcbDecrypt ( @retval TRUE AES encryption succeeded. @retval FALSE AES encryption failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -931,11 +1340,12 @@ AesCbcEncrypt ( AesContext should be already correctly initialized by AesInit(). Behavior with invalid AES context is undefined. - If AesContext is NULL, then ASSERT(). - If Input is NULL, then ASSERT(). - If InputSize is not multiple of block size (16 bytes), then ASSERT(). - If Ivec is NULL, then ASSERT(). - If Output is NULL, then ASSERT(). + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (16 bytes), then return FALSE. + If Ivec is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] AesContext Pointer to the AES context. @param[in] Input Pointer to the buffer containing the data to be encrypted. @@ -945,6 +1355,7 @@ AesCbcEncrypt ( @retval TRUE AES decryption succeeded. @retval FALSE AES decryption failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -960,7 +1371,10 @@ AesCbcDecrypt ( /** Retrieves the size, in bytes, of the context buffer required for ARC4 operations. + If this interface is not supported, then return zero. + @return The size, in bytes, of the context buffer required for ARC4 operations. + @retval 0 This interface is not supported. **/ UINTN @@ -973,12 +1387,13 @@ Arc4GetContextSize ( Initializes user-supplied memory as ARC4 context for subsequent use. This function initializes user-supplied memory pointed by Arc4Context as ARC4 context. - In addtion, it sets up all ARC4 key materials for subsequent encryption and decryption + In addition, it sets up all ARC4 key materials for subsequent encryption and decryption operations. - If Arc4Context is NULL, then ASSERT(). - If Key is NULL, then ASSERT(). - If KeySize does not in the range of [5, 256] bytes, then ASSERT(). + If Arc4Context is NULL, then return FALSE. + If Key is NULL, then return FALSE. + If KeySize does not in the range of [5, 256] bytes, then return FALSE. + If this interface is not supported, then return FALSE. @param[out] Arc4Context Pointer to ARC4 context being initialized. @param[in] Key Pointer to the user-supplied ARC4 key. @@ -986,6 +1401,7 @@ Arc4GetContextSize ( @retval TRUE ARC4 context initialization succeeded. @retval FALSE ARC4 context initialization failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -1004,9 +1420,10 @@ Arc4Init ( Arc4Context should be already correctly initialized by Arc4Init(). Behavior with invalid ARC4 context is undefined. - If Arc4Context is NULL, then ASSERT(). - If Input is NULL, then ASSERT(). - If Output is NULL, then ASSERT(). + If Arc4Context is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] Arc4Context Pointer to the ARC4 context. @param[in] Input Pointer to the buffer containing the data to be encrypted. @@ -1015,6 +1432,7 @@ Arc4Init ( @retval TRUE ARC4 encryption succeeded. @retval FALSE ARC4 encryption failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -1034,9 +1452,10 @@ Arc4Encrypt ( Arc4Context should be already correctly initialized by Arc4Init(). Behavior with invalid ARC4 context is undefined. - If Arc4Context is NULL, then ASSERT(). - If Input is NULL, then ASSERT(). - If Output is NULL, then ASSERT(). + If Arc4Context is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] Arc4Context Pointer to the ARC4 context. @param[in] Input Pointer to the buffer containing the data to be decrypted. @@ -1045,6 +1464,7 @@ Arc4Encrypt ( @retval TRUE ARC4 decryption succeeded. @retval FALSE ARC4 decryption failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -1064,12 +1484,14 @@ Arc4Decrypt ( Contrary to ARC4Init(), Arc4Reset() requires no secret key as input, but ARC4 context should be already correctly initialized by ARC4Init(). - If Arc4Context is NULL, then ASSERT(). + If Arc4Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in, out] Arc4Context Pointer to the ARC4 context. @retval TRUE ARC4 reset succeeded. @retval FALSE ARC4 reset failed. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -1098,7 +1520,7 @@ RsaNew ( /** Release the specified RSA context. - If RsaContext is NULL, then ASSERT(). + If RsaContext is NULL, then return FALSE. @param[in] RsaContext Pointer to the RSA context to be released. @@ -1117,7 +1539,7 @@ RsaFree ( represented in RSA PKCS#1). If BigNumber is NULL, then the specified key componenet in RSA context is cleared. - If RsaContext is NULL, then ASSERT(). + If RsaContext is NULL, then return FALSE. @param[in, out] RsaContext Pointer to RSA context being set. @param[in] KeyTag Tag of RSA key component being set. @@ -1151,9 +1573,10 @@ RsaSetKey ( If the BigNumber buffer is too small to hold the contents of the key, FALSE is returned and BnSize is set to the required buffer size to obtain the key. - If RsaContext is NULL, then ASSERT(). - If BnSize is NULL, then ASSERT(). - If BnSize is large enough but BigNumber is NULL, then ASSERT(). + If RsaContext is NULL, then return FALSE. + If BnSize is NULL, then return FALSE. + If BnSize is large enough but BigNumber is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in, out] RsaContext Pointer to RSA context being set. @param[in] KeyTag Tag of RSA key component being set. @@ -1164,6 +1587,7 @@ RsaSetKey ( @retval TRUE RSA key component was retrieved successfully. @retval FALSE Invalid RSA key component tag. @retval FALSE BnSize is too small. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -1185,15 +1609,17 @@ RsaGetKey ( Before this function can be invoked, pseudorandom number generator must be correctly initialized by RandomSeed(). - If RsaContext is NULL, then ASSERT(). + If RsaContext is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in, out] RsaContext Pointer to RSA context being set. @param[in] ModulusLength Length of RSA modulus N in bits. @param[in] PublicExponent Pointer to RSA public exponent. - @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes. + @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes. @retval TRUE RSA key component was generated successfully. @retval FALSE Invalid RSA key component tag. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -1207,6 +1633,8 @@ RsaGenerateKey ( /** Validates key components of RSA context. + NOTE: This function performs integrity checks on all the RSA key material, so + the RSA key structure must contain all the private key data. This function validates key compoents of RSA context in following aspects: - Whether p is a prime @@ -1214,12 +1642,14 @@ RsaGenerateKey ( - Whether n = p * q - Whether d*e = 1 mod lcm(p-1,q-1) - If RsaContext is NULL, then ASSERT(). + If RsaContext is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] RsaContext Pointer to RSA context to check. @retval TRUE RSA key components are valid. @retval FALSE RSA key components are not valid. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -1236,21 +1666,23 @@ RsaCheckKey ( If the Signature buffer is too small to hold the contents of signature, FALSE is returned and SigSize is set to the required buffer size to obtain the signature. - If RsaContext is NULL, then ASSERT(). - If MessageHash is NULL, then ASSERT(). - If HashSize is not equal to the size of MD5, SHA-1, SHA-256, SHA-224, SHA-512 or SHA-384 digest, then ASSERT(). - If SigSize is large enough but Signature is NULL, then ASSERT(). + If RsaContext is NULL, then return FALSE. + If MessageHash is NULL, then return FALSE. + If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE. + If SigSize is large enough but Signature is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in] RsaContext Pointer to RSA context for signature generation. @param[in] MessageHash Pointer to octet message hash to be signed. @param[in] HashSize Size of the message hash in bytes. @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature. @param[in, out] SigSize On input, the size of Signature buffer in bytes. - On output, the size of data returned in Signature buffer in bytes. + On output, the size of data returned in Signature buffer in bytes. @retval TRUE Signature successfully generated in PKCS1-v1_5. @retval FALSE Signature generation failed. @retval FALSE SigSize is too small. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -1267,10 +1699,10 @@ RsaPkcs1Sign ( Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in RSA PKCS#1. - If RsaContext is NULL, then ASSERT(). - If MessageHash is NULL, then ASSERT(). - If Signature is NULL, then ASSERT(). - If HashSize is not equal to the size of MD5, SHA-1, SHA-256, SHA-224, SHA-512 or SHA-384 digest, then ASSERT(). + If RsaContext is NULL, then return FALSE. + If MessageHash is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE. @param[in] RsaContext Pointer to RSA context for signature verification. @param[in] MessageHash Pointer to octet message hash to be checked. @@ -1288,37 +1720,465 @@ RsaPkcs1Verify ( IN VOID *RsaContext, IN CONST UINT8 *MessageHash, IN UINTN HashSize, - IN UINT8 *Signature, + IN CONST UINT8 *Signature, IN UINTN SigSize ); /** - Verifies the validility of a PKCS#7 signed data as described in "PKCS #7: Cryptographic - Message Syntax Standard". + Retrieve the RSA Private Key from the password-protected PEM key data. + + If PemData is NULL, then return FALSE. + If RsaContext is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved + RSA private key component. Use RsaFree() function to free the + resource. + + @retval TRUE RSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +RsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **RsaContext + ); + +/** + Retrieve the RSA Public Key from one DER-encoded X509 certificate. + + If Cert is NULL, then return FALSE. + If RsaContext is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved + RSA public key component. Use RsaFree() function to free the + resource. + + @retval TRUE RSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve RSA public key from X509 certificate. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +RsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **RsaContext + ); + +/** + Retrieve the subject bytes from one X.509 certificate. + + If Cert is NULL, then return FALSE. + If SubjectSize is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] CertSubject Pointer to the retrieved certificate subject bytes. + @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input, + and the size of buffer returned CertSubject on output. + + @retval TRUE The certificate subject retrieved successfully. + @retval FALSE Invalid certificate, or the SubjectSize is too small for the result. + The SubjectSize will be updated with the required size. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +X509GetSubjectName ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT UINT8 *CertSubject, + IN OUT UINTN *SubjectSize + ); + +/** + Verify one X509 certificate was issued by the trusted CA. + + If Cert is NULL, then return FALSE. + If CACert is NULL, then return FALSE. + If this interface is not supported, then return FALSE. - If P7Data is NULL, then ASSERT(). + @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[in] CACert Pointer to the DER-encoded trusted CA certificate. + @param[in] CACertSize Size of the CA Certificate in bytes. + + @retval TRUE The certificate was issued by the trusted CA. + @retval FALSE Invalid certificate or the certificate was not issued by the given + trusted CA. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +X509VerifyCert ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + IN CONST UINT8 *CACert, + IN UINTN CACertSize + ); + +/** + Construct a X509 object from DER-encoded certificate data. + + If Cert is NULL, then return FALSE. + If SingleX509Cert is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Cert Pointer to the DER-encoded certificate data. + @param[in] CertSize The size of certificate data in bytes. + @param[out] SingleX509Cert The generated X509 object. + + @retval TRUE The X509 object generation succeeded. + @retval FALSE The operation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +X509ConstructCertificate ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT UINT8 **SingleX509Cert + ); + +/** + Construct a X509 stack object from a list of DER-encoded certificate data. + + If X509Stack is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object. + On output, pointer to the X509 stack object with new + inserted X509 certificate. + @param ... A list of DER-encoded single certificate data followed + by certificate size. A NULL terminates the list. The + pairs are the arguments to X509ConstructCertificate(). + + @retval TRUE The X509 stack construction succeeded. + @retval FALSE The construction operation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +X509ConstructCertificateStack ( + IN OUT UINT8 **X509Stack, + ... + ); + +/** + Release the specified X509 object. + + If the interface is not supported, then ASSERT(). + + @param[in] X509Cert Pointer to the X509 object to be released. + +**/ +VOID +EFIAPI +X509Free ( + IN VOID *X509Cert + ); + +/** + Release the specified X509 stack object. + + If the interface is not supported, then ASSERT(). + + @param[in] X509Stack Pointer to the X509 stack object to be released. + +**/ +VOID +EFIAPI +X509StackFree ( + IN VOID *X509Stack + ); + +/** + Retrieve the TBSCertificate from one given X.509 certificate. + + @param[in] Cert Pointer to the given DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] TBSCert DER-Encoded To-Be-Signed certificate. + @param[out] TBSCertSize Size of the TBS certificate in bytes. + + If Cert is NULL, then return FALSE. + If TBSCert is NULL, then return FALSE. + If TBSCertSize is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @retval TRUE The TBSCertificate was retrieved successfully. + @retval FALSE Invalid X.509 certificate. + +**/ +BOOLEAN +EFIAPI +X509GetTBSCert ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT UINT8 **TBSCert, + OUT UINTN *TBSCertSize + ); + +/** + Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7: + Cryptographic Message Syntax Standard". The input signed data could be wrapped + in a ContentInfo structure. + + If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then + return FALSE. If P7Length overflow, then return FAlSE. + If this interface is not supported, then return FALSE. + + @param[in] P7Data Pointer to the PKCS#7 message to verify. + @param[in] P7Length Length of the PKCS#7 message in bytes. + @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data. + It's caller's responsiblity to free the buffer. + @param[out] StackLength Length of signer's certificates in bytes. + @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates. + It's caller's responsiblity to free the buffer. + @param[out] CertLength Length of the trusted certificate in bytes. + + @retval TRUE The operation is finished successfully. + @retval FALSE Error occurs during the operation. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Pkcs7GetSigners ( + IN CONST UINT8 *P7Data, + IN UINTN P7Length, + OUT UINT8 **CertStack, + OUT UINTN *StackLength, + OUT UINT8 **TrustedCert, + OUT UINTN *CertLength + ); + +/** + Wrap function to use free() to free allocated memory for certificates. + + If this interface is not supported, then ASSERT(). + + @param[in] Certs Pointer to the certificates to be freed. + +**/ +VOID +EFIAPI +Pkcs7FreeSigners ( + IN UINT8 *Certs + ); + +/** + Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7: + Cryptographic Message Syntax Standard", and outputs two certificate lists chained and + unchained to the signer's certificates. + The input signed data could be wrapped in a ContentInfo structure. + + @param[in] P7Data Pointer to the PKCS#7 message. + @param[in] P7Length Length of the PKCS#7 message in bytes. + @param[out] SignerChainCerts Pointer to the certificates list chained to signer's + certificate. It's caller's responsiblity to free the buffer. + @param[out] ChainLength Length of the chained certificates list buffer in bytes. + @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's + responsiblity to free the buffer. + @param[out] UnchainLength Length of the unchained certificates list buffer in bytes. + + @retval TRUE The operation is finished successfully. + @retval FALSE Error occurs during the operation. + +**/ +BOOLEAN +EFIAPI +Pkcs7GetCertificatesList ( + IN CONST UINT8 *P7Data, + IN UINTN P7Length, + OUT UINT8 **SignerChainCerts, + OUT UINTN *ChainLength, + OUT UINT8 **UnchainCerts, + OUT UINTN *UnchainLength + ); + +/** + Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message + Syntax Standard, version 1.5". This interface is only intended to be used for + application to perform PKCS#7 functionality validation. + + If this interface is not supported, then return FALSE. + + @param[in] PrivateKey Pointer to the PEM-formatted private key data for + data signing. + @param[in] PrivateKeySize Size of the PEM private key data in bytes. + @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM + key data. + @param[in] InData Pointer to the content to be signed. + @param[in] InDataSize Size of InData in bytes. + @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with. + @param[in] OtherCerts Pointer to an optional additional set of certificates to + include in the PKCS#7 signedData (e.g. any intermediate + CAs in the chain). + @param[out] SignedData Pointer to output PKCS#7 signedData. + @param[out] SignedDataSize Size of SignedData in bytes. + + @retval TRUE PKCS#7 data signing succeeded. + @retval FALSE PKCS#7 data signing failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Pkcs7Sign ( + IN CONST UINT8 *PrivateKey, + IN UINTN PrivateKeySize, + IN CONST UINT8 *KeyPassword, + IN UINT8 *InData, + IN UINTN InDataSize, + IN UINT8 *SignCert, + IN UINT8 *OtherCerts OPTIONAL, + OUT UINT8 **SignedData, + OUT UINTN *SignedDataSize + ); + +/** + Verifies the validility of a PKCS#7 signed data as described in "PKCS #7: + Cryptographic Message Syntax Standard". The input signed data could be wrapped + in a ContentInfo structure. + + If P7Data, TrustedCert or InData is NULL, then return FALSE. + If P7Length, CertLength or DataLength overflow, then return FAlSE. + If this interface is not supported, then return FALSE. @param[in] P7Data Pointer to the PKCS#7 message to verify. - @param[in] P7Size Size of the PKCS#7 message in bytes. + @param[in] P7Length Length of the PKCS#7 message in bytes. @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which is used for certificate chain verification. - @param[in] CertSize Size of the trusted certificate in bytes. + @param[in] CertLength Length of the trusted certificate in bytes. @param[in] InData Pointer to the content to be verified. - @param[in] DataSize Size of InData in bytes. + @param[in] DataLength Length of InData in bytes. @retval TRUE The specified PKCS#7 signed data is valid. @retval FALSE Invalid PKCS#7 signed data. + @retval FALSE This interface is not supported. **/ BOOLEAN EFIAPI Pkcs7Verify ( IN CONST UINT8 *P7Data, - IN UINTN P7Size, + IN UINTN P7Length, IN CONST UINT8 *TrustedCert, - IN UINTN CertSize, + IN UINTN CertLength, IN CONST UINT8 *InData, - IN UINTN DataSize + IN UINTN DataLength + ); + +/** + Extracts the attached content from a PKCS#7 signed data if existed. The input signed + data could be wrapped in a ContentInfo structure. + + If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow, + then return FAlSE. If the P7Data is not correctly formatted, then return FALSE. + + Caution: This function may receive untrusted input. So this function will do + basic check for PKCS#7 data structure. + + @param[in] P7Data Pointer to the PKCS#7 signed data to process. + @param[in] P7Length Length of the PKCS#7 signed data in bytes. + @param[out] Content Pointer to the extracted content from the PKCS#7 signedData. + It's caller's responsiblity to free the buffer. + @param[out] ContentSize The size of the extracted content in bytes. + + @retval TRUE The P7Data was correctly formatted for processing. + @retval FALSE The P7Data was not correctly formatted for processing. + +*/ +BOOLEAN +EFIAPI +Pkcs7GetAttachedContent ( + IN CONST UINT8 *P7Data, + IN UINTN P7Length, + OUT VOID **Content, + OUT UINTN *ContentSize + ); + +/** + Verifies the validility of a PE/COFF Authenticode Signature as described in "Windows + Authenticode Portable Executable Signature Format". + + If AuthData is NULL, then return FALSE. + If ImageHash is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed + PE/COFF image to be verified. + @param[in] DataSize Size of the Authenticode Signature in bytes. + @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which + is used for certificate chain verification. + @param[in] CertSize Size of the trusted certificate in bytes. + @param[in] ImageHash Pointer to the original image file hash value. The procudure + for calculating the image hash value is described in Authenticode + specification. + @param[in] HashSize Size of Image hash value in bytes. + + @retval TRUE The specified Authenticode Signature is valid. + @retval FALSE Invalid Authenticode Signature. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +AuthenticodeVerify ( + IN CONST UINT8 *AuthData, + IN UINTN DataSize, + IN CONST UINT8 *TrustedCert, + IN UINTN CertSize, + IN CONST UINT8 *ImageHash, + IN UINTN HashSize + ); + +/** + Verifies the validility of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode + signature. + + If AuthData is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed + PE/COFF image to be verified. + @param[in] DataSize Size of the Authenticode Signature in bytes. + @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which + is used for TSA certificate chain verification. + @param[in] CertSize Size of the trusted certificate in bytes. + @param[out] SigningTime Return the time of timestamp generation time if the timestamp + signature is valid. + + @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature. + @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data. + +**/ +BOOLEAN +EFIAPI +ImageTimestampVerify ( + IN CONST UINT8 *AuthData, + IN UINTN DataSize, + IN CONST UINT8 *TsaCert, + IN UINTN CertSize, + OUT EFI_TIME *SigningTime ); //===================================================================================== @@ -1330,6 +2190,7 @@ Pkcs7Verify ( @return Pointer to the Diffie-Hellman Context that has been initialized. If the allocations fails, DhNew() returns NULL. + If the interface is not supported, DhNew() returns NULL. **/ VOID * @@ -1341,7 +2202,7 @@ DhNew ( /** Release the specified DH context. - If DhContext is NULL, then ASSERT(). + If the interface is not supported, then ASSERT(). @param[in] DhContext Pointer to the DH context to be released. @@ -1357,12 +2218,13 @@ DhFree ( Given generator g, and length of prime number p in bits, this function generates p, and sets DH context according to value of g and p. - + Before this function can be invoked, pseudorandom number generator must be correctly initialized by RandomSeed(). - If DhContext is NULL, then ASSERT(). - If Prime is NULL, then ASSERT(). + If DhContext is NULL, then return FALSE. + If Prime is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in, out] DhContext Pointer to the DH context. @param[in] Generator Value of generator. @@ -1372,6 +2234,7 @@ DhFree ( @retval TRUE DH pamameter generation succeeded. @retval FALSE Value of Generator is not supported. @retval FALSE PRNG fails to generate random prime number with PrimeLength. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -1389,8 +2252,9 @@ DhGenerateParameter ( Given generator g, and prime number p, this function and sets DH context accordingly. - If DhContext is NULL, then ASSERT(). - If Prime is NULL, then ASSERT(). + If DhContext is NULL, then return FALSE. + If Prime is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in, out] DhContext Pointer to the DH context. @param[in] Generator Value of generator. @@ -1402,6 +2266,7 @@ DhGenerateParameter ( @retval FALSE Value of Generator is not suitable for the Prime. @retval FALSE Value of Prime is not a prime number. @retval FALSE Value of Prime is not a safe prime number. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -1416,14 +2281,15 @@ DhSetParameter ( /** Generates DH public key. - This function generates random secret exponent, and computes the public key, which is + This function generates random secret exponent, and computes the public key, which is returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly. If the PublicKey buffer is too small to hold the public key, FALSE is returned and PublicKeySize is set to the required buffer size to obtain the public key. - If DhContext is NULL, then ASSERT(). - If PublicKeySize is NULL, then ASSERT(). - If PublicKeySize is large enough but PublicKey is NULL, then ASSERT(). + If DhContext is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If PublicKeySize is large enough but PublicKey is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[in, out] DhContext Pointer to the DH context. @param[out] PublicKey Pointer to the buffer to receive generated public key. @@ -1433,6 +2299,7 @@ DhSetParameter ( @retval TRUE DH public key generation succeeded. @retval FALSE DH public key generation failed. @retval FALSE PublicKeySize is not large enough. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -1447,12 +2314,14 @@ DhGenerateKey ( Computes exchanged common key. Given peer's public key, this function computes the exchanged common key, based on its own - context including value of prime modulus and random secret exponent. + context including value of prime modulus and random secret exponent. - If DhContext is NULL, then ASSERT(). - If PeerPublicKey is NULL, then ASSERT(). - If KeySize is NULL, then ASSERT(). - If KeySize is large enough but Key is NULL, then ASSERT(). + If DhContext is NULL, then return FALSE. + If PeerPublicKey is NULL, then return FALSE. + If KeySize is NULL, then return FALSE. + If Key is NULL, then return FALSE. + If KeySize is not large enough, then return FALSE. + If this interface is not supported, then return FALSE. @param[in, out] DhContext Pointer to the DH context. @param[in] PeerPublicKey Pointer to the peer's public key. @@ -1464,6 +2333,7 @@ DhGenerateKey ( @retval TRUE DH exchanged key generation succeeded. @retval FALSE DH exchanged key generation failed. @retval FALSE KeySize is not large enough. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -1486,6 +2356,7 @@ DhComputeKey ( This function sets up the seed value for the pseudorandom number generator. If Seed is not NULL, then the seed passed in is used. If Seed is NULL, then default seed is used. + If this interface is not supported, then return FALSE. @param[in] Seed Pointer to seed value. If NULL, default seed is used. @@ -1494,6 +2365,7 @@ DhComputeKey ( @retval TRUE Pseudorandom number generator has enough entropy for random generation. @retval FALSE Pseudorandom number generator does not have enough entropy for random generation. + @retval FALSE This interface is not supported. **/ BOOLEAN @@ -1506,13 +2378,15 @@ RandomSeed ( /** Generates a pseudorandom byte stream of the specified size. - If Output is NULL, then ASSERT(). + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. @param[out] Output Pointer to buffer to receive random value. @param[in] Size Size of randome bytes to generate. @retval TRUE Pseudorandom byte stream generated successfully. @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy. + @retval FALSE This interface is not supported. **/ BOOLEAN