]> git.ozlabs.org Git - ccan/blob - ccan/crypto/siphash24/_info
crypto/siphash: new module.
[ccan] / ccan / crypto / siphash24 / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * crypto/siphash24 - implementation of SipHash-2-4.
7  *
8  * SipHash was designed as a mitigation to hash-flooding DoS
9  * attacks. It is now used in the hash tables implementation of
10  * Python, Ruby, Perl 5, etc.
11  *
12  * SipHash was designed by Jean-Philippe Aumasson and Daniel J. Bernstein. 
13  *
14  * License: CC0
15  * Maintainer: Rusty Russell <rusty@rustcorp.com.au>
16  *
17  * Example:
18  * // Dumb example to print siphash of words, and all strung together.
19  * #include <ccan/crypto/siphash24/siphash24.h>
20  * #include <stdio.h>
21  * #include <stdlib.h>
22  * #include <string.h>
23  * #include <inttypes.h>
24  *
25  * int main(int argc, char *argv[])
26  * {
27  *      struct siphash_seed seed;
28  *      struct siphash24_ctx ctx;
29  *      int i;
30  *
31  *      if (argc < 3) {
32  *              fprintf(stderr, "Need at least seed1 and seed2 arguments");
33  *              exit(1);
34  *      }
35  *
36  *      seed.u.u64[0] = atoi(argv[1]);
37  *      seed.u.u64[1] = atoi(argv[2]);
38  *      siphash24_init(&ctx, &seed);
39  *      for (i = 3; i < argc; i++) {
40  *              printf("Hash of '%s' = %"PRIu64,
41  *                      argv[i], siphash24(&seed, argv[i], strlen(argv[i])));
42  *              siphash24_update(&ctx, argv[i], strlen(argv[i]));
43  *      }
44  *      printf("Hash of concatenated args = %"PRIu64, siphash24_done(&ctx));
45  *      return 0;
46  * }
47  */
48 int main(int argc, char *argv[])
49 {
50         /* Expect exactly one argument */
51         if (argc != 2)
52                 return 1;
53
54         if (strcmp(argv[1], "depends") == 0) {
55                 printf("ccan/endian\n");
56                 return 0;
57         }
58
59         return 1;
60 }