aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-09-01 16:34:46 +0200
committerMattias Andrée <maandree@kth.se>2024-09-01 16:34:46 +0200
commitd737d34b436f673173695c4c772f0ddef9fe7837 (patch)
treef6bf400809124d411eaff38fe2c9d24842c8d23a /libhashsum.h
parentm fix (diff)
downloadlibhashsum-d737d34b436f673173695c4c772f0ddef9fe7837.tar.gz
libhashsum-d737d34b436f673173695c4c772f0ddef9fe7837.tar.bz2
libhashsum-d737d34b436f673173695c4c772f0ddef9fe7837.tar.xz
Add support for BLAKE2 (but not tree-hashing)
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libhashsum.h')
-rw-r--r--libhashsum.h77
1 files changed, 76 insertions, 1 deletions
diff --git a/libhashsum.h b/libhashsum.h
index 780b567..777176b 100644
--- a/libhashsum.h
+++ b/libhashsum.h
@@ -186,6 +186,7 @@
/**
* The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHAKE256`
+ * (using default hash size)
*
* @since 1.0
*/
@@ -193,6 +194,7 @@
/**
* The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHAKE512`
+ * (using default hash size)
*
* @since 1.0
*/
@@ -200,6 +202,7 @@
/**
* The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_RAWSHAKE128`
+ * (using default hash size)
*
* @since 1.0
*/
@@ -207,6 +210,7 @@
/**
* The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_RAWSHAKE256`
+ * (using default hash size)
*
* @since 1.0
*/
@@ -214,6 +218,7 @@
/**
* The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_RAWSHAKE512`
+ * (using default hash size)
*
* @since 1.0
*/
@@ -247,6 +252,22 @@
*/
#define LIBHASHSUM_BLAKE512_HASH_SIZE 64
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_BLAKE2S`
+ * (using default/maximium hash size)
+ *
+ * @since 1.0
+ */
+#define LIBHASHSUM_BLAKE2S_HASH_SIZE 32
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_BLAKE2B`
+ * (using default/maximium hash size)
+ *
+ * @since 1.0
+ */
+#define LIBHASHSUM_BLAKE2B_HASH_SIZE 64
+
#if defined(__GNUC__)
# pragma GCC diagnostic push
@@ -297,7 +318,9 @@ enum libhashsum_algorithm {
LIBHASHSUM_BLAKE224, /**< BLAKE224 (BLAKE, BLAKEs) */
LIBHASHSUM_BLAKE256, /**< BLAKE256 (BLAKE, BLAKEs) */
LIBHASHSUM_BLAKE384, /**< BLAKE384 (BLAKE, BLAKEb) */
- LIBHASHSUM_BLAKE512 /**< BLAKE512 (BLAKE, BLAKEb) */
+ LIBHASHSUM_BLAKE512, /**< BLAKE512 (BLAKE, BLAKEb) */
+ LIBHASHSUM_BLAKE2S, /**< BLAKE2s (BLAKE2) */
+ LIBHASHSUM_BLAKE2B /**< BLAKE2b (BLAKE2) */
};
@@ -1214,5 +1237,57 @@ int libhashsum_init_blakeb_hasher(struct libhashsum_hasher *this, size_t hashbit
LIBHASHSUM_1_NONNULL_
int libhashsum_init_blake_hasher(struct libhashsum_hasher *this, size_t hashbits, const void *salt, size_t saltbytes);
+/**
+ * Create an initialised state for BLAKE2s (BLAKE2)
+ * 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, must be an multiple of 8 between
+ * 8 and 256 (inclusively), or 0 for the maximum size
+ * @param salt `NULL` (for all zeroes) or a 8-byte salt
+ * @param pepper `NULL` (for all zeroes) or a 8-byte pepper
+ * @param key Key or `NULL` for unkeyed mode,
+ * @param keybits The number of byts in `key` (0 if `key` is `NULL`),
+ * which must be a multiple of 8 no greater than 256
+ * @return 0 on success, -1 on failure
+ *
+ * @throws EINVAL `hashbits` is greater than 256
+ * @throws EINVAL `hashbits` is not a multiple of 8
+ * @throws EINVAL `keybits` is greater than 256
+ * @throws EINVAL `keybits` is not a multiple of 8
+ * @throws ENOSYS Support was excluded at compile time
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_blake2s_hasher(struct libhashsum_hasher *this, size_t hashbits, const void *salt, /* TODO man, test */
+ const void *pepper, const void *key, size_t keybits);
+
+/**
+ * Create an initialised state for BLAKE2b (BLAKE2)
+ * 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, must be an multiple of 8 between
+ * 8 and 512 (inclusively), or 0 for the maximum size
+ * @param salt `NULL` (for all zeroes) or a 16-byte salt
+ * @param pepper `NULL` (for all zeroes) or a 16-byte pepper
+ * @param key Key or `NULL` for unkeyed mode,
+ * @param keybits The number of byts in `key` (0 if `key` is `NULL`),
+ * which must be a multiple of 8 no greater than 512
+ * @return 0 on success, -1 on failure
+ *
+ * @throws EINVAL `hashbits` is greater than 512
+ * @throws EINVAL `hashbits` is not a multiple of 8
+ * @throws EINVAL `keybits` is greater than 512
+ * @throws EINVAL `keybits` is not a multiple of 8
+ * @throws ENOSYS Support was excluded at compile time
+ *
+ * @since 1.0
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_blake2b_hasher(struct libhashsum_hasher *this, size_t hashbits, const void *salt, /* TODO man, test */
+ const void *pepper, const void *key, size_t keybits);
+
#endif