diff --git a/CryptoPkg/Driver/Crypto.c b/CryptoPkg/Driver/Crypto.c index f1cdb72cca..94c0c25da9 100644 --- a/CryptoPkg/Driver/Crypto.c +++ b/CryptoPkg/Driver/Crypto.c @@ -2384,6 +2384,70 @@ CryptoServiceAesCbcDecrypt ( return CALL_BASECRYPTLIB (Aes.Services.CbcDecrypt, AesCbcDecrypt, (AesContext, Input, InputSize, Ivec, Output), FALSE); } +/** + Performs AES encryption on single block (AES_BLOCK_SIZE) + + This function performs AES encryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block data + @param[out] Output Pointer to a buffer that receives the AES encryption output. + + @retval TRUE AES encryption succeeded. + @retval FALSE AES encryption failed. + +**/ +BOOLEAN +EFIAPI +CryptoServiceAesEncrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ) +{ + return CALL_BASECRYPTLIB (Aes.Services.Encrypt, AesEncrypt, (AesContext, Input, Output), FALSE); +} + +/** + Performs AES decryption on single block (AES_BLOCK_SIZE) + + This function performs AES decryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block encrpyted data. + @param[out] Output Pointer to a buffer that receives the AES decryption output. + + @retval TRUE AES decryption succeeded. + @retval FALSE AES decryption failed. + +**/ +BOOLEAN +EFIAPI +CryptoServiceAesDecrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ) +{ + return CALL_BASECRYPTLIB (Aes.Services.Decrypt, AesDecrypt, (AesContext, Input, Output), FALSE); +} + /** ARC4 is deprecated and unsupported any longer. Keep the function field for binary compability. @@ -7164,4 +7228,7 @@ const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto = { /// TLS Set (Continued) CryptoServiceTlsSetServerName, CryptoServiceTlsSetSecurityLevel, + /// AES (Continued) + CryptoServiceAesEncrypt, + CryptoServiceAesDecrypt, }; diff --git a/CryptoPkg/Include/Library/BaseCryptLib.h b/CryptoPkg/Include/Library/BaseCryptLib.h index a3759ecb0c..2e7ce26ab5 100644 --- a/CryptoPkg/Include/Library/BaseCryptLib.h +++ b/CryptoPkg/Include/Library/BaseCryptLib.h @@ -1373,6 +1373,64 @@ AesCbcDecrypt ( OUT UINT8 *Output ); +/** + Performs AES encryption on single block (AES_BLOCK_SIZE) + + This function performs AES encryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block data + @param[out] Output Pointer to a buffer that receives the AES encryption output. + + @retval TRUE AES encryption succeeded. + @retval FALSE AES encryption failed. + +**/ +BOOLEAN +EFIAPI +AesEncrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ); + +/** + Performs AES decryption on single block (AES_BLOCK_SIZE) + + This function performs AES decryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block encrpyted data. + @param[out] Output Pointer to a buffer that receives the AES decryption output. + + @retval TRUE AES decryption succeeded. + @retval FALSE AES decryption failed. + +**/ +BOOLEAN +EFIAPI +AesDecrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ); + // ===================================================================================== // Authenticated Encryption with Associated Data (AEAD) Cryptography Primitive // ===================================================================================== diff --git a/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h b/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h index b5b52b408c..6fdea884a0 100644 --- a/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h +++ b/CryptoPkg/Include/Pcd/PcdCryptoServiceFamilyEnable.h @@ -256,6 +256,8 @@ typedef struct { UINT8 EcbDecrypt : 1; // Deprecated UINT8 CbcEncrypt : 1; UINT8 CbcDecrypt : 1; + UINT8 Encrypt : 1; + UINT8 Decrypt : 1; } Services; UINT32 Family; } Aes; diff --git a/CryptoPkg/Library/BaseCryptLib/Cipher/CryptAes.c b/CryptoPkg/Library/BaseCryptLib/Cipher/CryptAes.c index 587885e33d..a290eec7bc 100644 --- a/CryptoPkg/Library/BaseCryptLib/Cipher/CryptAes.c +++ b/CryptoPkg/Library/BaseCryptLib/Cipher/CryptAes.c @@ -203,3 +203,93 @@ AesCbcDecrypt ( return TRUE; } + +/** + Performs AES encryption on single block (AES_BLOCK_SIZE) + + This function performs AES encryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block data + @param[out] Output Pointer to a buffer that receives the AES encryption output. + + @retval TRUE AES encryption succeeded. + @retval FALSE AES encryption failed. + +**/ +BOOLEAN +EFIAPI +AesEncrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ) +{ + AES_KEY *AesKey; + + // + // Check parameters. + // + if ((AesContext == NULL) || (Input == NULL) || (Output == NULL)) { + return FALSE; + } + + AesKey = (AES_KEY *)AesContext; + + AES_encrypt (Input, Output, AesKey); + + return TRUE; +} + +/** + Performs AES decryption on single block (AES_BLOCK_SIZE) + + This function performs AES decryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block encrpyted data. + @param[out] Output Pointer to a buffer that receives the AES decryption output. + + @retval TRUE AES decryption succeeded. + @retval FALSE AES decryption failed. + +**/ +BOOLEAN +EFIAPI +AesDecrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ) +{ + AES_KEY *AesKey; + + // + // Check parameters. + // + if ((AesContext == NULL) || (Input == NULL) || (Output == NULL)) { + return FALSE; + } + + AesKey = (AES_KEY *)AesContext; + + AES_decrypt (Input, Output, AesKey + 1); + + return TRUE; +} diff --git a/CryptoPkg/Library/BaseCryptLib/Cipher/CryptAesNull.c b/CryptoPkg/Library/BaseCryptLib/Cipher/CryptAesNull.c index d235422e7a..8610e5fa13 100644 --- a/CryptoPkg/Library/BaseCryptLib/Cipher/CryptAesNull.c +++ b/CryptoPkg/Library/BaseCryptLib/Cipher/CryptAesNull.c @@ -105,3 +105,69 @@ AesCbcDecrypt ( ASSERT (FALSE); return FALSE; } + +/** + Performs AES encryption on single block (AES_BLOCK_SIZE) + + This function performs AES encryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block data + @param[out] Output Pointer to a buffer that receives the AES encryption output. + + @retval TRUE AES encryption succeeded. + @retval FALSE AES encryption failed. + +**/ +BOOLEAN +EFIAPI +AesEncrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Performs AES decryption on single block (AES_BLOCK_SIZE) + + This function performs AES decryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block encrpyted data. + @param[out] Output Pointer to a buffer that receives the AES decryption output. + + @retval TRUE AES decryption succeeded. + @retval FALSE AES decryption failed. + +**/ +BOOLEAN +EFIAPI +AesDecrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/Cipher/CryptAes.c b/CryptoPkg/Library/BaseCryptLibMbedTls/Cipher/CryptAes.c index 274d2fa471..dc13bd029c 100644 --- a/CryptoPkg/Library/BaseCryptLibMbedTls/Cipher/CryptAes.c +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/Cipher/CryptAes.c @@ -223,3 +223,69 @@ AesCbcDecrypt ( return TRUE; } } + +/** + Performs AES encryption on single block (AES_BLOCK_SIZE) + + This function performs AES encryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block data + @param[out] Output Pointer to a buffer that receives the AES encryption output. + + @retval TRUE AES encryption succeeded. + @retval FALSE AES encryption failed. + +**/ +BOOLEAN +EFIAPI +AesEncrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Performs AES decryption on single block (AES_BLOCK_SIZE) + + This function performs AES decryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block encrpyted data. + @param[out] Output Pointer to a buffer that receives the AES decryption output. + + @retval TRUE AES decryption succeeded. + @retval FALSE AES decryption failed. + +**/ +BOOLEAN +EFIAPI +AesDecrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/Cipher/CryptAesNull.c b/CryptoPkg/Library/BaseCryptLibMbedTls/Cipher/CryptAesNull.c index ad93d56492..867c814068 100644 --- a/CryptoPkg/Library/BaseCryptLibMbedTls/Cipher/CryptAesNull.c +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/Cipher/CryptAesNull.c @@ -157,3 +157,69 @@ AesCbcDecrypt ( ASSERT (FALSE); return FALSE; } + +/** + Performs AES encryption on single block (AES_BLOCK_SIZE) + + This function performs AES encryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block data + @param[out] Output Pointer to a buffer that receives the AES encryption output. + + @retval TRUE AES encryption succeeded. + @retval FALSE AES encryption failed. + +**/ +BOOLEAN +EFIAPI +AesEncrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Performs AES decryption on single block (AES_BLOCK_SIZE) + + This function performs AES decryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block encrpyted data. + @param[out] Output Pointer to a buffer that receives the AES decryption output. + + @retval TRUE AES decryption succeeded. + @retval FALSE AES decryption failed. + +**/ +BOOLEAN +EFIAPI +AesDecrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLibNull/Cipher/CryptAesNull.c b/CryptoPkg/Library/BaseCryptLibNull/Cipher/CryptAesNull.c index d235422e7a..8610e5fa13 100644 --- a/CryptoPkg/Library/BaseCryptLibNull/Cipher/CryptAesNull.c +++ b/CryptoPkg/Library/BaseCryptLibNull/Cipher/CryptAesNull.c @@ -105,3 +105,69 @@ AesCbcDecrypt ( ASSERT (FALSE); return FALSE; } + +/** + Performs AES encryption on single block (AES_BLOCK_SIZE) + + This function performs AES encryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block data + @param[out] Output Pointer to a buffer that receives the AES encryption output. + + @retval TRUE AES encryption succeeded. + @retval FALSE AES encryption failed. + +**/ +BOOLEAN +EFIAPI +AesEncrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ) +{ + ASSERT (FALSE); + return FALSE; +} + +/** + Performs AES decryption on single block (AES_BLOCK_SIZE) + + This function performs AES decryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block encrpyted data. + @param[out] Output Pointer to a buffer that receives the AES decryption output. + + @retval TRUE AES decryption succeeded. + @retval FALSE AES decryption failed. + +**/ +BOOLEAN +EFIAPI +AesDecrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ) +{ + ASSERT (FALSE); + return FALSE; +} diff --git a/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c b/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c index 5162cfd932..c7811c44b4 100644 --- a/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c +++ b/CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c @@ -1552,6 +1552,70 @@ AesCbcDecrypt ( CALL_CRYPTO_SERVICE (AesCbcDecrypt, (AesContext, Input, InputSize, Ivec, Output), FALSE); } +/** + Performs AES encryption on single block (AES_BLOCK_SIZE) + + This function performs AES encryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block data + @param[out] Output Pointer to a buffer that receives the AES encryption output. + + @retval TRUE AES encryption succeeded. + @retval FALSE AES encryption failed. + +**/ +BOOLEAN +EFIAPI +AesEncrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ) +{ + CALL_CRYPTO_SERVICE (AesEncrypt, (AesContext, Input, Output), FALSE); +} + +/** + Performs AES decryption on single block (AES_BLOCK_SIZE) + + This function performs AES decryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block encrpyted data. + @param[out] Output Pointer to a buffer that receives the AES decryption output. + + @retval TRUE AES decryption succeeded. + @retval FALSE AES decryption failed. + +**/ +BOOLEAN +EFIAPI +AesDecrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ) +{ + CALL_CRYPTO_SERVICE (AesDecrypt, (AesContext, Input, Output), FALSE); +} + // ===================================================================================== // Authenticated Encryption with Associated Data (AEAD) Cryptography Primitive // ===================================================================================== diff --git a/CryptoPkg/Private/Protocol/Crypto.h b/CryptoPkg/Private/Protocol/Crypto.h index b9f603bbe7..7beded14d2 100644 --- a/CryptoPkg/Private/Protocol/Crypto.h +++ b/CryptoPkg/Private/Protocol/Crypto.h @@ -20,7 +20,7 @@ /// the EDK II Crypto Protocol is extended, this version define must be /// increased. /// -#define EDKII_CRYPTO_VERSION 19 +#define EDKII_CRYPTO_VERSION 20 /// /// EDK II Crypto Protocol forward declaration @@ -3036,6 +3036,64 @@ BOOLEAN OUT UINT8 *Output ); +/** + Performs AES encryption on single block (AES_BLOCK_SIZE) + + This function performs AES encryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block data + @param[out] Output Pointer to a buffer that receives the AES encryption output. + + @retval TRUE AES encryption succeeded. + @retval FALSE AES encryption failed. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_AES_ENCRYPT)( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ); + +/** + Performs AES decryption on single block (AES_BLOCK_SIZE) + + This function performs AES decryption on single block pointed by Input. + + Caller must perform padding, if necessary, to ensure single block size. + AesContext should be already correctly initialized by AesInit(). + Behavior with invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing single block encrpyted data. + @param[out] Output Pointer to a buffer that receives the AES decryption output. + + @retval TRUE AES decryption succeeded. + @retval FALSE AES decryption failed. + +**/ +typedef +BOOLEAN +(EFIAPI *EDKII_CRYPTO_AES_DECRYPT)( + IN VOID *AesContext, + IN CONST UINT8 *Input, + OUT UINT8 *Output + ); + /** ARC4 is deprecated and unsupported any longer. Keep the function field for binary compability. @@ -5750,6 +5808,9 @@ struct _EDKII_CRYPTO_PROTOCOL { /// TLS Set (Continued) EDKII_CRYPTO_TLS_SET_SERVER_NAME TlsSetServerName; EDKII_CRYPTO_TLS_SET_SECURITY_LEVEL TlsSetSecurityLevel; + /// AES (Continued) + EDKII_CRYPTO_AES_ENCRYPT AesEncrypt; + EDKII_CRYPTO_AES_DECRYPT AesDecrypt; }; extern GUID gEdkiiCryptoProtocolGuid;