mirror of https://github.com/status-im/go-waku.git
25 lines
347 B
Go
25 lines
347 B
Go
package hash
|
|
|
|
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()
|
|
for i := range data {
|
|
h.Write(data[i])
|
|
}
|
|
return h.Sum(nil)
|
|
}
|