aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_init_blake2s_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_blake2s_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_blake2s_hasher.c')
-rw-r--r--libhashsum_init_blake2s_hasher.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/libhashsum_init_blake2s_hasher.c b/libhashsum_init_blake2s_hasher.c
index 0957b22..689dc64 100644
--- a/libhashsum_init_blake2s_hasher.c
+++ b/libhashsum_init_blake2s_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.blake2s.buf;
if (this->state.blake2s.keybytes) {
bytes = BLAKE2S_BLOCK_SIZE;
@@ -100,7 +100,7 @@ allzeroes(const uint8_t *data, size_t n)
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++) {
@@ -150,12 +150,14 @@ libhashsum_init_blake2s_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 > 256U || keybits > 256U) {
errno = EINVAL;
return -1;
}
- if (!hashbits)
+ if (!hashbits) {
hashbits = 256U;
+ params.digest_len = (unsigned char)(hashbits / 8U);
+ }
libblake_init();
this->algorithm = LIBHASHSUM_BLAKE2S;
this->algorithm_string = mkalgostr(this->state.blake2s.algostr, "BLAKE2s",