Crypto++
cmac.h
1 #ifndef CRYPTOPP_CMAC_H
2 #define CRYPTOPP_CMAC_H
3 
4 #include "seckey.h"
5 #include "secblock.h"
6 
7 NAMESPACE_BEGIN(CryptoPP)
8 
9 //! _
10 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CMAC_Base : public MessageAuthenticationCode
11 {
12 public:
13  CMAC_Base() {}
14 
15  void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
16  void Update(const byte *input, size_t length);
17  void TruncatedFinal(byte *mac, size_t size);
18  unsigned int DigestSize() const {return GetCipher().BlockSize();}
19  unsigned int OptimalBlockSize() const {return GetCipher().BlockSize();}
20  unsigned int OptimalDataAlignment() const {return GetCipher().OptimalDataAlignment();}
21 
22 protected:
23  friend class EAX_Base;
24 
25  const BlockCipher & GetCipher() const {return const_cast<CMAC_Base*>(this)->AccessCipher();}
26  virtual BlockCipher & AccessCipher() =0;
27 
28  void ProcessBuf();
29  SecByteBlock m_reg;
30  unsigned int m_counter;
31 };
32 
33 /// <a href="http://www.cryptolounge.org/wiki/CMAC">CMAC</a>
34 /*! Template parameter T should be a class derived from BlockCipherDocumentation, for example AES, with a block size of 8, 16, or 32 */
35 template <class T>
36 class CMAC : public MessageAuthenticationCodeImpl<CMAC_Base, CMAC<T> >, public SameKeyLengthAs<T>
37 {
38 public:
39  CMAC() {}
40  CMAC(const byte *key, size_t length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH)
41  {this->SetKey(key, length);}
42 
43  static std::string StaticAlgorithmName() {return std::string("CMAC(") + T::StaticAlgorithmName() + ")";}
44 
45 private:
46  BlockCipher & AccessCipher() {return m_cipher;}
47  typename T::Encryption m_cipher;
48 };
49 
50 NAMESPACE_END
51 
52 #endif
interface for message authentication codes
Definition: cryptlib.h:617
virtual void SetKey(const byte *key, size_t length, const NameValuePairs &params=g_nullNameValuePairs)
set or reset the key of this object
Definition: eax.h:11
interface for one direction (encryption or decryption) of a block cipher
Definition: cryptlib.h:603
CMAC
Definition: cmac.h:36
support query of key length that's the same as another class
Definition: seckey.h:114
unsigned int OptimalBlockSize() const
input to Update() should have length a multiple of this for optimal speed
Definition: cmac.h:19
unsigned int OptimalDataAlignment() const
returns how input should be aligned for optimal performance
Definition: cmac.h:20
unsigned int DigestSize() const
size of the hash/digest/MAC returned by Final()
Definition: cmac.h:18
_
Definition: cmac.h:10
interface for retrieving values given their names
Definition: cryptlib.h:224