1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Many applications and programming language implementations were recently
//! found to be vulnerable to denial-of-service attacks when a hash function
//! with weak security guarantees, such as Murmurhash 3, was used to construct a
//! hash table.
//!
//! In order to address this, Sodium provides the crypto_shorthash() function,
//! which outputs short but unpredictable (without knowing the secret key)
//! values suitable for picking a list in a hash table for a given key.
//!
//! This function is optimized for short inputs.
//!
//! The output of this function is only 64 bits. Therefore, it should not be
//! considered collision-resistant.
//!
//! Use cases:
//!
//! - Hash tables
//! - Probabilistic data structures such as Bloom filters
//! - Integrity checking in interactive protocols
use ;
use ;
use secmem;
pub const BYTES: usize = 8;
pub const KEYBYTES: usize = 16;
extern "C"
/// Compute a fixed-size (*BYTES* bytes) fingerprint for the message using the
/// key k.
///
/// The k is *KEYBYTES* bytes and can be created using *random_byte_array()*.
///
/// The same message hashed with the same key will always produce the same
/// output.
///
/// # Examples
///
/// ```
/// use sodium_sys::crypto::utils::{init,randombytes};
/// use sodium_sys::crypto::hash::shorthash;
///
/// // Initialize sodium_sys
/// init::init();
///
/// // Generate the hash.
/// let mut key = [0; shorthash::KEYBYTES];
/// randombytes::random_byte_array(&mut key);
/// let hash = shorthash::hash(b"test", &key).unwrap();
/// assert!(hash.len() == shorthash::BYTES);
/// ```