libsodium_crypto_xof_turboshake128 (libsodium v3.0.1)

View Source

TurboSHAKE128 (RFC 9861) is an extendable-output function (XOF) with the same sponge and rate as SHAKE128 but using the Keccak-p[1600] permutation reduced to 12 rounds, roughly doubling its speed. It hashes an input of any length into an output of any requested length and targets 128-bit security.

init/0 and the one-shot function use the standard domain byte domain_standard/0 (16#1F). init_with_domain/1 selects another domain byte so that different uses of TurboSHAKE128 produce independent outputs; RFC 9861 defines domain bytes from 16#01 to 16#7F.

The streaming functions thread an opaque state/0 through init/0, update/2, and squeeze/2. Every call returns a new state and leaves its argument unchanged. Squeezing continues the output stream: consecutive squeeze/2 calls on the returned states produce the same bytes as one longer squeeze, so output can be read incrementally. Updates over large inputs yield to other processes between chunks.

Out = libsodium_crypto_xof_turboshake128:crypto_xof_turboshake128(32, <<"hello world">>),
32 = byte_size(Out),
State0 = libsodium_crypto_xof_turboshake128:init(),
State1 = libsodium_crypto_xof_turboshake128:update(State0, <<"hello ">>),
State2 = libsodium_crypto_xof_turboshake128:update(State1, <<"world">>),
{State3, First} = libsodium_crypto_xof_turboshake128:squeeze(State2, 16),
{_State4, Second} = libsodium_crypto_xof_turboshake128:squeeze(State3, 16),
Out = <<First/binary, Second/binary>>.

Summary

Types

An opaque native crypto_xof_turboshake128_state.

Functions

Return crypto_xof_turboshake128_blockbytes(), in bytes.

Hash In with TurboSHAKE128 and the standard domain byte, returning Outlen bytes of output.

Return crypto_xof_turboshake128_domain_standard().

Start a streaming TurboSHAKE128 hash with the standard domain byte domain_standard/0.

Start a streaming TurboSHAKE128 hash with the domain separation byte Domain (an integer from 0 to 255).

Read the next Outlen bytes of output from State.

Return crypto_xof_turboshake128_statebytes(), in bytes.

Absorb In into State and return the updated state.

Types

state()

An opaque native crypto_xof_turboshake128_state.

Operations never modify a state: each returns a new one, so earlier states remain valid and can be reused or shared between processes. States cannot be serialized; they exist only within the running VM.

Functions

blockbytes()

-spec blockbytes() -> Result when Result :: 168.

Return crypto_xof_turboshake128_blockbytes(), in bytes.

crypto_xof_turboshake128(Outlen, In)

-spec crypto_xof_turboshake128(Outlen, In) -> Result
                                  when
                                      Outlen :: non_neg_integer(),
                                      In :: binary(),
                                      Result :: binary() | -1.

Hash In with TurboSHAKE128 and the standard domain byte, returning Outlen bytes of output.

domain_standard()

-spec domain_standard() -> Result when Result :: 31.

Return crypto_xof_turboshake128_domain_standard().

init()

-spec init() -> Result when Result :: state() | -1.

Start a streaming TurboSHAKE128 hash with the standard domain byte domain_standard/0.

init_with_domain(Domain)

-spec init_with_domain(Domain) -> Result when Domain :: 0..255, Result :: state() | -1.

Start a streaming TurboSHAKE128 hash with the domain separation byte Domain (an integer from 0 to 255).

squeeze(State, Outlen)

-spec squeeze(State, Outlen) -> Result
                 when State :: state(), Outlen :: non_neg_integer(), Result :: {state(), binary()} | -1.

Read the next Outlen bytes of output from State.

Returns {NewState, Out}. Squeezing NewState again continues the output stream where Out ended, so successive squeezes produce the same bytes as a single longer one. State itself is unchanged and squeezing it again repeats Out.

statebytes()

-spec statebytes() -> Result when Result :: 256.

Return crypto_xof_turboshake128_statebytes(), in bytes.

update(State, In)

-spec update(State, In) -> Result when State :: state(), In :: binary(), Result :: state() | -1.

Absorb In into State and return the updated state.

Returns -1 if State has already been squeezed; absorbing after squeezing is not supported.