added cbindgen

This commit is contained in:
decanus 2021-09-13 16:42:26 +02:00
parent a69c11dcff
commit 3faa61ce34
No known key found for this signature in database
GPG Key ID: 3730AAF5D6589867
3 changed files with 28 additions and 29 deletions

View File

@ -1,6 +1,8 @@
.PHONY: rlnlib .PHONY: rlnlib
rlnlib: rlnlib:
cd lib/rln && cargo build --release cd lib/rln && cargo build --release
cp lib/rln/target/release/librln.* lib/ cbindgen --config ../cbindgen.toml --crate rln --output librln.h --lang c
mv lib/rln/target/release/librln.* lib/
# @TODO TARGET FOR BINDINGS. # @TODO TARGET FOR BINDINGS.

View File

@ -1,37 +1,35 @@
#include <cstdarg> #include <stdarg.h>
#include <cstdint> #include <stdbool.h>
#include <cstdlib> #include <stdint.h>
#include <ostream> #include <stdlib.h>
#include <new>
template<typename E = void> typedef struct RLN_Bn256 RLN_Bn256;
struct RLN;
/// Buffer struct is taken from /**
/// https://github.com/celo-org/celo-threshold-bls-rs/blob/master/crates/threshold-bls-ffi/src/ffi.rs * Buffer struct is taken from
struct Buffer { * https://github.com/celo-org/celo-threshold-bls-rs/blob/master/crates/threshold-bls-ffi/src/ffi.rs
*/
typedef struct Buffer {
const uint8_t *ptr; const uint8_t *ptr;
uintptr_t len; uintptr_t len;
}; } Buffer;
extern "C" {
bool new_circuit_from_params(uintptr_t merkle_depth, bool new_circuit_from_params(uintptr_t merkle_depth,
const Buffer *parameters_buffer, const struct Buffer *parameters_buffer,
RLN<Bn256> **ctx); struct RLN_Bn256 **ctx);
bool generate_proof(const RLN<Bn256> *ctx, const Buffer *input_buffer, Buffer *output_buffer); bool generate_proof(const struct RLN_Bn256 *ctx,
const struct Buffer *input_buffer,
struct Buffer *output_buffer);
bool verify(const RLN<Bn256> *ctx, bool verify(const struct RLN_Bn256 *ctx,
const Buffer *proof_buffer, const struct Buffer *proof_buffer,
const Buffer *public_inputs_buffer, const struct Buffer *public_inputs_buffer,
uint32_t *result_ptr); uint32_t *result_ptr);
bool hash(const RLN<Bn256> *ctx, bool hash(const struct RLN_Bn256 *ctx,
const Buffer *inputs_buffer, const struct Buffer *inputs_buffer,
const uintptr_t *input_len, const uintptr_t *input_len,
Buffer *output_buffer); struct Buffer *output_buffer);
bool key_gen(const RLN<Bn256> *ctx, Buffer *keypair_buffer); bool key_gen(const struct RLN_Bn256 *ctx, struct Buffer *keypair_buffer);
} // extern "C"

5
rln.go
View File

@ -1,12 +1,11 @@
package main package main
/* /*
//#cgo CFLAGS: -I../lib #cgo CFLAGS: -I../lib
#cgo LDFLAGS: -L./lib -llibrnl
#include "./lib/librln.h" #include "./lib/librln.h"
*/ */
import "C" import "C"
func main() { func main() {
C.verify() //C
} }