diff options
-rw-r--r-- | include/bls.hpp | 4 | ||||
-rw-r--r-- | src/bls.cpp | 9 | ||||
-rw-r--r-- | test/bls_test.cpp | 11 |
3 files changed, 24 insertions, 0 deletions
diff --git a/include/bls.hpp b/include/bls.hpp index 2ba7ef5..82378be 100644 --- a/include/bls.hpp +++ b/include/bls.hpp @@ -67,6 +67,10 @@ public: friend std::ostream& operator<<(std::ostream& os, const PublicKey& pub); friend std::istream& operator>>(std::istream& is, PublicKey& pub); bool verify(const Sign& sign, const std::string& m) const; + /* + recover publicKey from k pubVec + */ + void recover(const std::vector<PublicKey>& pubVec); }; class PrivateKey { diff --git a/src/bls.cpp b/src/bls.cpp index 8c6ff4a..8577c95 100644 --- a/src/bls.cpp +++ b/src/bls.cpp @@ -152,6 +152,7 @@ struct PublicKey { BN::pairing(e2, sQ, Hm); // e(sQ, Hm) return e1 == e2; } + const G2& get() const { return sQ; } }; struct PrivateKey { @@ -292,6 +293,14 @@ bool PublicKey::verify(const Sign& sign, const std::string& m) const return self_->verify(*sign.self_, m); } +void PublicKey::recover(const std::vector<PublicKey>& pubVec) +{ + G2 sQ; + LagrangeInterpolation(sQ, pubVec); + self_->sQ = sQ; + id_ = 0; +} + PrivateKey::PrivateKey() : self_(new impl::PrivateKey()) , id_(0) diff --git a/test/bls_test.cpp b/test/bls_test.cpp index 074117f..59924d9 100644 --- a/test/bls_test.cpp +++ b/test/bls_test.cpp @@ -158,4 +158,15 @@ CYBOZU_TEST_AUTO(k_of_n) CYBOZU_TEST_ASSERT(s != s0); } } + // share and recover publicKey + { + std::vector<bls::PublicKey> pubVec(k); + // select [0, k) publicKey + for (int i = 0; i < k; i++) { + allPrvVec[i].getPublicKey(pubVec[i]); + } + bls::PublicKey pub; + pub.recover(pubVec); + CYBOZU_TEST_EQUAL(pub, pub0); + } } |