nik-u / pbc Goto Github PK
View Code? Open in Web Editor NEWPairing-based cryptography for Go
License: GNU Lesser General Public License v3.0
Pairing-based cryptography for Go
License: GNU Lesser General Public License v3.0
Is there a way to serialize the preprocessing outputs (i.e. Power)?
Hello, Nik-U,
I utilize go pbc wrapper to achieve a proxy re-encryption algorithm.
When I using Bytes() to transfer an element to []byte, like:
e := pairing.NewGT()
temp1 := pairing.NewZr().Set1()
temp := temp1.Neg(temp1)
C0_ := C_list[1].PowZn(C_list[1], temp)
temp2 := e.Pair(skid, C0_)
plainM := C_list[0].Mul(C_list[0], temp2)
plainM_bytes := plainM.Bytes()
return plainM_bytes
I have a problem: the plainM.Bytes()
return an incorrect []byte sometimes.
plainM should be [104 101 108 108 111 119 111 114 108 100]
, but I get [1 47 246 192 237 179 26 99 159 235 180 239 91 206 53 193 189 23 5 254 49 99 142 137 76 196 171 28 114 110 103 236 110 21 199 94 190 183 187 232 0 180 144 198 177 77 51 156 100 209 182 233 74 240 222 46 20 244 182 20 227 157 104 160 148]
sometimes, which is not expected []byte.
I want to ask how can I solve this problem? Thanks.
Hi Nik,
I believe as of Go1.6 there is a change to the way Go pointers can be passed to C code, which is causing the below runtime panic. The description of the change is here: https://golang.org/doc/go1.6#cgo.
One temporary fix is to turn-off this runtime check with GODEBUG=cgocheck=0
, but I think it might be better to fix the issues directly in the code. I'm not sure how much work it is to fix or if the fix will sacrifice performance. What do you think?
Btw, your wrapper is awesome, thanks for creating it!
`panic: runtime error: cgo argument has Go pointer to Go pointer
goroutine 1 [running]:
panic(0x4175e0, 0xc82010f460)
/usr/local/go/src/runtime/panic.go:464 +0x3e6
github.com/Nik-U/pbc.makeUncheckedElement(0xc820116028, 0xc82010e001, 0x0, 0x346940)
/go/src/github.com/Nik-U/pbc/element.go:122 +0x15e
github.com/Nik-U/pbc.makeCheckedElement(0xc820116028, 0x0, 0x2800370, 0xc820116028)
/go/src/github.com/Nik-U/pbc/element.go:138 +0x34
github.com/Nik-U/pbc.(*Pairing).NewG1(0xc820116028, 0xc820116028)
/go/src/github.com/Nik-U/pbc/pairing.go:128 +0x39`
`func init() {
file.FileRemove("params")
file.FileRemove("groupPublicKey")
file.FileRemove("groupPrivateKey")
params := pbc.GenerateA(160, 512)
//params := pbc.GenerateE(160,1024)
// serialization params
str := params.String()
file.Byte2File("params", []byte(str))
str1 := file.File2Byte("params")
pairing, _ := pbc.NewPairingFromString(string(str1))
// get g1 and g2
g1 := pairing.NewG1().Rand()
g2 := pairing.NewG2().Rand()
privateKey := bbs.GenerateGroup(g1, g2, pairing)
// 编码群公钥,转换成byte数组
groupPK := bbs.EncodeGroup(privateKey.Group)
groupPrivateKey := bbs.EncodePrivateKey(privateKey)
file.Byte2File("groupPublicKey", groupPK)
file.Byte2File("groupPrivateKey", groupPrivateKey)
}`
why the str is empty? can you help me?
Thank you for your amazing Go bindings, but I have several questions:
Frequent calls run for dozens of minutes to a few hours will crash, the exception stack is as follows, each crash occurs in pairing.go line 65:
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0xb01dfacedebac1e pc=0x429289e]
runtime stack:
runtime.throw(0x40fbc00, 0x2a)
/usr/local/go/src/runtime/panic.go:608 +0x72
runtime.sigpanic()
/usr/local/go/src/runtime/signal_unix.go:374 +0x2f2
goroutine 5 [syscall]:
runtime.cgocall(0x40bc1e0, 0xc000052c70, 0x40ea1e0)
/usr/local/go/src/runtime/cgocall.go:128 +0x5e fp=0xc000052c40 sp=0xc000052c08 pc=0x400484e
github.com/samoslab/nebula/vendor/github.com/Nik-U/pbc._Cfunc_pairing_init_pbc_param(0x8000000, 0x723de50)
_cgo_gotypes.go:1439 +0x41 fp=0xc000052c70 sp=0xc000052c40 pc=0x40b4171
github.com/samoslab/nebula/vendor/github.com/Nik-U/pbc.NewPairing.func1(0x8000000, 0x723de50)
/Users/lijt/go/src/github.com/samoslab/nebula/vendor/github.com/Nik-U/pbc/pairing.go:65 +0x8f fp=0xc000052ca8 sp=0xc000052c70 pc=0x40b7faf
github.com/samoslab/nebula/vendor/github.com/Nik-U/pbc.NewPairing(0xc0000c4068, 0x166)
/Users/lijt/go/src/github.com/samoslab/nebula/vendor/github.com/Nik-U/pbc/pairing.go:65 +0x44 fp=0xc000052cd0 sp=0xc000052ca8 pc=0x40b6204
github.com/samoslab/nebula/vendor/github.com/Nik-U/pbc.NewPairingFromString(0x40fd037, 0x166, 0x1e3, 0xc000396000, 0x0)
/Users/lijt/go/src/github.com/samoslab/nebula/vendor/github.com/Nik-U/pbc/pairing.go:84 +0x6f fp=0xc000052d08 sp=0xc000052cd0 pc=0x40b628f
github.com/samoslab/nebula/util/filecheck.GenMetadata(0xc000297d00, 0x33, 0xc000040000, 0x40fd037, 0x166, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/Users/lijt/go/src/github.com/samoslab/nebula/util/filecheck/filecheck.go:39 +0x1fb fp=0xc000052e10 sp=0xc000052d08 pc=0x40b917b
github.com/samoslab/nebula/util/filecheck.(*GenMetadataRunner).doGen(0xc00006a100, 0xc00029edc0)
go version go1.11.1 darwin/amd64
mac mojave 10.14.1
My goal is to export an Element 32 base encoded and import it again.
I use fmt.SprintF("%32v",elm)
for exporting this works fine. I will get the Element in String representation with characters between (a-v,0-9)
But if i try to Set the Element from that string with base 32. It does not work as I expect.
In the following code i expect the variable recreatedElm to be same as the variable elm. Why is this not so ? Am i understanding something wrong? Or is there a bug?
var pairing *pbc.Pairing
// ...populate pairing...
elm := pairing.NewZr().Rand()
elmString := fmt.Sprintf("%32v", elm)
recreatedElm := pairing.NewZr().SetString(elmString, 32)
I have encountered errors shown like this:
# github.com/Nik-U/pbc
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lpbc
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lgmp
In the GoDoc page, I found statement "During the build process, this package will attempt to include <gmp.h> and <pbc/pbc.h>, and then dynamically link to GMP and PBC." I guess my errors are caused because it fails to link GMP and PBC dynamically?
All files ended with .so, .a, .la, etc, are located in the /usr/local/lib, and I have tried to use soft link to create files under the pbc-0.5.14 directory and gmp-6.2.1 directory using command like ln -s /usr/local/lib/libpbc.so ./libpbc.so
, and make/make install again. It does not work. I wonder if there is any method that I can use to manually link GMP and PBC? Thanks!
I define a struct like:
type BswabePub struct{
/*
* A public key
*/
PairingDesc string json:"PairingDesc"
P *pbc.Pairing json:"P"
G pbc.Element / G_1 */ json:"G"
H pbc.Element / G_1 */ json:"H"
F pbc.Element / G_1 */ json:"F"
Gp pbc.Element / G_2 */ json:"Gp"
G_hat_alpha pbc.Element / G_T */ json:"G_hat_alpha"
}
but when I try to save the data of my pub-key, the json.Marshal() can not export all the member,like P and G [ gob can not work either]. The struct of Element has private member, so I can not save the complete data. I don't know how to solve this.Thank you!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.