libdecaf_keccak_sha3 (libdecaf v3.0.0)
View SourceDeprecated compatibility API for legacy Keccak 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.
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:
keccak_224: 28 bytes.keccak_256: 32 bytes.keccak_384: 48 bytes.keccak_512: 64 bytes.
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(keccak_224),
State1 = libdecaf:hash_update(State0, [<<"a">>, <<"bc">>]),
Digest = libdecaf:hash_final(State1),
Digest = libdecaf:hash(keccak_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.
Functions
Return a fixed-output digest using the algorithm's default length. The wrapped state remains reusable.
Return Length bytes without changing the wrapped state.
Fixed-output hashes return a digest prefix and reject lengths above their
maximum.
Hash iodata using the algorithm's default digest length.
Hash iodata and return exactly Length bytes.
Fixed-output hashes allow truncation up to their maximum digest length.
Initialize an immutable {Type, NativeState} tuple.
Pass the returned tuple to update/2 and final/1,2 in this module.
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().
Algorithms accepted by this compatibility module.
-type hash_algorithm() :: keccak_224 | keccak_256 | keccak_384 | keccak_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().
An immutable tagged hash state returned by init/1 or update/2.
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.
-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.
-spec hash(Type, Data) -> Digest when Type :: hash_algorithm(), Data :: iodata(), Digest :: binary().
Hash iodata using the algorithm's default digest length.
-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.
Initialize an immutable {Type, NativeState} tuple.
Pass the returned tuple to update/2 and final/1,2 in this module.
Absorb iodata and return a new {Algorithm, NativeState} tuple.
The algorithm tag is preserved and the input tuple remains reusable.