eax.cpp
// eax.cpp - originally written and placed in the public domain by Wei Dai
#include "pch.h"
#include "eax.h"
NAMESPACE_BEGIN(CryptoPP)
void EAX_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs &params)
{
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();
std::memset(m_buffer, 0, blockSize);
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()
{
CRYPTOPP_ASSERT(m_bufferedDataLength == 0);
MessageAuthenticationCode &mac = AccessMAC();
const unsigned int blockSize = mac.TagSize();
mac.Final(m_buffer);
xorbuf(m_buffer+blockSize, m_buffer, blockSize);
std::memset(m_buffer, 0, blockSize);
m_buffer[blockSize-1] = 2;
mac.Update(m_buffer, blockSize);
}
void EAX_Base::AuthenticateLastFooterBlock(byte *tag, size_t macSize)
{
CRYPTOPP_ASSERT(m_bufferedDataLength == 0);
MessageAuthenticationCode &mac = AccessMAC();
unsigned int blockSize = mac.TagSize();
mac.TruncatedFinal(m_buffer, macSize);
xorbuf(tag, m_buffer, m_buffer+blockSize, macSize);
}
NAMESPACE_END
CMAC_Base::Update
void Update(const byte *input, size_t length)
Updates a hash with additional input.
CipherModeBase::SetCipherWithIV
void SetCipherWithIV(BlockCipher &cipher, const byte *iv, int feedbackSize=0)
Set external block cipher and IV.
Definition modes.h:117
HashTransformation::TruncatedFinal
virtual void TruncatedFinal(byte *digest, size_t digestSize)=0
Computes the hash of the current message.
HashTransformation::Final
virtual void Final(byte *digest)
Computes the hash of the current message.
Definition cryptlib.h:1147
HashTransformation::Update
virtual void Update(const byte *input, size_t length)=0
Updates a hash with additional input.
HashTransformation::TagSize
unsigned int TagSize() const
Provides the tag size of the hash.
Definition cryptlib.h:1162
HashTransformation::CalculateDigest
virtual void CalculateDigest(byte *digest, const byte *input, size_t length)
Updates the hash with additional input and computes the hash of the current message.
Definition cryptlib.h:1193
MessageAuthenticationCode
Interface for message authentication codes.
Definition cryptlib.h:1304
NameValuePairs
Interface for retrieving values given their names.
Definition cryptlib.h:327
SimpleKeyingInterface::SetKey
virtual void SetKey(const byte *key, size_t length, const NameValuePairs &params=g_nullNameValuePairs)
Sets or reset the key of this object.
eax.h
EAX block cipher mode of operation.
xorbuf
CRYPTOPP_DLL void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
CryptoPP
Crypto++ library namespace.
pch.h
Precompiled header file.
CRYPTOPP_ASSERT
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Definition trap.h:68