• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

cbcmac.h

00001 #ifndef CRYPTOPP_CBCMAC_H
00002 #define CRYPTOPP_CBCMAC_H
00003 
00004 #include "seckey.h"
00005 #include "secblock.h"
00006 
00007 NAMESPACE_BEGIN(CryptoPP)
00008 
00009 //! _
00010 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_MAC_Base : public MessageAuthenticationCode
00011 {
00012 public:
00013         CBC_MAC_Base() {}
00014 
00015         void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
00016         void Update(const byte *input, size_t length);
00017         void TruncatedFinal(byte *mac, size_t size);
00018         unsigned int DigestSize() const {return const_cast<CBC_MAC_Base*>(this)->AccessCipher().BlockSize();}
00019 
00020 protected:
00021         virtual BlockCipher & AccessCipher() =0;
00022 
00023 private:
00024         void ProcessBuf();
00025         SecByteBlock m_reg;
00026         unsigned int m_counter;
00027 };
00028 
00029 //! <a href="http://www.weidai.com/scan-mirror/mac.html#CBC-MAC">CBC-MAC</a>
00030 /*! Compatible with FIPS 113. T should be a class derived from BlockCipherDocumentation.
00031         Secure only for fixed length messages. For variable length messages use CMAC or DMAC.
00032 */
00033 template <class T>
00034 class CBC_MAC : public MessageAuthenticationCodeImpl<CBC_MAC_Base, CBC_MAC<T> >, public SameKeyLengthAs<T>
00035 {
00036 public:
00037         CBC_MAC() {}
00038         CBC_MAC(const byte *key, size_t length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH)
00039                 {this->SetKey(key, length);}
00040 
00041         static std::string StaticAlgorithmName() {return std::string("CBC-MAC(") + T::StaticAlgorithmName() + ")";}
00042 
00043 private:
00044         BlockCipher & AccessCipher() {return m_cipher;}
00045         typename T::Encryption m_cipher;
00046 };
00047 
00048 NAMESPACE_END
00049 
00050 #endif

Generated on Mon Aug 9 2010 15:56:33 for Crypto++ by  doxygen 1.7.1