tendermint/p2p/util.go

22 lines
368 B
Go
Raw Normal View History

2015-10-25 18:21:51 -07:00
package p2p
import (
"crypto/sha256"
)
// doubleSha256 calculates sha256(sha256(b)) and returns the resulting bytes.
func doubleSha256(b []byte) []byte {
hasher := sha256.New()
2017-09-06 11:50:43 -04:00
_, err := hasher.Write(b)
if err != nil {
panic(err)
}
2015-10-25 18:21:51 -07:00
sum := hasher.Sum(nil)
hasher.Reset()
2017-09-06 11:50:43 -04:00
_, err = hasher.Write(sum)
if err != nil {
panic(err)
}
2015-10-25 18:21:51 -07:00
return hasher.Sum(nil)
}