Crypto++
sha3.h
1 // sha3.h - written and placed in the public domain by Wei Dai
2 
3 #ifndef CRYPTOPP_SHA3_H
4 #define CRYPTOPP_SHA3_H
5 
6 #include "cryptlib.h"
7 #include "secblock.h"
8 
9 NAMESPACE_BEGIN(CryptoPP)
10 
11 /// <a href="http://en.wikipedia.org/wiki/SHA-3">SHA-3</a>
12 class SHA3 : public HashTransformation
13 {
14 public:
15  SHA3(unsigned int digestSize) : m_digestSize(digestSize) {Restart();}
16  unsigned int DigestSize() const {return m_digestSize;}
17  std::string AlgorithmName() const {return "SHA-3-" + IntToString(m_digestSize*8);}
18  unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word64>();}
19 
20  void Update(const byte *input, size_t length);
21  void Restart();
22  void TruncatedFinal(byte *hash, size_t size);
23 
24 protected:
25  inline unsigned int r() const {return 200 - 2 * m_digestSize;}
26 
28  unsigned int m_digestSize, m_counter;
29 };
30 
31 class SHA3_224 : public SHA3
32 {
33 public:
34  CRYPTOPP_CONSTANT(DIGESTSIZE = 28)
35  SHA3_224() : SHA3(DIGESTSIZE) {}
36  static const char * StaticAlgorithmName() {return "SHA-3-224";}
37 };
38 
39 class SHA3_256 : public SHA3
40 {
41 public:
42  CRYPTOPP_CONSTANT(DIGESTSIZE = 32)
43  SHA3_256() : SHA3(DIGESTSIZE) {}
44  static const char * StaticAlgorithmName() {return "SHA-3-256";}
45 };
46 
47 class SHA3_384 : public SHA3
48 {
49 public:
50  CRYPTOPP_CONSTANT(DIGESTSIZE = 48)
51  SHA3_384() : SHA3(DIGESTSIZE) {}
52  static const char * StaticAlgorithmName() {return "SHA-3-384";}
53 };
54 
55 class SHA3_512 : public SHA3
56 {
57 public:
58  CRYPTOPP_CONSTANT(DIGESTSIZE = 64)
59  SHA3_512() : SHA3(DIGESTSIZE) {}
60  static const char * StaticAlgorithmName() {return "SHA-3-512";}
61 };
62 
63 NAMESPACE_END
64 
65 #endif