hash_comm

package
v0.0.0-...-7685c8a Latest Latest
Warning

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

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

README

Hash-Based Commitments

This package provides a simple, non-homomorphic commitment scheme built from a keyed BLAKE2b-256 hash (HMAC-style). A random witness is mixed with the message and keyed hash to produce a binding digest.

Overview

  • Commitment to message with randomness witness: C = HMAC_key(witness || message) using BLAKE2b-256 by default.
  • Key is derived from a session identifier (SID), domain separation tag, and optional CRS transcripts.
  • Witness randomness is always 32 bytes; the resulting commitment digest is 32 bytes.
  • All types are Go value types suitable for copying and CBOR/binary transport via their byte representations.

Types

  • Key: 32-byte secret key for the HMAC; derive with NewKeyFromCRSBytes.
  • Message: arbitrary byte slice to commit.
  • Witness: 32-byte nonce mixed into the commitment.
  • Commitment: 32-byte digest output.
  • Scheme: convenience wrapper exposing a committer and verifier bound to a Key.

Algorithms

  • NewKeyFromCRSBytes(sid, dst, crs...): derives the commitment key from the SID, domain separation tag, and optional CRS blobs.
  • Commit(message, prng): samples a fresh witness from prng, returns (commitment, witness).
  • CommitWithWitness(message, witness): deterministic commitment using caller-provided randomness.
  • Verify(commitment, message, witness): recomputes the digest and checks equality.

Notes

  • HmacFunc is configurable for testing; it defaults to blake2b.New256.
  • The scheme is computationally binding and hiding assuming the PRF security of the keyed hash and the unpredictability of the witness.

Documentation

Overview

Package hash_comm provides a simple, non-homomorphic commitment scheme built from a keyed BLAKE2b-256 hash (HMAC-style).

See README.md for details.

Index

Constants

View Source
const (
	KeySize    = 32
	DigestSize = 32

	// Name identifies the hash-based commitment scheme.
	Name commitments.Name = "KMACBasedCommitmentScheme"
)

Variables

View Source
var (
	ErrInvalidArgument = errs.New("invalid argument")
	ErrFailed          = errs.New("failed")
)
View Source
var (

	// HmacFunc defines the hash function used to instantiate the HMAC-based commitments.
	HmacFunc = blake2b.New256
)

Functions

This section is empty.

Types

type Commitment

type Commitment [DigestSize]byte

Commitment is the hash digest produced by the commitment algorithm.

func (Commitment) Bytes

func (c Commitment) Bytes() []byte

Bytes returns the raw commitment digest bytes.

func (Commitment) Equal

func (c Commitment) Equal(other Commitment) bool

type Committer

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

Committer computes hash-based commitments with an HMAC keyed by the CRS output.

func (*Committer) Commit

func (c *Committer) Commit(message Message, prng io.Reader) (commitment Commitment, witness Witness, err error)

Commit samples fresh witness randomness and computes a commitment to the message.

func (*Committer) CommitWithWitness

func (c *Committer) CommitWithWitness(message Message, witness Witness) (commitment Commitment, err error)

CommitWithWitness commits to the message using caller-supplied witness randomness.

type CommitterOption

type CommitterOption = func(*Committer) error

CommitterOption is a functional option for configuring committers.

type Key

type Key [KeySize]byte

Key is the secret HMAC key derived from the CRS.

func NewKeyFromCRSBytes

func NewKeyFromCRSBytes(sid network.SID, dst string, crs ...[]byte) (Key, error)

NewKeyFromCRSBytes derives a commitment key from the SID, domain separation tag and CRS transcripts.

type Message

type Message []byte

Message is an arbitrary byte slice being committed.

type Scheme

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

Scheme bundles the hash-based committer and verifier using a shared key.

func NewScheme

func NewScheme(key Key) (*Scheme, error)

NewScheme constructs the hash-based commitment scheme with the provided key.

func (*Scheme) Committer

func (s *Scheme) Committer(opts ...CommitterOption) (*Committer, error)

Committer returns a committer initialised with the scheme key.

func (*Scheme) Key

func (s *Scheme) Key() Key

Key returns the scheme key material.

func (*Scheme) Name

func (*Scheme) Name() commitments.Name

Name returns the identifier of the hash-based commitment scheme.

func (*Scheme) Verifier

func (s *Scheme) Verifier(opts ...VerifierOption) (*Verifier, error)

Verifier returns a verifier compatible with commitments produced by the scheme.

type Verifier

Verifier checks commitments against provided messages and witnesses.

type VerifierOption

type VerifierOption = func(*Verifier) error

VerifierOption is a functional option for configuring verifiers.

type Witness

type Witness [DigestSize]byte

Witness is the random nonce mixed into the commitment.

func (Witness) Bytes

func (w Witness) Bytes() []byte

Bytes returns the raw witness bytes.

Jump to

Keyboard shortcuts

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