diff options
author | Jack Lloyd <[email protected]> | 2017-10-26 17:05:08 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-10-26 17:05:08 -0400 |
commit | 9c7436fbd0a750d0dca5a4dfd3970917c50dedfb (patch) | |
tree | 2aed10f36a8fc553f645c5efd5051c09f0d035e0 /src | |
parent | 9bbca51d2c760db724136695837bc9c1d1a4f4b4 (diff) |
Avoid invalid iterator woes
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/hash/blake2/blake2b.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/lib/hash/blake2/blake2b.cpp b/src/lib/hash/blake2/blake2b.cpp index 2cc1c3888..42ec707bd 100644 --- a/src/lib/hash/blake2/blake2b.cpp +++ b/src/lib/hash/blake2/blake2b.cpp @@ -128,13 +128,19 @@ void Blake2b::compress(const uint8_t* input, size_t blocks, size_t increment) void Blake2b::add_data(const uint8_t input[], size_t length) { + if(length == 0) + return; + if(m_bufpos > 0) { - const size_t take = std::min(BLAKE2B_BLOCKBYTES - m_bufpos, length); - copy_mem(&m_buffer[m_bufpos], input, take); - m_bufpos += take; - length -= take; - input += take; + if(m_bufpos < BLAKE2B_BLOCKBYTES) + { + const size_t take = std::min(BLAKE2B_BLOCKBYTES - m_bufpos, length); + copy_mem(&m_buffer[m_bufpos], input, take); + m_bufpos += take; + length -= take; + input += take; + } if(m_bufpos == m_buffer.size() && length > 0) { @@ -152,13 +158,17 @@ void Blake2b::add_data(const uint8_t input[], size_t length) length -= full_blocks * BLAKE2B_BLOCKBYTES; } - copy_mem(&m_buffer[m_bufpos], input, length); - m_bufpos += length; + if(length > 0) + { + copy_mem(&m_buffer[m_bufpos], input, length); + m_bufpos += length; + } } void Blake2b::final_result(uint8_t output[]) { - clear_mem(&m_buffer[m_bufpos], BLAKE2B_BLOCKBYTES - m_bufpos); + if(m_bufpos != BLAKE2B_BLOCKBYTES) + clear_mem(&m_buffer[m_bufpos], BLAKE2B_BLOCKBYTES - m_bufpos); m_F[0] = 0xFFFFFFFFFFFFFFFF; compress(m_buffer.data(), 1, m_bufpos); copy_out_vec_le(output, output_length(), m_H); |