diff options
Diffstat (limited to 'libhashsum.h')
-rw-r--r-- | libhashsum.h | 169 |
1 files changed, 165 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 |