aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2016-08-30 11:51:53 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2016-08-30 11:51:53 +0800
commitd50143e7909559f745f33090d429b3105af0ee4d (patch)
tree5b197ff2d54e4a3fe2ac26c8d2407f7e41b5cb14
parent85ccb843bd20ca11c8bb0f3582e420698acc04ee (diff)
downloaddexon-bls-d50143e7909559f745f33090d429b3105af0ee4d.tar
dexon-bls-d50143e7909559f745f33090d429b3105af0ee4d.tar.gz
dexon-bls-d50143e7909559f745f33090d429b3105af0ee4d.tar.bz2
dexon-bls-d50143e7909559f745f33090d429b3105af0ee4d.tar.lz
dexon-bls-d50143e7909559f745f33090d429b3105af0ee4d.tar.xz
dexon-bls-d50143e7909559f745f33090d429b3105af0ee4d.tar.zst
dexon-bls-d50143e7909559f745f33090d429b3105af0ee4d.zip
change id to public menmber and remove id from io
-rw-r--r--include/bls.hpp9
-rw-r--r--sample/bls_smpl.cpp9
-rw-r--r--src/bls.cpp61
-rw-r--r--test/bls_test.cpp6
4 files changed, 41 insertions, 44 deletions
diff --git a/include/bls.hpp b/include/bls.hpp
index 57ae73e..1d33777 100644
--- a/include/bls.hpp
+++ b/include/bls.hpp
@@ -81,19 +81,18 @@ public:
*/
class SecretKey {
impl::SecretKey *self_;
- Id 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:
+ Id id; // master if id = 0, shared if id > 0
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); }
- const Id& getId() const { return id_; }
friend std::ostream& operator<<(std::ostream& os, const SecretKey& sec);
friend std::istream& operator>>(std::istream& is, SecretKey& sec);
/*
@@ -135,7 +134,6 @@ public:
*/
class PublicKey {
impl::PublicKey *self_;
- Id id_;
friend class SecretKey;
friend class Sign;
template<class G, class T>
@@ -143,13 +141,13 @@ class PublicKey {
template<class T, class G>
friend struct Wrap;
public:
+ Id id;
PublicKey();
~PublicKey();
PublicKey(const PublicKey& rhs);
PublicKey& operator=(const PublicKey& rhs);
bool operator==(const PublicKey& rhs) const;
bool operator!=(const PublicKey& rhs) const { return !(*this == rhs); }
- const Id& 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;
@@ -172,19 +170,18 @@ public:
*/
class Sign {
impl::Sign *self_;
- Id id_;
friend class PublicKey;
friend class SecretKey;
template<class G, class T>
friend void LagrangeInterpolation(G& r, const T& vec);
public:
+ Id id;
Sign();
~Sign();
Sign(const Sign& rhs);
Sign& operator=(const Sign& rhs);
bool operator==(const Sign& rhs) const;
bool operator!=(const Sign& rhs) const { return !(*this == rhs); }
- const Id& 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;
diff --git a/sample/bls_smpl.cpp b/sample/bls_smpl.cpp
index 28d2c04..85530dd 100644
--- a/sample/bls_smpl.cpp
+++ b/sample/bls_smpl.cpp
@@ -14,7 +14,7 @@ std::string makeName(const std::string& name, const bls::Id& id)
const std::string suf = ".txt";
if (id.isZero()) return name + suf;
std::ostringstream os;
- os << name << id << suf;
+ os << name << '.' << id << suf;
return os.str();
}
@@ -23,7 +23,7 @@ void save(const std::string& file, const T& t, const bls::Id& id = 0)
{
const std::string name = makeName(file, id);
std::ofstream ofs(name.c_str(), std::ios::binary);
- if (!(ofs << t)) {
+ if (!(ofs << std::hex << t)) {
throw cybozu::Exception("can't save") << name;
}
}
@@ -33,9 +33,10 @@ void load(T& t, const std::string& file, const bls::Id& id = 0)
{
const std::string name = makeName(file, id);
std::ifstream ifs(name.c_str(), std::ios::binary);
- if (!(ifs >> t)) {
+ if (!(ifs >> std::hex >> t)) {
throw cybozu::Exception("can't load") << name;
}
+ t.id = id;
}
int init()
@@ -89,7 +90,7 @@ int share(int n, int k)
secVec[i].set(msk, i + 1);
}
for (int i = 0; i < n; i++) {
- const bls::Id& id = secVec[i].getId();
+ const bls::Id& id = secVec[i].id;
save(secFile, secVec[i], id);
bls::PublicKey pub;
secVec[i].getPublicKey(pub);
diff --git a/src/bls.cpp b/src/bls.cpp
index 30241e8..b6d12f9 100644
--- a/src/bls.cpp
+++ b/src/bls.cpp
@@ -40,7 +40,7 @@ void init()
G1::setCompressedExpression();
G2::setCompressedExpression();
Fr::init(BN::param.r);
- mcl::setIoMode(mcl::IoHeximal);
+// mcl::setIoMode(mcl::IoHeximal);
}
static const G2& getQ()
@@ -137,7 +137,7 @@ void LagrangeInterpolation(G& r, const T& vec)
{
FrVec S(vec.size());
for (size_t i = 0; i < vec.size(); i++) {
- S[i] = vec[i].getId().self_->v;
+ S[i] = vec[i].id.self_->v;
}
FrVec delta;
calcDelta(delta, S);
@@ -255,7 +255,7 @@ void Id::set(const uint64_t *p)
Sign::Sign()
: self_(new impl::Sign())
- , id_(0)
+ , id(0)
{
}
@@ -266,30 +266,30 @@ Sign::~Sign()
Sign::Sign(const Sign& rhs)
: self_(new impl::Sign(*rhs.self_))
- , id_(rhs.id_)
+ , id(rhs.id)
{
}
Sign& Sign::operator=(const Sign& rhs)
{
*self_ = *rhs.self_;
- id_ = rhs.id_;
+ id = rhs.id;
return *this;
}
bool Sign::operator==(const Sign& rhs) const
{
- return id_ == rhs.id_ && self_->sHm == rhs.self_->sHm;
+ return id == rhs.id && self_->sHm == rhs.self_->sHm;
}
std::ostream& operator<<(std::ostream& os, const Sign& s)
{
- return os << s.id_ << ' ' << s.self_->sHm;
+ return os << s.self_->sHm;
}
std::istream& operator>>(std::istream& os, Sign& s)
{
- return os >> s.id_ >> s.self_->sHm;
+ return os >> s.self_->sHm;
}
bool Sign::verify(const PublicKey& pub, const std::string& m) const
@@ -307,18 +307,18 @@ void Sign::recover(const SignVec& signVec)
G1 sHm;
LagrangeInterpolation(sHm, signVec);
self_->sHm = sHm;
- id_ = 0;
+ id = 0;
}
void Sign::add(const Sign& rhs)
{
- if (!id_.isZero() || !rhs.id_.isZero()) throw cybozu::Exception("bls:Sign:add:bad id") << id_ << rhs.id_;
+ if (!id.isZero() || !rhs.id.isZero()) throw cybozu::Exception("bls:Sign:add:bad id") << id << rhs.id;
self_->sHm += rhs.self_->sHm;
}
PublicKey::PublicKey()
: self_(new impl::PublicKey())
- , id_(0)
+ , id(0)
{
}
@@ -329,30 +329,30 @@ PublicKey::~PublicKey()
PublicKey::PublicKey(const PublicKey& rhs)
: self_(new impl::PublicKey(*rhs.self_))
- , id_(rhs.id_)
+ , id(rhs.id)
{
}
PublicKey& PublicKey::operator=(const PublicKey& rhs)
{
*self_ = *rhs.self_;
- id_ = rhs.id_;
+ id = rhs.id;
return *this;
}
bool PublicKey::operator==(const PublicKey& rhs) const
{
- return id_ == rhs.id_ && self_->sQ == rhs.self_->sQ;
+ return id == rhs.id && self_->sQ == rhs.self_->sQ;
}
std::ostream& operator<<(std::ostream& os, const PublicKey& pub)
{
- return os << pub.id_ << ' ' << pub.self_->sQ;
+ return os << pub.self_->sQ;
}
std::istream& operator>>(std::istream& is, PublicKey& pub)
{
- return is >> pub.id_ >> pub.self_->sQ;
+ return is >> pub.self_->sQ;
}
void PublicKey::getStr(std::string& str) const
@@ -366,7 +366,7 @@ void PublicKey::set(const PublicKeyVec& mpk, const Id& id)
{
Wrap<PublicKey, G2> w(mpk);
evalPoly(self_->sQ,id.self_->v, w);
- id_ = id;
+ this->id = id;
}
void PublicKey::recover(const PublicKeyVec& pubVec)
@@ -374,18 +374,18 @@ void PublicKey::recover(const PublicKeyVec& pubVec)
G2 sQ;
LagrangeInterpolation(sQ, pubVec);
self_->sQ = sQ;
- id_ = 0;
+ id = 0;
}
void PublicKey::add(const PublicKey& rhs)
{
- if (!id_.isZero() || !rhs.id_.isZero()) throw cybozu::Exception("bls:PublicKey:add:bad id") << id_ << rhs.id_;
+ if (!id.isZero() || !rhs.id.isZero()) throw cybozu::Exception("bls:PublicKey:add:bad id") << id << rhs.id;
self_->sQ += rhs.self_->sQ;
}
SecretKey::SecretKey()
: self_(new impl::SecretKey())
- , id_(0)
+ , id(0)
{
}
@@ -396,30 +396,30 @@ SecretKey::~SecretKey()
SecretKey::SecretKey(const SecretKey& rhs)
: self_(new impl::SecretKey(*rhs.self_))
- , id_(rhs.id_)
+ , id(rhs.id)
{
}
SecretKey& SecretKey::operator=(const SecretKey& rhs)
{
*self_ = *rhs.self_;
- id_ = rhs.id_;
+ id = rhs.id;
return *this;
}
bool SecretKey::operator==(const SecretKey& rhs) const
{
- return id_ == rhs.id_ && self_->s == rhs.self_->s;
+ return id == rhs.id && self_->s == rhs.self_->s;
}
std::ostream& operator<<(std::ostream& os, const SecretKey& sec)
{
- return os << sec.id_ << ' ' << sec.self_->s;
+ return os << sec.self_->s;
}
std::istream& operator>>(std::istream& is, SecretKey& sec)
{
- return is >> sec.id_ >> sec.self_->s;
+ return is >> sec.self_->s;
}
void SecretKey::init()
@@ -435,13 +435,13 @@ void SecretKey::set(const uint64_t *p)
void SecretKey::getPublicKey(PublicKey& pub) const
{
self_->getPublicKey(*pub.self_);
- pub.id_ = id_;
+ pub.id = id;
}
void SecretKey::sign(Sign& sign, const std::string& m) const
{
self_->sign(*sign.self_, m);
- sign.id_ = id_;
+ sign.id = id;
}
void SecretKey::getPop(Sign& pop) const
@@ -467,7 +467,7 @@ void SecretKey::set(const SecretKeyVec& msk, const Id& id)
{
Wrap<SecretKey, Fr> w(msk);
evalPoly(self_->s, id.self_->v, w);
- id_ = id;
+ this->id = id;
}
void SecretKey::recover(const SecretKeyVec& secVec)
@@ -475,14 +475,13 @@ void SecretKey::recover(const SecretKeyVec& secVec)
Fr s;
LagrangeInterpolation(s, secVec);
self_->s = s;
- id_ = 0;
+ id = 0;
}
void SecretKey::add(const SecretKey& rhs)
{
- if (!id_.isZero() || !rhs.id_.isZero()) throw cybozu::Exception("bls:SecretKey:add:bad id") << id_ << rhs.id_;
+ if (!id.isZero() || !rhs.id.isZero()) throw cybozu::Exception("bls:SecretKey: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 cfd655c..186cb5c 100644
--- a/test/bls_test.cpp
+++ b/test/bls_test.cpp
@@ -7,10 +7,10 @@ template<class T>
void streamTest(const T& t)
{
std::ostringstream oss;
- oss << t;
+ oss << t.id << ' ' << t;
std::istringstream iss(oss.str());
T t2;
- iss >> t2;
+ iss >> t2.id >> t2;
CYBOZU_TEST_EQUAL(t, t2);
}
@@ -79,7 +79,7 @@ CYBOZU_TEST_AUTO(k_of_n)
}
CYBOZU_TEST_EQUAL(allPrvVec.size(), n);
for (int i = 0; i < n; i++) {
- CYBOZU_TEST_EQUAL(allPrvVec[i].getId(), i + 1);
+ CYBOZU_TEST_EQUAL(allPrvVec[i].id, i + 1);
}
std::vector<bls::Sign> allSignVec(n);