Documentation ¶
Overview ¶
Package hashx provides a concrete implementation of hash.Hash that operates on a particular block size.
Index ¶
- type Block512
- func (h *Block512) HashBytes(b []byte)
- func (h *Block512) HashString(s string)
- func (h *Block512) HashUint16(n uint16)
- func (h *Block512) HashUint32(n uint32)
- func (h *Block512) HashUint64(n uint64)
- func (h *Block512) HashUint8(n uint8)
- func (h *Block512) Reset()
- func (h *Block512) Sum(b []byte) []byte
- func (h *Block512) Write(b []byte) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block512 ¶
Block512 wraps a hash.Hash for functions that operate on 512-bit block sizes. It has efficient methods for hashing fixed-width integers.
A hashing algorithm that operates on 512-bit block sizes should be used. The hash still operates correctly even with misaligned block sizes, but operates less efficiently.
Example algorithms with 512-bit block sizes include:
- MD4 (https://golang.org/x/crypto/md4)
- MD5 (https://golang.org/pkg/crypto/md5)
- BLAKE2s (https://golang.org/x/crypto/blake2s)
- BLAKE3
- RIPEMD (https://golang.org/x/crypto/ripemd160)
- SHA-0
- SHA-1 (https://golang.org/pkg/crypto/sha1)
- SHA-2 (https://golang.org/pkg/crypto/sha256)
- Whirlpool
See https://en.wikipedia.org/wiki/Comparison_of_cryptographic_hash_functions#Parameters for a list of hash functions and their block sizes.
Block512 assumes that hash.Hash.Write never fails and never allows the provided buffer to escape.
func New512 ¶
New512 constructs a new Block512 that wraps h.
It reports an error if the block sizes do not match. Misaligned block sizes perform poorly, but execute correctly. The error may be ignored if performance is not a concern.
func (*Block512) HashBytes ¶
HashBytes hashes the contents of b. It does not explicitly hash the length separately.
func (*Block512) HashString ¶
HashString hashes the contents of s. It does not explicitly hash the length separately.
func (*Block512) HashUint16 ¶
HashUint16 hashes n as a 2-byte little-endian integer.
func (*Block512) HashUint32 ¶
HashUint32 hashes n as a 4-byte little-endian integer.
func (*Block512) HashUint64 ¶
HashUint64 hashes n as a 8-byte little-endian integer.
func (*Block512) Reset ¶
func (h *Block512) Reset()
Reset resets Block512 to its initial state. It recursively resets the underlying hash.Hash.
func (*Block512) Sum ¶
Sum appends the current hash to b and returns the resulting slice.
It flushes any partially completed blocks to the underlying hash.Hash, which may cause future operations to be misaligned and less efficient until Block512.Reset is called.