mirror of https://github.com/status-im/go-waku.git
26 lines
355 B
Go
26 lines
355 B
Go
|
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()
|
||
|
|
||
|
var result [32]byte
|
||
|
h.Write(data)
|
||
|
h.Sum(result[:0])
|
||
|
return result[:]
|
||
|
}
|