diff options
Diffstat (limited to 'libhashsum_init_blake2b_hasher.c')
-rw-r--r-- | libhashsum_init_blake2b_hasher.c | 17 |
1 files changed, 9 insertions, 8 deletions
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", |