From fa4774e7d94e01b1f97c2126821544aec8e001a4 Mon Sep 17 00:00:00 2001 From: weidai Date: Fri, 23 Jul 2004 09:57:11 +0000 Subject: add SHA-224 git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@191 57ff6487-cd31-0410-9ec3-f628ee90f5f0 --- iterhash.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'iterhash.cpp') diff --git a/iterhash.cpp b/iterhash.cpp index 33dc924..a863782 100644 --- a/iterhash.cpp +++ b/iterhash.cpp @@ -6,15 +6,22 @@ NAMESPACE_BEGIN(CryptoPP) +HashInputTooLong::HashInputTooLong(const std::string &alg) + : InvalidDataFormat("IteratedHashBase: input data exceeds maximum allowed by hash function " + alg) +{ +} + template void IteratedHashBase::Update(const byte *input, unsigned int len) { - HashWordType tmp = m_countLo; - if ((m_countLo = tmp + len) < tmp) + HashWordType oldCountLo = m_countLo, oldCountHi = m_countHi; + if ((m_countLo = oldCountLo + len) < oldCountLo) m_countHi++; // carry from low to high m_countHi += SafeRightShift<8*sizeof(HashWordType)>(len); + if (m_countHi < oldCountHi) + throw HashInputTooLong(AlgorithmName()); unsigned int blockSize = BlockSize(); - unsigned int num = ModPowerOf2(tmp, blockSize); + unsigned int num = ModPowerOf2(oldCountLo, blockSize); if (num != 0) // process left over data { -- cgit v1.2.1