From 490d36e65ac24e34e3021c2a0947384aee138c88 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 13 Apr 2016 21:05:14 -0400 Subject: Root commit for new Compass repository This is the Alpha version of ComPASS, originally developed sometime in 2014. --- cryptopp562/hmac.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 cryptopp562/hmac.cpp (limited to 'cryptopp562/hmac.cpp') diff --git a/cryptopp562/hmac.cpp b/cryptopp562/hmac.cpp new file mode 100644 index 0000000..d4a649c --- /dev/null +++ b/cryptopp562/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