Crypto++
8.4
Free C++ class library of cryptographic schemes
|
Go to the documentation of this file.
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);
virtual void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms=g_nullNameValuePairs)
Sets or reset the key of this object.
unsigned char byte
8-bit unsigned datatype
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
DMAC message authentication code base class.
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.
void TruncatedFinal(byte *mac, size_t size)
Computes the hash of the current message.
Provides key lengths based on another class's key length.
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.
Crypto++ library namespace.
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
Sets the key for this object without performing parameter validation.
Interface for message authentication codes.
virtual std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Provides class member functions to key a message authentication code.
Interface for retrieving values given their names.
DMAC message authentication code.