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// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], commit: dd03c4a23ab067274b4964cacb36d1545f73fb14}
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
19
20namespace bb::bbapi {
21
26
28{
30
31 // inputs is already std::array<fr, 4>, direct use
32 return { Permutation::permutation(inputs) };
33}
34
41
43{
45 ctx.offset = static_cast<size_t>(hash_index);
46 return { crypto::pedersen_hash::hash(inputs, ctx) };
47}
48
55
60
62{
63 auto hash_result = crypto::blake2s(data);
64 return { fr::serialize_from_buffer(hash_result.data()) };
65}
66
68{
69 // Copy plaintext as AES encrypts in-place
70 std::vector<uint8_t> result = plaintext;
71 result.resize(length);
72
73 crypto::aes128_encrypt_buffer_cbc(result.data(), iv.data(), key.data(), length);
74
75 return { std::move(result) };
76}
77
79{
80 // Copy ciphertext as AES decrypts in-place
81 std::vector<uint8_t> result = ciphertext;
82 result.resize(length);
83
84 crypto::aes128_decrypt_buffer_cbc(result.data(), iv.data(), key.data(), length);
85
86 return { std::move(result) };
87}
88
89} // namespace bb::bbapi
Cryptographic primitives command definitions for the Barretenberg RPC API.
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
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:232
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) &&
static field serialize_from_buffer(const uint8_t *buffer)