summaryrefslogtreecommitdiff
path: root/iterhash.h
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2004-09-03 10:57:31 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2004-09-03 10:57:31 +0000
commit65ea2d1cb9f91b81127142551d0f4098583ede73 (patch)
tree19dad58c2b6f0728c0598cc5b120e9846d289b19 /iterhash.h
parentbf7ce9baa84e06a5bf001e55db1111c1050e2cfc (diff)
downloadcryptopp-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.h')
-rw-r--r--iterhash.h73
1 files changed, 19 insertions, 54 deletions
diff --git a/iterhash.h b/iterhash.h
index 899a89f..4453c82 100644
--- a/iterhash.h
+++ b/iterhash.h
@@ -12,7 +12,8 @@ NAMESPACE_BEGIN(CryptoPP)
class CRYPTOPP_DLL HashInputTooLong : public InvalidDataFormat
{
public:
- explicit HashInputTooLong(const std::string &alg);
+ explicit HashInputTooLong(const std::string &alg)
+ : InvalidDataFormat("IteratedHashBase: input data exceeds maximum allowed by hash function " + alg) {}
};
//! _
@@ -29,6 +30,7 @@ public:
void Update(const byte *input, unsigned int length);
byte * CreateUpdateSpace(unsigned int &size);
void Restart();
+ void TruncatedFinal(byte *digest, unsigned int size);
protected:
void SetBlockSize(unsigned int blockSize) {m_data.resize(blockSize / sizeof(HashWordType));}
@@ -37,10 +39,13 @@ protected:
T GetBitCountHi() const {return (m_countLo >> (8*sizeof(T)-3)) + (m_countHi << 3);}
T GetBitCountLo() const {return m_countLo << 3;}
- virtual unsigned int HashMultipleBlocks(const T *input, unsigned int length);
void PadLastBlock(unsigned int lastBlockSize, byte padFirst=0x80);
virtual void Init() =0;
- virtual void HashBlock(const T *input) =0;
+
+ virtual ByteOrder GetByteOrder() const =0;
+ virtual void HashEndianCorrectedBlock(const HashWordType *data) =0;
+ virtual unsigned int HashMultipleBlocks(const T *input, unsigned int length);
+ void HashBlock(const HashWordType *input) {HashMultipleBlocks(input, BlockSize());}
SecBlock<T> m_data; // Data buffer
SecBlock<T> m_digest; // Message digest
@@ -50,7 +55,7 @@ private:
};
#ifdef WORD64_AVAILABLE
-CRYPTOPP_STATIC_TEMPLATE_CLASS IteratedHashBase<word64, HashTransformation>;
+CRYPTOPP_DLL_TEMPLATE_CLASS IteratedHashBase<word64, HashTransformation>;
CRYPTOPP_STATIC_TEMPLATE_CLASS IteratedHashBase<word64, MessageAuthenticationCode>;
#endif
@@ -58,33 +63,23 @@ CRYPTOPP_DLL_TEMPLATE_CLASS IteratedHashBase<word32, HashTransformation>;
CRYPTOPP_STATIC_TEMPLATE_CLASS IteratedHashBase<word32, MessageAuthenticationCode>;
//! _
-template <class T, class B, class BASE>
-class CRYPTOPP_NO_VTABLE IteratedHashBase2 : public IteratedHashBase<T, BASE>
+template <class T_HashWordType, class T_Endianness, unsigned int T_BlockSize, class T_Base = HashTransformation>
+class CRYPTOPP_NO_VTABLE IteratedHash : public IteratedHashBase<T_HashWordType, T_Base>
{
public:
- typedef B ByteOrderClass;
- typedef typename IteratedHashBase<T, BASE>::HashWordType HashWordType;
+ typedef T_Endianness ByteOrderClass;
+ typedef T_HashWordType HashWordType;
+
+ enum {BLOCKSIZE = T_BlockSize};
+ CRYPTOPP_COMPILE_ASSERT((BLOCKSIZE & (BLOCKSIZE - 1)) == 0); // blockSize is a power of 2
+
+ ByteOrder GetByteOrder() const {return T_Endianness::ToEnum();}
inline static void CorrectEndianess(HashWordType *out, const HashWordType *in, unsigned int byteCount)
{
- ConditionalByteReverse(B::ToEnum(), out, in, byteCount);
+ ConditionalByteReverse(T_Endianness::ToEnum(), out, in, byteCount);
}
- void TruncatedFinal(byte *digest, unsigned int size);
-
-protected:
- void HashBlock(const HashWordType *input);
- virtual void HashEndianCorrectedBlock(const HashWordType *data) =0;
-};
-
-//! _
-template <class T_HashWordType, class T_Endianness, unsigned int T_BlockSize, class T_Base = HashTransformation>
-class CRYPTOPP_NO_VTABLE IteratedHash : public IteratedHashBase2<T_HashWordType, T_Endianness, T_Base>
-{
-public:
- enum {BLOCKSIZE = T_BlockSize};
- CRYPTOPP_COMPILE_ASSERT((BLOCKSIZE & (BLOCKSIZE - 1)) == 0); // blockSize is a power of 2
-
protected:
IteratedHash() {this->SetBlockSize(T_BlockSize);}
};
@@ -108,36 +103,6 @@ protected:
void Init() {T_Transform::InitState(this->m_digest);}
};
-// *************************************************************
-
-template <class T, class B, class BASE> void IteratedHashBase2<T, B, BASE>::TruncatedFinal(byte *digest, unsigned int size)
-{
- this->ThrowIfInvalidTruncatedSize(size);
-
- PadLastBlock(this->BlockSize() - 2*sizeof(HashWordType));
- CorrectEndianess(this->m_data, this->m_data, this->BlockSize() - 2*sizeof(HashWordType));
-
- this->m_data[this->m_data.size()-2] = B::ToEnum() ? this->GetBitCountHi() : this->GetBitCountLo();
- this->m_data[this->m_data.size()-1] = B::ToEnum() ? this->GetBitCountLo() : this->GetBitCountHi();
-
- HashEndianCorrectedBlock(this->m_data);
- CorrectEndianess(this->m_digest, this->m_digest, this->DigestSize());
- memcpy(digest, this->m_digest, size);
-
- this->Restart(); // reinit for next use
-}
-
-template <class T, class B, class BASE> void IteratedHashBase2<T, B, BASE>::HashBlock(const HashWordType *input)
-{
- if (NativeByteOrderIs(B::ToEnum()))
- HashEndianCorrectedBlock(input);
- else
- {
- ByteReverse(this->m_data.begin(), input, this->BlockSize());
- HashEndianCorrectedBlock(this->m_data);
- }
-}
-
NAMESPACE_END
#endif