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
27 CRYPTOPP_ASSERT(len == 16);
36 CRYPTOPP_ASSERT(len >= 8);
37 CRYPTOPP_ASSERT(len <= 128);
75ANONYMOUS_NAMESPACE_END
77NAMESPACE_BEGIN(CryptoPP)
82 cipher.
SetKey(key, length, params);
84 unsigned int blockSize = cipher.
BlockSize();
85 m_reg.CleanNew(3*blockSize);
89 MulU(m_reg+blockSize, blockSize);
90 memcpy(m_reg+2*blockSize, m_reg+blockSize, blockSize);
91 MulU(m_reg+2*blockSize, blockSize);
96 CRYPTOPP_ASSERT((input && length) || !(input || length));
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)
123 CRYPTOPP_ASSERT(m_counter == 0);
125 input += (length - leftOver);
131 CRYPTOPP_ASSERT(m_counter + length <= blockSize);
132 xorbuf(m_reg+m_counter, input, length);
133 m_counter += (
unsigned int)length;
136 CRYPTOPP_ASSERT(m_counter > 0);
144 unsigned int blockSize = cipher.
BlockSize();
146 if (m_counter < blockSize)
148 m_reg[m_counter] ^= 0x80;
156 memcpy(mac, m_reg, size);
159 memset(m_reg, 0, blockSize);
Interface for one direction (encryption or decryption) of a block cipher.
CMAC base implementation.
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.
Interface for retrieving values given their names.
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.