Fabcoin Core  0.16.2
P2P Digital Currency
keccak.h
Go to the documentation of this file.
1 // keccak.h - written and placed in the public domain by Wei Dai
2 
11 
12 #ifndef CRYPTOPP_KECCAK_H
13 #define CRYPTOPP_KECCAK_H
14 
15 #include "cryptlib.h"
16 #include "secblock.h"
17 
19 
20 class Keccak : public HashTransformation
42 {
43 public:
50  Keccak(unsigned int digestSize) : m_digestSize(digestSize) {Restart();}
51  unsigned int DigestSize() const {return m_digestSize;}
52  std::string AlgorithmName() const {return "Keccak-" + IntToString(m_digestSize*8);}
53  CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "Keccak"; }
54  unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word64>();}
55 
56  void Update(const byte *input, size_t length);
57  void Restart();
58  void TruncatedFinal(byte *hash, size_t size);
59 
60  //unsigned int BlockSize() const { return r(); } // that's the idea behind it
61 
62 protected:
63  inline unsigned int r() const {return 200 - 2 * m_digestSize;}
64 
66  unsigned int m_digestSize, m_counter;
67 };
68 
73 template<unsigned int T_DigestSize>
74 class Keccak_Final : public Keccak
75 {
76 public:
77  CRYPTOPP_CONSTANT(DIGESTSIZE = T_DigestSize)
78  CRYPTOPP_CONSTANT(BLOCKSIZE = 200 - 2 * DIGESTSIZE)
79 
80 
81  Keccak_Final() : Keccak(DIGESTSIZE) {}
82  static std::string StaticAlgorithmName() { return "Keccak-" + IntToString(DIGESTSIZE * 8); }
83  unsigned int BlockSize() const { return BLOCKSIZE; }
84 private:
85  CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
86  CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > (int)T_DigestSize); // this is a general expectation by HMAC
87 };
88 
105 
107 
108 #endif
unsigned int BlockSize() const
Provides the block size of the compression function.
Definition: keccak.h:83
uint8_t byte
Definition: Common.h:57
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: keccak.h:54
#define CRYPTOPP_STATIC_CONSTEXPR
Definition: config.h:892
static std::string StaticAlgorithmName()
Definition: keccak.h:82
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: keccak.h:52
Abstract base classes that provide a uniform interface to this library.
Keccak_Final< 64 > Keccak_512
Definition: keccak.h:104
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: keccak.h:51
Keccak_Final< 28 > Keccak_224
Definition: keccak.h:92
unsigned int r() const
Definition: keccak.h:63
Classes and functions for secure memory allocations.
Keccak(unsigned int digestSize)
Construct a Keccak.
Definition: keccak.h:50
Keccak message digest base class.
Definition: keccak.h:41
#define CRYPTOPP_CONSTANT(x)
Definition: config.h:540
CRYPTOPP_STATIC_CONSTEXPR const char * StaticAlgorithmName()
Definition: keccak.h:53
Keccak_Final< 48 > Keccak_384
Definition: keccak.h:100
FixedSizeSecBlock< word64, 25 > m_state
Definition: keccak.h:65
Keccak_Final< 32 > Keccak_256
Definition: keccak.h:96
unsigned int m_digestSize
Definition: keccak.h:66
uint8_t const size_t const size
Definition: sha3.h:20
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:930
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Definition: misc.h:539
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE< 200)
#define NAMESPACE_END
Definition: config.h:201