diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-11-28 00:29:36 +0100 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-12-07 12:36:04 +0100 |
commit | 263abeee3a8c97e98fec49ee0ce628d6c5c5df50 (patch) | |
tree | c6a326a7c90280cb3926c58275f361b999bd2ba3 /src/Volume | |
parent | 68fababbe88cf213b3f2f3a71d66c2b05196aaed (diff) | |
download | VeraCrypt-263abeee3a8c97e98fec49ee0ce628d6c5c5df50.tar.gz VeraCrypt-263abeee3a8c97e98fec49ee0ce628d6c5c5df50.zip |
Crypto: Add optimized Twofish assembly implementation for x86_64.
Diffstat (limited to 'src/Volume')
-rw-r--r-- | src/Volume/Cipher.cpp | 33 | ||||
-rw-r--r-- | src/Volume/Cipher.h | 3 | ||||
-rw-r--r-- | src/Volume/Volume.make | 5 |
3 files changed, 40 insertions, 1 deletions
diff --git a/src/Volume/Cipher.cpp b/src/Volume/Cipher.cpp index 09c821bb..be8cc3eb 100644 --- a/src/Volume/Cipher.cpp +++ b/src/Volume/Cipher.cpp @@ -296,6 +296,39 @@ namespace VeraCrypt twofish_set_key ((TwofishInstance *) ScheduledKey.Ptr(), (unsigned int *) key); } + void CipherTwofish::EncryptBlocks (byte *data, size_t blockCount) const + { + if (!Initialized) + throw NotInitialized (SRC_POS); + +#if CRYPTOPP_BOOL_X64 + twofish_encrypt_blocks ( (TwofishInstance *) ScheduledKey.Ptr(), data, data, blockCount); +#else + Cipher::EncryptBlocks (data, blockCount); +#endif + } + + void CipherTwofish::DecryptBlocks (byte *data, size_t blockCount) const + { + if (!Initialized) + throw NotInitialized (SRC_POS); + +#if CRYPTOPP_BOOL_X64 + twofish_decrypt_blocks ( (TwofishInstance *) ScheduledKey.Ptr(), data, data, blockCount); +#else + Cipher::DecryptBlocks (data, blockCount); +#endif + } + + bool CipherTwofish::IsHwSupportAvailable () const + { +#if CRYPTOPP_BOOL_X64 + return true; +#else + return false; +#endif + } + // Camellia void CipherCamellia::Decrypt (byte *data) const { diff --git a/src/Volume/Cipher.h b/src/Volume/Cipher.h index 7aefbfc6..5ebdde19 100644 --- a/src/Volume/Cipher.h +++ b/src/Volume/Cipher.h @@ -14,6 +14,7 @@ #define TC_HEADER_Encryption_Ciphers #include "Platform/Platform.h" +#include "Crypto/config.h" namespace VeraCrypt @@ -101,11 +102,11 @@ namespace VeraCrypt TC_CIPHER (AES, 16, 32); TC_CIPHER (Serpent, 16, 32); + TC_CIPHER (Twofish, 16, 32); #undef TC_CIPHER_ADD_METHODS #define TC_CIPHER_ADD_METHODS - TC_CIPHER (Twofish, 16, 32); TC_CIPHER (Camellia, 16, 32); TC_CIPHER (Gost89, 16, 32); TC_CIPHER (Gost89StaticSBOX, 16, 32); diff --git a/src/Volume/Volume.make b/src/Volume/Volume.make index fa3a4207..f6a8cec8 100644 --- a/src/Volume/Volume.make +++ b/src/Volume/Volume.make @@ -33,12 +33,14 @@ ifeq "$(PLATFORM)" "MacOSX" OBJSEX += ../Crypto/Aes_asm.oo OBJS += ../Crypto/Aes_hw_cpu.o OBJS += ../Crypto/Aescrypt.o + OBJSEX += ../Crypto/Twofish_asm.oo else ifeq "$(CPU_ARCH)" "x86" OBJS += ../Crypto/Aes_x86.o OBJS += ../Crypto/Aes_hw_cpu.o else ifeq "$(CPU_ARCH)" "x64" OBJS += ../Crypto/Aes_x64.o OBJS += ../Crypto/Aes_hw_cpu.o + OBJS += ../Crypto/Twofish_x64.o else OBJS += ../Crypto/Aescrypt.o endif @@ -72,6 +74,9 @@ ifeq "$(PLATFORM)" "MacOSX" $(AS) $(ASFLAGS) -f macho64 -o ../Crypto/Aes_x64.o ../Crypto/Aes_x64.asm lipo -create ../Crypto/Aes_x86.o ../Crypto/Aes_x64.o -output ../Crypto/Aes_asm.oo rm -fr ../Crypto/Aes_x86.o ../Crypto/Aes_x64.o +../Crypto/Twofish_asm.oo: ../Crypto/Twofish_x64.S + @echo Assembling $(<F) + $(CC) -arch x86_64 -c ../Crypto/Twofish_x64.S -o ../Crypto/Twofish_asm.oo endif include $(BUILD_INC)/Makefile.inc |