5#ifndef CRYPTOPP_IMPORTS
10ANONYMOUS_NAMESPACE_BEGIN
13using CryptoPP::IsPowerOf2;
15void MulU(
byte *k,
unsigned int len)
18 for (
int i=len-1; i>=1; i-=2)
20 byte carry2 = k[i] >> 7;
23 k[i-1] += k[i-1] + carry2;
26#ifndef CRYPTOPP_CMAC_WIDE_BLOCK_CIPHERS
75ANONYMOUS_NAMESPACE_END
82 cipher.
SetKey(key, length, params);
84 unsigned int blockSize = cipher.
BlockSize();
89 MulU(m_reg+blockSize, blockSize);
90 std::memcpy(m_reg+2*blockSize, m_reg+blockSize, blockSize);
91 MulU(m_reg+2*blockSize, blockSize);
101 unsigned int blockSize = cipher.
BlockSize();
105 const unsigned int len =
UnsignedMin(blockSize - m_counter, length);
108 xorbuf(m_reg+m_counter, input, len);
114 if (m_counter == blockSize && length > 0)
121 if (length > blockSize)
125 input += (length - leftOver);
132 xorbuf(m_reg+m_counter, input, length);
133 m_counter += (
unsigned int)length;
141 ThrowIfInvalidTruncatedSize(size);
144 unsigned int blockSize = cipher.
BlockSize();
146 if (m_counter < blockSize)
148 m_reg[m_counter] ^= 0x80;
156 std::memcpy(mac, m_reg, size);
159 std::memset(m_reg, 0, blockSize);
Interface for one direction (encryption or decryption) of a block cipher.
void Update(const byte *input, size_t length)
Updates a hash with additional input.
void TruncatedFinal(byte *mac, size_t size)
Computes the hash of the current message.
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
Sets the key for this object without performing parameter validation.
Interface for retrieving values given their names.
void CleanNew(size_type newSize)
Change size without preserving contents.
virtual void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms=g_nullNameValuePairs)
Sets or reset the key of this object.
Classes for CMAC message authentication code.
Utility functions for the Crypto++ library.
bool IsPowerOf2(const T &value)
Tests whether a value is a power of 2.
const T1 UnsignedMin(const T1 &a, const T2 &b)
Safe comparison of values that could be negative and incorrectly promoted.
CRYPTOPP_DLL void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
Crypto++ library namespace.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.