cbcmac.cpp
#include "pch.h"
#ifndef CRYPTOPP_IMPORTS
#include "cbcmac.h"
NAMESPACE_BEGIN(CryptoPP)
void CBC_MAC_Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
{
AccessCipher().SetKey(key, length, params);
m_reg.CleanNew(AccessCipher().BlockSize());
m_counter = 0;
}
void CBC_MAC_Base::Update(const byte *input, size_t length)
{
unsigned int blockSize = AccessCipher().BlockSize();
while (m_counter && length)
{
m_reg[m_counter++] ^= *input++;
if (m_counter == blockSize)
ProcessBuf();
length--;
}
if (length >= blockSize)
{
size_t leftOver = AccessCipher().AdvancedProcessBlocks(m_reg, input, m_reg, length, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput);
input += (length - leftOver);
length = leftOver;
}
while (length--)
{
m_reg[m_counter++] ^= *input++;
if (m_counter == blockSize)
ProcessBuf();
}
}
void CBC_MAC_Base::TruncatedFinal(byte *mac, size_t size)
{
ThrowIfInvalidTruncatedSize(size);
if (m_counter)
ProcessBuf();
memcpy(mac, m_reg, size);
memset(m_reg, 0, AccessCipher().BlockSize());
}
void CBC_MAC_Base::ProcessBuf()
{
AccessCipher().ProcessBlock(m_reg);
m_counter = 0;
}
NAMESPACE_END
#endif
HashTransformation::BlockSize
virtual unsigned int BlockSize() const
Provides the block size of the compression function.
Definition: cryptlib.h:975
SimpleKeyingInterface::SetKey
virtual void SetKey(const byte *key, size_t length, const NameValuePairs &params=g_nullNameValuePairs)
Sets or reset the key of this object.
Definition: cryptlib.cpp:101
BlockTransformation::BT_DontIncrementInOutPointers
should not modify block pointers
Definition: cryptlib.h:789
cbcmac.h
Classes for CBC MAC.
CBC_MAC_Base
_
Definition: cbcmac.h:16
CBC_MAC_Base::TruncatedFinal
void TruncatedFinal(byte *mac, size_t size)
Computes the hash of the current message.
Definition: cbcmac.cpp:43
BlockTransformation::BlockSize
virtual unsigned int BlockSize() const =0
Provides the block size of the cipher.
BlockTransformation::AdvancedProcessBlocks
virtual size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const
Encrypt and xor multiple blocks using additional flags.
Definition: cryptlib.cpp:182
BlockTransformation::ProcessBlock
void ProcessBlock(const byte *inBlock, byte *outBlock) const
Encrypt or decrypt a block.
Definition: cryptlib.h:751
Name::BlockSize
const char * BlockSize()
int, in bytes
Definition: argnames.h:26
CBC_MAC_Base::Update
void Update(const byte *input, size_t length)
Updates a hash with additional input.
Definition: cbcmac.cpp:16
void
CryptoPP
Crypto++ library namespace.
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:277