00001
00002
00003
00004
00005
00006
00007 #ifndef CRYPTOPP_AUTHENC_H
00008 #define CRYPTOPP_AUTHENC_H
00009
00010 #include "cryptlib.h"
00011 #include "secblock.h"
00012
00013 NAMESPACE_BEGIN(CryptoPP)
00014
00015
00016
00017 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedSymmetricCipherBase : public AuthenticatedSymmetricCipher
00018 {
00019 public:
00020 AuthenticatedSymmetricCipherBase() : m_state(State_Start), m_bufferedDataLength(0),
00021 m_totalHeaderLength(0), m_totalMessageLength(0), m_totalFooterLength(0) {}
00022
00023 bool IsRandomAccess() const {return false;}
00024 bool IsSelfInverting() const {return true;}
00025 void UncheckedSetKey(const byte *,unsigned int,const CryptoPP::NameValuePairs &) {assert(false);}
00026
00027 void SetKey(const byte *userKey, size_t keylength, const NameValuePairs ¶ms);
00028 void Restart() {if (m_state > State_KeySet) m_state = State_KeySet;}
00029 void Resynchronize(const byte *iv, int length=-1);
00030 void Update(const byte *input, size_t length);
00031 void ProcessData(byte *outString, const byte *inString, size_t length);
00032 void TruncatedFinal(byte *mac, size_t macSize);
00033
00034 protected:
00035 void AuthenticateData(const byte *data, size_t len);
00036 const SymmetricCipher & GetSymmetricCipher() const {return const_cast<AuthenticatedSymmetricCipherBase *>(this)->AccessSymmetricCipher();};
00037
00038 virtual SymmetricCipher & AccessSymmetricCipher() =0;
00039 virtual bool AuthenticationIsOnPlaintext() const =0;
00040 virtual unsigned int AuthenticationBlockSize() const =0;
00041 virtual void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms) =0;
00042 virtual void Resync(const byte *iv, size_t len) =0;
00043 virtual size_t AuthenticateBlocks(const byte *data, size_t len) =0;
00044 virtual void AuthenticateLastHeaderBlock() =0;
00045 virtual void AuthenticateLastConfidentialBlock() {}
00046 virtual void AuthenticateLastFooterBlock(byte *mac, size_t macSize) =0;
00047
00048 enum State {State_Start, State_KeySet, State_IVSet, State_AuthUntransformed, State_AuthTransformed, State_AuthFooter};
00049 State m_state;
00050 unsigned int m_bufferedDataLength;
00051 lword m_totalHeaderLength, m_totalMessageLength, m_totalFooterLength;
00052 AlignedSecByteBlock m_buffer;
00053 };
00054
00055 NAMESPACE_END
00056
00057 #endif