remove base argument in Fp::init

dev
MITSUNARI Shigeo 9 years ago
parent ab416e7310
commit 909fbbaa5d
  1. 9
      include/mcl/bn.hpp
  2. 12
      include/mcl/fp.hpp
  3. 4
      java/mcl_if.hpp
  4. 10
      sample/bench.cpp
  5. 4
      sample/ecdh.cpp
  6. 2
      sample/random.cpp
  7. 2
      sample/rawbench.cpp
  8. 4
      sample/vote.cpp
  9. 12
      test/ec_test.cpp
  10. 4
      test/elgamal_test.cpp
  11. 10
      test/fp_generator_test.cpp
  12. 24
      test/fp_test.cpp
  13. 2
      test/fp_tower_test.cpp
  14. 12
      test/mont_fp_test.cpp
  15. 2
      test/window_method_test.cpp

@ -142,14 +142,14 @@ struct ParamT {
p = eval(pCoff, z);
r = eval(rCoff, z);
mpz_class t = eval(tCoff, z);
Fp::setModulo(p.get_str(), 10, mode);
Fp::init(p.get_str(), mode);
Fp2::init(cp.xi_a);
b = cp.b; // set b before calling Fp::setModulo
b = cp.b; // set b before calling Fp::init
half = Fp(1) / Fp(2);
Fp2 xi(cp.xi_a, 1);
b_invxi = Fp2(b) / xi;
G1::setParam(0, b, mcl::ec::Proj);
G2::setParam(0, b_invxi, mcl::ec::Proj);
G1::init(0, b, mcl::ec::Proj);
G2::init(0, b_invxi, mcl::ec::Proj);
power(gammar[0], xi, (p - 1) / 6);
for (size_t i = 1; i < gammarN; i++) {
@ -373,6 +373,7 @@ struct BNT {
}
G2 Q1, Q2;
Frobenius(Q1, Q, p);
PUT(Q1);
Frobenius(Q2, Q1, p);
if (param.z < 0) {
G2::neg(T, T);

@ -78,7 +78,16 @@ public:
}
printf("\n");
}
static inline void setModulo(const std::string& mstr, int base = 0, fp::Mode mode = fp::FP_AUTO)
// backward compatibility
static inline void setModulo(const std::string& mstr, fp::Mode mode = fp::FP_AUTO)
{
init(mstr, mode);
}
static inline void init(const mpz_class& m, fp::Mode mode = fp::FP_AUTO)
{
init(m.get_str(), mode);
}
static inline void init(const std::string& mstr, fp::Mode mode = fp::FP_AUTO)
{
assert(maxBitSize <= MCL_MAX_OP_BIT_SIZE);
assert(sizeof(mp_limb_t) == sizeof(Unit));
@ -124,6 +133,7 @@ public:
#endif
"\n", mode, op_.isMont);
#endif
int base = 0;
op_.init(mstr, base, maxBitSize, mode);
{ // set oneRep
FpT& one = *reinterpret_cast<FpT*>(op_.oneRep);

@ -29,8 +29,8 @@ void SystemInit(const std::string& param) throw(std::exception)
if (iss >> ecParamStr >> hashNameStr) {
Param& p = Param::getParam();
p.ecParam = mcl::getEcParam(ecParamStr);
Zn::setModulo(p.ecParam->n);
Fp::setModulo(p.ecParam->p);
Zn::init(p.ecParam->n);
Fp::init(p.ecParam->p);
Ec::init(p.ecParam->a, p.ecParam->b);
p.hashName = cybozu::crypto::Hash::getName(hashNameStr);
return;

@ -23,7 +23,7 @@ const char *getModeStr(mcl::fp::Mode mode)
void benchFpSub(const char *pStr, const char *xStr, const char *yStr, mcl::fp::Mode mode)
{
const char *s = getModeStr(mode);
Fp::setModulo(pStr, 0, mode);
Fp::init(pStr, mode);
Fp x(xStr);
Fp y(yStr);
@ -86,8 +86,8 @@ void benchFp(size_t bitSize, int mode)
void benchEcSub(const mcl::EcParam& para, mcl::fp::Mode mode, mcl::ec::Mode ecMode)
{
Fp::setModulo(para.p, 0, mode);
Zn::setModulo(para.n);
Fp::init(para.p, mode);
Zn::init(para.n);
Ec::init(para.a, para.b, ecMode);
Fp x(para.gx);
Fp y(para.gy);
@ -147,7 +147,7 @@ void benchToStr16()
"0x100000000000000000000000000000033",
"0x11ee12312312940000000000000000000000000002342343"
};
Fp::setModulo("0xffffffffffffffffffffffffffffffffffffffffffffff13");
Fp::init("0xffffffffffffffffffffffffffffffffffffffffffffff13");
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
std::string str;
Fp x(tbl[i]);
@ -169,7 +169,7 @@ void benchFromStr16()
"100000000000000000000000000000033",
"11ee12312312940000000000000000000000000002342343"
};
Fp::setModulo("0xffffffffffffffffffffffffffffffffffffffffffffff13");
Fp::init("0xffffffffffffffffffffffffffffffffffffffffffffff13");
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
std::string str = tbl[i];
Fp x;

@ -20,8 +20,8 @@ int main()
the cyclic group of <P> is isomorphic to Zn
*/
const mcl::EcParam& para = mcl::ecparam::secp192k1;
Zn::setModulo(para.n);
Fp::setModulo(para.p);
Zn::init(para.n);
Fp::init(para.p);
Ec::init(para.a, para.b);
const Ec P(Fp(para.gx), Fp(para.gy));

@ -15,7 +15,7 @@ int main(int argc, char *argv[])
if (argc == 2) {
p = argv[1];
}
Fp::setModulo(p);
Fp::init(p);
Fp x;
printf("p=%s\n", p);
Map m;

@ -24,7 +24,7 @@ const char *getModeStr(mcl::fp::Mode mode)
void benchRaw(const char *p, mcl::fp::Mode mode)
{
Fp::setModulo(p, 0, mode);
Fp::init(p, mode);
Fp2::init(1);
typedef mcl::fp::Unit Unit;
const size_t maxN = sizeof(Fp) / sizeof(Unit);

@ -61,8 +61,8 @@ struct Param {
void SysInit()
{
const mcl::EcParam& para = mcl::ecparam::secp192k1;
Zn::setModulo(para.n);
Fp::setModulo(para.p);
Zn::init(para.n);
Fp::init(para.p);
Ec::init(para.a, para.b);
}

@ -16,12 +16,12 @@ typedef mcl::EcT<Fp> Ec;
struct Test {
const mcl::EcParam& para;
Test(const mcl::EcParam& para, mcl::ec::Mode mode)
Test(const mcl::EcParam& para, mcl::fp::Mode fpMode, mcl::ec::Mode ecMode)
: para(para)
{
Fp::setModulo(para.p);
Zn::setModulo(para.n);
Ec::init(para.a, para.b, mode);
Fp::init(para.p, fpMode);
Zn::init(para.n, fpMode);
Ec::init(para.a, para.b, ecMode);
}
void cstr() const
{
@ -321,9 +321,9 @@ void test_sub(const mcl::EcParam *para, size_t paraNum)
for (size_t i = 0; i < paraNum; i++) {
puts(para[i].name);
puts("Jacobi");
Test(para[i], mcl::ec::Jacobi).run();
Test(para[i], mcl::fp::FP_AUTO, mcl::ec::Jacobi).run();
puts("Proj");
Test(para[i], mcl::ec::Proj).run();
Test(para[i], mcl::fp::FP_AUTO, mcl::ec::Proj).run();
}
}

@ -16,8 +16,8 @@ cybozu::RandomGenerator rg;
CYBOZU_TEST_AUTO(testEc)
{
Fp::setModulo(para.p);
Zn::setModulo(para.n);
Fp::init(para.p);
Zn::init(para.n);
Ec::init(para.a, para.b);
const Fp x0(para.gx);
const Fp y0(para.gy);

@ -17,10 +17,10 @@ typedef mcl::FpT<> Fp;
const int MAX_N = 4;
const char *primeTable[] = {
"7fffffffffffffffffffffffffffffff", // 127bit(not full)
"ffffffffffffffffffffffffffffff61", // 128bit(full)
"fffffffffffffffffffffffffffffffffffffffeffffee37", // 192bit(full)
"2523648240000001ba344d80000000086121000000000013a700000000000013", // 254bit(not full)
"0x7fffffffffffffffffffffffffffffff", // 127bit(not full)
"0xffffffffffffffffffffffffffffff61", // 128bit(full)
"0xfffffffffffffffffffffffffffffffffffffffeffffee37", // 192bit(full)
"0x2523648240000001ba344d80000000086121000000000013a700000000000013", // 254bit(not full)
};
void strToArray(uint64_t *p, size_t n, const char *pStr)
@ -183,7 +183,7 @@ void testShr1(const mcl::fp::FpGenerator& fg, int pn)
void test(const char *pStr)
{
Fp::setModulo(pStr, 16, mcl::fp::FP_XBYAK);
Fp::init(pStr, mcl::fp::FP_XBYAK);
const mcl::fp::Op& op = Fp::getOp();
const int pn = (int)op.N;
testAddSub(op);

@ -17,7 +17,7 @@ struct Init {
{
std::ostringstream ms;
ms << m;
Fp::setModulo(ms.str());
Fp::init(ms.str());
}
};
@ -275,7 +275,7 @@ CYBOZU_TEST_AUTO(power)
z *= x;
}
typedef mcl::FpT<tag2, 128> Fp2;
Fp2::setModulo("1009");
Fp2::init("1009");
x = 5;
Fp2 n = 3;
z = 3;
@ -316,7 +316,7 @@ struct TagAnother;
CYBOZU_TEST_AUTO(another)
{
typedef mcl::FpT<TagAnother, 128> G;
G::setModulo("13");
G::init("13");
G a = 3;
G b = 9;
a *= b;
@ -325,7 +325,7 @@ CYBOZU_TEST_AUTO(another)
CYBOZU_TEST_AUTO(setArray)
{
Fp::setModulo("1000000000000000000117");
Fp::init("1000000000000000000117");
char b1[] = { 0x56, 0x34, 0x12 };
Fp x;
x.setArray(b1, 3);
@ -334,7 +334,7 @@ CYBOZU_TEST_AUTO(setArray)
x.setArray(b2, 2);
CYBOZU_TEST_EQUAL(x, Fp("0x3400000012"));
Fp::setModulo("0x10000000000001234567a5");
Fp::init("0x10000000000001234567a5");
const struct {
uint32_t buf[3];
size_t bufN;
@ -355,7 +355,7 @@ CYBOZU_TEST_AUTO(setArray)
CYBOZU_TEST_AUTO(setArrayMask)
{
Fp::setModulo("1000000000000000000117");
Fp::init("1000000000000000000117");
char b1[] = { 0x56, 0x34, 0x12 };
Fp x;
x.setArrayMask(b1, 3);
@ -364,7 +364,7 @@ CYBOZU_TEST_AUTO(setArrayMask)
x.setArrayMask(b2, 2);
CYBOZU_TEST_EQUAL(x, Fp("0x3400000012"));
Fp::setModulo("0x10000000000001234567a5");
Fp::init("0x10000000000001234567a5");
const struct {
uint32_t buf[3];
size_t bufN;
@ -383,7 +383,7 @@ CYBOZU_TEST_AUTO(setArrayMask)
CYBOZU_TEST_AUTO(set64bit)
{
Fp::setModulo("0x1000000000000000000f");
Fp::init("0x1000000000000000000f");
const struct {
const char *p;
int64_t i;
@ -400,7 +400,7 @@ CYBOZU_TEST_AUTO(set64bit)
CYBOZU_TEST_AUTO(getUint64)
{
Fp::setModulo("0x1000000000000000000f");
Fp::init("0x1000000000000000000f");
const uint64_t tbl[] = {
0, 1, 123, 0xffffffff, int64_t(0x7fffffffffffffffull)
};
@ -431,7 +431,7 @@ CYBOZU_TEST_AUTO(getUint64)
CYBOZU_TEST_AUTO(getInt64)
{
Fp::setModulo("0x1000000000000000000f");
Fp::init("0x1000000000000000000f");
const int64_t tbl[] = {
0, 1, 123, 0xffffffff, int64_t(0x7fffffffffffffffull),
-1, -2, -12345678, -int64_t(1) << 63,
@ -489,7 +489,7 @@ CYBOZU_TEST_AUTO(getStr)
"0x100000000000000000000000000000033",
"0x11ee12312312940000000000000000000000000002342343"
};
Fp::setModulo("0xfffffffffffffffffffffffe26f2fc170f69466a74defd8d");
Fp::init("0xfffffffffffffffffffffffe26f2fc170f69466a74defd8d");
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
mpz_class x(tbl[i]);
Fp y(tbl[i]);
@ -519,7 +519,7 @@ CYBOZU_TEST_AUTO(mod_NIST_P521)
"0x3ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
};
const char *p = "0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
Fp::setModulo(p, 0, mcl::fp::FP_XBYAK);
Fp::init(p, mcl::fp::FP_XBYAK);
const mcl::fp::Op& op = Fp::getOp();
const mpz_class mp(p);
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {

@ -338,7 +338,7 @@ void benchFp2()
void test(const char *p, mcl::fp::Mode mode)
{
Fp::setModulo(p, 0, mode);
Fp::init(p, mode);
printf("mode=%s\n", mcl::fp::ModeToStr(mode));
const int xi_a = 1;
Fp2::init(xi_a);

@ -112,9 +112,9 @@ struct Test {
mpz_class m;
void run(const char *p)
{
Fp::setModulo(p);
Fp::init(p);
m = p;
Zn::setModulo(p);
Zn::init(p);
edge();
cstr();
getStr();
@ -584,7 +584,7 @@ void customTest(const char *pStr, const char *xStr, const char *yStr)
#if 0
{
pStr = "0xfffffffffffffffffffffffffffffffffffffffeffffee37",
Fp::setModulo(pStr);
Fp::init(pStr);
static uint64_t x[3] = { 1, 0, 0 };
uint64_t z[3];
std::cout<<std::hex;
@ -598,7 +598,7 @@ put(z);
uint64_t x[9] = { 0xff7fffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0x1ff };
uint64_t y[9] = { 0xff7fffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0x1ff };
uint64_t z1[9], z2[9];
Fp::setModulo(pStr);
Fp::init(pStr);
Fp::fg_.mul_(z2, x, y);
put(z2);
{
@ -615,7 +615,7 @@ put(z);
exit(1);
#else
std::string rOrg, rC, rAsm;
Zn::setModulo(pStr);
Zn::init(pStr);
Zn s(xStr), t(yStr);
s *= t;
rOrg = getStr(s);
@ -633,7 +633,7 @@ put(z);
}
puts("asm");
Fp::setModulo(pStr);
Fp::init(pStr);
Fp x(xStr), y(yStr);
x *= y;
rAsm = getStr(x);

@ -29,7 +29,7 @@ CYBOZU_TEST_AUTO(int)
typedef mcl::FpT<> Fp;
typedef mcl::EcT<Fp> Ec;
const struct mcl::EcParam& para = mcl::ecparam::secp192k1;
Fp::setModulo(para.p);
Fp::init(para.p);
Ec::init(para.a, para.b);
const Fp x(para.gx);
const Fp y(para.gy);

Loading…
Cancel
Save