diff options
author | Mattias Andrée <maandree@kth.se> | 2024-08-24 20:13:01 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-08-24 20:13:01 +0200 |
commit | febb5279f7bf3c86ec872c1b2ed1e024f73e64c5 (patch) | |
tree | ea6918fc1dcb29e11ce9399b8300a124cc0342cf /libhashsum | |
parent | Add support for Keccak, SHA3, SHAKE, and RawSHAKE via libkeccak>=1.3 (this version introduced zerocopy) (diff) | |
download | libhashsum-febb5279f7bf3c86ec872c1b2ed1e024f73e64c5.tar.gz libhashsum-febb5279f7bf3c86ec872c1b2ed1e024f73e64c5.tar.bz2 libhashsum-febb5279f7bf3c86ec872c1b2ed1e024f73e64c5.tar.xz |
Add BLAKE via libblake>=1.1 (this version introduced libblake_init())
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libhashsum.h | 169 | ||||
-rw-r--r-- | libhashsum_init_blake224_hasher.c | 98 | ||||
-rw-r--r-- | libhashsum_init_blake256_hasher.c | 98 | ||||
-rw-r--r-- | libhashsum_init_blake384_hasher.c | 98 | ||||
-rw-r--r-- | libhashsum_init_blake512_hasher.c | 98 | ||||
-rw-r--r-- | libhashsum_init_blake_hasher.c | 32 | ||||
-rw-r--r-- | libhashsum_init_blakeb_hasher.c | 28 | ||||
-rw-r--r-- | libhashsum_init_blakes_hasher.c | 28 | ||||
-rw-r--r-- | libhashsum_init_hasher.c | 8 | ||||
-rw-r--r-- | libhashsum_init_hasher_from_string.c | 8 |
10 files changed, 661 insertions, 4 deletions
diff --git a/libhashsum.h b/libhashsum.h index e7050c1..d85dadd 100644 --- a/libhashsum.h +++ b/libhashsum.h @@ -14,6 +14,9 @@ #ifdef LIBHASHSUM_INCLUDE_LIBKECCAK_STATE # include <libkeccak.h> #endif +#ifdef LIBHASHSUM_INCLUDE_LIBBLAKE_STATE +# include <libblake.h> +#endif #if defined(__GNUC__) @@ -63,7 +66,11 @@ enum libhashsum_algorithm { LIBHASHSUM_SHAKE512, /**< SHAKE512 */ LIBHASHSUM_RAWSHAKE128, /**< RawSHAKE128 */ LIBHASHSUM_RAWSHAKE256, /**< RawSHAKE256 */ - LIBHASHSUM_RAWSHAKE512 /**< RawSHAKE512 */ + LIBHASHSUM_RAWSHAKE512, /**< RawSHAKE512 */ + LIBHASHSUM_BLAKE224, /**< BLAKE224 */ + LIBHASHSUM_BLAKE256, /**< BLAKE256 */ + LIBHASHSUM_BLAKE384, /**< BLAKE384 */ + LIBHASHSUM_BLAKE512 /**< BLAKE512 */ }; @@ -270,6 +277,34 @@ enum libhashsum_algorithm { */ #define LIBHASHSUM_RAWSHAKE_512_HASH_SIZE 64 +/** + * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_BLAKE224` + * + * @since 1.0 + */ +#define LIBHASHSUM_BLAKE224_HASH_SIZE 28 + +/** + * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_BLAKE256` + * + * @since 1.0 + */ +#define LIBHASHSUM_BLAKE256_HASH_SIZE 32 + +/** + * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_BLAKE384` + * + * @since 1.0 + */ +#define LIBHASHSUM_BLAKE384_HASH_SIZE 48 + +/** + * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_BLAKE512` + * + * @since 1.0 + */ +#define LIBHASHSUM_BLAKE512_HASH_SIZE 64 + /** * Hash state @@ -385,7 +420,29 @@ union libhashsum_state { } keccak; /* size = [1020, 1065] */ #endif - /* libblake: size = 56(s), 112(b), 48(2s), 96(2b), 144(2Xs), 276(2Xb) */ +#ifdef LIBHASHSUM_INCLUDE_LIBBLAKE_STATE + struct { + struct libblake_blake224_state s; + uint8_t buf[128]; + } blake224; /* size = 184 */ + + struct { + struct libblake_blake256_state s; + uint8_t buf[128]; + } blake256; /* size = 184 */ + + struct { + struct libblake_blake384_state s; + uint8_t buf[256]; + } blake384; /* size = 368 */ + + struct { + struct libblake_blake512_state s; + uint8_t buf[256]; + } blake512; /* size = 368 */ +#endif + + /* libblake: 48(2s), 96(2b), 144(2Xs), 276(2Xb) */ char max_size[1648]; #define libhashsum_init_hasher libhashsum_init_hasher__1648 @@ -478,7 +535,7 @@ struct libhashsum_hasher { * last bit * * @param this The object containing this function pointer - * @param data The new input data, the function may rewrite it's content + * @param data The new input data * @param bytes The number of bytes available in `data` for reading * @param extra_bits Additional bits in `data` not covered by `bytes` * @return 0 on success, -1 on failure @@ -503,7 +560,7 @@ struct libhashsum_hasher { * last bit * * @param this The object containing this function pointer - * @param data The new input data, the function may rewrite it's content + * @param data The new input data, the function may rewrite its content * @param bytes The number of bytes available in `data` for reading * @param extra_bits Additional bits in `data` not covered by `bytes` * @param size `bytes` plus any number of additional bytes available @@ -1118,5 +1175,109 @@ int libhashsum_init_rawshake512_hasher(struct libhashsum_hasher *this, size_t ha LIBHASHSUM_1_NONNULL_ int libhashsum_init_rawshake_hasher(struct libhashsum_hasher *this, size_t hcapbits, size_t hashbits); +/** + * Create an initialised state for BLAKE224 (BLAKE, BLAKEs) + * hashing and return hash functions and details + * + * @param this The output parameter for the functions, details, and state + * @return 0 on success, -1 on failure + * + * @throws ENOSYS Support was excluded at compile time + * + * @since 1.0 + */ +LIBHASHSUM_1_NONNULL_ +int libhashsum_init_blake224_hasher(struct libhashsum_hasher *this); + +/** + * Create an initialised state for BLAKE256 (BLAKE, BLAKEs) + * hashing and return hash functions and details + * + * @param this The output parameter for the functions, details, and state + * @return 0 on success, -1 on failure + * + * @throws ENOSYS Support was excluded at compile time + * + * @since 1.0 + */ +LIBHASHSUM_1_NONNULL_ +int libhashsum_init_blake256_hasher(struct libhashsum_hasher *this); + +/** + * Create an initialised state for BLAKEs (BLAKE) + * hashing and return hash functions and details + * + * @param this The output parameter for the functions, details, and state + * @param hashbits Hash output size in bits + * @return 0 on success, -1 on failure + * + * @throws EINVAL `hashbits` is invalid (neither 224 nor 256) + * @throws ENOSYS Support was excluded at compile time + * + * @since 1.0 + */ +LIBHASHSUM_1_NONNULL_ +int libhashsum_init_blakes_hasher(struct libhashsum_hasher *this, size_t hashbits); + +/** + * Create an initialised state for BLAKE384 (BLAKE, BLAKEb) + * hashing and return hash functions and details + * + * @param this The output parameter for the functions, details, and state + * @return 0 on success, -1 on failure + * + * @throws ENOSYS Support was excluded at compile time + * + * @since 1.0 + */ +LIBHASHSUM_1_NONNULL_ +int libhashsum_init_blake384_hasher(struct libhashsum_hasher *this); + +/** + * Create an initialised state for BLAKE512 (BLAKE, BLAKEb) + * hashing and return hash functions and details + * + * @param this The output parameter for the functions, details, and state + * @return 0 on success, -1 on failure + * + * @throws ENOSYS Support was excluded at compile time + * + * @since 1.0 + */ +LIBHASHSUM_1_NONNULL_ +int libhashsum_init_blake512_hasher(struct libhashsum_hasher *this); + +/** + * Create an initialised state for BLAKEb (BLAKE) + * hashing and return hash functions and details + * + * @param this The output parameter for the functions, details, and state + * @param hashbits Hash output size in bits + * @return 0 on success, -1 on failure + * + * @throws EINVAL `hashbits` is invalid (neither 384 nor 512) + * @throws ENOSYS Support was excluded at compile time + * + * @since 1.0 + */ +LIBHASHSUM_1_NONNULL_ +int libhashsum_init_blakeb_hasher(struct libhashsum_hasher *this, size_t hashbits); + +/** + * Create an initialised state for BLAKE + * hashing and return hash functions and details + * + * @param this The output parameter for the functions, details, and state + * @param hashbits Hash output size in bits + * @return 0 on success, -1 on failure + * + * @throws EINVAL `hashbits` is invalid (neither 224, 256, 384, nor 512) + * @throws ENOSYS Support was excluded at compile time + * + * @since 1.0 + */ +LIBHASHSUM_1_NONNULL_ +int libhashsum_init_blake_hasher(struct libhashsum_hasher *this, size_t hashbits); + #endif diff --git a/libhashsum_init_blake224_hasher.c b/libhashsum_init_blake224_hasher.c new file mode 100644 index 0000000..65d0ee1 --- /dev/null +++ b/libhashsum_init_blake224_hasher.c @@ -0,0 +1,98 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifdef SUPPORT_BLAKE224 + + +LIBHASHSUM_1_NONNULL_ +static size_t +process(struct libhashsum_hasher *this, const void *data, size_t bytes) +{ + return libblake_blake224_update(&this->state.blake224.s, data, bytes); +} + + +LIBHASHSUM_1_NONNULL_ +static int +finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, unsigned extra_bits) +{ + const uint8_t *m = data; + size_t r; + + if (extra_bits > 7U) { + errno = EINVAL; + return -1; + } + + r = libblake_blake224_update(&this->state.blake224.s, data, bytes); + m = &m[r]; + bytes -= r; + + memcpy(this->state.blake224.buf, m, bytes + (size_t)(extra_bits > 0U)); + if (extra_bits) + this->state.blake224.buf[bytes] = libhashsum_reverse_byte__(this->state.blake224.buf[bytes]); + libblake_blake224_digest(&this->state.blake224.s, this->state.blake224.buf, bytes, + extra_bits, NULL, this->state.blake224.buf); + memset(&this->state.blake224.s, 0, sizeof(this->state.blake224.s)); + this->hash_output = this->state.blake224.buf; + return 0; +} + + +LIBHASHSUM_1_NONNULL_ +static int +finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extra_bits, size_t size) +{ + uint8_t *m = data; + size_t r; + + if (extra_bits > 7U) { + errno = EINVAL; + return -1; + } + + r = libblake_blake224_update(&this->state.blake224.s, data, bytes); + m = &m[r]; + bytes -= r; + size -= r; + + if (size < libblake_blake224_digest_get_required_input_size(bytes, extra_bits, NULL)) { + memcpy(this->state.blake224.buf, m, bytes + (size_t)(extra_bits > 0U)); + m = this->state.blake224.buf; + } + if (extra_bits) + m[bytes] = libhashsum_reverse_byte__(m[bytes]); + libblake_blake224_digest(&this->state.blake224.s, m, bytes, extra_bits, NULL, this->state.blake224.buf); + memset(&this->state.blake224.s, 0, sizeof(this->state.blake224.s)); + this->hash_output = this->state.blake224.buf; + return 0; +} + + +int +libhashsum_init_blake224_hasher(struct libhashsum_hasher *this) +{ + libblake_init(); + this->algorithm = LIBHASHSUM_BLAKE224; + this->algorithm_string = "BLAKE224"; + this->input_block_size = 64U; + this->hash_size = LIBHASHSUM_BLAKE224_HASH_SIZE; + this->hash_output = NULL; + this->supports_non_whole_bytes = 1; + this->process = &process; + this->finalise_const = &finalise_const; + this->finalise = &finalise; + this->destroy = NULL; + libblake_blake224_init2(&this->state.blake224.s, NULL); + return 0; +} + + +#else +int +libhashsum_init_blake224_hasher(struct libhashsum_hasher *this) +{ + (void) this; + errno = ENOSYS; + return -1; +} +#endif diff --git a/libhashsum_init_blake256_hasher.c b/libhashsum_init_blake256_hasher.c new file mode 100644 index 0000000..202dc37 --- /dev/null +++ b/libhashsum_init_blake256_hasher.c @@ -0,0 +1,98 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifdef SUPPORT_BLAKE256 + + +LIBHASHSUM_1_NONNULL_ +static size_t +process(struct libhashsum_hasher *this, const void *data, size_t bytes) +{ + return libblake_blake256_update(&this->state.blake256.s, data, bytes); +} + + +LIBHASHSUM_1_NONNULL_ +static int +finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, unsigned extra_bits) +{ + const uint8_t *m = data; + size_t r; + + if (extra_bits > 7U) { + errno = EINVAL; + return -1; + } + + r = libblake_blake256_update(&this->state.blake256.s, data, bytes); + m = &m[r]; + bytes -= r; + + memcpy(this->state.blake256.buf, m, bytes + (size_t)(extra_bits > 0U)); + if (extra_bits) + this->state.blake256.buf[bytes] = libhashsum_reverse_byte__(this->state.blake256.buf[bytes]); + libblake_blake256_digest(&this->state.blake256.s, this->state.blake256.buf, bytes, + extra_bits, NULL, this->state.blake256.buf); + memset(&this->state.blake256.s, 0, sizeof(this->state.blake256.s)); + this->hash_output = this->state.blake256.buf; + return 0; +} + + +LIBHASHSUM_1_NONNULL_ +static int +finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extra_bits, size_t size) +{ + uint8_t *m = data; + size_t r; + + if (extra_bits > 7U) { + errno = EINVAL; + return -1; + } + + r = libblake_blake256_update(&this->state.blake256.s, data, bytes); + m = &m[r]; + bytes -= r; + size -= r; + + if (size < libblake_blake256_digest_get_required_input_size(bytes, extra_bits, NULL)) { + memcpy(this->state.blake256.buf, m, bytes + (size_t)(extra_bits > 0U)); + m = this->state.blake256.buf; + } + if (extra_bits) + m[bytes] = libhashsum_reverse_byte__(m[bytes]); + libblake_blake256_digest(&this->state.blake256.s, m, bytes, extra_bits, NULL, this->state.blake256.buf); + memset(&this->state.blake256.s, 0, sizeof(this->state.blake256.s)); + this->hash_output = this->state.blake256.buf; + return 0; +} + + +int +libhashsum_init_blake256_hasher(struct libhashsum_hasher *this) +{ + libblake_init(); + this->algorithm = LIBHASHSUM_BLAKE256; + this->algorithm_string = "BLAKE256"; + this->input_block_size = 64U; + this->hash_size = LIBHASHSUM_BLAKE256_HASH_SIZE; + this->hash_output = NULL; + this->supports_non_whole_bytes = 1; + this->process = &process; + this->finalise_const = &finalise_const; + this->finalise = &finalise; + this->destroy = NULL; + libblake_blake256_init2(&this->state.blake256.s, NULL); + return 0; +} + + +#else +int +libhashsum_init_blake256_hasher(struct libhashsum_hasher *this) +{ + (void) this; + errno = ENOSYS; + return -1; +} +#endif diff --git a/libhashsum_init_blake384_hasher.c b/libhashsum_init_blake384_hasher.c new file mode 100644 index 0000000..6f92c6c --- /dev/null +++ b/libhashsum_init_blake384_hasher.c @@ -0,0 +1,98 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifdef SUPPORT_BLAKE384 + + +LIBHASHSUM_1_NONNULL_ +static size_t +process(struct libhashsum_hasher *this, const void *data, size_t bytes) +{ + return libblake_blake384_update(&this->state.blake384.s, data, bytes); +} + + +LIBHASHSUM_1_NONNULL_ +static int +finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, unsigned extra_bits) +{ + const uint8_t *m = data; + size_t r; + + if (extra_bits > 7U) { + errno = EINVAL; + return -1; + } + + r = libblake_blake384_update(&this->state.blake384.s, data, bytes); + m = &m[r]; + bytes -= r; + + memcpy(this->state.blake384.buf, m, bytes + (size_t)(extra_bits > 0U)); + if (extra_bits) + this->state.blake384.buf[bytes] = libhashsum_reverse_byte__(this->state.blake384.buf[bytes]); + libblake_blake384_digest(&this->state.blake384.s, this->state.blake384.buf, bytes, + extra_bits, NULL, this->state.blake384.buf); + memset(&this->state.blake384.s, 0, sizeof(this->state.blake384.s)); + this->hash_output = this->state.blake384.buf; + return 0; +} + + +LIBHASHSUM_1_NONNULL_ +static int +finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extra_bits, size_t size) +{ + uint8_t *m = data; + size_t r; + + if (extra_bits > 7U) { + errno = EINVAL; + return -1; + } + + r = libblake_blake384_update(&this->state.blake384.s, data, bytes); + m = &m[r]; + bytes -= r; + size -= r; + + if (size < libblake_blake384_digest_get_required_input_size(bytes, extra_bits, NULL)) { + memcpy(this->state.blake384.buf, m, bytes + (size_t)(extra_bits > 0U)); + m = this->state.blake384.buf; + } + if (extra_bits) + m[bytes] = libhashsum_reverse_byte__(m[bytes]); + libblake_blake384_digest(&this->state.blake384.s, m, bytes, extra_bits, NULL, this->state.blake384.buf); + memset(&this->state.blake384.s, 0, sizeof(this->state.blake384.s)); + this->hash_output = this->state.blake384.buf; + return 0; +} + + +int +libhashsum_init_blake384_hasher(struct libhashsum_hasher *this) +{ + libblake_init(); + this->algorithm = LIBHASHSUM_BLAKE384; + this->algorithm_string = "BLAKE384"; + this->input_block_size = 128U; + this->hash_size = LIBHASHSUM_BLAKE384_HASH_SIZE; + this->hash_output = NULL; + this->supports_non_whole_bytes = 1; + this->process = &process; + this->finalise_const = &finalise_const; + this->finalise = &finalise; + this->destroy = NULL; + libblake_blake384_init2(&this->state.blake384.s, NULL); + return 0; +} + + +#else +int +libhashsum_init_blake384_hasher(struct libhashsum_hasher *this) +{ + (void) this; + errno = ENOSYS; + return -1; +} +#endif diff --git a/libhashsum_init_blake512_hasher.c b/libhashsum_init_blake512_hasher.c new file mode 100644 index 0000000..b1d2c13 --- /dev/null +++ b/libhashsum_init_blake512_hasher.c @@ -0,0 +1,98 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifdef SUPPORT_BLAKE512 + + +LIBHASHSUM_1_NONNULL_ +static size_t +process(struct libhashsum_hasher *this, const void *data, size_t bytes) +{ + return libblake_blake512_update(&this->state.blake512.s, data, bytes); +} + + +LIBHASHSUM_1_NONNULL_ +static int +finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, unsigned extra_bits) +{ + const uint8_t *m = data; + size_t r; + + if (extra_bits > 7U) { + errno = EINVAL; + return -1; + } + + r = libblake_blake512_update(&this->state.blake512.s, data, bytes); + m = &m[r]; + bytes -= r; + + memcpy(this->state.blake512.buf, m, bytes + (size_t)(extra_bits > 0U)); + if (extra_bits) + this->state.blake512.buf[bytes] = libhashsum_reverse_byte__(this->state.blake512.buf[bytes]); + libblake_blake512_digest(&this->state.blake512.s, this->state.blake512.buf, bytes, + extra_bits, NULL, this->state.blake512.buf); + memset(&this->state.blake512.s, 0, sizeof(this->state.blake512.s)); + this->hash_output = this->state.blake512.buf; + return 0; +} + + +LIBHASHSUM_1_NONNULL_ +static int +finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extra_bits, size_t size) +{ + uint8_t *m = data; + size_t r; + + if (extra_bits > 7U) { + errno = EINVAL; + return -1; + } + + r = libblake_blake512_update(&this->state.blake512.s, data, bytes); + m = &m[r]; + bytes -= r; + size -= r; + + if (size < libblake_blake512_digest_get_required_input_size(bytes, extra_bits, NULL)) { + memcpy(this->state.blake512.buf, m, bytes + (size_t)(extra_bits > 0U)); + m = this->state.blake512.buf; + } + if (extra_bits) + m[bytes] = libhashsum_reverse_byte__(m[bytes]); + libblake_blake512_digest(&this->state.blake512.s, m, bytes, extra_bits, NULL, this->state.blake512.buf); + memset(&this->state.blake512.s, 0, sizeof(this->state.blake512.s)); + this->hash_output = this->state.blake512.buf; + return 0; +} + + +int +libhashsum_init_blake512_hasher(struct libhashsum_hasher *this) +{ + libblake_init(); + this->algorithm = LIBHASHSUM_BLAKE512; + this->algorithm_string = "BLAKE512"; + this->input_block_size = 128U; + this->hash_size = LIBHASHSUM_BLAKE512_HASH_SIZE; + this->hash_output = NULL; + this->supports_non_whole_bytes = 1; + this->process = &process; + this->finalise_const = &finalise_const; + this->finalise = &finalise; + this->destroy = NULL; + libblake_blake512_init2(&this->state.blake512.s, NULL); + return 0; +} + + +#else +int +libhashsum_init_blake512_hasher(struct libhashsum_hasher *this) +{ + (void) this; + errno = ENOSYS; + return -1; +} +#endif diff --git a/libhashsum_init_blake_hasher.c b/libhashsum_init_blake_hasher.c new file mode 100644 index 0000000..645ab95 --- /dev/null +++ b/libhashsum_init_blake_hasher.c @@ -0,0 +1,32 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifdef SUPPORT_BLAKEB + + +int +libhashsum_init_blake_hasher(struct libhashsum_hasher *this, size_t hashbits) +{ + if (hashbits == 224U) + return libhashsum_init_blake224_hasher(this); + if (hashbits == 256U) + return libhashsum_init_blake256_hasher(this); + if (hashbits == 384U) + return libhashsum_init_blake384_hasher(this); + if (hashbits == 512U) + return libhashsum_init_blake512_hasher(this); + + errno = EINVAL; + return -1; +} + + +#else +int +libhashsum_init_blake_hasher(struct libhashsum_hasher *this, size_t hashbits) +{ + (void) this; + (void) hashbits; + errno = ENOSYS; + return -1; +} +#endif diff --git a/libhashsum_init_blakeb_hasher.c b/libhashsum_init_blakeb_hasher.c new file mode 100644 index 0000000..417553b --- /dev/null +++ b/libhashsum_init_blakeb_hasher.c @@ -0,0 +1,28 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifdef SUPPORT_BLAKEB + + +int +libhashsum_init_blakeb_hasher(struct libhashsum_hasher *this, size_t hashbits) +{ + if (hashbits == 384U) + return libhashsum_init_blake384_hasher(this); + if (hashbits == 512U) + return libhashsum_init_blake512_hasher(this); + + errno = EINVAL; + return -1; +} + + +#else +int +libhashsum_init_blakeb_hasher(struct libhashsum_hasher *this, size_t hashbits) +{ + (void) this; + (void) hashbits; + errno = ENOSYS; + return -1; +} +#endif diff --git a/libhashsum_init_blakes_hasher.c b/libhashsum_init_blakes_hasher.c new file mode 100644 index 0000000..f5e7c20 --- /dev/null +++ b/libhashsum_init_blakes_hasher.c @@ -0,0 +1,28 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifdef SUPPORT_BLAKES + + +int +libhashsum_init_blakes_hasher(struct libhashsum_hasher *this, size_t hashbits) +{ + if (hashbits == 224U) + return libhashsum_init_blake224_hasher(this); + if (hashbits == 256U) + return libhashsum_init_blake256_hasher(this); + + errno = EINVAL; + return -1; +} + + +#else +int +libhashsum_init_blakes_hasher(struct libhashsum_hasher *this, size_t hashbits) +{ + (void) this; + (void) hashbits; + errno = ENOSYS; + return -1; +} +#endif diff --git a/libhashsum_init_hasher.c b/libhashsum_init_hasher.c index 3d8a521..ab44ac1 100644 --- a/libhashsum_init_hasher.c +++ b/libhashsum_init_hasher.c @@ -64,6 +64,14 @@ libhashsum_init_hasher(struct libhashsum_hasher *this, enum libhashsum_algorithm return libhashsum_init_rawshake256_hasher(this, 0); case LIBHASHSUM_RAWSHAKE512: return libhashsum_init_rawshake512_hasher(this, 0); + case LIBHASHSUM_BLAKE224: + return libhashsum_init_blake224_hasher(this); + case LIBHASHSUM_BLAKE256: + return libhashsum_init_blake256_hasher(this); + case LIBHASHSUM_BLAKE384: + return libhashsum_init_blake384_hasher(this); + case LIBHASHSUM_BLAKE512: + return libhashsum_init_blake512_hasher(this); default: case LIBHASHSUM_KECCAK: errno = EINVAL; diff --git a/libhashsum_init_hasher_from_string.c b/libhashsum_init_hasher_from_string.c index 30526da..9a53864 100644 --- a/libhashsum_init_hasher_from_string.c +++ b/libhashsum_init_hasher_from_string.c @@ -180,6 +180,14 @@ libhashsum_init_hasher_from_string(struct libhashsum_hasher *this, const char *a return with_n(&libhashsum_init_rawshake512_hasher, this, algorithm); if (equiv(algorithm, "Keccak[")) return with_rcn(&libhashsum_init_keccak_hasher, this, algorithm); + if (equiv(algorithm, "BLAKE-224")) + return libhashsum_init_blake224_hasher(this); + if (equiv(algorithm, "BLAKE-256")) + return libhashsum_init_blake256_hasher(this); + if (equiv(algorithm, "BLAKE-384")) + return libhashsum_init_blake384_hasher(this); + if (equiv(algorithm, "BLAKE-512")) + return libhashsum_init_blake512_hasher(this); errno = EINVAL; return -1; |