summaryrefslogtreecommitdiff
path: root/lea.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-06-22 16:26:27 -0400
committerJeffrey Walton <noloader@gmail.com>2018-06-22 16:26:27 -0400
commitfa7714f6cbe7e491faaa2b6299a12476b9be04c2 (patch)
tree324bdbc2fc76ea93acb0cfc829bee9e92bd22629 /lea.cpp
parentea109e0f8fc5c41e712cea2978adc0215e36fbbe (diff)
downloadcryptopp-git-fa7714f6cbe7e491faaa2b6299a12476b9be04c2.tar.gz
Add LEA-128 SSSE3 implementation (GH #669)
LEA-128(128) from 6.73 cpb to 2.84 cpb on modern Core-i5 6400. LEA-128 from 10.12 cpb to 7.84 cpb antique Core2 Duo.
Diffstat (limited to 'lea.cpp')
-rw-r--r--lea.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/lea.cpp b/lea.cpp
index 008dcf8b..780bb407 100644
--- a/lea.cpp
+++ b/lea.cpp
@@ -18,6 +18,7 @@
#include "lea.h"
#include "misc.h"
+#include "cpu.h"
ANONYMOUS_NAMESPACE_BEGIN
@@ -554,6 +555,16 @@ inline void SetKey256(word32 rkey[192], const word32 key[8])
NAMESPACE_BEGIN(CryptoPP)
+#if CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS
+extern void LEA_SplatKeys_SSSE3(SecBlock<word32>& rkeys);
+
+extern size_t LEA_Enc_AdvancedProcessBlocks_SSSE3(const word32* subKeys, size_t rounds,
+ const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags);
+
+extern size_t LEA_Dec_AdvancedProcessBlocks_SSSE3(const word32* subKeys, size_t rounds,
+ const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags);
+#endif
+
void LEA::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params)
{
CRYPTOPP_UNUSED(params);
@@ -584,6 +595,15 @@ void LEA::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, con
default:
CRYPTOPP_ASSERT(0);;
}
+
+#if (CRYPTOPP_SSSE3_AVAILABLE)
+ if (HasSSSE3())
+ {
+ // If we pre-splat the round keys at setup then we avoid a shuffle
+ // at runtime for each subkey used during encryption and decryption.
+ LEA_SplatKeys_SSSE3(m_rkey);
+ }
+#endif
}
void LEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
@@ -826,4 +846,26 @@ void LEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byt
oblock(m_temp[0])(m_temp[1])(m_temp[2])(m_temp[3]);
}
+#if CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS
+size_t LEA::Enc::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks,
+ byte *outBlocks, size_t length, word32 flags) const
+{
+ if (HasSSSE3()) {
+ return LEA_Enc_AdvancedProcessBlocks_SSSE3(m_rkey, m_rounds,
+ inBlocks, xorBlocks, outBlocks, length, flags);
+ }
+ return BlockTransformation::AdvancedProcessBlocks(inBlocks, xorBlocks, outBlocks, length, flags);
+}
+
+size_t LEA::Dec::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks,
+ byte *outBlocks, size_t length, word32 flags) const
+{
+ if (HasSSSE3()) {
+ return LEA_Dec_AdvancedProcessBlocks_SSSE3(m_rkey, m_rounds,
+ inBlocks, xorBlocks, outBlocks, length, flags);
+ }
+ return BlockTransformation::AdvancedProcessBlocks(inBlocks, xorBlocks, outBlocks, length, flags);
+}
+#endif // CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS
+
NAMESPACE_END