VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Crypto/Camellia.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2017-07-04 02:05:11 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2017-07-04 02:26:24 +0200
commit89efcdb8cd95ea798187fe4062a73fa5d2fca456 (patch)
tree5b87e340ffc7fb6ad8a8859750aa388487188f8f /src/Crypto/Camellia.c
parentc2f6190627de27903264258c6ea8ee72199c0c81 (diff)
downloadVeraCrypt-89efcdb8cd95ea798187fe4062a73fa5d2fca456.tar.gz
VeraCrypt-89efcdb8cd95ea798187fe4062a73fa5d2fca456.zip
Windows Driver: correctly save and restore extended processor state when performing AVX operations on Windows 7 and later. Enhance readability of code handling save/restore of floating point state.
Diffstat (limited to 'src/Crypto/Camellia.c')
-rw-r--r--src/Crypto/Camellia.c32
1 files changed, 25 insertions, 7 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