OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / btcsuite / btcd / chaincfg / chainhash / hashfuncs.go
1 // Copyright (c) 2015 The Decred developers
2 // Copyright (c) 2016-2017 The btcsuite developers
3 // Use of this source code is governed by an ISC
4 // license that can be found in the LICENSE file.
5
6 package chainhash
7
8 import "crypto/sha256"
9
10 // HashB calculates hash(b) and returns the resulting bytes.
11 func HashB(b []byte) []byte {
12         hash := sha256.Sum256(b)
13         return hash[:]
14 }
15
16 // HashH calculates hash(b) and returns the resulting bytes as a Hash.
17 func HashH(b []byte) Hash {
18         return Hash(sha256.Sum256(b))
19 }
20
21 // DoubleHashB calculates hash(hash(b)) and returns the resulting bytes.
22 func DoubleHashB(b []byte) []byte {
23         first := sha256.Sum256(b)
24         second := sha256.Sum256(first[:])
25         return second[:]
26 }
27
28 // DoubleHashH calculates hash(hash(b)) and returns the resulting bytes as a
29 // Hash.
30 func DoubleHashH(b []byte) Hash {
31         first := sha256.Sum256(b)
32         return Hash(sha256.Sum256(first[:]))
33 }