From e5a9e9239b0cf1001d9b91497b4ff3ab4a190b1f Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Tue, 4 Oct 2016 13:21:48 +0200 Subject: Crypto: Use SIMD optimized Serpent implementation from Botan. 2.5x speed gain factor. Update credits and copyrights notice. --- src/Common/Crypto.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src/Common/Crypto.c') diff --git a/src/Common/Crypto.c b/src/Common/Crypto.c index cae705b6..49ccbde5 100644 --- a/src/Common/Crypto.c +++ b/src/Common/Crypto.c @@ -232,6 +232,21 @@ void EncipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount) KeRestoreFloatingPointState (&floatingPointState); #endif } +#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE + 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 else if (cipher == GOST89) { gost_encrypt(data, data, ks, (int)blockCount); } @@ -312,6 +327,21 @@ void DecipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount) KeRestoreFloatingPointState (&floatingPointState); #endif } +#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE + 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 else if (cipher == GOST89) { gost_decrypt(data, data, ks, (int)blockCount); } @@ -383,8 +413,12 @@ int CipherGetKeyScheduleSize (int cipherId) BOOL CipherSupportsIntraDataUnitParallelization (int cipher) { - return cipher == AES && IsAesHwCpuSupported() || - cipher == GOST89; + return (cipher == AES && IsAesHwCpuSupported()) + || (cipher == GOST89) +#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE + || (cipher == SERPENT && HasSSE2()) +#endif + ; } #endif -- cgit v1.2.3