package crypto

import "github.com/renegade-fi/golang-sdk/crypto"

Package crypto provides cryptographic primitives for the Renegade SDK

Index

Constants

const (
	// R_F is the number of full rounds in the Poseidon permutation
	R_F = 8 //nolint:revive

	// R_P is the number of partial rounds in the Poseidon permutation
	R_P = 56 //nolint:revive

	// WIDTH is the width of the Poseidon permutation's code
	WIDTH = 3

	// RATE is the rate of the sponge construction layered on the permutation
	RATE = 2

	// CAPACITY is the capacity of the sponge construction layered on the permutation
	CAPACITY = 1

	// ALPHA is the constant used to parameterize the S-box in the Poseidon permutation
	ALPHA = 5
)

Poseidon2Sponge is a sponge

Types

type Poseidon2Sponge

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

Poseidon2Sponge represents a sponge construction on top of the Poseidon2 permutation Modeled after the implementation in: https://github.com/renegade-fi/renegade/blob/main/renegade-crypto/src/hash/poseidon2.rs The original paper can be found at: https://eprint.iacr.org/2023/323

func NewPoseidon2Sponge

func NewPoseidon2Sponge() *Poseidon2Sponge

NewPoseidon2Sponge creates a new Poseidon2Sponge instance

func (*Poseidon2Sponge) Absorb

func (p *Poseidon2Sponge) Absorb(x fr.Element) error

Absorb absorbs a single scalar into the sponge

func (*Poseidon2Sponge) AbsorbBatch

func (p *Poseidon2Sponge) AbsorbBatch(x []fr.Element) error

AbsorbBatch absorbs a batch of scalars into the sponge

func (*Poseidon2Sponge) Hash

func (p *Poseidon2Sponge) Hash(seq []fr.Element) fr.Element

Hash hashes the given input and returns a single-squeeze

func (*Poseidon2Sponge) Squeeze

func (p *Poseidon2Sponge) Squeeze() fr.Element

Squeeze squeezes a single scalar from the sponge

func (*Poseidon2Sponge) SqueezeBatch

func (p *Poseidon2Sponge) SqueezeBatch(n int) []fr.Element

SqueezeBatch squeezes a batch of scalars from the sponge

type PoseidonCSPRNG

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

PoseidonCSPRNG is a CSPRNG based on the Poseidon2 permutation

func NewPoseidonCSPRNG

func NewPoseidonCSPRNG(seed fr.Element) *PoseidonCSPRNG

NewPoseidonCSPRNG creates a new PoseidonCSPRNG instance

func (*PoseidonCSPRNG) Next

func (p *PoseidonCSPRNG) Next() fr.Element

Next returns the next scalar in the CSPRNG

func (*PoseidonCSPRNG) NextN

func (p *PoseidonCSPRNG) NextN(n int) []fr.Element

NextN returns the next n scalars in the CSPRNG