1 #ifndef CRYPTOPP_ITERHASH_H
2 #define CRYPTOPP_ITERHASH_H
9 NAMESPACE_BEGIN(CryptoPP)
16 : InvalidDataFormat(
"IteratedHashBase: input data exceeds maximum allowed by hash function " + alg) {}
20 template <
class T,
class BASE>
24 typedef T HashWordType;
27 unsigned int OptimalBlockSize()
const {
return this->BlockSize();}
28 unsigned int OptimalDataAlignment()
const {
return GetAlignmentOf<T>();}
29 void Update(
const byte *input,
size_t length);
30 byte * CreateUpdateSpace(
size_t &size);
32 void TruncatedFinal(byte *digest,
size_t size);
35 inline T GetBitCountHi()
const {
return (m_countLo >> (8*
sizeof(T)-3)) + (m_countHi << 3);}
36 inline T GetBitCountLo()
const {
return m_countLo << 3;}
38 void PadLastBlock(
unsigned int lastBlockSize, byte padFirst=0x80);
39 virtual void Init() =0;
41 virtual ByteOrder GetByteOrder()
const =0;
42 virtual void HashEndianCorrectedBlock(
const HashWordType *data) =0;
43 virtual size_t HashMultipleBlocks(
const T *input,
size_t length);
44 void HashBlock(
const HashWordType *input) {HashMultipleBlocks(input, this->BlockSize());}
46 virtual T* DataBuf() =0;
47 virtual T* StateBuf() =0;
50 T m_countLo, m_countHi;
54 template <
class T_HashWordType,
class T_Endianness,
unsigned int T_BlockSize,
class T_Base = HashTransformation>
58 typedef T_Endianness ByteOrderClass;
59 typedef T_HashWordType HashWordType;
61 CRYPTOPP_CONSTANT(BLOCKSIZE = T_BlockSize)
63 CRYPTOPP_COMPILE_ASSERT((T_BlockSize & (T_BlockSize - 1)) == 0);
64 unsigned int BlockSize()
const {
return T_BlockSize;}
66 ByteOrder GetByteOrder()
const {
return T_Endianness::ToEnum();}
68 inline static void CorrectEndianess(HashWordType *out,
const HashWordType *in,
size_t byteCount)
70 ConditionalByteReverse(T_Endianness::ToEnum(), out, in, byteCount);
74 T_HashWordType* DataBuf() {
return this->m_data;}
79 template <
class T_HashWordType,
class T_Endianness,
unsigned int T_BlockSize,
unsigned int T_StateSize,
class T_Transform,
unsigned int T_DigestSize = 0,
bool T_StateAligned = false>
81 :
public ClonableImpl<T_Transform, AlgorithmImpl<IteratedHash<T_HashWordType, T_Endianness, T_BlockSize>, T_Transform> >
84 CRYPTOPP_CONSTANT(DIGESTSIZE = T_DigestSize ? T_DigestSize : T_StateSize)
85 unsigned int DigestSize()
const {
return DIGESTSIZE;};
89 void HashEndianCorrectedBlock(
const T_HashWordType *data) {T_Transform::Transform(this->m_state, data);}
90 void Init() {T_Transform::InitState(this->m_state);}
92 T_HashWordType* StateBuf() {
return this->m_state;}
a SecBlock with fixed size, allocated statically