From 65ea2d1cb9f91b81127142551d0f4098583ede73 Mon Sep 17 00:00:00 2001 From: weidai Date: Fri, 3 Sep 2004 10:57:31 +0000 Subject: 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 --- iterhash.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'iterhash.cpp') 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 void IteratedHashBase::Update(const byte *input, unsigned int len) { HashWordType oldCountLo = m_countLo, oldCountHi = m_countHi; @@ -80,9 +75,17 @@ template byte * IteratedHashBase::CreateUpdateSpa template unsigned int IteratedHashBase::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 void IteratedHashBase::Restart() Init(); } +template void IteratedHashBase::TruncatedFinal(byte *digest, unsigned int size) +{ + this->ThrowIfInvalidTruncatedSize(size); + + PadLastBlock(this->BlockSize() - 2*sizeof(HashWordType)); + ByteOrder order = this->GetByteOrder(); + ConditionalByteReverse(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(order, this->m_digest, this->m_digest, this->DigestSize()); + memcpy(digest, this->m_digest, size); + + this->Restart(); // reinit for next use +} + NAMESPACE_END -- cgit v1.2.1