VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Volume
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2017-11-27 07:10:17 (GMT)
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2017-11-27 15:16:35 (GMT)
commitf53eb8e260d174153bb3fc24ff1fff7966dcfbee (patch)
treeb8e5263c7fc7e90177ca7c296f6bc493fc735877 /src/Volume
parent685fad2d5d56ff1049ba2f5c8b901bca5a4a07bd (diff)
downloadVeraCrypt-f53eb8e260d174153bb3fc24ff1fff7966dcfbee.zip
VeraCrypt-f53eb8e260d174153bb3fc24ff1fff7966dcfbee.tar.gz
SIMD speed optimization for Kuznyechik cipher implementation (up to 2x speedup). Based on https://github.com/aprelev/libgost15.
Diffstat (limited to 'src/Volume')
-rw-r--r--src/Volume/Cipher.cpp48
-rw-r--r--src/Volume/Cipher.h2
-rw-r--r--src/Volume/Volume.make1
3 files changed, 50 insertions, 1 deletions
diff --git a/src/Volume/Cipher.cpp b/src/Volume/Cipher.cpp
index de351ad..32f61b7 100644
--- a/src/Volume/Cipher.cpp
+++ b/src/Volume/Cipher.cpp
@@ -462,5 +462,53 @@ namespace VeraCrypt
{
kuznyechik_set_key (key, (kuznyechik_kds *) ScheduledKey.Ptr());
}
+ void CipherKuznyechik::EncryptBlocks (byte *data, size_t blockCount) const
+ {
+ if (!Initialized)
+ throw NotInitialized (SRC_POS);
+
+#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE
+ if ((blockCount >= 4)
+ && IsHwSupportAvailable())
+ {
+ kuznyechik_encrypt_blocks (data, data, blockCount, (kuznyechik_kds *) ScheduledKey.Ptr());
+ }
+ else
+#endif
+ Cipher::EncryptBlocks (data, blockCount);
+ }
+
+ void CipherKuznyechik::DecryptBlocks (byte *data, size_t blockCount) const
+ {
+ if (!Initialized)
+ throw NotInitialized (SRC_POS);
+
+#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE
+ if ((blockCount >= 4)
+ && IsHwSupportAvailable())
+ {
+ kuznyechik_decrypt_blocks (data, data, blockCount, (kuznyechik_kds *) ScheduledKey.Ptr());
+ }
+ else
+#endif
+ Cipher::DecryptBlocks (data, blockCount);
+ }
+
+ bool CipherKuznyechik::IsHwSupportAvailable () const
+ {
+#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE
+ static bool state = false;
+ static bool stateValid = false;
+
+ if (!stateValid)
+ {
+ state = HasSSE2() ? true : false;
+ stateValid = true;
+ }
+ return state;
+#else
+ return false;
+#endif
+ }
bool Cipher::HwSupportEnabled = true;
}
diff --git a/src/Volume/Cipher.h b/src/Volume/Cipher.h
index 27925b7..18d1d2e 100644
--- a/src/Volume/Cipher.h
+++ b/src/Volume/Cipher.h
@@ -104,13 +104,13 @@ namespace VeraCrypt
TC_CIPHER (Serpent, 16, 32);
TC_CIPHER (Twofish, 16, 32);
TC_CIPHER (Camellia, 16, 32);
+ TC_CIPHER (Kuznyechik, 16, 32);
#undef TC_CIPHER_ADD_METHODS
#define TC_CIPHER_ADD_METHODS
TC_CIPHER (Gost89, 16, 32);
TC_CIPHER (Gost89StaticSBOX, 16, 32);
- TC_CIPHER (Kuznyechik, 16, 32);
#undef TC_CIPHER
diff --git a/src/Volume/Volume.make b/src/Volume/Volume.make
index b8f6942..7b5cb4f 100644
--- a/src/Volume/Volume.make
+++ b/src/Volume/Volume.make
@@ -79,6 +79,7 @@ OBJS += ../Crypto/Camellia.o
OBJS += ../Crypto/GostCipher.o
OBJS += ../Crypto/Streebog.o
OBJS += ../Crypto/kuznyechik.o
+OBJS += ../Crypto/kuznyechik_simd.o
OBJS += ../Common/Crc.o
OBJS += ../Common/Endian.o