VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Crypto
diff options
context:
space:
mode:
Diffstat (limited to 'src/Crypto')
-rw-r--r--src/Crypto/Camellia.c32
-rw-r--r--src/Crypto/GostCipher.c4
2 files changed, 27 insertions, 9 deletions
diff --git a/src/Crypto/Camellia.c b/src/Crypto/Camellia.c
index f74130cd..49bc7670 100644
--- a/src/Crypto/Camellia.c
+++ b/src/Crypto/Camellia.c
@@ -1096,15 +1096,24 @@ void camellia_decrypt(const unsigned __int8 *inBlock, unsigned __int8 *outBlock
void camellia_encrypt_blocks(unsigned __int8 *instance, const byte* in_blk, byte* out_blk, uint32 blockCount)
{
#if !defined (_UEFI)
- if (IsCpuIntel() && IsAesHwCpuSupported () && HasSAVX()) /* on AMD cpu, AVX is too slow */
+ if ((blockCount >= 16) && IsCpuIntel() && IsAesHwCpuSupported () && HasSAVX()) /* on AMD cpu, AVX is too slow */
{
- while (blockCount >= 16)
+#if defined (TC_WINDOWS_DRIVER)
+ XSTATE_SAVE SaveState;
+ if (NT_SUCCESS (KeSaveExtendedProcessorState(XSTATE_MASK_GSSE, &SaveState)))
{
- camellia_ecb_enc_16way (instance, out_blk, in_blk);
- out_blk += 16 * 16;
- in_blk += 16 * 16;
- blockCount -= 16;
+#endif
+ while (blockCount >= 16)
+ {
+ camellia_ecb_enc_16way (instance, out_blk, in_blk);
+ out_blk += 16 * 16;
+ in_blk += 16 * 16;
+ blockCount -= 16;
+ }
+#if defined (TC_WINDOWS_DRIVER)
+ KeRestoreExtendedProcessorState(&SaveState);
}
+#endif
}
#endif
@@ -1123,8 +1132,13 @@ void camellia_encrypt_blocks(unsigned __int8 *instance, const byte* in_blk, byte
void camellia_decrypt_blocks(unsigned __int8 *instance, const byte* in_blk, byte* out_blk, uint32 blockCount)
{
#if !defined (_UEFI)
- if (IsCpuIntel() && IsAesHwCpuSupported () && HasSAVX()) /* on AMD cpu, AVX is too slow */
+ if ((blockCount >= 16) && IsCpuIntel() && IsAesHwCpuSupported () && HasSAVX()) /* on AMD cpu, AVX is too slow */
{
+#if defined (TC_WINDOWS_DRIVER)
+ XSTATE_SAVE SaveState;
+ if (NT_SUCCESS (KeSaveExtendedProcessorState(XSTATE_MASK_GSSE, &SaveState)))
+ {
+#endif
while (blockCount >= 16)
{
camellia_ecb_dec_16way (instance, out_blk, in_blk);
@@ -1132,6 +1146,10 @@ void camellia_decrypt_blocks(unsigned __int8 *instance, const byte* in_blk, byte
in_blk += 16 * 16;
blockCount -= 16;
}
+#if defined (TC_WINDOWS_DRIVER)
+ KeRestoreExtendedProcessorState(&SaveState);
+ }
+#endif
}
#endif
diff --git a/src/Crypto/GostCipher.c b/src/Crypto/GostCipher.c
index 0fd3941a..ddd649cd 100644
--- a/src/Crypto/GostCipher.c
+++ b/src/Crypto/GostCipher.c
@@ -96,7 +96,7 @@ void gost_set_key(const byte *key, gost_kds *ks, int useDynamicSbox)
byte sbox_seed[64];
#if defined (DEVICE_DRIVER) && !defined (_WIN64)
KFLOATING_SAVE floatingPointState;
- NTSTATUS saveStatus = STATUS_SUCCESS;
+ NTSTATUS saveStatus = STATUS_INVALID_PARAMETER;
if (HasSSE2() || HasSSE41())
saveStatus = KeSaveFloatingPointState (&floatingPointState);
#endif
@@ -106,7 +106,7 @@ void gost_set_key(const byte *key, gost_kds *ks, int useDynamicSbox)
STREEBOG_finalize(&sctx, sbox_seed);
#if defined (DEVICE_DRIVER) && !defined (_WIN64)
- if (NT_SUCCESS (saveStatus) && (HasSSE2() || HasSSE41()))
+ if (NT_SUCCESS (saveStatus))
KeRestoreFloatingPointState (&floatingPointState);
#endif