2023-03-04 21:51:51 +00:00
|
|
|
package hash
|
2023-03-02 15:53:10 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/sha256"
|
|
|
|
"hash"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
var sha256Pool = sync.Pool{New: func() interface{} {
|
|
|
|
return sha256.New()
|
|
|
|
}}
|
|
|
|
|
2023-09-11 14:24:05 +00:00
|
|
|
// SHA256 generates the SHA256 hash from the input data
|
2023-03-04 21:51:51 +00:00
|
|
|
func SHA256(data ...[]byte) []byte {
|
2023-03-02 15:53:10 +00:00
|
|
|
h, ok := sha256Pool.Get().(hash.Hash)
|
|
|
|
if !ok {
|
|
|
|
h = sha256.New()
|
|
|
|
}
|
|
|
|
defer sha256Pool.Put(h)
|
|
|
|
h.Reset()
|
2023-03-04 21:51:51 +00:00
|
|
|
for i := range data {
|
|
|
|
h.Write(data[i])
|
|
|
|
}
|
2023-03-04 15:55:42 +00:00
|
|
|
return h.Sum(nil)
|
2023-03-02 15:53:10 +00:00
|
|
|
}
|