forked from rubblelabs/ripple
/
util.go
41 lines (34 loc) · 801 Bytes
/
util.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
package crypto
import (
"crypto/sha256"
"crypto/sha512"
"golang.org/x/crypto/ripemd160"
)
// Write operations in a hash.Hash never return an error
// Returns first 32 bytes of a SHA512 of the input bytes
func Sha512Half(b []byte) []byte {
hasher := sha512.New()
hasher.Write(b)
return hasher.Sum(nil)[:32]
}
// Returns first 16 bytes of a SHA512 of the input bytes
func Sha512Quarter(b []byte) []byte {
hasher := sha512.New()
hasher.Write(b)
return hasher.Sum(nil)[:16]
}
func DoubleSha256(b []byte) []byte {
hasher := sha256.New()
hasher.Write(b)
sha := hasher.Sum(nil)
hasher.Reset()
hasher.Write(sha)
return hasher.Sum(nil)
}
func Sha256RipeMD160(b []byte) []byte {
ripe := ripemd160.New()
sha := sha256.New()
sha.Write(b)
ripe.Write(sha.Sum(nil))
return ripe.Sum(nil)
}