aboutsummaryrefslogtreecommitdiffstats
path: root/go/main.go
blob: ab902f2ba5bf4aba2e98164eae4e8fb90a829622 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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)
}