Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
c_bind.cpp
Go to the documentation of this file.
1#include "c_bind.hpp"
4#include "pedersen.hpp"
5
6using namespace bb;
7
8WASM_EXPORT void pedersen_hash(fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, fr::out_buf output)
9{
11 read(inputs_buffer, to_hash);
13 ctx.offset = static_cast<size_t>(ntohl(*hash_index));
14 auto r = crypto::pedersen_hash::hash(to_hash, ctx);
15 fr::serialize_to_buffer(r, output);
16}
17
18WASM_EXPORT void pedersen_hashes(fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, fr::out_buf output)
19{
21 read(inputs_buffer, to_hash);
23 ctx.offset = static_cast<size_t>(ntohl(*hash_index));
24 const size_t numHashes = to_hash.size() / 2;
26 size_t count = 0;
27 while (count < numHashes) {
28 auto r = crypto::pedersen_hash::hash({ to_hash[count * 2], to_hash[count * 2 + 1] }, ctx);
29 results.push_back(r);
30 ++count;
31 }
32 write(output, results);
33}
34
35WASM_EXPORT void pedersen_hash_buffer(uint8_t const* input_buffer, uint32_t const* hash_index, fr::out_buf output)
36{
37 std::vector<uint8_t> to_hash;
38 read(input_buffer, to_hash);
40 ctx.offset = static_cast<size_t>(ntohl(*hash_index));
41 auto r = crypto::pedersen_hash::hash_buffer(to_hash, ctx);
42 fr::serialize_to_buffer(r, output);
43}
static Fq hash_buffer(const std::vector< uint8_t > &input, GeneratorContext context={})
Given an arbitrary length of bytes, convert them to fields and hash the result using the default gene...
Definition pedersen.cpp:88
static Fq hash(const std::vector< Fq > &inputs, GeneratorContext context={})
Given a vector of fields, generate a pedersen hash using generators from context.
Definition pedersen.cpp:78
WASM_EXPORT void pedersen_hash(fr::vec_in_buf inputs_buffer, uint32_t const *hash_index, fr::out_buf output)
Definition c_bind.cpp:8
WASM_EXPORT void pedersen_hashes(fr::vec_in_buf inputs_buffer, uint32_t const *hash_index, fr::out_buf output)
Definition c_bind.cpp:18
WASM_EXPORT void pedersen_hash_buffer(uint8_t const *input_buffer, uint32_t const *hash_index, fr::out_buf output)
Definition c_bind.cpp:35
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
void read(B &it, field2< base_field, Params > &value)
void write(B &buf, field2< base_field, Params > const &value)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static void serialize_to_buffer(const field &value, uint8_t *buffer)
const uint8_t * vec_in_buf
#define WASM_EXPORT