aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--go/bls/bls.go32
-rw-r--r--go/main.go36
-rw-r--r--include/bls_if.h5
-rw-r--r--src/bls_if.cpp22
4 files changed, 95 insertions, 0 deletions
diff --git a/go/bls/bls.go b/go/bls/bls.go
index 5ba2f24..c7749f5 100644
--- a/go/bls/bls.go
+++ b/go/bls/bls.go
@@ -94,6 +94,38 @@ func (sec *SecretKey) Add(rhs *SecretKey) {
C.blsSecretKeyAdd(sec.self, rhs.self);
}
+func (sec *SecretKey) GetMasterSecretKey(k int) (msk []SecretKey) {
+ msk = make([]SecretKey, k)
+ msk[0] = *sec
+ for i := 1; i < k; i++ {
+ msk[i] = *NewSecretKey()
+ msk[i].Init()
+ }
+ return msk
+}
+
+func (sec *SecretKey) Set(msk []SecretKey, id Id) {
+ n := len(msk)
+ v := make([]*C.blsSecretKey, n)
+ for i := 0; i < n; i++ {
+ v[i] = msk[i].self
+ }
+ C.blsSecretKeySet(sec.self, (**C.blsSecretKey)(unsafe.Pointer(&v[0])), C.size_t(n), id.self)
+}
+
+func (sec *SecretKey) Recover(secVec []SecretKey, idVec []Id) {
+ n := len(secVec)
+ sv := make([]*C.blsSecretKey, n)
+ for i := 0; i < n; i++ {
+ sv[i] = secVec[i].self
+ }
+ iv := make([]*C.blsId, n)
+ for i := 0; i < n; i++ {
+ iv[i] = idVec[i].self
+ }
+ C.blsSecretKeyRecover(sec.self, (**C.blsSecretKey)(unsafe.Pointer(&sv[0])), (**C.blsId)(unsafe.Pointer(&iv[0])), C.size_t(n))
+}
+
type PublicKey struct {
self *C.blsPublicKey
}
diff --git a/go/main.go b/go/main.go
index a43d9ac..e769aea 100644
--- a/go/main.go
+++ b/go/main.go
@@ -3,6 +3,31 @@ package main
import "fmt"
import "./bls"
+func testRecoverSecretKey() {
+ fmt.Println("testRecoverSecretKey")
+ k := 5
+ sec := bls.NewSecretKey()
+ sec.Init()
+ fmt.Println("sec =", sec)
+
+ // make master secret key
+ msk := sec.GetMasterSecretKey(k)
+
+ n := k
+ secVec := make([]bls.SecretKey, n)
+ idVec := make([]bls.Id, n)
+ for i := 0; i < n; i++ {
+ idVec[i] = *bls.NewId()
+ idVec[i].Set([]uint64{1, 2, 3, uint64(i)})
+ secVec[i] = *bls.NewSecretKey()
+ secVec[i].Set(msk, idVec[i])
+ }
+ // recover sec2 from secVec and idVec
+ sec2 := bls.NewSecretKey()
+ sec2.Recover(secVec, idVec)
+ fmt.Println("sec2=", sec2)
+}
+
func main() {
fmt.Println("init")
bls.Init()
@@ -26,4 +51,15 @@ func main() {
sign := sec.Sign(m)
fmt.Println("sign:", sign)
fmt.Println("verify:", sign.Verify(pub, m))
+
+ // How to make array of SecretKey
+ {
+ sec := make([]bls.SecretKey, 3)
+ for i := 0; i < len(sec); i++ {
+ sec[i] = *bls.NewSecretKey()
+ sec[i].Init()
+ fmt.Println("sec=", sec[i].String())
+ }
+ }
+ testRecoverSecretKey()
}
diff --git a/include/bls_if.h b/include/bls_if.h
index 943cb24..84b5f34 100644
--- a/include/bls_if.h
+++ b/include/bls_if.h
@@ -47,6 +47,8 @@ void blsSecretKeyAdd(blsSecretKey *sec, const blsSecretKey *rhs);
void blsSecretKeyInit(blsSecretKey *sec);
void blsSecretKeyGetPublicKey(const blsSecretKey *sec, blsPublicKey *pub);
void blsSecretKeySign(const blsSecretKey *sec, blsSign *sign, const char *m, size_t size);
+void blsSecretKeySet(blsSecretKey *sec, const blsSecretKey* const *msk, size_t k, const blsId *id);
+void blsSecretKeyRecover(blsSecretKey *sec, const blsSecretKey* const *secVec, const blsId *const *idVec, size_t n);
blsPublicKey *blsPublicKeyCreate(void);
void blsPublicKeyDestroy(blsPublicKey *pub);
@@ -54,6 +56,8 @@ void blsPublicKeyPut(const blsPublicKey *pub);
int blsPublicKeySetStr(blsPublicKey *pub, const char *buf, size_t bufSize);
size_t blsPublicKeyGetStr(const blsPublicKey *pub, char *buf, size_t maxBufSize);
void blsPublicKeyAdd(blsPublicKey *pub, const blsPublicKey *rhs);
+void blsPublicKeySet(blsPublicKey *pub, const blsPublicKey *const *mpk, size_t k, const blsId *id);
+void blsPublicKeyRecover(blsPublicKey *pub, const blsPublicKey *const *pubVec, const blsId *const *idVec, size_t n);
blsSign *blsSignCreate(void);
void blsSignDestroy(blsSign *sign);
@@ -61,6 +65,7 @@ void blsSignPut(const blsSign *sign);
int blsSignSetStr(blsSign *sign, const char *buf, size_t bufSize);
size_t blsSignGetStr(const blsSign *sign, char *buf, size_t maxBufSize);
void blsSignAdd(blsSign *sign, const blsSign *rhs);
+void blsSignRecover(blsSign *sign, const blsSign *const *signVec, const blsId *const *idVec, size_t n);
int blsSignVerify(const blsSign *sign, const blsPublicKey *pub, const char *m, size_t size);
diff --git a/src/bls_if.cpp b/src/bls_if.cpp
index 4315fad..6021c30 100644
--- a/src/bls_if.cpp
+++ b/src/bls_if.cpp
@@ -115,6 +115,16 @@ void blsSecretKeySign(const blsSecretKey *sec, blsSign *sign, const char *m, siz
((const bls::SecretKey*)sec)->sign(*(bls::Sign*)sign, std::string(m, size));
}
+void blsSecretKeySet(blsSecretKey *sec, const blsSecretKey* const *msk, size_t k, const blsId *id)
+{
+ ((bls::SecretKey*)sec)->set((const bls::SecretKey *const *)msk, k, *(const bls::Id*)id);
+}
+
+void blsSecretKeyRecover(blsSecretKey *sec, const blsSecretKey* const *secVec, const blsId *const *idVec, size_t n)
+{
+ ((bls::SecretKey*)sec)->recover((const bls::SecretKey *const *)secVec, (const bls::Id *const *)idVec, n);
+}
+
blsPublicKey *blsPublicKeyCreate()
{
return createT<bls::PublicKey, blsPublicKey>();
@@ -141,6 +151,14 @@ void blsPublicKeyAdd(blsPublicKey *pub, const blsPublicKey *rhs)
{
((bls::PublicKey*)pub)->add(*(const bls::PublicKey*)rhs);
}
+void blsPublicKeySet(blsPublicKey *pub, const blsPublicKey *const *mpk, size_t k, const blsId *id)
+{
+ ((bls::PublicKey*)pub)->set((const bls::PublicKey* const *)mpk, k, *(const bls::Id*)id);
+}
+void blsPublicKeyRecover(blsPublicKey *pub, const blsPublicKey *const *pubVec, const blsId *const *idVec, size_t n)
+{
+ ((bls::PublicKey*)pub)->recover((const bls::PublicKey* const *)pubVec, (const bls::Id* const *)idVec, n);
+}
blsSign *blsSignCreate()
{
@@ -168,6 +186,10 @@ void blsSignAdd(blsSign *sign, const blsSign *rhs)
{
((bls::Sign*)sign)->add(*(const bls::Sign*)rhs);
}
+void blsSignRecover(blsSign *sign, const blsSign *const *signVec, const blsId *const *idVec, size_t n)
+{
+ ((bls::Sign*)sign)->recover((const bls::Sign* const *)signVec, (const bls::Id* const *)idVec, n);
+}
int blsSignVerify(const blsSign *sign, const blsPublicKey *pub, const char *m, size_t size)
{