1
// eax.cpp - written and placed in the public domain by Wei Dai
6
NAMESPACE_BEGIN(CryptoPP)
8
void EAX_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms)
10
AccessMAC().SetKey(userKey, keylength, params);
11
m_buffer.New(2*AccessMAC().TagSize());
14
void EAX_Base::Resync(const byte *iv, size_t len)
16
MessageAuthenticationCode &mac = AccessMAC();
17
unsigned int blockSize = mac.TagSize();
19
memset(m_buffer, 0, blockSize);
20
mac.Update(m_buffer, blockSize);
21
mac.CalculateDigest(m_buffer+blockSize, iv, len);
23
m_buffer[blockSize-1] = 1;
24
mac.Update(m_buffer, blockSize);
26
m_ctr.SetCipherWithIV(AccessMAC().AccessCipher(), m_buffer+blockSize, blockSize);
29
size_t EAX_Base::AuthenticateBlocks(const byte *data, size_t len)
31
AccessMAC().Update(data, len);
35
void EAX_Base::AuthenticateLastHeaderBlock()
37
assert(m_bufferedDataLength == 0);
38
MessageAuthenticationCode &mac = AccessMAC();
39
unsigned int blockSize = mac.TagSize();
42
xorbuf(m_buffer+blockSize, m_buffer, blockSize);
44
memset(m_buffer, 0, blockSize);
45
m_buffer[blockSize-1] = 2;
46
mac.Update(m_buffer, blockSize);
49
void EAX_Base::AuthenticateLastFooterBlock(byte *tag, size_t macSize)
51
assert(m_bufferedDataLength == 0);
52
MessageAuthenticationCode &mac = AccessMAC();
53
unsigned int blockSize = mac.TagSize();
55
mac.TruncatedFinal(m_buffer, macSize);
56
xorbuf(tag, m_buffer, m_buffer+blockSize, macSize);