From cda19b080eee1c8057ebcb4369455582949ed20e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 4 Sep 2024 19:41:56 +0200 Subject: Fix and test BLAKE2 support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libhashsum_init_blake2b_hasher.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'libhashsum_init_blake2b_hasher.c') diff --git a/libhashsum_init_blake2b_hasher.c b/libhashsum_init_blake2b_hasher.c index 57be6fe..06504d3 100644 --- a/libhashsum_init_blake2b_hasher.c +++ b/libhashsum_init_blake2b_hasher.c @@ -69,7 +69,7 @@ finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extr size -= r; if (!this->hash_output) - this->hash_output = this->state.blake224.buf; + this->hash_output = this->state.blake2b.buf; if (this->state.blake2b.keybytes) { bytes = BLAKE2B_BLOCK_SIZE; @@ -92,16 +92,15 @@ __attribute__((__pure__)) static int allzeroes(const uint8_t *data, size_t n) { - if (data) - while (n--) - if (data[n]) - return 0; + while (n--) + if (data[n]) + return 0; return 1; } static char * -hex(char *buf, const uint8_t *data, size_t n) +hex(char *restrict buf, const uint8_t *restrict data, size_t n) { size_t i; for (i = 0; i < n; i++) { @@ -151,12 +150,14 @@ libhashsum_init_blake2b_hasher(struct libhashsum_hasher *this, size_t hashbits, .node_depth = 0U, .inner_len = 0U }; - if (((hashbits | keybits) & 7U) || ((hashbits | keybits) > 256U)) { + if (((hashbits | keybits) & 7U) || hashbits > 512U || keybits > 512U) { errno = EINVAL; return -1; } - if (!hashbits) + if (!hashbits) { hashbits = 512U; + params.digest_len = (unsigned char)(hashbits / 8U); + } libblake_init(); this->algorithm = LIBHASHSUM_BLAKE2B; this->algorithm_string = mkalgostr(this->state.blake2b.algostr, "BLAKE2b", -- cgit v1.2.3-70-g09d2