summaryrefslogtreecommitdiff
path: root/lsh.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2021-04-26 04:50:48 -0400
committerGitHub <noreply@github.com>2021-04-26 04:50:48 -0400
commita0e21c77aeadb2d8bb4c03a830528c9ae0616dfe (patch)
tree9c8dd638fa7dd6a1c84d483eb062c7716f6a3db5 /lsh.h
parent21a40abc5ceeb0ccf6577a444f1b4c19fa6379c6 (diff)
downloadcryptopp-git-a0e21c77aeadb2d8bb4c03a830528c9ae0616dfe.tar.gz
Add LSH dynamic dispatch (PR #1032)
This commit adds dynamic dispatch to LSH. The implementation pivots on AVX2 and SSSE3.
Diffstat (limited to 'lsh.h')
-rw-r--r--lsh.h31
1 files changed, 23 insertions, 8 deletions
diff --git a/lsh.h b/lsh.h
index 68284f97..2f9918d8 100644
--- a/lsh.h
+++ b/lsh.h
@@ -4,6 +4,11 @@
// see https://seed.kisa.or.kr/kisa/algorithm/EgovLSHInfo.do
// and https://seed.kisa.or.kr/kisa/Board/22/detailView.do.
+// We are hitting some sort of GCC bug in the LSH AVX2 code path.
+// Clang is OK on the AVX2 code path. We believe it is GCC Issue
+// 82735, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82735. It
+// makes using zeroupper a little tricky.
+
/// \file lsh.h
/// \brief Classes for the LSH hash functions
/// \since Crypto++ 8.6
@@ -15,6 +20,12 @@
#include "cryptlib.h"
#include "secblock.h"
+// Enable SSE2 and AVX2 for 64-bit machines.
+// 32-bit machines slow down with SSE2.
+#if (CRYPTOPP_BOOL_X32) || (CRYPTOPP_BOOL_X64)
+# define CRYPTOPP_ENABLE_64BIT_SSE 1
+#endif
+
NAMESPACE_BEGIN(CryptoPP)
/// \brief LSH-224 and LSH-256 hash base class
@@ -34,14 +45,14 @@ public:
unsigned int OptimalDataAlignment() const { return GetAlignmentOf<word32>(); }
void Restart();
- void Update(const byte *input, size_t length);
+ void Update(const byte *input, size_t size);
void TruncatedFinal(byte *hash, size_t size);
std::string AlgorithmProvider() const;
protected:
LSH256_Base(unsigned int algType, unsigned int digestSize)
- : m_algType(algType), m_digestSize(digestSize) {}
+ : m_digestSize(digestSize) { m_state[80] = algType; }
protected:
// Working state is:
@@ -52,8 +63,10 @@ protected:
// * submsg_o_l = 8 32-bit words
// * submsg_o_r = 8 32-bit words
// * last_block = 32 32-bit words (128 bytes)
- FixedSizeSecBlock<word32, 80> m_state;
- word32 m_algType, m_remainingBitLength;
+ // * algType
+ // * remainingBitLength
+ FixedSizeSecBlock<word32, 80+2> m_state;
+ // word32 m_algType, m_remainingBitLength;
word32 m_digestSize;
};
@@ -132,14 +145,14 @@ public:
unsigned int OptimalDataAlignment() const { return GetAlignmentOf<word64>(); }
void Restart();
- void Update(const byte *input, size_t length);
+ void Update(const byte *input, size_t size);
void TruncatedFinal(byte *hash, size_t size);
std::string AlgorithmProvider() const;
protected:
LSH512_Base(unsigned int algType, unsigned int digestSize)
- : m_algType(algType), m_digestSize(digestSize) {}
+ : m_digestSize(digestSize) { m_state[80] = algType; }
protected:
// Working state is:
@@ -150,8 +163,10 @@ protected:
// * submsg_o_l = 8 64-bit words
// * submsg_o_r = 8 64-bit words
// * last_block = 32 64-bit words (256 bytes)
- FixedSizeSecBlock<word64, 80> m_state;
- word32 m_algType, m_remainingBitLength;
+ // * algType
+ // * remainingBitLength
+ FixedSizeSecBlock<word64, 80+2> m_state;
+ // word32 m_algType, m_remainingBitLength;
word32 m_digestSize;
};