diff options
author | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2004-09-03 10:57:31 +0000 |
---|---|---|
committer | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2004-09-03 10:57:31 +0000 |
commit | 65ea2d1cb9f91b81127142551d0f4098583ede73 (patch) | |
tree | 19dad58c2b6f0728c0598cc5b120e9846d289b19 /iterhash.cpp | |
parent | bf7ce9baa84e06a5bf001e55db1111c1050e2cfc (diff) | |
download | cryptopp-65ea2d1cb9f91b81127142551d0f4098583ede73.tar.gz |
changes related to the next FIPS validation
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@193 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'iterhash.cpp')
-rw-r--r-- | iterhash.cpp | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/iterhash.cpp b/iterhash.cpp index a863782..3e01556 100644 --- a/iterhash.cpp +++ b/iterhash.cpp @@ -6,11 +6,6 @@ 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 oldCountLo = m_countLo, oldCountHi = m_countHi; @@ -80,9 +75,17 @@ template <class T, class BASE> byte * IteratedHashBase<T, BASE>::CreateUpdateSpa template <class T, class BASE> unsigned int IteratedHashBase<T, BASE>::HashMultipleBlocks(const T *input, unsigned int length) { unsigned int blockSize = BlockSize(); + bool noReverse = NativeByteOrderIs(GetByteOrder()); do { - HashBlock(input); + if (noReverse) + HashEndianCorrectedBlock(input); + else + { + ByteReverse(this->m_data.begin(), input, this->BlockSize()); + HashEndianCorrectedBlock(this->m_data); + } + input += blockSize/sizeof(T); length -= blockSize; } @@ -111,4 +114,22 @@ template <class T, class BASE> void IteratedHashBase<T, BASE>::Restart() Init(); } +template <class T, class BASE> void IteratedHashBase<T, BASE>::TruncatedFinal(byte *digest, unsigned int size) +{ + this->ThrowIfInvalidTruncatedSize(size); + + PadLastBlock(this->BlockSize() - 2*sizeof(HashWordType)); + ByteOrder order = this->GetByteOrder(); + ConditionalByteReverse<HashWordType>(order, this->m_data, this->m_data, this->BlockSize() - 2*sizeof(HashWordType)); + + this->m_data[this->m_data.size()-2] = order ? this->GetBitCountHi() : this->GetBitCountLo(); + this->m_data[this->m_data.size()-1] = order ? this->GetBitCountLo() : this->GetBitCountHi(); + + HashEndianCorrectedBlock(this->m_data); + ConditionalByteReverse<HashWordType>(order, this->m_digest, this->m_digest, this->DigestSize()); + memcpy(digest, this->m_digest, size); + + this->Restart(); // reinit for next use +} + NAMESPACE_END |