siphash_test.go raw
1 package filter
2
3 import (
4 "encoding/hex"
5 "testing"
6 )
7
8 // Official SipHash-2-4 test vectors from the reference implementation. The key
9 // is 000102...0f and the messages are the first 0, 1, 8, and 15 bytes of
10 // 000102...0e.
11 func TestSipHash24Vectors(t *testing.T) {
12 keyBytes, err := hex.DecodeString("000102030405060708090a0b0c0d0e0f")
13 if err != nil {
14 t.Fatal(err)
15 }
16 var key [16]byte
17 copy(key[:], keyBytes)
18
19 tests := []struct {
20 msg int
21 want uint64
22 }{
23 {0, 0x726fdb47dd0e0e31},
24 {1, 0x74f839c593dc67fd},
25 {8, 0x93f5f5799a932462},
26 {15, 0xa129ca6149be45e5},
27 }
28 for _, tc := range tests {
29 msg := make([]byte, tc.msg)
30 for i := range msg {
31 msg[i] = byte(i)
32 }
33 if got := siphash24(key, msg); got != tc.want {
34 t.Errorf("siphash24(%d-byte msg) = %#016x, want %#016x", tc.msg, got, tc.want)
35 }
36 }
37 }
38