mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-23 04:03:49 +00:00
59df60a2c1
* first prototype * Added Proper Message ID to gossip * ops * ops * lint why? * u kidding? * just why * maybe Co-authored-by: giuliorebuffo <giuliorebuffo@system76-pc.localdomain>
30 lines
350 B
Go
30 lines
350 B
Go
package utils
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"hash"
|
|
"sync"
|
|
)
|
|
|
|
var hasherPool = sync.Pool{
|
|
New: func() interface{} {
|
|
return sha256.New()
|
|
},
|
|
}
|
|
|
|
func Keccak256(data []byte) [32]byte {
|
|
h, ok := hasherPool.Get().(hash.Hash)
|
|
if !ok {
|
|
h = sha256.New()
|
|
}
|
|
defer hasherPool.Put(h)
|
|
h.Reset()
|
|
|
|
var b [32]byte
|
|
|
|
h.Write(data)
|
|
h.Sum(b[:0])
|
|
|
|
return b
|
|
}
|