hash

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const Blake2bXOFUnknown = xof.Blake2bUnknown

Blake2bXOFUnknown indicates that the output length of a BLAKE2b XOF is unspecified in advance.

View Source
const Blake2sXOFUnknown = xof.Blake2sUnknown

Blake2sXOFUnknown indicates that the output length of a BLAKE2s XOF is unspecified in advance.

View Source
const DigestSize = 32

Variables

This section is empty.

Functions

func NewBLAKE3

func NewBLAKE3() stdhash.Hash

NewBLAKE3 returns an unkeyed BLAKE3 hash.Hash producing 32-byte digests.

func NewBLAKE3Keyed

func NewBLAKE3Keyed(key []byte) (stdhash.Hash, error)

NewBLAKE3Keyed returns a keyed BLAKE3 hash.Hash. The key must be exactly 32 bytes.

func NewBlake2b

func NewBlake2b(size int, key []byte) (stdhash.Hash, error)

NewBlake2b returns a streaming BLAKE2b hash.Hash with the specified digest length and key.

func NewBlake2bXOF

func NewBlake2bXOF(length uint32, key []byte) (xof.XOF, error)

NewBlake2bXOF constructs a BLAKE2b extendable-output instance. Deprecated: use xof.Blake2b.

func NewBlake2s

func NewBlake2s(size int, key []byte) (stdhash.Hash, error)

NewBlake2s returns a streaming BLAKE2s hash.Hash with the specified digest length and key.

func NewBlake2sXOF deprecated

func NewBlake2sXOF(length uint32, key []byte) (xof.XOF, error)

Deprecated: use xof.Blake2s.

func NewSHA224 added in v1.0.1

func NewSHA224() stdhash.Hash

NewSHA224 returns a hash computing the SHA-224 digest.

func NewSHA256 added in v1.0.1

func NewSHA256() stdhash.Hash

NewSHA256 returns a hash computing the SHA-256 digest.

func NewSHA3224

func NewSHA3224() stdhash.Hash

NewSHA3224 returns a hash computing the SHA3-224 digest.

func NewSHA3256

func NewSHA3256() stdhash.Hash

NewSHA3256 returns a hash computing the SHA3-256 digest.

func NewSHA3384

func NewSHA3384() stdhash.Hash

NewSHA3384 returns a hash computing the SHA3-384 digest.

func NewSHA3512

func NewSHA3512() stdhash.Hash

NewSHA3512 returns a hash computing the SHA3-512 digest.

func NewSHA384 added in v1.0.1

func NewSHA384() stdhash.Hash

NewSHA384 returns a hash computing the SHA-384 digest.

func NewSHA512 added in v1.0.1

func NewSHA512() stdhash.Hash

NewSHA512 returns a hash computing the SHA-512 digest.

func NewXoodyak

func NewXoodyak() stdhash.Hash

NewXoodyak returns a hash.Hash computing the 32-byte Xoodyak digest.

func ParallelHash128

func ParallelHash128(msg []byte, blockSize int, outLen int, customization []byte) ([]byte, error)

ParallelHash128 computes ParallelHash-128 over msg using the specified block size and produces outLen bytes of output. The customization string may be nil.

func ParallelHash256

func ParallelHash256(msg []byte, blockSize int, outLen int, customization []byte) ([]byte, error)

ParallelHash256 computes ParallelHash-256 over msg using the provided block size and returns outLen bytes of output.

func Sum224

func Sum224(data []byte) [sha3Size224]byte

Sum224 returns the SHA3-224 digest of the input.

func Sum256

func Sum256(data []byte) [sha3Size256]byte

Sum256 returns the SHA3-256 digest of the input.

func Sum384

func Sum384(data []byte) [sha3Size384]byte

Sum384 returns the SHA3-384 digest of the input.

func Sum512

func Sum512(data []byte) [sha3Size512]byte

Sum512 returns the SHA3-512 digest of the input.

func SumBLAKE3

func SumBLAKE3(msg []byte) []byte

