- 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 CheckedSetKey(void *, Empty empty, const byte *key, size_t 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
    00032         messages use DMAC.
    00033 */
    00034 template <class T>
    00035 class CBC_MAC : public MessageAuthenticationCodeImpl<CBC_MAC_Base, CBC_MAC<T> >, public SameKeyLengthAs<T>
    00036 {
    00037 public:
    00038         CBC_MAC() {}
    00039         CBC_MAC(const byte *key, size_t length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH)
    00040                 {this->SetKey(key, length);}
    00041
    00042         static std::string StaticAlgorithmName() {return std::string("CBC-MAC(") + T::StaticAlgorithmName() + ")";}
    00043
    00044 private:
    00045         BlockCipher & AccessCipher() {return m_cipher;}
    00046         typename T::Encryption m_cipher;
    00047 };
    00048
    00049 NAMESPACE_END
    00050
    00051 #endif