diff options
Diffstat (limited to 'libhashsum_init_blake384_hasher.c')
-rw-r--r-- | libhashsum_init_blake384_hasher.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/libhashsum_init_blake384_hasher.c b/libhashsum_init_blake384_hasher.c index 6f92c6c..cd6457f 100644 --- a/libhashsum_init_blake384_hasher.c +++ b/libhashsum_init_blake384_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_blake384_hasher(struct libhashsum_hasher *this) +libhashsum_init_blake384_hasher(struct libhashsum_hasher *this, const void *salt) { libblake_init(); this->algorithm = LIBHASHSUM_BLAKE384; - this->algorithm_string = "BLAKE384"; + this->algorithm_string = mkalgostr(this->state.blake224.algostr, "BLAKE384", salt); this->input_block_size = 128U; this->hash_size = LIBHASHSUM_BLAKE384_HASH_SIZE; this->hash_output = NULL; @@ -82,16 +105,17 @@ libhashsum_init_blake384_hasher(struct libhashsum_hasher *this) this->finalise_const = &finalise_const; this->finalise = &finalise; this->destroy = NULL; - libblake_blake384_init2(&this->state.blake384.s, NULL); + libblake_blake384_init2(&this->state.blake384.s, salt); return 0; } #else int -libhashsum_init_blake384_hasher(struct libhashsum_hasher *this) +libhashsum_init_blake384_hasher(struct libhashsum_hasher *this, const void *salt) { (void) this; + (void) salt; errno = ENOSYS; return -1; } |