5#ifndef CRYPTOPP_IMPORTS
9NAMESPACE_BEGIN(CryptoPP)
13 AssertValidKeyLength(keylength);
18 unsigned int blockSize = hash.
BlockSize();
21 throw InvalidArgument(
"HMAC: can only be used with a block-based hash function");
23 m_buf.resize(2*AccessHash().BlockSize() + AccessHash().DigestSize());
25 if (keylength <= blockSize)
28 if (AccessIpad() && userKey && keylength)
29 memcpy(AccessIpad(), userKey, keylength);
33 AccessHash().CalculateDigest(AccessIpad(), userKey, keylength);
37 CRYPTOPP_ASSERT(keylength <= blockSize);
38 memset(AccessIpad()+keylength, 0, blockSize-keylength);
40 for (
unsigned int i=0; i<blockSize; i++)
42 AccessOpad()[i] = AccessIpad()[i] ^ 0x5c;
43 AccessIpad()[i] ^= 0x36;
47void HMAC_Base::KeyInnerHash()
49 CRYPTOPP_ASSERT(!m_innerHashKeyed);
52 m_innerHashKeyed =
true;
60 m_innerHashKeyed =
false;
66 if (!m_innerHashKeyed)
68 AccessHash().
Update(input, length);
77 if (!m_innerHashKeyed)
79 hash.
Final(AccessInnerHash());
85 m_innerHashKeyed =
false;
void TruncatedFinal(byte *mac, size_t size)
Computes the hash of the current message.
void Restart()
Restart the hash.
void Update(const byte *input, size_t length)
Updates a hash with additional input.
An invalid argument was detected.
Interface for retrieving values given their names.
Classes for HMAC message authentication codes.