diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2016-09-06 12:44:29 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2016-09-06 12:44:29 +0800 |
commit | 19b37de33aed66cfa869b958b16b7bc08f2d5954 (patch) | |
tree | c9546cca31533e415f1e23018c9b2fc1208b64cb /go/main.go | |
parent | 2e59d4a1f514e0d4b3f856f29eda705c6e9d7ae4 (diff) | |
download | dexon-bls-19b37de33aed66cfa869b958b16b7bc08f2d5954.tar dexon-bls-19b37de33aed66cfa869b958b16b7bc08f2d5954.tar.gz dexon-bls-19b37de33aed66cfa869b958b16b7bc08f2d5954.tar.bz2 dexon-bls-19b37de33aed66cfa869b958b16b7bc08f2d5954.tar.lz dexon-bls-19b37de33aed66cfa869b958b16b7bc08f2d5954.tar.xz dexon-bls-19b37de33aed66cfa869b958b16b7bc08f2d5954.tar.zst dexon-bls-19b37de33aed66cfa869b958b16b7bc08f2d5954.zip |
add go sample
Diffstat (limited to 'go/main.go')
-rw-r--r-- | go/main.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/go/main.go b/go/main.go new file mode 100644 index 0000000..ab902f2 --- /dev/null +++ b/go/main.go @@ -0,0 +1,42 @@ +package main + +/* +#cgo CFLAGS:-I../include +#cgo LDFLAGS:-lbls -lbls_if -lmcl -lgmp -lgmpxx -L../lib -L../../mcl/lib -lstdc++ -lcrypto +#include "bls_if.h" +*/ +import "C" +import "fmt" +import "unsafe" + +func main() { + fmt.Println("init") + C.blsInit() + + fmt.Println("create secret key") + sec := C.blsSecretKeyCreate() + C.blsSecretKeyInit(sec) + C.blsSecretKeyPut(sec) + + fmt.Println("create public key") + pub := C.blsPublicKeyCreate() + C.blsSecretKeyGetPublicKey(sec, pub) + + C.blsPublicKeyPut(pub) + + sign := C.blsSignCreate() + + msg := "Hello bls" + pmsg := C.CString(msg) + fmt.Println("sign message") + C.blsSecretKeySign(sec, sign, pmsg, C.size_t(len(msg))) + + C.blsSignPut(sign) + + fmt.Println("verify:", C.blsSignVerify(sign, pub, pmsg, C.size_t(len(msg)))) + + C.free(unsafe.Pointer(pmsg)) + + C.blsPublicKeyDestroy(pub) + C.blsSecretKeyDestroy(sec) +} |