From 54e2eae4f8a6193c8d4cf776ca3044a7314aff79 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Fri, 16 Apr 2021 04:56:47 -0400 Subject: Use BLOCKSIZE constant in LSH base classes --- lsh.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 18 deletions(-) (limited to 'lsh.h') diff --git a/lsh.h b/lsh.h index 0bf2c638..9913e418 100644 --- a/lsh.h +++ b/lsh.h @@ -23,9 +23,13 @@ NAMESPACE_BEGIN(CryptoPP) class LSH256_Base : public HashTransformation { public: + /// \brief Block size, in bytes + /// \details LSH_256 uses LSH256_MSG_BLK_BYTE_LEN for block size, which is 128 + CRYPTOPP_CONSTANT(BLOCKSIZE = 128); + virtual ~LSH256_Base() {} - unsigned int BlockSize() const { return m_blockSize; } + unsigned int BlockSize() const { return BLOCKSIZE; } unsigned int DigestSize() const { return m_digestSize; } unsigned int OptimalDataAlignment() const { return GetAlignmentOf(); } @@ -36,8 +40,8 @@ public: std::string AlgorithmProvider() const; protected: - LSH256_Base(unsigned int algType, unsigned int digestSize, unsigned int blockSize) - : m_algType(algType), m_digestSize(digestSize), m_blockSize(blockSize) {} + LSH256_Base(unsigned int algType, unsigned int digestSize) + : m_algType(algType), m_digestSize(digestSize) {} protected: // Working state is: @@ -50,7 +54,7 @@ protected: // * last_block = 32 32-bit words (128 bytes) FixedSizeSecBlock m_state; word32 m_algType, m_remainingBitLength; - word32 m_digestSize, m_blockSize; + word32 m_digestSize; }; /// \brief LSH-224 hash function @@ -60,14 +64,18 @@ protected: class LSH224 : public LSH256_Base { public: + /// \brief Digest size, in bytes + /// \details LSH_256 uses LSH_GET_HASHBYTE(algType) for digest size, which is 28 CRYPTOPP_CONSTANT(DIGESTSIZE = 28); - CRYPTOPP_CONSTANT(BLOCKSIZE = 64); + /// \brief Block size, in bytes + /// \details LSH_256 uses LSH256_MSG_BLK_BYTE_LEN for block size, which is 128 + CRYPTOPP_CONSTANT(BLOCKSIZE = LSH256_Base::BLOCKSIZE); static std::string StaticAlgorithmName() { return "LSH-224"; } /// \brief Construct a LSH-224 /// \details LSH_TYPE_224 is the magic value 0x000001C defined in lsh.cpp. - LSH224() : LSH256_Base(0x000001C, DIGESTSIZE, BLOCKSIZE) { Restart(); } + LSH224() : LSH256_Base(0x000001C, DIGESTSIZE) { Restart(); } std::string AlgorithmName() const { return StaticAlgorithmName(); } }; @@ -79,14 +87,18 @@ public: class LSH256 : public LSH256_Base { public: + /// \brief Digest size, in bytes + /// \details LSH_256 uses LSH_GET_HASHBYTE(algType) for digest size, which is 32 CRYPTOPP_CONSTANT(DIGESTSIZE = 32); - CRYPTOPP_CONSTANT(BLOCKSIZE = 64); + /// \brief Block size, in bytes + /// \details LSH_256 uses LSH256_MSG_BLK_BYTE_LEN for block size, which is 128 + CRYPTOPP_CONSTANT(BLOCKSIZE = LSH256_Base::BLOCKSIZE); static std::string StaticAlgorithmName() { return "LSH-256"; } /// \brief Construct a LSH-256 /// \details LSH_TYPE_256 is the magic value 0x0000020 defined in lsh.cpp. - LSH256() : LSH256_Base(0x0000020, DIGESTSIZE, BLOCKSIZE) { Restart(); } + LSH256() : LSH256_Base(0x0000020, DIGESTSIZE) { Restart(); } std::string AlgorithmName() const { return StaticAlgorithmName(); } }; @@ -97,9 +109,13 @@ public: class LSH512_Base : public HashTransformation { public: + /// \brief Block size, in bytes + //// \details LSH_512 uses LSH512_MSG_BLK_BYTE_LEN for block size, which is 256 + CRYPTOPP_CONSTANT(BLOCKSIZE = 256); + virtual ~LSH512_Base() {} - unsigned int BlockSize() const { return m_blockSize; } + unsigned int BlockSize() const { return BLOCKSIZE; } unsigned int DigestSize() const { return m_digestSize; } unsigned int OptimalDataAlignment() const { return GetAlignmentOf(); } @@ -110,8 +126,8 @@ public: std::string AlgorithmProvider() const; protected: - LSH512_Base(unsigned int algType, unsigned int digestSize, unsigned int blockSize) - : m_algType(algType), m_digestSize(digestSize), m_blockSize(blockSize) {} + LSH512_Base(unsigned int algType, unsigned int digestSize) + : m_algType(algType), m_digestSize(digestSize) {} protected: // Working state is: @@ -124,7 +140,7 @@ protected: // * last_block = 32 64-bit words (256 bytes) FixedSizeSecBlock m_state; word32 m_algType, m_remainingBitLength; - word32 m_digestSize, m_blockSize; + word32 m_digestSize; }; /// \brief LSH-384 hash function @@ -134,14 +150,18 @@ protected: class LSH384 : public LSH512_Base { public: + /// \brief Digest size, in bytes + /// \details LSH_512 uses LSH_GET_HASHBYTE(algType) for digest size, which is 48 CRYPTOPP_CONSTANT(DIGESTSIZE = 48); - CRYPTOPP_CONSTANT(BLOCKSIZE = 128); + /// \brief Block size, in bytes + /// \details LSH_512 uses LSH512_MSG_BLK_BYTE_LEN for block size, which is 256 + CRYPTOPP_CONSTANT(BLOCKSIZE = LSH512_Base::BLOCKSIZE); static std::string StaticAlgorithmName() { return "LSH-384"; } /// \brief Construct a LSH-384 /// \details LSH_TYPE_384 is the magic value 0x0010030 defined in lsh.cpp. - LSH384() : LSH512_Base(0x0010030, DIGESTSIZE, BLOCKSIZE) { Restart(); } + LSH384() : LSH512_Base(0x0010030, DIGESTSIZE) { Restart(); } std::string AlgorithmName() const { return StaticAlgorithmName(); } }; @@ -153,14 +173,18 @@ public: class LSH512 : public LSH512_Base { public: + /// \brief Digest size, in bytes + /// \details LSH_512 uses LSH_GET_HASHBYTE(algType) for digest size, which is 64 CRYPTOPP_CONSTANT(DIGESTSIZE = 64); - CRYPTOPP_CONSTANT(BLOCKSIZE = 128); + /// \brief Block size, in bytes + /// \details LSH_512 uses LSH512_MSG_BLK_BYTE_LEN for block size, which is 256 + CRYPTOPP_CONSTANT(BLOCKSIZE = LSH512_Base::BLOCKSIZE); static std::string StaticAlgorithmName() { return "LSH-512"; } /// \brief Construct a LSH-512 /// \details LSH_TYPE_512 is the magic value 0x0010040 defined in lsh.cpp. - LSH512() : LSH512_Base(0x0010040, DIGESTSIZE, BLOCKSIZE) { Restart(); } + LSH512() : LSH512_Base(0x0010040, DIGESTSIZE) { Restart(); } std::string AlgorithmName() const { return StaticAlgorithmName(); } }; @@ -172,14 +196,18 @@ public: class LSH512_256 : public LSH512_Base { public: + /// \brief Digest size, in bytes + /// \details LSH_512 uses LSH_GET_HASHBYTE(algType) for digest size, which is 32 CRYPTOPP_CONSTANT(DIGESTSIZE = 32); - CRYPTOPP_CONSTANT(BLOCKSIZE = 128); + /// \brief Block size, in bytes + /// \details LSH_512 uses LSH512_MSG_BLK_BYTE_LEN for block size, which is 256 + CRYPTOPP_CONSTANT(BLOCKSIZE = LSH512_Base::BLOCKSIZE); static std::string StaticAlgorithmName() { return "LSH-512-256"; } /// \brief Construct a LSH-512-256 /// \details LSH_TYPE_512_256 is the magic value 0x0010020 defined in lsh.cpp. - LSH512_256() : LSH512_Base(0x0010020, DIGESTSIZE, BLOCKSIZE) { Restart(); } + LSH512_256() : LSH512_Base(0x0010020, DIGESTSIZE) { Restart(); } std::string AlgorithmName() const { return StaticAlgorithmName(); } }; -- cgit v1.2.1