diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2018-05-19 09:32:27 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2018-05-19 09:32:27 +0800 |
commit | 9d2327edd4c3b03dbfc58e0bd1d1ae3eaa66a260 (patch) | |
tree | ac6961301e1559747a9aeed2f1ea1e0e24ae3c9c | |
parent | 09a998993fbd41643ba552751a9a7fd235c25ded (diff) | |
download | tangerine-mcl-9d2327edd4c3b03dbfc58e0bd1d1ae3eaa66a260.tar.gz tangerine-mcl-9d2327edd4c3b03dbfc58e0bd1d1ae3eaa66a260.tar.zst tangerine-mcl-9d2327edd4c3b03dbfc58e0bd1d1ae3eaa66a260.zip |
conversion.hpp to include/mcl
-rw-r--r-- | include/mcl/conversion.hpp (renamed from src/conversion.hpp) | 24 | ||||
-rw-r--r-- | include/mcl/fp.hpp | 5 | ||||
-rw-r--r-- | include/mcl/op.hpp | 6 | ||||
-rw-r--r-- | sample/bench.cpp | 2 | ||||
-rw-r--r-- | src/fp.cpp | 19 | ||||
-rw-r--r-- | test/base_test.cpp | 2 | ||||
-rw-r--r-- | test/conversion_test.cpp | 2 | ||||
-rw-r--r-- | test/fp_util_test.cpp | 2 |
8 files changed, 30 insertions, 32 deletions
diff --git a/src/conversion.hpp b/include/mcl/conversion.hpp index 3c5a036..e4a4844 100644 --- a/src/conversion.hpp +++ b/include/mcl/conversion.hpp @@ -5,7 +5,7 @@ #include <mcl/util.hpp> /** @file - @brief convertion from T[] to str2, str16 + @brief convertion bin/dec/hex <=> array @author MITSUNARI Shigeo(@herumi) @license modified new BSD license http://opensource.org/licenses/BSD-3-Clause @@ -320,4 +320,24 @@ inline size_t decToArray(UT *_x, size_t maxN, const char *buf, size_t bufSize) return xn / (sizeof(UT) / 4); } -} } // mcp::fp +/* + return retavl is written size if success else 0 + REMARK : the top of string is buf + bufSize - retval +*/ +template<class UT> +size_t arrayToStr(char *buf, size_t bufSize, const UT *x, size_t n, int base, bool withPrefix) +{ + switch (base) { + case 0: + case 10: + return arrayToDec(buf, bufSize, x, n); + case 16: + return arrayToHex(buf, bufSize, x, n, withPrefix); + case 2: + return arrayToBin(buf, bufSize, x, n, withPrefix); + default: + return 0; + } +} + +} } // mcl::fp diff --git a/include/mcl/fp.hpp b/include/mcl/fp.hpp index d05f380..7fb076e 100644 --- a/include/mcl/fp.hpp +++ b/include/mcl/fp.hpp @@ -29,6 +29,7 @@ #include <mcl/op.hpp> #include <mcl/util.hpp> #include <mcl/operator.hpp> +#include <mcl/conversion.hpp> namespace mcl { @@ -305,9 +306,9 @@ public: } fp::Block b; getBlock(b); - // use low 8-bit ioMode for Fp + // use low 8-bit ioMode for (base, withPrefix) char buf[2048]; - size_t len = fp::arrayToStr(buf, sizeof(buf), b.p, b.n, ioMode & 255); + size_t len = mcl::fp::arrayToStr(buf, sizeof(buf), b.p, b.n, ioMode & 31, (ioMode & IoPrefix) != 0); if (len == 0) { *pb = false; return; diff --git a/include/mcl/op.hpp b/include/mcl/op.hpp index ffc679d..dc116e1 100644 --- a/include/mcl/op.hpp +++ b/include/mcl/op.hpp @@ -329,12 +329,6 @@ private: */ size_t strToArray(bool *pIsMinus, Unit *x, size_t xN, const char *buf, size_t bufSize, int ioMode); -/* - return retavl is written size if success else 0 - REMARK : the top of string is buf + bufSize - retval -*/ -size_t arrayToStr(char *buf, size_t bufSize, const Unit *x, size_t n, int ioMode); - inline const char* getIoSeparator(int ioMode) { return (ioMode & (IoArray | IoArrayRaw | IoSerialize)) ? "" : " "; diff --git a/sample/bench.cpp b/sample/bench.cpp index 4e43020..0f865b1 100644 --- a/sample/bench.cpp +++ b/sample/bench.cpp @@ -2,7 +2,7 @@ #include <cybozu/option.hpp> #include <cybozu/xorshift.hpp> #include <mcl/fp.hpp> -#include "../src/conversion.hpp" +#include <mcl/conversion.hpp> #include <mcl/ecparam.hpp> typedef mcl::FpT<> Fp; @@ -6,7 +6,7 @@ #include <cybozu/crypto.hpp> #endif #include <cybozu/endian.hpp> -#include "conversion.hpp" +#include <mcl/conversion.hpp> #ifdef MCL_USE_XBYAK #include "fp_generator.hpp" #endif @@ -575,23 +575,6 @@ bool Op::init(const char *str, size_t maxBitSize, Mode mode, size_t mclMaxBitSiz return true; } -size_t arrayToStr(char *buf, size_t bufSize, const Unit *x, size_t n, int ioMode) -{ - int base = ioMode & ~IoPrefix; - bool withPrefix = (ioMode & IoPrefix) != 0; - switch (base) { - case 0: - case 10: - return mcl::fp::arrayToDec(buf, bufSize, x, n); - case 16: - return mcl::fp::arrayToHex(buf, bufSize, x, n, withPrefix); - case 2: - return mcl::fp::arrayToBin(buf, bufSize, x, n, withPrefix); - default: - return 0; - } -} - void copyUnitToByteAsLE(uint8_t *dst, const Unit *src, size_t byteSize) { while (byteSize >= sizeof(Unit)) { diff --git a/test/base_test.cpp b/test/base_test.cpp index 29a39ee..2733d17 100644 --- a/test/base_test.cpp +++ b/test/base_test.cpp @@ -5,7 +5,7 @@ #include <cybozu/benchmark.hpp> #include <cybozu/xorshift.hpp> #include <cybozu/bit_operation.hpp> -#include "../src/conversion.hpp" +#include <mcl/conversion.hpp> #include <mcl/fp.hpp> #include "../src/fp_generator.hpp" diff --git a/test/conversion_test.cpp b/test/conversion_test.cpp index 41b4203..0f39907 100644 --- a/test/conversion_test.cpp +++ b/test/conversion_test.cpp @@ -1,5 +1,5 @@ #include <cybozu/test.hpp> -#include "../src/conversion.hpp" +#include <mcl/conversion.hpp> CYBOZU_TEST_AUTO(arrayToDec) { diff --git a/test/fp_util_test.cpp b/test/fp_util_test.cpp index c516274..3e77b3b 100644 --- a/test/fp_util_test.cpp +++ b/test/fp_util_test.cpp @@ -1,6 +1,6 @@ #define PUT(x) std::cout << #x "=" << (x) << std::endl -#include "../src/conversion.hpp" #include <cybozu/test.hpp> +#include <mcl/conversion.hpp> #include <mcl/gmp_util.hpp> #include <mcl/fp.hpp> |