all repos — TinyCrypT @ 157aae0362d97e06e1e0c7562d7b79e4b19d5b6c

Short and sweet classical cryptographic primitives

Expose TurboSHAKE128 API publicly
Juniper Beatitudes [email protected]
Sat, 18 Jul 2026 19:59:21 -0500
commit

157aae0362d97e06e1e0c7562d7b79e4b19d5b6c

parent

15791d38c8f011a16648742e77b25435ee93ab76

2 files changed, 38 insertions(+), 21 deletions(-)

jump to
M tinycrypt/kangarootwelve128.htinycrypt/kangarootwelve128.h

@@ -8,4 +8,20 @@ void tct_kangarootwelve128 (const uint8_t *input, const uint64_t input_len,

const uint8_t *custom_str, const uint64_t cs_len, uint8_t *output, const uint64_t output_len); +#define TCT_TURBOSHAKE128_STATE_LEN 200 + +/// Initialize TurboSHAKE128 state +void tct_turboshake128_init (uint8_t state[TCT_TURBOSHAKE128_STATE_LEN]); + +/// Absorb new data into the TurboSHAKE128 state +void tct_turboshake128_absorb (uint8_t state[TCT_TURBOSHAKE128_STATE_LEN], + const uint8_t *data, const uint64_t data_len, + const uint8_t separation_byte); + +/// Squeeze new hashed data out of the TurboSHAKE128 state, destructively (to +/// the state) +void tct_turboshake128_squeeze_destructive ( + uint8_t state[TCT_TURBOSHAKE128_STATE_LEN], uint8_t *output, + const uint64_t output_len); + #endif
M tinycrypt/portable/kangarootwelve128.ctinycrypt/portable/kangarootwelve128.c

@@ -117,18 +117,19 @@ }

} } -static void -turboshake128_init (uint8_t *state) +void +tct_turboshake128_init (uint8_t state[TCT_TURBOSHAKE128_STATE_LEN]) { - for (unsigned int i = 0; i < 200; ++i) + for (unsigned int i = 0; i < TCT_TURBOSHAKE128_STATE_LEN; ++i) { state[i] = 0x0; } } -static void -turboshake128_absorb (uint8_t *state, const uint8_t *data, - const uint64_t data_len, const uint8_t separation_byte) +void +tct_turboshake128_absorb (uint8_t state[TCT_TURBOSHAKE128_STATE_LEN], const uint8_t *data, + const uint64_t data_len, + const uint8_t separation_byte) { for (unsigned int i = 0; i < data_len; ++i) {

@@ -142,9 +143,9 @@ }

kp (state); } -static void -turboshake128_squeeze_destructive (uint8_t *state, uint8_t *output, - const uint64_t output_len) +void +tct_turboshake128_squeeze_destructive (uint8_t state[TCT_TURBOSHAKE128_STATE_LEN], uint8_t *output, + const uint64_t output_len) { for (uint64_t i = 0; i < output_len; i += 168) {

@@ -178,8 +179,8 @@ const uint8_t *custom_str, const uint64_t cs_len,

uint8_t *output, const uint64_t output_len) { uint8_t buf[168]; - uint8_t state[200]; - turboshake128_init (state); + uint8_t state[TCT_TURBOSHAKE128_STATE_LEN]; + tct_turboshake128_init (state); uint8_t encoded[16]; uint64_t encoded_len; length_encode (cs_len, encoded, &encoded_len);

@@ -204,9 +205,9 @@ {

buf[j] = encoded[i + j - input_len - cs_len]; } } - turboshake128_absorb (state, buf, buf_len, 0x07); + tct_turboshake128_absorb (state, buf, buf_len, 0x07); } - turboshake128_squeeze_destructive (state, output, output_len); + tct_turboshake128_squeeze_destructive (state, output, output_len); return; } uint64_t buf_len;

@@ -241,7 +242,7 @@ }

} if (buf_len == 168) { - turboshake128_absorb (state, buf, 168, 0x06); + tct_turboshake128_absorb (state, buf, 168, 0x06); } } uint64_t offset = 8192;

@@ -252,7 +253,7 @@ uint64_t block_size = (8192 < s_size - offset) ? 8192 : s_size - offset;

uint8_t cv[32]; uint8_t cv_buf[168]; uint8_t cv_state[200]; - turboshake128_init (cv_state); + tct_turboshake128_init (cv_state); for (uint64_t i = offset; i < offset + block_size; i += 168) { uint64_t cv_block_size = (168 < offset + block_size - i)

@@ -273,16 +274,16 @@ {

cv_buf[j] = encoded[i + j - input_len - cs_len]; } } - turboshake128_absorb (cv_state, cv_buf, cv_block_size, 0x0B); + tct_turboshake128_absorb (cv_state, cv_buf, cv_block_size, 0x0B); } - turboshake128_squeeze_destructive (cv_state, cv, 32); + tct_turboshake128_squeeze_destructive (cv_state, cv, 32); if (buf_len + 32 >= 168) { for (unsigned int i = buf_len; i < 168; ++i) { buf[i] = cv[i - buf_len]; } - turboshake128_absorb (state, buf, 168, 0x06); + tct_turboshake128_absorb (state, buf, 168, 0x06); for (unsigned int i = (buf_len + 32) - 168; i < 32; ++i) { buf[i] = cv[i];

@@ -316,7 +317,7 @@ {

buf[i] = 0xFF; } } - turboshake128_absorb (state, buf, 168, 0x06); + tct_turboshake128_absorb (state, buf, 168, 0x06); for (unsigned int i = (buf_len + nb_encoded_size + 2) - 168; i < nb_encoded_size + 2; ++i)

@@ -347,6 +348,6 @@ }

} buf_len += nb_encoded_size + 2; } - turboshake128_absorb (state, buf, buf_len, 0x06); - turboshake128_squeeze_destructive (state, output, output_len); + tct_turboshake128_absorb (state, buf, buf_len, 0x06); + tct_turboshake128_squeeze_destructive (state, output, output_len); }