aboutsummaryrefslogtreecommitdiffstats
path: root/go/main.go
blob: f4ee0302ae5bd701103fdefb4cf31b93172b0516 (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
43
44
45
46
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()

    id := C.blsIdCreate()
    defer C.blsIdDestroy(id)

    C.blsIdSet(id, (*C.uint64_t)(unsafe.Pointer(&[]uint64{1, 2, 3, 4}[0])))
    C.blsIdPut(id)

    fmt.Println("create secret key")
    sec := C.blsSecretKeyCreate()
    defer C.blsSecretKeyDestroy(sec)
    C.blsSecretKeyInit(sec)
    C.blsSecretKeyPut(sec)

    fmt.Println("create public key")
    pub := C.blsPublicKeyCreate()
    defer C.blsPublicKeyDestroy(pub)
    C.blsSecretKeyGetPublicKey(sec, pub)

    C.blsPublicKeyPut(pub)

    sign := C.blsSignCreate()
    defer C.blsSignDestroy(sign)

    msg := []byte("Hello bls")
    fmt.Println("sign message")
    C.blsSecretKeySign(sec, sign, (*C.char)(unsafe.Pointer(&msg[0])), C.size_t(len(msg)))

    C.blsSignPut(sign)

    fmt.Println("verify:", C.blsSignVerify(sign, pub, (*C.char)(unsafe.Pointer(&msg[0])), C.size_t(len(msg))))

}