aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-08-24 20:39:01 +0200
committerMattias Andrée <maandree@kth.se>2024-08-24 20:39:01 +0200
commit2bc752da4a803cf6c03fb84bb90bc6e468981526 (patch)
tree5223412269afd9af411f918b51a66a433f235af0 /libhashsum.h
parentAdd BLAKE via libblake>=1.1 (this version introduced libblake_init()) (diff)
downloadlibhashsum-2bc752da4a803cf6c03fb84bb90bc6e468981526.tar.gz
libhashsum-2bc752da4a803cf6c03fb84bb90bc6e468981526.tar.bz2
libhashsum-2bc752da4a803cf6c03fb84bb90bc6e468981526.tar.xz
Add support for salt for BLAKE
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libhashsum.h')
-rw-r--r--libhashsum.h44
1 files changed, 30 insertions, 14 deletions
diff --git a/libhashsum.h b/libhashsum.h
index d85dadd..00fbb17 100644
--- a/libhashsum.h
+++ b/libhashsum.h
@@ -424,22 +424,26 @@ union libhashsum_state {
struct {
struct libblake_blake224_state s;
uint8_t buf[128];
- } blake224; /* size = 184 */
+ char algostr[49];
+ } blake224; /* size = 233 */
struct {
struct libblake_blake256_state s;
uint8_t buf[128];
- } blake256; /* size = 184 */
+ char algostr[49];
+ } blake256; /* size = 233 */
struct {
struct libblake_blake384_state s;
uint8_t buf[256];
- } blake384; /* size = 368 */
+ char algostr[81];
+ } blake384; /* size = 449 */
struct {
struct libblake_blake512_state s;
uint8_t buf[256];
- } blake512; /* size = 368 */
+ char algostr[81];
+ } blake512; /* size = 449 */
#endif
/* libblake: 48(2s), 96(2b), 144(2Xs), 276(2Xb) */
@@ -1180,6 +1184,7 @@ int libhashsum_init_rawshake_hasher(struct libhashsum_hasher *this, size_t hcapb
* hashing and return hash functions and details
*
* @param this The output parameter for the functions, details, and state
+ * @param salt `NULL` (for all zeroes) or a 16-byte salt
* @return 0 on success, -1 on failure
*
* @throws ENOSYS Support was excluded at compile time
@@ -1187,13 +1192,14 @@ int libhashsum_init_rawshake_hasher(struct libhashsum_hasher *this, size_t hcapb
* @since 1.0
*/
LIBHASHSUM_1_NONNULL_
-int libhashsum_init_blake224_hasher(struct libhashsum_hasher *this);
+int libhashsum_init_blake224_hasher(struct libhashsum_hasher *this, const void *salt);
/**
* 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
+ * @param salt `NULL` (for all zeroes) or a 16-byte salt
* @return 0 on success, -1 on failure
*
* @throws ENOSYS Support was excluded at compile time
@@ -1201,7 +1207,7 @@ int libhashsum_init_blake224_hasher(struct libhashsum_hasher *this);
* @since 1.0
*/
LIBHASHSUM_1_NONNULL_
-int libhashsum_init_blake256_hasher(struct libhashsum_hasher *this);
+int libhashsum_init_blake256_hasher(struct libhashsum_hasher *this, const void *salt);
/**
* Create an initialised state for BLAKEs (BLAKE)
@@ -1209,6 +1215,7 @@ int libhashsum_init_blake256_hasher(struct libhashsum_hasher *this);
*
* @param this The output parameter for the functions, details, and state
* @param hashbits Hash output size in bits
+ * @param salt `NULL` (for all zeroes) or a 16-byte salt
* @return 0 on success, -1 on failure
*
* @throws EINVAL `hashbits` is invalid (neither 224 nor 256)
@@ -1217,13 +1224,14 @@ int libhashsum_init_blake256_hasher(struct libhashsum_hasher *this);
* @since 1.0
*/
LIBHASHSUM_1_NONNULL_
-int libhashsum_init_blakes_hasher(struct libhashsum_hasher *this, size_t hashbits);
+int libhashsum_init_blakes_hasher(struct libhashsum_hasher *this, size_t hashbits, const void *salt);
/**
* 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
+ * @param salt `NULL` (for all zeroes) or a 32-byte salt
* @return 0 on success, -1 on failure
*
* @throws ENOSYS Support was excluded at compile time
@@ -1231,13 +1239,14 @@ int libhashsum_init_blakes_hasher(struct libhashsum_hasher *this, size_t hashbit
* @since 1.0
*/
LIBHASHSUM_1_NONNULL_
-int libhashsum_init_blake384_hasher(struct libhashsum_hasher *this);
+int libhashsum_init_blake384_hasher(struct libhashsum_hasher *this, const void *salt);
/**
* 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
+ * @param salt `NULL` (for all zeroes) or a 32-byte salt
* @return 0 on success, -1 on failure
*
* @throws ENOSYS Support was excluded at compile time
@@ -1245,7 +1254,7 @@ int libhashsum_init_blake384_hasher(struct libhashsum_hasher *this);
* @since 1.0
*/
LIBHASHSUM_1_NONNULL_
-int libhashsum_init_blake512_hasher(struct libhashsum_hasher *this);
+int libhashsum_init_blake512_hasher(struct libhashsum_hasher *this, const void *salt);
/**
* Create an initialised state for BLAKEb (BLAKE)
@@ -1253,6 +1262,7 @@ int libhashsum_init_blake512_hasher(struct libhashsum_hasher *this);
*
* @param this The output parameter for the functions, details, and state
* @param hashbits Hash output size in bits
+ * @param salt `NULL` (for all zeroes) or a 32-byte salt
* @return 0 on success, -1 on failure
*
* @throws EINVAL `hashbits` is invalid (neither 384 nor 512)
@@ -1261,23 +1271,29 @@ int libhashsum_init_blake512_hasher(struct libhashsum_hasher *this);
* @since 1.0
*/
LIBHASHSUM_1_NONNULL_
-int libhashsum_init_blakeb_hasher(struct libhashsum_hasher *this, size_t hashbits);
+int libhashsum_init_blakeb_hasher(struct libhashsum_hasher *this, size_t hashbits, const void *salt);
/**
* 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
+ * @param this The output parameter for the functions, details, and state
+ * @param hashbits Hash output size in bits
+ * @param salt `NULL` (for all zeroes) or a salt
+ * @parma saltbytes The number of bytes in `salt` (ignored if `salt` is `NULL`),
+ * shall be 16 for if `hashbits` is 224 or 256, and 32 if
+ * `hashbits` is 384 or 512
+ * @return 0 on success, -1 on failure
*
* @throws EINVAL `hashbits` is invalid (neither 224, 256, 384, nor 512)
+ * @throws EINVAL `salt` is not `NULL` but `saltbytes` does not match
+ * the expected value for the input `hashbits`
* @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);
+int libhashsum_init_blake_hasher(struct libhashsum_hasher *this, size_t hashbits, const void *salt, size_t saltbytes);
#endif