remove fromStr16

dev
MITSUNARI Shigeo 7 years ago
parent b5e34ca403
commit 09a998993f
  1. 2
      sample/bench.cpp
  2. 26
      src/conversion.hpp
  3. 9
      test/fp_util_test.cpp

@ -173,7 +173,7 @@ void benchFromStr16()
Fp x;
const size_t N = 64;
mcl::fp::Unit buf[N];
CYBOZU_BENCH("fp:fromStr16", mcl::fp::fromStr16, buf, N, str.c_str(), str.size());
CYBOZU_BENCH("fp:hexToArray", mcl::fp::hexToArray, buf, N, str.c_str(), str.size());
mpz_class y;
CYBOZU_BENCH("gmp:setStr ", mcl::gmp::setStr, y, str, 16);

@ -201,32 +201,6 @@ size_t arrayToBin(char *buf, size_t bufSize, const T *x, size_t n, bool withPref
return totalSize;
}
/*
convert hex string to x[0..xn)
hex string = [0-9a-fA-F]+
*/
template<class T>
void fromStr16(T *x, size_t xn, const char *str, size_t strLen)
{
if (strLen == 0) throw cybozu::Exception("fp:fromStr16:strLen is zero");
const size_t unitLen = sizeof(T) * 2;
const size_t q = strLen / unitLen;
const size_t r = strLen % unitLen;
const size_t requireSize = q + (r ? 1 : 0);
if (xn < requireSize) throw cybozu::Exception("fp:fromStr16:short size") << xn << requireSize;
for (size_t i = 0; i < q; i++) {
bool b;
x[i] = cybozu::hextoi(&b, &str[r + (q - 1 - i) * unitLen], unitLen);
if (!b) throw cybozu::Exception("fp:fromStr16:bad char") << cybozu::exception::makeString(str, strLen);
}
if (r) {
bool b;
x[q] = cybozu::hextoi(&b, str, r);
if (!b) throw cybozu::Exception("fp:fromStr16:bad char") << cybozu::exception::makeString(str, strLen);
}
for (size_t i = requireSize; i < xn; i++) x[i] = 0;
}
/*
convert hex string to x[0..xn)
hex string = [0-9a-fA-F]+

@ -53,7 +53,7 @@ CYBOZU_TEST_AUTO(arrayToBin)
}
// CYBOZU_TEST_AUTO(verifyStr) // QQQ
CYBOZU_TEST_AUTO(fromStr16)
CYBOZU_TEST_AUTO(hexToArray)
{
const struct {
const char *str;
@ -71,10 +71,9 @@ CYBOZU_TEST_AUTO(fromStr16)
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
const size_t xN = 4;
uint64_t x[xN];
mcl::fp::fromStr16(x, xN, tbl[i].str, strlen(tbl[i].str));
for (size_t j = 0; j < xN; j++) {
CYBOZU_TEST_EQUAL(x[j], tbl[i].x[j]);
}
size_t n = mcl::fp::hexToArray(x, xN, tbl[i].str, strlen(tbl[i].str));
CYBOZU_TEST_ASSERT(n > 0);
CYBOZU_TEST_EQUAL_ARRAY(x, tbl[i].x, n);
}
}

Loading…
Cancel
Save