]> git.ozlabs.org Git - ccan/blob - ccan/siphash/_info
endian: add constant versions.
[ccan] / ccan / siphash / _info
1 #include <stdio.h>
2 #include <string.h>
3 #include "config.h"
4
5 /**
6  * siphash - a keyed hash function
7  *
8  * SipHash-c-d, where `c` is the number of rounds per message chunk
9  *              and `d` the number of finalization rounds,
10  * "is a family of pseudorandom functions optimized for speed on short
11  * messages"
12  *
13  * Implemented from the paper https://131002.net/siphash/
14  * The designers recommend using SipHash-2-4 or SipHash-4-8
15  *
16  * SipHash-c-d uses a 16-byte key.
17  * To defend against hash-flooding, the application needs to use
18  * a new random key regularly.
19  *
20  * The designers of SipHash claim it is cryptographically strong
21  * to use as MAC with secret key but _not_collision_resistant_.
22  *
23  * Returns one 64-bit word as the hash function result.
24  *
25  * Example:
26  *      // Outputs "cf2794e0277187b7"
27  *      #include <stdio.h>
28  *      #include <ccan/siphash/siphash.h>
29  *
30  *      int main(void)
31  *      {
32  *              unsigned char t_key[16] =
33  *                      {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
34  *              unsigned char data[4] = "\0\1\2\3";
35  *              uint64_t hash = siphash_2_4(data, sizeof(data), t_key);
36  *              printf("%llx\n", (unsigned long long)hash);
37  *
38  *              return 0;
39  *      }
40  *
41  *
42  * License: GPL (v2 or any later version)
43  */
44 int main(int argc, char *argv[])
45 {
46         if (argc != 2)
47                 return 1;
48
49         if (strcmp(argv[1], "depends") == 0) {
50                 printf("ccan/endian\n");
51                 return 0;
52         }
53
54         return 1;
55 }