VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Volume
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2016-10-04 13:21:48 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2016-10-17 18:40:23 +0200
commite5a9e9239b0cf1001d9b91497b4ff3ab4a190b1f (patch)
tree5656a151e5f777d834924a3784432c5bd928ed03 /src/Volume
parent7ff3c5d1080482c55a5c5f4720d22d212a8d7373 (diff)
downloadVeraCrypt-e5a9e9239b0cf1001d9b91497b4ff3ab4a190b1f.tar.gz
VeraCrypt-e5a9e9239b0cf1001d9b91497b4ff3ab4a190b1f.zip
Crypto: Use SIMD optimized Serpent implementation from Botan. 2.5x speed gain factor. Update credits and copyrights notice.
Diffstat (limited to 'src/Volume')
-rw-r--r--src/Volume/Cipher.cpp53
-rw-r--r--src/Volume/Cipher.h2
-rw-r--r--src/Volume/Volume.make3
3 files changed, 54 insertions, 4 deletions
diff --git a/src/Volume/Cipher.cpp b/src/Volume/Cipher.cpp
index 3363f640..09c821bb 100644
--- a/src/Volume/Cipher.cpp
+++ b/src/Volume/Cipher.cpp
@@ -13,7 +13,7 @@
#include "Platform/Platform.h"
#include "Cipher.h"
#include "Crypto/Aes.h"
-#include "Crypto/Serpent.h"
+#include "Crypto/SerpentFast.h"
#include "Crypto/Twofish.h"
#include "Crypto/Camellia.h"
#include "Crypto/GostCipher.h"
@@ -21,8 +21,8 @@
#ifdef TC_AES_HW_CPU
# include "Crypto/Aes_hw_cpu.h"
-# include "Crypto/cpu.h"
#endif
+#include "Crypto/cpu.h"
namespace VeraCrypt
{
@@ -224,6 +224,55 @@ namespace VeraCrypt
{
serpent_set_key (key, ScheduledKey);
}
+
+ void CipherSerpent::EncryptBlocks (byte *data, size_t blockCount) const
+ {
+ if (!Initialized)
+ throw NotInitialized (SRC_POS);
+
+#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE
+ if ((blockCount >= 4)
+ && IsHwSupportAvailable())
+ {
+ serpent_encrypt_blocks (data, data, blockCount, ScheduledKey.Ptr());
+ }
+ else
+#endif
+ Cipher::EncryptBlocks (data, blockCount);
+ }
+
+ void CipherSerpent::DecryptBlocks (byte *data, size_t blockCount) const
+ {
+ if (!Initialized)
+ throw NotInitialized (SRC_POS);
+
+#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE
+ if ((blockCount >= 4)
+ && IsHwSupportAvailable())
+ {
+ serpent_decrypt_blocks (data, data, blockCount, ScheduledKey.Ptr());
+ }
+ else
+#endif
+ Cipher::DecryptBlocks (data, blockCount);
+ }
+
+ bool CipherSerpent::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
+ }
// Twofish
diff --git a/src/Volume/Cipher.h b/src/Volume/Cipher.h
index 1805229e..7aefbfc6 100644
--- a/src/Volume/Cipher.h
+++ b/src/Volume/Cipher.h
@@ -100,11 +100,11 @@ namespace VeraCrypt
virtual bool IsHwSupportAvailable () const;
TC_CIPHER (AES, 16, 32);
+ TC_CIPHER (Serpent, 16, 32);
#undef TC_CIPHER_ADD_METHODS
#define TC_CIPHER_ADD_METHODS
- TC_CIPHER (Serpent, 16, 32);
TC_CIPHER (Twofish, 16, 32);
TC_CIPHER (Camellia, 16, 32);
TC_CIPHER (Gost89, 16, 32);
diff --git a/src/Volume/Volume.make b/src/Volume/Volume.make
index 855e5f60..fa3a4207 100644
--- a/src/Volume/Volume.make
+++ b/src/Volume/Volume.make
@@ -47,7 +47,8 @@ OBJS += ../Crypto/Aeskey.o
OBJS += ../Crypto/Aestab.o
OBJS += ../Crypto/cpu.o
OBJS += ../Crypto/Rmd160.o
-OBJS += ../Crypto/Serpent.o
+OBJS += ../Crypto/SerpentFast.o
+OBJS += ../Crypto/SerpentFast_simd.o
OBJS += ../Crypto/Sha2.o
OBJS += ../Crypto/Twofish.o
OBJS += ../Crypto/Whirlpool.o