4 #define CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES 13 template <class T, class BASE>
void IteratedHashBase<T, BASE>::Update(const byte *input,
size_t len)
15 HashWordType oldCountLo = m_countLo, oldCountHi = m_countHi;
16 if ((m_countLo = oldCountLo + HashWordType(len)) < oldCountLo)
18 m_countHi += (HashWordType)
SafeRightShift<8*
sizeof(HashWordType)>(len);
19 if (m_countHi < oldCountHi ||
SafeRightShift<2*8*
sizeof(HashWordType)>(len) != 0)
22 const unsigned int blockSize = this->
BlockSize();
23 unsigned int num =
ModPowerOf2(oldCountLo, blockSize);
25 T* dataBuf = this->DataBuf();
26 byte* data = (byte *)dataBuf;
31 if (num+len >= blockSize)
33 if (data && input) {memcpy(data+num, input, blockSize-num);}
35 input += (blockSize-num);
36 len -= (blockSize-num);
42 if (data && input && len) {memcpy(data+num, input, len);}
56 else if (IsAligned<T>(input))
58 size_t leftOver = HashMultipleBlocks((T *)(
void*)input, len);
59 input += (len - leftOver);
65 if (data && input) memcpy(data, input, blockSize);
69 }
while (len >= blockSize);
72 if (data && input && len && data != input)
73 memcpy(data, input, len);
78 unsigned int blockSize = this->
BlockSize();
79 unsigned int num =
ModPowerOf2(m_countLo, blockSize);
80 size = blockSize - num;
81 return (byte *)DataBuf() + num;
86 unsigned int blockSize = this->
BlockSize();
88 T* dataBuf = this->DataBuf();
92 this->HashEndianCorrectedBlock(input);
96 this->HashEndianCorrectedBlock(dataBuf);
99 input += blockSize/
sizeof(T);
102 while (length >= blockSize);
108 unsigned int blockSize = this->
BlockSize();
109 unsigned int num =
ModPowerOf2(m_countLo, blockSize);
110 T* dataBuf = this->DataBuf();
111 byte* data = (byte *)dataBuf;
112 data[num++] = padFirst;
113 if (num <= lastBlockSize)
114 memset(data+num, 0, lastBlockSize-num);
117 memset(data+num, 0, blockSize-num);
119 memset(data, 0, lastBlockSize);
125 m_countLo = m_countHi = 0;
131 this->ThrowIfInvalidTruncatedSize(size);
133 T* dataBuf = this->DataBuf();
134 T* stateBuf = this->StateBuf();
135 unsigned int blockSize = this->
BlockSize();
138 PadLastBlock(blockSize - 2*
sizeof(HashWordType));
144 if (IsAligned<HashWordType>(digest) && size%
sizeof(HashWordType)==0)
145 ConditionalByteReverse<HashWordType>(order, (HashWordType *)(
void*)digest, stateBuf, size);
148 ConditionalByteReverse<HashWordType>(order, stateBuf, stateBuf, this->
DigestSize());
149 memcpy(digest, stateBuf, size);
155 #if defined(__GNUC__) || defined(__clang__) 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)
Reduces a value to a power of 2.
T SafeRightShift(T value)
Safely right shift values when undefined behavior could occur.
T ConditionalByteReverse(ByteOrder order, T value)
Reverses bytes in a value depending upon endianness.
void TruncatedFinal(byte *digest, size_t digestSize)
Computes the hash of the current message.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
const char * BlockSize()
int, in bytes
Functions for CPU features and intrinsics.
void Restart()
Restart the hash.
Iterated hash base class.
Crypto++ library namespace.
byte ByteReverse(byte value)
Reverses bytes in a 8-bit value.
byte * CreateUpdateSpace(size_t &size)
Requests space which can be written into by the caller.