github.com/Bytom/bytom@v1.1.2-0.20210127130405-ae40204c0b09/crypto/crypto.go (about) 1 package crypto 2 3 import ( 4 "github.com/bytom/bytom/common" 5 "golang.org/x/crypto/ripemd160" 6 "golang.org/x/crypto/sha3" 7 ) 8 9 func Sha256(data ...[]byte) []byte { 10 d := sha3.New256() 11 for _, b := range data { 12 d.Write(b) 13 } 14 return d.Sum(nil) 15 } 16 17 func Sha256Hash(data ...[]byte) (h common.Hash) { 18 d := sha3.New256() 19 for _, b := range data { 20 d.Write(b) 21 } 22 d.Sum(h[:0]) 23 return h 24 } 25 26 func Ripemd160(data []byte) []byte { 27 ripemd := ripemd160.New() 28 ripemd.Write(data) 29 30 return ripemd.Sum(nil) 31 }