libsodium_crypto_shorthash_siphash24 (libsodium v3.0.1)

View Source

Keyed hashing of short inputs with 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. Keys can be generated with libsodium_crypto_shorthash:keygen/0.

Key = libsodium_randombytes:buf(libsodium_crypto_shorthash_siphash24:keybytes()),
Hash = libsodium_crypto_shorthash_siphash24:crypto_shorthash_siphash24(<<"short input">>, Key),
8 = byte_size(Hash),
Hash = libsodium_crypto_shorthash_siphash24:crypto_shorthash_siphash24(<<"short input">>, Key).

Summary

Types

k()

A crypto_shorthash_siphash24_KEYBYTES (16-byte) binary.

A crypto_shorthash_siphash24_BYTES (8-byte) binary.

Functions

Return crypto_shorthash_siphash24_bytes(), in bytes.

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

Return crypto_shorthash_siphash24_keybytes(), in bytes.

Types

k()

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

A crypto_shorthash_siphash24_KEYBYTES (16-byte) binary.

out()

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

A crypto_shorthash_siphash24_BYTES (8-byte) binary.

Functions

bytes()

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

Return crypto_shorthash_siphash24_bytes(), in bytes.

crypto_shorthash_siphash24(In, K)

-spec crypto_shorthash_siphash24(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_siphash24_keybytes(), in bytes.