diff options
-rw-r--r-- | include/bls.hpp | 8 | ||||
-rw-r--r-- | sample/bls_smpl.cpp | 34 | ||||
-rw-r--r-- | src/bls.cpp | 12 | ||||
-rw-r--r-- | test/bls_test.cpp | 94 |
4 files changed, 74 insertions, 74 deletions
diff --git a/include/bls.hpp b/include/bls.hpp index 96a0d72..7cfeed8 100644 --- a/include/bls.hpp +++ b/include/bls.hpp @@ -143,8 +143,8 @@ public: bool operator==(const SecretKey& rhs) const; bool operator!=(const SecretKey& rhs) const { return !(*this == rhs); } int getId() const { return id_; } - friend std::ostream& operator<<(std::ostream& os, const SecretKey& prv); - friend std::istream& operator>>(std::istream& is, SecretKey& prv); + friend std::ostream& operator<<(std::ostream& os, const SecretKey& sec); + friend std::istream& operator>>(std::istream& is, SecretKey& sec); /* make a private key for id = 0 */ @@ -164,9 +164,9 @@ public: */ void set(const MasterSecretKey& msk, int id); /* - recover secretKey from k prvVec + recover secretKey from k secVec */ - void recover(const std::vector<SecretKey>& prvVec); + void recover(const std::vector<SecretKey>& secVec); /* add private key only if id_ == 0 */ diff --git a/sample/bls_smpl.cpp b/sample/bls_smpl.cpp index 36bb9e3..bbb558c 100644 --- a/sample/bls_smpl.cpp +++ b/sample/bls_smpl.cpp @@ -6,7 +6,7 @@ typedef std::vector<int> IntVec; const std::string pubFile = "sample/publickey"; -const std::string prvFile = "sample/privatekey"; +const std::string secFile = "sample/privatekey"; const std::string signFile = "sample/sign"; std::string makeName(const std::string& name, int id) @@ -38,12 +38,12 @@ void load(T& t, const std::string& file, int id = 0) int init() { - printf("make %s and %s files\n", prvFile.c_str(), pubFile.c_str()); - bls::SecretKey prv; - prv.init(); - save(prvFile, prv); + printf("make %s and %s files\n", secFile.c_str(), pubFile.c_str()); + bls::SecretKey sec; + sec.init(); + save(secFile, sec); bls::PublicKey pub; - prv.getPublicKey(pub); + sec.getPublicKey(pub); save(pubFile, pub); return 0; } @@ -51,10 +51,10 @@ int init() int sign(const std::string& m, int id) { printf("sign message `%s` by id=%d\n", m.c_str(), id); - bls::SecretKey prv; - load(prv, prvFile, id); + bls::SecretKey sec; + load(sec, secFile, id); bls::Sign s; - prv.sign(s, m); + sec.sign(s, m); save(signFile, s, id); return 0; } @@ -78,19 +78,19 @@ int verify(const std::string& m, int id) int share(int n, int k) { printf("%d-out-of-%d threshold sharing\n", k, n); - bls::SecretKey prv; - load(prv, prvFile); + bls::SecretKey sec; + load(sec, secFile); bls::SecretKeyVec msk; - prv.getMasterSecretKey(msk, k); - std::vector<bls::SecretKey> prvVec(n); + sec.getMasterSecretKey(msk, k); + std::vector<bls::SecretKey> secVec(n); for (int i = 0; i < n; i++) { - prvVec[i].set(msk, i + 1); + secVec[i].set(msk, i + 1); } for (int i = 0; i < n; i++) { - int id = prvVec[i].getId(); - save(prvFile, prvVec[i], id); + int id = secVec[i].getId(); + save(secFile, secVec[i], id); bls::PublicKey pub; - prvVec[i].getPublicKey(pub); + secVec[i].getPublicKey(pub); save(pubFile, pub, id); } return 0; diff --git a/src/bls.cpp b/src/bls.cpp index d9b8a6a..57c6dee 100644 --- a/src/bls.cpp +++ b/src/bls.cpp @@ -357,14 +357,14 @@ bool SecretKey::operator==(const SecretKey& rhs) const return id_ == rhs.id_ && self_->s == rhs.self_->s; } -std::ostream& operator<<(std::ostream& os, const SecretKey& prv) +std::ostream& operator<<(std::ostream& os, const SecretKey& sec) { - return os << prv.id_ << ' ' << prv.self_->s; + return os << sec.id_ << ' ' << sec.self_->s; } -std::istream& operator>>(std::istream& is, SecretKey& prv) +std::istream& operator>>(std::istream& is, SecretKey& sec) { - return is >> prv.id_ >> prv.self_->s; + return is >> sec.id_ >> sec.self_->s; } void SecretKey::init() @@ -408,10 +408,10 @@ void SecretKey::set(const MasterSecretKey& msk, int id) id_ = id; } -void SecretKey::recover(const std::vector<SecretKey>& prvVec) +void SecretKey::recover(const std::vector<SecretKey>& secVec) { Fr s; - LagrangeInterpolation(s, prvVec); + LagrangeInterpolation(s, secVec); self_->s = s; id_ = 0; } diff --git a/test/bls_test.cpp b/test/bls_test.cpp index 308153a..0c4172a 100644 --- a/test/bls_test.cpp +++ b/test/bls_test.cpp @@ -16,17 +16,17 @@ void streamTest(const T& t) CYBOZU_TEST_AUTO(bls) { bls::init(); - bls::SecretKey prv; - prv.init(); - streamTest(prv); + bls::SecretKey sec; + sec.init(); + streamTest(sec); bls::PublicKey pub; - prv.getPublicKey(pub); + sec.getPublicKey(pub); streamTest(pub); for (int i = 0; i < 5; i++) { std::string m = "hello"; m += char('0' + i); bls::Sign s; - prv.sign(s, m); + sec.sign(s, m); CYBOZU_TEST_ASSERT(s.verify(pub, m)); CYBOZU_TEST_ASSERT(!s.verify(pub, m + "a")); streamTest(s); @@ -38,16 +38,16 @@ CYBOZU_TEST_AUTO(k_of_n) const std::string m = "abc"; const int n = 5; const int k = 3; - bls::SecretKey prv0; - prv0.init(); + bls::SecretKey sec0; + sec0.init(); bls::Sign s0; - prv0.sign(s0, m); + sec0.sign(s0, m); bls::PublicKey pub0; - prv0.getPublicKey(pub0); + sec0.getPublicKey(pub0); CYBOZU_TEST_ASSERT(s0.verify(pub0, m)); bls::MasterSecretKey msk; - prv0.getMasterSecretKey(msk, k); + sec0.getMasterSecretKey(msk, k); std::vector<bls::SecretKey> allPrvVec(n); for (int i = 0; i < n; i++) { @@ -61,7 +61,7 @@ CYBOZU_TEST_AUTO(k_of_n) std::vector<bls::Sign> allSignVec(n); for (int i = 0; i < n; i++) { - CYBOZU_TEST_ASSERT(allPrvVec[i] != prv0); + CYBOZU_TEST_ASSERT(allPrvVec[i] != sec0); allPrvVec[i].sign(allSignVec[i], m); bls::PublicKey pub; allPrvVec[i].getPublicKey(pub); @@ -73,47 +73,47 @@ CYBOZU_TEST_AUTO(k_of_n) 3-out-of-n can recover */ - std::vector<bls::SecretKey> prvVec(3); + std::vector<bls::SecretKey> secVec(3); for (int a = 0; a < n; a++) { - prvVec[0] = allPrvVec[a]; + secVec[0] = allPrvVec[a]; for (int b = a + 1; b < n; b++) { - prvVec[1] = allPrvVec[b]; + secVec[1] = allPrvVec[b]; for (int c = b + 1; c < n; c++) { - prvVec[2] = allPrvVec[c]; - bls::SecretKey prv; - prv.recover(prvVec); - CYBOZU_TEST_EQUAL(prv, prv0); + secVec[2] = allPrvVec[c]; + bls::SecretKey sec; + sec.recover(secVec); + CYBOZU_TEST_EQUAL(sec, sec0); } } } { - prvVec[0] = allPrvVec[0]; - prvVec[1] = allPrvVec[1]; - prvVec[2] = allPrvVec[0]; // same of prvVec[0] - bls::SecretKey prv; - CYBOZU_TEST_EXCEPTION_MESSAGE(prv.recover(prvVec), std::exception, "same id"); + secVec[0] = allPrvVec[0]; + secVec[1] = allPrvVec[1]; + secVec[2] = allPrvVec[0]; // same of secVec[0] + bls::SecretKey sec; + CYBOZU_TEST_EXCEPTION_MESSAGE(sec.recover(secVec), std::exception, "same id"); } { /* n-out-of-n can recover */ - bls::SecretKey prv; - prv.recover(allPrvVec); - CYBOZU_TEST_EQUAL(prv, prv0); + bls::SecretKey sec; + sec.recover(allPrvVec); + CYBOZU_TEST_EQUAL(sec, sec0); } /* 2-out-of-n can't recover */ - prvVec.resize(2); + secVec.resize(2); for (int a = 0; a < n; a++) { - prvVec[0] = allPrvVec[a]; + secVec[0] = allPrvVec[a]; for (int b = a + 1; b < n; b++) { - prvVec[1] = allPrvVec[b]; - bls::SecretKey prv; - prv.recover(prvVec); - CYBOZU_TEST_ASSERT(prv != prv0); + secVec[1] = allPrvVec[b]; + bls::SecretKey sec; + sec.recover(secVec); + CYBOZU_TEST_ASSERT(sec != sec0); } } /* @@ -173,12 +173,12 @@ CYBOZU_TEST_AUTO(MasterSecretKey) { const int k = 3; const int n = 6; - bls::SecretKey prv0; - prv0.init(); + bls::SecretKey sec0; + sec0.init(); bls::PublicKey pub0; - prv0.getPublicKey(pub0); + sec0.getPublicKey(pub0); bls::MasterSecretKey msk; - prv0.getMasterSecretKey(msk, k); + sec0.getMasterSecretKey(msk, k); bls::MasterPublicKey mpk; bls::getMasterPublicKey(mpk, msk); @@ -186,12 +186,12 @@ CYBOZU_TEST_AUTO(MasterSecretKey) const int idTbl[n] = { 3, 5, 193, 22, 15 }; - bls::SecretKeyVec prvVec(n); + bls::SecretKeyVec secVec(n); bls::PublicKeyVec pubVec(n); for (int i = 0; i < n; i++) { int id = idTbl[i]; - prvVec[i].set(msk, id); - prvVec[i].getPublicKey(pubVec[i]); + secVec[i].set(msk, id); + secVec[i].getPublicKey(pubVec[i]); bls::PublicKey pub; pub.set(mpk, id); CYBOZU_TEST_EQUAL(pubVec[i], pub); @@ -200,18 +200,18 @@ CYBOZU_TEST_AUTO(MasterSecretKey) CYBOZU_TEST_AUTO(add) { - bls::SecretKey prv1, prv2; - prv1.init(); - prv2.init(); - CYBOZU_TEST_ASSERT(prv1 != prv2); + bls::SecretKey sec1, sec2; + sec1.init(); + sec2.init(); + CYBOZU_TEST_ASSERT(sec1 != sec2); bls::PublicKey pub1, pub2; - prv1.getPublicKey(pub1); - prv2.getPublicKey(pub2); + sec1.getPublicKey(pub1); + sec2.getPublicKey(pub2); const std::string m = "doremi"; bls::Sign s1, s2; - prv1.sign(s1, m); - prv2.sign(s2, m); + sec1.sign(s1, m); + sec2.sign(s2, m); CYBOZU_TEST_ASSERT((s1 + s2).verify(pub1 + pub2, m)); } |