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 ¶
- Variables
- func Blake3Hash(data []byte) []byte
- func CombineHashes(hashes ...[]byte) []byte
- func DeriveIndependentGenerators(c curve.Curve, count int) ([]*curve.Point, error)
- func DeriveKey(masterKey []byte, context string, keyID int, length int) ([]byte, error)
- func DeterministicNonce(privateKey, messageHash []byte, modulus *big.Int) *big.Int
- func FiatShamirChallenge(transcript []byte, modulus *big.Int) *big.Int
- func HKDF(secret, salt, info []byte, length int) ([]byte, error)
- func HMAC(key, data []byte) []byte
- func Hash(data []byte, hashFunc HashFunction) []byte
- func HashCommit(value, nonce []byte) []byte
- func HashPoints(points ...*curve.Point) []byte
- func HashToCurve(data []byte, c curve.Curve) (*curve.Point, error)
- func HashToCurveRFC9380(data []byte, dst []byte, c curve.Curve) (*curve.Point, error)
- func HashToScalar(data []byte, modulus *big.Int, hashFunc HashFunction) *big.Int
- func MerkleRoot(leaves [][]byte) []byte
- func VerifyHMAC(key, data, expectedMAC []byte) bool
- func VerifyHashCommit(commitment, value, nonce []byte) bool
- type HashFunction
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
CombineHashes combines multiple hashes into a single hash Useful for Merkle tree construction or multi-party protocols
func DeriveIndependentGenerators ¶
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 ¶
DeriveKey derives a key from a master key and context information Uses HKDF with domain separation
func DeterministicNonce ¶
DeterministicNonce generates a deterministic nonce using RFC 6979 This prevents nonce reuse attacks in signature schemes
func FiatShamirChallenge ¶
FiatShamirChallenge generates a challenge for Fiat-Shamir transform This makes interactive proofs non-interactive
func HKDF ¶
HKDF derives key material using HKDF (HMAC-based Key Derivation Function) This is useful for deriving multiple keys from a single master key
func Hash ¶
func Hash(data []byte, hashFunc HashFunction) []byte
Hash computes the hash of data using the specified hash function
func HashCommit ¶
HashCommit creates a hash-based commitment: H(value || nonce) This is non-homomorphic but simpler than Pedersen commitments
func HashPoints ¶
HashPoints hashes multiple curve points into a single value Used for Fiat-Shamir transform in zero-knowledge proofs
func HashToCurve ¶
HashToCurve maps arbitrary data to a curve point deterministically Uses production-ready RFC 9380 implementation
func HashToCurveRFC9380 ¶
HashToCurveRFC9380 implements RFC 9380 hash-to-curve This is a production-ready, standardized method
func HashToScalar ¶
HashToScalar converts arbitrary data to a scalar in the field Uses hash-and-reduce method: hash(data) mod order
func MerkleRoot ¶
MerkleRoot computes the Merkle root of a list of leaves
func VerifyHMAC ¶
VerifyHMAC verifies HMAC in constant time
func VerifyHashCommit ¶
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 )