hashx

package
v1.78.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2024 License: BSD-3-Clause Imports: 4 Imported by: 3

Documentation

Overview

Package hashx provides a concrete implementation of hash.Hash that operates on a particular block size.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block512

type Block512 struct {
	hash.Hash
	// contains filtered or unexported fields
}

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:

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

func New512(h hash.Hash) (*Block512, error)

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

func (h *Block512) HashBytes(b []byte)

HashBytes hashes the contents of b. It does not explicitly hash the length separately.

func (*Block512) HashString

func (h *Block512) HashString(s string)

HashString hashes the contents of s. It does not explicitly hash the length separately.

func (*Block512) HashUint16

func (h *Block512) HashUint16(n uint16)

HashUint16 hashes n as a 2-byte little-endian integer.

func (*Block512) HashUint32

func (h *Block512) HashUint32(n uint32)

HashUint32 hashes n as a 4-byte little-endian integer.

func (*Block512) HashUint64

func (h *Block512) HashUint64(n uint64)

HashUint64 hashes n as a 8-byte little-endian integer.

func (*Block512) HashUint8

func (h *Block512) HashUint8(n uint8)

HashUint8 hashes n as a 1-byte 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

func (h *Block512) Sum(b []byte) []byte

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.

func (*Block512) Write

func (h *Block512) Write(b []byte) (int, error)

Write hashes the contents of b.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL