1 | [[tags: egg]] |
---|
2 | |
---|
3 | == siphash |
---|
4 | |
---|
5 | [[toc:]] |
---|
6 | |
---|
7 | == Description |
---|
8 | |
---|
9 | A Scheme implementation of the SipHash family of hash functions. |
---|
10 | |
---|
11 | [[http://131002.net/siphash|SipHash]] is a cryptographically strong family of hash functions designed by Jean-Philippe Aumasson and Daniel J. Bernstein. |
---|
12 | |
---|
13 | The source for this extension is available [[http://git.foldling.org/siphash.git|here]]. |
---|
14 | |
---|
15 | == Requirements |
---|
16 | |
---|
17 | * [[http://wiki.call-cc.org/egg/numbers|numbers]] |
---|
18 | |
---|
19 | == API |
---|
20 | |
---|
21 | Three functions are provided: |
---|
22 | |
---|
23 | * {{make-siphash}} |
---|
24 | * {{siphash-2-4}} |
---|
25 | * {{siphash-4-8}} |
---|
26 | |
---|
27 | <procedure>(make-siphash c d) => procedure</procedure> |
---|
28 | |
---|
29 | {{make-siphash}} constructs a hashing function. |
---|
30 | |
---|
31 | It takes two positive integer arguments {{c}} and {{d}} and returns a hashing procedure with that many compression and finalization rounds, respectively. |
---|
32 | |
---|
33 | The returned procedure's signature matches those of {{siphash-2-4}} and {{siphash-4-8}}. |
---|
34 | |
---|
35 | <procedure>(siphash-2-4 key) => (procedure message) => integer</procedure> |
---|
36 | <procedure>(siphash-2-4 key message) => integer</procedure> |
---|
37 | <procedure>(siphash-4-8 key) => (procedure message) => integer</procedure> |
---|
38 | <procedure>(siphash-4-8 key message) => integer</procedure> |
---|
39 | |
---|
40 | {{siphash-2-4}} and {{siphash-4-8}} are predefined hashing procedures. |
---|
41 | |
---|
42 | Each takes one or two SRFI-4 u8vector arguments, the key and message to hash, and returns a positive integer. {{key}} should have a length of 16, while {{message}} may be any length. If {{message}} isn't given, a prekeyed hashing function is returned. |
---|
43 | |
---|
44 | The SipHash specification recommends SipHash-2-4 for performance and SipHash-4-8 for cryptographic security. |
---|
45 | |
---|
46 | == Examples |
---|
47 | |
---|
48 | <enscript highlight=scheme> |
---|
49 | > (define string->u8vector (compose blob->u8vector string->blob)) |
---|
50 | > (define key (u8vector 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)) |
---|
51 | > (define msg (string->u8vector "The rain in Spain falls mainly on the plain.")) |
---|
52 | |
---|
53 | > (siphash-2-4 key msg) |
---|
54 | ; => 8751579407287093977 |
---|
55 | |
---|
56 | > ((siphash-4-8 key) msg) |
---|
57 | ; => 13472556437817646137 |
---|
58 | |
---|
59 | > ((make-siphash 8 16) |
---|
60 | key |
---|
61 | (string->u8vector |
---|
62 | "In Hertford, Hereford and Hampshire, hurricanes hardly ever happen.")) |
---|
63 | ; => 9275736844991428064 |
---|
64 | </enscript> |
---|
65 | |
---|
66 | == Author |
---|
67 | |
---|
68 | Evan Hanson |
---|
69 | |
---|
70 | == License |
---|
71 | |
---|
72 | Copyright (c) 2013-2018, Evan Hanson, 3-Clause BSD License. |
---|