4 #define CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES 12 template <class T, class BASE>
void IteratedHashBase<T, BASE>::Update(const byte *input,
size_t len)
14 HashWordType oldCountLo = m_countLo, oldCountHi = m_countHi;
15 if ((m_countLo = oldCountLo + HashWordType(len)) < oldCountLo)
17 m_countHi += (HashWordType)SafeRightShift<8*
sizeof(HashWordType)>(len);
18 if (m_countHi < oldCountHi || SafeRightShift<2*8*
sizeof(HashWordType)>(len) != 0)
21 const unsigned int blockSize = this->
BlockSize();
22 unsigned int num =
ModPowerOf2(oldCountLo, blockSize);
24 T* dataBuf = this->DataBuf();
25 byte* data = (byte *)dataBuf;
26 assert(dataBuf && data);
30 if (num+len >= blockSize)
32 if (data && input) {memcpy(data+num, input, blockSize-num);}
34 input += (blockSize-num);
35 len -= (blockSize-num);
41 if (data && input && len) {memcpy(data+num, input, len);}
51 assert(len == blockSize);
55 else if (IsAligned<T>(input))
57 size_t leftOver = HashMultipleBlocks((T *)input, len);
58 input += (len - leftOver);
64 if (data && input) memcpy(data, input, blockSize);
68 }
while (len >= blockSize);
71 if (data && input && len && data != input)
72 memcpy(data, input, len);
77 unsigned int blockSize = this->
BlockSize();
78 unsigned int num =
ModPowerOf2(m_countLo, blockSize);
79 size = blockSize - num;
80 return (byte *)DataBuf() + num;
85 unsigned int blockSize = this->
BlockSize();
87 T* dataBuf = this->DataBuf();
91 this->HashEndianCorrectedBlock(input);
95 this->HashEndianCorrectedBlock(dataBuf);
98 input += blockSize/
sizeof(T);
101 while (length >= blockSize);
107 unsigned int blockSize = this->
BlockSize();
108 unsigned int num =
ModPowerOf2(m_countLo, blockSize);
109 T* dataBuf = this->DataBuf();
110 byte* data = (byte *)dataBuf;
111 data[num++] = padFirst;
112 if (num <= lastBlockSize)
113 memset(data+num, 0, lastBlockSize-num);
116 memset(data+num, 0, blockSize-num);
118 memset(data, 0, lastBlockSize);
124 m_countLo = m_countHi = 0;
130 this->ThrowIfInvalidTruncatedSize(size);
132 T* dataBuf = this->DataBuf();
133 T* stateBuf = this->StateBuf();
134 unsigned int blockSize = this->
BlockSize();
137 PadLastBlock(blockSize - 2*
sizeof(HashWordType));
143 if (IsAligned<HashWordType>(digest) && size%
sizeof(HashWordType)==0)
144 ConditionalByteReverse<HashWordType>(order, (HashWordType *)digest, stateBuf, size);
147 ConditionalByteReverse<HashWordType>(order, stateBuf, stateBuf, this->
DigestSize());
148 memcpy(digest, stateBuf, size);
const char * DigestSize()
int, in bytes
bool NativeByteOrderIs(ByteOrder order)
Determines whether order follows native byte ordering.
Utility functions for the Crypto++ library.
ByteOrder
Provides the byte ordering.
T2 ModPowerOf2(const T1 &a, const T2 &b)
Tests whether the residue of a value is a power of 2.
T ConditionalByteReverse(ByteOrder order, T value)
Reverses bytes in a value depending upon endianess.
const char * BlockSize()
int, in bytes
Crypto++ library namespace.
byte ByteReverse(byte value)
Reverses bytes in a 8-bit value.