-
Notifications
You must be signed in to change notification settings - Fork 1
/
dilithium.go
58 lines (28 loc) · 1.09 KB
/
dilithium.go
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
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"github.com/cloudflare/circl/sign/dilithium"
"encoding/hex"
"strconv"
"C"
)
var modename string = "Dilithium5"; // Dilithium2-AES Dilithium3 Dilithium3-AES Dilithium5 Dilithium5-AES
var mode = dilithium.ModeByName(modename);
//export genDIL
func genDIL() *C.char {
pk, sk, _ := mode.GenerateKey(nil);
return C.CString(string(hex.EncodeToString(pk.Bytes())+":"+hex.EncodeToString(sk.Bytes())))
}
//export signDIL
func signDIL(message *C.char,privKey *C.char) *C.char{
privateKey, _:=hex.DecodeString(C.GoString(privKey));
msg := []byte(C.GoString(message));
return C.CString(hex.EncodeToString(mode.Sign(mode.PrivateKeyFromBytes(privateKey), msg)))
}
//export verifyDIL
func verifyDIL(message *C.char,pubKey *C.char,sig *C.char) *C.char {
msg := []byte(C.GoString(message));
publicKey, _:=hex.DecodeString(C.GoString(pubKey));
signature, _:=hex.DecodeString(C.GoString(sig));
return C.CString(strconv.FormatBool(mode.Verify(mode.PublicKeyFromBytes(publicKey), msg, signature)))
}
func main() {}