aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-03-15 10:12:57 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-03-15 10:12:57 +0800
commit89a8d07fdc790734b8b3d89c729d0f251b452962 (patch)
tree9297a071c8ae67f01660a702ad107dc740fd0933
parent0310c3a2274f1e48b2aa1631229d3904c5c80022 (diff)
downloaddexon-bls-89a8d07fdc790734b8b3d89c729d0f251b452962.tar
dexon-bls-89a8d07fdc790734b8b3d89c729d0f251b452962.tar.gz
dexon-bls-89a8d07fdc790734b8b3d89c729d0f251b452962.tar.bz2
dexon-bls-89a8d07fdc790734b8b3d89c729d0f251b452962.tar.lz
dexon-bls-89a8d07fdc790734b8b3d89c729d0f251b452962.tar.xz
dexon-bls-89a8d07fdc790734b8b3d89c729d0f251b452962.tar.zst
dexon-bls-89a8d07fdc790734b8b3d89c729d0f251b452962.zip
ensure size of SetArray
-rw-r--r--go/blscgo/bls.go24
-rw-r--r--go/main.go33
2 files changed, 41 insertions, 16 deletions
diff --git a/go/blscgo/bls.go b/go/blscgo/bls.go
index 3d78ee0..782e8b2 100644
--- a/go/blscgo/bls.go
+++ b/go/blscgo/bls.go
@@ -19,6 +19,14 @@ const CurveFp382_2 = 2
func Init(curve int) {
C.blsInit(C.int(curve), C.BLS_MAX_OP_UNIT_SIZE)
}
+// getMaxOpUnitSize --
+func GetMaxOpUnitSize() int {
+ return int(C.BLS_MAX_OP_UNIT_SIZE)
+}
+// getOpUnitSize --
+func GetOpUnitSize() int {
+ return int(C.blsGetOpUnitSize())
+}
// ID --
type ID struct {
@@ -54,13 +62,13 @@ func (id *ID) SetStr(s string) error {
}
// Set --
-func (id *ID) Set(v []uint64) error {
- if len(v) != 6 {
- return fmt.Errorf("bad size (%d), expected size 6", len(v))
+func (id *ID) Set(v []uint64) {
+ expect := GetOpUnitSize()
+ if len(v) != expect {
+ panic(fmt.Errorf("bad size (%d), expected size %d", len(v), expect))
}
// #nosec
C.blsIdSet(id.getPointer(), (*C.uint64_t)(unsafe.Pointer(&v[0])))
- return nil
}
// SecretKey --
@@ -97,13 +105,13 @@ func (sec *SecretKey) SetStr(s string) error {
}
// SetArray --
-func (sec *SecretKey) SetArray(v []uint64) error {
- if len(v) != 6 {
- return fmt.Errorf("bad size (%d), expected size 6", len(v))
+func (sec *SecretKey) SetArray(v []uint64) {
+ expect := GetOpUnitSize()
+ if len(v) != expect {
+ panic(fmt.Errorf("bad size (%d), expected size %d", len(v), expect))
}
// #nosec
C.blsSecretKeySetArray(sec.getPointer(), (*C.uint64_t)(unsafe.Pointer(&v[0])))
- return nil
}
// Init --
diff --git a/go/main.go b/go/main.go
index c3da950..068471d 100644
--- a/go/main.go
+++ b/go/main.go
@@ -2,8 +2,10 @@ package main
import "fmt"
import "./blscgo"
-import "runtime"
-import "time"
+//import "runtime"
+//import "time"
+
+var unitN = 0
func verifyTrue(b bool) {
if !b {
@@ -24,7 +26,7 @@ func testRecoverSecretKey() {
secVec := make([]blscgo.SecretKey, n)
idVec := make([]blscgo.ID, n)
for i := 0; i < n; i++ {
- idVec[i].Set([]uint64{1, 2, 3, uint64(i), 4, 5})
+ idVec[i].Set([]uint64{1, 2, 3, uint64(i), 4, 5}[0:unitN])
secVec[i].Set(msk, &idVec[i])
}
// recover sec2 from secVec and idVec
@@ -56,7 +58,7 @@ func testSign() {
idVec := make([]blscgo.ID, n)
for i := 0; i < n; i++ {
- idVec[i].Set([]uint64{idTbl[i], 0, 0, 0, 0, 0})
+ idVec[i].Set([]uint64{idTbl[i], 0, 0, 0, 0, 0}[0:unitN])
fmt.Printf("idVec[%d]=%s\n", i, idVec[i].String())
secVec[i].Set(msk, &idVec[i])
@@ -110,12 +112,13 @@ func testPop() {
sec.Init()
verifyTrue(!pop.VerifyPop(sec.GetPublicKey()))
}
-func main() {
+func test(cp int) {
fmt.Println("init")
- blscgo.Init(blscgo.CurveFp254BNb)
+ blscgo.Init(cp)
+ unitN = blscgo.GetOpUnitSize()
{
var id blscgo.ID
- id.Set([]uint64{6, 5, 4, 3, 2, 1})
+ id.Set([]uint64{6, 5, 4, 3, 2, 1}[0:unitN])
fmt.Println("id :", id)
var id2 blscgo.ID
id2.SetStr(id.String())
@@ -123,7 +126,7 @@ func main() {
}
{
var sec blscgo.SecretKey
- sec.SetArray([]uint64{1, 2, 3, 4, 5, 6})
+ sec.SetArray([]uint64{1, 2, 3, 4, 5, 6}[0:unitN])
fmt.Println("sec=", sec)
}
@@ -151,11 +154,25 @@ func main() {
testAdd()
testSign()
testPop()
+ fmt.Println("end of test")
// put memory status
+/*
runtime.GC()
time.Sleep(2 * time.Second)
var mem runtime.MemStats
runtime.ReadMemStats(&mem)
fmt.Println("mem=", mem)
+*/
+}
+func main() {
+ fmt.Println("GetMaxOpUnitSize() = %d\n", blscgo.GetMaxOpUnitSize())
+ fmt.Println("CurveFp254BNb")
+ test(blscgo.CurveFp254BNb)
+ if blscgo.GetMaxOpUnitSize() == 6 {
+ fmt.Println("CurveFp382_1")
+ test(blscgo.CurveFp382_1)
+ fmt.Println("CurveFp382_1")
+ test(blscgo.CurveFp382_2)
+ }
}