Exemplo n.º 1
0
func (d *digest) Sum(buf []byte) []byte {
	digest := make([]byte, d.Size())
	// Make a copy of d.state so that caller can keep writing and summing.
	s := d.state
	C.blake2b_final(&s, (*C.uint8_t)(&digest[0]), C.uint8_t(d.Size()))
	return append(buf, digest...)
}
Exemplo n.º 2
0
// Return the hash of the stream up to this point, without changing the state.
func (s *Blake2bState) Sum(b []byte) []byte {

	// Make a copy of the hash state, since blake2b_final() mutates it
	// but the Hash interface specifies that Sum() does not affect state.
	st := s.s

	var d [Blake2bOutBytes]byte
	if C.blake2b_final(&st, (*C.uint8_t)(unsafe.Pointer(&d[0])),
		C.uint8_t(Blake2bOutBytes)) != 0 {
		panic("blake2b_final failed")
	}
	return append(b, d[:]...)
}
Exemplo n.º 3
0
func (d *digest) Sum(buf []byte) []byte {
	digest := make([]byte, d.Size())
	C.blake2b_final(d.state, (*C.uint8_t)(&digest[0]), C.uint8_t(d.Size()))
	return append(buf, digest...)
}