aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2016-04-30 04:42:20 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2016-04-30 04:42:20 +0800
commit909fbbaa5d643fa9b60d8d08a53b4ea6e8b9be97 (patch)
tree128c350753e1d48e4284764fcbe95b6913694b4a
parentab416e7310ffce54bdd48df3da6e3b04b9f8d368 (diff)
downloaddexon-mcl-909fbbaa5d643fa9b60d8d08a53b4ea6e8b9be97.tar.gz
dexon-mcl-909fbbaa5d643fa9b60d8d08a53b4ea6e8b9be97.tar.zst
dexon-mcl-909fbbaa5d643fa9b60d8d08a53b4ea6e8b9be97.zip
remove base argument in Fp::init
-rw-r--r--include/mcl/bn.hpp9
-rw-r--r--include/mcl/fp.hpp12
-rw-r--r--java/mcl_if.hpp4
-rw-r--r--sample/bench.cpp10
-rw-r--r--sample/ecdh.cpp4
-rw-r--r--sample/random.cpp2
-rw-r--r--sample/rawbench.cpp2
-rw-r--r--sample/vote.cpp4
-rw-r--r--test/ec_test.cpp12
-rw-r--r--test/elgamal_test.cpp4
-rw-r--r--test/fp_generator_test.cpp10
-rw-r--r--test/fp_test.cpp24
-rw-r--r--test/fp_tower_test.cpp2
-rw-r--r--test/mont_fp_test.cpp12
-rw-r--r--test/window_method_test.cpp2
15 files changed, 62 insertions, 51 deletions
diff --git a/include/mcl/bn.hpp b/include/mcl/bn.hpp
index 0d85e30..77bc24f 100644
--- a/include/mcl/bn.hpp
+++ b/include/mcl/bn.hpp
@@ -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);
diff --git a/include/mcl/fp.hpp b/include/mcl/fp.hpp
index 4d07ec3..9ee9b31 100644
--- a/include/mcl/fp.hpp
+++ b/include/mcl/fp.hpp
@@ -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);
diff --git a/java/mcl_if.hpp b/java/mcl_if.hpp
index 36d67e3..832e5b3 100644
--- a/java/mcl_if.hpp
+++ b/java/mcl_if.hpp
@@ -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;
diff --git a/sample/bench.cpp b/sample/bench.cpp
index a0e790d..1fed20f 100644
--- a/sample/bench.cpp
+++ b/sample/bench.cpp
@@ -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;
diff --git a/sample/ecdh.cpp b/sample/ecdh.cpp
index 90104c0..d5c4a31 100644
--- a/sample/ecdh.cpp
+++ b/sample/ecdh.cpp
@@ -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));
diff --git a/sample/random.cpp b/sample/random.cpp
index 9c15552..a2a3619 100644
--- a/sample/random.cpp
+++ b/sample/random.cpp
@@ -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;
diff --git a/sample/rawbench.cpp b/sample/rawbench.cpp
index 22aa33f..168fb67 100644
--- a/sample/rawbench.cpp
+++ b/sample/rawbench.cpp
@@ -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);
diff --git a/sample/vote.cpp b/sample/vote.cpp
index 7b877dc..ba09525 100644
--- a/sample/vote.cpp
+++ b/sample/vote.cpp
@@ -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);
}
diff --git a/test/ec_test.cpp b/test/ec_test.cpp
index c4bee58..70725e7 100644
--- a/test/ec_test.cpp
+++ b/test/ec_test.cpp
@@ -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();
}
}
diff --git a/test/elgamal_test.cpp b/test/elgamal_test.cpp
index 92f9fb0..6ddc001 100644
--- a/test/elgamal_test.cpp
+++ b/test/elgamal_test.cpp
@@ -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);
diff --git a/test/fp_generator_test.cpp b/test/fp_generator_test.cpp
index 020402c..499c1f0 100644
--- a/test/fp_generator_test.cpp
+++ b/test/fp_generator_test.cpp
@@ -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);
diff --git a/test/fp_test.cpp b/test/fp_test.cpp
index 8025af7..840ff49 100644
--- a/test/fp_test.cpp
+++ b/test/fp_test.cpp
@@ -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++) {
diff --git a/test/fp_tower_test.cpp b/test/fp_tower_test.cpp
index a7b6173..ca072b7 100644
--- a/test/fp_tower_test.cpp
+++ b/test/fp_tower_test.cpp
@@ -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);
diff --git a/test/mont_fp_test.cpp b/test/mont_fp_test.cpp
index c1b2393..64f3ba0 100644
--- a/test/mont_fp_test.cpp
+++ b/test/mont_fp_test.cpp
@@ -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);
diff --git a/test/window_method_test.cpp b/test/window_method_test.cpp
index b56fa62..741d02b 100644
--- a/test/window_method_test.cpp
+++ b/test/window_method_test.cpp
@@ -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);