diff options
author | Mattias Andrée <maandree@kth.se> | 2022-01-08 10:13:28 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-01-08 10:13:28 +0100 |
commit | fb527a8eb943bf7efdf6dc858c9fd88a3fcdbd19 (patch) | |
tree | adb5310a9cceaf24b460db710f350671c55c8995 | |
parent | m (diff) | |
download | libblake-fb527a8eb943bf7efdf6dc858c9fd88a3fcdbd19.tar.gz libblake-fb527a8eb943bf7efdf6dc858c9fd88a3fcdbd19.tar.bz2 libblake-fb527a8eb943bf7efdf6dc858c9fd88a3fcdbd19.tar.xz |
Add last_node parameter to libblake_blake2[sb]_digest
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r-- | libblake.h | 4 | ||||
-rw-r--r-- | libblake_blake2b_digest.c | 5 | ||||
-rw-r--r-- | libblake_blake2s_digest.c | 5 | ||||
-rw-r--r-- | test.c | 4 |
4 files changed, 12 insertions, 6 deletions
@@ -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); @@ -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, ¶ms, 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, ¶ms, 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); |