change method name

dev
MITSUNARI Shigeo 10 years ago
parent a0f4c41f03
commit 434afb6654
  1. 12
      include/mcl/ec.hpp
  2. 47
      include/mcl/fp.hpp
  3. 12
      include/mcl/gmp_util.hpp
  4. 2
      include/mcl/op.hpp
  5. 4
      include/mcl/operator.hpp
  6. 2
      sample/random_smpl.cpp
  7. 8
      src/fp.cpp
  8. 2
      test/base_test.cpp
  9. 26
      test/fp_generator_test.cpp
  10. 38
      test/fp_test.cpp
  11. 94
      test/mont_fp_test.cpp

@ -81,8 +81,8 @@ public:
static inline void setParam(const std::string& astr, const std::string& bstr)
{
a_.fromStr(astr);
b_.fromStr(bstr);
a_.setStr(astr);
b_.setStr(bstr);
if (a_.isZero()) {
specialA_ = zero;
} else if (a_ == -3) {
@ -403,11 +403,11 @@ public:
return os << '0';
} else {
self.normalize();
os << self.x.toStr(16) << '_';
os << self.x.getStr(16) << '_';
if (compressedExpression_) {
return os << Fp::isOdd(self.y);
} else {
return os << self.y.toStr(16);
return os << self.y.getStr(16);
}
}
}
@ -426,7 +426,7 @@ public:
size_t pos = str.find('_');
if (pos == std::string::npos) throw cybozu::Exception("EcT:operator>>:bad format") << str;
str[pos] = '\0';
self.x.fromStr(&str[0], 16);
self.x.setStr(&str[0], 16);
if (compressedExpression_) {
const char c = str[pos + 1];
if ((c == '0' || c == '1') && str.size() == pos + 2) {
@ -436,7 +436,7 @@ public:
throw cybozu::Exception("EcT:operator>>:bad y") << str;
}
} else {
self.y.fromStr(&str[pos + 1], 16);
self.y.setStr(&str[pos + 1], 16);
}
}
return is;

