package filter import ( "encoding/hex" "testing" ) // Official SipHash-2-4 test vectors from the reference implementation. The key // is 000102...0f and the messages are the first 0, 1, 8, and 15 bytes of // 000102...0e. func TestSipHash24Vectors(t *testing.T) { keyBytes, err := hex.DecodeString("000102030405060708090a0b0c0d0e0f") if err != nil { t.Fatal(err) } var key [16]byte copy(key[:], keyBytes) tests := []struct { msg int want uint64 }{ {0, 0x726fdb47dd0e0e31}, {1, 0x74f839c593dc67fd}, {8, 0x93f5f5799a932462}, {15, 0xa129ca6149be45e5}, } for _, tc := range tests { msg := make([]byte, tc.msg) for i := range msg { msg[i] = byte(i) } if got := siphash24(key, msg); got != tc.want { t.Errorf("siphash24(%d-byte msg) = %#016x, want %#016x", tc.msg, got, tc.want) } } }