summaryrefslogtreecommitdiff
path: root/keccak.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 /keccak.h
parente499131ea6ba23ce57f6a7e50d0c2ff3fb8eff62 (diff)
downloadcryptopp-git-c6e8a61b8b7dac8ac33bf12a4b9a0b510232da83.tar.gz
Add SHAKE-128 and SHAKE-256 (GH #805, PR #806)
Diffstat (limited to 'keccak.h')
-rw-r--r--keccak.h61
1 files changed, 29 insertions, 32 deletions
diff --git a/keccak.h b/keccak.h
index a686f0a3..b9665d8f 100644
--- a/keccak.h
+++ b/keccak.h
@@ -40,29 +40,25 @@ NAMESPACE_BEGIN(CryptoPP)
class Keccak : public HashTransformation
{
public:
- /// \brief Construct a Keccak
- /// \param digestSize the digest size, in bytes
- /// \details Keccak is the base class for Keccak_224, Keccak_256, Keccak_384 and Keccak_512.
- /// Library users should instantiate a derived class, and only use Keccak
- /// as a base class reference or pointer.
- /// \since Crypto++ 5.6.4
- Keccak(unsigned int digestSize) : m_digestSize(digestSize) {Restart();}
- unsigned int DigestSize() const {return m_digestSize;}
- std::string AlgorithmName() const {return "Keccak-" + IntToString(m_digestSize*8);}
- CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "Keccak"; }
- 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 Keccak
+ /// \param digestSize the digest size, in bytes
+ /// \details Keccak is the base class for Keccak_224, Keccak_256, Keccak_384 and Keccak_512.
+ /// Library users should instantiate a derived class, and only use Keccak
+ /// as a base class reference or pointer.
+ /// \since Crypto++ 5.6.4
+ Keccak(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 Keccak message digest template
@@ -72,33 +68,34 @@ template<unsigned int T_DigestSize>
class Keccak_Final : public Keccak
{
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 Keccak-X message digest
+ Keccak_Final() : Keccak(DIGESTSIZE) {}
+ static std::string StaticAlgorithmName() { return "Keccak-" + IntToString(DIGESTSIZE * 8); }
+ unsigned int BlockSize() const { return BLOCKSIZE; }
- /// \brief Construct a Keccak-X message digest
- Keccak_Final() : Keccak(DIGESTSIZE) {}
- static std::string StaticAlgorithmName() { return "Keccak-" + IntToString(DIGESTSIZE * 8); }
- unsigned int BlockSize() const { return BLOCKSIZE; }
private:
- 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
};
/// \brief Keccak-224 message digest
/// \since Crypto++ 5.6.4
-typedef Keccak_Final<28> Keccak_224;
+DOCUMENTED_TYPEDEF(Keccak_Final<28>, Keccak_224);
/// \brief Keccak-256 message digest
/// \since Crypto++ 5.6.4
-typedef Keccak_Final<32> Keccak_256;
+DOCUMENTED_TYPEDEF(Keccak_Final<32>, Keccak_256);
/// \brief Keccak-384 message digest
/// \since Crypto++ 5.6.4
-typedef Keccak_Final<48> Keccak_384;
+DOCUMENTED_TYPEDEF(Keccak_Final<48>, Keccak_384);
/// \brief Keccak-512 message digest
/// \since Crypto++ 5.6.4
-typedef Keccak_Final<64> Keccak_512;
+DOCUMENTED_TYPEDEF(Keccak_Final<64>, Keccak_512);
NAMESPACE_END