summaryrefslogtreecommitdiff
path: root/sha3.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2019-02-12 19:51:37 -0500
committerGitHub <noreply@github.com>2019-02-12 19:51:37 -0500
commitc6e8a61b8b7dac8ac33bf12a4b9a0b510232da83 (patch)
treee17f8e69cefe48982a36f44e7c062b894e23ad9a /sha3.h
parente499131ea6ba23ce57f6a7e50d0c2ff3fb8eff62 (diff)
downloadcryptopp-git-c6e8a61b8b7dac8ac33bf12a4b9a0b510232da83.tar.gz
Add SHAKE-128 and SHAKE-256 (GH #805, PR #806)
Diffstat (limited to 'sha3.h')
-rw-r--r--sha3.h72
1 files changed, 29 insertions, 43 deletions
diff --git a/sha3.h b/sha3.h
index fe1fe21a..a5ded799 100644
--- a/sha3.h
+++ b/sha3.h
@@ -27,27 +27,24 @@ NAMESPACE_BEGIN(CryptoPP)
class SHA3 : public HashTransformation
{
public:
- /// \brief Construct a SHA3
- /// \param digestSize the digest size, in bytes
- /// \details SHA3 is the base class for SHA3_224, SHA3_256, SHA3_384 and SHA3_512.
- /// Library users should instantiate a derived class, and only use SHA3
- /// as a base class reference or pointer.
- SHA3(unsigned int digestSize) : m_digestSize(digestSize) {Restart();}
- unsigned int DigestSize() const {return m_digestSize;}
- std::string AlgorithmName() const {return "SHA3-" + IntToString(m_digestSize*8);}
- CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "SHA3"; }
- unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word64>();}
-
- void Update(const byte *input, size_t length);
- void Restart();
- void TruncatedFinal(byte *hash, size_t size);
-
- // unsigned int BlockSize() const { return r(); } // that's the idea behind it
+ /// \brief Construct a SHA3
+ /// \param digestSize the digest size, in bytes
+ /// \details SHA3 is the base class for SHA3_224, SHA3_256, SHA3_384 and SHA3_512.
+ /// Library users should instantiate a derived class, and only use SHA3
+ /// as a base class reference or pointer.
+ SHA3(unsigned int digestSize) : m_digestSize(digestSize) {Restart();}
+ unsigned int DigestSize() const {return m_digestSize;}
+ unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word64>();}
+
+ void Update(const byte *input, size_t length);
+ void Restart();
+ void TruncatedFinal(byte *hash, size_t size);
+
protected:
- inline unsigned int r() const {return 200 - 2 * m_digestSize;}
+ inline unsigned int r() const {return BlockSize();}
- FixedSizeSecBlock<word64, 25> m_state;
- unsigned int m_digestSize, m_counter;
+ FixedSizeSecBlock<word64, 25> m_state;
+ unsigned int m_digestSize, m_counter;
};
/// \brief SHA3 message digest template
@@ -57,47 +54,36 @@ template<unsigned int T_DigestSize>
class SHA3_Final : public SHA3
{
public:
- CRYPTOPP_CONSTANT(DIGESTSIZE = T_DigestSize)
- CRYPTOPP_CONSTANT(BLOCKSIZE = 200 - 2 * DIGESTSIZE)
+ CRYPTOPP_CONSTANT(DIGESTSIZE = T_DigestSize)
+ CRYPTOPP_CONSTANT(BLOCKSIZE = 200 - 2 * DIGESTSIZE)
+
+ /// \brief Construct a SHA3-X message digest
+ SHA3_Final() : SHA3(DIGESTSIZE) {}
+ static std::string StaticAlgorithmName() { return "SHA3-" + IntToString(DIGESTSIZE * 8); }
+ unsigned int BlockSize() const { return BLOCKSIZE; }
- /// \brief Construct a SHA3-X message digest
- SHA3_Final() : SHA3(DIGESTSIZE) {}
- static std::string StaticAlgorithmName() { return "SHA3-" + IntToString(DIGESTSIZE * 8); }
- unsigned int BlockSize() const { return BLOCKSIZE; }
private:
#if !defined(__BORLANDC__)
- CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
- CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > (int)T_DigestSize); // this is a general expectation by HMAC
+ CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
+ CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > (int)T_DigestSize); // this is a general expectation by HMAC
#endif
};
/// \brief SHA3-224 message digest
/// \since Crypto++ 5.6.2
-// typedef SHA3_Final<28> SHA3_224;
-class SHA3_224 : public SHA3_Final<28>
-{
-};
+class SHA3_224 : public SHA3_Final<28> {};
/// \brief SHA3-256 message digest
/// \since Crypto++ 5.6.2
-// typedef SHA3_Final<32> SHA3_256;
-class SHA3_256 : public SHA3_Final<32>
-{
-};
+class SHA3_256 : public SHA3_Final<32> {};
/// \brief SHA3-384 message digest
/// \since Crypto++ 5.6.2
-// typedef SHA3_Final<48> SHA3_384;
-class SHA3_384 : public SHA3_Final<48>
-{
-};
+class SHA3_384 : public SHA3_Final<48> {};
/// \brief SHA3-512 message digest
/// \since Crypto++ 5.6.2
-// typedef SHA3_Final<64> SHA3_512;
-class SHA3_512 : public SHA3_Final<64>
-{
-};
+class SHA3_512 : public SHA3_Final<64> {};
NAMESPACE_END