SumBLAKE3 computes the 32-byte BLAKE3 digest of msg in a single shot.

func SumSHA224 added in v1.0.1

func SumSHA224(data []byte) [sha2Size224]byte

SumSHA224 returns the SHA-224 digest of the input.

func SumSHA256 added in v1.0.1

func SumSHA256(data []byte) [sha2Size256]byte

SumSHA256 returns the SHA-256 digest of the input.

func SumSHA384 added in v1.0.1

func SumSHA384(data []byte) [sha2Size384]byte

SumSHA384 returns the SHA-384 digest of the input.

func SumSHA512 added in v1.0.1

func SumSHA512(data []byte) [sha2Size512]byte

SumSHA512 returns the SHA-512 digest of the input.

func SumXoodyak

func SumXoodyak(msg []byte) [DigestSize]byte

SumXoodyak returns the Xoodyak hash of msg.

func TupleHash128

func TupleHash128(tuple [][]byte, outLen int, customization []byte) ([]byte, error)

TupleHash128 returns the TupleHash-128 digest of the provided tuple, producing outLen bytes of output. The optional customization string may be nil.

func TupleHash256

func TupleHash256(tuple [][]byte, outLen int, customization []byte) ([]byte, error)

TupleHash256 returns the TupleHash-256 digest of the provided tuple.

Types

type Blake2bBuilder

type Blake2bBuilder struct {
	// contains filtered or unexported fields
}

Blake2bBuilder constructs keyed or unkeyed BLAKE2b hash and XOF instances.

func NewBlake2bBuilder

func NewBlake2bBuilder() Blake2bBuilder

NewBlake2bBuilder returns a builder configured for the default 64-byte BLAKE2b digest without a key.

func (Blake2bBuilder) Hash

func (b Blake2bBuilder) Hash() (stdhash.Hash, error)

Hash returns a stateful hash.Hash instance implementing the configured BLAKE2b variant.

func (Blake2bBuilder) Hasher

func (b Blake2bBuilder) Hasher() (Hasher, error)

Hasher returns a stateless helper implementing hash.Hasher.

func (Blake2bBuilder) Key

func (b Blake2bBuilder) Key(key []byte) Blake2bBuilder

Key configures the secret key used for MAC mode. The key is copied so that subsequent modifications by the caller do not affect the builder.

func (Blake2bBuilder) Size

func (b Blake2bBuilder) Size(size int) Blake2bBuilder

Size sets the desired digest length. The value must be between 1 and 64.

func (Blake2bBuilder) Sum

func (b Blake2bBuilder) Sum(msg []byte) ([]byte, error)

Sum computes a single-shot digest using the configured parameters.

func (Blake2bBuilder) XOF

func (b Blake2bBuilder) XOF(length uint32) (xof.XOF, error)

XOF returns an extendable-output function using the configured key and the requested output length. For unknown-length output use Blake2bXOFUnknown.

type Blake2sBuilder

type Blake2sBuilder struct {
	// contains filtered or unexported fields
}

Blake2sBuilder constructs keyed or unkeyed BLAKE2s hash and XOF instances.

func NewBlake2sBuilder

func NewBlake2sBuilder() Blake2sBuilder

NewBlake2sBuilder returns a builder configured for the default 32-byte BLAKE2s digest without a key.

func (Blake2sBuilder) Hash

func (b Blake2sBuilder) Hash() (stdhash.Hash, error)

Hash returns a stateful hash.Hash instance implementing the configured BLAKE2s variant.

func (Blake2sBuilder) Hasher

func (b Blake2sBuilder) Hasher() (Hasher, error)

Hasher returns a stateless helper implementing hash.Hasher.

func (Blake2sBuilder) Key

func (b Blake2sBuilder) Key(key []byte) Blake2sBuilder

Key configures the secret key used for MAC mode. The key is copied so that subsequent modifications by the caller do not affect the builder.

func (Blake2sBuilder) Size

func (b Blake2sBuilder) Size(size int) Blake2sBuilder

