conversion.hpp to include/mcl

dev
MITSUNARI Shigeo 7 years ago
parent 09a998993f
commit 9d2327edd4
  1. 24
      include/mcl/conversion.hpp
  2. 5
      include/mcl/fp.hpp
  3. 6
      include/mcl/op.hpp
  4. 2
      sample/bench.cpp
  5. 19
      src/fp.cpp
  6. 2
      test/base_test.cpp
  7. 2
      test/conversion_test.cpp
  8. 2
      test/fp_util_test.cpp

@ -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

@ -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;

@ -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)) ? "" : " ";

@ -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)) {

@ -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"

@ -1,5 +1,5 @@
#include <cybozu/test.hpp>
#include "../src/conversion.hpp"
#include <mcl/conversion.hpp>
CYBOZU_TEST_AUTO(arrayToDec)
{

@ -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>

Loading…
Cancel
Save