libdecaf_keccak_sha3 (libdecaf v3.0.0)

View Source
This module is deprecated. Use libdecaf:hash/2, libdecaf:hash_init/1, libdecaf:hash_update/2, and libdecaf:hash_final/1..

Deprecated 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.

An immutable tagged hash state returned by init/1 or update/2.

Functions

final(State) deprecated

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(Type, Data) deprecated

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.

init(Type) deprecated

Initialize an immutable {Type, NativeState} tuple. Pass the returned tuple to update/2 and final/1,2 in this module.

update(State, Data) deprecated

Absorb iodata and return a new {Algorithm, NativeState} tuple. The algorithm tag is preserved and the input tuple remains reusable.

Types

algorithm()

-type algorithm() :: hash_algorithm().

Algorithms accepted by this compatibility module.

hash_algorithm()

-type hash_algorithm() :: keccak_224 | keccak_256 | keccak_384 | keccak_512.

Fixed-output algorithms supported by this module.

hash_state()

-type hash_state() :: {hash_algorithm(), libdecaf_nif:hash_state()}.

A legacy {Algorithm, NativeState} tuple for a fixed-output hash.

state()

-type state() :: hash_state().

An immutable tagged hash state returned by init/1 or update/2.

Functions

final(State)

This function is deprecated. Use libdecaf:hash_final/1 with an unwrapped hash state..
-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.

final(State, Length)

This function is deprecated. Choose the digest length with libdecaf:hash_init/1, then use libdecaf:hash_final/1..
-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.

hash(Type, Data)

This function is deprecated. Use libdecaf:hash/2..
-spec hash(Type, Data) -> Digest when Type :: hash_algorithm(), Data :: iodata(), Digest :: binary().

Hash iodata using the algorithm's default digest length.

hash(Type, Data, Length)

This function is deprecated. Use libdecaf:hash({Algorithm, Length}, Data)..
-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.

init(Type)

This function is deprecated. Use libdecaf:hash_init/1; retain the unwrapped state..
-spec init(Type) -> State when Type :: algorithm(), State :: state().

Initialize an immutable {Type, NativeState} tuple. Pass the returned tuple to update/2 and final/1,2 in this module.

update(State, Data)

This function is deprecated. Use libdecaf:hash_update/2 with an unwrapped state..
-spec update(State, Data) -> NewState when State :: state(), Data :: iodata(), NewState :: state().

Absorb iodata and return a new {Algorithm, NativeState} tuple. The algorithm tag is preserved and the input tuple remains reusable.