hash

package
v0.0.0-...-37b37ea Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package hash provides cryptographic hash functions and hash-to-curve operations

hash_to_curve.go implements RFC 9380 compliant hash-to-curve

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNilCurve is returned when a nil curve is provided
	ErrNilCurve = errors.New("curve cannot be nil")

	// ErrInvalidLength is returned when an invalid length is specified
	ErrInvalidLength = errors.New("length must be positive")

	// ErrInvalidHash is returned when hash verification fails
	ErrInvalidHash = errors.New("hash verification failed")

	// ErrHashToCurveFailed is returned when hash-to-curve fails
	ErrHashToCurveFailed = errors.New("hash-to-curve failed to find valid point")
)

Functions

func Blake3Hash

func Blake3Hash(data []byte) []byte

Blake3Hash computes BLAKE3 hash BLAKE3 is faster than SHA-256 and suitable for high-performance scenarios Currently uses SHA-256 as a secure fallback; BLAKE3 can be added via github.com/zeebo/blake3 if needed

func CombineHashes

func CombineHashes(hashes ...[]byte) []byte

CombineHashes combines multiple hashes into a single hash Useful for Merkle tree construction or multi-party protocols

func DeriveIndependentGenerators

func DeriveIndependentGenerators(c curve.Curve, count int) ([]*curve.Point, error)

DeriveIndependentGenerators derives multiple independent curve generators This is used for Pedersen commitments and similar protocols Uses RFC 9380 hash-to-curve with different domain separation tags

func DeriveKey

func DeriveKey(masterKey []byte, context string, keyID int, length int) ([]byte, error)

DeriveKey derives a key from a master key and context information Uses HKDF with domain separation

func DeterministicNonce

func DeterministicNonce(privateKey, messageHash []byte, modulus *big.Int) *big.Int

DeterministicNonce generates a deterministic nonce using RFC 6979 This prevents nonce reuse attacks in signature schemes

func FiatShamirChallenge

func FiatShamirChallenge(transcript []byte, modulus *big.Int) *big.Int

FiatShamirChallenge generates a challenge for Fiat-Shamir transform This makes interactive proofs non-interactive

func HKDF

func HKDF(secret, salt, info []byte, length int) ([]byte, error)

HKDF derives key material using HKDF (HMAC-based Key Derivation Function) This is useful for deriving multiple keys from a single master key

func HMAC

func HMAC(key, data []byte) []byte

HMAC computes HMAC-SHA256 of data with given key

func Hash

func Hash(data []byte, hashFunc HashFunction) []byte

Hash computes the hash of data using the specified hash function

func HashCommit

func HashCommit(value, nonce []byte) []byte

HashCommit creates a hash-based commitment: H(value || nonce) This is non-homomorphic but simpler than Pedersen commitments

func HashPoints

func HashPoints(points ...*curve.Point) []byte

HashPoints hashes multiple curve points into a single value Used for Fiat-Shamir transform in zero-knowledge proofs

func HashToCurve

func HashToCurve(data []byte, c curve.Curve) (*curve.Point, error)

HashToCurve maps arbitrary data to a curve point deterministically Uses production-ready RFC 9380 implementation

func HashToCurveRFC9380

func HashToCurveRFC9380(data []byte, dst []byte, c curve.Curve) (*curve.Point, error)

HashToCurveRFC9380 implements RFC 9380 hash-to-curve This is a production-ready, standardized method

func HashToScalar

func HashToScalar(data []byte, modulus *big.Int, hashFunc HashFunction) *big.Int

HashToScalar converts arbitrary data to a scalar in the field Uses hash-and-reduce method: hash(data) mod order

func MerkleRoot

func MerkleRoot(leaves [][]byte) []byte

MerkleRoot computes the Merkle root of a list of leaves

func VerifyHMAC

func VerifyHMAC(key, data, expectedMAC []byte) bool

VerifyHMAC verifies HMAC in constant time

func VerifyHashCommit

func VerifyHashCommit(commitment, value, nonce []byte) bool

VerifyHashCommit verifies a hash-based commitment

Types

type HashFunction

type HashFunction int

HashFunction represents a cryptographic hash function

const (
	// SHA256 uses SHA-256 hash function
	SHA256 HashFunction = iota
	// SHA512 uses SHA-512 hash function
	SHA512
)

Jump to

Keyboard shortcuts

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