Module dryoc::classic::crypto_shorthash
source · Expand description
Short-input hashing
This module implements libsodium’s short input hashing, based on SipHash-2-4.
You may want to use short input hashing when:
- you need to construct hash tables in a fashion that is collision resistant (i.e., it’s hard for other parties to guess when there may be a hash key collision, which could lead to DoS or timing attacks)
- you want to construct probabilistic data structures, such as bloom filters
- you want to perform basic integrity checks on data
- you have relatively short inputs
The key used with this function should be treated as a secret. If used for constructing hash tables, it’s recommended the table size be a prime number to ensure all bits from the output are used.
For details, refer to libsodium docs.
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
- Computes a short input hash for
input
andkey
, placing the result intooutput
, using SipHash-2-4. - Generates a random key for short input hashing.
Type Definitions
- Hash type alias for short input hashing.
- Key type alias for short input hashing.