File indexing completed on 2025-01-18 09:54:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef CRYPTOPP_AUTHENC_H
0021 #define CRYPTOPP_AUTHENC_H
0022
0023 #include "cryptlib.h"
0024 #include "secblock.h"
0025
0026 NAMESPACE_BEGIN(CryptoPP)
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedSymmetricCipherBase : public AuthenticatedSymmetricCipher
0041 {
0042 public:
0043 AuthenticatedSymmetricCipherBase() : m_totalHeaderLength(0), m_totalMessageLength(0),
0044 m_totalFooterLength(0), m_bufferedDataLength(0), m_state(State_Start) {}
0045
0046
0047 bool IsRandomAccess() const {return false;}
0048 bool IsSelfInverting() const {return true;}
0049
0050 void SetKey(const byte *userKey, size_t keylength, const NameValuePairs ¶ms);
0051 void Restart() {if (m_state > State_KeySet) m_state = State_KeySet;}
0052 void Resynchronize(const byte *iv, int length=-1);
0053 void Update(const byte *input, size_t length);
0054 void ProcessData(byte *outString, const byte *inString, size_t length);
0055 void TruncatedFinal(byte *mac, size_t macSize);
0056
0057 protected:
0058 void UncheckedSetKey(const byte * key, unsigned int length,const CryptoPP::NameValuePairs ¶ms)
0059 {CRYPTOPP_UNUSED(key), CRYPTOPP_UNUSED(length), CRYPTOPP_UNUSED(params); CRYPTOPP_ASSERT(false);}
0060
0061 void AuthenticateData(const byte *data, size_t len);
0062 const SymmetricCipher & GetSymmetricCipher() const
0063 {return const_cast<AuthenticatedSymmetricCipherBase *>(this)->AccessSymmetricCipher();}
0064
0065 virtual SymmetricCipher & AccessSymmetricCipher() =0;
0066 virtual bool AuthenticationIsOnPlaintext() const =0;
0067 virtual unsigned int AuthenticationBlockSize() const =0;
0068 virtual void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms) =0;
0069 virtual void Resync(const byte *iv, size_t len) =0;
0070 virtual size_t AuthenticateBlocks(const byte *data, size_t len) =0;
0071 virtual void AuthenticateLastHeaderBlock() =0;
0072 virtual void AuthenticateLastConfidentialBlock() {}
0073 virtual void AuthenticateLastFooterBlock(byte *mac, size_t macSize) =0;
0074
0075
0076
0077 enum State {State_Start, State_KeySet, State_IVSet, State_AuthUntransformed, State_AuthTransformed, State_AuthFooter};
0078
0079 AlignedSecByteBlock m_buffer;
0080 lword m_totalHeaderLength, m_totalMessageLength, m_totalFooterLength;
0081 unsigned int m_bufferedDataLength;
0082 State m_state;
0083 };
0084
0085 NAMESPACE_END
0086
0087 #endif