aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/bls.hpp9
-rw-r--r--sample/bls_smpl.cpp2
-rw-r--r--src/bls.cpp29
-rw-r--r--test/bls_test.cpp10
4 files changed, 29 insertions, 21 deletions
diff --git a/include/bls.hpp b/include/bls.hpp
index 0b8279a..b2c8e71 100644
--- a/include/bls.hpp
+++ b/include/bls.hpp
@@ -22,6 +22,7 @@ struct MasterPublicKey;
} // bls::impl
/*
+ BLS signature
e : G2 x G1 -> Fp12
Q in G2 ; fixed global parameter
H : {str} -> G1
@@ -30,6 +31,11 @@ struct MasterPublicKey;
s H(m) ; signature of m
verify ; e(sQ, H(m)) = e(Q, s H(m))
*/
+
+class Sign;
+class PublicKey;
+class PrivateKey;
+
void init();
class Sign {
@@ -49,6 +55,7 @@ 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);
+ bool verify(const PublicKey& pub, const std::string& m) const;
/*
recover sign from k signVec
*/
@@ -88,6 +95,7 @@ class PublicKey {
impl::PublicKey *self_;
int id_;
friend class PrivateKey;
+ friend class Sign;
template<class G, class T>
friend void LagrangeInterpolation(G& r, const T& vec);
public:
@@ -100,7 +108,6 @@ public:
int getId() const { return id_; }
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
*/
diff --git a/sample/bls_smpl.cpp b/sample/bls_smpl.cpp
index d87757b..8db2e72 100644
--- a/sample/bls_smpl.cpp
+++ b/sample/bls_smpl.cpp
@@ -66,7 +66,7 @@ int verify(const std::string& m, int id)
load(pub, pubFile, id);
bls::Sign s;
load(s, signFile, id);
- if (pub.verify(s, m)) {
+ if (s.verify(pub, m)) {
puts("verify ok");
return 0;
} else {
diff --git a/src/bls.cpp b/src/bls.cpp
index 50e7a1e..949cdf6 100644
--- a/src/bls.cpp
+++ b/src/bls.cpp
@@ -144,6 +144,7 @@ namespace impl {
struct Sign {
G1 sHm; // s Hash(m)
const G1& get() const { return sHm; }
+ bool verify(const PublicKey& pub, const std::string& m) const;
};
struct PublicKey {
@@ -152,18 +153,19 @@ struct PublicKey {
{
G2::mul(sQ, getQ(), s);
}
- bool verify(const Sign& sign, const std::string& m) const
- {
- G1 Hm;
- HashAndMapToG1(Hm, m); // Hm = Hash(m)
- Fp12 e1, e2;
- BN::pairing(e1, getQ(), sign.sHm); // e(Q, s Hm)
- BN::pairing(e2, sQ, Hm); // e(sQ, Hm)
- return e1 == e2;
- }
const G2& get() const { return sQ; }
};
+inline bool Sign::verify(const PublicKey& pub, const std::string& m) const
+{
+ G1 Hm;
+ HashAndMapToG1(Hm, m); // Hm = Hash(m)
+ Fp12 e1, e2;
+ BN::pairing(e1, getQ(), sHm); // e(Q, s Hm)
+ BN::pairing(e2, pub.sQ, Hm); // e(sQ, Hm)
+ return e1 == e2;
+}
+
struct MasterPublicKey {
std::vector<G2> vecR;
};
@@ -228,6 +230,10 @@ std::istream& operator>>(std::istream& os, Sign& s)
return os >> s.id_ >> s.self_->sHm;
}
+bool Sign::verify(const PublicKey& pub, const std::string& m) const
+{
+ return self_->verify(*pub.self_, m);
+}
void Sign::recover(const std::vector<Sign>& signVec)
{
G1 sHm;
@@ -328,11 +334,6 @@ std::istream& operator>>(std::istream& is, PublicKey& pub)
return is >> pub.id_ >> pub.self_->sQ;
}
-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;
diff --git a/test/bls_test.cpp b/test/bls_test.cpp
index dd948b4..9cacc05 100644
--- a/test/bls_test.cpp
+++ b/test/bls_test.cpp
@@ -27,8 +27,8 @@ CYBOZU_TEST_AUTO(bls)
m += char('0' + i);
bls::Sign s;
prv.sign(s, m);
- CYBOZU_TEST_ASSERT(pub.verify(s, m));
- CYBOZU_TEST_ASSERT(!pub.verify(s, m + "a"));
+ CYBOZU_TEST_ASSERT(s.verify(pub, m));
+ CYBOZU_TEST_ASSERT(!s.verify(pub, m + "a"));
streamTest(s);
}
}
@@ -44,7 +44,7 @@ CYBOZU_TEST_AUTO(k_of_n)
prv0.sign(s0, m);
bls::PublicKey pub0;
prv0.getPublicKey(pub0);
- CYBOZU_TEST_ASSERT(pub0.verify(s0, m));
+ CYBOZU_TEST_ASSERT(s0.verify(pub0, m));
std::vector<bls::PrivateKey> allPrvVec;
prv0.share(allPrvVec, n, k);
@@ -60,7 +60,7 @@ CYBOZU_TEST_AUTO(k_of_n)
bls::PublicKey pub;
allPrvVec[i].getPublicKey(pub);
CYBOZU_TEST_ASSERT(pub != pub0);
- CYBOZU_TEST_ASSERT(pub.verify(allSignVec[i], m));
+ CYBOZU_TEST_ASSERT(allSignVec[i].verify(pub, m));
}
/*
@@ -198,5 +198,5 @@ CYBOZU_TEST_AUTO(add)
bls::Sign s1, s2;
prv1.sign(s1, m);
prv2.sign(s2, m);
- CYBOZU_TEST_ASSERT((pub1 + pub2).verify(s1 + s2, m));
+ CYBOZU_TEST_ASSERT((s1 + s2).verify(pub1 + pub2, m));
}