Security Scol plugin
authenc.h
Go to the documentation of this file.
1// authenc.h - originally written and placed in the public domain by Wei Dai
2
19
20#ifndef CRYPTOPP_AUTHENC_H
21#define CRYPTOPP_AUTHENC_H
22
23#include "cryptlib.h"
24#include "secblock.h"
25
26NAMESPACE_BEGIN(CryptoPP)
27
28
40class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedSymmetricCipherBase : public AuthenticatedSymmetricCipher
41{
42public:
43 AuthenticatedSymmetricCipherBase() : m_totalHeaderLength(0), m_totalMessageLength(0),
44 m_totalFooterLength(0), m_bufferedDataLength(0), m_state(State_Start) {}
45
46 // StreamTransformation interface
47 bool IsRandomAccess() const {return false;}
48 bool IsSelfInverting() const {return true;}
49
50 void SetKey(const byte *userKey, size_t keylength, const NameValuePairs &params);
51 void Restart() {if (m_state > State_KeySet) m_state = State_KeySet;}
52 void Resynchronize(const byte *iv, int length=-1);
53 void Update(const byte *input, size_t length);
54 void ProcessData(byte *outString, const byte *inString, size_t length);
55 void TruncatedFinal(byte *mac, size_t macSize);
56
57protected:
58 void UncheckedSetKey(const byte * key, unsigned int length,const CryptoPP::NameValuePairs &params)
59 {CRYPTOPP_UNUSED(key), CRYPTOPP_UNUSED(length), CRYPTOPP_UNUSED(params); CRYPTOPP_ASSERT(false);}
60
61 void AuthenticateData(const byte *data, size_t len);
62 const SymmetricCipher & GetSymmetricCipher() const
63 {return const_cast<AuthenticatedSymmetricCipherBase *>(this)->AccessSymmetricCipher();}
64
65 virtual SymmetricCipher & AccessSymmetricCipher() =0;
66 virtual bool AuthenticationIsOnPlaintext() const =0;
67 virtual unsigned int AuthenticationBlockSize() const =0;
68 virtual void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs &params) =0;
69 virtual void Resync(const byte *iv, size_t len) =0;
70 virtual size_t AuthenticateBlocks(const byte *data, size_t len) =0;
71 virtual void AuthenticateLastHeaderBlock() =0;
72 virtual void AuthenticateLastConfidentialBlock() {}
73 virtual void AuthenticateLastFooterBlock(byte *mac, size_t macSize) =0;
74
75 // State_AuthUntransformed: authentication is applied to plain text (Authenticate-then-Encrypt)
76 // State_AuthTransformed: authentication is applied to cipher text (Encrypt-then-Authenticate)
77 enum State {State_Start, State_KeySet, State_IVSet, State_AuthUntransformed, State_AuthTransformed, State_AuthFooter};
78
79 AlignedSecByteBlock m_buffer;
80 lword m_totalHeaderLength, m_totalMessageLength, m_totalFooterLength;
81 unsigned int m_bufferedDataLength;
82 State m_state;
83};
84
85NAMESPACE_END
86
87#endif
Base class for authenticated encryption modes of operation.
Definition authenc.h:41
bool IsRandomAccess() const
Determines whether the cipher supports random access.
Definition authenc.h:47
bool IsSelfInverting() const
Determines whether the cipher is self-inverting.
Definition authenc.h:48
void Restart()
Restart the hash.
Definition authenc.h:51
Interface for authenticated encryption modes of operation.
Definition cryptlib.h:1321
Interface for retrieving values given their names.
Definition cryptlib.h:322
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode.
Definition cryptlib.h:1291
word64 lword
Large word type.
Definition config_int.h:158
Abstract base classes that provide a uniform interface to this library.
Classes and functions for secure memory allocations.