VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Volume/Cipher.cpp
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2017-06-20 17:43:35 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2017-06-21 01:39:55 +0200
commit70097ecfe54a9630e1e77fdc30204a5460228193 (patch)
treef43481a6ede0e0fcd81f8ba02006613d02d23032 /src/Volume/Cipher.cpp
parentee5c1784ea0ed1328f7607bf3ea619ef3bd96d03 (diff)
downloadVeraCrypt-70097ecfe54a9630e1e77fdc30204a5460228193.tar.gz
VeraCrypt-70097ecfe54a9630e1e77fdc30204a5460228193.zip
Crypto: Add optimized Camellia assembly implementation for x86_64 based on work by Jussi Kivilinna (https://github.com/jkivilin/supercop-blockciphers). This improve speed by a factor of 2.5 when AES-NI supported by CPU and by 30% if AES-NI not supported.
Diffstat (limited to 'src/Volume/Cipher.cpp')
-rw-r--r--src/Volume/Cipher.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/Volume/Cipher.cpp b/src/Volume/Cipher.cpp
index be8cc3eb..1b5df79f 100644
--- a/src/Volume/Cipher.cpp
+++ b/src/Volume/Cipher.cpp
@@ -24,6 +24,23 @@
#endif
#include "Crypto/cpu.h"
+extern "C" int IsAesHwCpuSupported ()
+{
+#ifdef TC_AES_HW_CPU
+ static bool state = false;
+ static bool stateValid = false;
+
+ if (!stateValid)
+ {
+ state = g_hasAESNI ? true : false;
+ stateValid = true;
+ }
+ return state && Cipher::IsHwSupportEnabled();
+#else
+ return false;
+#endif
+}
+
namespace VeraCrypt
{
Cipher::Cipher () : Initialized (false)
@@ -349,6 +366,39 @@ namespace VeraCrypt
{
camellia_set_key (key, ScheduledKey.Ptr());
}
+
+ void CipherCamellia::EncryptBlocks (byte *data, size_t blockCount) const
+ {
+ if (!Initialized)
+ throw NotInitialized (SRC_POS);
+
+#if CRYPTOPP_BOOL_X64
+ camellia_encrypt_blocks ( ScheduledKey.Ptr(), data, data, blockCount);
+#else
+ Cipher::EncryptBlocks (data, blockCount);
+#endif
+ }
+
+ void CipherCamellia::DecryptBlocks (byte *data, size_t blockCount) const
+ {
+ if (!Initialized)
+ throw NotInitialized (SRC_POS);
+
+#if CRYPTOPP_BOOL_X64
+ camellia_decrypt_blocks ( ScheduledKey.Ptr(), data, data, blockCount);
+#else
+ Cipher::DecryptBlocks (data, blockCount);
+#endif
+ }
+
+ bool CipherCamellia::IsHwSupportAvailable () const
+ {
+#if CRYPTOPP_BOOL_X64
+ return true;
+#else
+ return false;
+#endif
+ }
// GOST89
void CipherGost89::Decrypt (byte *data) const