VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Crypto.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/Crypto.c')
-rw-r--r--src/Common/Crypto.c64
1 files changed, 9 insertions, 55 deletions
diff --git a/src/Common/Crypto.c b/src/Common/Crypto.c
index 9c4ee5a3..9ae841eb 100644
--- a/src/Common/Crypto.c
+++ b/src/Common/Crypto.c
@@ -26,6 +26,7 @@
#else
#include <strsafe.h>
#endif
+#include "Crypto/t1ha.h"
#include "EncryptionThreadPool.h"
#endif
#endif
@@ -192,8 +193,7 @@ void EncipherBlock(int cipher, void *data, void *ks)
switch (cipher)
{
case AES:
- // In 32-bit kernel mode, due to KeSaveFloatingPointState() overhead, AES instructions can be used only when processing the whole data unit.
-#if (defined (_WIN64) || !defined (TC_WINDOWS_DRIVER)) && !defined (TC_WINDOWS_BOOT)
+#if !defined (TC_WINDOWS_BOOT)
if (IsAesHwCpuSupported())
aes_hw_cpu_encrypt (ks, data);
else
@@ -220,16 +220,10 @@ void EncipherBlock(int cipher, void *data, void *ks)
void EncipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount)
{
uint8 *data = dataPtr;
-#if defined (TC_WINDOWS_DRIVER) && !defined (_WIN64)
- KFLOATING_SAVE floatingPointState;
-#endif
if (cipher == AES
&& (blockCount & (32 - 1)) == 0
&& IsAesHwCpuSupported()
-#if defined (TC_WINDOWS_DRIVER) && !defined (_WIN64)
- && NT_SUCCESS (KeSaveFloatingPointState (&floatingPointState))
-#endif
)
{
while (blockCount > 0)
@@ -240,24 +234,15 @@ void EncipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount)
blockCount -= 32;
}
-#if defined (TC_WINDOWS_DRIVER) && !defined (_WIN64)
- KeRestoreFloatingPointState (&floatingPointState);
-#endif
}
#ifndef WOLFCRYPT_BACKEND
#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE && !defined (_UEFI)
else if (cipher == SERPENT
&& (blockCount >= 4)
&& HasSSE2()
-#if defined (TC_WINDOWS_DRIVER) && !defined (_WIN64)
- && NT_SUCCESS (KeSaveFloatingPointState (&floatingPointState))
-#endif
)
{
serpent_encrypt_blocks (data, data, blockCount, ks);
-#if defined (TC_WINDOWS_DRIVER) && !defined (_WIN64)
- KeRestoreFloatingPointState (&floatingPointState);
-#endif
}
#endif
#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM)
@@ -271,15 +256,9 @@ void EncipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount)
#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE && !defined (_UEFI)
else if (cipher == KUZNYECHIK
&& HasSSE2()
-#if defined (TC_WINDOWS_DRIVER) && !defined (_WIN64)
- && (blockCount >= 4) && NT_SUCCESS (KeSaveFloatingPointState (&floatingPointState))
-#endif
)
{
kuznyechik_encrypt_blocks (data, data, blockCount, ks);
-#if defined (TC_WINDOWS_DRIVER) && !defined (_WIN64)
- KeRestoreFloatingPointState (&floatingPointState);
-#endif
}
#endif
#endif
@@ -315,11 +294,9 @@ void DecipherBlock(int cipher, void *data, void *ks)
#ifndef TC_WINDOWS_BOOT
case AES:
-#if defined (_WIN64) || !defined (TC_WINDOWS_DRIVER)
if (IsAesHwCpuSupported())
aes_hw_cpu_decrypt ((uint8 *) ks + sizeof (aes_encrypt_ctx), data);
else
-#endif
aes_decrypt (data, data, (void *) ((char *) ks + sizeof(aes_encrypt_ctx)));
break;
@@ -335,16 +312,10 @@ void DecipherBlock(int cipher, void *data, void *ks)
void DecipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount)
{
uint8 *data = dataPtr;
-#if defined (TC_WINDOWS_DRIVER) && !defined (_WIN64)
- KFLOATING_SAVE floatingPointState;
-#endif
if (cipher == AES
&& (blockCount & (32 - 1)) == 0
&& IsAesHwCpuSupported()
-#if defined (TC_WINDOWS_DRIVER) && !defined (_WIN64)
- && NT_SUCCESS (KeSaveFloatingPointState (&floatingPointState))
-#endif
)
{
while (blockCount > 0)
@@ -355,24 +326,15 @@ void DecipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount)
blockCount -= 32;
}
-#if defined (TC_WINDOWS_DRIVER) && !defined (_WIN64)
- KeRestoreFloatingPointState (&floatingPointState);
-#endif
}
#ifndef WOLFCRYPT_BACKEND
#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE && !defined (_UEFI)
else if (cipher == SERPENT
&& (blockCount >= 4)
&& HasSSE2()
-#if defined (TC_WINDOWS_DRIVER) && !defined (_WIN64)
- && NT_SUCCESS (KeSaveFloatingPointState (&floatingPointState))
-#endif
)
{
serpent_decrypt_blocks (data, data, blockCount, ks);
-#if defined (TC_WINDOWS_DRIVER) && !defined (_WIN64)
- KeRestoreFloatingPointState (&floatingPointState);
-#endif
}
#endif
#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM)
@@ -386,15 +348,9 @@ void DecipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount)
#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE && !defined (_UEFI)
else if (cipher == KUZNYECHIK
&& HasSSE2()
-#if defined (TC_WINDOWS_DRIVER) && !defined (_WIN64)
- && (blockCount >= 4) && NT_SUCCESS (KeSaveFloatingPointState (&floatingPointState))
-#endif
)
{
kuznyechik_decrypt_blocks (data, data, blockCount, ks);
-#if defined (TC_WINDOWS_DRIVER) && !defined (_WIN64)
- KeRestoreFloatingPointState (&floatingPointState);
-#endif
}
#endif
#endif
@@ -659,8 +615,8 @@ int EAGetNextMode (int ea, int previousModeId)
return 0;
}
-// Returns the name of the mode of operation of the whole EA
-wchar_t *EAGetModeName (int ea, int mode, BOOL capitalLetters)
+// Returns the name of the mode of operation
+const wchar_t *EAGetModeName (int mode)
{
switch (mode)
{
@@ -669,7 +625,7 @@ wchar_t *EAGetModeName (int ea, int mode, BOOL capitalLetters)
return L"XTS";
}
- return L"[unknown]";
+ return L"[UNKNOWN]";
}
#endif // TC_WINDOWS_BOOT
@@ -891,7 +847,7 @@ PCRYPTO_INFO crypto_open ()
}
#ifndef TC_WINDOWS_BOOT
-void crypto_loadkey (PKEY_INFO keyInfo, char *lpszUserKey, int nUserKeyLen)
+void crypto_loadkey (PKEY_INFO keyInfo, unsigned char *lpszUserKey, int nUserKeyLen)
{
keyInfo->keyLength = nUserKeyLen;
burn (keyInfo->userKey, sizeof (keyInfo->userKey));
@@ -1239,9 +1195,11 @@ static BOOL RamEncryptionEnabled = FALSE;
BOOL IsCpuRngSupported ()
{
+#ifndef _M_ARM64
if (HasRDSEED() || HasRDRAND())
return TRUE;
else
+#endif
return FALSE;
}
@@ -1257,14 +1215,10 @@ BOOL IsCpuRngEnabled ()
BOOL IsRamEncryptionSupported ()
{
-#ifdef _WIN64
if (t1ha_selfcheck__t1ha2() == 0)
return TRUE;
else
return FALSE;
-#else
- return FALSE;
-#endif
}
void EnableRamEncryption (BOOL enable)
@@ -1313,7 +1267,7 @@ uint8 GetRandomIndex (ChaCha20RngCtx* pCtx, uint8 elementsCount)
return index;
}
-#if defined(_WIN64) && !defined (_UEFI)
+#if !defined (_UEFI)
/* declaration of variables and functions used for RAM encryption on 64-bit build */
static uint8* pbKeyDerivationArea = NULL;
static ULONG cbKeyDerivationArea = 0;