]> git.ozlabs.org Git - ccan/blob - ccan/siphash/siphash.h
memmem, bytestring: Fix includes in _info
[ccan] / ccan / siphash / siphash.h
1 #ifndef CCAN_SIPHASH_H_
2 #define CCAN_SIPHASH_H_
3
4 /* Licensed under GPL v2+ - see LICENSE file for details */
5 /* Written in 2013 by Ulrik Sverdrup */
6
7 #include <stdint.h>
8 #include <stddef.h>
9
10 /**
11  * siphash - a keyed hash function
12  *
13  * SipHash-c-d, where `c` is the number of rounds per message chunk
14  *              and `d` the number of finalization rounds,
15  * "is a family of pseudorandom functions optimized for speed on short
16  * messages"
17  *
18  * Implemented from the paper https://131002.net/siphash/
19  * The designers recommend using SipHash-2-4 or SipHash-4-8
20  *
21  * SipHash-c-d uses a 16-byte key.
22  * To defend against hash-flooding, the application needs to use
23  * a new random key regularly.
24  *
25  * The designers of SipHash claim it is cryptographically strong
26  * to use as MAC with secret key but _not_collision_resistant_.
27  *
28  * Returns one 64-bit word as the hash function result.
29  *
30  * Example:
31  *      // Outputs "cf2794e0277187b7"
32  *      #include <stdio.h>
33  *      #include <ccan/siphash/siphash.h>
34  *
35  *      int main(void)
36  *      {
37  *              unsigned char t_key[16] =
38  *                      {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
39  *              unsigned char data[4] = "\0\1\2\3";
40  *              uint64_t hash = siphash_2_4(data, sizeof(data), t_key);
41  *              printf("%llx\n", (unsigned long long)hash);
42  *
43  *              return 0;
44  *      }
45  *
46  */
47 uint64_t siphash_2_4(const void *in, size_t len, const unsigned char key[16]);
48
49 #endif /* CCAN_SIPHASH_H_ */
50