Fabcoin Core  0.16.2
P2P Digital Currency
sha3.h
Go to the documentation of this file.
1 // sha3.h - written and placed in the public domain by Wei Dai
2 
10 
11 #ifndef CRYPTOPP_SHA3_H
12 #define CRYPTOPP_SHA3_H
13 
14 #include "cryptlib.h"
15 #include "secblock.h"
16 
18 
19 class SHA3 : public HashTransformation
29 {
30 public:
36  SHA3(unsigned int digestSize) : m_digestSize(digestSize) {Restart();}
37  unsigned int DigestSize() const {return m_digestSize;}
38  std::string AlgorithmName() const {return "SHA3-" + IntToString(m_digestSize*8);}
39  CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "SHA3"; }
40  unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word64>();}
41 
42  void Update(const byte *input, size_t length);
43  void Restart();
44  void TruncatedFinal(byte *hash, size_t size);
45 
46  // unsigned int BlockSize() const { return r(); } // that's the idea behind it
47 protected:
48  inline unsigned int r() const {return 200 - 2 * m_digestSize;}
49 
51  unsigned int m_digestSize, m_counter;
52 };
53 
58 template<unsigned int T_DigestSize>
59 class SHA3_Final : public SHA3
60 {
61 public:
62  CRYPTOPP_CONSTANT(DIGESTSIZE = T_DigestSize)
63  CRYPTOPP_CONSTANT(BLOCKSIZE = 200 - 2 * DIGESTSIZE)
64 
65 
66  SHA3_Final() : SHA3(DIGESTSIZE) {}
67  static std::string StaticAlgorithmName() { return "SHA3-" + IntToString(DIGESTSIZE * 8); }
68  unsigned int BlockSize() const { return BLOCKSIZE; }
69 private:
70  CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
71  CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > (int)T_DigestSize); // this is a general expectation by HMAC
72 };
73 
90 
92 
93 #endif
uint8_t byte
Definition: Common.h:57
#define CRYPTOPP_STATIC_CONSTEXPR
Definition: config.h:892
SHA3 message digest base class.
Definition: sha3.h:28
unsigned int r() const
Definition: sha3.h:48
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
Abstract base classes that provide a uniform interface to this library.
CRYPTOPP_STATIC_CONSTEXPR const char * StaticAlgorithmName()
Definition: sha3.h:39
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: sha3.h:38
SHA3(unsigned int digestSize)
Construct a SHA3.
Definition: sha3.h:36
Classes and functions for secure memory allocations.
SHA3_Final< 64 > SHA3_512
Definition: sha3.h:89
SHA3_Final< 32 > SHA3_256
Definition: sha3.h:81
SHA3_Final< 48 > SHA3_384
Definition: sha3.h:85
unsigned int BlockSize() const
Provides the block size of the compression function.
Definition: sha3.h:68
#define CRYPTOPP_CONSTANT(x)
Definition: config.h:540
uint8_t const size_t const size
Definition: sha3.h:20
static std::string StaticAlgorithmName()
Definition: sha3.h:67
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:930
unsigned int m_digestSize
Definition: sha3.h:51
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Definition: misc.h:539
#define NAMESPACE_END
Definition: config.h:201
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: sha3.h:37
SHA3_Final< 28 > SHA3_224
Definition: sha3.h:77
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE< 200)
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: sha3.h:40
FixedSizeSecBlock< word64, 25 > m_state
Definition: sha3.h:50