2017-01-27 12:05:45 +00:00
|
|
|
// eax.cpp - originally written and placed in the public domain by Wei Dai
|
2009-03-12 11:24:12 +00:00
|
|
|
|
|
|
|
#include "pch.h"
|
|
|
|
#include "eax.h"
|
|
|
|
|
|
|
|
NAMESPACE_BEGIN(CryptoPP)
|
|
|
|
|
|
|
|
void EAX_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms)
|
|
|
|
{
|
|
|
|
AccessMAC().SetKey(userKey, keylength, params);
|
|
|
|
m_buffer.New(2*AccessMAC().TagSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
void EAX_Base::Resync(const byte *iv, size_t len)
|
|
|
|
{
|
|
|
|
MessageAuthenticationCode &mac = AccessMAC();
|
|
|
|
unsigned int blockSize = mac.TagSize();
|
|
|
|
|
2023-04-15 20:45:02 +00:00
|
|
|
std::memset(m_buffer, 0, blockSize);
|
2009-03-12 11:24:12 +00:00
|
|
|
mac.Update(m_buffer, blockSize);
|
|
|
|
mac.CalculateDigest(m_buffer+blockSize, iv, len);
|
|
|
|
|
|
|
|
m_buffer[blockSize-1] = 1;
|
|
|
|
mac.Update(m_buffer, blockSize);
|
|
|
|
|
|
|
|
m_ctr.SetCipherWithIV(AccessMAC().AccessCipher(), m_buffer+blockSize, blockSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t EAX_Base::AuthenticateBlocks(const byte *data, size_t len)
|
|
|
|
{
|
|
|
|
AccessMAC().Update(data, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EAX_Base::AuthenticateLastHeaderBlock()
|
|
|
|
{
|
2016-09-16 15:27:15 +00:00
|
|
|
CRYPTOPP_ASSERT(m_bufferedDataLength == 0);
|
2009-03-12 11:24:12 +00:00
|
|
|
MessageAuthenticationCode &mac = AccessMAC();
|
2017-09-30 10:19:28 +00:00
|
|
|
const unsigned int blockSize = mac.TagSize();
|
2009-03-12 11:24:12 +00:00
|
|
|
|
|
|
|
mac.Final(m_buffer);
|
|
|
|
xorbuf(m_buffer+blockSize, m_buffer, blockSize);
|
|
|
|
|
2023-04-15 20:45:02 +00:00
|
|
|
std::memset(m_buffer, 0, blockSize);
|
2009-03-12 11:24:12 +00:00
|
|
|
m_buffer[blockSize-1] = 2;
|
|
|
|
mac.Update(m_buffer, blockSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EAX_Base::AuthenticateLastFooterBlock(byte *tag, size_t macSize)
|
|
|
|
{
|
2016-09-16 15:27:15 +00:00
|
|
|
CRYPTOPP_ASSERT(m_bufferedDataLength == 0);
|
2009-03-12 11:24:12 +00:00
|
|
|
MessageAuthenticationCode &mac = AccessMAC();
|
|
|
|
unsigned int blockSize = mac.TagSize();
|
|
|
|
|
|
|
|
mac.TruncatedFinal(m_buffer, macSize);
|
|
|
|
xorbuf(tag, m_buffer, m_buffer+blockSize, macSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
NAMESPACE_END
|