aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_init_blake224_hasher.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libhashsum_init_blake224_hasher.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/libhashsum_init_blake224_hasher.c b/libhashsum_init_blake224_hasher.c
index 65d0ee1..642af8d 100644
--- a/libhashsum_init_blake224_hasher.c
+++ b/libhashsum_init_blake224_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_blake224_hasher(struct libhashsum_hasher *this)
+libhashsum_init_blake224_hasher(struct libhashsum_hasher *this, const void *salt)
{
libblake_init();
this->algorithm = LIBHASHSUM_BLAKE224;
- this->algorithm_string = "BLAKE224";
+ this->algorithm_string = mkalgostr(this->state.blake224.algostr, "BLAKE224", salt);
this->input_block_size = 64U;
this->hash_size = LIBHASHSUM_BLAKE224_HASH_SIZE;
this->hash_output = NULL;
@@ -82,16 +105,17 @@ libhashsum_init_blake224_hasher(struct libhashsum_hasher *this)
this->finalise_const = &finalise_const;
this->finalise = &finalise;
this->destroy = NULL;
- libblake_blake224_init2(&this->state.blake224.s, NULL);
+ libblake_blake224_init2(&this->state.blake224.s, salt);
return 0;
}
#else
int
-libhashsum_init_blake224_hasher(struct libhashsum_hasher *this)
+libhashsum_init_blake224_hasher(struct libhashsum_hasher *this, const void *salt)
{
(void) this;
+ (void) salt;
errno = ENOSYS;
return -1;
}