github.com/ari-anchor/sei-tendermint@v0.0.0-20230519144642-dc826b7b56bb/crypto/tmhash/hash.go (about) 1 package tmhash 2 3 import ( 4 "crypto/sha256" 5 "hash" 6 ) 7 8 const ( 9 Size = sha256.Size 10 BlockSize = sha256.BlockSize 11 ) 12 13 // New returns a new hash.Hash. 14 func New() hash.Hash { 15 return sha256.New() 16 } 17 18 // Sum returns the SHA256 of the bz. 19 func Sum(bz []byte) []byte { 20 h := sha256.Sum256(bz) 21 return h[:] 22 } 23 24 //------------------------------------------------------------- 25 26 const ( 27 TruncatedSize = 20 28 ) 29 30 type sha256trunc struct { 31 sha256 hash.Hash 32 } 33 34 func (h sha256trunc) Write(p []byte) (n int, err error) { 35 return h.sha256.Write(p) 36 } 37 func (h sha256trunc) Sum(b []byte) []byte { 38 shasum := h.sha256.Sum(b) 39 return shasum[:TruncatedSize] 40 } 41 42 func (h sha256trunc) Reset() { 43 h.sha256.Reset() 44 } 45 46 func (h sha256trunc) Size() int { 47 return TruncatedSize 48 } 49 50 func (h sha256trunc) BlockSize() int { 51 return h.sha256.BlockSize() 52 }