diff --git a/barretenberg/cpp/src/aztec/crypto/blake2s/c_bind.hpp b/barretenberg/cpp/src/aztec/crypto/blake2s/c_bind.hpp new file mode 100644 index 000000000000..32a7d1d01dbc --- /dev/null +++ b/barretenberg/cpp/src/aztec/crypto/blake2s/c_bind.hpp @@ -0,0 +1,9 @@ +#include +#include + +#define WASM_EXPORT __attribute__((visibility("default"))) + +extern "C" { + +WASM_EXPORT void blake2s_to_field(uint8_t const* data, size_t length, uint8_t* r); +} diff --git a/barretenberg/cpp/src/aztec/crypto/pedersen/c_bind.cpp b/barretenberg/cpp/src/aztec/crypto/pedersen/c_bind.cpp index 810db9c93919..f46e6193e143 100644 --- a/barretenberg/cpp/src/aztec/crypto/pedersen/c_bind.cpp +++ b/barretenberg/cpp/src/aztec/crypto/pedersen/c_bind.cpp @@ -1,3 +1,4 @@ +#include "c_bind.hpp" #include "pedersen.hpp" #include #include @@ -36,6 +37,15 @@ WASM_EXPORT void pedersen__compress_with_hash_index(uint8_t const* inputs_buffer barretenberg::fr::serialize_to_buffer(r, output); } +WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output) +{ + std::vector to_compress; + read(inputs_buffer, to_compress); + grumpkin::g1::affine_element pedersen_hash = crypto::pedersen::commit_native(to_compress); + + write(output, pedersen_hash); +} + WASM_EXPORT void pedersen__buffer_to_field(uint8_t const* data, size_t length, uint8_t* r) { std::vector to_compress(data, data + length); @@ -67,4 +77,4 @@ WASM_EXPORT uint8_t* pedersen__hash_to_tree(uint8_t const* data) return buf; } -} \ No newline at end of file +} diff --git a/barretenberg/cpp/src/aztec/crypto/pedersen/c_bind.hpp b/barretenberg/cpp/src/aztec/crypto/pedersen/c_bind.hpp new file mode 100644 index 000000000000..0c7828b2f8ca --- /dev/null +++ b/barretenberg/cpp/src/aztec/crypto/pedersen/c_bind.hpp @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#define WASM_EXPORT __attribute__((visibility("default"))) + +extern "C" { + +WASM_EXPORT void pedersen__init(); + +WASM_EXPORT void pedersen__compress_fields(uint8_t const* left, uint8_t const* right, uint8_t* result); + +WASM_EXPORT void pedersen__compress(uint8_t const* inputs_buffer, uint8_t* output); + +WASM_EXPORT void pedersen__compress_with_hash_index(uint8_t const* inputs_buffer, uint8_t* output, uint32_t hash_index); + +WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output); + +WASM_EXPORT void pedersen__buffer_to_field(uint8_t const* data, size_t length, uint8_t* r); + +/** + * Given a buffer containing 32 byte pedersen leaves, return a new buffer containing the leaves and all pairs of + * nodes that define a merkle tree. + * e.g. + * input: [1][2][3][4] + * output: [1][2][3][4][compress(1,2)][compress(3,4)][compress(5,6)] + */ +WASM_EXPORT uint8_t* pedersen__hash_to_tree(uint8_t const* data); +} diff --git a/barretenberg/cpp/src/aztec/crypto/schnorr/c_bind.hpp b/barretenberg/cpp/src/aztec/crypto/schnorr/c_bind.hpp new file mode 100644 index 000000000000..900612374086 --- /dev/null +++ b/barretenberg/cpp/src/aztec/crypto/schnorr/c_bind.hpp @@ -0,0 +1,39 @@ +#include + +#define WASM_EXPORT __attribute__((visibility("default"))) + +extern "C" { + +WASM_EXPORT void compute_public_key(uint8_t const* private_key, uint8_t* public_key_buf); +WASM_EXPORT void negate_public_key(uint8_t const* public_key_buffer, uint8_t* output); + +WASM_EXPORT void construct_signature( + uint8_t const* message, size_t msg_len, uint8_t const* private_key, uint8_t* s, uint8_t* e); + +WASM_EXPORT bool verify_signature( + uint8_t const* message, size_t msg_len, uint8_t const* pub_key, uint8_t const* sig_s, uint8_t const* sig_e); + +WASM_EXPORT void multisig_create_multisig_public_key(uint8_t const* private_key, uint8_t* multisig_pubkey_buf); + +WASM_EXPORT bool multisig_validate_and_combine_signer_pubkeys(uint8_t const* signer_pubkey_buf, + uint8_t* combined_key_buf); + +WASM_EXPORT void multisig_construct_signature_round_1(uint8_t* round_one_public_output_buf, + uint8_t* round_one_private_output_buf); + +WASM_EXPORT bool multisig_construct_signature_round_2(uint8_t const* message, + size_t msg_len, + uint8_t* private_key, + uint8_t* signer_round_one_private_buf, + uint8_t* signer_pubkeys_buf, + uint8_t* round_one_public_buf, + uint8_t* round_two_buf); + +WASM_EXPORT bool multisig_combine_signatures(uint8_t const* message, + size_t msg_len, + uint8_t* signer_pubkeys_buf, + uint8_t* round_one_buf, + uint8_t* round_two_buf, + uint8_t* s, + uint8_t* e); +} diff --git a/barretenberg/cpp/src/aztec/ecc/curves/bn254/scalar_multiplication/c_bind.cpp b/barretenberg/cpp/src/aztec/ecc/curves/bn254/scalar_multiplication/c_bind.cpp index 2773fafb9b57..c117b870b7c6 100644 --- a/barretenberg/cpp/src/aztec/ecc/curves/bn254/scalar_multiplication/c_bind.cpp +++ b/barretenberg/cpp/src/aztec/ecc/curves/bn254/scalar_multiplication/c_bind.cpp @@ -1,7 +1,5 @@ -#include "./scalar_multiplication.hpp" #include "pippenger.hpp" -#include -#include +#include "common/mem.hpp" using namespace barretenberg; @@ -20,7 +18,7 @@ WASM_EXPORT void bbfree(void* ptr) aligned_free(ptr); } -WASM_EXPORT void* new_pippenger(g1::affine_element* points, size_t num_points) +WASM_EXPORT void* new_pippenger(uint8_t* points, size_t num_points) { auto ptr = new scalar_multiplication::Pippenger(points, num_points); return ptr; @@ -47,4 +45,4 @@ WASM_EXPORT void g1_sum(void* points_ptr, const size_t num_points, void* result_ result->self_set_infinity(); *result = std::accumulate(points, points + num_points, *result); } -} \ No newline at end of file +} diff --git a/barretenberg/cpp/src/aztec/ecc/curves/bn254/scalar_multiplication/c_bind.hpp b/barretenberg/cpp/src/aztec/ecc/curves/bn254/scalar_multiplication/c_bind.hpp new file mode 100644 index 000000000000..e8b2d9755a09 --- /dev/null +++ b/barretenberg/cpp/src/aztec/ecc/curves/bn254/scalar_multiplication/c_bind.hpp @@ -0,0 +1,18 @@ +#include +#include "../g1.hpp" + +#define WASM_EXPORT __attribute__((visibility("default"))) + +extern "C" { + +WASM_EXPORT void* bbmalloc(size_t size); + +WASM_EXPORT void bbfree(void* ptr); + +WASM_EXPORT void* new_pippenger(uint8_t* points, size_t num_points); + +WASM_EXPORT void delete_pippenger(void* pippenger); + +WASM_EXPORT void pippenger_unsafe(void* pippenger_ptr, void* scalars_ptr, size_t from, size_t range, void* result_ptr); +WASM_EXPORT void g1_sum(void* points_ptr, size_t num_points, void* result_ptr); +}