From 30e9097985656920f01a72efc1088caa2b8d41b3 Mon Sep 17 00:00:00 2001 From: bertagaz Date: Tue, 14 Jun 2011 15:26:19 +0200 Subject: Imported Upstream version 0.5.29 --- embeddedcryptopp/hmac.cpp | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 embeddedcryptopp/hmac.cpp (limited to 'embeddedcryptopp/hmac.cpp') diff --git a/embeddedcryptopp/hmac.cpp b/embeddedcryptopp/hmac.cpp new file mode 100644 index 0000000..d4a649c --- /dev/null +++ b/embeddedcryptopp/hmac.cpp @@ -0,0 +1,86 @@ +// hmac.cpp - written and placed in the public domain by Wei Dai + +#include "pch.h" + +#ifndef CRYPTOPP_IMPORTS + +#include "hmac.h" + +NAMESPACE_BEGIN(CryptoPP) + +void HMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &) +{ + AssertValidKeyLength(keylength); + + Restart(); + + HashTransformation &hash = AccessHash(); + unsigned int blockSize = hash.BlockSize(); + + if (!blockSize) + throw InvalidArgument("HMAC: can only be used with a block-based hash function"); + + m_buf.resize(2*AccessHash().BlockSize() + AccessHash().DigestSize()); + + if (keylength <= blockSize) + memcpy(AccessIpad(), userKey, keylength); + else + { + AccessHash().CalculateDigest(AccessIpad(), userKey, keylength); + keylength = hash.DigestSize(); + } + + assert(keylength <= blockSize); + memset(AccessIpad()+keylength, 0, blockSize-keylength); + + for (unsigned int i=0; i