summaryrefslogtreecommitdiff
path: root/iterhash.cpp
diff options
context:
space:
mode:
authorweidai <weidai11@users.noreply.github.com>2004-09-03 10:57:31 +0000
committerweidai <weidai11@users.noreply.github.com>2004-09-03 10:57:31 +0000
commitc39b3de3c4fe55214f4d689797e39f037901f964 (patch)
tree19dad58c2b6f0728c0598cc5b120e9846d289b19 /iterhash.cpp
parentbfd8ad2f1fc1652d3ccabcbeb4cb94147cad63ff (diff)
downloadcryptopp-git-c39b3de3c4fe55214f4d689797e39f037901f964.tar.gz
changes related to the next FIPS validation
Diffstat (limited to 'iterhash.cpp')
-rw-r--r--iterhash.cpp33
1 files changed, 27 insertions, 6 deletions
diff --git a/iterhash.cpp b/iterhash.cpp
index a863782a..3e01556f 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