Skip to main content

Module crypto_shorthash

Module crypto_shorthash 

Source
Expand description

§Short-input hashing

Implements libsodium’s SipHash-2-4 function for short inputs. It produces a compact, keyed hash that can protect hash tables against attacker-chosen collision patterns.

This function is intended for short, keyed inputs. It is not a general-purpose hash or an encryption primitive. Use crate::classic::crypto_auth for message authentication, or crate::classic::crypto_generichash for general-purpose hashing.

Treat the key as secret and generate it randomly. See the libsodium documentation for details.

§Classic API example

use dryoc::classic::crypto_shorthash::*;
use dryoc::rng::copy_randombytes;

// Generate a random key
let key = crypto_shorthash_keygen();

// Generate some random input data
let mut input = vec![0u8; 69];
copy_randombytes(&mut input);

// Compute the hash, put result into `output`
let mut output = Hash::default();
crypto_shorthash(&mut output, &input, &key);

Functions§

crypto_shorthash
Computes a short input hash for input and key, placing the result into output, using SipHash-2-4.
crypto_shorthash_keygen
Generates a random key for short input hashing.

Type Aliases§

Hash
Hash type alias for short input hashing.
Key
Key type alias for short input hashing.