summaryrefslogtreecommitdiff
path: root/iterhash.cpp
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2004-07-23 09:57:11 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2004-07-23 09:57:11 +0000
commitfa4774e7d94e01b1f97c2126821544aec8e001a4 (patch)
tree28bc00f13c4aa241379c6a2d2276a9a3200c8dff /iterhash.cpp
parent4d4ca69d28e47cbb81e39135471e1b4f3e477e4d (diff)
downloadcryptopp-fa4774e7d94e01b1f97c2126821544aec8e001a4.tar.gz
add SHA-224
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@191 57ff6487-cd31-0410-9ec3-f628ee90f5f0
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 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 <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
{