hashfuncs.go raw

   1  package chainhash
   2  
   3  import "crypto/sha256"
   4  
   5  // HashB calculates hash(b) and returns the resulting bytes.
   6  func HashB(b []byte) []byte {
   7  	hash := sha256.Sum256(b)
   8  	return hash[:]
   9  }
  10  
  11  // HashH calculates hash(b) and returns the resulting bytes as a Hash.
  12  func HashH(b []byte) Hash {
  13  	return sha256.Sum256(b)
  14  }
  15  
  16  // DoubleHashB calculates hash(hash(b)) and returns the resulting bytes.
  17  func DoubleHashB(b []byte) []byte {
  18  	first := sha256.Sum256(b)
  19  	second := sha256.Sum256(first[:])
  20  	return second[:]
  21  }
  22  
  23  // DoubleHashH calculates hash(hash(b)) and returns the resulting bytes as a Hash.
  24  func DoubleHashH(b []byte) Hash {
  25  	first := sha256.Sum256(b)
  26  	return sha256.Sum256(first[:])
  27  }
  28