forked from decred/dcraddrgen
/
hashfuncs.go
48 lines (40 loc) · 1.09 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
// Copyright (c) 2015 The Decred Developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package chainhash
import (
"github.com/dchest/blake256"
)
// HashFunc calculates the hash of the supplied bytes.
// TODO(jcv) Should modify blake256 so it has the same interface as blake2
// and fastsha256 so these function can look more like btcsuite. Then should
// try to get it to the upstream blake256 repo
func HashFunc(data []byte) [blake256.Size]byte {
var outB [blake256.Size]byte
a := blake256.New()
a.Write(data)
out := a.Sum(nil)
for i, el := range out {
outB[i] = el
}
return outB
}
// HashFuncB calculates hash(b) and returns the resulting bytes.
func HashFuncB(b []byte) []byte {
a := blake256.New()
a.Write(b)
out := a.Sum(nil)
return out
}
// HashFuncH calculates hash(b) and returns the resulting bytes as a Hash.
func HashFuncH(b []byte) Hash {
var outB [blake256.Size]byte
a := blake256.New()
a.Write(b)
out := a.Sum(nil)
for i, el := range out {
outB[i] = el
}
return Hash(outB)
}
const HashBlockSize = blake256.BlockSize