From f53eb8e260d174153bb3fc24ff1fff7966dcfbee Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Mon, 27 Nov 2017 09:10:17 +0200 Subject: SIMD speed optimization for Kuznyechik cipher implementation (up to 2x speedup). Based on https://github.com/aprelev/libgost15. --- src/Common/Crypto.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/Common') diff --git a/src/Common/Crypto.c b/src/Common/Crypto.c index c7b0c73d..3f7e9871 100644 --- a/src/Common/Crypto.c +++ b/src/Common/Crypto.c @@ -254,6 +254,20 @@ void EncipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount) else if (cipher == CAMELLIA) { camellia_encrypt_blocks(ks, data, data, (uint32) blockCount); } +#endif +#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 else if (cipher == GOST89) { gost_encrypt(data, data, ks, (int)blockCount); @@ -357,6 +371,20 @@ void DecipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount) else if (cipher == CAMELLIA) { camellia_decrypt_blocks(ks, data, data, (uint32) blockCount); } +#endif +#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 else if (cipher == GOST89) { gost_decrypt(data, data, ks, (int)blockCount); @@ -429,6 +457,7 @@ BOOL CipherSupportsIntraDataUnitParallelization (int cipher) || (cipher == GOST89) #if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE && !defined (_UEFI) || (cipher == SERPENT && HasSSE2()) + || (cipher == KUZNYECHIK && HasSSE2()) #endif #if CRYPTOPP_BOOL_X64 || (cipher == TWOFISH) -- cgit v1.2.3