6 #ifndef CRYPTOPP_DMAC_H
7 #define CRYPTOPP_DMAC_H
20 CRYPTOPP_CONSTANT(DIGESTSIZE=T::BLOCKSIZE);
21 static std::string StaticAlgorithmName() {
return std::string(
"DMAC(") + T::StaticAlgorithmName() +
")";}
24 DMAC_Base() : m_subkeylength(0), m_counter(0) {}
26 void UncheckedSetKey(
const byte *key,
unsigned int length,
const NameValuePairs ¶ms);
27 void Update(
const byte *input,
size_t length);
34 byte *GenerateSubKeys(
const byte *key,
size_t keylength);
36 size_t m_subkeylength;
39 typename T::Encryption m_f2;
40 unsigned int m_counter;
46 return m_f2.AlgorithmProvider();
65 {this->
SetKey(key, length);}
71 m_subkeylength = T::StaticGetValidKeyLength(T::BLOCKSIZE);
72 m_subkeys.resize(2*
UnsignedMin((
unsigned int)T::BLOCKSIZE, m_subkeylength));
73 m_mac1.SetKey(GenerateSubKeys(key, length), m_subkeylength, params);
74 m_f2.SetKey(m_subkeys+m_subkeys.size()/2, m_subkeylength, params);
82 m_mac1.Update(input, length);
83 m_counter = (
unsigned int)((m_counter + length) % T::BLOCKSIZE);
89 ThrowIfInvalidTruncatedSize(size);
91 byte pad[T::BLOCKSIZE];
92 byte padByte = byte(T::BLOCKSIZE-m_counter);
93 memset(pad, padByte, padByte);
94 m_mac1.Update(pad, padByte);
95 m_mac1.TruncatedFinal(mac, size);
96 m_f2.ProcessBlock(mac);
104 typename T::Encryption cipher(key, keylength);
105 memset(m_subkeys, 0, m_subkeys.size());
106 cipher.ProcessBlock(m_subkeys);
107 m_subkeys[m_subkeys.size()/2 + T::BLOCKSIZE - 1] = 1;
108 cipher.ProcessBlock(m_subkeys+m_subkeys.size()/2);