aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_init_blake256_hasher.c
diff options
context:
space:
mode:
Diffstat (limited to 'libhashsum_init_blake256_hasher.c')
-rw-r--r--libhashsum_init_blake256_hasher.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/libhashsum_init_blake256_hasher.c b/libhashsum_init_blake256_hasher.c
index 202dc37..fd77878 100644
--- a/libhashsum_init_blake256_hasher.c
+++ b/libhashsum_init_blake256_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 < 16U; i++)
+ if (salt[i])
+ goto nonzero;
+ return name;
+nonzero:
+ p = stpcpy(stpcpy(buf, name), "[salt=");
+ for (i = 0; i < 16U; i++) {
+ *p++ = "0123456789abcdef"[(salt[i] >> 4) & 15];
+ *p++ = "0123456789abcdef"[(salt[i] >> 0) & 15];
+ }
+ *p++ = ']';
+ *p++ = '\0';
+ return buf;
+}
+
+
int
-libhashsum_init_blake256_hasher(struct libhashsum_hasher *this)
+libhashsum_init_blake256_hasher(struct libhashsum_hasher *this, const void *salt)
{
libblake_init();
this->algorithm = LIBHASHSUM_BLAKE256;
- this->algorithm_string = "BLAKE256";
+ this->algorithm_string = mkalgostr(this->state.blake224.algostr, "BLAKE256", salt);
this->input_block_size = 64U;
this->hash_size = LIBHASHSUM_BLAKE256_HASH_SIZE;
this->hash_output = NULL;
@@ -82,16 +105,17 @@ libhashsum_init_blake256_hasher(struct libhashsum_hasher *this)
this->finalise_const = &finalise_const;
this->finalise = &finalise;
this->destroy = NULL;
- libblake_blake256_init2(&this->state.blake256.s, NULL);
+ libblake_blake256_init2(&this->state.blake256.s, salt);
return 0;
}
#else
int
-libhashsum_init_blake256_hasher(struct libhashsum_hasher *this)
+libhashsum_init_blake256_hasher(struct libhashsum_hasher *this, const void *salt)
{
(void) this;
+ (void) salt;
errno = ENOSYS;
return -1;
}