412
by weidai
changes for 5.6: |
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 ¶ms); |
|
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 ¶ms) =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; |
|
423
by weidai
- add EAX mode, XSalsa20 |
37 |
virtual void AuthenticateLastConfidentialBlock() {} |
412
by weidai
changes for 5.6: |
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
|