poseidon2

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2025 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

Package poseidon2 implements the Poseidon2 permutation

Poseidon2 permutation is a cryptographic permutation for algebraic hashes. See the original paper by Grassi, Khovratovich and Schofnegger for the full details.

This implementation is based on the reference implementation from HorizenLabs. See the specifications for parameter choices.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSizebuffer = errors.New("the size of the input should match the size of the hash buffer")
)
View Source
var GetDefaultParameters = sync.OnceValue(func() *Parameters {
	return NewParameters(2, 6, 40)
})

GetDefaultParameters returns a set of parameters for the Poseidon2 permutation. The default parameters are: - width: 2 for compression 3 for sponge - nbFullRounds: 6 - nbPartialRounds: 26

Functions

func DegreeSBox added in v0.17.0

func DegreeSBox() int

DegreeSBox returns the degree of the sBox function used in the Poseidon2 permutation.

func NewMerkleDamgardHasher added in v0.17.0

func NewMerkleDamgardHasher() gnarkHash.StateStorer

NewMerkleDamgardHasher returns a Poseidon2 hasher using the Merkle-Damgard construction with the default parameters.

Types

type Parameters added in v0.17.0

type Parameters struct {
	// len(preimage)+len(digest)=len(preimage)+ceil(log(2*<security_level>/r))
	Width int

	// number of full rounds (even number)
	NbFullRounds int

	// number of partial rounds
	NbPartialRounds int

	// derived round keys from the parameter seed and curve ID
	RoundKeys [][]fr.Element
}

Parameters describing the Poseidon2 implementation. Use NewParameters or NewParametersWithSeed to initialize a new set of parameters to deterministically precompute the round keys.

func NewParameters added in v0.17.0

func NewParameters(width, nbFullRounds, nbPartialRounds int) *Parameters

NewParameters returns a new set of parameters for the Poseidon2 permutation. After creating the parameters, the round keys are initialized deterministically from the seed which is a digest of the parameters and curve ID.

func NewParametersWithSeed added in v0.17.0

func NewParametersWithSeed(width, nbFullRounds, nbPartialRounds int, seed string) *Parameters

NewParametersWithSeed returns a new set of parameters for the Poseidon2 permutation. After creating the parameters, the round keys are initialized deterministically from the given seed.

func (*Parameters) String added in v0.17.0

func (p *Parameters) String() string

String returns a string representation of the parameters. It is unique for specific parameters and curve.

type Permutation added in v0.17.0

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

Permutation stores the buffer of the Poseidon2 permutation and provides Poseidon2 permutation methods on the buffer

func NewPermutation added in v0.17.0

func NewPermutation(t, rf, rp int) *Permutation

NewPermutation returns a new Poseidon2 permutation instance.

func NewPermutationWithSeed added in v0.17.0

func NewPermutationWithSeed(t, rf, rp int, seed string) *Permutation

NewPermutationWithSeed returns a new Poseidon2 permutation instance with a given seed.

func (*Permutation) BlockSize added in v0.17.0

func (h *Permutation) BlockSize() int

func (*Permutation) Compress added in v0.17.0

func (h *Permutation) Compress(left []byte, right []byte) ([]byte, error)

Compress uses the permutation to compress the left and right input in a collision resistant manner. Returns an error if the permutation instance is not initialized with a width of 2.

func (*Permutation) Permutation added in v0.17.0

func (h *Permutation) Permutation(input []fr.Element) error

Permutation applies the permutation on input, and stores the result in input.

Jump to

Keyboard shortcuts

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