-
Notifications
You must be signed in to change notification settings - Fork 0
/
crypto.go
53 lines (44 loc) · 947 Bytes
/
crypto.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package crypto
import (
"golang.org/x/crypto/ripemd160"
"golang.org/x/crypto/sha3"
"github.com/bytom-gm/common"
"github.com/bytom-gm/crypto/sm3"
)
func DoubleSha256(b []byte) []byte {
hasher := sha3.New256()
hasher.Write(b)
sum := hasher.Sum(nil)
hasher.Reset()
hasher.Write(sum)
return hasher.Sum(nil)
}
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 Sha3(data ...[]byte) []byte { return Sha256(data...) }
func Sha3Hash(data ...[]byte) common.Hash { return Sha256Hash(data...) }
func Ripemd160(data []byte) []byte {
ripemd := ripemd160.New()
ripemd.Write(data)
return ripemd.Sum(nil)
}
func Sm3(data ...[]byte) []byte {
d := sm3.New()
for _, b := range data {
d.Write(b)
}
return d.Sum(nil)
}