github.com/number571/tendermint@v0.34.11-gost/crypto/tmhash/hash.go (about) 1 package tmhash 2 3 import ( 4 "hash" 5 6 ghash "github.com/number571/go-cryptopro/gost_r_34_11_2012" 7 ) 8 9 const ( 10 Size = ghash.Size256 11 BlockSize = ghash.BlockSize 12 ) 13 14 func New() hash.Hash { 15 return ghash.New(ghash.H256) 16 } 17 18 func Sum(bz []byte) []byte { 19 h := ghash.Sum(ghash.H256, bz) 20 return h[:] 21 } 22 23 //------------------------------------------------------------- 24 25 const ( 26 TruncatedSize = 20 27 ) 28 29 type gostTrunc struct { 30 ghash hash.Hash 31 } 32 33 func (h gostTrunc) Write(p []byte) (n int, err error) { 34 return h.ghash.Write(p) 35 } 36 37 func (h gostTrunc) Sum(b []byte) []byte { 38 shasum := h.ghash.Sum(b) 39 return shasum[:TruncatedSize] 40 } 41 42 func (h gostTrunc) Reset() { 43 h.ghash.Reset() 44 } 45 46 func (h gostTrunc) Size() int { 47 return TruncatedSize 48 } 49 50 func (h gostTrunc) BlockSize() int { 51 return h.ghash.BlockSize() 52 } 53 54 func NewTruncated() hash.Hash { 55 return gostTrunc{ 56 ghash: ghash.New(ghash.H256), 57 } 58 } 59 60 func SumTruncated(bz []byte) []byte { 61 hash := ghash.Sum(ghash.H256, bz) 62 return hash[:TruncatedSize] 63 }