go-waku/waku/v2/utils/hash.go

23 lines
315 B
Go
Raw Normal View History

package utils
import (
"crypto/sha256"
"hash"
"sync"
)
var sha256Pool = sync.Pool{New: func() interface{} {
return sha256.New()
}}
func SHA256(data []byte) []byte {
h, ok := sha256Pool.Get().(hash.Hash)
if !ok {
h = sha256.New()
}
defer sha256Pool.Put(h)
h.Reset()
h.Write(data)
2023-03-04 15:55:42 +00:00
return h.Sum(nil)
}