4 Star 5 Fork 4

Gitee 极速下载/cryptopp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/weidai11/cryptopp
克隆/下载
hmac.cpp 2.00 KB
一键复制 编辑 原始数据 按行查看 历史
// hmac.cpp - originally 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)
{
// hmac.cpp:26:9: runtime error: null pointer passed as argument 2
if (AccessIpad() && userKey && keylength)
std::memcpy(AccessIpad(), userKey, keylength);
}
else
{
AccessHash().CalculateDigest(AccessIpad(), userKey, keylength);
keylength = hash.DigestSize();
}
CRYPTOPP_ASSERT(keylength <= blockSize);
std::memset(AccessIpad()+keylength, 0, blockSize-keylength);
for (unsigned int i=0; i<blockSize; i++)
{
AccessOpad()[i] = AccessIpad()[i] ^ 0x5c;
AccessIpad()[i] ^= 0x36;
}
}
void HMAC_Base::KeyInnerHash()
{
CRYPTOPP_ASSERT(!m_innerHashKeyed);
HashTransformation &hash = AccessHash();
hash.Update(AccessIpad(), hash.BlockSize());
m_innerHashKeyed = true;
}
void HMAC_Base::Restart()
{
if (m_innerHashKeyed)
{
AccessHash().Restart();
m_innerHashKeyed = false;
}
}
void HMAC_Base::Update(const byte *input, size_t length)
{
if (!m_innerHashKeyed)
KeyInnerHash();
AccessHash().Update(input, length);
}
void HMAC_Base::TruncatedFinal(byte *mac, size_t size)
{
ThrowIfInvalidTruncatedSize(size);
HashTransformation &hash = AccessHash();
if (!m_innerHashKeyed)
KeyInnerHash();
hash.Final(AccessInnerHash());
hash.Update(AccessOpad(), hash.BlockSize());
hash.Update(AccessInnerHash(), hash.DigestSize());
hash.TruncatedFinal(mac, size);
m_innerHashKeyed = false;
}
NAMESPACE_END
#endif
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/cryptopp.git
git@gitee.com:mirrors/cryptopp.git
mirrors
cryptopp
cryptopp
master

搜索帮助