hash

package
v0.0.0-...-70ee9f5 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package hash provides an interface that hash functions (as gadget) should implement.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, builder func(api frontend.API) (FieldHasher, error))

Types

type BinaryFixedLengthHasher

type BinaryFixedLengthHasher interface {
	BinaryHasher
	// FixedLengthSum returns digest of the first length bytes.
	FixedLengthSum(length frontend.Variable) []uints.U8
}

BinaryFixedLengthHasher is like BinaryHasher, but assumes the length of the input is not full length as defined during compile time. This allows to compute digest of variable-length input, unlike BinaryHasher which assumes the length of the input is the total number of bytes written.

type BinaryHasher

type BinaryHasher interface {
	// Sum finalises the current hash and returns the digest.
	Sum() []uints.U8

	// Write writes more bytes into the current hash state.
	Write([]uints.U8)

	// Size returns the number of bytes this hash function returns in a call to
	// [BinaryHasher.Sum].
	Size() int
}

BinaryHasher hashes inputs into a short digest. It takes as inputs bytes and outputs byte array whose length depends on the underlying hash function. For SNARK-native hash functions use FieldHasher.

type FieldHasher

type FieldHasher interface {
	// Sum computes the hash of the internal state of the hash function.
	Sum() frontend.Variable

	// Write populate the internal state of the hash function with data. The inputs are native field elements.
	Write(data ...frontend.Variable)

	// Reset empty the internal state and put the intermediate state to zero.
	Reset()
}

FieldHasher hashes inputs into a short digest. This interface mocks BinaryHasher, but is more suitable in-circuit by assuming the inputs are scalar field elements and outputs digest as a field element. Such hash functions are for examle Poseidon, MiMC etc.

func GetFieldHasher

func GetFieldHasher(name string, api frontend.API) (FieldHasher, error)

Directories

Path Synopsis
Package mimc provides a ZKP-circuit function to compute a MiMC hash.
Package mimc provides a ZKP-circuit function to compute a MiMC hash.
Package sha2 implements SHA2 hash computation.
Package sha2 implements SHA2 hash computation.
Package sha3 provides ZKP circuits for SHA3 hash algorithms applying sponge construction over Keccak f-[1600] permutation function.
Package sha3 provides ZKP circuits for SHA3 hash algorithms applying sponge construction over Keccak f-[1600] permutation function.

Jump to

Keyboard shortcuts

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