Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::stdlib::SHA256< Builder > Class Template Reference

#include <sha256.hpp>

Classes

struct  sparse_ch_value
 
struct  sparse_maj_value
 
struct  sparse_value
 
struct  sparse_witness_limbs
 

Static Public Member Functions

static std::array< field_ct, 8 > sha256_block (const std::array< field_ct, 8 > &h_init, const std::array< field_ct, 16 > &input)
 
static std::array< field_ct, 64 > extend_witness (const std::array< field_ct, 16 > &w_in)
 
static byte_array< Builderhash (const byte_array_ct &input)
 

Private Types

using field_ct = field_t< Builder >
 
using byte_array_ct = byte_array< Builder >
 

Static Private Member Functions

static void prepare_constants (std::array< field_ct, 8 > &input)
 
static sparse_witness_limbs convert_witness (const field_ct &w)
 
static field_ct choose (sparse_value &e, const sparse_value &f, const sparse_value &g)
 
static field_ct majority (sparse_value &a, const sparse_value &b, const sparse_value &c)
 
static sparse_value map_into_choose_sparse_form (const field_ct &e)
 
static sparse_value map_into_maj_sparse_form (const field_ct &e)
 
static field_ct add_normalize (const field_ct &a, const field_ct &b)
 

Static Private Attributes

static constexpr uint64_t init_constants [8]
 
static constexpr fr base { 16 }
 
static constexpr std::array< fr, 4 > left_multipliers
 
static constexpr std::array< fr, 4 > right_multipliers
 
static constexpr uint64_t round_constants [64]
 

Detailed Description

template<typename Builder>
class bb::stdlib::SHA256< Builder >

Definition at line 19 of file sha256.hpp.

Member Typedef Documentation

◆ byte_array_ct

template<typename Builder >
using bb::stdlib::SHA256< Builder >::byte_array_ct = byte_array<Builder>
private

Definition at line 22 of file sha256.hpp.

◆ field_ct

template<typename Builder >
using bb::stdlib::SHA256< Builder >::field_ct = field_t<Builder>
private

Definition at line 21 of file sha256.hpp.

Member Function Documentation

◆ add_normalize()

template<typename Builder >
field_t< Builder > bb::stdlib::SHA256< Builder >::add_normalize ( const field_ct a,
const field_ct b 
)
staticprivate

Definition at line 213 of file sha256.cpp.

◆ choose()

template<typename Builder >
field_t< Builder > bb::stdlib::SHA256< Builder >::choose ( sparse_value e,
const sparse_value f,
const sparse_value g 
)
staticprivate

Definition at line 162 of file sha256.cpp.

◆ convert_witness()

template<typename Builder >
SHA256< Builder >::sparse_witness_limbs bb::stdlib::SHA256< Builder >::convert_witness ( const field_ct w)
staticprivate

Definition at line 34 of file sha256.cpp.

◆ extend_witness()

template<typename Builder >
std::array< field_t< Builder >, 64 > bb::stdlib::SHA256< Builder >::extend_witness ( const std::array< field_ct, 16 > &  w_in)
static

Definition at line 60 of file sha256.cpp.

◆ hash()

template<typename Builder >
byte_array< Builder > bb::stdlib::SHA256< Builder >::hash ( const byte_array_ct input)
static

Definition at line 308 of file sha256.cpp.

◆ majority()

template<typename Builder >
field_t< Builder > bb::stdlib::SHA256< Builder >::majority ( sparse_value a,
const sparse_value b,
const sparse_value c 
)
staticprivate

Definition at line 188 of file sha256.cpp.

◆ map_into_choose_sparse_form()

template<typename Builder >
SHA256< Builder >::sparse_value bb::stdlib::SHA256< Builder >::map_into_choose_sparse_form ( const field_ct e)
staticprivate

Definition at line 142 of file sha256.cpp.

◆ map_into_maj_sparse_form()

template<typename Builder >
SHA256< Builder >::sparse_value bb::stdlib::SHA256< Builder >::map_into_maj_sparse_form ( const field_ct e)
staticprivate

Definition at line 152 of file sha256.cpp.

◆ prepare_constants()

template<typename Builder >
void bb::stdlib::SHA256< Builder >::prepare_constants ( std::array< field_ct, 8 > &  input)
staticprivate

Definition at line 26 of file sha256.cpp.

◆ sha256_block()

template<typename Builder >
std::array< field_t< Builder >, 8 > bb::stdlib::SHA256< Builder >::sha256_block ( const std::array< field_ct, 8 > &  h_init,
const std::array< field_ct, 16 > &  input 
)
static

Initialize round variables with previous block output

We can initialize round variables a and c and put value h_init[0] and h_init[4] in .normal, and don't do lookup for maj_output, because majority and choose functions will do that in the next step

Extend witness

Apply SHA-256 compression function to the message schedule

Add into previous block output and return

At this point, a malicilous prover could tweak the add_normalise function and the result could be 'overflowed'. Thus, we need 32-bit range checks on the outputs. Note that we won't need range checks while applying the SHA-256 compression function because the outputs of the lookup table ensures that the output is contrained to 32 bits.

Definition at line 237 of file sha256.cpp.

Member Data Documentation

◆ base

template<typename Builder >
constexpr fr bb::stdlib::SHA256< Builder >::base { 16 }
staticconstexprprivate

Definition at line 41 of file sha256.hpp.

◆ init_constants

template<typename Builder >
constexpr uint64_t bb::stdlib::SHA256< Builder >::init_constants[8]
staticconstexprprivate
Initial value:
{ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 }

Definition at line 38 of file sha256.hpp.

◆ left_multipliers

template<typename Builder >
constexpr std::array<fr, 4> bb::stdlib::SHA256< Builder >::left_multipliers
staticconstexprprivate
Initial value:
{
(base.pow(32 - 7) + base.pow(32 - 18)),
(base.pow(32 - 18 + 3) + 1),
(base.pow(32 - 18 + 10) + base.pow(10 - 7) + base.pow(10 - 3)),
(base.pow(18 - 7) + base.pow(18 - 3) + 1),
}
static constexpr fr base
Definition sha256.hpp:41
BB_INLINE constexpr field pow(const uint256_t &exponent) const noexcept

Definition at line 43 of file sha256.hpp.

◆ right_multipliers

template<typename Builder >
constexpr std::array<fr, 4> bb::stdlib::SHA256< Builder >::right_multipliers
staticconstexprprivate
Initial value:
{
base.pow(32 - 17) + base.pow(32 - 19),
base.pow(32 - 17 + 3) + base.pow(32 - 19 + 3),
base.pow(32 - 19 + 10) + fr(1),
base.pow(18 - 17) + base.pow(18 - 10),
}
field< Bn254FrParams > fr
Definition fr.hpp:174

Definition at line 50 of file sha256.hpp.

◆ round_constants

template<typename Builder >
constexpr uint64_t bb::stdlib::SHA256< Builder >::round_constants[64]
staticconstexprprivate
Initial value:
{
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
}

Definition at line 57 of file sha256.hpp.


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