aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libblake.h4
-rw-r--r--libblake_blake2b_digest.c5
-rw-r--r--libblake_blake2s_digest.c5
-rw-r--r--test.c4
4 files changed, 12 insertions, 6 deletions
diff --git a/libblake.h b/libblake.h
index 9704d3a..5e49726 100644
--- a/libblake.h
+++ b/libblake.h
@@ -112,14 +112,14 @@ struct libblake_blake2b_state {
void libblake_blake2s_init(struct libblake_blake2s_state *state, const struct libblake_blake2s_params *params,
const unsigned char *key /* append null bytes until 64 bytes; if key is used */);
size_t libblake_blake2s_update(struct libblake_blake2s_state *state, const void *data, size_t len);
-void libblake_blake2s_digest(struct libblake_blake2s_state *state, void *data, size_t len,
+void libblake_blake2s_digest(struct libblake_blake2s_state *state, void *data, size_t len, int last_node /* normally 0 */,
size_t output_len, unsigned char output[static output_len]);
LIBBLAKE_CONST__ size_t libblake_blake2s_digest_get_required_input_size(size_t len);
void libblake_blake2b_init(struct libblake_blake2b_state *state, const struct libblake_blake2b_params *params,
const unsigned char *key /* append null bytes until 128 bytes; if key is used */);
size_t libblake_blake2b_update(struct libblake_blake2b_state *state, const void *data, size_t len);
-void libblake_blake2b_digest(struct libblake_blake2b_state *state, void *data, size_t len,
+void libblake_blake2b_digest(struct libblake_blake2b_state *state, void *data, size_t len, int last_node /* normally 0 */,
size_t output_len, unsigned char output[static output_len]);
LIBBLAKE_CONST__ size_t libblake_blake2b_digest_get_required_input_size(size_t len);
diff --git a/libblake_blake2b_digest.c b/libblake_blake2b_digest.c
index f1e45a8..016282d 100644
--- a/libblake_blake2b_digest.c
+++ b/libblake_blake2b_digest.c
@@ -35,7 +35,7 @@ encode_uint64_le(unsigned char *out, uint_least64_t value, size_t bytes)
}
void
-libblake_blake2b_digest(struct libblake_blake2b_state *state, void *data_, size_t len,
+libblake_blake2b_digest(struct libblake_blake2b_state *state, void *data_, size_t len, int last_node,
size_t output_len, unsigned char output[static output_len])
{
unsigned char *data = data_;
@@ -46,6 +46,9 @@ libblake_blake2b_digest(struct libblake_blake2b_state *state, void *data_, size_
len -= r;
state->f[0] = UINT_LEAST64_C(0xFFFFffffFFFFffff);
+ if (last_node)
+ state->f[1] = UINT_LEAST64_C(0xFFFFffffFFFFffff);
+
memset(&data[len], 0, 128 - len);
state->t[0] = (state->t[0] + len) & UINT_LEAST64_C(0xFFFFffffFFFFffff);
diff --git a/libblake_blake2s_digest.c b/libblake_blake2s_digest.c
index d9106a5..29a31a6 100644
--- a/libblake_blake2s_digest.c
+++ b/libblake_blake2s_digest.c
@@ -23,7 +23,7 @@ encode_uint32_le(unsigned char *out, uint_least32_t value, size_t bytes)
}
void
-libblake_blake2s_digest(struct libblake_blake2s_state *state, void *data_, size_t len,
+libblake_blake2s_digest(struct libblake_blake2s_state *state, void *data_, size_t len, int last_node,
size_t output_len, unsigned char output[static output_len])
{
unsigned char *data = data_;
@@ -34,6 +34,9 @@ libblake_blake2s_digest(struct libblake_blake2s_state *state, void *data_, size_
len -= r;
state->f[0] = UINT_LEAST32_C(0xFFFFffff);
+ if (last_node)
+ state->f[1] = UINT_LEAST32_C(0xFFFFffff);
+
memset(&data[len], 0, 64 - len);
state->t[0] = (state->t[0] + len) & UINT_LEAST32_C(0xFFFFffff);
diff --git a/test.c b/test.c
index 9cb85dd..77bdbc0 100644
--- a/test.c
+++ b/test.c
@@ -362,7 +362,7 @@ digest_blake2s(int length, const void *msg, size_t msglen)
data = malloc(req);
memcpy(data, msg, msglen);
libblake_blake2s_init(&s, &params, NULL);
- libblake_blake2s_digest(&s, data, msglen, (size_t)length / 8, buf);
+ libblake_blake2s_digest(&s, data, msglen, 0, (size_t)length / 8, buf);
libblake_encode_hex(buf, (size_t)length / 8, hex, 0);
free(data);
@@ -429,7 +429,7 @@ digest_blake2b(int length, const void *msg, size_t msglen)
data = malloc(req);
memcpy(data, msg, msglen);
libblake_blake2b_init(&s, &params, NULL);
- libblake_blake2b_digest(&s, data, msglen, (size_t)length / 8, buf);
+ libblake_blake2b_digest(&s, data, msglen, 0, (size_t)length / 8, buf);
libblake_encode_hex(buf, (size_t)length / 8, hex, 0);
free(data);