@ -70,7 +70,7 @@ public:
}
static inline void getModulo(std::string& pstr)
{
Gmp::toStr(pstr, op_.mp);
Gmp::getStr(pstr, op_.mp);
}
static inline bool isOdd(const FpT& x)
{
@ -81,10 +81,10 @@ public:
static inline bool squareRoot(FpT& y, const FpT& x)
{
mpz_class mx, my;
x.toGmp(mx);
x.getGmp(mx);
bool b = op_.sq.get(my, mx);
if (!b) return false;
y.fromGmp(my);
y.setGmp(my);
return true;
}
FpT() {}
@ -104,7 +104,7 @@ public:
FpT(int64_t x) { operator=(x); }
explicit FpT(const std::string& str, int base = 0)
{
fromStr(str, base);
setStr(str, base);
}
FpT& operator=(int64_t x)
{
@ -130,38 +130,37 @@ public:
{
if (op_.useMont) op_.fromMont(y.v_, x.v_);
}
void fromStr(const std::string& str, int base = 0)
void setStr(const std::string& str, int base = 0)
{
bool isMinus;
mpz_class x;
fp::strToGmp(x, &isMinus, str, base);
if (x >= op_.mp) throw cybozu::Exception("fp:FpT:fromStr:large str") << str << op_.mp;
if (x >= op_.mp) throw cybozu::Exception("FpT:setStr:large str") << str << op_.mp;
fp::toArray(v_, op_.N, x.get_mpz_t());
if (isMinus) {
neg(*this, *this);
}
toMont(*this, *this);
}
// alias of fromStr
void set(const std::string& str, int base = 0) { fromStr(str, base); }
// alias of setStr
template<class S>
void setRaw(const S *inBuf, size_t n)
void setArray(const S *inBuf, size_t n)
{
const size_t byteN = sizeof(S) * n;
const size_t fpByteN = sizeof(Unit) * op_.N;
if (byteN > fpByteN) throw cybozu::Exception("setRaw:bad n") << n << fpByteN;
if (byteN > fpByteN) throw cybozu::Exception("FpT:setArray:bad n") << n << fpByteN;
assert(byteN <= fpByteN);
memcpy(v_, inBuf, byteN);
memset((char *)v_ + byteN, 0, fpByteN - byteN);
if (!isValid()) throw cybozu::Exception("setRaw:large value");
if (!isValid()) throw cybozu::Exception("FpT:setArray:large value");
toMont(*this, *this);
}
template<class S>
size_t getRaw(S *outBuf, size_t n) const
size_t getArray(S *outBuf, size_t n) const
{
const size_t byteN = sizeof(S) * n;
const size_t fpByteN = sizeof(Unit) * op_.N;
if (byteN < fpByteN) throw cybozu::Exception("getRaw:bad n") << n << fpByteN;
if (byteN < fpByteN) throw cybozu::Exception("FpT:getArray:bad n") << n << fpByteN;
assert(byteN >= fpByteN);
fp::Block b;
getBlock(b);
@ -186,33 +185,33 @@ public:
fp::getRandVal(v_, rg, op_.p, op_.bitLen);
fromMont(*this, *this);
}
void toStr(std::string& str, int base = 10, bool withPrefix = false) const
void getStr(std::string& str, int base = 10, bool withPrefix = false) const
{
fp::Block b;
getBlock(b);
fp::arrayToStr(str, b.p, b.n, base, withPrefix);
}
std::string toStr(int base = 10, bool withPrefix = false) const
std::string getStr(int base = 10, bool withPrefix = false) const
{
std::string str;
toStr(str, base, withPrefix);
getStr(str, base, withPrefix);
return str;
}
void toGmp(mpz_class& x) const
void getGmp(mpz_class& x) const
{
fp::Block b;
getBlock(b);
Gmp::setRaw(x, b.p, b.n);
Gmp::setArray(x, b.p, b.n);
}
mpz_class toGmp() const
mpz_class getGmp() const
{
mpz_class x;
toGmp(x);
getGmp(x);
return x;
}
void fromGmp(const mpz_class& x)
void setGmp(const mpz_class& x)
{
setRaw(Gmp::getBlock(x), Gmp::getBlockSize(x));
setArray(Gmp::getBlock(x), Gmp::getBlockSize(x));
}
static inline void add(FpT& z, const FpT& x, const FpT& y) { op_.add(z.v_, x.v_, y.v_); }
static inline void sub(FpT& z, const FpT& x, const FpT& y) { op_.sub(z.v_, x.v_, y.v_); }
@ -293,7 +292,7 @@ public:
const int base = (f & std::ios_base::hex) ? 16 : 10;
const bool showBase = (f & std::ios_base::showbase) != 0;
std::string str;
self.toStr(str, base, showBase);
self.getStr(str, base, showBase);
return os << str;
}
friend inline std::istream& operator>>(std::istream& is, FpT& self)
@ -303,7 +302,7 @@ public:
const int base = (f & std::ios_base::hex) ? 16 : 0;
std::string str;
is >> str;
self.fromStr(str, base);
self.setStr(str, base);
return is;
}
/*

@ -65,7 +65,7 @@ struct Gmp {
// z = [buf[n-1]:..:buf[1]:buf[0]]
// eg. buf[] = {0x12345678, 0xaabbccdd}; => z = 0xaabbccdd12345678;
template<class T>
static void setRaw(mpz_class& z, const T *buf, size_t n)
static void setArray(mpz_class& z, const T *buf, size_t n)
{
mpz_import(z.get_mpz_t(), n, -1, sizeof(*buf), 0, 0, buf);
}
@ -74,7 +74,7 @@ struct Gmp {
return 0 if failure
*/
template<class T>
static size_t getRaw(T *buf, size_t maxSize, const mpz_class& x)
static size_t getArray(T *buf, size_t maxSize, const mpz_class& x)
{
const size_t totalSize = sizeof(T) * maxSize;
if (getBitLen(x) > totalSize * 8) return 0;
@ -86,13 +86,13 @@ struct Gmp {
}
static inline void set(mpz_class& z, uint64_t x)
{
setRaw(z, &x, 1);
setArray(z, &x, 1);
}
static inline bool fromStr(mpz_class& z, const std::string& str, int base = 0)
static inline bool setStr(mpz_class& z, const std::string& str, int base = 0)
{
return z.set_str(str, base) == 0;
}
static inline void toStr(std::string& str, const mpz_class& z, int base = 10)
static inline void getStr(std::string& str, const mpz_class& z, int base = 10)
{
str = z.get_str(base);
}
@ -277,7 +277,7 @@ struct Gmp {
v |= 1U << (rem - 1);
}
buf[n - 1] = v;
Gmp::setRaw(z, &buf[0], n);
Gmp::setArray(z, &buf[0], n);
}
template<class RG>
static void getRandPrime(mpz_class& z, size_t bitLen, RG& rg, bool setSecondBit = false, bool mustBe3mod4 = false)

