aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2016-08-15 16:05:53 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2016-08-15 16:05:53 +0800
commit6d7a12718ba4bc4784c6c86bfdcb49dc0cac6318 (patch)
tree3793e48d5db8b8cd8d9238354f4b4467d4cdd7e8
parentd3d6bf8848950be1bafae4b90c8e83085b894d16 (diff)
downloaddexon-bls-6d7a12718ba4bc4784c6c86bfdcb49dc0cac6318.tar
dexon-bls-6d7a12718ba4bc4784c6c86bfdcb49dc0cac6318.tar.gz
dexon-bls-6d7a12718ba4bc4784c6c86bfdcb49dc0cac6318.tar.bz2
dexon-bls-6d7a12718ba4bc4784c6c86bfdcb49dc0cac6318.tar.lz
dexon-bls-6d7a12718ba4bc4784c6c86bfdcb49dc0cac6318.tar.xz
dexon-bls-6d7a12718ba4bc4784c6c86bfdcb49dc0cac6318.tar.zst
dexon-bls-6d7a12718ba4bc4784c6c86bfdcb49dc0cac6318.zip
add operator+()
-rw-r--r--include/bls.hpp20
-rw-r--r--src/bls.cpp18
-rw-r--r--test/bls_test.cpp20
3 files changed, 56 insertions, 2 deletions
diff --git a/include/bls.hpp b/include/bls.hpp
index 23bff1c..0b8279a 100644
--- a/include/bls.hpp
+++ b/include/bls.hpp
@@ -49,11 +49,14 @@ public:
int getId() const { return id_; }
friend std::ostream& operator<<(std::ostream& os, const Sign& s);
friend std::istream& operator>>(std::istream& is, Sign& s);
-
/*
recover sign from k signVec
*/
void recover(const std::vector<Sign>& signVec);
+ /*
+ add signature key only if id_ == 0
+ */
+ void add(const Sign& rhs);
};
/*
@@ -106,8 +109,15 @@ public:
validate self by MasterPublicKey
*/
bool isValid(const MasterPublicKey& mpk) const;
+ /*
+ add public key only if id_ == 0
+ */
+ void add(const PublicKey& rhs);
};
+/*
+ s ; private key
+*/
class PrivateKey {
impl::PrivateKey *self_;
int id_; // master if id_ = 0, shared if id_ > 0
@@ -135,6 +145,14 @@ public:
recover privateKey from k prvVec
*/
void recover(const std::vector<PrivateKey>& prvVec);
+ /*
+ add private key only if id_ == 0
+ */
+ void add(const PrivateKey& rhs);
};
+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; }
+inline PrivateKey operator+(const PrivateKey& a, const PrivateKey& b) { PrivateKey r(a); r.add(b); return r; }
+
} //bls
diff --git a/src/bls.cpp b/src/bls.cpp
index ecbb59e..6bc5fc6 100644
--- a/src/bls.cpp
+++ b/src/bls.cpp
@@ -236,6 +236,12 @@ void Sign::recover(const std::vector<Sign>& signVec)
id_ = 0;
}
+void Sign::add(const Sign& rhs)
+{
+ if (id_ != 0 || rhs.id_ != 0) throw cybozu::Exception("bls:Sign:add:bad id") << id_ << rhs.id_;
+ self_->sHm += rhs.self_->sHm;
+}
+
MasterPublicKey::MasterPublicKey()
: self_(new impl::MasterPublicKey())
{
@@ -342,6 +348,12 @@ bool PublicKey::isValid(const MasterPublicKey& mpk) const
return v == self_->sQ;
}
+void PublicKey::add(const PublicKey& rhs)
+{
+ if (id_ != 0 || rhs.id_ != 0) throw cybozu::Exception("bls:PublicKey:add:bad id") << id_ << rhs.id_;
+ self_->sQ += rhs.self_->sQ;
+}
+
PrivateKey::PrivateKey()
: self_(new impl::PrivateKey())
, id_(0)
@@ -426,4 +438,10 @@ void PrivateKey::recover(const std::vector<PrivateKey>& prvVec)
id_ = 0;
}
+void PrivateKey::add(const PrivateKey& rhs)
+{
+ if (id_ != 0 || rhs.id_ != 0) throw cybozu::Exception("bls:PrivateKey:add:bad id") << id_ << rhs.id_;
+ self_->s += rhs.self_->s;
+}
+
} // bls
diff --git a/test/bls_test.cpp b/test/bls_test.cpp
index 64c04c2..dd948b4 100644
--- a/test/bls_test.cpp
+++ b/test/bls_test.cpp
@@ -163,7 +163,7 @@ CYBOZU_TEST_AUTO(k_of_n)
}
}
-CYBOZU_TEST_AUTO(verifier)
+CYBOZU_TEST_AUTO(MasterPublicKey)
{
const int n = 6;
const int k = 3;
@@ -182,3 +182,21 @@ CYBOZU_TEST_AUTO(verifier)
}
streamTest(mpk);
}
+
+CYBOZU_TEST_AUTO(add)
+{
+ bls::PrivateKey prv1, prv2;
+ prv1.init();
+ prv2.init();
+ CYBOZU_TEST_ASSERT(prv1 != prv2);
+
+ bls::PublicKey pub1, pub2;
+ prv1.getPublicKey(pub1);
+ prv2.getPublicKey(pub2);
+
+ const std::string m = "doremi";
+ bls::Sign s1, s2;
+ prv1.sign(s1, m);
+ prv2.sign(s2, m);
+ CYBOZU_TEST_ASSERT((pub1 + pub2).verify(s1 + s2, m));
+}