Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bbapi_crypto.cpp
Go to the documentation of this file.
1
13
14namespace bb::bbapi {
15
20
22{
24
25 // inputs is already std::array<fr, 4>, direct use
26 return { Permutation::permutation(inputs) };
27}
28
30{
31 if (inputs.empty()) {
32 throw_or_abort("Poseidon2HashAccumulate requires at least one input");
33 }
34
35 fr result = inputs[0];
36 for (size_t i = 1; i < inputs.size(); ++i) {
38 }
39
40 return { result };
41}
42
49
51{
53 ctx.offset = static_cast<size_t>(hash_index);
54 return { crypto::pedersen_hash::hash(inputs, ctx) };
55}
56
63
68
70{
71 auto hash_result = crypto::blake2s(data);
72 return { fr::serialize_from_buffer(hash_result.data()) };
73}
74
76{
77 // Copy plaintext as AES encrypts in-place
78 std::vector<uint8_t> result = plaintext;
79 result.resize(length);
80
81 crypto::aes128_encrypt_buffer_cbc(result.data(), iv.data(), key.data(), length);
82
83 return { std::move(result) };
84}
85
87{
88 // Copy ciphertext as AES decrypts in-place
89 std::vector<uint8_t> result = ciphertext;
90 result.resize(length);
91
92 crypto::aes128_decrypt_buffer_cbc(result.data(), iv.data(), key.data(), length);
93
94 return { std::move(result) };
95}
96
97} // namespace bb::bbapi
Cryptographic primitives command definitions for the Barretenberg RPC API.
Applies the Poseidon2 permutation function from https://eprint.iacr.org/2023/323.
static AffineElement commit_native(const std::vector< Fq > &inputs, GeneratorContext context={})
Given a vector of fields, generate a pedersen commitment using the indexed generators.
Definition pedersen.cpp:24
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
#define BB_UNUSED
const std::vector< MemoryValue > data
uint8_t const size_t length
Definition data_store.hpp:9
stdlib::Poseidon2Permutation< Builder > Permutation
AvmProvingInputs inputs
void aes128_decrypt_buffer_cbc(uint8_t *buffer, uint8_t *iv, const uint8_t *key, const size_t length)
Definition aes128.cpp:253
std::array< uint8_t, BLAKE2S_OUTBYTES > blake2s(std::vector< uint8_t > const &input)
Definition blake2s.cpp:232
void aes128_encrypt_buffer_cbc(uint8_t *buffer, uint8_t *iv, const uint8_t *key, const size_t length)
Definition aes128.cpp:233
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
Response execute(BBApiRequest &request) &&
Response execute(BBApiRequest &request) &&
Response execute(BBApiRequest &request) &&
Response execute(BBApiRequest &request) &&
Response execute(BBApiRequest &request) &&
Response execute(BBApiRequest &request) &&
Response execute(BBApiRequest &request) &&
Response execute(BBApiRequest &request) &&
Response execute(BBApiRequest &request) &&
Response execute(BBApiRequest &request) &&
static field serialize_from_buffer(const uint8_t *buffer)
void throw_or_abort(std::string const &err)