Beispiel #1
0
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()
	}
}
Beispiel #2
0
Datei: id.go Projekt: vmware/vic
// 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
}
Beispiel #3
0
Datei: id.go Projekt: vmware/vic
// 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
}
Beispiel #4
0
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),
	}
}
Beispiel #5
0
// 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),
	}
}
Beispiel #6
0
// 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
}