aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_init_blake2b_hasher.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-09-04 19:41:56 +0200
committerMattias Andrée <maandree@kth.se>2024-09-04 19:41:56 +0200
commitcda19b080eee1c8057ebcb4369455582949ed20e (patch)
tree39d4ff4a5efaac08207ca33606fa01877b404927 /libhashsum_init_blake2b_hasher.c
parenttests: check .supports_non_whole_bytes (diff)
downloadlibhashsum-cda19b080eee1c8057ebcb4369455582949ed20e.tar.gz
libhashsum-cda19b080eee1c8057ebcb4369455582949ed20e.tar.bz2
libhashsum-cda19b080eee1c8057ebcb4369455582949ed20e.tar.xz
Fix and test BLAKE2 support
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libhashsum_init_blake2b_hasher.c')
-rw-r--r--libhashsum_init_blake2b_hasher.c17
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",