4 #define CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES 13 template <class T, class BASE>
void IteratedHashBase<T, BASE>::Update(const byte *input,
size_t length)
16 if (length == 0) {
return; }
18 HashWordType oldCountLo = m_countLo, oldCountHi = m_countHi;
19 if ((m_countLo = oldCountLo + HashWordType(length)) < oldCountLo)
21 m_countHi += (HashWordType)
SafeRightShift<8*
sizeof(HashWordType)>(length);
22 if (m_countHi < oldCountHi ||
SafeRightShift<2*8*
sizeof(HashWordType)>(length) != 0)
25 const unsigned int blockSize = this->
BlockSize();
26 unsigned int num =
ModPowerOf2(oldCountLo, blockSize);
28 T* dataBuf = this->DataBuf();
29 byte* data = (byte *)dataBuf;
33 if (num+length >= blockSize)
36 {std::memcpy(data+num, input, blockSize-num);}
39 input += (blockSize-num);
40 length -= (blockSize-num);
47 {std::memcpy(data+num, input, length);}
53 if (length >= blockSize)
61 else if (IsAligned<T>(input))
63 size_t leftOver = HashMultipleBlocks((T *)(
void*)input, length);
64 input += (length - leftOver);
72 { std::memcpy(data, input, blockSize); }
77 }
while (length >= blockSize);
81 if (input && data != input)
82 std::memcpy(data, input, length);
87 unsigned int blockSize = this->
BlockSize();
88 unsigned int num =
ModPowerOf2(m_countLo, blockSize);
89 size = blockSize - num;
90 return (byte *)DataBuf() + num;
95 const unsigned int blockSize = this->
BlockSize();
97 T* dataBuf = this->DataBuf();
107 if (IsAligned<HashWordType>(input))
110 this->HashEndianCorrectedBlock(input);
114 std::memcpy(dataBuf, input, blockSize);
115 this->HashEndianCorrectedBlock(dataBuf);
120 if (IsAligned<HashWordType>(input))
124 this->HashEndianCorrectedBlock(dataBuf);
128 std::memcpy(dataBuf, input, blockSize);
130 this->HashEndianCorrectedBlock(dataBuf);
134 input += blockSize/
sizeof(T);
137 while (length >= blockSize);
143 unsigned int blockSize = this->
BlockSize();
144 unsigned int num =
ModPowerOf2(m_countLo, blockSize);
145 T* dataBuf = this->DataBuf();
146 byte* data = (byte *)dataBuf;
148 data[num++] = padFirst;
149 if (num <= lastBlockSize)
150 memset(data+num, 0, lastBlockSize-num);
153 memset(data+num, 0, blockSize-num);
155 memset(data, 0, lastBlockSize);
161 m_countLo = m_countHi = 0;
168 this->ThrowIfInvalidTruncatedSize(size);
170 T* dataBuf = this->DataBuf();
171 T* stateBuf = this->StateBuf();
172 unsigned int blockSize = this->
BlockSize();
175 PadLastBlock(blockSize - 2*
sizeof(HashWordType));
181 if (IsAligned<HashWordType>(digest) && size%
sizeof(HashWordType)==0)
182 ConditionalByteReverse<HashWordType>(order, (HashWordType *)(
void*)digest, stateBuf, size);
185 ConditionalByteReverse<HashWordType>(order, stateBuf, stateBuf, this->
DigestSize());
186 std::memcpy(digest, stateBuf, size);
192 #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.