Documentation ¶
Index ¶
- Constants
- type BytesWithDomain
- type Commitment
- type Decommitment
- type Hash
- func (hash *Hash) Clone() *Hash
- func (hash *Hash) Commit(data ...interface{}) (Commitment, Decommitment, error)
- func (hash *Hash) Decommit(c Commitment, d Decommitment, data ...interface{}) bool
- func (hash *Hash) Digest() io.Reader
- func (hash *Hash) Fork(data ...interface{}) *Hash
- func (hash *Hash) Sum() []byte
- func (hash *Hash) WriteAny(data ...interface{}) error
- type WriterToWithDomain
Constants ¶
const DigestLengthBytes = params.SecBytes * 2 // 64
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BytesWithDomain ¶
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.
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
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
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) 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 ¶
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) Sum ¶
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 ¶
WriteAny takes many different data types and writes them to the hash state.
Currently supported types:
- []byte
- *saferith.Nat
- *saferith.Int
- *saferith.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.