This commit is contained in:
decanus 2021-09-13 22:20:32 +02:00
parent e928e8a25a
commit 2e02e6d97b
No known key found for this signature in database
GPG Key ID: 3730AAF5D6589867
2 changed files with 15 additions and 5 deletions

View File

@ -13,14 +13,22 @@ type RLN struct {
ptr *C.RLN_Bn256 ptr *C.RLN_Bn256
} }
func New(depth int, parameters []byte) *RLN {
r := &RLN{}
buf := toBuffer(parameters)
C.new_circuit_from_params(C.ulong(depth), &buf, &r.ptr)
return r
}
func (r *RLN) Hash(input []byte) []byte { func (r *RLN) Hash(input []byte) []byte {
size := int(unsafe.Sizeof(C.Buffer{})) size := int(unsafe.Sizeof(C.Buffer{}))
size = int(unsafe.Sizeof(C.Buffer{}))
in := (*C.Buffer)(C.malloc(C.size_t(size))) in := (*C.Buffer)(C.malloc(C.size_t(size)))
*in = toBuffer(input)
out := (*C.Buffer)(C.malloc(C.size_t(size))) out := (*C.Buffer)(C.malloc(C.size_t(size)))
C.hash(r.ptr, in, size, out) C.hash(r.ptr, in, &in.len, out)
return C.GoBytes(unsafe.Pointer(out.ptr), C.int(out.len)) return C.GoBytes(unsafe.Pointer(out.ptr), C.int(out.len))
} }

View File

@ -1,8 +1,10 @@
package rln package rln
import "testing" import (
"testing"
)
func TestHash(t *testing.T) { func TestHash(t *testing.T) {
rln := &RLN{} rln := New(0, []byte{})
rln.Hash([]byte{1, 2, 3}) rln.Hash([]byte{1, 2, 3})
} }