Size sets the desired digest length. The value must be between 1 and 32.

func (Blake2sBuilder) Sum

func (b Blake2sBuilder) Sum(msg []byte) ([]byte, error)

Sum computes a single-shot digest using the configured parameters.

func (Blake2sBuilder) XOF

func (b Blake2sBuilder) XOF(length uint32) (xof.XOF, error)

XOF returns an extendable-output function using the configured key and the requested output length. For unknown-length output use Blake2sXOFUnknown.

type Hash

type Hash struct {
	// contains filtered or unexported fields
}

Hash implements the Xoodyak hash function (32-byte digest) using the Cyclist hash mode.

func (*Hash) BlockSize

func (h *Hash) BlockSize() int

func (*Hash) Hash

func (h *Hash) Hash(msg []byte) []byte

Hash computes the digest of msg without altering the streaming state.

func (*Hash) Reset

func (h *Hash) Reset()

func (*Hash) Size

func (h *Hash) Size() int

func (*Hash) Sum

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

func (*Hash) Write

func (h *Hash) Write(p []byte) (int, error)

type Hasher

type Hasher interface {
	Hash(msg []byte) []byte
	Size() int
}

Hasher defines the minimal single-shot hashing API exposed by the library.

It mirrors the simple AEAD interface in the aead package by offering a uniform helper for computing fixed-length digests without having to use the streaming hash.Hash interface from the standard library. Implementations are expected to be stateless and may be backed by any of the concrete hash primitives exposed under hash/.

Hash computes the digest of msg and returns the resulting bytes. Size reports the digest length in bytes.

func NewBLAKE3Hasher

func NewBLAKE3Hasher() Hasher

NewBLAKE3Hasher returns a stateless helper implementing hash.Hasher.

func NewBLAKE3KeyedHasher

func NewBLAKE3KeyedHasher(key []byte) (Hasher, error)

NewBLAKE3KeyedHasher returns a keyed helper implementing hash.Hasher.

func NewBlake2bHasher

func NewBlake2bHasher(size int, key []byte) (Hasher, error)

NewBlake2bHasher creates a stateless BLAKE2b helper with the given digest length and optional key.

func NewBlake2sHasher

func NewBlake2sHasher(size int, key []byte) (Hasher, error)

NewBlake2sHasher creates a stateless BLAKE2s helper with the given digest length and optional key.

func NewSHA224Hasher added in v1.0.1

func NewSHA224Hasher() Hasher

NewSHA224Hasher returns a stateless SHA-224 helper implementing hash.Hasher.

func NewSHA256Hasher added in v1.0.1

func NewSHA256Hasher() Hasher

NewSHA256Hasher returns a stateless SHA-256 helper implementing hash.Hasher.

func NewSHA3224Hasher

func NewSHA3224Hasher() Hasher

NewSHA3224Hasher returns a stateless SHA3-224 helper implementing hash.Hasher.

func NewSHA3256Hasher

func NewSHA3256Hasher() Hasher

NewSHA3256Hasher returns a stateless SHA3-256 helper implementing hash.Hasher.

func NewSHA3384Hasher

func NewSHA3384Hasher() Hasher

NewSHA3384Hasher returns a stateless SHA3-384 helper implementing hash.Hasher.

func NewSHA3512Hasher

func NewSHA3512Hasher() Hasher

NewSHA3512Hasher returns a stateless SHA3-512 helper implementing hash.Hasher.

func NewSHA384Hasher added in v1.0.1

func NewSHA384Hasher() Hasher

NewSHA384Hasher returns a stateless SHA-384 helper implementing hash.Hasher.

func NewSHA512Hasher added in v1.0.1

func NewSHA512Hasher() Hasher

NewSHA512Hasher returns a stateless SHA-512 helper implementing hash.Hasher.

func NewXoodyakHasher

func NewXoodyakHasher() Hasher

NewXoodyakHasher returns a stateless helper implementing hash.Hasher for Xoodyak.

Jump to

Keyboard shortcuts

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