24
24
typedef T HashWordType;
26
26
IteratedHashBase() : m_countLo(0), m_countHi(0) {}
27
unsigned int BlockSize() const {return (unsigned int)m_data.size() * sizeof(T);}
28
unsigned int OptimalBlockSize() const {return BlockSize();}
29
unsigned int OptimalDataAlignment() const {return sizeof(T);}
27
unsigned int OptimalBlockSize() const {return this->BlockSize();}
28
unsigned int OptimalDataAlignment() const {return GetAlignmentOf<T>();}
30
29
void Update(const byte *input, size_t length);
31
30
byte * CreateUpdateSpace(size_t &size);
33
32
void TruncatedFinal(byte *digest, size_t size);
36
void SetBlockSize(unsigned int blockSize) {m_data.resize(blockSize / sizeof(HashWordType));}
37
void SetStateSize(unsigned int stateSize) {m_digest.resize(stateSize / sizeof(HashWordType));}
39
T GetBitCountHi() const {return (m_countLo >> (8*sizeof(T)-3)) + (m_countHi << 3);}
40
T GetBitCountLo() const {return m_countLo << 3;}
35
inline T GetBitCountHi() const {return (m_countLo >> (8*sizeof(T)-3)) + (m_countHi << 3);}
36
inline T GetBitCountLo() const {return m_countLo << 3;}
42
38
void PadLastBlock(unsigned int lastBlockSize, byte padFirst=0x80);
43
39
virtual void Init() =0;
45
41
virtual ByteOrder GetByteOrder() const =0;
46
42
virtual void HashEndianCorrectedBlock(const HashWordType *data) =0;
47
43
virtual size_t HashMultipleBlocks(const T *input, size_t length);
48
void HashBlock(const HashWordType *input) {HashMultipleBlocks(input, BlockSize());}
44
void HashBlock(const HashWordType *input) {HashMultipleBlocks(input, this->BlockSize());}
50
SecBlock<T> m_data; // Data buffer
51
SecBlock<T> m_digest; // Message digest
46
virtual T* DataBuf() =0;
47
virtual T* StateBuf() =0;
54
50
T m_countLo, m_countHi;
62
58
typedef T_Endianness ByteOrderClass;
63
59
typedef T_HashWordType HashWordType;
65
enum {BLOCKSIZE = T_BlockSize};
66
CRYPTOPP_COMPILE_ASSERT((BLOCKSIZE & (BLOCKSIZE - 1)) == 0); // blockSize is a power of 2
61
CRYPTOPP_CONSTANT(BLOCKSIZE = T_BlockSize)
62
// BCB2006 workaround: can't use BLOCKSIZE here
63
CRYPTOPP_COMPILE_ASSERT((T_BlockSize & (T_BlockSize - 1)) == 0); // blockSize is a power of 2
64
unsigned int BlockSize() const {return T_BlockSize;}
68
66
ByteOrder GetByteOrder() const {return T_Endianness::ToEnum();}
76
IteratedHash() {this->SetBlockSize(T_BlockSize);}
74
T_HashWordType* DataBuf() {return this->m_data;}
75
FixedSizeSecBlock<T_HashWordType, T_BlockSize/sizeof(T_HashWordType)> m_data;
80
template <class T_HashWordType, class T_Endianness, unsigned int T_BlockSize, unsigned int T_StateSize, class T_Transform, unsigned int T_DigestSize = T_StateSize>
79
template <class T_HashWordType, class T_Endianness, unsigned int T_BlockSize, unsigned int T_StateSize, class T_Transform, unsigned int T_DigestSize = 0>
81
80
class CRYPTOPP_NO_VTABLE IteratedHashWithStaticTransform
82
81
: public ClonableImpl<T_Transform, AlgorithmImpl<IteratedHash<T_HashWordType, T_Endianness, T_BlockSize>, T_Transform> >
85
enum {DIGESTSIZE = T_DigestSize};
84
CRYPTOPP_CONSTANT(DIGESTSIZE = T_DigestSize ? T_DigestSize : T_StateSize)
86
85
unsigned int DigestSize() const {return DIGESTSIZE;};
89
IteratedHashWithStaticTransform()
91
this->SetStateSize(T_StateSize);
94
void HashEndianCorrectedBlock(const T_HashWordType *data) {T_Transform::Transform(this->m_digest, data);}
95
void Init() {T_Transform::InitState(this->m_digest);}
88
IteratedHashWithStaticTransform() {this->Init();}
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;}
93
FixedSizeSecBlock<T_HashWordType, T_BlockSize/sizeof(T_HashWordType)> m_state;