aboutsummaryrefslogtreecommitdiffstats
path: root/ffi/go/bls/bls.go
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2019-01-27 14:47:09 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2019-01-27 14:47:09 +0800
commit3900a6ec637be56529972e17553e2b301832da46 (patch)
tree6b99ae017158a00490910b7c94a02fa8f071c02e /ffi/go/bls/bls.go
parent16714d96ba69b286d4342bc2c6206ece57b412a8 (diff)
downloaddexon-bls-3900a6ec637be56529972e17553e2b301832da46.tar
dexon-bls-3900a6ec637be56529972e17553e2b301832da46.tar.gz
dexon-bls-3900a6ec637be56529972e17553e2b301832da46.tar.bz2
dexon-bls-3900a6ec637be56529972e17553e2b301832da46.tar.lz
dexon-bls-3900a6ec637be56529972e17553e2b301832da46.tar.xz
dexon-bls-3900a6ec637be56529972e17553e2b301832da46.tar.zst
dexon-bls-3900a6ec637be56529972e17553e2b301832da46.zip
add SetRandFunc function
Diffstat (limited to 'ffi/go/bls/bls.go')
-rw-r--r--ffi/go/bls/bls.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/ffi/go/bls/bls.go b/ffi/go/bls/bls.go
index a5c657c..2374d2e 100644
--- a/ffi/go/bls/bls.go
+++ b/ffi/go/bls/bls.go
@@ -10,11 +10,14 @@ package bls
#cgo LDFLAGS:-lbls384
#cgo LDFLAGS:-lcrypto -lgmp -lgmpxx -lstdc++
#include "config.h"
+typedef unsigned int (*ReadRandFunc)(void *, void *, unsigned int);
+int wrapReadRandCgo(void *self, void *buf, unsigned int n);
#include <bls/bls.h>
*/
import "C"
import "fmt"
import "unsafe"
+import "io"
// Init --
// call this function before calling all the other operations
@@ -384,3 +387,34 @@ func (sign *Sign) VerifyAggregateHashes(pubVec []PublicKey, hash [][]byte) bool
}
return C.blsVerifyAggregatedHashes(sign.getPointer(), pubVec[0].getPointer(), unsafe.Pointer(&h[0]), C.size_t(hashByte), C.size_t(n)) == 1
}
+
+///
+
+var s_randReader *io.Reader
+
+func createSlice(buf *C.char, n C.uint) []byte {
+ size := int(n)
+ return (*[1 << 30]byte)(unsafe.Pointer(buf))[:size:size]
+}
+
+// this function can't be put in callback.go
+//export wrapReadRandGo
+func wrapReadRandGo(buf *C.char, n C.uint) C.uint {
+ slice := createSlice(buf, n)
+ ret, err := (*s_randReader).Read(slice)
+ if ret == int(n) && err == nil {
+ return n
+ }
+ return 0
+}
+
+// SetRandFunc --
+func SetRandFunc(randReader *io.Reader) {
+ s_randReader = randReader
+ if randReader != nil {
+ C.blsSetRandFunc(nil, C.ReadRandFunc(unsafe.Pointer(C.wrapReadRandCgo)))
+ } else {
+ // use default random generator
+ C.blsSetRandFunc(nil, C.ReadRandFunc(unsafe.Pointer(nil)))
+ }
+}