Package hash provides abstracted hash functionality.
This package provides a generic hash type and associated functions that allows the specific hash algorithm to be abstracted.
Q: WHY SHA-256 twice?
A: SHA-256(SHA-256(x)) was proposed by Ferguson and Schneier in their excellent book "Practical Cryptography" (later updated by Ferguson, Schneier, and Kohno and renamed "Cryptography Engineering") as a way to make SHA-256 invulnerable to "length-extension" attack. They called it "SHA-256d". We started using SHA-256d for everything when we launched the Tahoe-LAFS project in 2006, on the principle that it is hardly less efficient than SHA-256, and that it frees us from having to reason about whether length-extension attacks are dangerous every place that we use a hash function. I wouldn't be surprised if the inventors of Bitcoin used it for similar reasons. Why not use SHA-256d instead of SHA-256?
Note that the SHA-3 project required all candidates to have some method of preventing length-extension attacks. Some of them use a method that is rather like SHA-256d, i.e. they do an extra "finalization" hash of their state at the end, before emitting a result.
HashBSize is the size of HashB.
const HashSize = 32
HashSize of array used to store hashes. See Hash.
MaxHashStringSize is the maximum length of a Hash hash string.
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.
DoubleHashB calculates hash(hash(b)) and returns the resulting bytes.
FNVHash32B calculates hash(b) into [0, 2^64] and returns the resulting bytes.
FNVHash32uint return the uint32 value of fnv hash 32 of b.
HashB calculates hash(b) and returns the resulting bytes.
THashB is a combination of blake2b-512 and SHA256
The cryptographic hash function BLAKE2 is an improved version of the
SHA-3 finalist BLAKE.
Hash is used in several of the bitcoin messages and common structures. It typically represents the double sha256 of data.
DoubleHashH calculates hash(hash(b)) and returns the resulting bytes as a Hash.
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.
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.
THashH calculates sha256(blake2b-512(b)) and returns the resulting bytes as a Hash.
AsBytes returns internal bytes of hash.
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.
Difficulty returns the leading Zero **bit** count of Hash in binary.
return -1 indicate the Hash pointer is nil.
IsEqual returns true if target is the same as hash.
MarshalHash marshals for hash.
MarshalJSON implements the json.Marshaler interface.
MarshalYAML implements the yaml.Marshaler interface.
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message.
SetBytes sets the bytes which represent the hash. An error is returned if the number of bytes passed in is not HashSize.
Short returns the hexadecimal string of the first `n` reversed byte(s).
String returns the Hash as the hexadecimal string of the byte-reversed hash.
UnmarshalJSON implements the json.Unmarshaler interface.
UnmarshalYAML implements the yaml.Unmarshaler interface.
HashSuite contains the hash length and the func handler.