aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2016-08-21 14:47:19 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2016-08-21 14:47:19 +0800
commit3b17399925767333832756ca5ccc04c3197eed4b (patch)
treeeb289b41fbf29364a459e74416e2ec817cceb7d6
parent7a42782e361af6ea7b7e199c7aef4214071c441e (diff)
downloaddexon-bls-3b17399925767333832756ca5ccc04c3197eed4b.tar
dexon-bls-3b17399925767333832756ca5ccc04c3197eed4b.tar.gz
dexon-bls-3b17399925767333832756ca5ccc04c3197eed4b.tar.bz2
dexon-bls-3b17399925767333832756ca5ccc04c3197eed4b.tar.lz
dexon-bls-3b17399925767333832756ca5ccc04c3197eed4b.tar.xz
dexon-bls-3b17399925767333832756ca5ccc04c3197eed4b.tar.zst
dexon-bls-3b17399925767333832756ca5ccc04c3197eed4b.zip
rename PrivateKey to SecretKey
-rw-r--r--include/bls.hpp48
-rw-r--r--sample/bls_smpl.cpp14
-rw-r--r--src/bls.cpp46
-rw-r--r--test/bls_test.cpp32
4 files changed, 70 insertions, 70 deletions
diff --git a/include/bls.hpp b/include/bls.hpp
index 31b3d1c..96a0d72 100644
--- a/include/bls.hpp
+++ b/include/bls.hpp
@@ -15,7 +15,7 @@ namespace bls {
namespace impl {
struct PublicKey;
-struct PrivateKey;
+struct SecretKey;
struct Sign;
} // bls::impl
@@ -39,17 +39,17 @@ void init();
class Sign;
class PublicKey;
-class PrivateKey;
+class SecretKey;
typedef std::vector<Sign> SignVec;
typedef std::vector<PublicKey> PublicKeyVec;
-typedef std::vector<PrivateKey> PrivateKeyVec;
+typedef std::vector<SecretKey> SecretKeyVec;
/*
[s_0, s_1, ..., s_{k-1}]
s_0 is original private key
*/
-typedef std::vector<PrivateKey> MasterPrivateKey;
+typedef std::vector<SecretKey> MasterSecretKey;
/*
[s_0 Q, ..., s_{k-1} Q]
Q is global fixed parameter
@@ -60,7 +60,7 @@ class Sign {
impl::Sign *self_;
int id_;
friend class PublicKey;
- friend class PrivateKey;
+ friend class SecretKey;
template<class G, class T>
friend void LagrangeInterpolation(G& r, const T& vec);
public:
@@ -94,7 +94,7 @@ public:
class PublicKey {
impl::PublicKey *self_;
int id_;
- friend class PrivateKey;
+ friend class SecretKey;
friend class Sign;
template<class G, class T>
friend void LagrangeInterpolation(G& r, const T& vec);
@@ -128,23 +128,23 @@ public:
/*
s ; private key
*/
-class PrivateKey {
- impl::PrivateKey *self_;
+class SecretKey {
+ impl::SecretKey *self_;
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();
- PrivateKey(const PrivateKey& rhs);
- PrivateKey& operator=(const PrivateKey& rhs);
- bool operator==(const PrivateKey& rhs) const;
- bool operator!=(const PrivateKey& rhs) const { return !(*this == rhs); }
+ SecretKey();
+ ~SecretKey();
+ SecretKey(const SecretKey& rhs);
+ SecretKey& operator=(const SecretKey& rhs);
+ 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 PrivateKey& prv);
- friend std::istream& operator>>(std::istream& is, PrivateKey& prv);
+ friend std::ostream& operator<<(std::ostream& os, const SecretKey& prv);
+ friend std::istream& operator>>(std::istream& is, SecretKey& prv);
/*
make a private key for id = 0
*/
@@ -158,33 +158,33 @@ public:
/*
make [s_0, ..., s_{k-1}] to prepare k-out-of-n secret sharing
*/
- void getMasterPrivateKey(MasterPrivateKey& msk, int k) const;
+ void getMasterSecretKey(MasterSecretKey& msk, int k) const;
/*
set a private key for id > 0 from msk
*/
- void set(const MasterPrivateKey& msk, int id);
+ void set(const MasterSecretKey& msk, int id);
/*
- recover privateKey from k prvVec
+ recover secretKey from k prvVec
*/
- void recover(const std::vector<PrivateKey>& prvVec);
+ void recover(const std::vector<SecretKey>& prvVec);
/*
add private key only if id_ == 0
*/
- void add(const PrivateKey& rhs);
+ void add(const SecretKey& rhs);
};
/*
make master public key [s_0 Q, ..., s_{k-1} Q] from msk
*/
-void getMasterPublicKey(MasterPublicKey& mpk, const MasterPrivateKey& msk);
+void getMasterPublicKey(MasterPublicKey& mpk, const MasterSecretKey& msk);
/*
make pop from msk and mpk
*/
-void getPopVec(std::vector<Sign>& popVec, const MasterPrivateKey& msk, const MasterPublicKey& mpk);
+void getPopVec(std::vector<Sign>& popVec, const MasterSecretKey& 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; }
+inline SecretKey operator+(const SecretKey& a, const SecretKey& b) { SecretKey r(a); r.add(b); return r; }
} //bls
diff --git a/sample/bls_smpl.cpp b/sample/bls_smpl.cpp
index c4215cc..36bb9e3 100644
--- a/sample/bls_smpl.cpp
+++ b/sample/bls_smpl.cpp
@@ -39,7 +39,7 @@ 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::PrivateKey prv;
+ bls::SecretKey prv;
prv.init();
save(prvFile, prv);
bls::PublicKey pub;
@@ -51,7 +51,7 @@ int init()
int sign(const std::string& m, int id)
{
printf("sign message `%s` by id=%d\n", m.c_str(), id);
- bls::PrivateKey prv;
+ bls::SecretKey prv;
load(prv, prvFile, id);
bls::Sign s;
prv.sign(s, m);
@@ -78,11 +78,11 @@ 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::PrivateKey prv;
+ bls::SecretKey prv;
load(prv, prvFile);
- bls::PrivateKeyVec msk;
- prv.getMasterPrivateKey(msk, k);
- std::vector<bls::PrivateKey> prvVec(n);
+ bls::SecretKeyVec msk;
+ prv.getMasterSecretKey(msk, k);
+ std::vector<bls::SecretKey> prvVec(n);
for (int i = 0; i < n; i++) {
prvVec[i].set(msk, i + 1);
}
@@ -128,7 +128,7 @@ int main(int argc, char *argv[])
opt.appendOpt(&n, 10, "n", ": k-out-of-n threshold");
opt.appendOpt(&k, 3, "k", ": k-out-of-n threshold");
opt.appendOpt(&m, "", "m", ": message to be signed");
- opt.appendOpt(&id, 0, "id", ": id of privateKey");
+ opt.appendOpt(&id, 0, "id", ": id of secretKey");
opt.appendVec(&ids, "ids", ": select k id in [0, n). this option should be last");
opt.appendHelp("h");
if (!opt.parse(argc, argv)) {
diff --git a/src/bls.cpp b/src/bls.cpp
index b887469..d9b8a6a 100644
--- a/src/bls.cpp
+++ b/src/bls.cpp
@@ -177,7 +177,7 @@ inline bool Sign::verify(const PublicKey& pub, const std::string& m) const
return e1 == e2;
}
-struct PrivateKey {
+struct SecretKey {
Fr s;
const Fr& get() const { return s; }
void init()
@@ -328,72 +328,72 @@ void PublicKey::add(const PublicKey& rhs)
self_->sQ += rhs.self_->sQ;
}
-PrivateKey::PrivateKey()
- : self_(new impl::PrivateKey())
+SecretKey::SecretKey()
+ : self_(new impl::SecretKey())
, id_(0)
{
}
-PrivateKey::~PrivateKey()
+SecretKey::~SecretKey()
{
delete self_;
}
-PrivateKey::PrivateKey(const PrivateKey& rhs)
- : self_(new impl::PrivateKey(*rhs.self_))
+SecretKey::SecretKey(const SecretKey& rhs)
+ : self_(new impl::SecretKey(*rhs.self_))
, id_(rhs.id_)
{
}
-PrivateKey& PrivateKey::operator=(const PrivateKey& rhs)
+SecretKey& SecretKey::operator=(const SecretKey& rhs)
{
*self_ = *rhs.self_;
id_ = rhs.id_;
return *this;
}
-bool PrivateKey::operator==(const PrivateKey& rhs) const
+bool SecretKey::operator==(const SecretKey& rhs) const
{
return id_ == rhs.id_ && self_->s == rhs.self_->s;
}
-std::ostream& operator<<(std::ostream& os, const PrivateKey& prv)
+std::ostream& operator<<(std::ostream& os, const SecretKey& prv)
{
return os << prv.id_ << ' ' << prv.self_->s;
}
-std::istream& operator>>(std::istream& is, PrivateKey& prv)
+std::istream& operator>>(std::istream& is, SecretKey& prv)
{
return is >> prv.id_ >> prv.self_->s;
}
-void PrivateKey::init()
+void SecretKey::init()
{
self_->init();
}
-void PrivateKey::getPublicKey(PublicKey& pub) const
+void SecretKey::getPublicKey(PublicKey& pub) const
{
self_->getPublicKey(*pub.self_);
pub.id_ = id_;
}
-void PrivateKey::sign(Sign& sign, const std::string& m) const
+void SecretKey::sign(Sign& sign, const std::string& m) const
{
self_->sign(*sign.self_, m);
sign.id_ = id_;
}
-void PrivateKey::getPop(Sign& pop, const PublicKey& pub) const
+void SecretKey::getPop(Sign& pop, const PublicKey& pub) const
{
std::string m;
pub.getStr(m);
sign(pop, m);
}
-void PrivateKey::getMasterPrivateKey(MasterPrivateKey& msk, int k) const
+void SecretKey::getMasterSecretKey(MasterSecretKey& msk, int k) const
{
- if (k <= 1) throw cybozu::Exception("bls:PrivateKey:getMasterPrivateKey:bad k") << k;
+ if (k <= 1) throw cybozu::Exception("bls:SecretKey:getMasterSecretKey:bad k") << k;
msk.resize(k);
msk[0] = *this;
for (int i = 1; i < k; i++) {
@@ -401,14 +401,14 @@ void PrivateKey::getMasterPrivateKey(MasterPrivateKey& msk, int k) const
}
}
-void PrivateKey::set(const MasterPrivateKey& msk, int id)
+void SecretKey::set(const MasterSecretKey& msk, int id)
{
- Wrap<PrivateKey, Fr> w(msk);
+ Wrap<SecretKey, Fr> w(msk);
evalPoly(self_->s, id, w);
id_ = id;
}
-void PrivateKey::recover(const std::vector<PrivateKey>& prvVec)
+void SecretKey::recover(const std::vector<SecretKey>& prvVec)
{
Fr s;
LagrangeInterpolation(s, prvVec);
@@ -416,13 +416,13 @@ void PrivateKey::recover(const std::vector<PrivateKey>& prvVec)
id_ = 0;
}
-void PrivateKey::add(const PrivateKey& rhs)
+void SecretKey::add(const SecretKey& rhs)
{
- if (id_ != 0 || rhs.id_ != 0) throw cybozu::Exception("bls:PrivateKey:add:bad id") << id_ << rhs.id_;
+ if (id_ != 0 || rhs.id_ != 0) throw cybozu::Exception("bls:SecretKey:add:bad id") << id_ << rhs.id_;
self_->s += rhs.self_->s;
}
-void getMasterPublicKey(MasterPublicKey& mpk, const MasterPrivateKey& msk)
+void getMasterPublicKey(MasterPublicKey& mpk, const MasterSecretKey& msk)
{
mpk.resize(msk.size());
for (size_t i = 0; i < msk.size(); i++) {
@@ -430,7 +430,7 @@ void getMasterPublicKey(MasterPublicKey& mpk, const MasterPrivateKey& msk)
}
}
-void getPopVec(std::vector<Sign>& popVec, const MasterPrivateKey& msk, const MasterPublicKey& mpk)
+void getPopVec(std::vector<Sign>& popVec, const MasterSecretKey& msk, const MasterPublicKey& mpk)
{
if (msk.size() != mpk.size()) throw cybozu::Exception("bls:getPopVec:bad size") << msk.size() << mpk.size();
const size_t n = msk.size();
diff --git a/test/bls_test.cpp b/test/bls_test.cpp
index 08da1a2..308153a 100644
--- a/test/bls_test.cpp
+++ b/test/bls_test.cpp
@@ -16,7 +16,7 @@ void streamTest(const T& t)
CYBOZU_TEST_AUTO(bls)
{
bls::init();
- bls::PrivateKey prv;
+ bls::SecretKey prv;
prv.init();
streamTest(prv);
bls::PublicKey pub;
@@ -38,7 +38,7 @@ CYBOZU_TEST_AUTO(k_of_n)
const std::string m = "abc";
const int n = 5;
const int k = 3;
- bls::PrivateKey prv0;
+ bls::SecretKey prv0;
prv0.init();
bls::Sign s0;
prv0.sign(s0, m);
@@ -46,10 +46,10 @@ CYBOZU_TEST_AUTO(k_of_n)
prv0.getPublicKey(pub0);
CYBOZU_TEST_ASSERT(s0.verify(pub0, m));
- bls::MasterPrivateKey msk;
- prv0.getMasterPrivateKey(msk, k);
+ bls::MasterSecretKey msk;
+ prv0.getMasterSecretKey(msk, k);
- std::vector<bls::PrivateKey> allPrvVec(n);
+ std::vector<bls::SecretKey> allPrvVec(n);
for (int i = 0; i < n; i++) {
int id = i + 1;
allPrvVec[i].set(msk, id);
@@ -73,14 +73,14 @@ CYBOZU_TEST_AUTO(k_of_n)
3-out-of-n
can recover
*/
- std::vector<bls::PrivateKey> prvVec(3);
+ std::vector<bls::SecretKey> prvVec(3);
for (int a = 0; a < n; a++) {
prvVec[0] = allPrvVec[a];
for (int b = a + 1; b < n; b++) {
prvVec[1] = allPrvVec[b];
for (int c = b + 1; c < n; c++) {
prvVec[2] = allPrvVec[c];
- bls::PrivateKey prv;
+ bls::SecretKey prv;
prv.recover(prvVec);
CYBOZU_TEST_EQUAL(prv, prv0);
}
@@ -90,7 +90,7 @@ CYBOZU_TEST_AUTO(k_of_n)
prvVec[0] = allPrvVec[0];
prvVec[1] = allPrvVec[1];
prvVec[2] = allPrvVec[0]; // same of prvVec[0]
- bls::PrivateKey prv;
+ bls::SecretKey prv;
CYBOZU_TEST_EXCEPTION_MESSAGE(prv.recover(prvVec), std::exception, "same id");
}
{
@@ -98,7 +98,7 @@ CYBOZU_TEST_AUTO(k_of_n)
n-out-of-n
can recover
*/
- bls::PrivateKey prv;
+ bls::SecretKey prv;
prv.recover(allPrvVec);
CYBOZU_TEST_EQUAL(prv, prv0);
}
@@ -111,7 +111,7 @@ CYBOZU_TEST_AUTO(k_of_n)
prvVec[0] = allPrvVec[a];
for (int b = a + 1; b < n; b++) {
prvVec[1] = allPrvVec[b];
- bls::PrivateKey prv;
+ bls::SecretKey prv;
prv.recover(prvVec);
CYBOZU_TEST_ASSERT(prv != prv0);
}
@@ -169,16 +169,16 @@ CYBOZU_TEST_AUTO(k_of_n)
}
}
-CYBOZU_TEST_AUTO(MasterPrivateKey)
+CYBOZU_TEST_AUTO(MasterSecretKey)
{
const int k = 3;
const int n = 6;
- bls::PrivateKey prv0;
+ bls::SecretKey prv0;
prv0.init();
bls::PublicKey pub0;
prv0.getPublicKey(pub0);
- bls::MasterPrivateKey msk;
- prv0.getMasterPrivateKey(msk, k);
+ bls::MasterSecretKey msk;
+ prv0.getMasterSecretKey(msk, k);
bls::MasterPublicKey mpk;
bls::getMasterPublicKey(mpk, msk);
@@ -186,7 +186,7 @@ CYBOZU_TEST_AUTO(MasterPrivateKey)
const int idTbl[n] = {
3, 5, 193, 22, 15
};
- bls::PrivateKeyVec prvVec(n);
+ bls::SecretKeyVec prvVec(n);
bls::PublicKeyVec pubVec(n);
for (int i = 0; i < n; i++) {
int id = idTbl[i];
@@ -200,7 +200,7 @@ CYBOZU_TEST_AUTO(MasterPrivateKey)
CYBOZU_TEST_AUTO(add)
{
- bls::PrivateKey prv1, prv2;
+ bls::SecretKey prv1, prv2;
prv1.init();
prv2.init();
CYBOZU_TEST_ASSERT(prv1 != prv2);