Crypto++  5.6.3
Free C++ class library of cryptographic schemes
authenc.h
Go to the documentation of this file.
1 // authenc.h - written and placed in the public domain by Wei Dai
2 
3 //! \file
4 //! \headerfile authenc.h
5 //! \brief Base classes for working with authenticated encryption modes of encryption
6 
7 #ifndef CRYPTOPP_AUTHENC_H
8 #define CRYPTOPP_AUTHENC_H
9 
10 #include "cryptlib.h"
11 #include "secblock.h"
12 
13 NAMESPACE_BEGIN(CryptoPP)
14 
15 //! \class AuthenticatedSymmetricCipherBase
16 //! \brief Base implementation for one direction (encryption or decryption) of a stream cipher or block cipher mode with authentication
17 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedSymmetricCipherBase : public AuthenticatedSymmetricCipher
18 {
19 public:
20  AuthenticatedSymmetricCipherBase() : m_state(State_Start), m_bufferedDataLength(0),
21  m_totalHeaderLength(0), m_totalMessageLength(0), m_totalFooterLength(0) {}
22 
23  bool IsRandomAccess() const {return false;}
24  bool IsSelfInverting() const {return true;}
25 
26  //! \brief Sets the key for this object without performing parameter validation
27  //! \param key a byte buffer used to key the cipher
28  //! \param length the length of the byte buffer
29  //! \param params additional parameters passed as NameValuePairs
30  //! \details key must be at least DEFAULT_KEYLENGTH in length.
31  void UncheckedSetKey(const byte * key, unsigned int length,const CryptoPP::NameValuePairs &params)
32  {CRYPTOPP_UNUSED(key), CRYPTOPP_UNUSED(length), CRYPTOPP_UNUSED(params); assert(false);}
33 
34  void SetKey(const byte *userKey, size_t keylength, const NameValuePairs &params);
35  void Restart() {if (m_state > State_KeySet) m_state = State_KeySet;}
36  void Resynchronize(const byte *iv, int length=-1);
37  void Update(const byte *input, size_t length);
38  void ProcessData(byte *outString, const byte *inString, size_t length);
39  void TruncatedFinal(byte *mac, size_t macSize);
40 
41 protected:
42  void AuthenticateData(const byte *data, size_t len);
43  const SymmetricCipher & GetSymmetricCipher() const {return const_cast<AuthenticatedSymmetricCipherBase *>(this)->AccessSymmetricCipher();};
44 
45  virtual SymmetricCipher & AccessSymmetricCipher() =0;
46  virtual bool AuthenticationIsOnPlaintext() const =0;
47  virtual unsigned int AuthenticationBlockSize() const =0;
48  virtual void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs &params) =0;
49  virtual void Resync(const byte *iv, size_t len) =0;
50  virtual size_t AuthenticateBlocks(const byte *data, size_t len) =0;
51  virtual void AuthenticateLastHeaderBlock() =0;
52  virtual void AuthenticateLastConfidentialBlock() {}
53  virtual void AuthenticateLastFooterBlock(byte *mac, size_t macSize) =0;
54 
55  enum State {State_Start, State_KeySet, State_IVSet, State_AuthUntransformed, State_AuthTransformed, State_AuthFooter};
56  State m_state;
57  unsigned int m_bufferedDataLength;
58  lword m_totalHeaderLength, m_totalMessageLength, m_totalFooterLength;
59  AlignedSecByteBlock m_buffer;
60 };
61 
62 NAMESPACE_END
63 
64 #endif
Interface for one direction (encryption or decryption) of a stream cipher or block cipher mode with a...
Definition: cryptlib.h:1117
void UncheckedSetKey(const byte *key, unsigned int length, const ::NameValuePairs &params)
Sets the key for this object without performing parameter validation.
Definition: authenc.h:31
Abstract base classes that provide a uniform interface to this library.
bool IsRandomAccess() const
Determines whether the cipher supports random access.
Definition: authenc.h:23
void Restart()
Restart the hash.
Definition: authenc.h:35
Classes and functions for secure memory allocations.
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...
Definition: cryptlib.h:1099
Base implementation for one direction (encryption or decryption) of a stream cipher or block cipher m...
Definition: authenc.h:17
SecBlock using AllocatorWithCleanup typedef.
Definition: secblock.h:736
bool IsSelfInverting() const
Determines whether the cipher is self-inverting.
Definition: authenc.h:24
Crypto++ library namespace.
Interface for retrieving values given their names.
Definition: cryptlib.h:277