@ -75,7 +75,7 @@ struct Op {
void3u modP;
FpGenerator *fg;
Op()
: p(), N(0), bitLen(0)
: N(0), bitLen(0)
, isZero(0), clear(0), copy(0)
, neg(0), add(0), sub(0), mul(0)
, useMont(false), preInv(0)

@ -86,7 +86,7 @@ struct hasIO : E {
const int base = (f & std::ios_base::hex) ? 16 : 10;
const bool showBase = (f & std::ios_base::showbase) != 0;
std::string str;
self.toStr(str, base, showBase);
self.getStr(str, base, showBase);
return os << str;
}
friend inline std::istream& operator>>(std::istream& is, T& self)
@ -96,7 +96,7 @@ struct hasIO : E {
const int base = (f & std::ios_base::hex) ? 16 : 0;
std::string str;
is >> str;
self.fromStr(str, base);
self.setStr(str, base);
return is;
}
};

@ -21,7 +21,7 @@ int main(int argc, char *argv[])
Map m;
for (int i = 0; i < 10000; i++) {
x.setRand(rg);
m[x.toStr(16)]++;
m[x.getStr(16)]++;
}
for (Map::const_iterator i = m.begin(), ie = m.end(); i != ie; ++i) {
printf("%s %d\n", i->first.c_str(), i->second);

@ -59,7 +59,7 @@ inline const char *verifyStr(bool *isMinus, int *base, const std::string& str)
void strToGmp(mpz_class& x, bool *isMinus, const std::string& str, int base)
{
const char *p = fp::verifyStr(isMinus, &base, str);
if (!Gmp::fromStr(x, p, base)) {
if (!Gmp::setStr(x, p, base)) {
throw cybozu::Exception("fp:FpT:inFromStr") << str;
}
}
@ -250,7 +250,7 @@ void Op::init(const std::string& mstr, int base, size_t maxBitN)
if (isMinus) throw cybozu::Exception("Op:init:mstr is minus") << mstr;
bitLen = Gmp::getBitLen(mp);
if (bitLen > maxBitN) throw cybozu::Exception("Op:init:too large bitLen") << mstr << bitLen << maxBitN;
const size_t n = Gmp::getRaw(p, maxN, mp);
const size_t n = Gmp::getArray(p, maxN, mp);
if (n == 0) throw cybozu::Exception("Op:init:bad mstr") << mstr;
if (bitLen <= 128) {
@ -302,8 +302,8 @@ void arrayToStr(std::string& str, const Unit *x, size_t n, int base, bool withPr
case 10:
{
mpz_class t;
Gmp::setRaw(t, x, n);
Gmp::toStr(str, t, 10);
Gmp::setArray(t, x, n);
Gmp::getStr(str, t, 10);
}
return;
case 16:

@ -25,7 +25,7 @@ size_t getUnitN(size_t bitLen)
void setMpz(mpz_class& mx, const Unit *x, size_t n)
{
mcl::Gmp::setRaw(mx, x, n);
mcl::Gmp::setArray(mx, x, n);
}
void getMpz(Unit *x, size_t n, const mpz_class& mx)
{

@ -62,20 +62,20 @@ struct Int {
}
this->vn = vn;
}
void set(const char *str) { fromStr(str); }
void set(const char *str) { setStr(str); }
void set(const Fp& rhs)
{
convertToArray(v, rhs.toGmp());
convertToArray(v, rhs.getGmp());
}
void set(const uint64_t* x)
{
for (int i = 0; i < vn; i++) v[i] = x[i];
}
void fromStr(const char *str)
void setStr(const char *str)
{
convertToArray(v, str);
}
std::string toStr() const
std::string getStr() const
{
std::string ret;
for (int i = 0; i < vn; i++) {
@ -86,7 +86,7 @@ struct Int {
void put(const char *msg = "") const
{
if (msg) printf("%s=", msg);
printf("%s\n", toStr().c_str());
printf("%s\n", getStr().c_str());
}
bool operator==(const Int& rhs) const
{
@ -107,15 +107,15 @@ struct Int {
};
static inline std::ostream& operator<<(std::ostream& os, const Int& x)
{
return os << x.toStr();
return os << x.getStr();
}
void testAddSub(const mcl::fp::FpGenerator& fg, int pn)
{
Fp x, y;
Int mx(pn), my(pn);
x.fromStr("0x8811aabb23427cc");
y.fromStr("0x8811aabb23427cc11");
x.setStr("0x8811aabb23427cc");
y.setStr("0x8811aabb23427cc11");
mx.set(x);
my.set(y);
for (int i = 0; i < 30; i++) {
@ -146,7 +146,7 @@ void testNeg(const mcl::fp::FpGenerator& fg, int pn)
"0x0abbccddeeffaabb0000000000000000",
};
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
x.fromStr(tbl[i]);
x.setStr(tbl[i]);
mx.set(x);
x = -x;
fg.neg_(mx.v, mx.v);
@ -163,13 +163,13 @@ void testMulI(const mcl::fp::FpGenerator& fg, int pn)
rg.read(x, pn);
uint64_t y = rg.get64();
mpz_class mx;
mcl::Gmp::setRaw(mx, x, pn);
mcl::Gmp::setArray(mx, x, pn);
mpz_class my;
mcl::Gmp::set(my, y);
mx *= my;
uint64_t d = fg.mulI_(z, x, y);
z[pn] = d;
mcl::Gmp::setRaw(my, z, pn + 1);
mcl::Gmp::setArray(my, z, pn + 1);
CYBOZU_TEST_EQUAL(mx, my);
}
{
@ -189,11 +189,11 @@ void testShr1(const mcl::fp::FpGenerator& fg, int pn)
uint64_t z[MAX_N];
rg.read(x, pn);
mpz_class mx;
mcl::Gmp::setRaw(mx, x, pn);
mcl::Gmp::setArray(mx, x, pn);
mx >>= 1;
fg.shr1_(z, x);
mpz_class my;
mcl::Gmp::setRaw(my, z, pn);
mcl::Gmp::setArray(my, z, pn);
CYBOZU_TEST_EQUAL(mx, my);
}
}

@ -66,12 +66,12 @@ CYBOZU_TEST_AUTO(cstr)
os << tbl[i].val;
std::string str;
x.toStr(str);
x.getStr(str);
CYBOZU_TEST_EQUAL(str, os.str());
}
}
CYBOZU_TEST_AUTO(fromStr)
CYBOZU_TEST_AUTO(setStr)
{
const struct {
const char *in;
@ -88,13 +88,13 @@ CYBOZU_TEST_AUTO(fromStr)
};
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
Fp x;
x.fromStr(tbl[i].in, tbl[i].base);
x.setStr(tbl[i].in, tbl[i].base);
CYBOZU_TEST_EQUAL(x, tbl[i].out);
}
// conflict prefix with base
Fp x;
CYBOZU_TEST_EXCEPTION(x.fromStr("0b100", 16), cybozu::Exception);
CYBOZU_TEST_EXCEPTION(x.fromStr("0x100", 2), cybozu::Exception);
CYBOZU_TEST_EXCEPTION(x.setStr("0b100", 16), cybozu::Exception);
CYBOZU_TEST_EXCEPTION(x.setStr("0x100", 2), cybozu::Exception);
}
CYBOZU_TEST_AUTO(stream)
@ -138,11 +138,11 @@ CYBOZU_TEST_AUTO(conv)
CYBOZU_TEST_EQUAL(b, d);
std::string str;
b.toStr(str, 2, true);
b.getStr(str, 2, true);
CYBOZU_TEST_EQUAL(str, bin);
b.toStr(str);
b.getStr(str);
CYBOZU_TEST_EQUAL(str, dec);
b.toStr(str, 16, true);
b.getStr(str, 16, true);
CYBOZU_TEST_EQUAL(str, hex);
}
@ -283,17 +283,17 @@ CYBOZU_TEST_AUTO(another)
}
CYBOZU_TEST_AUTO(setRaw)
CYBOZU_TEST_AUTO(setArray)
{
Fp::setModulo("1000000000000000000117");
char b1[] = { 0x56, 0x34, 0x12 };
Fp x;
x.setRaw(b1, 3);
x.setArray(b1, 3);
CYBOZU_TEST_EQUAL(x, 0x123456);
int b2[] = { 0x12, 0x34 };
x.setRaw(b2, 2);
x.setArray(b2, 2);
CYBOZU_TEST_EQUAL(x, Fp("0x3400000012"));
x.fromStr("0xffffffffffff");
x.setStr("0xffffffffffff");
Fp::setModulo("0x10000000000001234567a5");
const struct {
@ -305,11 +305,11 @@ CYBOZU_TEST_AUTO(setRaw)
{ { 0x234567a4, 0x00000001, 0x00100000}, 2, "0x1234567a4" },
};
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
x.setRaw(tbl[i].buf, tbl[i].bufN);
x.setArray(tbl[i].buf, tbl[i].bufN);
CYBOZU_TEST_EQUAL(x, Fp(tbl[i].expected));
}
uint32_t large[3] = { 0x234567a5, 0x00000001, 0x00100000};
CYBOZU_TEST_EXCEPTION(x.setRaw(large, 3), cybozu::Exception);
CYBOZU_TEST_EXCEPTION(x.setArray(large, 3), cybozu::Exception);
}
@ -330,7 +330,7 @@ CYBOZU_TEST_AUTO(set64bit)
}
}
CYBOZU_TEST_AUTO(getRaw)
CYBOZU_TEST_AUTO(getArray)
{
const struct {
const char *s;
@ -346,13 +346,13 @@ CYBOZU_TEST_AUTO(getRaw)
mpz_class x(tbl[i].s);
const size_t bufN = 8;
uint32_t buf[bufN];
size_t n = mcl::Gmp::getRaw(buf, bufN, x);
size_t n = mcl::Gmp::getArray(buf, bufN, x);
CYBOZU_TEST_EQUAL(n, tbl[i].vn);
CYBOZU_TEST_EQUAL_ARRAY(buf, tbl[i].v, n);
}
}
CYBOZU_TEST_AUTO(toStr)
CYBOZU_TEST_AUTO(getStr)
{
const char *tbl[] = {
"0x0",
@ -368,8 +368,8 @@ CYBOZU_TEST_AUTO(toStr)
mpz_class x(tbl[i]);
Fp y(tbl[i]);
std::string xs, ys;
mcl::Gmp::toStr(xs, x, 16);
y.toStr(ys, 16);
mcl::Gmp::getStr(xs, x, 16);
y.getStr(ys, 16);
CYBOZU_TEST_EQUAL(xs, ys);
}
}

