 Documentation
      ¶
      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 ¶
Types ¶
type BinaryFixedLengthHasher ¶ added in v0.9.0
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 ¶ added in v0.9.0
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 ¶ added in v0.9.0
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 example Poseidon, MiMC etc.
func GetFieldHasher ¶ added in v0.10.0
func GetFieldHasher(name string, api frontend.API) (FieldHasher, error)
type StateStorer ¶ added in v0.12.0
type StateStorer interface {
	FieldHasher
	// State retrieves the current state of the hash function. Calling this
	// method should not destroy the current state and allow continue the use of
	// the current hasher. The number of returned Variable is implementation
	// dependent.
	State() []frontend.Variable
	// SetState sets the state of the hash function from a previously stored
	// state retrieved using [StateStorer.State] method. The implementation
	// returns an error if the number of supplied Variable does not match the
	// number of Variable expected.
	SetState(state []frontend.Variable) error
}
    StateStorer allows to store and retrieve the state of a hash function.
       Directories
      ¶
      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 ripemd160 implements in-circuit ripemd160 hash function. | Package ripemd160 implements in-circuit ripemd160 hash function. | 
| 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. |