Crypto++
cbcmac.h
1 #ifndef CRYPTOPP_CBCMAC_H
2 #define CRYPTOPP_CBCMAC_H
3 
4 #include "seckey.h"
5 #include "secblock.h"
6 
7 NAMESPACE_BEGIN(CryptoPP)
8 
9 //! _
10 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_MAC_Base : public MessageAuthenticationCode
11 {
12 public:
13  CBC_MAC_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 const_cast<CBC_MAC_Base*>(this)->AccessCipher().BlockSize();}
19 
20 protected:
21  virtual BlockCipher & AccessCipher() =0;
22 
23 private:
24  void ProcessBuf();
25  SecByteBlock m_reg;
26  unsigned int m_counter;
27 };
28 
29 //! <a href="http://www.weidai.com/scan-mirror/mac.html#CBC-MAC">CBC-MAC</a>
30 /*! Compatible with FIPS 113. T should be a class derived from BlockCipherDocumentation.
31  Secure only for fixed length messages. For variable length messages use CMAC or DMAC.
32 */
33 template <class T>
34 class CBC_MAC : public MessageAuthenticationCodeImpl<CBC_MAC_Base, CBC_MAC<T> >, public SameKeyLengthAs<T>
35 {
36 public:
37  CBC_MAC() {}
38  CBC_MAC(const byte *key, size_t length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH)
39  {this->SetKey(key, length);}
40 
41  static std::string StaticAlgorithmName() {return std::string("CBC-MAC(") + T::StaticAlgorithmName() + ")";}
42 
43 private:
44  BlockCipher & AccessCipher() {return m_cipher;}
45  typename T::Encryption m_cipher;
46 };
47 
48 NAMESPACE_END
49 
50 #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
unsigned int DigestSize() const
size of the hash/digest/MAC returned by Final()
Definition: cbcmac.h:18
interface for one direction (encryption or decryption) of a block cipher
Definition: cryptlib.h:603
virtual unsigned int BlockSize() const
block size of underlying compression function, or 0 if not block based
Definition: cryptlib.h:559
support query of key length that's the same as another class
Definition: seckey.h:114
CBC-MAC
Definition: cbcmac.h:34
interface for retrieving values given their names
Definition: cryptlib.h:224