moved BlockSize() into child classes

moved the BlockkSize() function into the child classes and made it
return the BLOCKSIZE value to enhance speed
pull/280/head
DevJPM 2016-09-20 00:48:02 +02:00
parent 8779c8cd78
commit 51466b5b24
2 changed files with 10 additions and 2 deletions

View File

@ -56,7 +56,7 @@ public:
void Restart(); void Restart();
void TruncatedFinal(byte *hash, size_t size); void TruncatedFinal(byte *hash, size_t size);
unsigned int BlockSize() const { return r(); } //unsigned int BlockSize() const { return r(); } // that's the idea behind it
protected: protected:
inline unsigned int r() const {return 200 - 2 * m_digestSize;} inline unsigned int r() const {return 200 - 2 * m_digestSize;}
@ -77,6 +77,7 @@ public:
//! \brief Construct a Keccak-224 message digest //! \brief Construct a Keccak-224 message digest
Keccak_224() : Keccak(DIGESTSIZE) {} Keccak_224() : Keccak(DIGESTSIZE) {}
CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Keccak-224";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Keccak-224";}
unsigned int BlockSize() const { return BLOCKSIZE; }
private: private:
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC
@ -94,6 +95,7 @@ public:
//! \brief Construct a Keccak-256 message digest //! \brief Construct a Keccak-256 message digest
Keccak_256() : Keccak(DIGESTSIZE) {} Keccak_256() : Keccak(DIGESTSIZE) {}
CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Keccak-256";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Keccak-256";}
unsigned int BlockSize() const { return BLOCKSIZE; }
private: private:
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC
@ -111,6 +113,7 @@ public:
//! \brief Construct a Keccak-384 message digest //! \brief Construct a Keccak-384 message digest
Keccak_384() : Keccak(DIGESTSIZE) {} Keccak_384() : Keccak(DIGESTSIZE) {}
CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Keccak-384";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Keccak-384";}
unsigned int BlockSize() const { return BLOCKSIZE; }
private: private:
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC
@ -128,6 +131,7 @@ public:
//! \brief Construct a Keccak-512 message digest //! \brief Construct a Keccak-512 message digest
Keccak_512() : Keccak(DIGESTSIZE) {} Keccak_512() : Keccak(DIGESTSIZE) {}
CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Keccak-512";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Keccak-512";}
unsigned int BlockSize() const { return BLOCKSIZE; }
private: private:
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC

6
sha3.h
View File

@ -42,7 +42,7 @@ public:
void Restart(); void Restart();
void TruncatedFinal(byte *hash, size_t size); void TruncatedFinal(byte *hash, size_t size);
unsigned int BlockSize() const { return r(); } // unsigned int BlockSize() const { return r(); } // that's the idea behind it
protected: protected:
inline unsigned int r() const {return 200 - 2 * m_digestSize;} inline unsigned int r() const {return 200 - 2 * m_digestSize;}
@ -62,6 +62,7 @@ public:
//! \brief Construct a SHA3-224 message digest //! \brief Construct a SHA3-224 message digest
SHA3_224() : SHA3(DIGESTSIZE) {} SHA3_224() : SHA3(DIGESTSIZE) {}
CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA3-224";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA3-224";}
unsigned int BlockSize() const { return BLOCKSIZE; }
private: private:
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC
@ -79,6 +80,7 @@ public:
//! \brief Construct a SHA3-256 message digest //! \brief Construct a SHA3-256 message digest
SHA3_256() : SHA3(DIGESTSIZE) {} SHA3_256() : SHA3(DIGESTSIZE) {}
CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA3-256";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA3-256";}
unsigned int BlockSize() const { return BLOCKSIZE; }
private: private:
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC
@ -96,6 +98,7 @@ public:
//! \brief Construct a SHA3-384 message digest //! \brief Construct a SHA3-384 message digest
SHA3_384() : SHA3(DIGESTSIZE) {} SHA3_384() : SHA3(DIGESTSIZE) {}
CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA3-384";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA3-384";}
unsigned int BlockSize() const { return BLOCKSIZE; }
private: private:
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC
@ -113,6 +116,7 @@ public:
//! \brief Construct a SHA3-512 message digest //! \brief Construct a SHA3-512 message digest
SHA3_512() : SHA3(DIGESTSIZE) {} SHA3_512() : SHA3(DIGESTSIZE) {}
CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA3-512";} CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA3-512";}
unsigned int BlockSize() const { return BLOCKSIZE; }
private: private:
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC