OSDN Git Service

Hulk did something
[bytom/vapor.git] / crypto / crypto.go
diff --git a/crypto/crypto.go b/crypto/crypto.go
new file mode 100644 (file)
index 0000000..fd434b4
--- /dev/null
@@ -0,0 +1,31 @@
+package crypto
+
+import (
+       "github.com/vapor/common"
+       "golang.org/x/crypto/ripemd160"
+       "golang.org/x/crypto/sha3"
+)
+
+func Sha256(data ...[]byte) []byte {
+       d := sha3.New256()
+       for _, b := range data {
+               d.Write(b)
+       }
+       return d.Sum(nil)
+}
+
+func Sha256Hash(data ...[]byte) (h common.Hash) {
+       d := sha3.New256()
+       for _, b := range data {
+               d.Write(b)
+       }
+       d.Sum(h[:0])
+       return h
+}
+
+func Ripemd160(data []byte) []byte {
+       ripemd := ripemd160.New()
+       ripemd.Write(data)
+
+       return ripemd.Sum(nil)
+}