11NAMESPACE_BEGIN(CryptoPP)
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) {}
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);
virtual std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
DMAC message authentication code base class.
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
Sets the key for this object without performing parameter validation.
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
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.
unsigned int DigestSize() const
DMAC message authentication code.
DMAC(const byte *key, size_t length=DMAC_Base< T >::DEFAULT_KEYLENGTH)
Construct a DMAC.
Provides class member functions to key a message authentication code.
Interface for message authentication codes.
Interface for retrieving values given their names.
Provides key lengths based on another class's key length.
virtual void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)=0
Sets the key for this object without performing parameter validation.
unsigned char byte
8-bit unsigned datatype
const T1 UnsignedMin(const T1 &a, const T2 &b)
Safe comparison of values that could be negative and incorrectly promoted.