summaryrefslogtreecommitdiff
path: root/iterhash.cpp
diff options
context:
space:
mode:
authorweidai <weidai11@users.noreply.github.com>2004-07-23 09:57:11 +0000
committerweidai <weidai11@users.noreply.github.com>2004-07-23 09:57:11 +0000
commit6d4f31be8b397f8c3c3ed09c2cab1a5d51d15a93 (patch)
tree28bc00f13c4aa241379c6a2d2276a9a3200c8dff /iterhash.cpp
parent31cf02632fa09c94e44639a1e7de263ff850d962 (diff)
downloadcryptopp-git-6d4f31be8b397f8c3c3ed09c2cab1a5d51d15a93.tar.gz
add SHA-224
Diffstat (limited to 'iterhash.cpp')
-rw-r--r--iterhash.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/iterhash.cpp b/iterhash.cpp
index 33dc9249..a863782a 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 <class T, class BASE> void IteratedHashBase<T, BASE>::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
{