aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2016-08-27 19:56:04 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2016-08-27 19:56:04 +0800
commitfb67a31a6c7720e9499301127bfe57d5342c1d35 (patch)
tree89035773f009c5e935c8ddca002ee911d7ab9144
parentea600930c3e920b75d15fa1bffe3d48d818a294b (diff)
downloaddexon-bls-fb67a31a6c7720e9499301127bfe57d5342c1d35.tar
dexon-bls-fb67a31a6c7720e9499301127bfe57d5342c1d35.tar.gz
dexon-bls-fb67a31a6c7720e9499301127bfe57d5342c1d35.tar.bz2
dexon-bls-fb67a31a6c7720e9499301127bfe57d5342c1d35.tar.lz
dexon-bls-fb67a31a6c7720e9499301127bfe57d5342c1d35.tar.xz
dexon-bls-fb67a31a6c7720e9499301127bfe57d5342c1d35.tar.zst
dexon-bls-fb67a31a6c7720e9499301127bfe57d5342c1d35.zip
add init ; remove public key from getPop
-rw-r--r--include/bls.hpp26
-rw-r--r--src/bls.cpp25
-rw-r--r--test/bls_test.cpp4
3 files changed, 28 insertions, 27 deletions
diff --git a/include/bls.hpp b/include/bls.hpp
index be6d17d..d05449a 100644
--- a/include/bls.hpp
+++ b/include/bls.hpp
@@ -40,7 +40,10 @@ void init();
class SecretKey;
class PublicKey;
class Sign;
-
+/*
+ value of secretKey and Id is less than
+r = 16798108731015832284940804142231733909759579603404752749028378864165570215949
+*/
const size_t keySize = 32;
typedef std::vector<SecretKey> SecretKeyVec;
@@ -70,6 +73,7 @@ public:
/*
make a secret key for id = 0
set p[keySize] if p != 0
+ @note the value should be less than r
*/
void init(const uint64_t *p = 0);
void getPublicKey(PublicKey& pub) const;
@@ -78,7 +82,7 @@ public:
make Pop(Proof of Possesion)
pop = prv.sign(pub)
*/
- void getPop(Sign& pop, const PublicKey& pub) const;
+ void getPop(Sign& pop) const;
/*
make [s_0, ..., s_{k-1}] to prepare k-out-of-n secret sharing
*/
@@ -173,12 +177,26 @@ public:
/*
make master public key [s_0 Q, ..., s_{k-1} Q] from msk
*/
-void getMasterPublicKey(PublicKeyVec& mpk, const SecretKeyVec& msk);
+inline void getMasterPublicKey(PublicKeyVec& mpk, const SecretKeyVec& msk)
+{
+ const size_t n = msk.size();
+ mpk.resize(n);
+ for (size_t i = 0; i < n; i++) {
+ msk[i].getPublicKey(mpk[i]);
+ }
+}
/*
make pop from msk and mpk
*/
-void getPopVec(SignVec& popVec, const SecretKeyVec& msk, const PublicKeyVec& mpk);
+inline void getPopVec(SignVec& popVec, const SecretKeyVec& msk)
+{
+ const size_t n = msk.size();
+ popVec.resize(n);
+ for (size_t i = 0; i < n; i++) {
+ msk[i].getPop(popVec[i]);
+ }
+}
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 40599af..87a78f4 100644
--- a/src/bls.cpp
+++ b/src/bls.cpp
@@ -183,7 +183,7 @@ struct SecretKey {
void init(const uint64_t *p)
{
if (p) {
- s.setArray(p, keySize);
+ s.setArrayMask(p, keySize);
} else {
s.setRand(getRG());
}
@@ -388,8 +388,10 @@ void SecretKey::sign(Sign& sign, const std::string& m) const
sign.id_ = id_;
}
-void SecretKey::getPop(Sign& pop, const PublicKey& pub) const
+void SecretKey::getPop(Sign& pop) const
{
+ PublicKey pub;
+ getPublicKey(pub);
std::string m;
pub.getStr(m);
sign(pop, m);
@@ -426,24 +428,5 @@ void SecretKey::add(const SecretKey& rhs)
self_->s += rhs.self_->s;
}
-void getMasterPublicKey(PublicKeyVec& mpk, const SecretKeyVec& msk)
-{
- mpk.resize(msk.size());
- for (size_t i = 0; i < msk.size(); i++) {
- msk[i].getPublicKey(mpk[i]);
- }
-}
-
-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();
- popVec.resize(n);
- std::string m;
- for (size_t i = 0; i < n; i++) {
- mpk[i].getStr(m);
- msk[i].sign(popVec[i], m);
- }
-}
} // bls
diff --git a/test/bls_test.cpp b/test/bls_test.cpp
index 7a1d4e0..0c801c6 100644
--- a/test/bls_test.cpp
+++ b/test/bls_test.cpp
@@ -188,7 +188,7 @@ CYBOZU_TEST_AUTO(pop)
bls::PublicKeyVec mpk;
bls::getMasterPublicKey(mpk, msk);
bls::SignVec popVec;
- bls::getPopVec(popVec, msk, mpk);
+ bls::getPopVec(popVec, msk);
for (size_t i = 0; i < popVec.size(); i++) {
CYBOZU_TEST_ASSERT(popVec[i].verify(mpk[i]));
@@ -209,7 +209,7 @@ CYBOZU_TEST_AUTO(pop)
CYBOZU_TEST_EQUAL(pubVec[i], pub);
bls::Sign pop;
- secVec[i].getPop(pop, pubVec[i]);
+ secVec[i].getPop(pop);
CYBOZU_TEST_ASSERT(pop.verify(pubVec[i]));
secVec[i].sign(sVec[i], m);