@ -69,16 +69,16 @@ struct Montgomery {
};
template<class T>
mpz_class toGmp(const T& x)
mpz_class getGmp(const T& x)
{
std::string str = x.toStr();
std::string str = x.getStr();
mpz_class t;
mcl::Gmp::fromStr(t, str);
mcl::Gmp::setStr(t, str);
return t;
}
template<class T>
std::string toStr(const T& x)
std::string getStr(const T& x)
{
std::ostringstream os;
os << x;
@ -89,7 +89,7 @@ template<class T, class U>
T castTo(const U& x)
{
T t;
t.fromStr(toStr(x));
t.setStr(getStr(x));
return t;
}
@ -123,8 +123,8 @@ struct Test {
Zn::setModulo(p);
edge();
cstr();
toStr();
fromStr();
getStr();
setStr();
stream();
conv();
compare();
@ -133,9 +133,9 @@ struct Test {
cvtInt();
power();
power_Zn();
setRaw();
setArray();
set64bit();
getRaw();
getArray();
bench();
}
void cstr()
@ -178,7 +178,7 @@ struct Test {
os << tbl[i].val;
std::string str;
x.toStr(str);
x.getStr(str);
CYBOZU_TEST_EQUAL(str, os.str());
}
const struct {
@ -195,31 +195,31 @@ struct Test {
CYBOZU_TEST_EQUAL(x, tbl2[i].val);
}
}
void toStr()
void getStr()
{
Fp x(0);
std::string str;
str = x.toStr();
str = x.getStr();
CYBOZU_TEST_EQUAL(str, "0");
str = x.toStr(2, true);
str = x.getStr(2, true);
CYBOZU_TEST_EQUAL(str, "0b0");
str = x.toStr(2, false);
str = x.getStr(2, false);
CYBOZU_TEST_EQUAL(str, "0");
str = x.toStr(16, true);
str = x.getStr(16, true);
CYBOZU_TEST_EQUAL(str, "0x0");
str = x.toStr(16, false);
str = x.getStr(16, false);
CYBOZU_TEST_EQUAL(str, "0");
x = 123;
str = x.toStr();
str = x.getStr();
CYBOZU_TEST_EQUAL(str, "123");
str = x.toStr(2, true);
str = x.getStr(2, true);
CYBOZU_TEST_EQUAL(str, "0b1111011");
str = x.toStr(2, false);
str = x.getStr(2, false);
CYBOZU_TEST_EQUAL(str, "1111011");
str = x.toStr(16, true);
str = x.getStr(16, true);
CYBOZU_TEST_EQUAL(str, "0x7b");
str = x.toStr(16, false);
str = x.getStr(16, false);
CYBOZU_TEST_EQUAL(str, "7b");
{
@ -239,7 +239,7 @@ struct Test {
}
}
void fromStr()
void setStr()
{
const struct {
const char *in;
@ -256,13 +256,13 @@ struct Test {
};
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
Fp x;
x.fromStr(tbl[i].in, tbl[i].base);
x.setStr(tbl[i].in, tbl[i].base);
CYBOZU_TEST_EQUAL(x, tbl[i].out);
}
// conflict prefix with base
Fp x;
CYBOZU_TEST_EXCEPTION(x.fromStr("0b100", 16), cybozu::Exception);
CYBOZU_TEST_EXCEPTION(x.fromStr("0x100", 2), cybozu::Exception);
CYBOZU_TEST_EXCEPTION(x.setStr("0b100", 16), cybozu::Exception);
CYBOZU_TEST_EXCEPTION(x.setStr("0x100", 2), cybozu::Exception);
}
void stream()
@ -340,11 +340,11 @@ struct Test {
CYBOZU_TEST_EQUAL(b, d);
std::string str;
b.toStr(str, 2, true);
b.getStr(str, 2, true);
CYBOZU_TEST_EQUAL(str, bin);
b.toStr(str);
b.getStr(str);
CYBOZU_TEST_EQUAL(str, dec);
b.toStr(str, 16, true);
b.getStr(str, 16, true);
CYBOZU_TEST_EQUAL(str, hex);
}
@ -441,7 +441,7 @@ struct Test {
x = 12345;
uint64_t y = x.cvtInt();
CYBOZU_TEST_EQUAL(y, 12345u);
x.fromStr("123456789012342342342342342");
x.setStr("123456789012342342342342342");
CYBOZU_TEST_EXCEPTION(x.cvtInt(), cybozu::Exception);
bool err = false;
CYBOZU_TEST_NO_EXCEPTION(x.cvtInt(&err));
@ -473,16 +473,16 @@ struct Test {
}
}
void setRaw()
void setArray()
{
// QQQ
#if 0
char b1[] = { 0x56, 0x34, 0x12 };
Fp x;
x.setRaw(b1, 3);
x.setArray(b1, 3);
CYBOZU_TEST_EQUAL(x, 0x123456);
int b2[] = { 0x12, 0x34 };
x.setRaw(b2, 2);
x.setArray(b2, 2);
CYBOZU_TEST_EQUAL(x, Fp("0x3400000012"));
#endif
}
@ -504,7 +504,7 @@ struct Test {
}
}
void getRaw()
void getArray()
{
const struct {
const char *s;
@ -520,7 +520,7 @@ struct Test {
mpz_class x(tbl[i].s);
const size_t bufN = 8;
uint32_t buf[bufN];
size_t n = mcl::Gmp::getRaw(buf, bufN, x);
size_t n = mcl::Gmp::getArray(buf, bufN, x);
CYBOZU_TEST_EQUAL(n, tbl[i].vn);
for (size_t j = 0; j < n; j++) {
CYBOZU_TEST_EQUAL(buf[j], tbl[i].v[j]);
@ -566,8 +566,8 @@ put(z);
mpz_class p(pStr);
Montgomery mont(p);
mpz_class xx, yy;
mcl::Gmp::setRaw(xx, x, CYBOZU_NUM_OF_ARRAY(x));
mcl::Gmp::setRaw(yy, y, CYBOZU_NUM_OF_ARRAY(y));
mcl::Gmp::setArray(xx, x, CYBOZU_NUM_OF_ARRAY(x));
mcl::Gmp::setArray(yy, y, CYBOZU_NUM_OF_ARRAY(y));
mpz_class z;
mont.mul(z, xx, yy);
std::cout << std::hex << z << std::endl;
@ -578,7 +578,7 @@ put(z);
Zn::setModulo(pStr);
Zn s(xStr), t(yStr);
s *= t;
rOrg = toStr(s);
rOrg = getStr(s);
{
puts("C");
mpz_class p(pStr);
@ -589,14 +589,14 @@ put(z);
mpz_class z;
mont.mul(z, x, y);
mont.fromMont(z);
rC = toStr(z);
rC = getStr(z);
}
puts("asm");
MontFp9::setModulo(pStr);
MontFp9 x(xStr), y(yStr);
x *= y;
rAsm = toStr(x);
rAsm = getStr(x);
CYBOZU_TEST_EQUAL(rOrg, rC);
CYBOZU_TEST_EQUAL(rOrg, rAsm);
#endif
@ -698,9 +698,9 @@ CYBOZU_TEST_AUTO(toStr16)
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
std::string str, str2;
MontFp3 x(tbl[i]);
x.toStr(str, 16);
x.getStr(str, 16);
mpz_class y(tbl[i]);
mcl::Gmp::toStr(str2, y, 16);
mcl::Gmp::getStr(str2, y, 16);
CYBOZU_TEST_EQUAL(str, str2);
}
}
@ -722,9 +722,9 @@ CYBOZU_TEST_AUTO(toStr16bench)
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
std::string str, str2;
MontFp3 x(tbl[i]);
CYBOZU_BENCH_C("Mont:toStr", C, x.toStr, str, 16);
CYBOZU_BENCH_C("Mont:getStr", C, x.getStr, str, 16);
mpz_class y(tbl[i]);
CYBOZU_BENCH_C("Gmp:toStr ", C, mcl::Gmp::toStr, str2, y, 16);
CYBOZU_BENCH_C("Gmp:getStr ", C, mcl::Gmp::getStr, str2, y, 16);
str2.insert(0, "0x");
CYBOZU_TEST_EQUAL(str, str2);
}
@ -746,14 +746,14 @@ CYBOZU_TEST_AUTO(fromStr16bench)
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
std::string str = tbl[i];
MontFp3 x;
CYBOZU_BENCH_C("Mont:fromStr", C, x.fromStr, str);
CYBOZU_BENCH_C("Mont:setStr", C, x.setStr, str);
mpz_class y;
str.erase(0, 2);
CYBOZU_BENCH_C("Gmp:fromStr ", C, mcl::Gmp::fromStr, y, str, 16);
x.toStr(str, 16);
CYBOZU_BENCH_C("Gmp:setStr ", C, mcl::Gmp::setStr, y, str, 16);
x.getStr(str, 16);
std::string str2;
mcl::Gmp::toStr(str2, y, 16);
mcl::Gmp::getStr(str2, y, 16);
str2.insert(0, "0x");
CYBOZU_TEST_EQUAL(str, str2);
}

Loading…
Cancel
Save