Add call to ThrowIfInvalidTruncatedSize in TruncatedFinal

pull/174/head
Jeffrey Walton 2016-05-21 12:28:52 -04:00
parent 309fbc2e78
commit 2162219299
1 changed files with 3 additions and 2 deletions

View File

@ -422,9 +422,10 @@ void BLAKE2_Base<W, T_64bit>::Update(const byte *input, size_t length)
template <class W, bool T_64bit> template <class W, bool T_64bit>
void BLAKE2_Base<W, T_64bit>::TruncatedFinal(byte *hash, size_t size) void BLAKE2_Base<W, T_64bit>::TruncatedFinal(byte *hash, size_t size)
{ {
State& state = *m_state; this->ThrowIfInvalidTruncatedSize(size);
// Set last block unconditionally // Set last block unconditionally
State& state = *m_state;
state.f[0] = static_cast<W>(-1); state.f[0] = static_cast<W>(-1);
// Set last node if tree mode // Set last node if tree mode
@ -438,7 +439,7 @@ void BLAKE2_Base<W, T_64bit>::TruncatedFinal(byte *hash, size_t size)
Compress(state.buffer); Compress(state.buffer);
// Copy to caller buffer // Copy to caller buffer
memcpy_s(hash, size, &state.h[0], DIGESTSIZE); memcpy_s(hash, size, &state.h[0], size);
Restart(); Restart();
} }