1 #ifndef CRYPTOPP_DMAC_H
2 #define CRYPTOPP_DMAC_H
6 NAMESPACE_BEGIN(CryptoPP)
13 static std::string StaticAlgorithmName() {
return std::string(
"DMAC(") + T::StaticAlgorithmName() +
")";}
15 CRYPTOPP_CONSTANT(DIGESTSIZE=T::BLOCKSIZE)
19 void UncheckedSetKey(
const byte *key,
unsigned int length,
const NameValuePairs ¶ms);
20 void Update(
const byte *input,
size_t length);
21 void TruncatedFinal(byte *mac,
size_t size);
25 byte *GenerateSubKeys(
const byte *key,
size_t keylength);
27 size_t m_subkeylength;
30 typename T::Encryption m_f2;
31 unsigned int m_counter;
44 {this->
SetKey(key, length);}
50 m_subkeylength = T::StaticGetValidKeyLength(T::BLOCKSIZE);
51 m_subkeys.resize(2*UnsignedMin((
unsigned int)T::BLOCKSIZE, m_subkeylength));
52 m_mac1.SetKey(GenerateSubKeys(key, length), m_subkeylength, params);
53 m_f2.SetKey(m_subkeys+m_subkeys.size()/2, m_subkeylength, params);
61 m_mac1.Update(input, length);
62 m_counter = (
unsigned int)((m_counter + length) % T::BLOCKSIZE);
68 ThrowIfInvalidTruncatedSize(size);
70 byte pad[T::BLOCKSIZE];
71 byte padByte = byte(T::BLOCKSIZE-m_counter);
72 memset(pad, padByte, padByte);
73 m_mac1.Update(pad, padByte);
74 m_mac1.TruncatedFinal(mac, size);
75 m_f2.ProcessBlock(mac);
83 typename T::Encryption cipher(key, keylength);
84 memset(m_subkeys, 0, m_subkeys.size());
85 cipher.ProcessBlock(m_subkeys);
86 m_subkeys[m_subkeys.size()/2 + T::BLOCKSIZE - 1] = 1;
87 cipher.ProcessBlock(m_subkeys+m_subkeys.size()/2);
void TruncatedFinal(byte *mac, size_t size)
truncated version of Final()
interface for message authentication codes
virtual void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms=g_nullNameValuePairs)
set or reset the key of this object
void Update(const byte *input, size_t length)
process more input
support query of key length that's the same as another class
unsigned int DigestSize() const
size of the hash/digest/MAC returned by Final()
interface for retrieving values given their names