diff options
Diffstat (limited to 'update.c')
-rw-r--r-- | update.c | 14 |
1 files changed, 5 insertions, 9 deletions
@@ -16,17 +16,13 @@ libsha2_update(struct libsha2_state *restrict state, const void *restrict messag n = msglen < state->chunk_size - off ? msglen : state->chunk_size - off; memcpy(&state->chunk[off], message, n); if (off + n == state->chunk_size) - libsha2_process(state, state->chunk); - message += n; + libsha2_process(state, state->chunk, state->chunk_size); + message = &message[n]; msglen -= n; } - while (msglen >= state->chunk_size) { - libsha2_process(state, (const unsigned char *)message); - message += state->chunk_size; - msglen -= state->chunk_size; - } + off = libsha2_process(state, (const unsigned char *)message, msglen); - if (msglen) - memcpy(state->chunk, message, msglen); + if (msglen > off) + memcpy(state->chunk, &message[off], msglen - off); } |