libdecaf_sha3 (libdecaf v3.0.0)
View SourceDeprecated compatibility API for SHA-3 and SHAKE with tagged, immutable states.
New code should use libdecaf:hash/2, libdecaf:hash_init/1,
libdecaf:hash_update/2, and libdecaf:hash_final/1 directly.
For SHAKE, use libdecaf:xof/3, libdecaf:xof_init/1,
libdecaf:xof_absorb/2, and libdecaf:xof_squeeze/2.
This compatibility module keeps {Algorithm, NativeState} wrapped states.
Updates return a new state; existing states remain reusable. The new API
returns opaque states directly. See the migration guide.
Fixed-output algorithms and their default digest lengths:
sha3_224: 28 bytes.sha3_256: 32 bytes.sha3_384: 48 bytes.sha3_512: 64 bytes.
SHAKE algorithms are shake128, shake256. They require an explicit
output length with hash/3, xof/3, or final/2; hash/2 and final/1
accept only fixed-output hashes.
Lengths are in bytes. Fixed-output hashes allow truncation from zero bytes through the algorithm's maximum digest length. Input accepts iodata.
For example, the replacement incremental API needs no wrapper:
State0 = libdecaf:hash_init(sha3_224),
State1 = libdecaf:hash_update(State0, [<<"a">>, <<"bc">>]),
Digest = libdecaf:hash_final(State1),
Digest = libdecaf:hash(sha3_224, <<"abc">>).
Summary
Types
Algorithms accepted by this compatibility module.
Fixed-output algorithms supported by this module.
A legacy {Algorithm, NativeState} tuple for a fixed-output hash.
A legacy {Algorithm, NativeState} tuple for SHAKE.
Functions
Return a fixed-output digest using the algorithm's default length.
The wrapped state remains reusable.
SHAKE requires final/2.
Return Length bytes without changing the wrapped state.
Fixed-output hashes return a digest prefix and reject lengths above their
maximum.
SHAKE accepts any nonnegative output length.
Hash iodata and return exactly Length bytes.
Fixed-output hashes allow truncation up to their maximum digest length.
SHAKE produces the requested number of XOF bytes, including zero.
Initialize an immutable {Type, NativeState} tuple.
Pass the returned tuple to update/2 and final/1,2 in this module.
SHAKE states can only be finalized with an explicit output length.
Absorb iodata and return a new {Algorithm, NativeState} tuple.
The algorithm tag is preserved and the input tuple remains reusable.
Types
-type algorithm() :: hash_algorithm() | xof_algorithm().
Algorithms accepted by this compatibility module.
-type hash_algorithm() :: sha3_224 | sha3_256 | sha3_384 | sha3_512.
Fixed-output algorithms supported by this module.
-type hash_state() :: {hash_algorithm(), libdecaf_nif:hash_state()}.
A legacy {Algorithm, NativeState} tuple for a fixed-output hash.
-type state() :: hash_state() | xof_state().
An immutable tagged hash or SHAKE state returned by init/1 or update/2.
-type xof_algorithm() :: shake128 | shake256.
-type xof_state() :: {xof_algorithm(), libdecaf_nif:xof_state()}.
A legacy {Algorithm, NativeState} tuple for SHAKE.
Functions
-spec final(State) -> Digest when State :: hash_state(), Digest :: binary().
Return a fixed-output digest using the algorithm's default length.
The wrapped state remains reusable.
SHAKE requires final/2.
-spec final(State, Length) -> Digest when State :: state(), Length :: non_neg_integer(), Digest :: binary().
Return Length bytes without changing the wrapped state.
Fixed-output hashes return a digest prefix and reject lengths above their
maximum.
SHAKE accepts any nonnegative output length.
-spec hash(Type, Data) -> Digest when Type :: hash_algorithm(), Data :: iodata(), Digest :: binary().
Hash iodata using the algorithm's default digest length.
SHAKE requires an explicit output length with hash/3 or xof/3.
-spec hash(Type, Data, Length) -> Digest when Type :: algorithm(), Data :: iodata(), Length :: non_neg_integer(), Digest :: binary().
Hash iodata and return exactly Length bytes.
Fixed-output hashes allow truncation up to their maximum digest length.
SHAKE produces the requested number of XOF bytes, including zero.
Initialize an immutable {Type, NativeState} tuple.
Pass the returned tuple to update/2 and final/1,2 in this module.
SHAKE states can only be finalized with an explicit output length.
Absorb iodata and return a new {Algorithm, NativeState} tuple.
The algorithm tag is preserved and the input tuple remains reusable.
-spec xof(Type, Data, Length) -> Output when Type :: xof_algorithm(), Data :: iodata(), Length :: non_neg_integer(), Output :: binary().
Return Length SHAKE bytes from iodata in one call.
This preserves the historical xof/3 alias for SHAKE through hash/3.