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
|
#include "config.h"
#include <stdio.h>
#include <string.h>
/**
* siphash - a keyed hash function
*
* SipHash-c-d, where `c` is the number of rounds per message chunk
* and `d` the number of finalization rounds,
* "is a family of pseudorandom functions optimized for speed on short
* messages"
*
* Implemented from the paper https://131002.net/siphash/
* The designers recommend using SipHash-2-4 or SipHash-4-8
*
* SipHash-c-d uses a 16-byte key.
* To defend against hash-flooding, the application needs to use
* a new random key regularly.
*
* The designers of SipHash claim it is cryptographically strong
* to use as MAC with secret key but _not_collision_resistant_.
*
* Returns one 64-bit word as the hash function result.
*
* Example:
* // Outputs "cf2794e0277187b7"
* #include <stdio.h>
* #include <ccan/siphash/siphash.h>
*
* int main(void)
* {
* unsigned char t_key[16] =
* {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
* unsigned char data[4] = "\0\1\2\3";
* uint64_t hash = siphash_2_4(data, sizeof(data), t_key);
* printf("%llx\n", (unsigned long long)hash);
*
* return 0;
* }
*
*
* License: GPL (v2 or any later version)
*/
int main(int argc, char *argv[])
{
if (argc != 2)
return 1;
if (strcmp(argv[1], "depends") == 0) {
printf("ccan/endian\n");
return 0;
}
return 1;
}
|