diff options
Diffstat (limited to '')
-rw-r--r-- | libhashsum_init_blake512_hasher.c | 32 |
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; } |