aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_init_blake512_hasher.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-08-24 20:39:01 +0200
committerMattias Andrée <maandree@kth.se>2024-08-24 20:39:01 +0200
commit2bc752da4a803cf6c03fb84bb90bc6e468981526 (patch)
tree5223412269afd9af411f918b51a66a433f235af0 /libhashsum_init_blake512_hasher.c
parentAdd BLAKE via libblake>=1.1 (this version introduced libblake_init()) (diff)
downloadlibhashsum-2bc752da4a803cf6c03fb84bb90bc6e468981526.tar.gz
libhashsum-2bc752da4a803cf6c03fb84bb90bc6e468981526.tar.bz2
libhashsum-2bc752da4a803cf6c03fb84bb90bc6e468981526.tar.xz
Add support for salt for BLAKE
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libhashsum_init_blake512_hasher.c')
-rw-r--r--libhashsum_init_blake512_hasher.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/libhashsum_init_blake512_hasher.c b/libhashsum_init_blake512_hasher.c
index b1d2c13..d174fdd 100644
--- a/libhashsum_init_blake512_hasher.c
+++ b/libhashsum_init_blake512_hasher.c
@@ -68,12 +68,35 @@ finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extr
}
+static const char *
+mkalgostr(char *buf, const char *name, const uint8_t *salt)
+{
+ char *p;
+ size_t i;
+ if (!salt)
+ return name;
+ for (i = 0; i < 32U; i++)
+ if (salt[i])
+ goto nonzero;
+ return name;
+nonzero:
+ p = stpcpy(stpcpy(buf, name), "[salt=");
+ for (i = 0; i < 32U; i++) {
+ *p++ = "0123456789abcdef"[(salt[i] >> 4) & 15];
+ *p++ = "0123456789abcdef"[(salt[i] >> 0) & 15];
+ }
+ *p++ = ']';
+ *p++ = '\0';
+ return buf;
+}
+
+
int
-libhashsum_init_blake512_hasher(struct libhashsum_hasher *this)
+libhashsum_init_blake512_hasher(struct libhashsum_hasher *this, const void *salt)
{
libblake_init();
this->algorithm = LIBHASHSUM_BLAKE512;
- this->algorithm_string = "BLAKE512";
+ this->algorithm_string = mkalgostr(this->state.blake224.algostr, "BLAKE512", salt);
this->input_block_size = 128U;
this->hash_size = LIBHASHSUM_BLAKE512_HASH_SIZE;
this->hash_output = NULL;
@@ -82,16 +105,17 @@ libhashsum_init_blake512_hasher(struct libhashsum_hasher *this)
this->finalise_const = &finalise_const;
this->finalise = &finalise;
this->destroy = NULL;
- libblake_blake512_init2(&this->state.blake512.s, NULL);
+ libblake_blake512_init2(&this->state.blake512.s, salt);
return 0;
}
#else
int
-libhashsum_init_blake512_hasher(struct libhashsum_hasher *this)
+libhashsum_init_blake512_hasher(struct libhashsum_hasher *this, const void *salt)
{
(void) this;
+ (void) salt;
errno = ENOSYS;
return -1;
}