4#define CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES
13template <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 std::memset(data+num, 0, lastBlockSize-num);
153 std::memset(data+num, 0, blockSize-num);
155 std::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__)
Iterated hash base class.
void TruncatedFinal(byte *digest, size_t digestSize)
Computes the hash of the current message.
byte * CreateUpdateSpace(size_t &size)
Requests space which can be written into by the caller.
void Restart()
Restart the hash.
Functions for CPU features and intrinsics.
ByteOrder
Provides the byte ordering.
Base classes for iterated hashes.
Utility functions for the Crypto++ library.
byte ByteReverse(byte value)
Reverses bytes in a 8-bit value.
T2 ModPowerOf2(const T1 &a, const T2 &b)
Reduces a value to a power of 2.
bool NativeByteOrderIs(ByteOrder order)
Determines whether order follows native byte ordering.
T ConditionalByteReverse(ByteOrder order, T value)
Reverses bytes in a value depending upon endianness.
T SafeRightShift(T value)
Safely right shift values when undefined behavior could occur.
Crypto++ library namespace.
const char * BlockSize()
int, in bytes
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.