aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_init_blake256_hasher.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-08-31 07:41:27 +0200
committerMattias Andrée <maandree@kth.se>2024-08-31 07:41:27 +0200
commitd1acc40f9361cf5d1f0e92a0a2569b518b29b1cf (patch)
treea0538a97e06b8783f07eeed5cc3d686e3a8a686f /libhashsum_init_blake256_hasher.c
parentAdd more tests + m fixes (diff)
downloadlibhashsum-d1acc40f9361cf5d1f0e92a0a2569b518b29b1cf.tar.gz
libhashsum-d1acc40f9361cf5d1f0e92a0a2569b518b29b1cf.tar.bz2
libhashsum-d1acc40f9361cf5d1f0e92a0a2569b518b29b1cf.tar.xz
Add support for extended hash + add support for output hash to custom buffer when supported
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libhashsum_init_blake256_hasher.c')
-rw-r--r--libhashsum_init_blake256_hasher.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/libhashsum_init_blake256_hasher.c b/libhashsum_init_blake256_hasher.c
index 39a8eb9..3d00290 100644
--- a/libhashsum_init_blake256_hasher.c
+++ b/libhashsum_init_blake256_hasher.c
@@ -27,13 +27,15 @@ finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, u
m = &m[r];
bytes -= r;
+ if (!this->hash_output)
+ this->hash_output = this->state.blake256.buf;
+
memcpy(this->state.blake256.buf, m, bytes + (size_t)(extra_bits > 0U));
if (extra_bits)
this->state.blake256.buf[bytes] = libhashsum_reverse_byte__(this->state.blake256.buf[bytes]);
libblake_blake256_digest(&this->state.blake256.s, this->state.blake256.buf, bytes,
- extra_bits, NULL, this->state.blake256.buf);
+ extra_bits, NULL, this->hash_output);
memset(&this->state.blake256.s, 0, sizeof(this->state.blake256.s));
- this->hash_output = this->state.blake256.buf;
return 0;
}
@@ -55,15 +57,17 @@ finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extr
bytes -= r;
size -= r;
+ if (!this->hash_output)
+ this->hash_output = this->state.blake256.buf;
+
if (size < libblake_blake256_digest_get_required_input_size(bytes, extra_bits, NULL)) {
memcpy(this->state.blake256.buf, m, bytes + (size_t)(extra_bits > 0U));
m = this->state.blake256.buf;
}
if (extra_bits)
m[bytes] = libhashsum_reverse_byte__(m[bytes]);
- libblake_blake256_digest(&this->state.blake256.s, m, bytes, extra_bits, NULL, this->state.blake256.buf);
+ libblake_blake256_digest(&this->state.blake256.s, m, bytes, extra_bits, NULL, this->hash_output);
memset(&this->state.blake256.s, 0, sizeof(this->state.blake256.s));
- this->hash_output = this->state.blake256.buf;
return 0;
}
@@ -104,6 +108,7 @@ libhashsum_init_blake256_hasher(struct libhashsum_hasher *this, const void *salt
this->process = &process;
this->finalise_const = &finalise_const;
this->finalise = &finalise;
+ this->stretch = NULL;
this->destroy = NULL;
libblake_blake256_init2(&this->state.blake256.s, salt);
return 0;