hashing

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

hashing

Core hashing utilities providing generic hash, HMAC, and KMAC operations with support for length-prefixed encoding.

Subpackages

  • bip340 - BIP-340 tagged hashing for Schnorr signatures
  • kmac - KMAC (Keccak Message Authentication Code) implementation
  • poseidon - Poseidon hash function for zero-knowledge proofs

Documentation

Overview

Package hashing provides core hashing utilities providing generic hash, HMAC, and KMAC operations with support for length-prefixed encoding.

See README.md for details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash[H hash.Hash](hashFunc func() H, xs ...[]byte) ([]byte, error)

Hash iteratively writes all the inputs to the given hash function and returns the result.

func HashChain

func HashChain[H hash.Hash](hashFunc func() H, xs ...[]byte) ([]byte, error)

HashChain computes an iterated hash where each input is hashed together with the previous output. It starts with a zero-initialised buffer and iteratively computes H(previous || input) for each input.

func HashFuncTypeErase

func HashFuncTypeErase[H hash.Hash](hashFunc func() H) func() hash.Hash

HashFuncTypeErase converts a generic hash constructor to a non-generic one returning hash.Hash. This is useful when interfacing with APIs that require func() hash.Hash, such as crypto/hmac.

func HashIndexLengthPrefixed

func HashIndexLengthPrefixed[H hash.Hash](hashFunc func() H, xs ...[]byte) ([]byte, error)

HashIndexLengthPrefixed hashes the inputs after encoding each with its index and length prefix. This encoding ensures that different input sequences produce distinct hash inputs.

func Hmac

func Hmac[H hash.Hash](key []byte, hashFunc func() H, xs ...[]byte) ([]byte, error)

Hmac iteratively writes all the inputs to an hmac (defined by the hash function and the key) and returns the result.

func HmacIndexLengthPrefixed

func HmacIndexLengthPrefixed[H hash.Hash](key []byte, hashFunc func() H, xs ...[]byte) ([]byte, error)

HmacIndexLengthPrefixed computes an HMAC over the inputs after encoding each with its index and length prefix.

func Kmac

func Kmac(key, customizationString []byte, tagSize int, h func(key []byte, tagSize int, customizationString []byte) (*kmac.Kmac, error), xs ...[]byte) ([]byte, error)

Kmac computes a KMAC (Keccak Message Authentication Code) over the inputs using a cSHAKE function. The key must be at least half the output size to meet the security level requirements.

func KmacIndexLengthPrefixed

func KmacIndexLengthPrefixed(key, customizationString []byte, tagSize int, h func(key []byte, tagSize int, customizationString []byte) (*kmac.Kmac, error), xs ...[]byte) ([]byte, error)

KmacIndexLengthPrefixed computes a KMAC over the inputs after encoding each with its index and length prefix.

Types

This section is empty.

Directories

Path Synopsis
Package bip340 provides bIP-340 tagged hash implementation for Schnorr signatures.
Package bip340 provides bIP-340 tagged hash implementation for Schnorr signatures.
Package kmac provides kMAC (Keccak Message Authentication Code) implementation per NIST SP 800-185.
Package kmac provides kMAC (Keccak Message Authentication Code) implementation per NIST SP 800-185.
Package poseidon provides poseidon hash function over the Pallas base field, designed for efficient use in zero-knowledge proof systems.
Package poseidon provides poseidon hash function over the Pallas base field, designed for efficient use in zero-knowledge proof systems.

Jump to

Keyboard shortcuts

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