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// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#include "c_bind.hpp"
10#include "pedersen.hpp"
11
12using namespace bb;
13
14WASM_EXPORT void pedersen_hash(fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, fr::out_buf output)
15{
17 read(inputs_buffer, to_hash);
19 ctx.offset = static_cast<size_t>(ntohl(*hash_index));
20 auto r = crypto::pedersen_hash::hash(to_hash, ctx);
21 fr::serialize_to_buffer(r, output);
22}
23
24WASM_EXPORT void pedersen_hashes(fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, fr::out_buf output)
25{
27 read(inputs_buffer, to_hash);
29 ctx.offset = static_cast<size_t>(ntohl(*hash_index));
30 const size_t numHashes = to_hash.size() / 2;
32 size_t count = 0;
33 while (count < numHashes) {
34 auto r = crypto::pedersen_hash::hash({ to_hash[count * 2], to_hash[count * 2 + 1] }, ctx);
35 results.push_back(r);
36 ++count;
37 }
38 write(output, results);
39}
40
41WASM_EXPORT void pedersen_hash_buffer(uint8_t const* input_buffer, uint32_t const* hash_index, fr::out_buf output)
42{
43 std::vector<uint8_t> to_hash;
44 read(input_buffer, to_hash);
46 ctx.offset = static_cast<size_t>(ntohl(*hash_index));
47 auto r = crypto::pedersen_hash::hash_buffer(to_hash, ctx);
48 fr::serialize_to_buffer(r, output);
49}
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:14
WASM_EXPORT void pedersen_hashes(fr::vec_in_buf inputs_buffer, uint32_t const *hash_index, fr::out_buf output)
Definition c_bind.cpp:24
WASM_EXPORT void pedersen_hash_buffer(uint8_t const *input_buffer, uint32_t const *hash_index, fr::out_buf output)
Definition c_bind.cpp:41
Entry point for Barretenberg command-line interface.
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