chainhash provides a generic hash type and associated functions that allows the specific hash algorithm to be abstracted.
Installation and Updating
This package is part of the
Use the standard go tooling for working with modules to incorporate it.
Package chainhash is licensed under the copyfree ISC License.
Package chainhash provides abstracted hash functionality.
This package provides a generic hash type and associated functions that allows the specific hash algorithm to be abstracted.
- func Decode(dst *Hash, src string) error
- func HashB(b byte) byte
- func HashFunc(b byte) [blake256.Size]byte
- type Hash
HashBlockSize is the block size of the hash algorithm in bytes.
const HashSize = 32
HashSize of array used to store hashes. See Hash.
MaxHashStringSize is the maximum length of a Hash hash string.
var ErrHashStrSize = fmt.Errorf("max hash string length is %v bytes", MaxHashStringSize)
ErrHashStrSize describes an error that indicates the caller specified a hash string that has too many characters.
Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a destination.
Hash is used in several of the messages and common structures. It is a generic type so that it can represent any fixed-size hash as specified by the HashSize.
HashH calculates hash(b) and returns the resulting bytes as a Hash.
NewHash returns a new Hash from a byte slice. An error is returned if the number of bytes passed in is not HashSize.
func NewHashFromStr ¶
NewHashFromStr creates a Hash from a hash string. The string should be the hexadecimal string of a byte-reversed hash, but any missing characters result in zero padding at the end of the Hash.
func (*Hash) CloneBytes ¶
CloneBytes returns a copy of the bytes which represent the hash as a byte slice.
NOTE: It is generally cheaper to just slice the hash directly thereby reusing the same bytes rather than calling this method.
IsEqual returns true if target is the same as hash.
SetBytes sets the bytes which represent the hash. An error is returned if the number of bytes passed in is not HashSize.