diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-04-23 16:34:18 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-04-23 16:34:18 +0800 |
commit | 728b084e9acfd968e03ef299b97a4f844a730cbd (patch) | |
tree | 506bcd86eedf46d0d04dd2971e9b476d9f4181b7 /src | |
parent | 1ec74e2ea0b4e7c715c6a4c23ae71af262cea4c4 (diff) | |
download | dexon-bls-728b084e9acfd968e03ef299b97a4f844a730cbd.tar dexon-bls-728b084e9acfd968e03ef299b97a4f844a730cbd.tar.gz dexon-bls-728b084e9acfd968e03ef299b97a4f844a730cbd.tar.bz2 dexon-bls-728b084e9acfd968e03ef299b97a4f844a730cbd.tar.lz dexon-bls-728b084e9acfd968e03ef299b97a4f844a730cbd.tar.xz dexon-bls-728b084e9acfd968e03ef299b97a4f844a730cbd.tar.zst dexon-bls-728b084e9acfd968e03ef299b97a4f844a730cbd.zip |
add getCurveOrder/getFieldOrder
Diffstat (limited to 'src')
-rw-r--r-- | src/bls.cpp | 9 | ||||
-rw-r--r-- | src/bls_if.cpp | 37 |
2 files changed, 40 insertions, 6 deletions
diff --git a/src/bls.cpp b/src/bls.cpp index 312cf23..9f94723 100644 --- a/src/bls.cpp +++ b/src/bls.cpp @@ -211,6 +211,15 @@ size_t getOpUnitSize() return Fp::getUnitSize() * sizeof(mcl::fp::Unit) / sizeof(uint64_t); } +void getCurveOrder(std::string& str) +{ + Fr::getModulo(str); +} +void getFieldOrder(std::string& str) +{ + Fp::getModulo(str); +} + Id::Id(unsigned int id) { getInner().v = id; diff --git a/src/bls_if.cpp b/src/bls_if.cpp index 3bab145..7d2d78a 100644 --- a/src/bls_if.cpp +++ b/src/bls_if.cpp @@ -26,6 +26,16 @@ int setStrT(Outer *p, const char *buf, size_t bufSize) return 1; } +size_t checkAndCopy(char *buf, size_t maxBufSize, const std::string& s) +{ + if (s.size() >= maxBufSize) { + return 0; + } + memcpy(buf, s.c_str(), s.size()); + buf[s.size()] = '\0'; + return s.size(); +} + template<class Inner, class Outer> size_t getStrT(const Outer *p, char *buf, size_t maxBufSize) try @@ -33,12 +43,7 @@ size_t getStrT(const Outer *p, char *buf, size_t maxBufSize) std::ostringstream oss; oss << *(const Inner*)p; std::string s = oss.str(); - if (s.size() > maxBufSize) { - fprintf(stderr, "err getStrT size is small %d %d\n", (int)s.size(), (int)maxBufSize); - return 0; - } - memcpy(buf, s.c_str(), s.size()); - return s.size(); + return checkAndCopy(buf, maxBufSize, s); } catch (std::exception&) { return 0; } @@ -79,6 +84,26 @@ size_t blsGetOpUnitSize() return bls::getOpUnitSize(); } +int blsGetCurveOrder(char *buf, size_t maxBufSize) + try +{ + std::string s; + bls::getCurveOrder(s); + return checkAndCopy(buf, maxBufSize, s); +} catch (std::exception&) { + return 0; +} + +int blsGetFieldOrder(char *buf, size_t maxBufSize) + try +{ + std::string s; + bls::getFieldOrder(s); + return checkAndCopy(buf, maxBufSize, s); +} catch (std::exception&) { + return 0; +} + blsId *blsIdCreate() { return createT<bls::Id, blsId>(); |