Documentation ¶
Overview ¶
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.
Index ¶
Constants ¶
const HashBlockSize = blake256.BlockSize
HashBlockSize is the block size of the hash algorithm in bytes.
const HashSize = 32
HashSize of array used to store hashes. See Hash.
const MaxHashStringSize = HashSize * 2
MaxHashStringSize is the maximum length of a Hash hash string.
Variables ¶
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.
var MagicBytes = []byte{
0x3b, 0xe5, 0xd4, 0x9e, 0xca, 0x59, 0x81, 0x5b,
0x7a, 0x5d, 0xa1, 0xbb, 0x65, 0x37, 0x6f, 0x5d,
0x04, 0xf4, 0x3b, 0x90, 0x2a, 0x41, 0x3a, 0xe5,
0x8f, 0x98, 0x87, 0x93, 0xf9, 0x41, 0x67, 0x35,
}
MagicBytes is the magic 256-bit random number used for Proof-of-Work in Bitum.
Functions ¶
func Decode ¶
Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a destination.
func HashFunc ¶
HashFunc calculates the hash of the supplied bytes. TODO(jcv) Should modify blake256 so it has the same interface as blake2 and sha256 so these function can look more like btcsuite. Then should try to get it to the upstream blake256 repo
Types ¶
type Hash ¶
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.
func NewHash ¶
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 PoWHashH ¶
PoWHashH calculates (hash(hash(b) ^ MagicBytes) ^ MagicBytes) and returns the resulting bytes as a 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.