forked from BitgesellOfficial/bgld
/
hashfuncs.go
49 lines (41 loc) · 1.27 KB
/
hashfuncs.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
// Copyright (c) 2015 The Decred developers
// Copyright (c) 2016-2017 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package chainhash
import "crypto/sha256"
import "github.com/ebfe/keccak"
// HashB calculates hash(b) and returns the resulting bytes.
func HashB(b []byte) []byte {
hash := sha256.Sum256(b)
return hash[:]
}
// HashH calculates hash(b) and returns the resulting bytes as a Hash.
func HashH(b []byte) Hash {
return Hash(sha256.Sum256(b))
}
// DoubleHashB calculates hash(hash(b)) and returns the resulting bytes.
func DoubleHashB(b []byte) []byte {
first := sha256.Sum256(b)
second := sha256.Sum256(first[:])
return second[:]
}
// DoubleHashH calculates hash(hash(b)) and returns the resulting bytes as a
// Hash.
func DoubleHashH(b []byte) Hash {
first := sha256.Sum256(b)
return Hash(sha256.Sum256(first[:]))
}
// HashKeccakH calculates hash(b) and returns the resulting bytes as a Hash.
func HashKeccakH(b []byte) Hash {
hasher := keccak.New256()
hasher.Write(b)
hash, _ := NewHash(hasher.Sum(nil))
return *hash
}
// HashKeccakH calculates hash(b) and returns the resulting bytes
func HashKeccakB(b []byte) []byte {
hasher := keccak.New256()
hasher.Write(b)
return hasher.Sum(nil)[:]
}