barretenberg
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
crypto Namespace Reference

Classes

class  FieldSponge
 Implements 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...
 
class  generator_data
 class that stores precomputed generators used for Pedersen commitments and Pedersen hashes More...
 
struct  GeneratorContext
 
class  pedersen_commitment_base
 Performs pedersen commitments! More...
 
class  pedersen_hash_base
 Performs pedersen hashes! More...
 
class  Poseidon2
 
struct  Poseidon2Bn254ScalarFieldParams
 
class  Poseidon2Permutation
 Applies the Poseidon2 permutation function from https://eprint.iacr.org/2023/323 . This algorithm was implemented using https://github.com/HorizenLabs/poseidon2 as a reference. More...
 

Typedefs

using pedersen_commitment = pedersen_commitment_base< curve::Grumpkin >
 
using pedersen_hash = pedersen_hash_base< curve::Grumpkin >
 

Functions

template<typename Hash , typename MessageContainer , typename KeyContainer >
std::array< uint8_t, Hash::OUTPUT_SIZE > hmac (const MessageContainer &message, const KeyContainer &key)
 Compute an HMAC given a secret key and a message.
 
template<typename Hash , typename Fr , typename MessageContainer , typename KeyContainer >
requires (Hash::OUTPUT_SIZE == 32)
Fr get_unbiased_field_from_hmac (const MessageContainer &message, const KeyContainer &key)
 Takes a size-HASH_OUTPUT buffer from HMAC and converts into a field element.
 
 TEST (Pedersen, Commitment)
 
 TEST (Pedersen, CommitmentWithZero)
 
 TEST (Pedersen, CommitmentProf)
 
 TEST (Pedersen, GeneratorPrinter)
 
 TEST (Pedersen, Hash)
 
 TEST (Pedersen, HashWithIndex)
 

Detailed Description

AES-128 Cipher

Implements AES-128 block cipher, and buffer encryption using cbc cipher chaining

Based off of tiny-AES by @kokke : https://github.com/kokke/tiny-AES-c

Function Documentation

◆ get_unbiased_field_from_hmac()

template<typename Hash , typename Fr , typename MessageContainer , typename KeyContainer >
requires (Hash::OUTPUT_SIZE == 32)
Fr crypto::get_unbiased_field_from_hmac ( const MessageContainer &  message,
const KeyContainer &  key 
)

Takes a size-HASH_OUTPUT buffer from HMAC and converts into a field element.

We assume HASH_OUTPUT = 32. Reducing HMAC(key, message) modulo r would result in an unacceptable bias. We hash input with 0 and 1 to produce 64 bytes of input data. This is then converted into a uin512_t, which is taken modulo Fr::modulus to produce our field element, where the statistical bias is negligble in the security parameter.

Template Parameters
Hashthe hash function we're using
Frfield type
MessageContainera byte container (std::vector<uint8_t>, std::array<uint8_t, ...>, std::string)
KeyContainera byte container
Parameters
messagethe input buffer
keykey used to derive
Returns
Fr output field element as uint512_t( H(10...0 || HMAC(k,m)) || H(00...0 || HMAC(k,m)) ) % r

◆ hmac()

template<typename Hash , typename MessageContainer , typename KeyContainer >
std::array< uint8_t, Hash::OUTPUT_SIZE > crypto::hmac ( const MessageContainer &  message,
const KeyContainer &  key 
)

Compute an HMAC given a secret key and a message.

Template Parameters
Hashhasher being used
MessageContainera byte container (std::vector<uint8_t>, std::array<uint8_t, ...>, std::string)
KeyContainera byte container
Parameters
messagethe message!
keythe key!
Returns
std::array<uint8_t, Hash::OUTPUT_SIZE> the HMAC output!