diff --git a/blake2.cpp b/blake2.cpp index 6409f6a8..7f0933a6 100644 --- a/blake2.cpp +++ b/blake2.cpp @@ -422,9 +422,10 @@ void BLAKE2_Base::Update(const byte *input, size_t length) template void BLAKE2_Base::TruncatedFinal(byte *hash, size_t size) { - State& state = *m_state; + this->ThrowIfInvalidTruncatedSize(size); // Set last block unconditionally + State& state = *m_state; state.f[0] = static_cast(-1); // Set last node if tree mode @@ -438,7 +439,7 @@ void BLAKE2_Base::TruncatedFinal(byte *hash, size_t size) Compress(state.buffer); // Copy to caller buffer - memcpy_s(hash, size, &state.h[0], DIGESTSIZE); + memcpy_s(hash, size, &state.h[0], size); Restart(); }