Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | 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 class CRYPTOPP_DLL CBC_MAC_Base : public MessageAuthenticationCode
00010 {
00011 public:
00012         CBC_MAC_Base() {}
00013 
00014         void CheckedSetKey(void *, Empty empty, const byte *key, unsigned int length, const NameValuePairs &params);
00015         void Update(const byte *input, unsigned int length);
00016         void TruncatedFinal(byte *mac, unsigned int size);
00017         unsigned int DigestSize() const {return const_cast<CBC_MAC_Base*>(this)->AccessCipher().BlockSize();}
00018 
00019 protected:
00020         virtual BlockCipher & AccessCipher() =0;
00021 
00022 private:
00023         void ProcessBuf();
00024         SecByteBlock m_reg;
00025         unsigned int m_counter;
00026 };
00027 
00028 //! <a href="http://www.weidai.com/scan-mirror/mac.html#CBC-MAC">CBC-MAC</a>
00029 /*! Compatible with FIPS 113. T should be an encryption class.
00030         Secure only for fixed length messages. For variable length
00031         messages use DMAC.
00032 */
00033 template <class T>
00034 class CBC_MAC : public MessageAuthenticationCodeFinalTemplate<CBC_MAC_Base, CBC_MAC<T> >, public SameKeyLengthAs<T>
00035 {
00036 public:
00037         CBC_MAC() {}
00038         CBC_MAC(const byte *key, unsigned int length=DEFAULT_KEYLENGTH)
00039                 {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 Tue Jul 8 23:34:10 2003 for Crypto++ by doxygen 1.3.2