Fabcoin Core  0.16.2
P2P Digital Currency
cmac.h
Go to the documentation of this file.
1 // cmac.h - written and placed in the public domain by Wei Dai
2 
6 
7 #ifndef CRYPTOPP_CMAC_H
8 #define CRYPTOPP_CMAC_H
9 
10 #include "seckey.h"
11 #include "secblock.h"
12 
14 
19 {
20 public:
21  CMAC_Base() : m_counter(0) {}
22 
23  void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
24  void Update(const byte *input, size_t length);
25  void TruncatedFinal(byte *mac, size_t size);
26  unsigned int DigestSize() const {return GetCipher().BlockSize();}
27  unsigned int OptimalBlockSize() const {return GetCipher().BlockSize();}
28  unsigned int OptimalDataAlignment() const {return GetCipher().OptimalDataAlignment();}
29 
30 protected:
31  friend class EAX_Base;
32 
33  const BlockCipher & GetCipher() const {return const_cast<CMAC_Base*>(this)->AccessCipher();}
34  virtual BlockCipher & AccessCipher() =0;
35 
36  void ProcessBuf();
38  unsigned int m_counter;
39 };
40 
46 template <class T>
47 class CMAC : public MessageAuthenticationCodeImpl<CMAC_Base, CMAC<T> >, public SameKeyLengthAs<T>
48 {
49 public:
51  CMAC() {}
55  CMAC(const byte *key, size_t length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH)
56  {this->SetKey(key, length);}
57 
58  static std::string StaticAlgorithmName() {return std::string("CMAC(") + T::StaticAlgorithmName() + ")";}
59 
60 private:
62  typename T::Encryption m_cipher;
63 };
64 
66 
67 #endif
Interface for message authentication codes.
Definition: cryptlib.h:1111
uint8_t byte
Definition: Common.h:57
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
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
EAX block cipher base implementation.
Definition: eax.h:19
Interface for one direction (encryption or decryption) of a block cipher.
Definition: cryptlib.h:1095
unsigned int m_counter
Definition: cmac.h:38
CMAC message authentication code.
Definition: cmac.h:47
Classes and functions for secure memory allocations.
T::Encryption m_cipher
Definition: cmac.h:62
CMAC()
Construct a CMAC.
Definition: cmac.h:51
CMAC_Base()
Definition: cmac.h:21
Classes and functions for implementing secret key algorithms.
Provides a base implementation of Algorithm and SimpleKeyingInterface for message authentication code...
Definition: seckey.h:370
Provides key lengths based on another class&#39;s key length.
Definition: seckey.h:222
unsigned int OptimalBlockSize() const
Provides the input block size most efficient for this hash.
Definition: cmac.h:27
CMAC(const byte *key, size_t length=SameKeyLengthAs< T >::DEFAULT_KEYLENGTH)
Construct a CMAC.
Definition: cmac.h:55
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: cmac.h:28
#define CRYPTOPP_NO_VTABLE
Definition: config.h:369
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: cmac.h:26
uint8_t const size_t const size
Definition: sha3.h:20
static std::string StaticAlgorithmName()
Definition: cmac.h:58
CMAC base implementation.
Definition: cmac.h:18
const BlockCipher & GetCipher() const
Definition: cmac.h:33
#define NAMESPACE_END
Definition: config.h:201
BlockCipher & AccessCipher()
Definition: cmac.h:61
#define CRYPTOPP_DLL
Definition: config.h:704
SecByteBlock m_reg
Definition: cmac.h:37
Interface for retrieving values given their names.
Definition: cryptlib.h:279