-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcsidh.go
More file actions
66 lines (36 loc) · 1.11 KB
/
csidh.go
File metadata and controls
66 lines (36 loc) · 1.11 KB
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
59
60
61
62
63
64
65
66
package main
import (
"github.com/cloudflare/circl/dh/csidh"
"encoding/hex"
"crypto/rand"
"C"
)
var rng = rand.Reader
//export genCSIDH
func genCSIDH()*C.char{
var priv csidh.PrivateKey
var pub csidh.PublicKey
csidh.GeneratePrivateKey(&priv,rng)
csidh.GeneratePublicKey(&pub,&priv,rng)
//Create buffers to export creds
exprtPub:= make([]byte,64);
exprtPriv:= make([]byte,37);
//Make export
pub.Export(exprtPub);
priv.Export(exprtPriv);
return C.CString(hex.EncodeToString(exprtPub)+":"+hex.EncodeToString(exprtPriv))
}
//export getCSIDH
func getCSIDH(friendPub *C.char,myPrivate *C.char)*C.char{
friendPubBytes,_:=hex.DecodeString(C.GoString(friendPub));
myPrivBytes,_:=hex.DecodeString(C.GoString(myPrivate));
var derivedPub csidh.PublicKey
var derivedPriv csidh.PrivateKey
//Common shared secret
var secret [64]byte
derivedPub.Import(friendPubBytes);
derivedPriv.Import(myPrivBytes);
csidh.DeriveSecret(&secret,&derivedPub,&derivedPriv,rng)
return C.CString(hex.EncodeToString(secret[:]))
}
func main() {}