Fabcoin Core  0.16.2
P2P Digital Currency
hmac.h
Go to the documentation of this file.
1 // hmac.h - written and placed in the public domain by Wei Dai
2 
5 
6 #ifndef CRYPTOPP_HMAC_H
7 #define CRYPTOPP_HMAC_H
8 
9 #include "seckey.h"
10 #include "secblock.h"
11 
13 
18 {
19 public:
21  HMAC_Base() : m_innerHashKeyed(false) {}
22  void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &params);
23 
24  void Restart();
25  void Update(const byte *input, size_t length);
26  void TruncatedFinal(byte *mac, size_t size);
27  unsigned int OptimalBlockSize() const {return const_cast<HMAC_Base*>(this)->AccessHash().OptimalBlockSize();}
28  unsigned int DigestSize() const {return const_cast<HMAC_Base*>(this)->AccessHash().DigestSize();}
29 
30 protected:
31  virtual HashTransformation & AccessHash() =0;
32  byte * AccessIpad() {return m_buf;}
33  byte * AccessOpad() {return m_buf + AccessHash().BlockSize();}
34  byte * AccessInnerHash() {return m_buf + 2*AccessHash().BlockSize();}
35 
36 private:
37  void KeyInnerHash();
38 
41 };
42 
49 template <class T>
50 class HMAC : public MessageAuthenticationCodeImpl<HMAC_Base, HMAC<T> >
51 {
52 public:
53  CRYPTOPP_CONSTANT(DIGESTSIZE=T::DIGESTSIZE)
54  CRYPTOPP_CONSTANT(BLOCKSIZE=T::BLOCKSIZE)
55 
56 
57  HMAC() {}
61  HMAC(const byte *key, size_t length=HMAC_Base::DEFAULT_KEYLENGTH)
62  {this->SetKey(key, length);}
63 
64  static std::string StaticAlgorithmName() {return std::string("HMAC(") + T::StaticAlgorithmName() + ")";}
65  std::string AlgorithmName() const {return std::string("HMAC(") + m_hash.AlgorithmName() + ")";}
66 
67 private:
69 
71 };
72 
74 
75 #endif
Interface for message authentication codes.
Definition: cryptlib.h:1111
uint8_t byte
Definition: Common.h:57
HMAC_Base()
Construct a HMAC_Base.
Definition: hmac.h:21
virtual void SetKey(const byte *key, size_t length, const NameValuePairs &params=g_nullNameValuePairs)
Sets or reset the key of this object.
Definition: cryptlib.cpp:97
static std::string StaticAlgorithmName()
Definition: hmac.h:64
#define T(i, x)
byte * AccessOpad()
Definition: hmac.h:33
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
T m_hash
Definition: hmac.h:70
Classes and functions for secure memory allocations.
byte * AccessInnerHash()
Definition: hmac.h:34
HMAC information.
Definition: hmac.h:17
HashTransformation & AccessHash()
Definition: hmac.h:68
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: hmac.h:28
Classes and functions for implementing secret key algorithms.
HMAC(const byte *key, size_t length=HMAC_Base::DEFAULT_KEYLENGTH)
Construct a HMAC.
Definition: hmac.h:61
Provides a base implementation of Algorithm and SimpleKeyingInterface for message authentication code...
Definition: seckey.h:370
SecByteBlock m_buf
Definition: hmac.h:39
#define CRYPTOPP_CONSTANT(x)
Definition: config.h:540
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:169
#define CRYPTOPP_NO_VTABLE
Definition: config.h:369
bool m_innerHashKeyed
Definition: hmac.h:40
HMAC.
Definition: hmac.h:50
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
byte * AccessIpad()
Definition: hmac.h:32
#define NAMESPACE_END
Definition: config.h:201
#define CRYPTOPP_DLL
Definition: config.h:704
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: hmac.h:65
Interface for retrieving values given their names.
Definition: cryptlib.h:279
unsigned int OptimalBlockSize() const
Provides the input block size most efficient for this hash.
Definition: hmac.h:27