aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2023-09-05 21:18:49 -0400
committerPaul Duncan <pabs@pablotron.org>2023-09-05 21:18:49 -0400
commitabb8f678231d2af34b51bf1cb7fd853e123cefee (patch)
tree1ced9c0e7222e08e97c24b8b3b02c3dfefefb4f3
parent671ef72433a6ea5420ae61dad8128034bccc7d1d (diff)
downloadsha3-abb8f678231d2af34b51bf1cb7fd853e123cefee.tar.bz2
sha3-abb8f678231d2af34b51bf1cb7fd853e123cefee.zip
sha3.[hc]: add turboshake{128,256}_custom()
-rw-r--r--sha3.c10
-rw-r--r--sha3.h32
2 files changed, 41 insertions, 1 deletions
diff --git a/sha3.c b/sha3.c
index 8dbc60b..88c83cb 100644
--- a/sha3.c
+++ b/sha3.c
@@ -1695,7 +1695,7 @@ void parallelhash256_xof_once(const parallelhash_params_t params, const uint8_t
// default turboshake pad byte (can be customized for domain separation)
#define TURBOSHAKE_PAD 0x1f
-// init turboeshake context with given pad byte. returns false if the
+// init turboshake context with given pad byte. returns false if the
// pad byte is out of range.
static inline _Bool turboshake_init(turboshake_t * const ts, const uint8_t pad) {
// check for valid pad
@@ -1736,6 +1736,10 @@ void turboshake128(const uint8_t * const src, const size_t src_len, uint8_t * co
xof_once(SHAKE128_XOF_RATE, TURBOSHAKE_NUM_ROUNDS, TURBOSHAKE_PAD, src, src_len, dst, dst_len);
}
+void turboshake128_custom(const uint8_t pad, const uint8_t * const src, const size_t src_len, uint8_t * const dst, const size_t dst_len) {
+ xof_once(SHAKE128_XOF_RATE, TURBOSHAKE_NUM_ROUNDS, pad, src, src_len, dst, dst_len);
+}
+
_Bool turboshake256_init_custom(turboshake_t * const ts, const uint8_t pad) {
return turboshake_init(ts, pad);
}
@@ -1756,6 +1760,10 @@ void turboshake256(const uint8_t * const src, const size_t src_len, uint8_t * co
xof_once(SHAKE256_XOF_RATE, TURBOSHAKE_NUM_ROUNDS, TURBOSHAKE_PAD, src, src_len, dst, dst_len);
}
+void turboshake256_custom(const uint8_t pad, const uint8_t * const src, const size_t src_len, uint8_t * const dst, const size_t dst_len) {
+ xof_once(SHAKE256_XOF_RATE, TURBOSHAKE_NUM_ROUNDS, pad, src, src_len, dst, dst_len);
+}
+
#ifdef SHA3_TEST
#include <stdio.h> // printf()
diff --git a/sha3.h b/sha3.h
index 6ca8922..4f1ce06 100644
--- a/sha3.h
+++ b/sha3.h
@@ -1156,6 +1156,22 @@ void parallelhash256_xof_once(const parallelhash_params_t params, const uint8_t
void turboshake128(const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len);
/**
+ * Initialize internal TurboSHAKE128 context with custom padding byte
+ * `pad`, absorb `src_len` bytes of input from in source buffer `src`,
+ * then squeeze `dst_len` bytes of output into destination buffer `dst`.
+ *
+ * Note: The padding byte value must be in the range [0x01, 0x7F] and
+ * can be used for domain separation.
+ *
+ * @param[in] pad Padding byte.
+ * @param[in] src Source buffer.
+ * @param[in] src_len Source buffer length, in bytes.
+ * @param[out] dst Destination buffer.
+ * @param[in] dst_len Destination buffer length, in bytes.
+ */
+void turboshake128_custom(const uint8_t pad, const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len);
+
+/**
* Initialize internal TurboSHAKE256 context, absorb `src_len` bytes of
* input from in source buffer `src`, then squeeze `dst_len` bytes of output
* into destination buffer `dst`.
@@ -1167,6 +1183,22 @@ void turboshake128(const uint8_t *src, const size_t src_len, uint8_t *dst, const
*/
void turboshake256(const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len);
+/**
+ * Initialize internal TurboSHAKE256 context with custom padding byte
+ * `pad`, absorb `src_len` bytes of input from in source buffer `src`,
+ * then squeeze `dst_len` bytes of output into destination buffer `dst`.
+ *
+ * Note: The padding byte value must be in the range [0x01, 0x7F] and
+ * can be used for domain separation.
+ *
+ * @param[in] pad Padding byte.
+ * @param[in] src Source buffer.
+ * @param[in] src_len Source buffer length, in bytes.
+ * @param[out] dst Destination buffer.
+ * @param[in] dst_len Destination buffer length, in bytes.
+ */
+void turboshake256_custom(const uint8_t pad, const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len);
+
// TurboShake XOF context.
typedef struct {
sha3_xof_t xof;