Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.2 KiB

  1. // authenc.h - written and placed in the public domain by Wei Dai
  2. //! \file
  3. //! \headerfile authenc.h
  4. //! \brief Base classes for working with authenticated encryption modes of encryption
  5. #ifndef CRYPTOPP_AUTHENC_H
  6. #define CRYPTOPP_AUTHENC_H
  7. #include "cryptlib.h"
  8. #include "secblock.h"
  9. NAMESPACE_BEGIN(CryptoPP)
  10. //! \class AuthenticatedSymmetricCipherBase
  11. //! \brief
  12. class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedSymmetricCipherBase : public AuthenticatedSymmetricCipher
  13. {
  14. public:
  15. AuthenticatedSymmetricCipherBase() : m_state(State_Start), m_bufferedDataLength(0),
  16. m_totalHeaderLength(0), m_totalMessageLength(0), m_totalFooterLength(0) {}
  17. bool IsRandomAccess() const {return false;}
  18. bool IsSelfInverting() const {return true;}
  19. void UncheckedSetKey(const byte *,unsigned int,const CryptoPP::NameValuePairs &) {assert(false);}
  20. void SetKey(const byte *userKey, size_t keylength, const NameValuePairs &params);
  21. void Restart() {if (m_state > State_KeySet) m_state = State_KeySet;}
  22. void Resynchronize(const byte *iv, int length=-1);
  23. void Update(const byte *input, size_t length);
  24. void ProcessData(byte *outString, const byte *inString, size_t length);
  25. void TruncatedFinal(byte *mac, size_t macSize);
  26. protected:
  27. void AuthenticateData(const byte *data, size_t len);
  28. const SymmetricCipher & GetSymmetricCipher() const {return const_cast<AuthenticatedSymmetricCipherBase *>(this)->AccessSymmetricCipher();};
  29. virtual SymmetricCipher & AccessSymmetricCipher() =0;
  30. virtual bool AuthenticationIsOnPlaintext() const =0;
  31. virtual unsigned int AuthenticationBlockSize() const =0;
  32. virtual void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs &params) =0;
  33. virtual void Resync(const byte *iv, size_t len) =0;
  34. virtual size_t AuthenticateBlocks(const byte *data, size_t len) =0;
  35. virtual void AuthenticateLastHeaderBlock() =0;
  36. virtual void AuthenticateLastConfidentialBlock() {}
  37. virtual void AuthenticateLastFooterBlock(byte *mac, size_t macSize) =0;
  38. enum State {State_Start, State_KeySet, State_IVSet, State_AuthUntransformed, State_AuthTransformed, State_AuthFooter};
  39. State m_state;
  40. unsigned int m_bufferedDataLength;
  41. lword m_totalHeaderLength, m_totalMessageLength, m_totalFooterLength;
  42. AlignedSecByteBlock m_buffer;
  43. };
  44. NAMESPACE_END
  45. #endif