Crypto++
authenc.h
1 #ifndef CRYPTOPP_AUTHENC_H
2 #define CRYPTOPP_AUTHENC_H
3 
4 #include "cryptlib.h"
5 #include "secblock.h"
6 
7 NAMESPACE_BEGIN(CryptoPP)
8 
9 //! .
10 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedSymmetricCipherBase : public AuthenticatedSymmetricCipher
11 {
12 public:
13  AuthenticatedSymmetricCipherBase() : m_state(State_Start) {}
14 
15  bool IsRandomAccess() const {return false;}
16  bool IsSelfInverting() const {return true;}
17  void UncheckedSetKey(const byte *,unsigned int,const CryptoPP::NameValuePairs &) {assert(false);}
18 
19  void SetKey(const byte *userKey, size_t keylength, const NameValuePairs &params);
20  void Restart() {if (m_state > State_KeySet) m_state = State_KeySet;}
21  void Resynchronize(const byte *iv, int length=-1);
22  void Update(const byte *input, size_t length);
23  void ProcessData(byte *outString, const byte *inString, size_t length);
24  void TruncatedFinal(byte *mac, size_t macSize);
25 
26 protected:
27  void AuthenticateData(const byte *data, size_t len);
28  const SymmetricCipher & GetSymmetricCipher() const {return const_cast<AuthenticatedSymmetricCipherBase *>(this)->AccessSymmetricCipher();};
29 
30  virtual SymmetricCipher & AccessSymmetricCipher() =0;
31  virtual bool AuthenticationIsOnPlaintext() const =0;
32  virtual unsigned int AuthenticationBlockSize() const =0;
33  virtual void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs &params) =0;
34  virtual void Resync(const byte *iv, size_t len) =0;
35  virtual size_t AuthenticateBlocks(const byte *data, size_t len) =0;
36  virtual void AuthenticateLastHeaderBlock() =0;
37  virtual void AuthenticateLastConfidentialBlock() {}
38  virtual void AuthenticateLastFooterBlock(byte *mac, size_t macSize) =0;
39 
40  enum State {State_Start, State_KeySet, State_IVSet, State_AuthUntransformed, State_AuthTransformed, State_AuthFooter};
41  State m_state;
42  unsigned int m_bufferedDataLength;
43  lword m_totalHeaderLength, m_totalMessageLength, m_totalFooterLength;
44  AlignedSecByteBlock m_buffer;
45 };
46 
47 NAMESPACE_END
48 
49 #endif
interface for for one direction (encryption or decryption) of a stream cipher or block cipher mode wi...
Definition: cryptlib.h:626
bool IsRandomAccess() const
returns whether this cipher supports random access
Definition: authenc.h:15
void Restart()
discard the current state, and restart with a new message
Definition: authenc.h:20
interface for one direction (encryption or decryption) of a stream cipher or cipher mode ...
Definition: cryptlib.h:610
bool IsSelfInverting() const
returns whether this transformation is self-inverting (e.g. xor with a keystream) ...
Definition: authenc.h:16
interface for retrieving values given their names
Definition: cryptlib.h:224