aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2016-08-21 14:34:52 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2016-08-21 14:34:52 +0800
commit76d28310b055dd596f4cd67fc7de49624948a85f (patch)
tree03ada7508d6e3301795437a37f23387951505222 /include
parentade6ac7396e497b1509bec9234440029ad4323cf (diff)
downloaddexon-bls-76d28310b055dd596f4cd67fc7de49624948a85f.tar.gz
dexon-bls-76d28310b055dd596f4cd67fc7de49624948a85f.tar.zst
dexon-bls-76d28310b055dd596f4cd67fc7de49624948a85f.zip
design IF again
Diffstat (limited to 'include')
-rw-r--r--include/bls.hpp87
1 files changed, 56 insertions, 31 deletions
diff --git a/include/bls.hpp b/include/bls.hpp
index b2c8e71..31b3d1c 100644
--- a/include/bls.hpp
+++ b/include/bls.hpp
@@ -17,7 +17,6 @@ namespace impl {
struct PublicKey;
struct PrivateKey;
struct Sign;
-struct MasterPublicKey;
} // bls::impl
@@ -32,11 +31,30 @@ struct MasterPublicKey;
verify ; e(sQ, H(m)) = e(Q, s H(m))
*/
+/*
+ initialize this library
+ call this once before using the other method
+*/
+void init();
+
class Sign;
class PublicKey;
class PrivateKey;
-void init();
+typedef std::vector<Sign> SignVec;
+typedef std::vector<PublicKey> PublicKeyVec;
+typedef std::vector<PrivateKey> PrivateKeyVec;
+
+/*
+ [s_0, s_1, ..., s_{k-1}]
+ s_0 is original private key
+*/
+typedef std::vector<PrivateKey> MasterPrivateKey;
+/*
+ [s_0 Q, ..., s_{k-1} Q]
+ Q is global fixed parameter
+*/
+typedef std::vector<PublicKey> MasterPublicKey;
class Sign {
impl::Sign *self_;
@@ -57,6 +75,10 @@ public:
friend std::istream& operator>>(std::istream& is, Sign& s);
bool verify(const PublicKey& pub, const std::string& m) const;
/*
+ verify self(pop) with pub
+ */
+ bool verify(const PublicKey& pub) const;
+ /*
recover sign from k signVec
*/
void recover(const std::vector<Sign>& signVec);
@@ -67,28 +89,6 @@ public:
};
/*
- (Q, sQ, c_1 Q, ..., c_{k-1}Q)
- s = c_0 ; private key
- c_1, ..., c_{k-1} ; secret sharing
- f(x) = c_0 + c_1 x + ... + c_{k-1} x^{k-1}
- f(id) ; private key for user id(>0)
-*/
-class MasterPublicKey {
- impl::MasterPublicKey *self_;
- friend class PrivateKey;
- friend class PublicKey;
-public:
- MasterPublicKey();
- ~MasterPublicKey();
- MasterPublicKey(const MasterPublicKey& rhs);
- MasterPublicKey& operator=(const MasterPublicKey& rhs);
- bool operator==(const MasterPublicKey& rhs) const;
- bool operator!=(const MasterPublicKey& rhs) const { return !(*this == rhs); }
- friend std::ostream& operator<<(std::ostream& os, const MasterPublicKey& mpk);
- friend std::istream& operator>>(std::istream& is, MasterPublicKey& mpk);
-};
-
-/*
sQ ; public key
*/
class PublicKey {
@@ -98,6 +98,8 @@ class PublicKey {
friend class Sign;
template<class G, class T>
friend void LagrangeInterpolation(G& r, const T& vec);
+ template<class T, class G>
+ friend struct Wrap;
public:
PublicKey();
~PublicKey();
@@ -108,14 +110,15 @@ 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);
+ void getStr(std::string& str) const;
/*
- recover publicKey from k pubVec
+ set public for id from mpk
*/
- void recover(const std::vector<PublicKey>& pubVec);
+ void set(const MasterPublicKey& mpk, int id);
/*
- validate self by MasterPublicKey
+ recover publicKey from k pubVec
*/
- bool isValid(const MasterPublicKey& mpk) const;
+ void recover(const std::vector<PublicKey>& pubVec);
/*
add public key only if id_ == 0
*/
@@ -130,6 +133,8 @@ class PrivateKey {
int id_; // master if id_ = 0, shared if id_ > 0
template<class G, class T>
friend void LagrangeInterpolation(G& r, const T& vec);
+ template<class T, class G>
+ friend struct Wrap;
public:
PrivateKey();
~PrivateKey();
@@ -140,14 +145,24 @@ public:
int getId() const { return id_; }
friend std::ostream& operator<<(std::ostream& os, const PrivateKey& prv);
friend std::istream& operator>>(std::istream& is, PrivateKey& prv);
+ /*
+ make a private key for id = 0
+ */
void init();
void getPublicKey(PublicKey& pub) const;
void sign(Sign& sign, const std::string& m) const;
/*
- k-out-of-n secret sharing of privateKey
- set verifier if mpk is not 0
+ make Pop(Proof of Possesion)
+ */
+ void getPop(Sign& pop, const PublicKey& pub) const;
+ /*
+ make [s_0, ..., s_{k-1}] to prepare k-out-of-n secret sharing
*/
- void share(std::vector<PrivateKey>& prvVec, int n, int k, MasterPublicKey *mpk = 0);
+ void getMasterPrivateKey(MasterPrivateKey& msk, int k) const;
+ /*
+ set a private key for id > 0 from msk
+ */
+ void set(const MasterPrivateKey& msk, int id);
/*
recover privateKey from k prvVec
*/
@@ -158,6 +173,16 @@ public:
void add(const PrivateKey& rhs);
};
+/*
+ make master public key [s_0 Q, ..., s_{k-1} Q] from msk
+*/
+void getMasterPublicKey(MasterPublicKey& mpk, const MasterPrivateKey& msk);
+
+/*
+ make pop from msk and mpk
+*/
+void getPopVec(std::vector<Sign>& popVec, const MasterPrivateKey& msk, const MasterPublicKey& mpk);
+
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; }