libsodium_crypto_shorthash (libsodium v3.0.1)

View Source

Keyed hashing of short inputs with the default construction, currently SipHash-2-4, producing bytes/0 byte (64-bit) outputs under a keybytes/0 byte secret key.

It is designed for hash tables, Bloom filters, and similar structures where an attacker must not be able to predict collisions. It is not a general-purpose or collision-resistant cryptographic hash; use libsodium_crypto_generichash for that.

Key = libsodium_crypto_shorthash:keygen(),
Hash = libsodium_crypto_shorthash:crypto_shorthash(<<"short input">>, Key),
8 = byte_size(Hash),
Hash = libsodium_crypto_shorthash_siphash24:crypto_shorthash_siphash24(<<"short input">>, Key).

Summary

Types

k()

A crypto_shorthash_KEYBYTES (16-byte) binary.

A crypto_shorthash_BYTES (8-byte) binary.

Functions

Return crypto_shorthash_bytes(), in bytes.

Hash In under the keybytes/0 byte key K, returning bytes/0 bytes.

Return crypto_shorthash_keybytes(), in bytes.

Generate a random keybytes/0 byte key.

Return crypto_shorthash_primitive() as an atom.

Types

k()

-type k() :: <<_:128>>.

A crypto_shorthash_KEYBYTES (16-byte) binary.

out()

-type out() :: <<_:64>>.

A crypto_shorthash_BYTES (8-byte) binary.

Functions

bytes()

-spec bytes() -> Result when Result :: 8.

Return crypto_shorthash_bytes(), in bytes.

crypto_shorthash(In, K)

-spec crypto_shorthash(In, K) -> Result when In :: binary(), K :: k(), Result :: out() | -1.

Hash In under the keybytes/0 byte key K, returning bytes/0 bytes.

keybytes()

-spec keybytes() -> Result when Result :: 16.

Return crypto_shorthash_keybytes(), in bytes.

keygen()

-spec keygen() -> Result when Result :: k().

Generate a random keybytes/0 byte key.

primitive()

-spec primitive() -> Result when Result :: siphash24.

Return crypto_shorthash_primitive() as an atom.