aboutsummaryrefslogtreecommitdiffstats
path: root/include/bls
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2018-12-02 20:29:18 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2018-12-02 20:29:18 +0800
commit615453117dd8a77d35ea1afea5ffdabdd41c93b2 (patch)
treebaaf2737bbf7079400c252eb2a934fe99ad70d05 /include/bls
parentb94e7aa9a6e3c38717e99825a1f5b2f6b5d04328 (diff)
downloaddexon-bls-615453117dd8a77d35ea1afea5ffdabdd41c93b2.tar
dexon-bls-615453117dd8a77d35ea1afea5ffdabdd41c93b2.tar.gz
dexon-bls-615453117dd8a77d35ea1afea5ffdabdd41c93b2.tar.bz2
dexon-bls-615453117dd8a77d35ea1afea5ffdabdd41c93b2.tar.lz
dexon-bls-615453117dd8a77d35ea1afea5ffdabdd41c93b2.tar.xz
dexon-bls-615453117dd8a77d35ea1afea5ffdabdd41c93b2.tar.zst
dexon-bls-615453117dd8a77d35ea1afea5ffdabdd41c93b2.zip
BLS_SWAP_G runs well for C++test
Diffstat (limited to 'include/bls')
-rw-r--r--include/bls/bls.hpp44
1 files changed, 35 insertions, 9 deletions
diff --git a/include/bls/bls.hpp b/include/bls/bls.hpp
index b32b7e1..7413345 100644
--- a/include/bls/bls.hpp
+++ b/include/bls/bls.hpp
@@ -250,7 +250,7 @@ public:
*/
void recover(const SecretKeyVec& secVec, const IdVec& idVec)
{
- if (secVec.size() != idVec.size()) throw std::invalid_argument("SecretKey::recover");
+ if (secVec.size() != idVec.size()) throw std::invalid_argument("SecretKey:recover");
recover(secVec.data(), idVec.data(), idVec.size());
}
/*
@@ -300,7 +300,12 @@ public:
if (str != "0") {
// 1 <x.a> <x.b> <y.a> <y.b>
std::string t;
- for (int i = 0; i < 4; i++) {
+#ifdef BLS_SWAP_G
+ const int elemNum = 2;
+#else
+ const int elemNum = 4;
+#endif
+ for (int i = 0; i < elemNum; i++) {
is >> t;
str += ' ';
str += t;
@@ -312,14 +317,22 @@ public:
void getStr(std::string& str, int ioMode = 0) const
{
str.resize(1024);
+#ifdef BLS_SWAP_G
+ size_t n = mclBnG1_getStr(&str[0], str.size(), &self_.v, ioMode);
+#else
size_t n = mclBnG2_getStr(&str[0], str.size(), &self_.v, ioMode);
- if (n == 0) throw std::runtime_error("mclBnG2_getStr");
+#endif
+ if (n == 0) throw std::runtime_error("PublicKey:getStr");
str.resize(n);
}
void setStr(const std::string& str, int ioMode = 0)
{
+#ifdef BLS_SWAP_G
+ int ret = mclBnG1_setStr(&self_.v, str.c_str(), str.size(), ioMode);
+#else
int ret = mclBnG2_setStr(&self_.v, str.c_str(), str.size(), ioMode);
- if (ret != 0) throw std::runtime_error("mclBnG2_setStr");
+#endif
+ if (ret != 0) throw std::runtime_error("PublicKey:setStr");
}
/*
set public for id from mpk
@@ -333,7 +346,7 @@ public:
*/
void recover(const PublicKeyVec& pubVec, const IdVec& idVec)
{
- if (pubVec.size() != idVec.size()) throw std::invalid_argument("PublicKey::recover");
+ if (pubVec.size() != idVec.size()) throw std::invalid_argument("PublicKey:recover");
recover(pubVec.data(), idVec.data(), idVec.size());
}
/*
@@ -382,7 +395,12 @@ public:
if (str != "0") {
// 1 <x> <y>
std::string t;
- for (int i = 0; i < 2; i++) {
+#ifdef BLS_SWAP_G
+ const int elemNum = 4;
+#else
+ const int elemNum = 2;
+#endif
+ for (int i = 0; i < elemNum; i++) {
is >> t;
str += ' ';
str += t;
@@ -394,14 +412,22 @@ public:
void getStr(std::string& str, int ioMode = 0) const
{
str.resize(1024);
+#ifdef BLS_SWAP_G
+ size_t n = mclBnG2_getStr(&str[0], str.size(), &self_.v, ioMode);
+#else
size_t n = mclBnG1_getStr(&str[0], str.size(), &self_.v, ioMode);
- if (n == 0) throw std::runtime_error("mclBnG1_getStr");
+#endif
+ if (n == 0) throw std::runtime_error("Signature:tgetStr");
str.resize(n);
}
void setStr(const std::string& str, int ioMode = 0)
{
+#ifdef BLS_SWAP_G
+ int ret = mclBnG2_setStr(&self_.v, str.c_str(), str.size(), ioMode);
+#else
int ret = mclBnG1_setStr(&self_.v, str.c_str(), str.size(), ioMode);
- if (ret != 0) throw std::runtime_error("mclBnG1_setStr");
+#endif
+ if (ret != 0) throw std::runtime_error("Signature:setStr");
}
bool verify(const PublicKey& pub, const void *m, size_t size) const
{
@@ -437,7 +463,7 @@ public:
*/
void recover(const SignatureVec& sigVec, const IdVec& idVec)
{
- if (sigVec.size() != idVec.size()) throw std::invalid_argument("Signature::recover");
+ if (sigVec.size() != idVec.size()) throw std::invalid_argument("Signature:recover");
recover(sigVec.data(), idVec.data(), idVec.size());
}
/*