hash

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DigestLengthBytes = params.SecBytes * 2 // 64

Variables

This section is empty.

Functions

This section is empty.

Types

type BytesWithDomain

type BytesWithDomain struct {
	TheDomain string
	Bytes     []byte
}

BytesWithDomain is a useful wrapper to annotate some chunk of data with a domain.

The intention is to wrap some data using this struct, and then call WriteWithDomain, or use this struct as a WriterToWithDomain somewhere else.

func (BytesWithDomain) Domain

func (b BytesWithDomain) Domain() string

Domain implements WriterToWithDomain.

func (BytesWithDomain) WriteTo

func (b BytesWithDomain) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo.

type Commitment

type Commitment []byte

func (Commitment) Domain

func (Commitment) Domain() string

Domain implements WriterToWithDomain, and separates this type within hash.Hash.

func (Commitment) Validate

func (c Commitment) Validate() error

func (Commitment) WriteTo

func (c Commitment) WriteTo(w io.Writer) (int64, error)

WriteTo implements the io.WriterTo interface for Commitment.

type Decommitment

type Decommitment []byte

func (Decommitment) Domain

func (Decommitment) Domain() string

Domain implements WriterToWithDomain, and separates this type within hash.Hash.

func (Decommitment) Validate

func (d Decommitment) Validate() error

func (Decommitment) WriteTo

func (d Decommitment) WriteTo(w io.Writer) (int64, error)

WriteTo implements the io.WriterTo interface for Decommitment.

type Hash

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

Hash is the hash function we use for generating commitments, consuming CMP types, etc.

Internally, this is a wrapper around sha3.ShakeHash, but any hash function with an easily extendable output would work as well.

func New

func New(initialData ...WriterToWithDomain) *Hash

New creates a Hash struct where the internal hash function is initialized with "CMP-BLAKE".

func (*Hash) Clone

func (hash *Hash) Clone() *Hash

Clone returns a copy of the Hash in its current state.

func (*Hash) Commit

func (hash *Hash) Commit(data ...interface{}) (Commitment, Decommitment, error)

Commit creates a commitment to data, and returns a commitment hash, and a decommitment string such that commitment = h(data, decommitment).

func (*Hash) Decommit

func (hash *Hash) Decommit(c Commitment, d Decommitment, data ...interface{}) bool

Decommit verifies that the commitment corresponds to the data and decommitment such that commitment = h(data, decommitment).

func (*Hash) Digest

func (hash *Hash) Digest() io.Reader

Digest returns a reader for the current output of the function.

This finalizes the current state of the hash, and returns what's essentially a stream of random bytes.

func (*Hash) Fork

func (hash *Hash) Fork(data ...interface{}) *Hash

Fork clones this hash, and then writes some data.

func (*Hash) Sum

func (hash *Hash) Sum() []byte

Sum returns a slice of length DigestLengthBytes resulting from the current hash state. If a different length is required, use io.ReadFull(hash.Digest(), out) instead.

func (*Hash) WriteAny

func (hash *Hash) WriteAny(data ...interface{}) error

WriteAny takes many different data types and writes them to the hash state.

Currently supported types:

  • []byte
  • *safenum.Nat
  • *safenum.Int
  • *safenum.Modulus
  • hash.WriterToWithDomain

This function will apply its own domain separation for the first two types. The last type already suggests which domain to use, and this function respects it.

type WriterToWithDomain

type WriterToWithDomain interface {
	io.WriterTo

	// Domain returns a context string, which should be unique for each implementor
	Domain() string
}

WriterToWithDomain represents a type writing itself, and knowing its domain.

Providing a domain string lets us distinguish the output of different types implementing this same interface.

Jump to

Keyboard shortcuts

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