aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-04-09 12:46:11 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-04-09 12:46:11 +0800
commitf299770465daefdb309c72845f41c9c078ba6d49 (patch)
tree6cff3d051058ab9721966f58183e0220ba500539
parent3691dc9dfffad8b3985c00a082af9ae8146fb8d5 (diff)
downloaddexon-bls-f299770465daefdb309c72845f41c9c078ba6d49.tar
dexon-bls-f299770465daefdb309c72845f41c9c078ba6d49.tar.gz
dexon-bls-f299770465daefdb309c72845f41c9c078ba6d49.tar.bz2
dexon-bls-f299770465daefdb309c72845f41c9c078ba6d49.tar.lz
dexon-bls-f299770465daefdb309c72845f41c9c078ba6d49.tar.xz
dexon-bls-f299770465daefdb309c72845f41c9c078ba6d49.tar.zst
dexon-bls-f299770465daefdb309c72845f41c9c078ba6d49.zip
add getData() and setData()
-rw-r--r--include/bls.hpp20
-rw-r--r--src/bls.cpp32
-rw-r--r--test/bls_test.cpp45
3 files changed, 97 insertions, 0 deletions
diff --git a/include/bls.hpp b/include/bls.hpp
index 7b2a673..c4f4769 100644
--- a/include/bls.hpp
+++ b/include/bls.hpp
@@ -86,6 +86,11 @@ public:
bool operator!=(const Id& rhs) const { return !(*this == rhs); }
friend std::ostream& operator<<(std::ostream& os, const Id& id);
friend std::istream& operator>>(std::istream& is, Id& id);
+ /*
+ get tight repl
+ */
+ void getData(std::string& str) const;
+ void setData(const std::string& str);
bool isZero() const;
/*
set p[0, .., keySize)
@@ -110,6 +115,11 @@ public:
friend std::ostream& operator<<(std::ostream& os, const SecretKey& sec);
friend std::istream& operator>>(std::istream& is, SecretKey& sec);
/*
+ get tight repl
+ */
+ void getData(std::string& str) const;
+ void setData(const std::string& str);
+ /*
initialize secretKey with random number and set id = 0
*/
void init();
@@ -171,6 +181,11 @@ public:
friend std::ostream& operator<<(std::ostream& os, const PublicKey& pub);
friend std::istream& operator>>(std::istream& is, PublicKey& pub);
/*
+ get tight repl
+ */
+ void getData(std::string& str) const;
+ void setData(const std::string& str);
+ /*
set public for id from mpk
*/
void set(const PublicKeyVec& mpk, const Id& id)
@@ -206,6 +221,11 @@ public:
bool operator!=(const Sign& rhs) const { return !(*this == rhs); }
friend std::ostream& operator<<(std::ostream& os, const Sign& s);
friend std::istream& operator>>(std::istream& is, Sign& s);
+ /*
+ get tight repl
+ */
+ void getData(std::string& str) const;
+ void setData(const std::string& str);
bool verify(const PublicKey& pub, const std::string& m) const;
/*
verify self(pop) with pub
diff --git a/src/bls.cpp b/src/bls.cpp
index 64cd40c..312cf23 100644
--- a/src/bls.cpp
+++ b/src/bls.cpp
@@ -230,6 +230,14 @@ std::istream& operator>>(std::istream& is, Id& id)
{
return is >> id.getInner().v;
}
+void Id::getData(std::string& str) const
+{
+ getInner().v.getStr(str, mcl::IoTight);
+}
+void Id::setData(const std::string& str)
+{
+ getInner().v.setStr(str, mcl::IoTight);
+}
bool Id::isZero() const
{
@@ -255,6 +263,14 @@ std::istream& operator>>(std::istream& os, Sign& s)
{
return os >> s.getInner().sHm;
}
+void Sign::getData(std::string& str) const
+{
+ getInner().sHm.getStr(str, mcl::IoTight);
+}
+void Sign::setData(const std::string& str)
+{
+ getInner().sHm.setStr(str, mcl::IoTight);
+}
bool Sign::verify(const PublicKey& pub, const std::string& m) const
{
@@ -322,6 +338,14 @@ std::istream& operator>>(std::istream& is, PublicKey& pub)
return is >> pub.getInner().sQ;
}
+void PublicKey::getData(std::string& str) const
+{
+ getInner().sQ.getStr(str, mcl::IoTight);
+}
+void PublicKey::setData(const std::string& str)
+{
+ getInner().sQ.setStr(str, mcl::IoTight);
+}
void PublicKey::set(const PublicKey *mpk, size_t k, const Id& id)
{
WrapArray<PublicKey, G2> w(mpk, k);
@@ -359,6 +383,14 @@ std::istream& operator>>(std::istream& is, SecretKey& sec)
{
return is >> sec.getInner().s;
}
+void SecretKey::getData(std::string& str) const
+{
+ getInner().s.getStr(str, mcl::IoTight);
+}
+void SecretKey::setData(const std::string& str)
+{
+ getInner().s.setStr(str, mcl::IoTight);
+}
void SecretKey::init()
{
diff --git a/test/bls_test.cpp b/test/bls_test.cpp
index 345bbcd..69d246f 100644
--- a/test/bls_test.cpp
+++ b/test/bls_test.cpp
@@ -344,12 +344,57 @@ void addTest()
CYBOZU_TEST_ASSERT((s1 + s2).verify(pub1 + pub2, m));
}
+void dataTest()
+{
+ const size_t size = bls::getOpUnitSize() * sizeof(uint64_t);
+ bls::SecretKey sec;
+ sec.init();
+ std::string str;
+ sec.getData(str);
+ {
+ CYBOZU_TEST_EQUAL(str.size(), size);
+ bls::SecretKey sec2;
+ sec2.setData(str);
+ CYBOZU_TEST_EQUAL(sec, sec2);
+ }
+ bls::PublicKey pub;
+ sec.getPublicKey(pub);
+ pub.getData(str);
+ {
+ CYBOZU_TEST_EQUAL(str.size(), size * 2);
+ bls::PublicKey pub2;
+ pub2.setData(str);
+ CYBOZU_TEST_EQUAL(pub, pub2);
+ }
+ std::string m = "abc";
+ bls::Sign sign;
+ sec.sign(sign, m);
+ sign.getData(str);
+ {
+ CYBOZU_TEST_EQUAL(str.size(), size);
+ bls::Sign sign2;
+ sign2.setData(str);
+ CYBOZU_TEST_EQUAL(sign, sign2);
+ }
+ bls::Id id;
+ const uint64_t v[] = { 1, 2, 3, 4, 5, 6, };
+ id.set(v);
+ id.getData(str);
+ {
+ CYBOZU_TEST_EQUAL(str.size(), size);
+ bls::Id id2;
+ id2.setData(str);
+ CYBOZU_TEST_EQUAL(id, id2);
+ }
+}
+
void testAll()
{
blsTest();
k_of_nTest();
popTest();
addTest();
+ dataTest();
}
CYBOZU_TEST_AUTO(all)
{