Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::stdlib::FieldSponge< rate, capacity, t, Permutation, Builder > Class Template Reference

Implements the circuit form of a cryptographic sponge over prime fields. Implements the sponge specification from the Community Cryptographic Specification Project see https://github.com/C2SP/C2SP/blob/792c1254124f625d459bfe34417e8f6bdd02eb28/poseidon-sponge.md (Note: this spec was not accepted into the C2SP repo, we might want to reference something else!) More...

#include <sponge.hpp>

Public Types

enum  Mode { ABSORB , SQUEEZE }
 Defines what phase of the sponge algorithm we are in. More...
 
using field_t = stdlib::field_t< Builder >
 

Public Member Functions

 FieldSponge (Builder &builder_, field_t domain_iv=0)
 
std::array< field_t, rate > perform_duplex ()
 
void absorb (const field_t &input)
 
field_t squeeze ()
 

Static Public Member Functions

template<size_t out_len>
static std::array< field_t, out_len > hash_internal (Builder &builder, std::span< const field_t > input)
 Use the sponge to hash an input string.
 
static field_t hash_internal (Builder &builder, std::span< const field_t > input)
 

Public Attributes

std::array< field_t, t > state
 
std::array< field_t, rate > cache
 
size_t cache_size = 0
 
Mode mode = Mode::ABSORB
 
Builderbuilder
 

Detailed Description

template<size_t rate, size_t capacity, size_t t, typename Permutation, typename Builder>
class bb::stdlib::FieldSponge< rate, capacity, t, Permutation, Builder >

Implements the circuit form of a cryptographic sponge over prime fields. Implements the sponge specification from the Community Cryptographic Specification Project see https://github.com/C2SP/C2SP/blob/792c1254124f625d459bfe34417e8f6bdd02eb28/poseidon-sponge.md (Note: this spec was not accepted into the C2SP repo, we might want to reference something else!)

Note: If we ever use this sponge class for more than 1 hash functions, we should move this out of poseidon2 and into its own directory

Template Parameters
field_t
rate
capacity
t
Permutation

Definition at line 34 of file sponge.hpp.

Member Typedef Documentation

◆ field_t

template<size_t rate, size_t capacity, size_t t, typename Permutation , typename Builder >
using bb::stdlib::FieldSponge< rate, capacity, t, Permutation, Builder >::field_t = stdlib::field_t<Builder>

Definition at line 47 of file sponge.hpp.

Member Enumeration Documentation

◆ Mode

template<size_t rate, size_t capacity, size_t t, typename Permutation , typename Builder >
enum bb::stdlib::FieldSponge::Mode

Defines what phase of the sponge algorithm we are in.

   ABSORB: 'absorbing' field elements into the sponge
   SQUEEZE: compressing the sponge and extracting a field element
Enumerator
ABSORB 
SQUEEZE 

Definition at line 43 of file sponge.hpp.

Constructor & Destructor Documentation

◆ FieldSponge()

template<size_t rate, size_t capacity, size_t t, typename Permutation , typename Builder >
bb::stdlib::FieldSponge< rate, capacity, t, Permutation, Builder >::FieldSponge ( Builder builder_,
field_t  domain_iv = 0 
)
inline

Definition at line 58 of file sponge.hpp.

Member Function Documentation

◆ absorb()

template<size_t rate, size_t capacity, size_t t, typename Permutation , typename Builder >
void bb::stdlib::FieldSponge< rate, capacity, t, Permutation, Builder >::absorb ( const field_t input)
inline

Definition at line 93 of file sponge.hpp.

◆ hash_internal() [1/2]

template<size_t rate, size_t capacity, size_t t, typename Permutation , typename Builder >
template<size_t out_len>
static std::array< field_t, out_len > bb::stdlib::FieldSponge< rate, capacity, t, Permutation, Builder >::hash_internal ( Builder builder,
std::span< const field_t input 
)
inlinestatic

Use the sponge to hash an input string.

Template Parameters
out_len
is_variable_length.Distinguishes between hashes where the preimage length is constant/not constant
Parameters
input
Returns
std::array<field_t, out_len>

Definition at line 151 of file sponge.hpp.

◆ hash_internal() [2/2]

template<size_t rate, size_t capacity, size_t t, typename Permutation , typename Builder >
static field_t bb::stdlib::FieldSponge< rate, capacity, t, Permutation, Builder >::hash_internal ( Builder builder,
std::span< const field_t input 
)
inlinestatic

Definition at line 178 of file sponge.hpp.

◆ perform_duplex()

template<size_t rate, size_t capacity, size_t t, typename Permutation , typename Builder >
std::array< field_t, rate > bb::stdlib::FieldSponge< rate, capacity, t, Permutation, Builder >::perform_duplex ( )
inline

Definition at line 67 of file sponge.hpp.

◆ squeeze()

template<size_t rate, size_t capacity, size_t t, typename Permutation , typename Builder >
field_t bb::stdlib::FieldSponge< rate, capacity, t, Permutation, Builder >::squeeze ( )
inline

Definition at line 113 of file sponge.hpp.

Member Data Documentation

◆ builder

template<size_t rate, size_t capacity, size_t t, typename Permutation , typename Builder >
Builder* bb::stdlib::FieldSponge< rate, capacity, t, Permutation, Builder >::builder

Definition at line 56 of file sponge.hpp.

◆ cache

template<size_t rate, size_t capacity, size_t t, typename Permutation , typename Builder >
std::array<field_t, rate> bb::stdlib::FieldSponge< rate, capacity, t, Permutation, Builder >::cache

Definition at line 53 of file sponge.hpp.

◆ cache_size

template<size_t rate, size_t capacity, size_t t, typename Permutation , typename Builder >
size_t bb::stdlib::FieldSponge< rate, capacity, t, Permutation, Builder >::cache_size = 0

Definition at line 54 of file sponge.hpp.

◆ mode

template<size_t rate, size_t capacity, size_t t, typename Permutation , typename Builder >
Mode bb::stdlib::FieldSponge< rate, capacity, t, Permutation, Builder >::mode = Mode::ABSORB

Definition at line 55 of file sponge.hpp.

◆ state

template<size_t rate, size_t capacity, size_t t, typename Permutation , typename Builder >
std::array<field_t, t> bb::stdlib::FieldSponge< rate, capacity, t, Permutation, Builder >::state

Definition at line 50 of file sponge.hpp.


The documentation for this class was generated from the following file: