mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-12 11:28:26 -06:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user