github.com/tendermint/tmlibs@v0.9.0/merkle/tmhash/hash.go (about) 1 package tmhash 2 3 import ( 4 "crypto/sha256" 5 "hash" 6 ) 7 8 var ( 9 Size = 20 10 BlockSize = sha256.BlockSize 11 ) 12 13 type sha256trunc struct { 14 sha256 hash.Hash 15 } 16 17 func (h sha256trunc) Write(p []byte) (n int, err error) { 18 return h.sha256.Write(p) 19 } 20 func (h sha256trunc) Sum(b []byte) []byte { 21 shasum := h.sha256.Sum(b) 22 return shasum[:Size] 23 } 24 25 func (h sha256trunc) Reset() { 26 h.sha256.Reset() 27 } 28 29 func (h sha256trunc) Size() int { 30 return Size 31 } 32 33 func (h sha256trunc) BlockSize() int { 34 return h.sha256.BlockSize() 35 } 36 37 func New() hash.Hash { 38 return sha256trunc{ 39 sha256: sha256.New(), 40 } 41 }