diff --git a/cpp/src/barretenberg/crypto/ecdsa/c_bind.h b/cpp/src/barretenberg/crypto/ecdsa/c_bind.h new file mode 100644 index 0000000000..897202a372 --- /dev/null +++ b/cpp/src/barretenberg/crypto/ecdsa/c_bind.h @@ -0,0 +1,29 @@ +#include + +#define WASM_EXPORT __attribute__((visibility("default"))) + +extern "C" { + +WASM_EXPORT void ecdsa__compute_public_key(uint8_t const* private_key, uint8_t* public_key_buf); + +WASM_EXPORT void ecdsa__construct_signature(uint8_t const* message, + size_t msg_len, + uint8_t const* private_key, + uint8_t* output_sig_r, + uint8_t* output_sig_s, + uint8_t* output_sig_v); + +WASM_EXPORT void ecdsa__recover_public_key_from_signature(uint8_t const* message, + size_t msg_len, + uint8_t const* sig_r, + uint8_t const* sig_s, + uint8_t* sig_v, + uint8_t* output_pub_key); + +WASM_EXPORT bool ecdsa__verify_signature(uint8_t const* message, + size_t msg_len, + uint8_t const* pub_key, + uint8_t const* sig_r, + uint8_t const* sig_s, + uint8_t const* sig_v); +} diff --git a/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.cpp b/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.cpp new file mode 100644 index 0000000000..107d889d4c --- /dev/null +++ b/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.cpp @@ -0,0 +1,30 @@ +#include "secp256k1.hpp" + +#define WASM_EXPORT __attribute__((visibility("default"))) + +extern "C" { + +WASM_EXPORT void ecc_secp256k1__mul(uint8_t const* point_buf, uint8_t const* scalar_buf, uint8_t* result) +{ + auto point = from_buffer(point_buf); + auto scalar = from_buffer(scalar_buf); + secp256k1::g1::affine_element r = point * scalar; + write(result, r); +} + +WASM_EXPORT void ecc_secp256k1__get_random_scalar_mod_circuit_modulus(uint8_t* result) +{ + barretenberg::fr output = barretenberg::fr::random_element(); + write(result, output); +} + +WASM_EXPORT void ecc_secp256k1__reduce512_buffer_mod_circuit_modulus(uint8_t* input, uint8_t* result) +{ + uint512_t bigint_input = from_buffer(input); + + uint512_t barretenberg_modulus(barretenberg::fr::modulus); + + uint512_t target_output = bigint_input % barretenberg_modulus; + write(result, target_output.lo); +} +} \ No newline at end of file diff --git a/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.hpp b/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.hpp new file mode 100644 index 0000000000..b1b1983239 --- /dev/null +++ b/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.hpp @@ -0,0 +1,12 @@ +#include "secp256k1.hpp" + +#define WASM_EXPORT __attribute__((visibility("default"))) + +extern "C" { + +WASM_EXPORT void ecc_secp256k1__mul(uint8_t const* point_buf, uint8_t const* scalar_buf, uint8_t* result); + +WASM_EXPORT void ecc_secp256k1__get_random_scalar_mod_circuit_modulus(uint8_t* result); + +WASM_EXPORT void ecc_secp256k1__reduce512_buffer_mod_circuit_modulus(uint8_t* input, uint8_t* result); +}