aboutsummaryrefslogtreecommitdiffstats
path: root/update.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-07-08 00:47:04 +0200
committerMattias Andrée <maandree@kth.se>2022-07-08 00:47:04 +0200
commitc5b86d52256d535149caefbe1031807b28c8face (patch)
tree0f5b52e3196ca435365244b7cc3b97f9fb9750c5 /update.c
parentm (diff)
downloadlibsha1-c5b86d52256d535149caefbe1031807b28c8face.tar.gz
libsha1-c5b86d52256d535149caefbe1031807b28c8face.tar.bz2
libsha1-c5b86d52256d535149caefbe1031807b28c8face.tar.xz
Add code using SHA intrinsics
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--update.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/update.c b/update.c
index 6ae2928..441ecd4 100644
--- a/update.c
+++ b/update.c
@@ -5,7 +5,7 @@
void
libsha1_update(struct libsha1_state *restrict state, const void *restrict message_, size_t msglen)
{
- const char *restrict message = message_;
+ const unsigned char *restrict message = message_;
size_t n, off;
off = (state->message_size / 8) % sizeof(state->chunk);
@@ -16,17 +16,13 @@ libsha1_update(struct libsha1_state *restrict state, const void *restrict messag
n = msglen < sizeof(state->chunk) - off ? msglen : sizeof(state->chunk) - off;
memcpy(&state->chunk[off], message, n);
if (off + n == sizeof(state->chunk))
- libsha1_process(state, state->chunk);
+ libsha1_process(state, state->chunk, sizeof(state->chunk));
message += n;
msglen -= n;
}
- while (msglen >= sizeof(state->chunk)) {
- libsha1_process(state, (const unsigned char *)message);
- message += sizeof(state->chunk);
- msglen -= sizeof(state->chunk);
- }
+ off = libsha1_process(state, message, msglen);
- if (msglen)
- memcpy(state->chunk, message, msglen);
+ if (msglen > off)
+ memcpy(state->chunk, &message[off], msglen - off);
}