7 #ifndef CRYPTOPP_DMAC_H 8 #define CRYPTOPP_DMAC_H 19 static std::string StaticAlgorithmName() {
return std::string(
"DMAC(") + T::StaticAlgorithmName() +
")";}
21 CRYPTOPP_CONSTANT(DIGESTSIZE=T::BLOCKSIZE)
23 DMAC_Base() : m_subkeylength(0), m_counter(0) {}
25 void UncheckedSetKey(
const byte *key,
unsigned int length,
const NameValuePairs ¶ms);
26 void Update(
const byte *input,
size_t length);
27 void TruncatedFinal(byte *mac,
size_t size);
31 byte *GenerateSubKeys(
const byte *key,
size_t keylength);
33 size_t m_subkeylength;
36 typename T::Encryption m_f2;
37 unsigned int m_counter;
50 {this->
SetKey(key, length);}
56 m_subkeylength = T::StaticGetValidKeyLength(T::BLOCKSIZE);
57 m_subkeys.resize(2*
UnsignedMin((
unsigned int)T::BLOCKSIZE, m_subkeylength));
58 m_mac1.SetKey(GenerateSubKeys(key, length), m_subkeylength, params);
59 m_f2.SetKey(m_subkeys+m_subkeys.size()/2, m_subkeylength, params);
67 m_mac1.Update(input, length);
68 m_counter = (
unsigned int)((m_counter + length) % T::BLOCKSIZE);
74 ThrowIfInvalidTruncatedSize(size);
76 byte pad[T::BLOCKSIZE];
77 byte padByte = byte(T::BLOCKSIZE-m_counter);
78 memset(pad, padByte, padByte);
79 m_mac1.Update(pad, padByte);
80 m_mac1.TruncatedFinal(mac, size);
81 m_f2.ProcessBlock(mac);
89 typename T::Encryption cipher(key, keylength);
90 memset(m_subkeys, 0, m_subkeys.size());
91 cipher.ProcessBlock(m_subkeys);
92 m_subkeys[m_subkeys.size()/2 + T::BLOCKSIZE - 1] = 1;
93 cipher.ProcessBlock(m_subkeys+m_subkeys.size()/2);
void TruncatedFinal(byte *mac, size_t size)
Computes the hash of the current message.
Interface for message authentication codes.
virtual void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms=g_nullNameValuePairs)
Sets or reset the key of this object.
Provides class member functions to key a message authentication code.
SecByteBlock is a SecBlock<byte> typedef.
void Update(const byte *input, size_t length)
Updates a hash with additional input.
const T1 UnsignedMin(const T1 &a, const T2 &b)
Safe comparison of values that could be neagtive and incorrectly promoted.
Provides key lengths based on another class's key length.
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
Sets the key for this object without performing parameter validation.
unsigned int DigestSize() const
Provides the digest size of the hash.
Crypto++ library namespace.
Interface for retrieving values given their names.