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
20
21namespace bb::bbapi {
22
27
29{
31
32 // inputs is already std::array<fr, 4>, direct use
33 return { Permutation::permutation(inputs) };
34}
35
42
44{
46 ctx.offset = static_cast<size_t>(hash_index);
47 return { crypto::pedersen_hash::hash(inputs, ctx) };
48}
49
56
61
63{
64 auto hash_result = crypto::blake2s(data);
65 return { fr::serialize_from_buffer(hash_result.data()) };
66}
67
69{
70 BB_ASSERT(length == plaintext.size(), "AesEncrypt: length must equal plaintext.size()");
71 BB_ASSERT(length % 16 == 0, "AesEncrypt: length must be a multiple of 16");
72
73 // Copy plaintext as AES encrypts in-place
74 std::vector<uint8_t> result = plaintext;
75 result.resize(length);
76
77 crypto::aes128_encrypt_buffer_cbc(result.data(), iv.data(), key.data(), length);
78
79 return { std::move(result) };
80}
81
83{
84 BB_ASSERT(length == ciphertext.size(), "AesDecrypt: length must equal ciphertext.size()");
85 BB_ASSERT(length % 16 == 0, "AesDecrypt: length must be a multiple of 16");
86
87 // Copy ciphertext as AES decrypts in-place
88 std::vector<uint8_t> result = ciphertext;
89 result.resize(length);
90
91 crypto::aes128_decrypt_buffer_cbc(result.data(), iv.data(), key.data(), length);
92
93 return { std::move(result) };
94}
95
96} // namespace bb::bbapi
#define BB_ASSERT(expression,...)
Definition assert.hpp:70
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:92
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
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:257
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:234
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)