diff options
-rw-r--r-- | include/bls.hpp | 27 | ||||
-rw-r--r-- | src/bls.cpp | 16 | ||||
-rw-r--r-- | test/bls_test.cpp | 10 |
3 files changed, 21 insertions, 32 deletions
diff --git a/include/bls.hpp b/include/bls.hpp index 7cfeed8..8a51488 100644 --- a/include/bls.hpp +++ b/include/bls.hpp @@ -45,17 +45,6 @@ typedef std::vector<Sign> SignVec; typedef std::vector<PublicKey> PublicKeyVec; typedef std::vector<SecretKey> SecretKeyVec; -/* - [s_0, s_1, ..., s_{k-1}] - s_0 is original private key -*/ -typedef std::vector<SecretKey> MasterSecretKey; -/* - [s_0 Q, ..., s_{k-1} Q] - Q is global fixed parameter -*/ -typedef std::vector<PublicKey> MasterPublicKey; - class Sign { impl::Sign *self_; int id_; @@ -81,7 +70,7 @@ public: /* recover sign from k signVec */ - void recover(const std::vector<Sign>& signVec); + void recover(const SignVec& signVec); /* add signature key only if id_ == 0 */ @@ -114,11 +103,11 @@ public: /* set public for id from mpk */ - void set(const MasterPublicKey& mpk, int id); + void set(const PublicKeyVec& mpk, int id); /* recover publicKey from k pubVec */ - void recover(const std::vector<PublicKey>& pubVec); + void recover(const PublicKeyVec& pubVec); /* add public key only if id_ == 0 */ @@ -158,15 +147,15 @@ public: /* make [s_0, ..., s_{k-1}] to prepare k-out-of-n secret sharing */ - void getMasterSecretKey(MasterSecretKey& msk, int k) const; + void getMasterSecretKey(SecretKeyVec& msk, int k) const; /* set a private key for id > 0 from msk */ - void set(const MasterSecretKey& msk, int id); + void set(const SecretKeyVec& msk, int id); /* recover secretKey from k secVec */ - void recover(const std::vector<SecretKey>& secVec); + void recover(const SecretKeyVec& secVec); /* add private key only if id_ == 0 */ @@ -176,12 +165,12 @@ public: /* make master public key [s_0 Q, ..., s_{k-1} Q] from msk */ -void getMasterPublicKey(MasterPublicKey& mpk, const MasterSecretKey& msk); +void getMasterPublicKey(PublicKeyVec& mpk, const SecretKeyVec& msk); /* make pop from msk and mpk */ -void getPopVec(std::vector<Sign>& popVec, const MasterSecretKey& msk, const MasterPublicKey& mpk); +void getPopVec(SignVec& popVec, const SecretKeyVec& msk, const PublicKeyVec& mpk); inline Sign operator+(const Sign& a, const Sign& b) { Sign r(a); r.add(b); return r; } inline PublicKey operator+(const PublicKey& a, const PublicKey& b) { PublicKey r(a); r.add(b); return r; } diff --git a/src/bls.cpp b/src/bls.cpp index 57c6dee..ab3d68b 100644 --- a/src/bls.cpp +++ b/src/bls.cpp @@ -247,7 +247,7 @@ bool Sign::verify(const PublicKey& pub) const pub.getStr(str); return verify(pub, str); } -void Sign::recover(const std::vector<Sign>& signVec) +void Sign::recover(const SignVec& signVec) { G1 sHm; LagrangeInterpolation(sHm, signVec); @@ -307,14 +307,14 @@ void PublicKey::getStr(std::string& str) const str = os.str(); } -void PublicKey::set(const MasterPublicKey& mpk, int id) +void PublicKey::set(const PublicKeyVec& mpk, int id) { Wrap<PublicKey, G2> w(mpk); evalPoly(self_->sQ, Fr(id), w); id_ = id; } -void PublicKey::recover(const std::vector<PublicKey>& pubVec) +void PublicKey::recover(const PublicKeyVec& pubVec) { G2 sQ; LagrangeInterpolation(sQ, pubVec); @@ -391,7 +391,7 @@ void SecretKey::getPop(Sign& pop, const PublicKey& pub) const sign(pop, m); } -void SecretKey::getMasterSecretKey(MasterSecretKey& msk, int k) const +void SecretKey::getMasterSecretKey(SecretKeyVec& msk, int k) const { if (k <= 1) throw cybozu::Exception("bls:SecretKey:getMasterSecretKey:bad k") << k; msk.resize(k); @@ -401,14 +401,14 @@ void SecretKey::getMasterSecretKey(MasterSecretKey& msk, int k) const } } -void SecretKey::set(const MasterSecretKey& msk, int id) +void SecretKey::set(const SecretKeyVec& msk, int id) { Wrap<SecretKey, Fr> w(msk); evalPoly(self_->s, id, w); id_ = id; } -void SecretKey::recover(const std::vector<SecretKey>& secVec) +void SecretKey::recover(const SecretKeyVec& secVec) { Fr s; LagrangeInterpolation(s, secVec); @@ -422,7 +422,7 @@ void SecretKey::add(const SecretKey& rhs) self_->s += rhs.self_->s; } -void getMasterPublicKey(MasterPublicKey& mpk, const MasterSecretKey& msk) +void getMasterPublicKey(PublicKeyVec& mpk, const SecretKeyVec& msk) { mpk.resize(msk.size()); for (size_t i = 0; i < msk.size(); i++) { @@ -430,7 +430,7 @@ void getMasterPublicKey(MasterPublicKey& mpk, const MasterSecretKey& msk) } } -void getPopVec(std::vector<Sign>& popVec, const MasterSecretKey& msk, const MasterPublicKey& mpk) +void getPopVec(SignVec& popVec, const SecretKeyVec& msk, const PublicKeyVec& mpk) { if (msk.size() != mpk.size()) throw cybozu::Exception("bls:getPopVec:bad size") << msk.size() << mpk.size(); const size_t n = msk.size(); diff --git a/test/bls_test.cpp b/test/bls_test.cpp index 0c4172a..271f862 100644 --- a/test/bls_test.cpp +++ b/test/bls_test.cpp @@ -46,10 +46,10 @@ CYBOZU_TEST_AUTO(k_of_n) sec0.getPublicKey(pub0); CYBOZU_TEST_ASSERT(s0.verify(pub0, m)); - bls::MasterSecretKey msk; + bls::SecretKeyVec msk; sec0.getMasterSecretKey(msk, k); - std::vector<bls::SecretKey> allPrvVec(n); + bls::SecretKeyVec allPrvVec(n); for (int i = 0; i < n; i++) { int id = i + 1; allPrvVec[i].set(msk, id); @@ -169,7 +169,7 @@ CYBOZU_TEST_AUTO(k_of_n) } } -CYBOZU_TEST_AUTO(MasterSecretKey) +CYBOZU_TEST_AUTO(pop) { const int k = 3; const int n = 6; @@ -177,10 +177,10 @@ CYBOZU_TEST_AUTO(MasterSecretKey) sec0.init(); bls::PublicKey pub0; sec0.getPublicKey(pub0); - bls::MasterSecretKey msk; + bls::SecretKeyVec msk; sec0.getMasterSecretKey(msk, k); - bls::MasterPublicKey mpk; + bls::PublicKeyVec mpk; bls::getMasterPublicKey(mpk, msk); const int idTbl[n] = { |