From 6282aab71c9f925b533065e4dbfce632b83ee4ac Mon Sep 17 00:00:00 2001 From: weidai Date: Sat, 19 Jan 2013 02:20:00 +0000 Subject: add SHA-3 update DSA to FIPS 186-3 update version numbers git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@535 57ff6487-cd31-0410-9ec3-f628ee90f5f0 --- sha3.h | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 sha3.h (limited to 'sha3.h') diff --git a/sha3.h b/sha3.h new file mode 100644 index 0000000..232bae5 --- /dev/null +++ b/sha3.h @@ -0,0 +1,65 @@ +// sha3.h - written and placed in the public domain by Wei Dai + +#ifndef CRYPTOPP_SHA3_H +#define CRYPTOPP_SHA3_H + +#include "cryptlib.h" +#include "secblock.h" + +NAMESPACE_BEGIN(CryptoPP) + +/// SHA-3 +class SHA3 : public HashTransformation +{ +public: + SHA3(unsigned int digestSize) : m_digestSize(digestSize) {Restart();} + unsigned int DigestSize() const {return m_digestSize;} + std::string AlgorithmName() const {return "SHA-3-" + IntToString(m_digestSize*8);} + unsigned int OptimalDataAlignment() const {return GetAlignmentOf();} + + 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;} + + FixedSizeSecBlock m_state; + unsigned int m_digestSize, m_counter; +}; + +class SHA3_224 : public SHA3 +{ +public: + CRYPTOPP_CONSTANT(DIGESTSIZE = 28) + SHA3_224() : SHA3(DIGESTSIZE) {} + static const char * StaticAlgorithmName() {return "SHA-3-224";} +}; + +class SHA3_256 : public SHA3 +{ +public: + CRYPTOPP_CONSTANT(DIGESTSIZE = 32) + SHA3_256() : SHA3(DIGESTSIZE) {} + static const char * StaticAlgorithmName() {return "SHA-3-256";} +}; + +class SHA3_384 : public SHA3 +{ +public: + CRYPTOPP_CONSTANT(DIGESTSIZE = 48) + SHA3_384() : SHA3(DIGESTSIZE) {} + static const char * StaticAlgorithmName() {return "SHA-3-384";} +}; + +class SHA3_512 : public SHA3 +{ +public: + CRYPTOPP_CONSTANT(DIGESTSIZE = 64) + SHA3_512() : SHA3(DIGESTSIZE) {} + static const char * StaticAlgorithmName() {return "SHA-3-512";} +}; + +NAMESPACE_END + +#endif -- cgit v1.2.1