libsodium_crypto_core_keccak1600 (libsodium v3.0.1)
View SourceThe Keccak-f[1600] permutation underlying SHA-3, SHAKE, and TurboSHAKE.
This is a low-level primitive for building sponge and duplex
constructions; prefer libsodium_crypto_xof_shake128,
libsodium_crypto_xof_turboshake128, or their 256-bit variants for
hashing.
The permutation acts on a 200-byte (1600-bit) state held in an opaque
state/0. init/0 returns the all-zero state, xor_bytes/3 XORs
bytes into it at an offset, extract_bytes/3 reads bytes from it,
permute_24/1 applies the full 24-round Keccak-f[1600], and
permute_12/1 applies the 12-round Keccak-p[1600,12] used by
TurboSHAKE. Offsets and lengths must satisfy Offset + Length =< 200.
States are immutable values: every operation returns a new state and leaves its argument unchanged.
State0 = libsodium_crypto_core_keccak1600:init(),
State1 = libsodium_crypto_core_keccak1600:xor_bytes(State0, <<"abc", 16#1F>>, 0),
State2 = libsodium_crypto_core_keccak1600:xor_bytes(State1, <<16#80>>, 167),
State3 = libsodium_crypto_core_keccak1600:permute_24(State2),
Out = libsodium_crypto_core_keccak1600:extract_bytes(State3, 0, 32),
Out = crypto:hash_xof(shake128, <<"abc">>, 256).
Summary
Functions
Return Length bytes of State starting at byte Offset.
Offset + Length must not exceed 200.
Return the all-zero permutation state.
Apply the 12-round Keccak-p[1600,12] permutation used by TurboSHAKE
to State and return the new state.
Apply the 24-round Keccak-f[1600] permutation to State and return the new state.
Return crypto_core_keccak1600_statebytes(), in bytes.
XOR Bytes into State starting at byte Offset and return the
new state. Offset + byte_size(Bytes) must not exceed 200.
Types
-type state() :: libsodium_nif:crypto_core_keccak1600_state().
An opaque native crypto_core_keccak1600_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
-spec extract_bytes(State, Offset, Length) -> Result when State :: state(), Offset :: non_neg_integer(), Length :: non_neg_integer(), Result :: binary().
Return Length bytes of State starting at byte Offset.
Offset + Length must not exceed 200.
-spec init() -> Result when Result :: state().
Return the all-zero permutation state.
Apply the 12-round Keccak-p[1600,12] permutation used by TurboSHAKE
to State and return the new state.
Apply the 24-round Keccak-f[1600] permutation to State and return the new state.
-spec statebytes() -> Result when Result :: 224.
Return crypto_core_keccak1600_statebytes(), in bytes.
-spec xor_bytes(State, Bytes, Offset) -> Result when State :: state(), Bytes :: binary(), Offset :: non_neg_integer(), Result :: state().
XOR Bytes into State starting at byte Offset and return the
new state. Offset + byte_size(Bytes) must not exceed 200.