Crypto++  5.6.3
Free C++ class library of cryptographic schemes
sha3.h
Go to the documentation of this file.
1 // sha3.h - written and placed in the public domain by Wei Dai
2 
3 //! \file
4 //! \headerfile sha3.h
5 //! \brief Classes for SHA-3 message digests
6 
7 #ifndef CRYPTOPP_SHA3_H
8 #define CRYPTOPP_SHA3_H
9 
10 #include "cryptlib.h"
11 #include "secblock.h"
12 
13 NAMESPACE_BEGIN(CryptoPP)
14 
15 /// <a href="http://en.wikipedia.org/wiki/SHA-3">SHA-3</a>
16 class SHA3 : public HashTransformation
17 {
18 public:
19  SHA3(unsigned int digestSize) : m_digestSize(digestSize) {Restart();}
20  unsigned int DigestSize() const {return m_digestSize;}
21  std::string AlgorithmName() const {return "SHA-3-" + IntToString(m_digestSize*8);}
22  unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word64>();}
23 
24  void Update(const byte *input, size_t length);
25  void Restart();
26  void TruncatedFinal(byte *hash, size_t size);
27 
28 protected:
29  inline unsigned int r() const {return 200 - 2 * m_digestSize;}
30 
32  unsigned int m_digestSize, m_counter;
33 };
34 
35 class SHA3_224 : public SHA3
36 {
37 public:
38  CRYPTOPP_CONSTANT(DIGESTSIZE = 28)
39  SHA3_224() : SHA3(DIGESTSIZE) {}
40  static const char * StaticAlgorithmName() {return "SHA-3-224";}
41 };
42 
43 class SHA3_256 : public SHA3
44 {
45 public:
46  CRYPTOPP_CONSTANT(DIGESTSIZE = 32)
47  SHA3_256() : SHA3(DIGESTSIZE) {}
48  static const char * StaticAlgorithmName() {return "SHA-3-256";}
49 };
50 
51 class SHA3_384 : public SHA3
52 {
53 public:
54  CRYPTOPP_CONSTANT(DIGESTSIZE = 48)
55  SHA3_384() : SHA3(DIGESTSIZE) {}
56  static const char * StaticAlgorithmName() {return "SHA-3-384";}
57 };
58 
59 class SHA3_512 : public SHA3
60 {
61 public:
62  CRYPTOPP_CONSTANT(DIGESTSIZE = 64)
63  SHA3_512() : SHA3(DIGESTSIZE) {}
64  static const char * StaticAlgorithmName() {return "SHA-3-512";}
65 };
66 
67 NAMESPACE_END
68 
69 #endif
SHA-3
Definition: sha3.h:16
Definition: sha3.h:43
Abstract base classes that provide a uniform interface to this library.
Definition: sha3.h:35
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: sha3.h:21
Classes and functions for secure memory allocations.
Definition: sha3.h:59
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:858
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Definition: misc.h:449
Crypto++ library namespace.
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: sha3.h:20
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: sha3.h:22
Definition: sha3.h:51