func BenchmarkSipHash(b *testing.B) { h := siphash.New([]byte("0123456789012345")) b.StartTimer() for i := 0; i < b.N; i++ { h.Write([]byte("Hello world")) h.Sum(nil) h.Reset() } }
// makeDuid constructs a new DUID. Adapted from systemd's implemenation here: https://github.com/systemd/systemd/blob/master/src/libsystemd-network/dhcp-identifier.c func makeDuid() (Duid, error) { id, err := getMachineID() if err != nil { return Duid{}, err } h := siphash.New(key) h.Write(id) return Duid{Type: DuidEn, PEN: VMwarePEN, ID: h.Sum64()}, nil }
// makeIaid constructs a new IAID. Ported from systemd's // implementation here: https://github.com/systemd/systemd/blob/master/src/libsystemd-network/dhcp-identifier.c func makeIaid(ifindex int, hw net.HardwareAddr) Iaid { h := siphash.New(key) h.Write(hw) id := h.Sum64() // fold into 32 bits iaid := make(Iaid, 4) binary.BigEndian.PutUint32(iaid, uint32(id&0xffffffff)^uint32(id>>32)) return iaid }
func New7x7Size(sqSize, maxX, maxY, borderX, borderY int, key []byte) Renderer { return &identicon{ sqSize: sqSize, maxX: maxX, maxY: maxY, borderX: borderX, borderY: borderY, rows: 7, cols: 7, h: siphash.New(key), } }
// New7x7 creates a new 7-by-7 identicon renderer using 'key' as the hash salt func New7x7(key []byte) Renderer { return &identicon{ sqSize: 50, maxX: maxX, maxY: maxY, borderX: xborder, borderY: yborder, rows: 7, cols: 7, h: siphash.New(key), } }
// NewHashDrbg makes a HashDrbg instance based off an optional seed. The seed // is truncated to SeedLength. func NewHashDrbg(seed *Seed) (*HashDrbg, error) { drbg := new(HashDrbg) if seed == nil { var err error if seed, err = NewSeed(); err != nil { return nil, err } } drbg.sip = siphash.New(seed.Bytes()[:16]) copy(drbg.ofb[:], seed.Bytes()[16:]) return drbg, nil }