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);
32 byte *GenerateSubKeys(
const byte *key,
size_t keylength);
34 size_t m_subkeylength;
37 typename T::Encryption m_f2;
38 unsigned int m_counter;
57 {this->SetKey(key, length);}
63 m_subkeylength = T::StaticGetValidKeyLength(T::BLOCKSIZE);
64 m_subkeys.resize(2*
UnsignedMin((
unsigned int)T::BLOCKSIZE, m_subkeylength));
65 m_mac1.SetKey(GenerateSubKeys(key, length), m_subkeylength, params);
66 m_f2.SetKey(m_subkeys+m_subkeys.size()/2, m_subkeylength, params);
74 m_mac1.Update(input, length);
75 m_counter = (
unsigned int)((m_counter + length) % T::BLOCKSIZE);
81 ThrowIfInvalidTruncatedSize(size);
83 byte pad[T::BLOCKSIZE];
84 byte padByte = byte(T::BLOCKSIZE-m_counter);
85 memset(pad, padByte, padByte);
86 m_mac1.Update(pad, padByte);
87 m_mac1.TruncatedFinal(mac, size);
88 m_f2.ProcessBlock(mac);
96 typename T::Encryption cipher(key, keylength);
97 memset(m_subkeys, 0, m_subkeys.size());
98 cipher.ProcessBlock(m_subkeys);
99 m_subkeys[m_subkeys.size()/2 + T::BLOCKSIZE - 1] = 1;
100 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.
DMAC message authentication code.
DMAC message authentication code base class.
Provides class member functions to key a message authentication code.
unsigned int DigestSize() const
Provides the digest size of the hash.
DMAC(const byte *key, size_t length=DMAC_Base< T >::DEFAULT_KEYLENGTH)
Construct a DMAC.
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.
Crypto++ library namespace.
Interface for retrieving values given their names.