aboutsummaryrefslogtreecommitdiffstats
path: root/update.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2019-02-10 20:21:19 +0100
committerMattias Andrée <maandree@kth.se>2019-02-10 20:21:19 +0100
commited0296b9055713df0d910e4e7528ffe6fc539514 (patch)
tree8cbf8ecc9b6352257d6bc4946ff75cb8a4b484c0 /update.c
downloadlibsha1-ed0296b9055713df0d910e4e7528ffe6fc539514.tar.gz
libsha1-ed0296b9055713df0d910e4e7528ffe6fc539514.tar.bz2
libsha1-ed0296b9055713df0d910e4e7528ffe6fc539514.tar.xz
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'update.c')
-rw-r--r--update.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/update.c b/update.c
new file mode 100644
index 0000000..7c9ed9b
--- /dev/null
+++ b/update.c
@@ -0,0 +1,39 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+/**
+ * Absorb more of the message
+ *
+ * @param state The hashing state
+ * @param message The message, in bits, must be equivalent to 0 modulus 8
+ * @param msglen The length of the message
+ */
+void
+libsha1_update(struct libsha1_state *restrict state, const void *restrict message_, size_t msglen)
+{
+ const char *restrict message = message_;
+ size_t n, off;
+
+ off = (state->message_size / 8) % state->chunk_size;
+ state->message_size += msglen;
+ msglen /= 8;
+
+ if (off) {
+ n = msglen < state->chunk_size - off ? msglen : state->chunk_size - off;
+ memcpy(state->chunk + off, message, n);
+ if (off + n == state->chunk_size)
+ libsha1_process(state, state->chunk);
+ message += n;
+ msglen -= n;
+ }
+
+ while (msglen >= state->chunk_size) {
+ libsha1_process(state, (const unsigned char *)message);
+ message += state->chunk_size;
+ msglen -= state->chunk_size;
+ }
+
+ if (msglen)
+ memcpy(state->chunk, message, msglen);
+}