2018-01-25 13:08:43 +00:00
|
|
|
// Copyright (c) 2013-2017 The btcsuite developers
|
2016-08-18 00:15:58 +00:00
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package btcutil
|
|
|
|
|
|
|
|
import (
|
2018-01-25 13:08:43 +00:00
|
|
|
"crypto/sha256"
|
2016-08-18 00:15:58 +00:00
|
|
|
"hash"
|
|
|
|
|
2018-01-25 13:08:43 +00:00
|
|
|
"golang.org/x/crypto/ripemd160"
|
2016-08-18 00:15:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Calculate the hash of hasher over buf.
|
|
|
|
func calcHash(buf []byte, hasher hash.Hash) []byte {
|
|
|
|
hasher.Write(buf)
|
|
|
|
return hasher.Sum(nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hash160 calculates the hash ripemd160(sha256(b)).
|
|
|
|
func Hash160(buf []byte) []byte {
|
2018-01-25 13:08:43 +00:00
|
|
|
return calcHash(calcHash(buf, sha256.New()), ripemd160.New())
|
2016-08-18 00:15:58 +00:00
|
|
|
}
|